---
name: "PGASortPop"
section: "8"
platform: "linux"
package: "pgapack"
version: "1.1.1-3"
release: "Debian 8 (Jessie)"
platforms: ["linux"]
url: "https://new.carta.tech/PGASortPop"
---

# PGASortPop(8)

Creates an (internal) array of indices according to one of three criteria.

## NAME

PGASortPop - 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.  If PGA\_POPREPL\_RANDOM\_REP is used the indices in the array are selected randomly with replacement. If PGA\_POPREPL\_RANDOM\_NOREP is used the indices in the array are selected randomly without replacement.  The function PGASetPopReplaceType() is used to specify which strategy is used.  The indices of the sorted population members may then be accessed from the internal array via PGAGetSortedPopIndex().  This routine is typically used during population replacement.

## INPUT PARAMETERS

- ctx

  \- context variable

- popindex

  \- symbolic constant of the population from which to create the srted array.

## OUTPUT PARAMETERS

- none

  ## SYNOPSIS

```
#include "pgapack.h"
void  PGASortPop(ctx, pop)
PGAContext *ctx
int pop
```

## LOCATION

pop.c

## EXAMPLE

```
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);
:
```
