Function PGASortPop
Defined in File pop.c
Function Documentation
-
void PGASortPop(PGAContext *ctx, int pop)
Creates an (internal) array of indices according to one of three criteria.
Description
If
PGA_POPREPL_BEST
is used (the default) the array is sorted from most fit to least fit. IfPGA_POPREPL_RANDOM_REP
is used the indices in the array are selected randomly with replacement. IfPGA_POPREPL_RANDOM_NOREP
is used the indices in the array are selected randomly without replacement. The functionPGASetPopReplaceType()
is used to specify which strategy is used. The indices of the sorted population members may then be accessed from the internal array viaPGAGetSortedPopIndex()
. This routine is typically used during population replacement.Example
Copy the five best strings from the old population into the new population. The rest of the new population will be created by recombination, and is not shown.
PGAContext *ctx; int i, j; ... PGASetPopReplaceType (ctx, PGA_POPREPL_BEST) ... PGASortPop (ctx, PGA_OLDPOP); for (i=0; i<5; i++) { j = PGAGetSortedPopIndex (ctx, i); PGACopyIndividual (ctx, j, PGA_OLDPOP, i, PGA_NEWPOP); }
- Parameters:
ctx – context variable
pop – symbolic constant of the population from which to create the sorted array
- Returns:
An inteneral array of indices sorted according to one of three criteria is created