Function Groups Standard API

Allele Access

group allele

Functions for getting and setting allele values.

Functions

void PGAEncodeIntegerAsBinary(PGAContext *ctx, int p, int pop, int start, int end, unsigned int val)

Encode an integer value as a binary string.

Example

Encode an integer 7 in 20 bits in bit positions 0–19 in string p in population PGA_NEWPOP.

PGAContext *ctx;
int p;

...
PGAEncodeIntegerAsBinary (ctx, p, PGA_NEWPOP, 0, 19, 7);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

  • start – starting bit position in p to encode val in

  • end – ending bit position in p to encode val in

  • val – the integer value to be represented as a binary string

Returns

The string is modified by side-effect

void PGAEncodeIntegerAsGrayCode(PGAContext *ctx, int p, int pop, int start, int end, unsigned int val)

Encode a real value as a binary reflected Gray code sequence.

Example

Encode an integer 7 in 20 bits in bit positions 0–19 in string p in population PGA_NEWPOP using Gray code.

PGAContext *ctx;
int p;

...
PGAEncodeIntegerAsGrayCode (ctx, p, PGA_NEWPOP, 0, 19, 7);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

  • start – starting bit position in p to encode val in

  • end – ending bit position in p to encode val in

  • val – the integer value to be represented as a binary reflected Gray code sequence

Returns

The string is modified by side-effect

void PGAEncodeRealAsBinary(PGAContext *ctx, int p, int pop, int start, int end, double low, double high, double val)

Encode a real value as a binary string.

Example

Encode 3.14 from the interval \([0,10]\) in 30 bits in bit positions 0–29 in string p in population PGA_NEWPOP.

PGAContext *ctx;
int p;

...
PGAEncodeRealAsBinary (ctx, p, PGA_NEWPOP, 0, 29, 0.0, 10.0, 3.14);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

  • start – starting bit position in p to encode val in

  • end – ending bit position in p to encode val in

  • low – lower bound of the interval the val is defined on

  • high – upper bound of the interval the val is defined on

  • val – the real number to be represented as a binary string

Returns

The string is modified by side-effect

void PGAEncodeRealAsGrayCode(PGAContext *ctx, int p, int pop, int start, int end, double low, double high, double val)

Encode a real value as a binary reflected Gray code sequence.

Example

Encode 3.14 from the interval \([0,10]\) in 30 bits in bit positions 0–29 in string p in population PGA_NEWPOP as a binary reflected Gray code sequence.

PGAContext *ctx;
int p;

...
PGAEncodeRealAsGrayCode (ctx, p, PGA_NEWPOP, 0, 29, 0.0, 10.0, 3.14);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

  • start – starting bit position in p to encode val in

  • end – ending bit position in p to encode val in

  • low – lower bound of the interval the val is defined on

  • high – upper bound of the interval the val is defined on

  • val – the real number to be represented as a binary string

Returns

The string is modified by side-effect

int PGAGetBinaryAllele(PGAContext *ctx, int p, int pop, int i)

Return the value of a (binary) allele.

Description

Applies to the binary data type, set with parameter PGA_DATATYPE_BINARY of PGACreate().

Example

Copies the alleles from member p in PGA_OLDPOP to member q PGA_NEWPOP. Assumes the strings are of the same length.

PGAContext *ctx;
int p, q, i;

...
for (i=PGAGetStringLength (ctx)-1; i>=0; i--) {
    int a = PGAGetBinaryAllele (ctx, p, PGA_OLDPOP, i);
    PGASetBinaryAllele (ctx, q, PGA_NEWPOP, i, a);
}

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

  • i – allele index

Returns

The value of the ith allele of string p in population pop

char PGAGetCharacterAllele(PGAContext *ctx, int p, int pop, int i)

Return the value of character allele in a string of the character data type.

Example

Copies the alleles from member p in PGA_OLDPOP to member q in PGA_NEWPOP. Assumes the strings are of the same length.

PGAContext *ctx;
int p, q, i;
int l;

...
l = PGAGetStringLength (ctx);
for (i=0; i<l; i++) {
    char a = PGAGetCharacterAllele (ctx, p, PGA_OLDPOP, i);
    PGASetCharacterAllele (ctx, q, PGA_NEWPOP, i, a);
}

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

  • i – allele index

Returns

The value of allele i in string p

PGAIndividual *PGAGetIndividual(PGAContext *ctx, int p, int pop)

Return individual defined by population symbolic constant and population index.

Example

PGAIndividual *source;
PGAContext *ctx;
int p;

...
source = PGAGetIndividual (ctx, p, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

Returns

Address of the PGAIndividual structure for string p in population pop

int PGAGetIntegerAllele(PGAContext *ctx, int p, int pop, int i)

Return the value of allele i of member p in population pop.

Description

Assumes the data type is PGA_DATATYPE_INTEGER.

Example

Returns the value of integer allele i of string p in population PGA_NEWPOP.

PGAContext *ctx;
int p, i, k;

...
k =  PGAGetIntegerAllele (ctx, p, PGA_NEWPOP, i)

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

  • i – allele index

Returns

The value of allele i in string p

unsigned int PGAGetIntegerFromBinary(PGAContext *ctx, int p, int pop, int start, int end)

Interpret a binary string as encoding an integer value and return the integer value it represents.

Example

Get an integer j from bits 10–29 of string p in population PGA_NEWPOP.

PGAContext *ctx;
int j, p;

...
j = PGAGetIntegerFromBinary (ctx, p, PGA_NEWPOP, 10, 29);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

  • start – starting bit position in the binary representation

  • end – ending bit position in the binary representation

Returns

The integer value encoded by the binary string

unsigned int PGAGetIntegerFromGrayCode(PGAContext *ctx, int p, int pop, int start, int end)

Interpret a binary reflected Gray code sequence as encoding an integer value and return the integer value it represents.

Example

Get an integer j from bits 10–29 of string p in population PGA_NEWPOP. The string is encoded in Gray code.

PGAContext *ctx;
int j, p;

...
j = PGAGetIntegerFromGrayCode (ctx, p, PGA_NEWPOP, 10, 29);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

  • start – starting bit position in the binary representation

  • end – ending bit position in the binary representation

Returns

The integer value encoded by the binary reflected Gray code sequence

double PGAGetRealAllele(PGAContext *ctx, int p, int pop, int i)

Return the value of real-valued allele i in string p in population pop.

Example

Returns the value of real-valued allele i of string p in population PGA_NEWPOP

PGAContext *ctx;
int p, i
double d;

...
d = PGAGetRealAllele (ctx, p, PGA_NEWPOP, i);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

  • i – allele index

Returns

The value of allele i

double PGAGetRealFromBinary(PGAContext *ctx, int p, int pop, int start, int end, double lower, double upper)

Interpret a binary string as encoding a real value and return the real value it represents.

Example

Decode a real value from the string p in population PGA_NEWPOP. The value to decode lies on the interval \([-10,20]\) and is represented using the 20 bits in bit positions 10–29.

double x;

...
x = PGAGetRealFromBinary (ctx, p, PGA_NEWPOP, 10, 29, -10.0, 20.0);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

  • start – starting bit position in the binary representation

  • end – ending bit position in the binary representation

  • lower – lower bound of the interval the real number is defined on

  • upper – upper bound of the interval the real number is defined on

Returns

The real value encoded by the binary string

double PGAGetRealFromGrayCode(PGAContext *ctx, int p, int pop, int start, int end, double lower, double upper)

Interpret a binary reflected Gray code sequence in a binary string as encoding a real value and return the real value it represents.

Example

Decode a real value from the string p in population PGA_NEWPOP. The value to decode lies on the interval \([-10,20]\) and is represented using the 20 bits in bit positions 10–29.

double x;

...
x = PGAGetRealFromGrayCode (ctx, p, PGA_NEWPOP, 10, 29, -10.0, 20.0);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

  • start – starting bit position in the binary representation

  • end – ending bit position in the binary representation

  • lower – lower bound of the interval the real number is defined on

  • upper – upper bound of the interval the real number is defined on

Returns

The real value encoded by the binary reflected Gray code sequence

void PGASetBinaryAllele(PGAContext *ctx, int p, int pop, int i, int val)

Sets a binary allele to the specified value.

Example

Copies the alleles from member p in PGA_OLDPOP to member q in PGA_NEWPOP.

PGAContext *ctx;
int p, q, i;
int l;

...
l = PGAGetStringLength (ctx);
for (i=0 i<l; i++) {
    int a = PGAGetBinaryAllele (ctx, p, PGA_OLDPOP, i);
    PGASetBinaryAllele (ctx, q, PGA_NEWPOP, i, a);
}

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

  • i – allele index

  • val – binary value (either 1 or 0) to set the allele to

Returns

The allele is changed by side-effect

void PGASetCharacterAllele(PGAContext *ctx, int p, int pop, int i, char val)

Sets the value of an allele in a string of the character data type.

Example

Copies the alleles from member p in PGA_OLDPOP to member q in PGA_NEWPOP. Assumes the strings are of the same length.

PGAContext *ctx;
int p, q, i;
int l;

...
l = PGAGetStringLength (ctx);
for (i=0; i<l; i++) {
    char a = PGAGetCharacterAllele (ctx, p, PGA_OLDPOP, i);
    PGASetCharacterAllele (ctx, q, PGA_NEWPOP, i, a);
}

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

  • i – allele index

  • val – character value to set the allele to

Returns

The allele is changed by side-effect.

void PGASetIntegerAllele(PGAContext *ctx, int p, int pop, int i, int val)

Set the value of a (integer) allele.

Example

Set the value of allele i of string p in population PGA_NEWPOP to 64.

PGAContext *ctx;
int p, i;

...
PGASetIntegerAllele (ctx, p, PGA_NEWPOP, i, 64)

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

  • i – allele index

  • val – integer value to set the allele to

Returns

None

void PGASetRealAllele(PGAContext *ctx, int p, int pop, int i, double val)

Set the value of real-valued allele i in string p in population pop.

Example

Sets the value of allele i of string p in population PGA_NEWPOP to 1.57

PGAContext *ctx;
int i, p;

...
PGASetRealAllele (ctx, p, PGA_NEWPOP, i, 1.57);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

  • i – allele index

  • val – real value to set the allele to

Returns

The specified allele in p is modified by side-effect.

Evaluation

group evaluation

Functions used during evaluation and fitness computation.

Functions

void PGAFitness(PGAContext *ctx, int popindex)

Map the user’s evaluation function value to a fitness value.

Description

First, the user’s evaluation function value is translated to all positive values if any are negative. Next, this positive sequence is translated to a maximization problem if the user’s optimization direction was minimization. This positive sequence is then mapped to a fitness value using linear ranking, linear normalization fitness, or the identity (i.e., the evaluation function value). See Constants for Fitness Types in the user guide for allowed values. This routine is usually used after PGAEvaluate() is called.

Example

Calculate the fitness of all strings in population PGA_NEWPOP after calling PGAEvaluate() to calculate the strings evaluation value.

double energy (PGAContext *ctx, int p, int pop, double *aux);
PGAContext *ctx;
MPI_Comm comm;

...
PGAEvaluate (ctx, PGA_NEWPOP, energy, comm);
PGAFitness  (ctx, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • popindex – symbolic constant of the population to calculate fitness for

Returns

Calculate the fitness for each string in the population via side effect

double *PGAGetAuxEvaluation(PGAContext *ctx, int p, int pop)

Return the auxiliary evaluation for string p in population pop.

Description

This is mostly used internally: the evaluation function will get a pointer to this anyway, this is the only point where the aux evaluations should be modified.

Example

PGAContext *ctx;
int p;
double *aux;

...
aux = PGAGetAuxEvaluation (ctx, p, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

Returns

The evaluation function value for string p in population pop

int PGAGetEvaluationUpToDateFlag(PGAContext *ctx, int p, int pop)

Return boolean to indicate whether the evaluate function value is up to date.

Example

PGAContext *ctx;

...
if (PGAGetEvaluationUpToDateFlag (ctx)) {
    printf ("Evaluation function value current\n");
} else {
    printf ("Evaluation function value out-of-date\n");
}

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

Returns

Return true if the evaluate function value is up to date

double PGAGetFitness(PGAContext *ctx, int p, int pop)

Return the fitness value for a string.

Example

PGAContext *ctx;
int p;
double fit;

...
fit = PGAGetFitness (ctx, p, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

Returns

The fitness value for string p in population pop

int PGARank(PGAContext *ctx, int p, int *order, int n)

Return the rank of a string in a population.

Description

This is a value between 1,…,N (the population size). The most fit string has rank 1, the least fit string has rank N.

Example

Determine the rank of string p.

PGAContext *ctx;
int i, popsize, rank;
int popsize = PGAGetPopsize (ctx)
int order [popsize];

...
PGAEvalSort (ctx, pop, order);
rank = PGARank (ctx, p, order, popsize)

Parameters
  • ctx – context variable

  • p – the index of the string whose rank is desired

  • order – an array containing a unique rank for each string

  • n – the size of the array order

Returns

The rank of string p

void PGASetEvaluationUpToDateFlag(PGAContext *ctx, int p, int pop, int status)

Set the flag to indicate whether the evaluate function value is up-to-date or not.

Description

Note that this flag is always set to PGA_TRUE when _PGASetEvaluation() is called.

Example

Set the evaluation function flag for string p in population PGA_NEWPOP to PGA_FALSE (as might happen after, for example, calling a hill-climbing routine that modified this string).

PGAContext *ctx;
int p;

...
PGASetEvaluationUpToDateFlag (ctx, p, PGA_NEWPOP, PGA_FALSE);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population string p is in

  • status – boolean for whether up-to-date

Returns

Sets the flag associated with the evaluation function value of string p via side effect

double _PGAGetEvaluation(PGAContext *ctx, int p, int pop, const double **aux)

Return the evaluation function value for string p in population pop and optionally a pointer to the auxiliary evaluations.

Description

This uses a trick for implementing optional arguments in C. The real function to use is without leading underscore. There is a macro that makes the last argument optional.

Example

PGAContext *ctx;
int p;
double eval;

...
eval = PGAGetEvaluation (ctx, p, PGA_NEWPOP);

or

const double *p;
...
eval = PGAGetEvaluation (ctx, p, PGA_NEWPOP, &p);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

  • aux – Pointer to Auxiliary evaluations

Returns

The evaluation function value for string p in population pop

void _PGASetEvaluation(PGAContext *ctx, int p, int pop, double val, const double *aux)

Set the evaluation function value for a string to a specified value.

Description

This uses a trick for implementing optional arguments in C. The real function to use is without leading underscore. There is a macro that makes the last argument optional. Also sets the evaluation up to date flag to PGA_TRUE.

Example

Set the evaluation function value of string p in population PGA_NEWPOP to 123.456.

PGAContext *ctx;
int p;
double aux [...];

...
PGASetEvaluation (ctx, p, PGA_NEWPOP, 123.456);

or

PGASetEvaluation (ctx, p, PGA_NEWPOP, 123.456, aux);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population string p is in

  • val – the (user) evaluation value to assign to string p

  • aux – Auxiliary evaluations

Returns

Sets the evaluation function value of string p and the EvalUpToDate flag via side effect

Initialization

group init

Functions used to change initialization.

Functions

void PGASetBinaryInitProb(PGAContext *ctx, double p)

Specify the probability of initializing an allele to “1” for the binary data type.

Description

The default value is 0.5. This is used during string creation of a PGA_DATATYPE_BINARY string.

Example

Set approximately 1 percent of all binary alleles to “1” when randomly initializing the population.

PGAContext *ctx;

...
PGASetBinaryInitProb (ctx, 0.01);

Parameters
  • ctx – context variable

  • p – the binary initialization probability

Returns

None

void PGASetCharacterInitType(PGAContext *ctx, int value)

Sets a flag to specify whether the character strings will be exclusively lowercase, exclusively uppercase, or a mixure of both cases.

Description

Legal flags are PGA_CINIT_UPPER, PGA_CINIT_LOWER, and PGA_CINIT_MIXED. Default is PGA_CINIT_LOWER. See Constants for Random Initialization of Genes for the constants and section Initialization of the user guide for details.

Example

Set program to generate exclusively uppercase letters.

PGAContext *ctx;

...
PGASetCharacterInitType (ctx, PGA_CINIT_UPPER);

Parameters
  • ctx – context variable

  • value – symbolic constant specifying which case

Returns

None

void PGASetCommunicator(PGAContext *ctx, MPI_Comm comm)

Set the default communicator to use when PGARun is called.

Description

Does not necessarily need to be MPI_COMM_WORLD (which is the default).

Example

MPI_Comm mycomm;
PGAContext *ctx,
double f (PGAContext *ctx, int p, int pop, double *aux);

ctx = PGACreate (&argc, argv, PGA_DATATYPE_BINARY, 100, PGA_MAXIMIZE);
PGASetCommunicator (ctx, mycomm);
PGASetUp (ctx);
PGARun (ctx, f);
PGADestroy (ctx);

Parameters
  • ctx – context variable

  • comm – communicator to use

Returns

None

void PGASetCrossoverBounceBackFlag(PGAContext *ctx, int flag)

If this flag is set to true, then for Integer and Real strings with simulated binary crossover (SBX) crossed over values that exceed the bounds are confined to the bounds by bouncing them back to a random value between the boundary and the neares parent.

Example

PGAContext *ctx;

...
PGASetCrossoverBounceBackFlag (ctx, PGA_TRUE);

Parameters
  • ctx – context variable

  • flag – to indicate whether out-of-range values should be bounced

Returns

None

void PGASetCrossoverBoundedFlag(PGAContext *ctx, int flag)

If this flag is set to true, then for Integer and Real strings with simulated binary crossover (SBX) crossed over values that exceed the bounds are confined to the bounds by setting them to the boundary.

Example

PGAContext *ctx;

...
PGASetCrossoverBoundedFlag (ctx, PGA_TRUE);

Parameters
  • ctx – context variable

  • flag – to indicate if strings should be constrained to boundary

Returns

None

void PGASetCrossoverProb(PGAContext *ctx, double p)

Set Probability that a selected string will undergo crossover.

Description

The default is 0.85.

Example

Make crossover happen infrequently.

PGAContext *ctx;

...
PGASetCrossoverProb (ctx, 0.001);

Parameters
  • ctx – context variable

  • p – the crossover probability

Returns

None

void PGASetCrossoverSBXEta(PGAContext *ctx, double eta)

Set the eta parameter for simulated binary crossover (SBX).

Example

PGAContext *ctx;

...
PGASetCrossoverSBXEta (ctx, 10);

Parameters
  • ctx – context variable

  • eta – eta >= 0

Returns

None

void PGASetCrossoverSBXOncePerString(PGAContext *ctx, int val)

Compute random number for simulated binary crossover (SBX) polynomial distribution only once per string/individual.

Description

If set to PGA_TRUE all alleles will use the same value which means that the resulting string will point into the same direction as the vector between both parents. The default is PGA_FALSE indicating that a new random number is used for each string.

Example

PGAContext *ctx;

...
PGASetCrossoverSBXOncePerString (ctx, PGA_TRUE);

Parameters
  • ctx – context variable

  • val – flag indicating if random number is computed once per string

Returns

None

void PGASetCrossoverType(PGAContext *ctx, int crossover_type)

Specify the type of crossover to use.

Description

Valid choices are PGA_CROSSOVER_ONEPT, PGA_CROSSOVER_TWOPT, or PGA_CROSSOVER_UNIFORM, PGA_CROSSOVER_SBX, and PGA_CROSSOVER_EDGE for one-point, two-point, uniform, simulated binary (SBX), and edge crossover, respectively. The default is PGA_CROSSOVER_TWOPT. Edge crossover is only defined for integer genes and SBX is only defined for integer and real genes. See Crossover Constants for the constants and section Crossover in the user guide for details.

Example

Use uniform crossover when crossingover strings.

PGAContext *ctx;

...
PGASetCrossoverType (ctx, PGA_CROSSOVER_UNIFORM);

Parameters
  • ctx – context variable

  • crossover_type – symbolic constant to specify crossover type

Returns

None

void PGASetDEAuxFactor(PGAContext *ctx, double val)

Set the auxiliary factor K for Differential Evolution.

Description

The default for the aux factor \(K\) of Differential Evolution is \(0.5 * (F + 1)\) where \(F\) is the Differential Evolution scale factor, see PGASetDEScaleFactor().

Example

PGAContext *ctx;

...
PGASetDEAuxFactor (ctx, 0.75);

Parameters
  • ctx – context variable

  • val – the auxiliary factor

Returns

None

void PGASetDECrossoverProb(PGAContext *ctx, double val)

Set the crossover probability for Differential Evolution.

Description

The default for the Differential Evolution crossover probability is 0.9.

Example

PGAContext *ctx;

...
PGASetDECrossoverProb (ctx, 0.75);

Parameters
  • ctx – context variable

  • val – the crossover probability

Returns

None

void PGASetDECrossoverType(PGAContext *ctx, int val)

Set the crossover type for Differential Evolution.

Description

Differential Evolution supports the crossover types PGA_DE_CROSSOVER_BIN and PGA_DE_CROSSOVER_EXP, the default is PGA_DE_CROSSOVER_BIN. See Differential Evolution Crossover Constants for the constants and section Mutation of the user guide for details.

Example

PGAContext *ctx;

...
PGASetDECrossoverType (ctx, PGA_DE_CROSSOVER_EXP);

Parameters
  • ctx – context variable

  • val – the crossover type

Returns

None

void PGASetDEDither(PGAContext *ctx, double val)

Set the Differential Evolution dither range (+/-).

Description

By default dither is turned off (the value is 0 by default). Quite large amounts (on the order of 0.5) are recommended for some problems like digital filter design. See section Mutation in the user guide for details.

Example

PGAContext *ctx;

...
PGASetDEDither (ctx, 0.5);

Parameters
  • ctx – context variable

  • val – the dither range

Returns

None

void PGASetDEDitherPerIndividual(PGAContext *ctx, int val)

Set if Differential Evolution dither is per individual.

Description

If this is set to PGA_TRUE, then for Differential Evolution if the dither value is non-zero we produce a new random value to add to the scale factor \(F\) for each individual. Otherwise if the flag is not set (PGA_FALSE), then we produce a new value in each generation, the same value for all individuals.

Example

PGAContext *ctx;

...
PGASetDEDitherPerIndividual (ctx, PGA_TRUE);

Parameters
  • ctx – context variable

  • val – boolean flag

Returns

None

void PGASetDEJitter(PGAContext *ctx, double val)

Set the jitter for Differential Evolution.

Description

By default jitter is turned off (the value is 0 by default). Very small amounts (on the order of 0.001) have been recommended for some problems like digital filter design. See section Mutation in the user guide for details.

Example

PGAContext *ctx;

...
PGASetDEJitter (ctx, 0.001);

Parameters
  • ctx – context variable

  • val – the jitter for Differential Evolution

Returns

None

void PGASetDENumDiffs(PGAContext *ctx, int val)

Set the number of differences for Differential Evolution.

Description

Some variants of Differential Evolution can specify the number of differences that go into the new value of an allele. By default this number is 1.

Example

PGAContext *ctx;

...
PGASetDENumDiffs (ctx, 2);

Parameters
  • ctx – context variable

  • val – the number of differences

Returns

None

void PGASetDEProbabilityEO(PGAContext *ctx, double val)

Set the either-or probability of Differential Evolution.

Description

The default for this probability is 0.5, it is only used when the either-or variant of Differential Evolution has been selected by calling PGASetDEVariant() with parameter PGA_DE_VARIANT_EITHER_OR.

Example

PGAContext *ctx;

...
PGASetDEProbabilityEO (ctx, 0.75);

Parameters
  • ctx – context variable

  • val – the either-or probability

Returns

None

void PGASetDEScaleFactor(PGAContext *ctx, double val)

Set the scale factor F for Differential Evolution.

Description

The default for the scale factor \(F\) is 0.9. For details see section Mutation in the user guide.

Example

PGAContext *ctx;

...
PGASetDEScaleFactor (ctx, 0.75);

Parameters
  • ctx – context variable

  • val – the scale factor

Returns

None

void PGASetDEVariant(PGAContext *ctx, int variant)

Set the variant used for Differential Evolution.

Description

Only used if the mutation type is Differential Evolution PGA_MUTATION_DE. The possible variants are PGA_DE_VARIANT_RAND, PGA_DE_VARIANT_BEST, and PGA_DE_VARIANT_EITHER_OR. See Constants for Differential Evolution Variants for the constants and section Mutation in the user guide for details.

Example

PGAContext *ctx;

...
PGASetDEVariant (ctx, PGA_DE_VARIANT_BEST);

Parameters
  • ctx – context variable

  • variant – symbolic constant for variant

Returns

None

void PGASetEpsilonExponent(PGAContext *ctx, double e)

Configure the exponent of the term computing the epsilon value in each generation.

Example

PGAContext *ctx;

...
PGASetEpsilonExponent (ctx, 5);

Parameters
  • ctx – context variable

  • e – Exponent

Returns

None

void PGASetEpsilonGeneration(PGAContext *ctx, int gen)

Configure the generation until which constraints are relaxed via the Epsilon Contraint method.

Description

The default is 0 (no Epsilon Contraint method is used). The parameter gen must be below the value set with PGASetMaxGAIterValue().

Example

PGAContext *ctx;

...
PGASetEpsilonGeneration (ctx, 50);

Parameters
  • ctx – context variable

  • gen – Epsilon contraint generation

Returns

None

void PGASetEpsilonTheta(PGAContext *ctx, int theta)

Set the theta generation value that is used for initializing the epsilon constraint.

Description

The initial population is sorted by constraint violation and the individual with index theta is used for initializing the initial epsilon for the epsilon constraint method.

Example

PGAContext *ctx;

...
PGASetEpsilonTheta (ctx, n);

Parameters
  • ctx – context variable

  • theta – population index

Returns

None

void PGASetFitnessCmaxValue(PGAContext *ctx, double val)

Set value of the multiplier used by MinCmax fitness algorithm so that the worst string has a nonzero fitness.

Description

The default value is 1.01.

Example

PGAContext *ctx;

...
PGASetFitnessCmaxValue (ctx, 1.2);

Parameters
  • ctx – context variable

  • val – the value of the multiplier

Returns

None

void PGASetFitnessMinType(PGAContext *ctx, int fitness_type)

Set the type of algorithm used if a minimization problem is specified to determine how values are remapped for maximization.

Description

Valid choices are PGA_FITNESSMIN_RECIPROCAL and PGA_FITNESSMIN_CMAX to do the mapping using the reciprocal of the evaluation function, or by subtracting the worst evaluation function value from each evaluation function value, respectively. The default is PGA_FITNESSMIN_CMAX. See Constants for Fitness Minimization Strategies for the constants and section String Evaluation and Fitness in the user guide for details.

Example

PGAContext *ctx;

...
PGASetFitnessMinType (ctx, PGA_FITNESSMIN_CMAX);

Parameters
  • ctx – context variable

  • fitness_type – symbolic constant to specify fitness minimization type

Returns

None

void PGASetFitnessType(PGAContext *ctx, int fitness_type)

Set the type of fitness algorithm to use.

Description

Valid choices are PGA_FITNESS_RAW, PGA_FITNESS_NORMAL, or PGA_FITNESS_RANKING for raw fitness (the evaluation function value), linear normalization, or linear ranking, respectively. The default is PGA_FITNESS_RAW. See Constants for Fitness Types for the constants and section String Evaluation and Fitness in the user guide for details.

Example

PGAContext *ctx;

...
PGASetFitnessType (ctx, PGA_FITNESS_RANKING);

Parameters
  • ctx – context variable

  • fitness_type – symbolic constant to specify fitness type

Returns

None

void PGASetIntegerInitPermute(PGAContext *ctx, int min, int max)

Set a flag to tell the initialization routines to set each integer-valued gene to a random permutation of the values given by an upper and lower bound.

Description

The length of the interval must be the same as the string length. This is the default strategy for initializing integer-valued strings. The default interval is \([0,L-1]\) where \(L\) is the string length. No string initialization is done by this call.

Example

Set the initialization routines to set each gene to a random and unique value from the interval [500,599].

PGAContext *ctx;

...
PGASetIntegerInitPermute (ctx, 500, 599)}

Parameters
  • ctx – context variable

  • min – the lower bound of numbers used in the permutation

  • max – the upper bound of numbers used in the permutation

Returns

None

void PGASetIntegerInitRange(PGAContext *ctx, const int *min, const int *max)

Set a flag to tell the initialization routines to set each integer-valued gene to a value chosen randomly from the interval given by an upper and lower bound.

Example

Set the initialization routines to select a value for gene i uniformly randomly from the interval \([0,i]\). Assumes all strings are of the same length.

PGAContext *ctx;
int *low, *high, stringlen, i;

...
stringlen = PGAGetStringLength (ctx);
low  = malloc (stringlen * sizeof (int));
high = malloc (stringlen * sizeof (int));
for (i=0; i<stringlen; i++) {
    low  [i] = 0;
    high [i] = i;
}
PGASetIntegerInitRange (ctx, low, high);

Parameters
  • ctx – context variable

  • min – array of lower bounds that define the interval the gene is initialized from

  • max – array of upper bounds that define the interval the gene is initialized from

Returns

None

void PGASetMaxFitnessRank(PGAContext *ctx, double max)

The value of the parameter Max when using linear ranking for fitness determination.

Description

The default value is 1.2. The value must be from the interval \([1.0, 2.0]\). The fitness type must have been set to PGA_FITNESS_RANKING with PGASetFitnessType() for this function call to have any effect.

Example

PGAContext *ctx;

...
PGASetMaxFitnessRank (ctx, 1.1);

Parameters
  • ctx – context variable

  • max – the value of the parameter Max when using linear ranking

Returns

None

void PGASetMaxGAIterValue(PGAContext *ctx, int maxiter)

Specify the maximum number of iterations.

Description

The stopping rule PGA_STOP_MAXITER is the default stopping rule and is always in effect. The default value is 1000 iterations.

Example

PGAContext *ctx;

...
PGASetMaxGAIterValue (ctx, 5000);

Parameters
  • ctx – context variable

  • maxiter – the maximum number of GA iterations to run before stopping

Returns

None

void PGASetMaxNoChangeValue(PGAContext *ctx, int max_no_change)

Specify maximum number of iterations of no change in the evaluation function value of the best string before stopping.

Description

The default value is 100. The stopping rule PGA_STOP_NOCHANGE must have been set by PGASetStoppingRuleType() for this function call to have any effect.

Example

PGAContext *ctx;

...
PGASetMaxNoChangeValue (ctx, 100);

Parameters
  • ctx – context variable

  • max_no_change – the maximum number of GA iterations allowed with no change in the best evaluation function value

Returns

None

void PGASetMaxSimilarityValue(PGAContext *ctx, int max_similarity)

Specify the maximum percent of homogeneity of the population before stopping.

Description

The similarity measure is the same evaluation function value. The default value is that 95 percent of the population have the same evaluation function value. The stopping rule PGA_STOP_TOOSIMILAR must have been set by PGASetStoppingRuleType() for this function call to have any effect.

Example

PGAContext *ctx;

...
PGASetMaxSimilarityValue (ctx, 99);

Parameters
  • ctx – context variable

  • max_similarity – the maximum percent of the population that can share the same evaluation function value

Returns

None

void PGASetMixingType(PGAContext *ctx, int type)

Set strategy for combining mutation and crossover.

Example

Set the genetic algorithm to use mutation only.

PGAContext *ctx;

...
PGASetMixingType (ctx, PGA_MIX_MUTATE_ONLY);

Parameters
  • ctx – context variable

  • type – Type of Mutation/Crossover combination

Returns

None

void PGASetMultiObjPrecision(PGAContext *ctx, int prec)

Specify the precision in decimal places for printing evaluations of multi objective optimization.

Example

PGAContext *ctx;

...
PGASetMultiObjPrecision (ctx, 12);

Parameters
  • ctx – context variable

  • prec – the precision

Returns

None

void PGASetMutationBounceBackFlag(PGAContext *ctx, int val)

If this flag is set to true, then for Integer and Real strings whenever a gene is mutated, if it underflows (overflows) the lower (upper) bound it is reset to a random value between the old value and the violated bound.

Description

When this flag is set, all allele values remain within the range the strings were initialized on by bouncing values that violate the bound back from the boundary. If this flag is PGA_FALSE (the default), the alleles may take any values. See also PGASetMutationBoundedFlag().

Example

PGAContext *ctx;

...
PGASetMutationBounceBackFlag (ctx, PGA_TRUE);

Parameters
  • ctx – context variable

  • val – either PGA_TRUE or PGA_FALSE

Returns

None

void PGASetMutationBoundedFlag(PGAContext *ctx, int val)

If this flag is set to true, then for Integer and Real strings whenever a gene is mutated, if it underflows (overflows) the lower (upper) bound it is reset to the lower (upper) bound.

Description

When this is enabled, all allele values remain within the range the integer strings were initialized on. If this flag is PGA_FALSE (the default), the alleles may take any values.

Example

PGAContext *ctx;

...
PGASetMutationBoundedFlag (ctx, PGA_TRUE);

Parameters
  • ctx – context variable

  • val – flag to indicate if mutation is bounded

Returns

None

void PGASetMutationIntegerValue(PGAContext *ctx, int val)

Set multiplier to mutate data type integer strings with.

Description

The use of this value depends on the type of mutation being used. The default value is 1. See section Mutation of the user guide for more details.

Example

PGAContext *ctx;

...
PGASetMutationIntegerValue (ctx, 5);

Parameters
  • ctx – context variable

  • val – the mutation value to use for Integer mutation

Returns

None

void PGASetMutationPolyEta(PGAContext *ctx, double eta)

Set Eta for polynomial mutation.

Example

PGAContext *ctx;

...
PGASetMutationPolyEta (ctx, 200);

Parameters
  • ctx – context variable

  • eta – the polynomial mutation eta

Returns

None

void PGASetMutationPolyValue(PGAContext *ctx, double v)

Specify the constant for polynomial mutation.

Example

PGAContext *ctx;

...
PGASetMutationPolyValue (ctx, 2.5);

Parameters
  • ctx – context variable

  • v – the polynomial mutation constant

Returns

None

void PGASetMutationProb(PGAContext *ctx, double mutation_prob)

Specify the probability that a given allele will be mutated.

Description

If this is called without calling PGASetMutationType(), the default mutation type is PGA_MUTATION_CONSTANT. The default probability is the reciprocal of the string length.

Example

PGAContext *ctx;

...
PGASetMutationProb (ctx, 0.001);

Parameters
  • ctx – context variable

  • mutation_prob – the mutation probability

Returns

None

void PGASetMutationRealValue(PGAContext *ctx, double val)

Set multiplier to mutate strings of data type real with.

Description

The use of this value depends on the type of mutation being used. The default value is 0.1 unless the mutation type is PGA_MUTATION_CONSTANT in which case the default is 0.01. See section Mutation in the user guide for more details.

Example

PGAContext *ctx;

...
PGASetMutationRealValue (ctx, 50.0);

Parameters
  • ctx – context variable

  • val – the mutation value to use for Real mutation

Returns

None

void PGASetMutationType(PGAContext *ctx, int mutation_type)

Set type of mutation to use.

Description

Only effects integer- and real-valued strings. Binary-valued strings are always complemented. In character-valued strings, one alphabetic character is replaced with another chosen uniformly randomly. The alphabetic characters will be lower, upper, or mixed case depending on how the strings were initialized.

Valid choices are PGA_MUTATION_CONSTANT (Real/Integer), PGA_MUTATION_RANGE (Real/Integer), PGA_MUTATION_UNIFORM (Real), PGA_MUTATION_GAUSSIAN (Real), PGA_MUTATION_PERMUTE (Integer), PGA_MUTATION_DE (Real), and PGA_MUTATION_POLY (Real/Integer). The default for integer-valued strings conforms to how the strings were initialized. The default for real-valued strings is PGA_MUTATION_GAUSSIAN. See Constants for Mutation Types for the constants and section Mutation in the user guide for more details.

Example

PGAContext *ctx;

...
PGASetMutationType (ctx, PGA_MUTATION_UNIFORM);

Parameters
  • ctx – context variable

  • mutation_type – symbolic constant to specify the mutation type

Returns

None

void PGASetNAMWindowSize(PGAContext *ctx, int wsize)

Set window size for negative assortative mating (NAM).

Description

On selection select first individual as configured, for the second individual draw wsize individuals and select the one that has the largest genetic difference to the first individual. The default window size 1 doesn’t use NAM. See description [FR01].

Example

PGAContext *ctx,

...
PGASetNAMWindowSize (ctx, 3);

Parameters
  • ctx – context variable

  • wsize – window size

Returns

None

void PGASetNoDuplicatesFlag(PGAContext *ctx, int no_dup)

A boolean flag to indicate if duplicate strings are allowed in the population.

Description

Valid choices are PGA_TRUE and PGA_FALSE. The default is PGA_FALSE allow duplicates.

Example

Set the NoDuplicates flag to require that all strings are unique.

PGAContext *ctx;

...
PGASetNoDuplicatesFlag (ctx, PGA_TRUE);

Parameters
  • ctx – context variable

  • no_dup – PGA_TRUE or PGA_FALSE

Returns

None

void PGASetNumAuxEval(PGAContext *ctx, int n)

Initialize the number of auxiliary evaluations.

Example

PGAContext *ctx;

...
PGASetNumAuxEval (ctx, 5);

Parameters
  • ctx – context variable

  • n – Number of auxiliary evaluations

Returns

None

void PGASetNumConstraint(PGAContext *ctx, int n)

Initialize the number of constraints.

Description

The maximum number of constraints (and the default) is the number of Auxiliary evaluations, see PGASetNumAuxEval().

Example

PGAContext *ctx;

...
PGASetNumConstraint (ctx, 5);

Parameters
  • ctx – context variable

  • n – Number of constraints

Returns

None

void PGASetNumReplaceValue(PGAContext *ctx, int pop_replace)

Specify the number of new strings to create each generation.

Description

The default is ten percent of the population size.

Example

PGAContext *ctx;

...
PGASetNumReplaceValue (ctx, 35);

Parameters
  • ctx – context variable

  • pop_replace – the number of population members to create each generation

Returns

None

void PGASetOutputFile(PGAContext *ctx, const char *name)

Set output file name for printing statistics etc.

Description

Note that the file is not immediately opened, instead it is later opened in the rank 0 individual.

Example

PGAContext *ctx;
char *name = "output.file";

...
PGASetOutputFile (ctx, name);

Parameters
  • ctx – context variable

  • name – output filename

Returns

None

void PGASetPTournamentProb(PGAContext *ctx, double ptournament_prob)

Specify the probability that the string that wins a binary tournament will be selected.

Description

This function will have no effect unless PGA_SELECT_PTOURNAMENT was specified as the type of selection to use with PGASetSelectType(). The default value is 0.6.

Example

PGAContext *ctx;

...
PGASetPTournamentProb (ctx, 0.8);

Parameters
  • ctx – context variable

  • ptournament_prob – the probability of selecting the better string

Returns

None

void PGASetPopReplaceType(PGAContext *ctx, int pop_replace)

Choose method of replacing strings in the new population.

Description

Valid choices are PGA_POPREPL_BEST, PGA_POPREPL_RANDOM_NOREP, or PGA_POPREPL_RANDOM_REP for copying the best strings, or random string, with or without replacement, respectively, from the old population into the new population. Additional replacement types are PGA_POPREPL_RTR for restricted tournament replacement, PGA_POPREPL_PAIRWISE_BEST for pairwise comparison of each individual in the old/new population, and PGA_POPREPL_NSGA_II and PGA_POPREPL_NSGA_III for multiobjective optimization using the Nondominated Sorting Genetic Algorithm (NSGA-II or NSGA-III). The default is PGA_POPREPL_BEST. See Constants for Population Replacement Strategies for the constants and section Population Replacement in the user guide for details.

Example

PGAContext *ctx;

...
PGASetPopReplaceType (ctx, PGA_POPREPL_RANDOM_NOREP);

Parameters
  • ctx – context variable

  • pop_replace – symbolic constant to specify the population replacement strategy

Returns

None

void PGASetPopSize(PGAContext *ctx, int popsize)

Specify the size of the genetic algorithm population.

Description

The default population size is 100, unless reference directions or reference points have been specified for NSGA-III replacement in which case the default is the number of reference points plus the number of reference directions.

Example

PGAContext *ctx;

...
PGASetPopSize (ctx, 200);

Parameters
  • ctx – context variable

  • popsize – the genetic algorithm population size to use

Returns

None

void PGASetPrintFrequencyValue(PGAContext *ctx, int print_freq)

Specify the frequency with which genetic algorithm statistics are reported.

Description

The default is every 10 GA iterations. Used only if PGARun() is used to run the GA.

Example

PGAContext *ctx;

...
PGASetPrintFrequencyValue (ctx, 1);

Parameters
  • ctx – context variable

  • print_freq – print frequency (in generations)

Returns

None

void PGASetPrintOptions(PGAContext *ctx, int option)

Set flags to indicate what GA statistics should be printed whenever output is printed.

Description

May be called more than once to specify different report options. Valid choices are PGA_REPORT_AVERAGE, PGA_REPORT_OFFLINE, PGA_REPORT_ONLINE, PGA_REPORT_WORST, PGA_REPORT_GENE_DISTANCE, and PGA_REPORT_STRING to specify offline analysis, online analysis, the worst string in the population, the mean genetic distance of the population, and the actual allele values of the best string. The best string is always printed. Note that reporting of mean genetic distance is quadratic in the population size and probably should be used only when trying to diagnose premature convergence problems. See Constants for Reporting for the constants and section Report Options in the user guide for details.

Example

PGAContext *ctx;

...
PGASetPrintOptions (ctx, PGA_REPORT_WORST);

Parameters
  • ctx – context variable

  • option – symbolic constant to specify a print option

Returns

None

void PGASetRTRWindowSize(PGAContext *ctx, int windowsize)

Set window size used for restricted tournament replacement.

Description

This function will have no effect unless PGA_POPREPL_RTR was specified as the population replacement strategy with PGASetPopReplaceType(). The window size must be smaller than the population size. The default is \(\min (n, N/20)\) where \(n\) is the string length and \(N\) is the population size.

Example

PGAContext *ctx;

...
PGASetRTRWindowSize (ctx, windowsize);

Parameters
  • ctx – context variable

  • windowsize – size of the window for restricted tournament replacement

Returns

None

void PGASetRandomInitFlag(PGAContext *ctx, int flag)

A boolean flag to indicate whether to randomly initialize alleles.

Description

Legal values are PGA_TRUE and PGA_FALSE. Default is PGA_TRUE: randomly initialize alleles.

Example

Set the initialization routine to initialize all alleles to zero:

PGAContext *ctx;

...
PGASetRandomInitFlag (ctx,PGA_FALSE);

Parameters
  • ctx – context variable

  • flag – indicates whether random initialization should be performed

Returns

None

void PGASetRandomSeed(PGAContext *ctx, int seed)

Set a seed for the random number generator.

Description

The default is to initialize the seed randomly (from the time). Specifying a seed explicitly allows for reproducibility of runs.

Example

PGAContext *ctx;

...
PGASetRandomSeed (ctx, 1);

Parameters
  • ctx – context variable

  • seed – seed for the random number generator

Returns

None

void PGASetRandomizeSelect(PGAContext *ctx, int v)

Specify if during PGASelect the chosen individuals should be randomized again.

Description

All selection schemes except PGA_SELECT_SUS already return the individuals in randomized order, previously this was randomized again. With this method you can re-enable the randomization for selection schemes other than PGA_SELECT_SUS (for which a randomization step is always performed).

Example

PGAContext *ctx;

...
PGASetRandomizeSelect (ctx, PGA_TRUE);

Parameters
  • ctx – context variable

  • v – flag, true if randomized again

Returns

None

void PGASetRealInitFraction(PGAContext *ctx, double *median, double *frac)

Set the upper and lower bounds for randomly initializing real-valued genes.

Description

For each gene these bounds define an interval from which the initial allele value is selected uniformly randomly. With this routine the user specifies a median value and a fraction of the median for each allele.

Example

Set the initialization routines to select a value for each real-valued gene i uniformly randomly from the interval \([i-v,i+v]\), where \(v = i/2\). Assumes all strings are the same length.

PGAContext *ctx;
double *median, *frac;
int i, stringlen;

...
stringlen = PGAGetStringLength (ctx);
median = malloc (stringlen * sizeof(double));
frac   = malloc (stringlen * sizeof(double));
for (i=0; i<stringlen; i++) {
   median [i] = (double) i;
   frac   [i] = 0.5;
}
PGASetRealInitPercent (ctx, median, frac);

Parameters
  • ctx – context variable

  • median – an array containing the mean value of the interval

  • frac – an array containing the fraction of median to add and subtract to/from the median to define the interval

Returns

None

void PGASetRealInitRange(PGAContext *ctx, const double *min, const double *max)

Set the upper and lower bounds for randomly initializing real-valued genes.

Description

For each gene these bounds define an interval from which the initial allele value is selected uniformly randomly. The user specifies two arrays containing lower and upper bound for each gene to define the interval. This is the default strategy for initializing real-valued strings. The default interval is \([0,1.0]\) for each gene.

Example

Set the initialization routines to select a value for each real-valued gene \(i\) uniformly randomly from the interval \([-10.,i]\) Assumes all strings are of the same length.

PGAContext *ctx;
double *low, *high;
int i, stringlen;

...
stringlen = PGAGetStringLength (ctx);
low  = malloc (stringlen * sizeof(double));
high = malloc (stringlen * sizeof(double));
for (i=0; i<stringlen; i++) {
   low  [i] = -10.0;
   high [i] = i;
}
PGASetRealInitRange (ctx, low, high);

Parameters
  • ctx – context variable

  • min – array containing the lower bound of the interval for each gene

  • max – array containing the upper bound of the interval for each gene

Returns

None

void PGASetReferenceDirections(PGAContext *ctx, size_t ndirs, void *dirs, int npart, double scale)

Set reference directions for NSGA-III.

Description

A direction is a point in objective space and can be seen as a vector from the origin to that point. During optimization the reference directions are mapped to the reference hyperplane and a scaled Das/Dennis hyperplane is constructed around that point. Each direction consists of dimension double variables.

Example

Asume 3 dimensions, i.e. 3 evaluation functions

PGAContext *ctx;
double dirs [][3] = {{1, 2, 3}, {4, 5, 6}};
...
int dim = PGAGetNumAuxEval (ctx) - PGAGetNumConstraint (ctx) + 1;

...
PGASetReferenceDirections (ctx, 2, dirs, 5, 0.1);

Parameters
  • ctx – context variable

  • ndirs – Number of directions

  • dirs – Pointer to directions

  • npart – Number of Das / Dennis partitions

  • scale – Scale factor for constructed Das / Dennis points, must be 0 < scale <= 1 but will typically be < 0.5

Returns

None

void PGASetReferencePoints(PGAContext *ctx, size_t npoints, void *points)

Set reference points on reference hyperplane for NSGA-III.

Example

PGAContext *ctx;
...
int dim = PGAGetNumAuxEval (ctx) - PGAGetNumConstraint (ctx) + 1;
void *p = NULL;
int np  = 0;

...
np = LIN_dasdennis (dim, 3, &p, 0, 1, NULL);
PGASetReferencePoints (ctx, np, p);

Parameters
  • ctx – context variable

  • npoints – Number of points

  • points – Pointer to points

Returns

None

void PGASetRestartAlleleChangeProb(PGAContext *ctx, double prob)

Specify the probability with which an allele will be mutated during a restart.

Description

By default the change probability for allele mutations during restart is 0.5.

Example

PGAContext *ctx;

...
PGASetRestartAlleleChangeProb (ctx, 0.7);

Parameters
  • ctx – context variable

  • prob – probability of mutation

Returns

None

void PGASetRestartFlag(PGAContext *ctx, int val)

Specify whether the algorithm should employ the restart operator.

Description

By default no restart is performed.

Example

PGAContext *ctx;

...
PGASetRestartFlag (ctx, PGA_TRUE);

Parameters
  • ctx – context variable

  • val – boolean variable

Returns

None

void PGASetRestartFrequencyValue(PGAContext *ctx, int numiter)

Specify the number of iterations of no change in the best string after which the algorithm should restart.

Description

By default no restarts are performed, see PGASetRestartFlag(). If restarts are performed, the default is after 50 iterations of no change.

Example

PGAContext *ctx;

...
PGASetRestartFrequencyValue (ctx, 100);

Parameters
  • ctx – context variable

  • numiter – number of changeless iterations

Returns

None

void PGASetSelectType(PGAContext *ctx, int select_type)

Specify the type of selection to use.

Description

Valid choices are PGA_SELECT_PROPORTIONAL, PGA_SELECT_SUS, PGA_SELECT_TOURNAMENT, PGA_SELECT_PTOURNAMENT, PGA_SELECT_TRUNCATION, and PGA_SELECT_LINEAR for proportional, stochastic universal selection, tournament, probabilistic tournament selection, truncation selection and linear selection, respectively. The default is PGA_SELECT_TOURNAMENT. See Constants for Selection Types for the constants and section Selection in the user guide for details.

Example

PGAContext *ctx;

...
PGASetSelectType (ctx, PGA_SELECT_SUS);

Parameters
  • ctx – context variable

  • select_type – symbolic constant to specify selection type

Returns

None

void PGASetStoppingRuleType(PGAContext *ctx, int stoprule)

Specify a stopping criterion.

Description

If called more than once the different stopping criterion are ORed together. Valid choices are PGA_STOP_MAXITER, PGA_STOP_TOOSIMILAR, or PGA_STOP_NOCHANGE to specify iteration limit reached, population too similar, or no change in the best solution found in a given number of iterations, respectively. The default is to stop when a maximum iteration limit is reached (by default, 1000 iterations). The constants can be found in Constants for Stopping Conditions and more details are in section Stopping Criteria of the user guide.

Example

PGAContext *ctx;

...
PGASetStoppingRuleType (ctx, PGA_STOP_TOOSIMILAR);

Parameters
  • ctx – context variable

  • stoprule – symbolic constant to specify stopping rule

Returns

None

void PGASetSumConstraintsFlag(PGAContext *ctx, int n)

Configure if constraints are summed for minimization or use nondominated sorting for optimization.

Description

This only has an effect if the NSGA-II or NSGA-III replacement scheme is configured. In that case, using nondominated sorting for constraint optimization can be turned on by this option. By default constraints are summed and the sum in minimized. This is also done if no NSGA replacement scheme is in use. If summing is disabled by setting this configuration to PGA_FALSE, constraints are minimized using nondominated sorting. Note that nondominated sorting for constrains may not work very well on many problems.

Example

PGAContext *ctx;

...
PGASetSumConstraintsFlag (ctx, PGA_FALSE);

Parameters
  • ctx – context variable

  • n – PGA_TRUE or PGA_FALSE

Returns

None

void PGASetTournamentSize(PGAContext *ctx, double tournament_size)

Specify the number of participants in a non-probabilistic Tournament.

Description

This function will have no effect unless PGA_SELECT_TOURNAMENT was specified as the type of selection to use with PGASetSelectType(). The default value is 2.

Example

PGAContext *ctx;

...
PGASetTournamentSize (ctx, 3);

Parameters
  • ctx – context variable

  • tournament_size – the size of the tournament

Returns

None

void PGASetTournamentWithReplacement(PGAContext *ctx, int v)

Specify if tournament is with or without replacement.

Description

This function will have no effect unless PGA_SELECT_TOURNAMENT was specified as the type of selection to use with PGASetSelectType(). The default value is PGA_TRUE indicating tournament with replacement.

Example

PGAContext *ctx;

...
PGASetTournamentWithReplacement (ctx, PGA_FALSE);

Parameters
  • ctx – context variable

  • v – flag indicating if replacement is used

Returns

None

void PGASetTruncationProportion(PGAContext *ctx, double proportion)

Specify the proportion of selected individuals for truncation selection.

Description

This function will have no effect unless PGA_SELECT_TRUNCATION was specified as the type of selection to use with PGASetSelectType(). The default value is 0.5.

Example

PGAContext *ctx;

...
PGASetTruncationProportion (ctx, 0.7);

Parameters
  • ctx – context variable

  • proportion – The value, 0 < proportion <= 1

Returns

None

void PGASetUniformCrossoverProb(PGAContext *ctx, double p)

Set probability used in uniform crossover to specify that an allele value value be selected from a particular parent.

Description

The default is 0.6. The crossover type must have been set to PGA_CROSSOVER_UNIFORM with PGASetCrossoverType() for this function call to have any effect.

Example

PGAContext *ctx;

...
PGASetUniformCrossoverProb (ctx, 0.9);

Parameters
  • ctx – context variable

  • p – the crossover probability

Returns

None

void PGASetUserFunction(PGAContext *ctx, int constant, void *f)

Specify the name of a user-written function to provide a specific GA capability (e.g., crossover, mutation, etc.).

Description

This function must be used when using a non-native datatype and must be called once for each of:

It may be called when using a native datatype to replace the built-in functions PGAPack has for that datatype (For example, if the Integer data type is used for a traveling salesperson problem, the user may want to provide their own custom crossover operator). See Constants for User Functions for the constants and chapters Custom Usage: Native Data Types and Custom Usage: New Data Types in the user guide and the examples in the examples directory for more details.

Example

void MyStringInit (PGAContext *, void *);
PGAContext *ctx;

...
PGASetUserFunction (ctx, PGA_USERFUNCTION_INITSTRING, MyStringInit);

Parameters
  • ctx – context variable

  • constant – symbolic constant of the user function to set

  • f – name of the function to use

Returns

None

Standard API

group standard-api

The standard API.

Functions

double INDGetAuxTotal(PGAIndividual *ind)

Compute total value over all constraint violations.

Description

This returns the sum of all positive individual aux evaluations that are used for constraints. The semantics is a total value of all constraint violations.

Example

PGAIndividual *ind = PGAGetIndividual (ctx, p, PGA_OLDPOP);
double result;

...
result = INDGetAuxTotal (ind);

Parameters
  • ind – Pointer to Individual

Returns

Computed or cached total value over all constraint violations

int LIN_dasdennis(int dim, int npart, void *result, int nexist, double scale, double *dir)

Allocate memory and compute Das & Dennis points.

Description

It will re-alloc the exiting array pointer pointed to by result (this must be a NULL pointer if no pre-existing points are given) and return the new number of points. Note that if there are no pre-existing points, the pointer pointed to by result must be NULL and nexist must be 0. Optionally the points can be scaled (with 0 < scale <= 1) and shifted in the direction of a given point back onto the reference hyperplane. This is not done if dir == NULL or scale == 1. A previously allocated result will be de-allocated in case of error.

Parameters
  • dim – dimension

  • npart – Number of partitions

  • result – List of existing points to extend

  • nexist – Number of existing points

  • scale – Scaling factor

  • dir – Direction vector

Returns

Number of points allocated, -1 on error

int PGACheckStoppingConditions(PGAContext *ctx)

Return boolean to indicate if the configured PGAPack termination conditions have been met.

Description

The default termination conditions are given in Constants for Stopping Conditions and more details are found in section Stopping Criteria of the user guide.

Example

Useful in a user-defined function that is registered as a stopping condition function. We can use this to keep the builtin stopping conditions in addition to a user-defined condition.

int StopCond (PGAContext *ctx)
{
    if (my_stop_check (ctx)) {
        return PGA_TRUE;
    }
    return PGACheckStoppingConditions (ctx);
}

Parameters
  • ctx – context variable

Returns

return true if at least one of the termination conditions has been met

PGAContext *PGACreate(int *argc, char **argv, int datatype, int len, int maxormin)

Create an uninitialized context variable.

Description

The Fortran version of this function call contains only the last three arguments.

The datatype must be one of PGA_DATATYPE_BINARY, PGA_DATATYPE_CHARACTER, PGA_DATATYPE_INTEGER, PGA_DATATYPE_REAL, or PGA_DATATYPE_USER to specify binary-valued, character-valued, integer-valued, real-valued, or a user-defined datatype, respectively. See Constants for Datatypes for the constants and types.

The maxormin parameter must be one of PGA_MAXIMIZE or PGA_MINIMIZE for maximization or minimization, respectively. See Constants for Optimization Direction for the constants.

Example

In C:

void main (int argc, char **argv) {
    PGAContext *ctx;

    ctx = PGACreate (&argc, argv, PGA_DATATYPE_BINARY, 100, PGA_MAXIMIZE);
    //  Set options here
    PGASetUp (ctx);
    //  Run the GA here
    PGADestroy (ctx);
}

In Fortran:

        integer ctx

        ctx = PGACreate(PGA_DATATYPE_BINARY, 100, PGA_MAXIMIZE)
c       Set options here
        call PGASetUp(ctx)
c       Run the GA here
        call PGADestroy(ctx)
        stop
        end

Parameters
  • argc – Address of the count of the number of command line arguments

  • argv – Array of command line arguments

  • datatype – The data type used for the strings

  • len – The string length (number of genes)

  • maxormin – The direction of optimization.

Returns

A pointer to the context variable

void PGADestroy(PGAContext *ctx)

Deallocate memory for this instance of PGAPack, if this context initialized MPI, finalize MPI as well.

Example

PGAContext *ctx;

...
PGADestroy (ctx);

Parameters
  • ctx – context variable

Returns

None

double PGAIntegerEuclidianDistance(PGAContext *ctx, int p1, int pop1, int p2, int pop2)

Compute genetic distance of two strings.

Description

This uses the Euclidian distance metric, the square-root of the sum of all squared differences of each allele. It can be used to override the default integer genetic distance function (which uses a manhattan distance metric) using PGASetUserFunction() with the PGA_USERFUNCTION_GEN_DISTANCE setting.

Example

Override genetic distance function:

PGAContext *ctx;

...
assert (PGAGetDataType (ctx) == PGA_DATATYPE_INTEGER);
PGASetUserFunction
 (ctx, PGA_USERFUNCTION_GEN_DISTANCE, PGAIntegerEuclidianDistance);

Parameters
  • ctx – context variable

  • p1 – first string index

  • pop1 – symbolic constant of the population the first string is in

  • p2 – second string index

  • pop2 – symbolic constant of the population the second string is in

Returns

genetic euclidian distance of the two strings

void PGAIntegerSetFixedEdges(PGAContext *ctx, size_t n, PGAInteger (*edge)[2], int symmetric)

Set edges that have to be present.

Description

This is used only in Edge Crossover. Note: The edges data structure is copied and must be freed by the caller. It is admissible that the edges data is in automatic variables allocated on the stack.

Example

Set edges (0, 213) and (7, 11) as fixed edges.

PGAContext *ctx;
PGAInteger edge[][2] = {(PGAInteger []){0, 213}, (PGAInteger []){7, 11}};
int  n = sizeof (edge) / (2 * sizeof (PGAInteger));

...
PGAIntegerSetFixedEdges (ctx, n, edge, PGA_TRUE);

Parameters
  • ctx – context variable

  • n – Number of edges

  • edge – Pointer to edges, each edge consists of two indices

  • symmetric – Flag that indicates if edges are allowed in reverse direction

Returns

None

double PGARealEuclidianDistance(PGAContext *ctx, int p1, int pop1, int p2, int pop2)

Compute genetic difference of two strings.

Description

This uses the Euclidian distance metric, the square-root of the sum of all squared differences of each allele. It can be used to override the default real genetic distance function (which uses a manhattan distance metric) using PGASetUserFunction() with the PGA_USERFUNCTION_GEN_DISTANCE setting.

Example

Override genetic distance function:

PGAContext *ctx;

...
assert (PGAGetDataType (ctx) == PGA_DATATYPE_REAL);
PGASetUserFunction
 (ctx, PGA_USERFUNCTION_GEN_DISTANCE, PGARealEuclidianDistance);

Parameters
  • ctx – context variable

  • p1 – first string index

  • pop1 – symbolic constant of the population the first string is in

  • p2 – second string index

  • pop2 – symbolic constant of the population the second string is in

Returns

Genetic euclidian distance of the two strings

void PGARun(PGAContext *ctx, double (*evaluate)(PGAContext *c, int p, int pop, double*))

Highest level routine to execute the genetic algorithm.

Description

It is called after PGACreate() and PGASetup() have been called.

Example

PGAContext *ctx;
double f (PGAContext *ctx, int p, int pop, double *aux);

ctx = PGACreate (&argc, argv, PGA_DATATYPE_BINARY, 100, PGA_MAXIMIZE);
PGASetUp (ctx);
PGARun (ctx, f);
PGADestroy (ctx);

Parameters
  • ctx – context variable

  • evaluate – a pointer to the user’s evaluation function, which must have the calling sequence shown in the example

Returns

None

void PGASetUp(PGAContext *ctx)

Set all uninitialized variables to default values and initialize some internal arrays.

Description

Must be called after PGACreate() and before the GA is started.

Example

PGAContext *ctx;

PGACreate (ctx, ...);
//  Set options here
PGASetUp (ctx);

Parameters
  • ctx – context variable

Returns

Uninitialized values in the context variable are set to defaults, and set values are checked for legality

PGAHash PGAUtilHash(const void *data, size_t len, PGAHash hashv)

Hashing utility function.

Description

This is Bob Jenkins’ hash function as implemented in the uthash project. The last parameter is the previous hash (if hashing different pieces), use PGA_INITIAL_HASH for the first hash.

Parameters
  • data – pointer to data to hash

  • len – length of data

  • hashv – previous hash, use PGA_INITIAL_HASH if first

Returns

hash over data

Querying Parameters

group query

Functions to query PGA parameters.

Functions

double PGAGetAuxTotal(PGAContext *ctx, int p, int pop)

Compute total value over all constraint violations.

Description

This returns the sum of all positive individual aux evaluations that are used for constraints. The semantics is a total value of all constraint violations.

Example

PGAContext *ctx;
double result;

...
result = PGAGetAuxTotal (ctx, p, PGA_OLDPOP);

Parameters
  • ctx – context variable

  • p – index of individual

  • pop – population

Returns

Computed or cached total value over all constraint violations

int PGAGetBestIndex(PGAContext *ctx, int popidx)

Return the index of the string with the best evaluation function value in population pop.

Description

Note that in the presence of multiple evaluations, this will return

  • If all strings violate constraints the one with the least constraint violation

  • In case there exist strings without constraint violations one randomly chosen from rank 0.

Example

PGAContext *ctx;
int best;

...
best = PGAGetBestIndex (ctx, PGA_OLDPOP);

Parameters
  • ctx – context variable

  • popidx – symbolic constant of the population to find the best string in

Returns

Index of the string with the best evaluation function value

double PGAGetBestReport(PGAContext *ctx, int pop, int idx)

Return the best evaluation value in population pop for the given evaluation index.

Description

The evaluation function index must be 0 < idx <= NumAuxEval. So for single evaluation only the index 0 is allowed and the return is the evaluation as from PGAGetBestIndex(). Note that this accesses the pre-computed statistics and therefore only PGA_OLDPOP is allowed for the population constant.

Example

PGAContext *ctx;
double best;

...
best = PGAGetBestReport (ctx, PGA_OLDPOP, 1);

Parameters
  • ctx – context variable

  • pop – symbolic constant of the population to find the best eval, only PGA_OLDPOP is allowed

  • idx – Index of the evaluation function, 0 for the one return by your evaluation function 1 .. NumAuxEval for the auxiliary evaluations

Returns

Index of the string with the best evaluation function value

int PGAGetBestReportIndex(PGAContext *ctx, int pop, int idx)

Return the index of the string with the best evaluation function value in population pop for the given evaluation index.

Description

The evaluation function index must be 0 < idx <= NumAuxEval. So for single evaluation only the index 0 is allowed and the return is the same as from PGAGetBestIndex(). Note that this accesses the pre-computed statistics and therefore only PGA_OLDPOP is allowed for the population constant.

Example

PGAContext *ctx;
int best;

...
best = PGAGetBestReportIndex (ctx, PGA_OLDPOP, 1);

Parameters
  • ctx – context variable

  • pop – symbolic constant of the population to find the best string in

  • idx – Index of the evaluation function, 0 for the one return by your evaluation function 1 .. NumAuxEval for the auxiliary evaluations

Returns

Index of the string with the best evaluation function value

double PGAGetBinaryInitProb(PGAContext *ctx)

Return the probability that an allele will be randomly initialized to “1” for data type binary.

Description

This is used during string creation of a PGA_DATATYPE_BINARY string.

Example

PGAContext *ctx;
double prob;

...
prob = PGAGetBinaryInitProb (ctx);

Parameters
  • ctx – context variable

Returns

The probability that a bit will be randomly initialized to one

MPI_Comm PGAGetCommunicator(PGAContext *ctx)

Returns the default communicator used when PGARun is called.

Example

MPI_Comm comm;
PGAContext *ctx,
double f (PGAContext *ctx, int p, int pop, double *aux);

ctx = PGACreate (&argc, argv, PGA_DATATYPE_BINARY, 100, PGA_MAXIMIZE);
PGASetUp (ctx);
comm = PGAGetCommunicator (ctx);

Parameters
  • ctx – context variable

Returns

The default communicator

int PGAGetCrossoverBounceBackFlag(PGAContext *ctx)

Return boolean to indicate whether crossed over strings are bounced back when exceeding the bounds.

Description

Return PGA_TRUE if restricted to the given range by bouncing out-of-range values back from the boundary, otherwise PGA_FALSE.

Example

PGAContext *ctx;
int val;

...
val = PGAGetCrossoverBounceBackFlag (ctx);

Parameters
  • ctx – context variable

Returns

flag indicating whether out-of-range values are bounced back

int PGAGetCrossoverBoundedFlag(PGAContext *ctx)

Return boolean value to indicate whether crossed over strings remain in the range specified.

Description

Return PGA_TRUE if restricted to the given range, otherwise PGA_FALSE.

Example

PGAContext *ctx;
int val;

...
val = PGAGetCrossoverBoundedFlag (ctx);

Parameters
  • ctx – context variable

Returns

boolean value indicating if strings remain in range

double PGAGetCrossoverProb(PGAContext *ctx)

Return the crossover probability.

Example

PGAContext *ctx;
double pc;

...
pc = PGAGetCrossoverProb (ctx);

Parameters
  • ctx – context variable

Returns

The crossover probability

double PGAGetCrossoverSBXEta(PGAContext *ctx)

Return simulated binary crossover (SBX) eta value.

Example

PGAContext *ctx;
double eta;

...
eta = PGAGetCrossoverSBXEta (ctx);

Parameters
  • ctx – context variable

Returns

The SBX eta value

int PGAGetCrossoverSBXOncePerString(PGAContext *ctx)

Return simulated binary crossover (SBX) setting if random number for SBX polynomial distribution is computed once per string.

Example

PGAContext *ctx;
int r;

...
r = PGAGetCrossoverSBXOncePerString (ctx);

Parameters
  • ctx – context variable

Returns

The SBX once-per-string value

int PGAGetCrossoverType(PGAContext *ctx)

Return the type of crossover selected.

Example

PGAContext *ctx;
int crosstype;

...
crosstype = PGAGetCrossoverType (ctx);
switch (crosstype) {
case PGA_CROSSOVER_ONEPT:
    printf ("Crossover Type = PGA_CROSSOVER_ONEPT\n");
    break;
case PGA_CROSSOVER_TWOPT:
    printf ("Crossover Type = PGA_CROSSOVER_TWOPT\n");
    break;
case PGA_CROSSOVER_UNIFORM:
    printf ("Crossover Type = PGA_CROSSOVER_UNIFORM\n");
    break;
case PGA_CROSSOVER_SBX:
    printf ("Crossover Type = PGA_CROSSOVER_SBX\n");
    break;
case PGA_CROSSOVER_EDGE:
    printf ("Crossover Type = PGA_CROSSOVER_EDGE\n");
    break;
}

Parameters
  • ctx – context variable

Returns

Return the integer corresponding to the symbolic constant used to specify the crossover type.

double PGAGetDEAuxFactor(PGAContext *ctx)

Return the value of the auxiliary factor K for Differential Evolution.

Example

PGAContext *ctx;
double val;

...
val = PGAGetDEAuxFactor (ctx);

Parameters
  • ctx – context variable

Returns

The value of the auxiliary factor

double PGAGetDECrossoverProb(PGAContext *ctx)

Return the crossover probability for Differential Evolution.

Example

PGAContext *ctx;
double val;

...
val = PGAGetDECrossoverProb (ctx);

Parameters
  • ctx – context variable

Returns

The value of the Differential Evolution crossover probability

int PGAGetDECrossoverType(PGAContext *ctx)

Return the Differential Evolution crossover type.

Example

PGAContext *ctx;
int val;

...
val = PGAGetDECrossoverType (ctx);

Parameters
  • ctx – context variable

Returns

The value of the Differential Evolution crossover type

double PGAGetDEDither(PGAContext *ctx)

Return the Differential Evolution dither value.

Example

PGAContext *ctx;
double val;

...
val = PGAGetDEDither (ctx);

Parameters
  • ctx – context variable

Returns

The value of the Differential Evolution dither

int PGAGetDEDitherPerIndividual(PGAContext *ctx)

Return boolean flag to indicate whether the dither is applied anew for each individual or if the value is re-used for all individuals in one generation.

Example

PGAContext *ctx;
int val;

...
val = PGAGetDEDitherPerIndividual (ctx);

Parameters
  • ctx – context variable

Returns

flag to indicate if dither is applied for each individual

double PGAGetDEJitter(PGAContext *ctx)

Return the jitter for Differential Evolution.

Example

PGAContext *ctx;
double val;

...
val = PGAGetDEJitter (ctx);

Parameters
  • ctx – context variable

Returns

The value of the Differential Evolution jitter

int PGAGetDENumDiffs(PGAContext *ctx)

Return the number of differences for Differential Evolution.

Example

PGAContext *ctx;
int val;

...
val = PGAGetDENumDiffs (ctx);

Parameters
  • ctx – context variable

Returns

The value of the Differential Evolution number of differences

double PGAGetDEProbabilityEO(PGAContext *ctx)

Return the probability of the either-or variant of Differential Evolution.

Example

PGAContext *ctx;
double val;

...
val = PGAGetDEProbabilityEO (ctx);

Parameters
  • ctx – context variable

Returns

The value of the Differential Evolution EO-Probability

double PGAGetDEScaleFactor(PGAContext *ctx)

Return the value of the scale factor F for Differential Evolution.

Example

PGAContext *ctx;
double val;

...
val = PGAGetDEScaleFactor (ctx);

Parameters
  • ctx – context variable

Returns

The value of the scale factor

int PGAGetDEVariant(PGAContext *ctx)

Return the variant of Differential Evolution.

Example

PGAContext *ctx;
int variant;

...
variant = PGAGetDEVariant (ctx);
switch (variant) {
case PGA_DE_VARIANT_RAND:
    printf ("DE Variant = PGA_DE_VARIANT_RAND\n");
    break;
case PGA_DE_VARIANT_BEST:
    printf ("DE Variant = PGA_DE_VARIANT_BEST\n");
    break;
case PGA_DE_VARIANT_EITHER_OR:
    printf ("DE Variant = PGA_DE_VARIANT_EITHER_OR\n");
    break;
}

Parameters
  • ctx – context variable

Returns

Returns the integer corresponding to the symbolic constant used to specify the variant of differential evolution

int PGAGetDataType(PGAContext *ctx)

Return the data type used by the given context.

Example

PGAContext *ctx;
int datatype;

...
datatype = PGAGetDataType (ctx);
switch (datatype) {
case PGA_DATATYPE_BINARY:
    printf ("Data Type = PGA_DATATYPE_BINARY\n");
    break;
case PGA_DATATYPE_CHARACTER:
    printf ("Data Type = PGA_DATATYPE_CHARACTER\n");
    break;
case PGA_DATATYPE_INTEGER:
    printf ("Data Type = PGA_DATATYPE_INTEGER\n");
    break;
case PGA_DATATYPE_REAL:
    printf ("Data Type = PGA_DATATYPE_REAL\n");
    break;
case PGA_DATATYPE_USER:
    printf ("Data Type = PGA_DATATYPE_USER\n");
    break;
}

Parameters
  • ctx – context variable

Returns

The integer corresponding to the symbolic constant used to specify the data type

double PGAGetEpsilonExponent(PGAContext *ctx)

Get the exponent used for epsilon constraints.

Example

PGAContext *ctx;
double e;

...
e = PGAGetEpsilonExponent (ctx);

Parameters
  • ctx – context variable

Returns

The epsilon exponent

int PGAGetEpsilonGeneration(PGAContext *ctx)

Get value of the generation until which constraints are relaxed via the Epsilon Contraint method.

Example

PGAContext *ctx;
int n;

...
n = PGAGetEpsilonGeneration (ctx);

Parameters
  • ctx – context variable

Returns

The epsilon generation

int PGAGetEpsilonTheta(PGAContext *ctx)

Query the population index for initializing epsilon for the epsilon constraint method.

Example

PGAContext *ctx;
int n;

...
n = PGAGetEpsilonTheta (ctx);

Parameters
  • ctx – context variable

Returns

The epsilon theta

int PGAGetEvalCount(PGAContext *ctx)

Return the number of function evaluations so far.

Example

PGAContext *ctx;
int g;

...
g = PGAGetEvalCount (ctx);

Parameters
  • ctx – context variable

Returns

The number of function evaluations

double PGAGetFitnessCmaxValue(PGAContext *ctx)

Return the value of the multiplier used in the MinCmax fitness algorithm.

Example

PGAContext *ctx;
double cmax;

...
cmax = PGAGetFitnessCmaxValue (ctx);

Parameters
  • ctx – context variable

Returns

The value of Cmax used

int PGAGetFitnessMinType(PGAContext *ctx)

Return the type of fitness transformation used for minimization problems.

Example

PGAContext *ctx;
int fitmintype;

...
fitmintype = PGAGetFitnessMinType (ctx);
switch (fitmintype) {
case PGA_FITNESSMIN_RECIPROCAL:
    printf ("Fitness Minimization Type = PGA_FITNESSMIN_RECIPROCAL\n");
    break;
case PGA_FITNESSMIN_CMAX:
    printf ("Fitness Minimization Type = PGA_FITNESSMIN_CMAX\n");
    break;
}

Parameters
  • ctx – context variable

Returns

Returns the integer corresponding to the symbolic constant used to specify the type of fitness transformation used for minimization problems

int PGAGetFitnessType(PGAContext *ctx)

Return the type of fitness transformation used.

Example

PGAContext *ctx;
int fittype;

...
fittype = PGAGetFitnessType (ctx);
switch (fittype) {
case PGA_FITNESS_RAW:
    printf ("Fitness Type = PGA_FITNESS_RAW\n");
    break;
case PGA_FITNESS_NORMAL:
    printf ("Fitness Type = PGA_FITNESS_NORMAL\n");
    break;
case PGA_FITNESS_RANKING:
    printf ("Fitness Type = PGA_FITNESS_RANKING\n");
    break;
}

Parameters
  • ctx – context variable

Returns

Returns the integer corresponding to the symbolic constant to specify the type of fitness transformation used

int PGAGetGAIterValue(PGAContext *ctx)

Return the number of the current genetic algorithm generation.

Example

PGAContext *ctx;
int g;

...
g = PGAGetGAIterValue (ctx);

Parameters
  • ctx – context variable

Returns

The genetic algorithm generation number

int PGAGetIntegerInitType(PGAContext *ctx)

Return the type of scheme used to randomly initialize strings of data type integer.

Example

PGAContext *ctx;
int inittype;

...
inittype = PGAGetIntegerInitType (ctx);
switch (inittype) {
case PGA_IINIT_PERMUTE:
    printf ("Data Type = PGA_IINIT_PERMUTE\n");
    break;
case PGA_IINIT_RANGE:
    printf ("Data Type = PGA_IINIT_RANGE\n");
    break;
}

Parameters
  • ctx – context variable

Returns

Returns the integer corresponding to the symbolic constant used to specify the scheme used to initialize integer strings.

double PGAGetMaxFitnessRank(PGAContext *ctx)

Return the maximum value used in rank-based fitness.

Example

PGAContext *ctx;
double max;

...
max = PGAGetMaxFitnessRank (ctx);

Parameters
  • ctx – context variable

Returns

The value of MAX used in rank-based fitness

int PGAGetMaxGAIterValue(PGAContext *ctx)

Return the maximum number of iterations to run.

Example

PGAContext *ctx;
int maxiter;

...
maxiter = PGAGetMaxGAIterValue (ctx);

Parameters
  • ctx – context variable

Returns

The maximum number of iterations to run

int PGAGetMaxIntegerInitValue(PGAContext *ctx, int i)

Return the maximum of the range of integers used to randomly initialize integer strings.

Example

PGAContext *ctx;
int idx;
int max;

...
max = PGAGetMaxIntegerInitValue (ctx, idx);

Parameters
  • ctx – context variable

  • i – Index of the initialization range

Returns

The maximum of the range of integers used to randomly initialize integer strings

double PGAGetMaxMachineDoubleValue(PGAContext *ctx)

Return the largest double of the current machine.

Example

PGAContext *ctx;
double big;

...
big = PGAGetMaxMachineDoubleValue (ctx);

Parameters
  • ctx – context variable

Returns

The largest double of the given machine

int PGAGetMaxMachineIntValue(PGAContext *ctx)

Return the largest integer of the current machine.

Example

PGAContext *ctx;
int intmax;

...
intmax = PGAGetMaxMachineIntValue (ctx);

Parameters
  • ctx – context variable

Returns

The largest integer of the given machine

double PGAGetMaxRealInitValue(PGAContext *ctx, int i)

Return the maximum value used to randomly initialize allele i in a real string.

Example

PGAContext *ctx;
int max;

...
max = PGAGetMaxRealInitValue (ctx, 0);

Parameters
  • ctx – context variable

  • i – an allele position

Returns

The maximum value used to randomly initialize allele i

int PGAGetMaxSimilarityValue(PGAContext *ctx)

Get the maximum percent of homogeneity of the population before stopping.

Example

PGAContext *ctx;
int max_similarity;

...
max_similarity = PGAGetMaxSimilarityValue (ctx);

Parameters
  • ctx – context variable

Returns

the maximum percent of the population that can share the same evaluation function value

int PGAGetMinIntegerInitValue(PGAContext *ctx, int i)

Return the minimum of the range of integers used to randomly initialize integer strings.

Example

PGAContext *ctx;
int min;
int idx;

...
min = PGAGetMinIntegerInitValue (ctx, idx);

Parameters
  • ctx – context variable

  • i – Index of the initialization range

Returns

The minimum of the range of integers used to randomly initialize integer strings

double PGAGetMinMachineDoubleValue(PGAContext *ctx)

Return the smallest double of the current machine.

Example

PGAContext *ctx;
double small;

...
small = PGAGetMinMachineDoubleValue (ctx);

Parameters
  • ctx – context variable

Returns

The smallest double of the given machine

int PGAGetMinMachineIntValue(PGAContext *ctx)

Return the smallest integer of the current machine.

Example

PGAContext *ctx;
int intmin;

...
intmin = PGAGetMinMachineIntValue (ctx);

Parameters
  • ctx – context variable

Returns

The smallest integer of the given machine

double PGAGetMinRealInitValue(PGAContext *ctx, int i)

Returns the minimum value used to randomly initialize allele i in a real string.

Example

PGAContext *ctx;
int min;

...
min = PGAGetMinRealInitValue (ctx, 0);

Parameters
  • ctx – context variable

  • i – an allele position

Returns

The minimum value used to randomly initialize allele i

int PGAGetMixingType(PGAContext *ctx)

Return the strategy setting for combination of mutation and crossover.

Example

PGAContext *ctx;
int mixtype;

...
mixtype = PGAGetMixingType (ctx);

Parameters
  • ctx – context variable

Returns

Return the mixing type

int PGAGetMultiObjPrecision(PGAContext *ctx)

Return the precision for printing multi objective optimization evaluations.

Example

PGAContext *ctx;
int prec;

...
prec = PGAGetMultiObjPrecision (ctx);

Parameters
  • ctx – context variable

Returns

The precision of printing multi objective evaluations

int PGAGetMutationBounceBackFlag(PGAContext *ctx)

Return flag to indicate whether mutated strings remain within the initialization range by bouncing them from the boundary.

Example

PGAContext *ctx;
int val;

...
val = PGAGetMutationBounceBackFlag (ctx);

Parameters
  • ctx – context variable

Returns

true if restricted to the given range

int PGAGetMutationBoundedFlag(PGAContext *ctx)

Return flag to indicate whether mutated integer strings remain in the initialization range.

Description

The initialization range is specified when initialized with PGASetIntegerInitRange().

Example

PGAContext *ctx;
int val;

...
val = PGAGetMutationBoundedFlag (ctx);

Parameters
  • ctx – context variable

Returns

true if restricted to the given range

int PGAGetMutationIntegerValue(PGAContext *ctx)

Return the value of the multiplier used to mutate data type integer strings with.

Example

PGAContext *ctx;
int ival;

...
ival = PGAGetMutationIntegerValue (ctx);

Parameters
  • ctx – context variable

Returns

The value of the multiplier

double PGAGetMutationPolyEta(PGAContext *ctx)

Return the Eta for polynomial mutation.

Example

PGAContext *ctx;
double eta;

...
eta = PGAGetMutationPolyEta (ctx);

Parameters
  • ctx – context variable

Returns

The eta for polynomial mutation

double PGAGetMutationPolyValue(PGAContext *ctx)

Return the value for polynomial mutation.

Example

PGAContext *ctx;
double v;

...
v = PGAGetMutationPolyValue (ctx);

Parameters
  • ctx – context variable

Returns

The value for polynomial mutation

double PGAGetMutationProb(PGAContext *ctx)

Return the probability of mutation.

Example

PGAContext *ctx;
double pm;

...
pm = PGAGetMutationProb (ctx);

Parameters
  • ctx – context variable

Returns

The mutation probability

double PGAGetMutationRealValue(PGAContext *ctx)

Return the value of the multiplier used to mutate strings of data type real with.

Example

PGAContext *ctx;
double val;

...
val = PGAGetMutationRealValue (ctx);

Parameters
  • ctx – context variable

Returns

The value of the multiplier

int PGAGetMutationType(PGAContext *ctx)

Return the type of mutation used.

Example

PGAContext *ctx;
int mutatetype;

...
mutatetype = PGAGetMutationType (ctx);
switch (mutatetype) {
case PGA_MUTATION_CONSTANT:
    printf ("Mutation Type = PGA_MUTATION_CONSTANT\n");
    break;
case PGA_MUTATION_RANGE:
    printf ("Mutation Type = PGA_MUTATION_RANGE\n");
    break;
case PGA_MUTATION_UNIFORM:
    printf ("Mutation Type = PGA_MUTATION_UNIFORM\n");
    break;
case PGA_MUTATION_GAUSSIAN:
    printf ("Mutation Type = PGA_MUTATION_GAUSSIAN\n");
    break;
case PGA_MUTATION_PERMUTE:
    printf ("Mutation Type = PGA_MUTATION_PERMUTE\n");
    break;
case PGA_MUTATION_DE:
    printf ("Mutation Type = PGA_MUTATION_DE\n");
    break;
case PGA_MUTATION_POLY:
    printf ("Mutation Type = PGA_MUTATION_POLY\n");
    break;
}

Parameters
  • ctx – context variable

Returns

Returns the integer corresponding to the symbolic constant used to specify the type of mutation specified

int PGAGetNAMWindowSize(PGAContext *ctx)

Get window size for negative assortative mating (NAM).

Description

On selection select first individual as configured, for the second individual draw wsize individuals and select the one that has the largest genetic difference to the first individual. The default window size 1 doesn’t use NAM. See description [FR01]. This gets the currently configured NAM window size.

Example

PGAContext *ctx,
int wsize;

...
wsize = PGAGetNAMWindowSize (ctx);

Parameters
  • ctx – context variable

Returns

Window size for NAM

int PGAGetNoDuplicatesFlag(PGAContext *ctx)

Return PGA_TRUE if duplicates are not allowed, else return PGA_FALSE.

Example

PGAContext *ctx;

...
if (PGAGetNoDuplicatesFlag (ctx)) {
    printf ("Duplicate strings not allowed in population\n");
} else {
    printf ("Duplicate strings allowed in population\n");
}

Parameters
  • ctx – context variable

Returns

The value of the NoDuplicates flag

int PGAGetNumAuxEval(PGAContext *ctx)

Get the number of auxiliary evaluations.

Example

PGAContext *ctx;
int num;

...
num = PGAGetNumAuxEval (ctx);

Parameters
  • ctx – context variable

Returns

Number of auxiliary evaluations

int PGAGetNumConstraint(PGAContext *ctx)

Get the number of constraints.

Example

PGAContext *ctx;
int num;

...
num = PGAGetNumConstraint (ctx);

Parameters
  • ctx – context variable

Returns

Number of constraints

int PGAGetNumReplaceValue(PGAContext *ctx)

Return the maximum number of strings to replace in each generation.

Example

PGAContext *ctx;
int numreplace;

...
numreplace = PGAGetNumReplaceValue (ctx);

Parameters
  • ctx – context variable

Returns

The maximum number number of strings to replace each generation

int PGAGetOptDirFlag(PGAContext *ctx)

Return a symbolic constant that represents the direction of optimization.

Example

PGAContext *ctx;
int optdir;

...
optdir = PGAGetOptDirFlag (ctx);
switch (optdir) {
case PGA_MAXIMIZE:
    printf ("Optimization direction = PGA_MAXIMIZE\n");
    break;
case PGA_MINIMIZE:
    printf ("Optimization direction = PGA_MINIMIZE\n");
    break;
}

Parameters
  • ctx – context variable

Returns

The integer corresponding to the symbolic constant used to specify the direction of optimization

double PGAGetPTournamentProb(PGAContext *ctx)

Return the probability of selecting the best string in a probabilistic binary tournament.

Example

PGAContext *ctx;
double pt;

...
pt = PGAGetPTournamentProb (ctx);

Parameters
  • ctx – context variable

Returns

The probabilistic binary tournament selection probability

int PGAGetPopReplaceType(PGAContext *ctx)

Return the symbolic constant used to determine which strings to copy from the old population to the new population.

Example

PGAContext *ctx;
int popreplace;

...
popreplace = PGAGetPopReplaceType (ctx);
switch (popreplace) {
case PGA_POPREPL_BEST:
    printf ("Replacement Strategy = PGA_POPREPL_BEST\n");
    break;
case PGA_POPREPL_RANDOM_REP:
    printf ("Replacement Strategy = PGA_POPREPL_RANDOM_REP\n");
    break;
case PGA_POPREPL_RANDOM_NOREP:
    printf ("Replacement Strategy = PGA_POPREPL_RANDOM_NOREP\n");
    break;
default:
    printf ("Another Replacement Strategy\n");
    break;
}

Parameters
  • ctx – context variable

Returns

The symbolic constant of the replacement strategy

int PGAGetPopSize(PGAContext *ctx)

Return the population size.

Example

PGAContext *ctx;
int popsize;

...
popsize = PGAGetPopSize (ctx);

Parameters
  • ctx – context variable

Returns

The population size

int PGAGetPrintFrequencyValue(PGAContext *ctx)

Return how often to print statistics reports.

Example

PGAContext *ctx;
int freq;

...
freq = PGAGetPrintFrequencyValue (ctx);

Parameters
  • ctx – context variable

Returns

The frequency of printing output

int PGAGetRTRWindowSize(PGAContext *ctx)

Return the window size for restricted tournament replacement.

Example

PGAContext *ctx;
int windowsize;

...
windowsize = PGAGetRTRWindowSize (ctx);

Parameters
  • ctx – context variable

Returns

The size of the window for restricted tournament selection

int PGAGetRandomInitFlag(PGAContext *ctx)

Return true/false to indicate whether or not alleles are randomly initialized.

Example

PGAContext *ctx;

...
if (PGAGetRandomInitFlag (ctx)) {
    printf ("Population is randomly initialized\n");
} else {
    printf ("Population initialized to zero\n");
}

Parameters
  • ctx – context variable

Returns

Return true if alleles are randomly initialized

int PGAGetRandomSeed(PGAContext *ctx)

Return the integer the random number generator was seeded with.

Example

PGAContext *ctx;
int seed;

...
seed = PGAGetRandomSeed (ctx);

Parameters
  • ctx – context variable

Returns

The seed for the random number generator

int PGAGetRandomizeSelect(PGAContext *ctx)

Return the setting for additional select randomization.

Description

This function will return PGA_TRUE if a second randomization step after selection is performed. All selection schemes except PGA_SELECT_SUS already return the individuals in randomized order, previously this was randomized again. With this method you can find out if the randomization for selection schemes other than PGA_SELECT_SUS (for which a randomization step is always performed)

Example

PGAContext *ctx;
int v;

...
v = PGAGetRandomizeSelect (ctx);

Parameters
  • ctx – context variable

Returns

The setting of select randomization, true if on

int PGAGetRealInitType(PGAContext *ctx)

Return the type of scheme used to randomly initialize strings of data type real.

Example

PGAContext *ctx;
int inittype;

...
inittype = PGAGetRealInitType (ctx);
switch (inittype) {
case PGA_RINIT_PERCENT:
    printf ("Data Type = PGA_RINIT_PERCENT\n");
    break;
case PGA_RINIT_RANGE:
    printf ("Data Type = PGA_RINIT_RANGE\n");
    break;
}

Parameters
  • ctx – context variable

Returns

Returns the integer corresponding to the symbolic constant used to specify the scheme used to initialize real strings

double PGAGetRestartAlleleChangeProb(PGAContext *ctx)

Return the probability with which an allele will be mutated during a restart.

Example

PGAContext *ctx;
double prob;

...
prob = PGAGetRestartAlleleChangeProb (ctx);

Parameters
  • ctx – context variable

Returns

The probability of mutating an allele during a restart

int PGAGetRestartFlag(PGAContext *ctx)

Return whether the algorithm should employ the restart operator.

Example

PGAContext *ctx;
int val;

...
val = PGAGetRestartFlag (ctx);

Parameters
  • ctx – context variable

Returns

true if restarting is enabled

int PGAGetRestartFrequencyValue(PGAContext *ctx)

Return the number of iterations of no change in the best string after which the algorithm should restart.

Example

PGAContext *ctx;
int frq;

...
frq = PGAGetRestartFrequencyValue (ctx);

Parameters
  • ctx – context variable

Returns

The number of iteration of no change required for a restart

int PGAGetSelectType(PGAContext *ctx)

Return the type of selection selected.

Example

PGAContext *ctx;
int selecttype;

...
selecttype = PGAGetSelectType (ctx);
switch (selecttype) {
case PGA_SELECT_PROPORTIONAL:
    printf ("Selection Type = PGA_SELECT_PROPORTIONAL\n");
    break;
case PGA_SELECT_SUS:
    printf ("Selection Type = PGA_SELECT_SUS\n");
    break;
case PGA_SELECT_TOURNAMENT:
    printf ("Selection Type = PGA_SELECT_TOURNAMENT\n");
    break;
case PGA_SELECT_PTOURNAMENT:
    printf ("Selection Type = PGA_SELECT_PTOURNAMENT\n");
    break;
case PGA_SELECT_TRUNCATION:
    printf ("Selection Type = PGA_SELECT_TRUNCATION\n");
    break;
}

Parameters
  • ctx – context variable

Returns

Return the integer corresponding to the symbolic constant used to specify the type of selection specified

int PGAGetSortedPopIndex(PGAContext *ctx, int n)

Return a population string index from the array created by sorting of the population.

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

  • n – specified which index element is to be returned.

Returns

A population string index from the array created by PGASortPop

int PGAGetStoppingRuleType(PGAContext *ctx)

Return a symbolic constant that defines the termination criteria.

Example

PGAContext *ctx;
int stop;

...
stop = PGAGetStoppingRuleType (ctx);
if (stop & PGA_STOP_MAXITER) {
    printf ("Stopping Rule = PGA_STOP_MAXITER\n");
}
if (stop & PGA_STOP_NOCHANGE) {
    printf ("Stopping Rule = PGA_STOP_NOCHANGE\n");
}
if (stop & PGA_STOP_TOOSIMILAR) {
    printf ("Stopping Rule = PGA_STOP_TOOSIMILAR\n");
}

Parameters
  • ctx – context variable

Returns

Return an integer which is an ORed mask of the symbolic constants used to specify the stopping rule(s).

int PGAGetStringLength(PGAContext *ctx)

Return the string length.

Example

PGAContext *ctx;
int stringlen;

...
stringlen = PGAGetStringLength (ctx);

Parameters
  • ctx – context variable

Returns

The string length

int PGAGetSumConstraintsFlag(PGAContext *ctx)

Query if constraints are summed or optimized by NSGA-II nondominated sorting.

Example

PGAContext *ctx;
int n;

...
n = PGAGetSumConstraintsFlag (ctx);

Parameters
  • ctx – context variable

Returns

sum constraints flag

double PGAGetTournamentSize(PGAContext *ctx)

Return the number of participants in a tournament.

Example

PGAContext *ctx;
double sz;

...
sz = PGAGetTournamentSize (ctx);

Parameters
  • ctx – context variable

Returns

The number of participants in a non probabilistic tournament

int PGAGetTournamentWithReplacement(PGAContext *ctx)

Return the setting for tournament sampling, true if with replacement.

Example

PGAContext *ctx;
int v;

...
v = PGAGetTournamentWithReplacement (ctx);

Parameters
  • ctx – context variable

Returns

The setting of tournament with/without replacement, true if with replacement

double PGAGetTruncationProportion(PGAContext *ctx)

Return the proportion of best individuals selected in truncation selection.

Example

PGAContext *ctx;
double v;

...
v = PGAGetTruncationProportion (ctx);

Parameters
  • ctx – context variable

Returns

Proportion of best individuals selected in truncation selection

double PGAGetUniformCrossoverProb(PGAContext *ctx)

Return the probability of an allele being selected from the first child string in uniform crossover.

Example

PGAContext *ctx;
double pu;

...
pu = PGAGetUniformCrossoverProb (ctx);

Parameters
  • ctx – context variable

Returns

The uniform crossover probability

int PGAGetWorstIndex(PGAContext *ctx, int pop)

Return the index of the string with the worst evaluation function value in population pop.

Example

PGAContext *ctx;
int worst;

...
worst = PGAGetWorstIndex (ctx, PGA_OLDPOP);

Parameters
  • ctx – context variable

  • pop – symbolic constant of the population to find the worst string in

Returns

Index of the string with the worst evaluation function value

Deprecated

group deprecated

Deprecated functions, see doc for replacement.

Functions

int PGAGetMutationAndCrossoverFlag(PGAContext *ctx)

Return true if mutation occurs only when crossover does.

Description

Note: This is a legacy interface. If mixing types other than PGA_MIX_MUTATE_OR_CROSS and PGA_MIX_MUTATE_AND_CROSS have been set this might return wrong values, use PGAGetMixingType() instead. Do not use this for new code.

Parameters
  • ctx – context variable

Returns

Return true if mutation is applied to crossed-over strings

int PGAGetMutationOnlyFlag(PGAContext *ctx)

Return true if only mutation is used.

Description

Note: This is a legacy interface, use PGAGetMixingType() instead. Do not use this for new code.

Parameters
  • ctx – context variable

Returns

flag to indicate if only mutation is applied

int PGAGetMutationOrCrossoverFlag(PGAContext *ctx)

Return true if mutation only occurs when crossover does not.

Description

Note: This is a legacy interface. If mixing types other than PGA_MIX_MUTATE_OR_CROSS and PGA_MIX_MUTATE_AND_CROSS have been set this might return wrong values, use PGAGetMixingType() instead. Do not use this for new code.

Parameters
  • ctx – context variable

Returns

Return true if mutation only occurs when crossover does not

void PGASetMutationAndCrossoverFlag(PGAContext *ctx, int flag)

Set a boolean flag to indicate if recombination uses both crossover and mutation on selected strings.

Description

Note: This is a legacy interface, use PGASetMixingType() instead. Do not use this for new code.

Parameters
  • ctx – context variable

  • flag – PGA_TRUE (default) or PGA_FALSE

Returns

None

void PGASetMutationOnlyFlag(PGAContext *ctx, int flag)

Set a boolean flag to indicate that recombination uses mutation only.

Description

Note: This is a legacy interface, use PGASetMixingType() instead. Note: This will override settings of PGASetMutationOrCrossoverFlag() and PGASetMutationAndCrossoverFlag() and will set the default (PGASetMutationOrCrossoverFlag()) when using PGA_FALSE as the flag. Do not use this for new code.

Parameters
  • ctx – context variable

  • flag – to indicate if only mutation is used

Returns

None

void PGASetMutationOrCrossoverFlag(PGAContext *ctx, int flag)

Set a boolean flag to indicate if recombination uses exactly one of crossover or mutation on selected strings.

Description

Note: This is a legacy interface, use PGASetMixingType() instead. Do not use this for new code.

Parameters
  • ctx – context variable

  • flag – to indicate if mutation uses exactly one of crossover or mutation

Returns

None

static inline void PGASetRealInitPercent(PGAContext *ctx, double *median, double *frac)

Set the upper and lower bounds for randomly initializing real-valued genes.

Description

This function is deprecated due to wrong naming: The last parameter was always a fraction, not a percentage. It is kept for backwards compatibility, do not use for new code. Use PGASetRealInitFraction() instead.

Parameters
  • ctx – context variable

  • median – an array containing the mean value of the interval

  • frac – an array containing the fraction of median to add and subtract to/from the median to define the interval

Returns

None

Function Groups Explicit Usage

Command Line

group cmdline

Functions

void PGAReadCmdLine(PGAContext *ctx, int *argc, char **argv)

Code that looks at the arguments, recognizes any that are for PGAPack, uses the arguments, and removes them from the command line args.

Example

int main (int argc, char **argv)
{
    PGAContext *ctx;

    PGAReadCmdLine (ctx, &argc, argv);
}

Parameters
  • ctx – context variable

  • argc – address of the count of the number of command line arguments

  • argv – array of command line arguments

Returns

None

Debugging

group debug

Functions for debugging function calls.

Functions

void PGAClearDebugLevel(PGAContext *ctx, int level)

Turn off a debug level.

Description

Only does anything if PGAPack was compiled to include debugging calls. See chapter Debugging Tools in the user guide for details.

Example

PGAContext *ctx;

...
PGAClearDebugLevel (ctx, 70);

Parameters
  • ctx – context variable

  • level – the debug level to turn off

Returns

None

void PGAClearDebugLevelByName(PGAContext *ctx, char *funcname)

Turn off debugging of the named function.

Example

PGAContext *ctx;

...
PGAClearDebugLevelByName (ctx, "PGAGetBinaryAllele");

Parameters
  • ctx – context variable

  • funcname – name of the function to turn off debugging output

Returns

None

void PGADebugPrint(PGAContext *ctx, int level, char *funcname, char *msg, int datatype, void *data)

Write debugging information.

Description

Valid values for level are PGA_DEBUG_ENTERED, PGA_DEBUG_EXIT, PGA_DEBUG_MALLOC, PGA_DEBUG_PRINTVAR, PGA_DEBUG_SEND, and PGA_DEBUG_RECV. See Debugging Constants for the constants and chapter Debugging Tools in the user guide for details.

Valid values for the datatype argument are PGA_INT, PGA_DOUBLE, PGA_CHAR and PGA_VOID (no data). The parameter data should be NULL, for PGA_VOID. See Constants for Error Printing for the constants in the user guide for details.

Example

If the debugging level includes printing variables (level 82), print the value of the integer variable num as a debugging tool in the routine Add2Nums.

PGAContext *ctx;
int num;

...
PGADebugPrint
   ( ctx, PGA_DEBUG_PRINTVAR
   , "Add2Nums", "num = ", PGA_INT, (void *) &num
   );

Parameters
  • ctx – context variable

  • level – a symbolic constant that maps to the type of print requested (e.g., an entry or exit print).

  • funcname – the name of the function that called this routine

  • msg – message to print

  • datatype – a symbolic constant that maps to the data type of the parameter data

  • data – a pointer, whose contents will be interpreted based upon the datatype parameter

Returns

The debugging information is printed to stdout

void PGASetDebugLevel(PGAContext *ctx, int level)

Turn on a debug level.

Description

Only does anything if PGAPack was compiled to include debugging calls. See chapter Debugging Tools in the user guide for details.

Example

PGAContext *ctx;

...
PGASetDebugLevel (ctx, 70);

Parameters
  • ctx – context variable

  • level – the debug level to set

Returns

None

void PGASetDebugLevelByName(PGAContext *ctx, char *funcname)

Turn on debugging of the named function.

Example

PGAContext *ctx;

...
PGASetDebugLevelByName (ctx, "PGAGetBinaryAllele");

Parameters
  • ctx – context variable

  • funcname – name of the function to turn on debugging output

Returns

None

Explicit Usage

group explicit

These functions are needed when explicitly programming the GA.

See chapter Explicit Usage for more details.

Functions

void INDCopyIndividual(PGAIndividual *src, PGAIndividual *dst)

Copy individual source to individual dest.

Example

PGAContext *ctx;
PGAIndividual *source, *dest;

...
INDCopyIndividual (ctx, source, dest);

Parameters
  • src – Individual to copy

  • dst – Individual to copy ind1 to

Returns

Individual dest is a copy of Individual source

MPI_Datatype PGABuildDatatype(PGAContext *ctx, int p, int pop)

Build an MPI datatype for string p in population pop.

Example

PGAContext *ctx;
int p;
MPI_Datatype dt;

...
dt = PGABuildDatatype (ctx, p, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p – index of an individual

  • pop – symbolic constant of the population

Returns

An MPI datatype for member p of population pop

int PGABuildDatatypeHeader(PGAContext *ctx, int p, int pop, int *counts, MPI_Aint *displs, MPI_Datatype *types)

Common part for building an MPI datatype for an individual.

Description

Returns by side effect a partially filled array of counts, displs, types. The returned index will be max PGA_MPI_HEADER_ELEMENTS. This means callers may use a statically allocated buffer.

Example

PGAContext *ctx;
int idx = 0;
int counts [PGA_MPI_HEADER_ELEMENTS + ...];
int displs [PGA_MPI_HEADER_ELEMENTS + ...];
MPI_Datatype types [PGA_MPI_HEADER_ELEMENTS + ...];

...
idx = PGABuildDatatypeHeader (ctx, counts, displs, types);
// Fill rest of counts, displs, types here and build datatype
counts [idx] =
displs [idx] =
types  [idx] =
idx++;
...

Parameters
  • ctx – context variable

  • p – index of string

  • pop – symbolic constant of the population string p is in

  • counts – Number of elements in each block

  • displs – byte displacement array pointer

  • types – type elements

Returns

The index of the next-to-be-filled counts, displs, types

void PGAChange(PGAContext *ctx, int p, int pop)

Repeatedly apply mutation to a string (with an increasing mutation rate) until one or more mutations have occurred.

Description

This routine is usually used with PGADuplicate() to modify a duplicate string. It is not intended to replace PGAMutate().

Example

Check the current to-be-inserted string if it is a copy of any of the strings in PGA_NEWPOP. Note that the check relies on all individuals in PGA_NEWPOP to also be inserted into the duplicate hash, see PGAHashIndividual().

PGAContext *ctx;
int p;

...
while (PGADuplicate (ctx, p, PGA_NEWNEW, PGA_NEWPOP)) {
    PGAChange (ctx, p, PGA_NEWPOP);
}

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population containing string p

Returns

Mutates string p in population pop via side effect

void PGACopyIndividual(PGAContext *ctx, int p1, int pop1, int p2, int pop2)

Copy string p1 in population pop1 to position p2 in population pop2.

Example

PGAContext *ctx;
int i, j;

...
PGACopyIndividual (ctx, i, PGA_OLDPOP, j, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – string to copy

  • pop1 – symbolic constant of population containing string p1

  • p2 – string to copy p1 to

  • pop2 – symbolic constant of population containing string p2

Returns

String p2 is an exact copy of string p1

void PGACrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2)

Perform crossover on two parent strings to create two child strings (via side-effect).

Description

The type of crossover performed is either the default or that specified by PGASetCrossoverType().

Example

Perform crossover on the two parent strings mom and dad in population PGA_OLDPOP, and insert the child strings, child1 and child1, in population PGA_NEWPOP.

PGAContext *ctx;
int mom, dad, child1, child2;

...
PGACrossover (ctx, mom, dad, PGA_OLDPOP, child1, child2, PGA_NEWPOP);

Parameters
  • ctx – the context variable

  • p1 – the first parent string

  • p2 – the second parent string

  • pop1 – symbolic constant of the population containing string p1 and p2

  • c1 – the first child string

  • c2 – the second child string

  • pop2 – symbolic constant of the population to contain string c1 and c2

Returns

c1 and c2 in pop2 are children of p1 and p2 in pop1. p1 and p2 are not modified.

int PGADone(PGAContext *ctx, MPI_Comm comm)

Return true if the stopping conditions have been met.

Description

Calls exactly one of the user defined C or Fortran or system PGACheckStoppingConditions() stopping condition functions.

Example

PGAContext *ctx;

...
PGADone (ctx, comm);

Parameters
  • ctx – context variable

  • comm – an MPI communicator

Returns

return true if at least one of the termination conditions has been met

int PGADuplicate(PGAContext *ctx, int p, int pop1, int pop2)

Determine if a specified string is a duplicate of one already in an existing population.

Description

Return PGA_TRUE if PGAGetNoDuplicatesFlag() returns PGA_TRUE and string p in population pop1 is a duplicate of at least one strings already inserted into population pop2, otherwise return PGA_FALSE.

Example

Check the current to-be-inserted string if it is a copy of any of the strings in PGA_NEWPOP. Note that the check relies on all individuals in PGA_NEWPOP to also be inserted into the duplicate hash, see PGAHashIndividual().

PGAContext *ctx;
int p;

...
while (PGADuplicate (ctx, p, PGA_NEWNEW, PGA_NEWPOP)) {
    PGAChange (ctx, p, PGA_NEWPOP);
}

Parameters
  • ctx – context variable

  • p – string index

  • pop1 – symbolic constant of the population containing string p

  • pop2 – symbolic constant of the (possibly partial) population containing strings to compare string p against

Returns

Return true if duplicate

void PGAEvaluate(PGAContext *ctx, int pop, double (*evaluate)(PGAContext*, int, int, double*), MPI_Comm comm)

Call a user-specified function to return an evaluation of each string in the population.

Description

The user-specified function is only called if the string has been changed (e.g., by crossover or mutation) or the user has explicitly signaled the string’s evaluation is out-of-date by a call to PGASetEvaluationUpToDateFlag().

The user-specified function will be called once for each string in population pop that requires evaluation. This function must return a double (the evaluation function value) and must fit the prototype:

double evaluate (PGAContext *c, int p, int pop, double *aux);

Example

Evaluate all strings in population PGA_NEWPOP using the user-defined evaluation function Energy.

double Energy (PGAContext *ctx, int p, int pop, double *aux) {
    ...
};

PGAContext *ctx;

...
PGAEvaluate (ctx, PGA_NEWPOP, Energy, MPI_COMM_WORLD);

Parameters
  • ctx – context variable

  • pop – symbolic constant of the population to be evaluated

  • evaluate – a pointer to a function to evaluate a string.

  • comm – an MPI communicator

Returns

Evaluates the population via side effect

double PGAGeneDistance(PGAContext *ctx, int pop)

Calculate the mean genetic distance for a population.

Description

This function has effort \(O(n^2)\) in the population size \(n\). It is very useful for detecting premature convergence and is used when genetic distance reporting has been turned on with PGA_REPORT_GENE_DISTANCE.

Example

PGAContext *ctx;
double gd;

...
gd = PGAGeneDistance (ctx, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • pop – symbolic constant of the population for which the genetic distance is to be calculated

Returns

The mean genetic distance in the population

void PGAHashIndividual(PGAContext *ctx, int p, int pop)

Compute Hash for this individual and insert into hash-table.

Description

Calls PGAIndividualHashIndex() for the hash value and puts it into the correct hash bucket.

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population containing string p

Returns

Computes hash of given individual and inserts it into hash table

int PGAMutate(PGAContext *ctx, int p, int pop)

Perform mutation on a string.

Description

The type of mutation depends on the data type. Refer to section Mutation in the user guide for data-specific examples.

Example

Mutate the best string in the population, until 10 or more mutations have occured.

PGAContext *ctx;
int p, count = 0;

...
p = PGAGetBestIndex (ctx, PGA_NEWPOP);
while (count < 10) {
    count += PGAMutate (ctx, p, PGA_NEWPOP);
}

Parameters
  • ctx – context variable

  • p – index of string to mutate

  • pop – symbolic constant of the population containing p

Returns

The number of mutations performed. Member p in population pop is mutated by side-effect

void PGAPairwiseBestReplacement(PGAContext *ctx)

Perform pairwise best replacement.

Description

Compare individuals with same index in PGA_OLDPOP and PGA_NEWPOP and select the one with better evalutation. Note that we may not use the fitness here: Fitness from two different populations are uncompareable! This replacement strategy is used in evolutionary algorithms that modify a single individual and replace the parent if the offspring is better. A popular example is Differential Evolution (DE). After this populations are swapped (exchange of PGA_NEWPOP and PGA_OLDPOP) for further processing.

Example

PGAContext *ctx;

...
PGAPairwiseBestReplacement (ctx);

Parameters
  • ctx – context variable

Returns

None

void PGAReceiveIndividual(PGAContext *ctx, int p, int pop, int source, int tag, MPI_Comm comm, MPI_Status *status)

Receive an individual from another process.

Description

This is usually called by one of the functions called via PGAEvaluate().

Example

Receive a string from the rank-0 process with tag PGA_SR_STRINGTOEVAL, and place it into the first temporary location in PGA_NEWPOP.

PGAContext *ctx;
MPI_Comm    comm;
MPI_Status  status;

...
PGAReceiveIndividual
  (ctx, PGA_TEMP1, PGA_NEWPOP, 0, PGA_SR_STRINGTOEVAL, comm, &status);

Parameters
  • ctx – contex variable

  • p – index of an individual

  • pop – symbolic constant of the population

  • source – ID of the process from which to receive

  • tag – MPI tag to look for

  • comm – MPI communicator

  • status – pointer to an MPI status structure

Returns

Status and string p in population pop are changed by side-effect

void PGARestart(PGAContext *ctx, int source_pop, int dest_pop)

Reseed a population from the best string.

Description

Perform mutation on the best string. For integers and reals, the amount by which to change is set with PGASetMutationIntegerValue() and PGASetMutationRealValue(), respectively. For binary strings, the bits are complemented.

Example

Perform an unspecified test to determine if the current evolution is not evolving fast enough, and if so, restart the evolution.

PGAContext *ctx;
...
PGAEvaluate (ctx, PGA_OLDPOP, f, comm);
PGAFitness  (ctx, PGA_OLDPOP);

...
if (StagnantEvolution ()) {
    PGARestart  (ctx, PGA_OLDPOP, PGA_NEWPOP);
    PGAEvaluate (ctx, PGA_NEWPOP, EvalFunc);
    PGAUpdateGeneration (ctx);
}

Parameters
  • ctx – context variable

  • source_pop – symbolic constant of the source population

  • dest_pop – symbolic constant of the destination population

Returns

dest_pop is modified by side-effect

void PGARestrictedTournamentReplacement(PGAContext *ctx)

Perform restricted tournament replacement.

Description

For each individual in PGA_NEWPOP we select a window of individuals from PGA_OLDPOP, find the one genetically most like the new candidate and replace the individual if the new candidate has better evalutation. Note that we may not use the fitness here: Fitness from two different populations are uncompareable! After this populations are swapped (exchange of PGA_NEWPOP and PGA_OLDPOP) for further processing.

Example

PGAContext *ctx;

...
PGARestrictedTournamentReplacement (ctx);

Parameters
  • ctx – context variable

Returns

None

void PGARunGM(PGAContext *ctx, double (*evaluate)(PGAContext*, int, int, double*), MPI_Comm comm)

High-level routine to execute the genetic algorithm using the global model.

Description

It is called after PGACreate() and PGASetUp() have been called. If a NULL communicator is given, a sequential execution method is used, otherwise, work is divided among the processors in the communicator.

Example

PGAContext *ctx;
double f (PGAContext *ctx, int p, int pop, double *aux);

...
PGARunGM (ctx, f, MPI_COMM_WORLD);

Parameters
  • ctx – context variable

  • evaluate – a pointer to the user’s evaluation function, which must have the calling sequence shown in the example

  • comm – an MPI communicator

Returns

None

void PGARunMutationAndCrossover(PGAContext *ctx, int oldpop, int newpop)

Perform crossover and mutation from one population to create the next.

Description

Assumes PGASelect() has been called.

Example

PGAContext *ctx;

...
PGARunMutationAndCrossover (ctx, PGA_OLDPOP, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • oldpop – symbolic constant of old population

  • newpop – symbolic constant of new population

Returns

newpop is modified by side-effect

void PGARunMutationOnly(PGAContext *ctx, int oldpop, int newpop)

Perform only mutation.

Description

Assumes PGASelect() has been called.

Example

PGAContext *ctx;

...
PGARunMutationOnly (ctx, PGA_OLDPOP, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • oldpop – symbolic constant of old population

  • newpop – symbolic constant of new population

Returns

newpop is modified by side-effect

void PGARunMutationOrCrossover(PGAContext *ctx, int oldpop, int newpop)

Perform crossover or mutation (but not both) from one population to create the next.

Description

Assumes PGASelect() has been called.

Example

PGAContext *ctx;

...
PGARunMutationOrCrossover (ctx, PGA_OLDPOP, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • oldpop – symbolic constant of old population

  • newpop – symbolic constant of new population

Returns

newpop is modified by side-effect

void PGASelect(PGAContext *ctx, int popix)

Perform genetic algorithm selection using the defined selection scheme.

Description

The selection scheme used is either the default selection scheme or that specified with PGASetSelectType().

Valid selection methods are proportional, stochastic universal, tournament, probabilistic tournament selection, truncation selection, or linear selection with macros PGA_SELECT_PROPORTIONAL, PGA_SELECT_SUS, PGA_SELECT_TOURNAMENT, PGA_SELECT_PTOURNAMENT, PGA_SELECT_TRUNCATION, PGA_SELECT_LINEAR respectively. This function updates an internal array with the indices of members of popix selected for recombination. These indices may be accessed with PGASelectNextIndex(). See Constants for Selection Types for the constants and section Selection in the user guide for details.

Example

PGAContext *ctx,

...
PGASelect (ctx, PGA_OLDPOP);

Parameters
  • ctx – context variable

  • popix – symbolic constant of population to select from

Returns

An array used by PGASelectNextIndex is created which contains the population indices of the selected individuals

int PGASelectNextIndex(PGAContext *ctx, int popix)

Return the index of next individual in internal array.

Description

The internal array used contains the indices determined by PGASelect().

Example

PGAContext *ctx;
int l;

...
l = PGASelectNextIndex (ctx, PGA_OLDPOP);

Parameters
  • ctx – context variable

  • popix – the population index, typically PGA_OLDPOP

Returns

A population index for the next selected creature

int PGASelectNextNAMIndex(PGAContext *ctx, int p1, int popix)

Return the index of next individual in internal array taking into account the genetic distance if negative assortative mating (NAM) is configured.

Description

Select the next index out of NAMWindow items that is genetically most distant from the first selected individual given in p1. Ties are broken by considering better evaluation.

Example

PGAContext *ctx;
int l;

...
l = PGASelectNextNAMIndex (ctx, PGA_OLDPOP);

Parameters
  • ctx – context variable

  • p1 – Index of first individual selected

  • popix – the population index, typically PGA_OLDPOP

Returns

A population index for the next selected creature taking NAM into account

void PGASendIndividual(PGAContext *ctx, int p, int pop, int dest, int tag, MPI_Comm comm)

Transmit an individual to another process.

Description

This is usually called by one of the functions called via PGAEvaluate().

Example

PGAContext *ctx;
int p, dest;

...
dest = SelectAFreeProcessor ();
PGASendIndividual (ctx, p, PGA_NEWPOP, dest, PGA_SR_STRINGTOEVAL, comm);

Parameters
  • ctx – context variable

  • p – index of an individual

  • pop – symbolic constant of the population

  • dest – ID of the process where this is going

  • tag – MPI tag to send with the individual

  • comm – MPI communicator

Returns

None

void PGASendReceiveIndividual(PGAContext *ctx, int send_p, int send_pop, int dest, int send_tag, int recv_p, int recv_pop, int source, int recv_tag, MPI_Comm comm, MPI_Status *status)

Send an individual to a process, while receiving a different individual from a different process.

Example

A dedicated process is being used to perform an optimization algorithm on the strings. Send a new string, s, to the process, while receiving an optimized string, r, from it.

PGAContext *ctx;
MPI_Comm    comm;
MPI_Status  status;
int  s, r;

...
PGASendReceiveIndividual
  ( ctx
  , s, PGA_NEWPOP, 1, PGA_SR_STRINGTOMODIFY
  , r, PGA_NEWPOP, 1, PGA_SR_MODIFIEDSTRING
  , comm, &status
  );

Parameters
  • ctx – context variable

  • send_p – index of string to send

  • send_pop – symbolic constant of population to send from

  • dest – destination process

  • send_tag – tag to send with

  • recv_p – index of string to receive

  • recv_pop – symbolic constant of population to receive from

  • source – process to receive from

  • recv_tag – tag to receive with

  • comm – an MPI communicator

  • status – pointer to the MPI status structure

Returns

status and string recv_p in population recv_pop are modified by side-effect

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. 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.

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

void PGAUnHashIndividual(PGAContext *ctx, int p, int pop)

Compute Hash for this individual and remove from hash-table.

Description

Calls PGAIndividualHashIndex() for the hash value and removes it from the correct hash bucket.

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population containing string p

Returns

Computes hash of given individual and removes it from hash table

void PGAUpdateGeneration(PGAContext *ctx, MPI_Comm comm)

Update internal data structures for the next genetic algorithm iteration, and check if the termination conditions, both user and PGAPack, have been met.

Description

This routine must be called by both rank-0 and worker processes at the end of each GA generation.

Example

PGAContext *ctx;

...
PGAUpdateGeneration (ctx, MPI_COMM_WORLD);

Parameters
  • ctx – context variable

  • comm – an MPI communicator

Returns

PGA_TRUE if the genetic algorithm has terminated, otherwise PGA_FALSE

static inline double PGAUserFunctionGeneDistance(PGAContext *ctx, int p1, int pop1, int p2, int pop2)

Call the genetic distance user function.

Description

Call the genetic distance user function. This calls the data-type specific user function for computing the genetic distance. For user-defined data types you need to register a genetic distance user function with PGASetUserFunction() with the constant PGA_USERFUNCTION_GEN_DISTANCE.

Parameters
  • ctx – context variable

  • p1 – first string index

  • pop1 – symbolic constant of the population the first string is in

  • p2 – second string index

  • pop2 – symbolic constant of the population the second string is in

Returns

Genetic distance of the two strings

void PGA_NSGA_III_Replacement(PGAContext *ctx)

Perform NSGA-III Replacement.

Description

  • Perform dominance computation (ranking)

  • Perform crowding computation specific to NSGA-III

  • Sort individuals and replace into next generation

Example

PGAContext *ctx;

...
PGA_NSGA_II_Replacement (ctx);

Parameters
  • ctx – context variable

Returns

None

void PGA_NSGA_II_Replacement(PGAContext *ctx)

Perform NSGA-II Replacement.

Description

  • Perform dominance computation (ranking)

  • Perform crowding computation specific to NSGA-II

  • Sort individuals and replace into next generation

Example

PGAContext *ctx;

...
PGA_NSGA_II_Replacement (ctx);

Parameters
  • ctx – context variable

Returns

None

Parallel Execution

group parallel

Parallel implementation of GA.

Functions

int PGAGetNumProcs(PGAContext *ctx, MPI_Comm comm)

Return the size of communicator comm in processes.

Description

If comm is NULL or a sequential version of PGAPack is used, 1 is returned.

Example

PGAContext  *ctx;

...
if (PGAGetNumProcs (ctx, MPI_COMM_WORLD) < 4) {
    printf ("Too few processors for decent performance!\n");
    exit (-1);
}

Parameters
  • ctx – context variable structure pointer

  • comm – an MPI communicator

Returns

The numbers of processors in communicator comm

int PGAGetRank(PGAContext *ctx, MPI_Comm comm)

Return the rank of the processor in communicator comm.

Description

If comm is NULL or a sequential version of PGAPack is used, 0 is returned.

Example

PGAContext  *ctx;
int          rank;

...
rank = PGAGetRank (ctx, MPI_COMM_WORLD);
if (rank == 0) {
    LetRank0DoSomething ();
}

Parameters
  • ctx – context variable structure pointer

  • comm – an MPI communicator

Returns

The rank of this processor

Randomness

group random

Functions

double PGARandom01(PGAContext *ctx, int newseed)

Generate a uniform random number on the interval [0,1).

Description

If the second argument is 0 it returns the next random number in the sequence. Otherwise, the second argument is used as a new seed for the population.

This is a C language implementation of the universal random number generator proposed by George Marsaglia, Arif Zaman, and Wai Wan Tsang [MZT90] and translated from F. James’ version [Jam90].

This algorithm is a combination of a lagged Fibonacci and arithmetic sequence (F. James) generator with period of \(2^{144}\). It provides 32-bit floating point numbers in the range from zero to one. It is claimed to be portable and provides bit-identical results on all machines with at least 24-bit mantissas.

PGARandom01() should be initialized with a 32-bit integer seed such that \(0 \le seed \le 900,000,000\). Each of these 900,000,000 values gives rise to an independent sequence of \(\approx 10^{30}\).

Warning on use of static storage class on thread shared memory machines.

Example

To get the next random number use

PGAContext *ctx;
double r;

...
r = PGARandom01 (ctx, 0);

Parameters
  • ctx – context variable

  • newseed – either 0 to get the next random number, or nonzero to reseed

Returns

A random number on the interval [0,1)

int PGARandomFlip(PGAContext *ctx, double p)

Flip a biased coin and return true if the coin is a “winner”.

Example

To return PGA_TRUE approximately seventy percent of the time, use

PGAContext *ctx;
int bit;

...
bit = PGARandomFlip (ctx, 0.7)

Parameters
  • ctx – context variable

  • p – biased probability (.5 is a fair coin)

Returns

true if coin flip is a winner

double PGARandomGaussian(PGAContext *ctx, double mean, double sigma)

Return an approximation to a Gaussian random number.

Example

To generate a Gaussian random number with mean 0.0 and standard deviation 1.0 use

PGAContext *ctx;
double r;

...
r = PGARandomGaussian (ctx, 0.0, 1.0);

Parameters
  • ctx – context variable

  • mean – the mean of the Gaussian distribution

  • sigma – the standard deviation of the Gaussian distribution

Returns

A random number selected from a Gaussian distribution with given mean and standard deviation

int PGARandomInterval(PGAContext *ctx, int start, int end)

Return a uniform random number on the specified interval.

Example

Generate a value uniformly random from the interval \([0,99]\)

PGAContext *ctx;
int r;

...
r = PGARandomInterval (ctx, 0, 99);

Parameters
  • ctx – context variable

  • start – starting (integer) value of the interval

  • end – ending (integer) value of the interval

Returns

A uniformly distributed random number in the interval [start, end]

int PGARandomNextSample(PGASampleState *state)

Get next sample index for k out of n.

Description

See PGARandomSampleInit() for documentation and example.

Parameters
  • state – pointer to PGASampleState, needs to be allocated by caller and initialized by PGARandomSampleInit

Returns

next sample

void PGARandomSampleInit(PGAContext *ctx, PGASampleState *state, int k, int n)

Init random sampling of k out of n without replacement.

Description

Algorithm from [Vit87]. This is implemented as an iterator, i.e., this init method that initializes n and k and a function PGARandomNextSample() that returns the next sample index. The algorithm guarantees that sample indexes are returned sorted in index order. Note that the internal implementation variable CUTOFF is arbitrary and no measurements were performed – modern CPUs can probably iterate a lot when not accessing memory, so this can probably be set a lot higher.

Example

PGAContext *ctx;
PGASampleState state;
int s;

...
PGARandomSampleInit (ctx, &state, 3, 6);
s = PGARandomNextSample (&state);

Parameters
  • ctx – context variable

  • state – pointer to PGASampleState, needs to be allocated by caller

  • k – k of the k out of n

  • n – n of the k out of n

Returns

None

double PGARandomUniform(PGAContext *ctx, double start, double end)

Return a uniform random number on the interval [start,end].

Example

Generate a uniform random number on the interval \([-0.5, 1.5]\)

PGAContext *ctx;
double r;

...
r = PGARandomUniform (ctx, -0.5, 1.5);

Parameters
  • ctx – context variable

  • start – starting (double) value of the interval

  • end – ending (double) value of the interval

Returns

A random number on the interval [start,end]

Reporting and Errors

group reporting

Reporting, output printing.

Functions

void PGAError(PGAContext *ctx, char *msg, int level, int datatype, void *data)

Report error messages.

Description

Prints out the message supplied, and the value of a piece of data. Terminates if PGA_FATAL. See Constants for Error Printing Flags for the level constants and Miscellaneous in the user guide for more information.

Example

PGAContext *ctx;
int         val;

...
PGAError
 ( ctx, "Some Non Fatal Error: val = "
 , PGA_WARNING, PGA_INT, (void *) &val
 );

PGAError (ctx, "A Fatal Error!", PGA_FATAL, PGA_VOID, NULL);

Parameters
  • ctx – context variable

  • msg – the error message to print

  • level – indicate the error’s severity

  • datatype – the data type of the following argument

  • data – the address of the data to be written out, cast as a void pointer

Returns

None

void PGAErrorPrintf(PGAContext *ctx, int level, char *fmt, ...)

Report error messages using printf-like interface.

Description

Prints out the message supplied, and optional parameters. Uses a printf-style interface. Terminates if PGA_FATAL. Note that compared to PGAError() msg and level are exchanged, seems more natural. See Constants for Error Printing Flags for the level constants and Miscellaneous in the user guide for more information.

Example

PGAContext *ctx;
int         val;

...
PGAErrorPrintf (ctx, PGA_WARNING, "Some Non Fatal Error: val = %d", val);
PGAErrorPrintf (ctx, PGA_FATAL, "A Fatal Error!");

Parameters
  • ctx – context variable

  • level – indicate the error’s severity

  • fmt – the printf-style format to print

  • ... – additional parameters depending on format string in msg

Returns

None

void PGAPrintContextVariable(PGAContext *ctx, FILE *fp)

Print the value of all the fields in the context variable.

Example

PGAContext *ctx;

...
PGAPrintContextVariable (ctx, stdout);

Parameters
  • ctx – context variable

  • fp – file pointer to print the output to

Returns

The value of all the fields in the context variable are printed to fp

void PGAPrintIndividual(PGAContext *ctx, FILE *fp, int p, int pop)

Print the allele values of a string and associated fields (evaluation, fitness, etc.) of a string.

Example

PGAContext *ctx;
int p;

...
PGAPrintIndividual (ctx, stdout, p, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • fp – file pointer to print the output to

  • p – string index

  • pop – symbolic constant of the population string p is in

Returns

The allele values of string p and associated fields are printed to fp

void PGAPrintPopulation(PGAContext *ctx, FILE *fp, int pop)

Print each member of a population.

Description

Call PGAPrintIndividual() to print each member of a population.

Example

PGAContext *ctx;

...
PGAPrintPopulation (ctx, stdout, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • fp – file pointer to print the output to

  • pop – symbolic constant of the population to be printed

Returns

The strings and associated fields that make up a population member are printed to fp

void PGAPrintReport(PGAContext *ctx, FILE *fp, int pop)

Print genetic algorithm statistics.

Description

The statistics that are printed are determined by PGASetPrintOptions().

Example

PGAContext *ctx;
int p;

...
PGAPrintReport (ctx, stdout, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • fp – file pointer to print the output to

  • pop – symbolic constant of the population whose statistics are printed

Returns

genetic algorithm statistics are printed to fp

void PGAPrintString(PGAContext *ctx, FILE *fp, int p, int pop)

Write the allele values in a string to a file.

Example

PGAContext *ctx;
int p;

...
PGAPrintString (ctx, stdout, p, PGA_OLDPOP);

Parameters
  • ctx – context variable

  • fp – pointer to file to write the string to

  • p – index of the string to write out

  • pop – symbolic constant of the population string p is in

Returns

None

void PGAUsage(PGAContext *ctx)

Print list of available parameters and quit.

Description

Print the usage info out if MPI isn’t running (thus, only one process is probably running), or if we actually are the rank-0 process.

Example

PGAContext ctx;

...
PGAUsage (ctx);

Parameters
  • ctx – context variable

Returns

print list of available parameters

Utilities

group utility

Utility functions for internal and explicit use.

Functions

int INDEvalCompare(PGAIndividual *ind1, PGAIndividual *ind2)

Compare two individuals by evaluation.

Description

This typically simply compares evaluation taking into account the evaluation direction (minimize/maximize). We sort “better” individuals first. For more details see PGAEvalCompare().

Thinks of this as sorting individuals by decreasing fitness or increasing constraint violations. See also PGAEvalCompare().

Example

PGAIndividual *ind1, *ind2;
int result;
ind1 = PGAGetIndividual (...
ind2 = PGAGetIndividual (...

result = INDEvalCompare (ind1, ind2);

Parameters
  • ind1 – Pointer to first individual

  • ind2 – Pointer to second individual

Returns

  • >0 if p2 is “better” than p1

  • <0 if p1 is “better” than p2

  • 0 if both compare equal

int PGACheckSum(PGAContext *ctx, int p, int pop)

Map a string to a number to be used as verification check.

Description

The data type PGA_DATATYPE_USER is not supported. See also the USER function PGAHash PGA_USERFUNCTION_HASH and the hash implementations for individual data types.

Example

PGAContext *ctx;
int p, sum;

...
sum = PGACheckSum (ctx, p, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant for the population

Returns

An integer representing the “value” of the string

int PGAEvalCompare(PGAContext *ctx, int p1, int pop1, int p2, int pop2)

Compare two strings for selection.

Description

Thinks of this as sorting individuals by decreasing fitness or increasing constraint violations.

This typically simply compares evaluation taking into account the evaluation direction (minimize/maximize). But if auxiliary evaluations are defined, the auxiliary evaluations are treated as constraints or for multi-objective optimization. The default handling of auxiliary evaluations is incompatible with certain selection schemes, see checks in create.c We handle constraints to compare first: If two constrained individuals are compared, the one with less constraint violations wins. If a constrained individual is compared to an unconstrained one, the latter wins. If two unconstrained individuals are compared, the (single) evaluation is compared depending on the direction of optimization (minimization or maximization).

For multi-objective optimization we do not compare the evaluations but only the rank (as computed by the NSGA-II algorithm). Note that many individuals may have the same rank.

Note that PGAEvalCompare() is now used in several contexts, including finding the best evaluation. For very badly scaled problems, the default fitness computation will degenerate if there are very large evaluation values and very small ones. In that case the fitness will not reflect the evaluation. Therefore PGAEvalCompare() will now always sort on evaluation values ignoring the fitness. This improves Tournament selection for very badly scaled problems.

Example

PGAContext *ctx;
int result;

...
result = PGAEvalCompare (ctx, p1, PGA_OLDPOP, p2, PGA_OLDPOP);

Parameters
  • ctx – context variable

  • p1 – first string to compare

  • pop1 – symbolic constant of population of first string

  • p2 – second string to compare

  • pop2 – symbolic constant of population of second string

Returns

  • >0 if p2 is “better” than p1

  • <0 if p1 is “better” than p2

  • 0 if both compare equal

void PGAEvalSort(PGAContext *ctx, int pop, int *idx)

Sort list of population indeces by evaluation.

Description

Note that the given list idx of indeces need not be initialized. It just has to have the correct size of course. Think of this as sorting individuals by “better” evaluation or increasing constraint violations. The best individals are sorted first.

Example

PGAContext *ctx;
int indexes [ctx->ga.PopSize];

...
PGAEvalSort (ctx, PGA_OLDPOP, indexes);

Parameters
  • ctx – context variable

  • pop – symbolic constant of population to sort

  • idx – Array of integer indeces into population pop

Returns

Array idx sorted by evalation

double PGAMean(PGAContext *ctx, double *a, int n)

Calculates the mean value of an array of elements.

Example

PGAContext *ctx;
double a [100], mean;

...
mean = PGAMean (ctx, a, 100);

Parameters
  • ctx – context variable

  • a – array to take the mean of

  • n – number of elements in array a

Returns

The mean of the n elements in array a

int PGARound(PGAContext *ctx, double x)

Mathematically round a double to an integer, using 0.5 as the cutoff value.

Example

PGAContext *ctx;
int y;

...
y = PGARound (ctx, -78.6);

Parameters
  • ctx – context variable

  • x – the number to be rounded

Returns

The rounded number

void PGAShuffle(PGAContext *ctx, int *list, int n)

Shuffle a list.

Description

We’re using Durstenfeld’s version of the Fisher-Yates shuffle.

Example

PGAContext *ctx;
int list [ctx->ga.PopSize];
...
for (i=0; i<ctx->ga.PopSize; i++) {
    list [i] = i;
}
PGAShuffle (ctx, list, ctx->ga.PopSize);

Parameters
  • ctx – Context pointer

  • list – array of integers to shuffle

  • n – number of elements in array

Returns

Shuffled array

double PGAStddev(PGAContext *ctx, double *a, int n, double mean)

Calculate the standard deviation of an array of elements.

Example

PGAContext *ctx;
double a [100], mean, sigma;

...
mean  = PGAMean (ctx, a, 100);
sigma = PGAStddev (ctx, a, 100, mean);

Parameters
  • ctx – context variable

  • a – array to take the standard deviation of

  • n – number of elements in array a

  • mean – the mean of the elements in array a

Returns

The standard deviation of the n elements in array a

Function Groups Internal Implementation

Bit Manipulation

group fun-bit

Some functions for manipulating bit arrays.

Functions

static inline void SET_BIT(PGABinary *bitptr, int idx)

Bit array: Set a bit.

static inline int GET_BIT(PGABinary *bitptr, int idx)

Bit array: Get a bit.

static inline void CLEAR_BIT(PGABinary *bitptr, int idx)

Bit array: Clear a bit.

Internal Implementation

group internal

These functions are only used internally.

Functions

static inline int CMP(const double a, const double b)

Used in PGAEvalCompare and others.

MPI_Datatype PGABinaryBuildDatatype(PGAContext *ctx, int p, int pop)

Build an MPI datatype for a binary string datatype.

Description

Called only by MPI routines. Not for user consumption.

Parameters
  • ctx – context variable

  • p – index of the string to build a datatype from

  • pop – symbolic constant of the population string p is in

Returns

MPI_Datatype.

void PGABinaryCopyString(PGAContext *ctx, int p1, int pop1, int p2, int pop2)

Copy one bit string to another.

Description

Note that this function is set in PGASetUp() as the copy string user function for the binary datatype by default.

Example

Copy bit string x to y (both are implicitly assumed to have the same length).

PGAContext *ctx;
int x, y

...
PGABinaryCopyString (ctx, x, PGA_OLDPOP, y, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – string to copy

  • pop1 – symbolic constant of population containing string p1

  • p2 – string to copy p1 to

  • pop2 – symbolic constant of population containing string p2

Returns

None

void PGABinaryCreateString(PGAContext *ctx, int p, int pop, int initflag)

Allocate a binary string for member p of population pop.

Description

If initflag is PGA_TRUE, randomly initialize all alleles, otherwise clear all alleles. Applies to PGA_DATATYPE_BINARY strings.

Note that this function is set in PGASetUp() as the create string user function for the binary datatype by default.

Example

Allocates and clears alleles for all strings in PGA_NEWPOP.

PGAContext *ctx;
int p;

...
for (p=PGAGetPopSize(ctx)-1; p>=0; p--) {
    PGABinaryCreateString (ctx, p, PGA_NEWPOP, PGA_FALSE);
}

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population string p is in

  • initflag – a flag, if set, randomly initialize, else clear alleles

Returns

Member p in population pop is allocated and initialized.

int PGABinaryDuplicate(PGAContext *ctx, int p1, int pop1, int p2, int pop2)

Return true if bit string a is a duplicate of bit string b, else returns false.

Description

Note that this function is set in PGASetUp() as the duplicate checking user function for the binary datatype by default.

Example

Compare bit string x with y and print a message if they are the same.

PGAContext *ctx;
int x, y;

...
if (PGABinaryDuplicate (ctx, x, PGA_NEWPOP, y, PGA_NEWPOP)) {
    printf ("strings are duplicates\n");
}

Parameters
  • ctx – context variable

  • p1 – string index of the first string to compare

  • pop1 – symbolic constant of the population string p1 is in

  • p2 – string index of the second string to compare

  • pop2 – symbolic constant of the population string p2 is in

Returns

Return true/false if strings are duplicates

double PGABinaryGeneDistance(PGAContext *ctx, int p1, int pop1, int p2, int pop2)

Compute genetic difference of two strings.

Description

For binary genes this is the Hamming distance. It is used in the default setting of the PGA_USERFUNCTION_GEN_DISTANCE user function for the binary data type. Internal function. Use the gene distance user function PGAUserFunctionGeneDistance().

Parameters
  • ctx – context variable

  • p1 – first string index

  • pop1 – symbolic constant of the population the first string is in

  • p2 – second string index

  • pop2 – symbolic constant of the population the second string is in

Returns

genetic distance of the two strings

int PGABinaryHammingDistance(PGAContext *ctx, PGABinary *s1, PGABinary *s2)

Return the Hamming distance between two strings.

Description

Note that this function is used in PGABinaryGeneDistance() for implementing a generic genetic distance function. It is used in the default setting of the PGA_USERFUNCTION_GEN_DISTANCE user function for the binary data type.

Example

Return the Hamming distance between bit strings x and y.

PGAContext *ctx;
PGABinary *x, *y;
int d;

...
d = PGABinaryHammingDistance (ctx, x, y);

Parameters
  • ctx – context variable

  • s1 – the first string to compare

  • s2 – the second string to compare

Returns

The Hamming distance between two strings

PGAHash PGABinaryHash(PGAContext *ctx, int p, int pop)

Return hash value of given gene.

Description

Note that this function is set in PGASetUp() as the hash user function for the binary datatype by default.

Parameters
  • ctx – context variable

  • p – string index of the string to hash

  • pop – symbolic constant of the population string p is in

Returns

Hash value for string

void PGABinaryInitString(PGAContext *ctx, int p, int pop)

Randomly initialize a string of the binary data type.

Description

Note that this function is set in PGASetUp() as the init string user function for the binary datatype by default.

Example

PGAContext *ctx;
int p;

...
PGABinaryInitString (ctx, p, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p – index of string to randomly initialize

  • pop – symbolic constant of the population string p is in

Returns

None

int PGABinaryMutation(PGAContext *ctx, int p, int pop, double mr)

Randomly mutates a bit with a specified probability.

Description

This routine is called from PGAMutate().

Note that this function is set in PGASetUp() as the mutation user function for the binary datatype by default.

Example

Mutates string p in population PGA_NEWPOP with a probability of 0.001 for each bit.

PGAContext *ctx;
int p;

...
PGABinaryMutation (ctx, p, PGA_NEWPOP, .001);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant for the population string p is in

  • mr – probability of mutating (toggling) a bit

Returns

Return the number of mutations

void PGABinaryOneptCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2)

Performs one-point crossover on two parent strings to create two children via side-effect.

Description

Note that this function is set in PGASetUp() as the crossover user function for the binary datatype when selecting one-point crossover.

Example

Performs crossover on the two parent strings m and d, producing children s and b.

PGAContext *ctx;
int m, d, s, b;

...
PGABinaryOneptCrossover (ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – the first parent string

  • p2 – the second parent string

  • pop1 – symbolic constant of the population containing p1 and p2

  • c1 – the first child string

  • c2 – the second child string

  • pop2 – symbolic constant of the population containing c1 and c2

Returns

None

static void PGABinaryPrint(PGAContext *ctx, FILE *fp, PGABinary *chrom, int nb)

Write a bit string to a file.

Description

Puts the binary representation of the bit string pointed to by chrom into a character string and writes that out. Assumes the maximum length of string to print is WL, and that all bits are in the same word.

Internal function. Use PGABinaryPrintString() to print a binary string.

Parameters
  • ctx – context variable

  • fp – file to write the bit string to

  • chrom – pointer to the bit string to write

  • nb – number of bits to write out

Returns

None

void PGABinaryPrintString(PGAContext *ctx, FILE *fp, int p, int pop)

Write a bit string to a file.

Example

Write string s to stdout.

PGAContext *ctx;
int s;

...
PGABinaryPrintString (ctx, stdout, s, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • fp – file pointer to file to write bit string to

  • p – index of the string to write out

  • pop – symbolic constant of the population string p is in

Returns

None

void PGABinaryTwoptCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2)

Perform two-point crossover on two parent strings producing two children via side-effect.

Description

Note that this function is set in PGASetUp() as the crossover user function for the binary datatype when selecting two-point crossover.

Example

Performs crossover on the two parent strings m and d, producing children s and b.

PGAContext *ctx;
int m, d, s, b;

...
PGABinaryTwoptCrossover (ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – the first parent string

  • p2 – the second parent string

  • pop1 – symbolic constant of the population containing string p1 and p2

  • c1 – the first child string

  • c2 – the second child string

  • pop2 – symbolic constant of the population to contain string c1 and c2

Returns

None

void PGABinaryUniformCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2)

Perform uniform crossover on two parent strings producing two children via side-effect.

Description

Note that this function is set in PGASetUp() as the crossover user function for the binary datatype when selecting uniform crossover.

Example

Performs crossover on the two parent strings m and d, producing children s and b.

PGAContext *ctx;
int m, d, s, b;

...
PGABinaryUniformCrossover (ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – the first parent string

  • p2 – the second parent string

  • pop1 – symbolic constant of the population containing string p1 and p2

  • c1 – the first child string

  • c2 – the second child string

  • pop2 – symbolic constant of the population to contain string c1 and c2

Returns

None

static MPI_Datatype PGABuildEvaluation(PGAContext *ctx, int p, int pop)

Build an MPI datatype for eval and auxeval.

Example

PGAContext   *ctx;
int           p;
MPI_Datatype  dt;

...
dt = PGABuildEvaluation (ctx, p, pop);

Parameters
  • ctx – context variable

  • p – index of string

  • pop – symbolic constant of population string p is in

Returns

An MPI_Datatype

MPI_Datatype PGACharacterBuildDatatype(PGAContext *ctx, int p, int pop)

Build an MPI datatype for a character string.

Description

Called only by MPI routines. Not for user consumption.

Parameters
  • ctx – context variable

  • p – index of the string to build a datatype from

  • pop – symbolic constant of the population string p is in

Returns

MPI_Datatype

void PGACharacterCopyString(PGAContext *ctx, int p1, int pop1, int p2, int pop2)

Copy one character-valued string to another, assumes the strings are of the same length.

Description

Note that this function is set in PGASetUp() as the copy string user function for the char datatype by default.

Example

Copy character string x to y (both are implicitly assumed to be the same length)

PGAContext *ctx;
int x, y;

...
PGACharacterCopyString (ctx, x, PGA_OLDPOP, y, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – string to copy

  • pop1 – symbolic constant of population containing string p1

  • p2 – string to copy p1 to

  • pop2 – symbolic constant of population containing string p2

Returns

None

void PGACharacterCreateString(PGAContext *ctx, int p, int pop, int initflag)

Allocate memory for a string of type character.

Description

Note that this function is set in PGASetUp() as the create string user function for the char datatype by default.

Example

Allocates memory and assigns the address of the allocated memory to the string field ind->chrom of the individual. Additionally, the string is initialized to zero.

PGAContext *ctx;
int p;

...
PGACharacterCreateString (ctx, p, PGA_NEWPOP, PGA_FALSE);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population string p is in

  • initflag – A true/false flag used in conjunction with ctx->ga.RandomInit to initialize the string either randomly or set to zero

Returns

Member p in population pop is allocated and initialized.

int PGACharacterDuplicate(PGAContext *ctx, int p1, int pop1, int p2, int pop2)

Return true if string p1 in pop1 is a duplicate of string p2 in pop2, else returns false, assumes the strings are the same length.

Description

Note that this function is set in PGASetUp() as the duplicate checking user function for the char datatype by default.

Example

Compare string x with y to see if they are duplicates

PGAContext *ctx;
int x, y;

...
if (PGACharacterDuplicate (ctx, x, PGA_NEWPOP, y, PGA_NEWPOP)) {
    printf ("strings are duplicates\n");
}

Parameters
  • ctx – context variable

  • p1 – string index of the first string to compare

  • pop1 – symbolic constant of the population string p1 is in

  • p2 – string index of the second string to compare

  • pop2 – symbolic constant of the population string p2 is in

Returns

Returns true if strings are duplicates

double PGACharacterGeneDistance(PGAContext *ctx, int p1, int pop1, int p2, int pop2)

Compute genetic difference of two strings.

Description

Return sum of the absolute values of the differences of each allele. Internal function. Use PGAUserFunctionGeneDistance().

Parameters
  • ctx – context variable

  • p1 – first string index

  • pop1 – symbolic constant of the population the first string is in

  • p2 – second string index

  • pop2 – symbolic constant of the population the second string is in

Returns

genetic distance of the two strings

PGAHash PGACharacterHash(PGAContext *ctx, int p, int pop)

Return hash value of given gene.

Description

Note that this function is set in PGASetUp() as the hash user function for the char datatype by default.

Parameters
  • ctx – context variable

  • p – string index of the string to hash

  • pop – symbolic constant of the population string p is in

Returns

Hash value for string

void PGACharacterInitString(PGAContext *ctx, int p, int pop)

Randomly initialize a string of type character.

Description

Note that this function is set in PGASetUp() as the init string user function for the char datatype by default.

Example

PGAContext *ctx;
int p;

...
PGACharacterInitString (ctx, p, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p – index of string to randomly initialize

  • pop – symbolic constant of the population string p is in

Returns

None

int PGACharacterMutation(PGAContext *ctx, int p, int pop, double mr)

Randomly mutates a character-valued gene with a specified probability.

Description

This routine is called from PGAMutate().

Note that this function is set in PGASetUp() as the mutation user function for the char datatype by default.

Example

PGAContext *ctx;
int p;
int NumMutations;

...
NumMutations = PGACharacterMutation (ctx, p, PGA_NEWPOP, 0.01);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population string p is in

  • mr – probability of mutating an character-valued gene

Returns

Returns the number of mutations

void PGACharacterOneptCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2)

Perform one-point crossover on two parent strings producing two children via side-effect.

Description

Note that this function is set in PGASetUp() as the crossover user function for the char datatype when selecting one-point crossover.

Example

Performs crossover on the two parent strings m and d, producing children s and b.

PGAContext *ctx;
int m, d, s, b;

...
PGACharacterOneptCrossover (ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – the first parent string

  • p2 – the second parent string

  • pop1 – symbolic constant of the population containing string p1 and p2

  • c1 – the first child string

  • c2 – the second child string

  • pop2 – symbolic constant of the population to contain string c1 and c2

Returns

None

void PGACharacterPrintString(PGAContext *ctx, FILE *fp, int p, int pop)

Write a character-valued string to a file.

Example

Write string s to stdout.

PGAContext *ctx;
int p;

...
PGACharacterPrintString (ctx, stdout, p, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • fp – file pointer to file to write the string to

  • p – index of the string to write out

  • pop – symbolic constant of the population string p is in

Returns

None

void PGACharacterTwoptCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2)

Perform two-point crossover on two parent strings producing two children via side-effect.

Description

Note that this function is set in PGASetUp() as the crossover user function for the char datatype when selecting two-point crossover.

Example

Performs crossover on the two parent strings m and d, producing children s and b.

PGAContext *ctx;
int m, d, s, b;

...
PGACharacterTwoptCrossover (ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – the first parent string

  • p2 – the second parent string

  • pop1 – symbolic constant of the population containing string p1 and p2

  • c1 – the first child string

  • c2 – the second child string

  • pop2 – symbolic constant of the population to contain string c1 and c2

Returns

None

void PGACharacterUniformCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2)

Perform uniform crossover on two parent strings producing two children via side-effect.

Description

Note that this function is set in PGASetUp() as the crossover user function for the char datatype when selecting uniform crossover.

Example

Performs crossover on the two parent strings m and d, producing children s and b.

PGAContext *ctx;
int m, d, s, b;

...
PGACharacterUniformCrossover (ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – the first parent string

  • p2 – the second parent string

  • pop1 – symbolic constant of the population containing string p1 and p2

  • c1 – the first child string

  • c2 – the second child string

  • pop2 – symbolic constant of the population to contain string c1 and c2

Returns

None

int PGAComputeSimilarity(PGAContext *ctx, int popindex)

Compute the percentage of the population that have the same evaluation function.

Example

PGAContext *ctx;

...
PGAComputeSimilarity (ctx, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • popindex – symbolic constant of the population whose statistics to use

Returns

returns a count of the number of population members that have the same evaluation function value

static void PGACreateIndividual(PGAContext *ctx, int p, int pop, int initflag)

Initialize to zero various data structures of an individual and call the appropriate function to create and initialize the string for the specific data type.

Example

PGAContext *ctx;
int p;

...
PGACreateIndividual (ctx, p, PGA_NEWPOP, PGA_TRUE);

Parameters
  • ctx – Context variable

  • p – String index

  • pop – Symbolic constant of the population string p is in

  • initflag – If the value is PGA_TRUE, the string is randomly initialized, otherwise it is set to zero

Returns

None

static void PGACreatePop(PGAContext *ctx, int pop)

Allocate a population of individuals and calls PGACreateIndividual to set up each one.

Example

PGAContext *ctx;

...
PGACreatePop (ctx, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • pop – symbolic constant of the population to create

Returns

None

void PGACrossoverSBX(PGAContext *ctx, double p1, double p2, double u, double *c1, double *c2)

Cross over two parent alleles with simulated binary crossover (SBX).

Description

This uses double for both parent alleles but is re-used in both, integer and real SBX crossover in PGAIntegerSBXCrossover() and PGARealSBXCrossover(), respectively. The probability is used to compute the new alleles from the polynomial distribution.

Example

PGAContext *ctx;
double p1, p2, u;
double c1, c2;
double result;

...
u = PGARandom01 (ctx, 0);
result = PGACrossoverSBX (ctx, p1, p2, u, &c1, &c2);

Parameters
  • ctx – context variable

  • p1 – (double) Allele of first string

  • p2 – (double) Allele of second string

  • u – Random value between 0 and 1

  • c1 – pointer to new first child allele

  • c2 – pointer to new second child allele

Returns

None

int PGAEvalSortHelper(const void *a1, const void *a2)

Compare two PGAIndividual pointers for qsort.

Description

Used as the comparison function in qsort.

Parameters
  • a1 – void pointer to first individual

  • a2 – void pointer to second individual

Returns

-1 if less, 0 if equal, 1 if greater

static void PGAEvaluateCoop(PGAContext *ctx, int pop, double (*evaluate)(PGAContext*, int, int, double*), MPI_Comm comm)

Cooperative internal evaluation function.

Description

Evaluates all strings that need to be evaluated using two processors cooperatively. The first being the rank-0 process will send a string to the second for evaluation. While the second is evaluating, the rank-0 process will also evaluate a string.

Parameters
  • ctx – context variable

  • pop – symbolic constant of the population to be evaluated

  • evaluate – a pointer to a function to evaluate a string.

  • comm – an MPI communicator

Returns

None

static void PGAEvaluateMP(PGAContext *ctx, int pop, MPI_Comm comm)

Internal evaluation function, multiprocessing version.

Description

Evaluates all strings that need evaluating using three or more processors. The rank-0 process sends individuals to evaluate to all other processes and collects the results. The rank-0 process performs no evaluations itself.

Parameters
  • ctx – context variable

  • pop – symbolic constant of the population to be evaluated

  • comm – an MPI communicator

Returns

None

static void PGAEvaluateSeq(PGAContext *ctx, int pop, double (*evaluate)(PGAContext*, int, int, double*))

Sequential internal evalution function.

Description

Evaluates all strings that need to be evaluated using one processor.

Parameters
  • ctx – context variable

  • pop – symbolic constant of the population to be evaluated

  • evaluate – a pointer to a function to evaluate a string.

static void PGAEvaluateWorker(PGAContext *ctx, int pop, double (*evaluate)(PGAContext*, int, int, double*), MPI_Comm comm)

Evaluation worker routine.

Description

Sit around and wait for a string to eval to show up, then evaluate it and return the evaluation. Terminates when it receives PGA_COMM_DONEWITHEVALS.

Parameters
  • ctx – context variable

  • pop – symbolic constant of the population to be evaluated

  • evaluate – a pointer to a function to evaluate a string.

  • comm – an MPI communicator

Returns

None

static void PGAFitnessLinearNormal(PGAContext *ctx, int popindex)

Calculates fitness using a ranking method and linear ordering.

Description

The fitness function is of the form \(u(x) = K - (\text{rank} \cdot \sigma)\) with the constant \(K\) equal to the mean of the evaluation functions, and the decrement \(\sigma\) equal to the standard deviation of the same as defined by Davis [Dav91], p.33.

Parameters
  • ctx – context variable

  • popindex – population index to calculate fitness for

Returns

Calculates the fitness for each string in the population via side effect

static void PGAFitnessLinearRank(PGAContext *ctx, int popindex)

Calculate fitness using linear ranking.

Description

The fitness function is of the form

\[\frac{1}{N} \cdot \left(\max - (\max-\min) * \frac{i-1}{N-1}\right)\]

where \(\min = 2-\max\) and \(1 \le \max \le 2\). See Baker [Bak87], Bäck and Hoffmeister [BH91], Grefenstette and Baker [GB89] and Whitley’s linear function on p. 121 in [Whi89].

Parameters
  • ctx – context variable

  • popindex – population index to calculate fitness for

Returns

Calculates the fitness for each string in the population via side effect

static void PGAFitnessMinCmax(PGAContext *ctx, PGAIndividual *pop)

Calculate fitness in the case of a minimization problem by subtracting the worst evaluation function value from each evaluation function.

Description

This is a dynamic linear fitness function \(u(x) = a f(x) + b(t)\) with \(a=-1, b(t) = 1.1 * \max f(x)\)

Parameters
  • ctx – context variable

  • pop – population pointer to calculate fitness for

Returns

Calculates the fitness for each string in the population via side effect

static void PGAFitnessMinReciprocal(PGAContext *ctx, PGAIndividual *pop)

Calculate fitness in the case of a minimization problem using the reciprocal of the evaluation function.

Description

This is a power law \(u(x) = (a f(x) + b)^k\) with \(a=1, b=0, k=-1\).

Parameters
  • ctx – context variable

  • pop – population pointer to calculate fitness for

Returns

Calculates the fitness for each string in the population via side effect

size_t PGAIndividualHashIndex(PGAContext *ctx, int p, int pop)

Compute Hash for individual in given population.

Description

Call the hash user function, by default PGACreate() makes sure the correct one is set for the data type.

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population containing string p

Returns

Hash of given individual

MPI_Datatype PGAIntegerBuildDatatype(PGAContext *ctx, int p, int pop)

Build an MPI datatype for a string of data type integer.

Description

Called only by MPI routines. Not for user consumption.

Parameters
  • ctx – context variable

  • p – index of string

  • pop – symbolic constant of the population string p is in

Returns

MPI_Datatype

void PGAIntegerCopyString(PGAContext *ctx, int p1, int pop1, int p2, int pop2)

Copy one integer-valued string to another.

Description

Note that this function is set in PGASetUp() as the copy string user function for the integer datatype by default.

Parameters
  • ctx – context variable

  • p1 – string to copy

  • pop1 – symbolic constant of population containing string p1

  • p2 – string to copy p1 to

  • pop2 – symbolic constant of population containing string p2

Returns

None

void PGAIntegerCreateString(PGAContext *ctx, int p, int pop, int initflag)

Allocate memory for a string of type PGAInteger, and initializes or clears the string according to initflag.

Description

Note that this function is set in PGASetUp() as the create string user function for the integer datatype.

Example

Allocates and clears memory and assigns the address of the allocated memory to the string field ind->chrom of the individual.

PGAContext *ctx;
PGAIndividual *ind;

...
PGAIntegerCreateString (ctx, ind, PGA_FALSE);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population string p is in

  • initflag – A true/false flag used in conjunction with ctx->ga.RandomInit to initialize the string either randomly or set to zero

Returns

None

int PGAIntegerDuplicate(PGAContext *ctx, int p1, int pop1, int p2, int pop2)

Return true if string a is a duplicate of string b, else returns false.

Description

Note that this function is set in PGASetUp() as the duplicate checking user function for the integer datatype by default.

Parameters
  • ctx – context variable

  • p1 – string index of the first string to compare

  • pop1 – symbolic constant of the population string p1 is in

  • p2 – string index of the second string to compare

  • pop2 – symbolic constant of the population string p2 is in

Returns

Returns true/false if strings are duplicates

void PGAIntegerEdgeCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2)

Perform Edge Recombination on two parent strings producing two children via side-effect.

Description

Note that this function is set in PGASetUp() as the crossover user function for the integer datatype when selecting edge crossover.

Example

Performs crossover on the two parent strings m and d, producing children s and b.

PGAContext *ctx;
int m, d, s, b;

...
PGAIntegerEdgeCrossover (ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – the first parent string

  • p2 – the second parent string

  • pop1 – symbolic constant of the population containing string p1 and p2

  • c1 – the first child string

  • c2 – the second child string

  • pop2 – symbolic constant of the population to contain string c1 and c2

Returns

c1 and c2 in population pop2 are modified by side-effect.

double PGAIntegerGeneDistance(PGAContext *ctx, int p1, int pop1, int p2, int pop2)

Compute genetic distance of two strings.

Description

Sum of the absolute values of the differences of each allele. Internal function. Use PGAUserFunctionGeneDistance().

Parameters
  • ctx – context variable

  • p1 – first string index

  • pop1 – symbolic constant of the population the first string is in

  • p2 – second string index

  • pop2 – symbolic constant of the population the second string is in

Returns

genetic distance of the two strings

PGAHash PGAIntegerHash(PGAContext *ctx, int p, int pop)

Return hash value of given gene.

Description

Note that this function is set in PGASetUp() as the hash user function for the integer datatype by default.

Parameters
  • ctx – context variable

  • p – string index of the string to hash

  • pop – symbolic constant of the population string p is in

Returns

Hash value for string

void PGAIntegerInitString(PGAContext *ctx, int p, int pop)

Randomly initialize a string of data type integer.

Description

Note that this function is set in PGASetUp() as the init string user function for the integer datatype by default.

Parameters
  • ctx – context variable

  • p – index of string to randomly initialize

  • pop – symbolic constant of the population string p is in

Returns

None

int PGAIntegerMutation(PGAContext *ctx, int p, int pop, double mr)

Randomly mutates an integer-valued gene with a specified probability.

Description

This routine is called from PGAMutate().

Note that this function is set in PGASetUp() as the mutation user function for the integer datatype by default.

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population string p is in

  • mr – probability of mutating an integer-valued gene

Returns

Returns the number of mutations

void PGAIntegerOneptCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2)

Perform one-point crossover on two parent strings producing two children via side-effect.

Description

Note that this function is set in PGASetUp() as the crossover user function for the integer datatype when selecting one-point crossover.

Example

Performs crossover on the two parent strings m and d, producing children s and b.

PGAContext *ctx;
int m, d, s, b;

...
PGAIntegerOneptCrossover (ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – the first parent string

  • p2 – the second parent string

  • pop1 – symbolic constant of the population containing string p1 and p2

  • c1 – the first child string

  • c2 – the second child string

  • pop2 – symbolic constant of the population to contain string c1 and c2

Returns

c1 and c2 in population pop2 are modified by side-effect

void PGAIntegerPrintString(PGAContext *ctx, FILE *fp, int p, int pop)

Write an integer-valued string to a file.

Example

Write member p in population PGA_NEWPOP to stdout.

PGAContext *ctx;
int  p;

...
PGAIntegerPrintString (ctx, stdout, p, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • fp – file pointer to file to write the string to

  • p – index of the string to write out

  • pop – symbolic constant of the population string p is in

Returns

None

void PGAIntegerSBXCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2)

Performs simulated binary crossover (SBX) on two parent strings producing two children via side-effect.

Description

Note that this function is set in PGASetUp() as the crossover user function for the integer datatype when selecting simulated binary crossover.

Example

Performs crossover on the two parent strings m and d, producing children s and b.

PGAContext *ctx;
int m, d, s, b;

...
PGAIntegerSBXCrossover (ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – the first parent string

  • p2 – the second parent string

  • pop1 – symbolic constant of the population containing string p1 and p2

  • c1 – the first child string

  • c2 – the second child string

  • pop2 – symbolic constant of the population to contain string c1 and c2

Returns

c1 and c2 in population pop2 are modified by side-effect.

void PGAIntegerTwoptCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2)

Perform two-point crossover on two parent strings producing two children via side-effect.

Description

Note that this function is set in PGASetUp() as the crossover user function for the integer datatype when selecting two-point crossover.

Example

Performs crossover on the two parent strings m and d, producing children s and b.

PGAContext *ctx;
int m, d, s, b;

...
PGAIntegerTwoptCrossover (ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – the first parent string

  • p2 – the second parent string

  • pop1 – symbolic constant of the population containing string p1 and p2

  • c1 – the first child string

  • c2 – the second child string

  • pop2 – symbolic constant of the population to contain string c1 and c2

Returns

c1 and c2 in population pop2 are modified by side-effect

void PGAIntegerUniformCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2)

Perform uniform crossover on two parent strings producing two children via side-effect.

Description

Note that this function is set in PGASetUp() as the crossover user function for the integer datatype when selecting uniform crossover.

Example

Performs crossover on the two parent strings m and d, producing children s and b.

PGAContext *ctx;
int m, d, s, b;

...
PGAIntegerUniformCrossover (ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – the first parent string

  • p2 – the second parent string

  • pop1 – symbolic constant of the population containing string p1 and p2

  • c1 – the first child string

  • c2 – the second child string

  • pop2 – symbolic constant of the population to contain string c1 and c2

Returns

c1 and c2 in population pop2 are modified by side-effect

static double PGAMapIntegerToReal(PGAContext *ctx, int v, int a, int b, double l, double u)

Maps the value v defined on [a,b] to r defined on [l,u].

Description

In the context of PGAPack \([a,b]\) is the discrete interval \([0,2^{nbits}-1]\) (i.e., the number of bits in a binary string) and \([l,u]\) represent the range of possible values of the real number \(r\).

Example

Map a five bit (that is, an integer with a range of [0, 31]) integer 5 to a real in the range [0, 3.14].

PGAContext *ctx;
double x;

...
x = PGAMapIntegerToReal (ctx, 5, 0, 31, 0.0, 3.14);

Parameters
  • ctx – context variable

  • v – value from original interval (usually the decoded bit string)

  • a – lower bound of integer interval

  • b – upper bound of integer interval

  • l – lower bound of real interval

  • u – upper bound of real interval

Returns

Scaled value of v defined on [l,u]

static int PGAMapRealToInteger(PGAContext *ctx, double r, double l, double u, int a, int b)

Map the value r defined on [l,u] to v defined on [a,b].

Description

In the context of PGAPack \([a,b]\) is the discrete interval \([0,2^{nbits}-1]\) (i.e., the number of bits in a binary string) and \([l,u]\) represent the range of possible values of the real number \(r\).

Example

Map the value r on the interval [0, 3.14] to a five bit integer v.

PGAContext *ctx;
double r;
int v;

...
v = PGAMapRealToInteger (ctx, r, 0.0, 3.14, 0, 31);

Parameters
  • ctx – context variable

  • r – real value defined on [l,u]

  • l – lower bound of real interval

  • u – upper bound of real interval

  • a – lower bound of integer interval

  • b – upper bound of integer interval

Returns

Scaled value of r defined on [a,b]

static void PGAParseDebugArg(PGAContext *ctx, char *st)

Routine to parse debug command line options, and set the appropriate debug level.

Description

Internal function. Called only by PGAReadCmdLine(). Uses PGASetDebugLevel() for setting the debug level.

Parameters
  • ctx – context variable

  • st – debug command line options

Returns

None

MPI_Datatype PGARealBuildDatatype(PGAContext *ctx, int p, int pop)

Build an MPI datatype for a string.

Example

PGAContext   *ctx;
int           p;
MPI_Datatype  dt;

...
dt = PGARealBuildDatatype(ctx, p, pop);

Parameters
  • ctx – context variable

  • p – index of string

  • pop – symbolic constant of population string p is in

Returns

An MPI_Datatype

void PGARealCopyString(PGAContext *ctx, int p1, int pop1, int p2, int pop2)

Copy one real-valued string string to another.

Description

Note that this function is set in PGASetUp() as the copy string user function for the real datatype by default.

Example

Copy string x in old population to y in new population.

PGAContext *ctx;
int x, y;

...
PGARealCopyString (ctx, x, PGA_OLDPOP, y, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – string to copy

  • pop1 – symbolic constant of population containing string p1

  • p2 – string to copy p1 to

  • pop2 – symbolic constant of population containing string p2

Returns

String p2 in population pop2 is modified to be a copy of string p1 in population pop1.

void PGARealCreateString(PGAContext *ctx, int p, int pop, int initflag)

Allocate memory for a string of type real.

Description

Note that this function is set in PGASetUp() as the create string user function for the real datatype by default. Parameter initflag is used in conjunction with ctx->ga.RandomInit to initialize the string either randomly or set to zero.

Example

Allocates memory and assigns the address of the allocated memory to the real string field ind->chrom of the individual. Also, clears the string.

PGAContext *ctx;
int p;

...
PGARealCreateString (ctx, p, PGA_NEWPOP, PGA_FALSE);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population string p is in

  • initflag – A boolean flag to indicate random initialization

Returns

None

int PGARealDuplicate(PGAContext *ctx, int p1, int pop1, int p2, int pop2)

Returns true if real-valued string a is a duplicate of real-valued string b, else returns false.

Description

Note that this function is set in PGASetUp() as the duplicate checking user function for the real datatype by default.

Example

Compare strings x with y to see if they are duplicates.

PGAContext *ctx;
int x, y;

...
if (PGARealDuplicate (ctx, x, PGA_OLDPOP, y, PGA_OLDPOP)) {
    printf ("strings are duplicates\n");
}

Parameters
  • ctx – context variable

  • p1 – string index of the first string to compare

  • pop1 – symbolic constant of the population string p1 is in

  • p2 – string index of the second string to compare

  • pop2 – symbolic constant of the population string p2 is in

Returns

Returns true/false if strings are duplicates

double PGARealGeneDistance(PGAContext *ctx, int p1, int pop1, int p2, int pop2)

Compute genetic difference of two strings.

Description

Sum of the absolute values of the differences of each allele. So this is a Manhattan distance (mainly for performance reasons). Internal function. Use PGAUserFunctionGeneDistance().

Parameters
  • ctx – context variable

  • p1 – first string index

  • pop1 – symbolic constant of the population the first string is in

  • p2 – second string index

  • pop2 – symbolic constant of the population the second string is in

Returns

genetic distance of the two strings

PGAHash PGARealHash(PGAContext *ctx, int p, int pop)

Return hash value of given gene.

Description

Note that this function is set in PGASetUp() as the hash user function for the real datatype by default.

Parameters
  • ctx – context variable

  • p – string index of the string to hash

  • pop – symbolic constant of the population string p is in

Returns

Hash value for string

void PGARealInitString(PGAContext *ctx, int p, int pop)

Randomly initialize a string of type real.

Description

Note that this function is set in PGASetUp() as the init string user function for the real datatype by default.

Example

PGAContext *ctx;
int p;

...
PGARealInitString (ctx, p, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p – index of string to randomly initialize

  • pop – symbolic constant of the population string p is in

Returns

String p in population pop is randomly initialized by side-effect

int PGARealMutation(PGAContext *ctx, int p, int pop, double mr)

Randomly mutates a floating point string with probability mr.

Description

Three of the four mutation operators are of the form \(v = v +- p \cdot v\). That is, the new value of \(v\) (allele \(i\)) is the old value + or - a percentage, \(p\), of the old value. There are three possibilities for choosing \(p\): (1) constant value (0.01 by default), (2) selected uniformly on \((0,\text{UB})\) (UB is .1 by default), and (3) selected from a Gaussian distribution (with mean 0 and standard deviation .1 be default). The change to an allele, \(p \cdot v\), is added or subtracted to the old value with a probability of .5. The fourth option is to replace \(v\) with a value selected uniformly random from the initialization range of that gene. Alleles to mutate are randomly selected. The value set by the routine PGASetMutationRealValue() is used as \(p\), UB, and sigma in cases 1, 2, and 3, respectively.

Note that this function is set in PGASetUp() as the mutation user function for the real datatype by default.

Example

Mutate string p in population PGA_NEWPOP with probability 0.001.

PGAContext *ctx;
int NumMutations, p;

...
NumMutations = PGARealMutation (ctx, p, PGA_NEWPOP, .001);

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population string p is in

  • mr – probability of mutating a real-valued gene

Returns

The number of mutations performed

void PGARealOneptCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2)

This routine performs one point crossover on two parent strings, producing (via side effect) the crossed children child1 and child2.

Description

Note that this function is set in PGASetUp() as the crossover user function for the real datatype when selecting one-point crossover.

Example

Performs crossover on the two parent strings m and d, producing children s and b.

PGAContext *ctx;
int m, d, s, b;

...
PGARealOneptCrossover (ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – the first parent string

  • p2 – the second parent string

  • pop1 – symbolic constant of the population containing string p1 and p2

  • c1 – the first child string

  • c2 – the second child string

  • pop2 – symbolic constant of the population to contain string c1 and c2

Returns

c1 and c2 in population pop2 are modified by side-effect

void PGARealPrintString(PGAContext *ctx, FILE *fp, int p, int pop)

Write a real-valued string to a file.

Example

Write string s to stdout.

PGAContext *ctx;
int s;

...
PGARealPrintString (ctx, stdout, s, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • fp – file pointer to file to write the string to

  • p – index of the string to write out

  • pop – symbolic constant of the population string p is in

Returns

None

void PGARealSBXCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2)

Perform simulated binary crossover (SBX) on two parent strings producing two children via side-effect.

Description

Note that this function is set in PGASetUp() as the crossover user function for the real datatype when selecting simulated binary crossover.

Example

Performs crossover on the two parent strings m and d, producing children s and b.

PGAContext *ctx;
int m, d, s, b;

...
PGARealSBXCrossover (ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – the first parent string

  • p2 – the second parent string

  • pop1 – symbolic constant of the population containing string p1 and p2

  • c1 – the first child string

  • c2 – the second child string

  • pop2 – symbolic constant of the population to contain string c1 and c2

Returns

c1 and c2 in population pop2 are modified by side-effect

void PGARealTwoptCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2)

Perform two-point crossover on two parent strings producing two children via side-effect.

Description

Note that this function is set in PGASetUp() as the crossover user function for the real datatype when selecting two-point crossover.

Example

Performs crossover on the two parent strings m and d, producing children s and b.

PGAContext *ctx;
int m, d, s, b;

...
PGARealTwoptCrossover (ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – the first parent string

  • p2 – the second parent string

  • pop1 – symbolic constant of the population containing string p1 and p2

  • c1 – the first child string

  • c2 – the second child string

  • pop2 – symbolic constant of the population to contain string c1 and c2

Returns

c1 and c2 in population pop2 are modified by side-effect

void PGARealUniformCrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2)

Perform uniform crossover on two parent strings producing two children via side-effect.

Description

Note that this function is set in PGASetUp() as the crossover user function for the real datatype when selecting uniform crossover.

Example

Performs crossover on the two parent strings m and d, producing children s and b.

PGAContext *ctx;
int m, d, s, b;

...
PGARealUniformCrossover (ctx, m, d, PGA_OLDPOP, s, b, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • p1 – the first parent string

  • p2 – the second parent string

  • pop1 – symbolic constant of the population containing string p1 and p2

  • c1 – the first child string

  • c2 – the second child string

  • pop2 – symbolic constant of the population to contain string c1 and c2

Returns

c1 and c2 in population pop2 are modified by side-effect

static void PGAReceiveEvaluation(PGAContext *ctx, int p, int pop, int source, int tag, MPI_Comm comm, MPI_Status *status)

Receive evaluation and aux eval from another process.

Example

Receive evaluation from sub-process and place it into the first temporary location in PGA_NEWPOP.

PGAContext *ctx;
MPI_Comm    comm;
MPI_Status  status;

...
PGAReceiveEvaluation
  (ctx, PGA_TEMP1, PGA_NEWPOP, 0, PGA_COMM_EVALOFSTRING, comm, &status);

Parameters
  • ctx – contex variable

  • p – index of an individual

  • pop – symbolic constant of the population

  • source – ID of the process from which to receive

  • tag – MPI tag to look for

  • comm – an MPI communicator

  • status – pointer to an MPI status structure

Returns

string p in population pop is changed by side-effect

static int PGASelectLinear(PGAContext *ctx, PGAIndividual *pop)

Choose all strings that are not already copied to the next generation due to elitist strategies.

Description

Note that this ‘selection’ scheme isn’t a selection scheme in the genetic sense, it has no selection pressure. Note that the indeces are not randomized.

Example

PGAContext *ctx,
int l;

...
l = PGASelectLinear (ctx, PGA_OLDPOP);

Parameters
  • ctx – context variable

  • pop – pointer to first individual of population

Returns

index of the selected string

int PGASelectPTournament(PGAContext *ctx, int pop)

Choose two strings randomly and return the one with better evaluation with a specified probability.

Description

See description in Goldbergs classic book [Gol89], p. 121.

Example

PGAContext *ctx,
int l;

...
l = PGASelectPTournament (ctx, PGA_OLDPOP);

Parameters
  • ctx – context variable

  • pop – symbolic constant of population to select from

Returns

index of the selected string

static int PGASelectProportional(PGAContext *ctx, PGAIndividual *pop)

Select a parent for the next generation using a linear search through a (fitness) weighted ‘roulette wheel’.

Description

The probability of selection of individual \(i\) with fitness \(f_i\) is given by Goldberg [Gol89], p. 11 as \(p_i = \frac{f_i}{\sum_{i} f_i}\)

Example

PGAContext *ctx,
int l;

...
l = PGASelectProportional (ctx, PGA_OLDPOP);

Parameters
  • ctx – context variable

  • pop – pointer to first individual of population

Returns

index of the selected string

static void PGASelectSUS(PGAContext *ctx, PGAIndividual *pop)

A select routine using stochastic universal sampling.

Description

Perform stochastic universal sampling selection [Bak87], p. 16. This routine creates the entire selected population with one call.

Example

PGAContext *ctx,

...
PGASelectSUS (ctx, PGA_OLDPOP);

Parameters
  • ctx – context variable

  • pop – pointer to first individual of population

Returns

the array ga.selected [] created via side effect.

static int PGASelectTournament(PGAContext *ctx, int pop)

Choose N strings randomly and return the one with best evaluation.

Description

The configuration parameter N is the value set with PGASetTournamentSize(), the default is 2. Depending on the setting of PGASetTournamentWithReplacement() calls one of two local functions to use the right sampling.

Example

PGAContext *ctx,
int l;

...
l = PGASelectTournament (ctx, PGA_OLDPOP);

Parameters
  • ctx – context variable

  • pop – symbolic constant of population to select from

Returns

index of the selected string

static int PGASelectTournamentWithReplacement(PGAContext *ctx, int pop)

Choose N strings randomly and return the one with best evaluation.

Description

The configuration parameter N is the value set with PGASetTournamentSize(), the default is 2. The selection happens with replacement. This is a generalization of Goldbergs description [Gol89], for the generalization see, e.g. in Goldberg and Deb [GD91].

Example

PGAContext *ctx,
int l;

...
l = PGASelectTournamentWithReplacement (ctx, PGA_OLDPOP);

Parameters
  • ctx – context variable

  • pop – symbolic constant of population to select from

Returns

index of the selected string

static int PGASelectTournamentWithoutReplacement(PGAContext *ctx, int pop)

Choose N strings randomly and return the one with best evaluation.

Description

The configuration parameter N is the value set with PGASetTournamentSize(), the default is 2. The selection happens without replacement. This means if we select N individuals with a tournament size of 2, each individual is participating in exactly two tournaments. This does not mean that a single individual cannot be returned more than once. For implementation notes on the algorithm see [GKD89], p. 504.

Example

PGAContext *ctx,
int l;

...
l = PGASelectTournamentWithoutReplacement (ctx, PGA_OLDPOP);

Parameters
  • ctx – context variable

  • pop – symbolic constant of population to select from

Returns

index of the selected string

int PGASelectTruncation(PGAContext *ctx, int pop)

Choose the best k strings and return them in random order.

Description

The value k is (N * TruncationProportion) rounded to the next integer.

Example

PGAContext *ctx,
int l;

...
l = PGASelectTruncation (ctx, PGA_OLDPOP);

Parameters
  • ctx – context variable

  • pop – symbolic constant of population to select from

Returns

index of the selected string

static void PGASendEvaluation(PGAContext *ctx, int p, int pop, int dest, int tag, MPI_Comm comm)

Transmit evaluation and aux eval to another process.

Example

PGAContext *ctx;
int p, dest;

...
dest = SelectAFreeProcessor ();
PGASendEvaluation (ctx, p, PGA_NEWPOP, dest, PGA_COMM_EVALOFSTRING, comm);

Parameters
  • ctx – context variable

  • p – index of an individual

  • pop – symbolic constant of the population

  • dest – ID of the process where this is going

  • tag – MPI tag to send with the individual

  • comm – MPI communicator

MPI_Datatype PGASerializedBuildDatatype(PGAContext *ctx, int p, int pop)

Build datatype from serialized data.

Description

This is the default function for the BuildDatatype user function if serialization is in use.

Parameters
  • ctx – context variable

  • p – index of string

  • pop – symbolic constant of the population string p is in

Returns

An MPI_Datatype

double PGASetupDE(PGAContext *ctx, int p, int pop, int maxidx, int *idx)

Helper function for differential evolution, used by both, the integer and the real implementations.

Parameters
  • ctx – context variable

  • p – string index

  • pop – symbolic constant of the population the string is in

  • maxidx – maximum index of DE vectors needed

  • idx – indeces of population members

Returns

dither value

void PGASortFuncNameIndex(PGAContext *ctx)

Sort the index of function names alphabetically.

Description

Only used internally by PGACreate().

Parameters
  • ctx – context variable

Returns

None

static void PGAStripArgs(char **argv, int *argc, int *c, int num)

Code to strip arguments out of command list.

Description

Internal function. Called only by PGAReadCmdLine().

Parameters
  • argc – address of the count of the number of command line arguments

  • argv – array of command line arguments

  • c – current command-line index

  • num – number of args to strip

Returns

None

void PGAUpdateAverage(PGAContext *ctx, int pop)

Update the average fitness statistic for reporting.

Description

Note that in the presence of constraints only the unconstrained function evaluations are averaged, except for the constraint-functions, these are averaged unconditionally.

Parameters
  • ctx – context variable

  • pop – symbolic constant of the population

Returns

None

void PGAUpdateBest(PGAContext *ctx, int popix)

Updates the best fitness statistic for reporting.

Description

Note that in the presence of constraints if no individual without constraints is found, the best value (for all functions except constraint functions) is NAN.

Parameters
  • ctx – context variable

  • popix – symbolic constant of the population

Returns

None

void PGAUpdateOffline(PGAContext *ctx, int pop)

Update the offline value based on the results in the new generation.

Description

Note that in the presence of constraints only the unconstrained best function evaluations are averaged, except for the constraint-functions, these are averaged unconditionally.

Example

PGAContext *ctx;

...
PGAUpdateOffline (ctx, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • pop – symbolic constant of the population whose statistics to use

Returns

Updates an internal field in the context variable

void PGAUpdateOnline(PGAContext *ctx, int pop)

Update the online value based on the results in the new generation.

Description

Note that in the presence of constraints only the unconstrained function evaluations are averaged, except for the constraint-functions, these are averaged unconditionally.

Example

PGAContext *ctx;

...
PGAUpdateOnline (ctx, PGA_NEWPOP);

Parameters
  • ctx – context variable

  • pop – symbolic constant of the population whose statistics to use

Returns

Updates an internal field in the context variable

static void PGA_NSGA_Replacement(PGAContext *ctx, crowding_t crowding_method)

Perform NSGA Replacement.

Description

  • Perform dominance computation (ranking)

  • Perform crowding computation specific to the NSGA-Variant given as the parameter crowding_method

  • Sort individuals and replace into next generation

Note that the crowding_method makes the difference between NSGA-II and NSGA-III.

Parameters
  • ctx – context variable

  • crowding_method – Method used for crowding sort

Returns

None

static int dasdennis(int dim, int npart, int depth, int sum, void *p)

Static recursive function for LIN_dasdennis.

Parameters
  • dim – dimension

  • npart – Number of partitions

  • depth – Recursion depth

  • sum – Number of points so far

  • p – Pointer to created points, memory must be already allocated

Returns

The number of points allocated

static void dasdennisscale(int dim, int npoints, double scale, double *dir, void *v)

Static function for LIN_dasdennis scaling of points.

Description

When scaling we translate the scaled-down points from the centroid of the shifted points to the reference direction on the reference plane.

Parameters
  • dim – dimension

  • npoints – Number of points

  • scale – Scaling factor

  • dir – Direction vector

  • v – Pointer to points, points must have been created

Returns

None

Linear Algebra

group linalg

Functions

double LIN_2norm(int dim, double *v)

Euclidian norm (2-norm) of a vector.

Parameters
  • dim – size of the vectors

  • v – vector of length n

Returns

The euclidian norm of v

size_t LIN_binom(int a, int b)

Compute binomial coefficient of two integers.

Description

Computes \(\binom{a}{b}\)

Parameters
  • a – first integer

  • b – second integer

Returns

Binomial coefficient

void LIN_dasdennis_allocated(int dim, int npart, double scale, double *dir, int npoints, void *mem)

Compute Das & Dennis points to allocated memory.

Description

This is the case where the memory is already allocated. For more details see LIN_dasdennis().

Parameters
  • dim – dimension

  • npart – Number of partitions

  • scale – Scaling factor

  • dir – Direction vector

  • npoints – Number of points

  • mem – Memory for points, memory must have been allocated

Returns

None

double LIN_dot(int dim, double *v1, double *v2)

Dot product of two vectors.

Parameters
  • dim – size of the vectors

  • v1 – first vector of length n

  • v2 – second vector of length n

Returns

The dot product of v1 and v2

double LIN_euclidian_distance(int dim, double *v1, double *v2)

Euclidian distance of two vectors.

Parameters
  • dim – size of the vectors

  • v1 – first vector of length n

  • v2 – second vector of length n

Returns

The euclidian distance of v1 and v2

int LIN_gcd(int a, int b)

Greatest common divisor of two integers.

Parameters
  • a – first integer

  • b – second integer

Returns

The greatest common divisor (gcd) of a and b

void LIN_normalize_to_refplane(int dim, double *v)

Normalize a vector with dimension dim to the n-dimensional reference hyperplane.

Description

Hyperplane is probably a misnomer, it’s a 3-dimensional tetraeder for dimension 4. It is a plane for the 3-dimensional case going through the point 1 on each axis.

Parameters
  • dim – dimension

  • v – vector of dimension dim

Returns

The vector v is modified in-place

void LIN_print_matrix(int n, void *a)

Print matrix.

Description

Print matrix \(a\). Mainly used for testing.

Parameters
  • n – size of the matrix

  • a – n * n matrix

Returns

None

void LIN_print_vector(int n, double *v)

Print vector.

Description

Print vector \(v\). Mainly used for testing.

Parameters
  • n – size of the vector

  • v – vector of length n

Returns

None

int LIN_solve(int n, void *a, double *b)

Solve a linear matrix equation, or system of linear scalar equations.

Description

Linear matrix equation \(ax = b\)

Parameters
  • n – size of the matrix

  • a – n * n matrix

  • b – vector of lenth n

Returns

0 if no error, a positive error-code otherwise, returns the solution in b, a and b are modified in-place

Not Yet Implemented

group notimplemented

Not yet implemented, mainly used for island/multiple demes.

Functions

int PGAGetNumDemes(PGAContext *ctx)

Returns the number of demes to use in a neighborhood model.

Example

PGAContext *ctx;
int npop;

...
npop = PGAGetNumDemes (ctx);

Parameters
  • ctx – context variable

Returns

The number of demes to use in a neighborhood model

int PGAGetNumIslands(PGAContext *ctx)

Returns the number of islands to use in an island model.

Example

PGAContext *ctx;
int npop;

...
npop = PGAGetNumIslands (ctx);

Parameters
  • ctx – context variable

Returns

The number of islands to use in an island model

void PGAPrintVersionNumber(PGAContext *ctx)

Print PGAPack version number.

Description

This currently prints a meaningless hard-coded string.

Example

PGAContext ctx;

...
PGAPrintVersionNumber (ctx);

Parameters
  • ctx – context variable

Returns

print PGAPack version number

void PGARunIM(PGAContext *ctx, double (*evaluate)(PGAContext *c, int p, int pop, double *aux), MPI_Comm comm)

Execute the island model genetic algorithm.

Description

Not yet implemented. Based on ctx->par.topology this routine will need to create the appropriate communicator out of comm.

Example

PGAContext *ctx,
double f (PGAContext *ctx, int p, int pop, double *aux);
MPI_Comm comm;

...
PGARunIM (ctx, f, comm);

Parameters
  • ctx – context variable

  • evaluate – a pointer to the user’s evaluation function, which must have the calling sequence shown in the example.

  • comm – the MPI communicator to use

Returns

None

void PGARunNM(PGAContext *ctx, double (*evaluate)(PGAContext *c, int p, int pop, double *aux), MPI_Comm comm)

Execute a neighborhood model genetic algorithm.

Description

Not yet implemented. Based on ctx->par.topology this routine will need to create the appropriate communicator out of comm.

Example

PGAContext *ctx,
MPI_Comm comm;
double f (PGAContext *ctx, int p, int pop);

...
PGARunNM (ctx, f, comm);

Parameters
  • ctx – context variable

  • evaluate – a pointer to the user’s evaluation function, which must have the calling sequence shown in the example.

  • comm – the MPI communicator to use

Returns

None

void PGASetNumDemes(PGAContext *ctx, int numdemes)

Set the number of demes to use in a neighborhood model GA.

Description

Currently must be the same as the number of processes in the default communicator. The default is one.

Example

PGAContext *ctx,
double f (PGAContext *ctx, int p, int pop, double *aux);

ctx = PGACreate (&argc, argv, PGA_DATATYPE_BINARY, 100, PGA_MAXIMIZE);
PGASetNumDemes (ctx, 4);
PGASetUp (ctx);
PGARun (ctx, f);
PGADestroy (ctx);

Parameters
  • ctx – context variable

  • numdemes – number of demes

Returns

None

void PGASetNumIslands(PGAContext *ctx, int n)

Set the number of islands to use in an island model GA.

Description

The default is one. Currently must be the same as the number of processes in the default communicator.

Example

PGAContext *ctx,
double f (PGAContext *ctx, int p, int pop, double *aux);

ctx = PGACreate (&argc, argv, PGA_DATATYPE_BINARY, 100, PGA_MAXIMIZE);
PGASetNumIslands (ctx, 10);
PGASetUp (ctx);
PGARun (ctx, f);
PGADestroy (ctx);

Parameters
  • ctx – context variable

  • n – number of islands

Returns

None

Constant Definitions

Boolean Constants

group const-bool

Constants for booleans.

Defines

PGA_TRUE

True value

PGA_FALSE

False value.

Crossover Constants

group const-crossover

Constants for crossover variants.

Defines

PGA_CROSSOVER_ONEPT

One point crossover

PGA_CROSSOVER_TWOPT

Two point crossover (default)

PGA_CROSSOVER_UNIFORM

Uniform crossover

PGA_CROSSOVER_SBX

Simulated binary crossover (SBX)

PGA_CROSSOVER_EDGE

Edge Recombination

Constants for Datatypes

group const-datatype

Abstract Data Types.

Defines

PGA_DATATYPE_BINARY

Array of unsigned ints parsed into bits.

PGA_DATATYPE_INTEGER

Array of ints.

PGA_DATATYPE_REAL

Array of doubles.

PGA_DATATYPE_CHARACTER

Array of characters.

PGA_DATATYPE_USER

user defined data type

Typedefs

typedef unsigned long PGABinary

Allele data type binary (bit)

typedef signed long int PGAInteger

Allele data type int.

typedef double PGAReal

Allele data type real.

typedef signed char PGACharacter

Allele data type char.

typedef unsigned int PGAHash

Result of hashing.

Debugging Constants

group const-debug

Debug Levels.

Defines

PGA_DEBUG_ENTERED

Entering a function.

PGA_DEBUG_EXIT

Exiting a function

PGA_DEBUG_MALLOC

Memory management

PGA_DEBUG_PRINTVAR

Variables

PGA_DEBUG_SEND

Sending

PGA_DEBUG_RECV

Receiving

PGA_DEBUG_MAXFLAGS

All debug flags

Differential Evolution Crossover Constants

group const-de-cross

Constants for Differential Evolution Crossover Variants.

Defines

PGA_DE_CROSSOVER_BIN

Standard DE binomial crossover.

PGA_DE_CROSSOVER_EXP

Exponential crossover

Constants for Differential Evolution Variants

group const-de-variant

Constants for Differential Evolution Variants.

Defines

PGA_DE_VARIANT_RAND

Standard DE from random string (default)

PGA_DE_VARIANT_BEST

Derive from best string.

PGA_DE_VARIANT_EITHER_OR

Either-or variant.

Constants for Epsilon Constraints

group const-eps

Constants for epsilon constraints algorithm.

Defines

PGA_EPSILON_EXPONENT_MIN

minimum exponent cp from paper

PGA_EPSILON_EXPONENT_MAX

maximum exponent cp from paper

Constants for Error Printing

group const-err-print

Constants for error printing.

Use these with PGAError or better use PGAErrorPrintf.

Defines

PGA_INT

integer value for printing

PGA_DOUBLE

double value for printing

PGA_CHAR

char value for printing

PGA_VOID

void (no) value for printing

Constants for Fitness Types

group const-fitness

Constants for fitness variants.

Defines

PGA_FITNESS_RAW

use raw fitness (evaluation) (default)

PGA_FITNESS_NORMAL

linear normalization fitness

PGA_FITNESS_RANKING

linear ranking fitness

Constants for Fitness Minimization Strategies

group const-fitness-min

Constants for fitness minimization variants.

Defines

PGA_FITNESSMIN_RECIPROCAL

reciprocal fitness

PGA_FITNESSMIN_CMAX

cmax fitness (default)

Miscellaneous Constants

group const-misc

Misc Constants.

Defines

PGA_TEMP1

temporary individual 1

PGA_TEMP2

temporary individual 2

PGA_OLDPOP

Old population.

PGA_NEWPOP

New population.

PGA_UNINITIALIZED_INT

Un-initialized integer.

PGA_UNINITIALIZED_DOUBLE

Un-initialized double

Constants for Mixing Variants

group const-mixing

Constants for defining mixing variants.

This defines how mutation/crossover are combined (or not) The MUTATE_AND_CROSS variant performs mutation only if crossover was also performed. The TRADITIONAL variant performs mutation with the configured probability and then mutates with the given probability regardless if crossover was performed or not (this is the way all traditional implementations of GA are handling it). Note: This replaces the previous flags (PGASetMutationOrCrossoverFlag and friends) which are still supported for legacy reasons. The default is PGA_MIX_MUTATE_OR_CROSS also for legacy reasons.

Defines

PGA_MIX_MUTATE_OR_CROSS

Either mutation or crossover (default)

PGA_MIX_MUTATE_AND_CROSS

Mutation only if crossover.

PGA_MIX_MUTATE_ONLY

Only mutation.

PGA_MIX_TRADITIONAL

Mutation after crossover (also when no mutation occurs due to randomness)

Constants for MPI Send/Receive Tags

group const-mpitag

MPI Send/Recv Tags.

Defines

PGA_COMM_STRINGTOEVAL

MPI tag for sending string

PGA_COMM_EVALOFSTRING

MPI tag for returning evaluation.

PGA_COMM_DONEWITHEVALS

MPI tag for ending parallel eval.

PGA_COMM_SERIALIZE_SIZE

MPI tag for serialized data size.

Constants for Mutation Types

group const-mutation

Constants for mutation variants.

The defaults for Integer and Real data types are noted in the docs of the individual constants. For the Binary data type mutation is a random flip. For the Character data type, mutation selects a random character from the init range, see PGASetCharacterInitType().

Defines

PGA_MUTATION_CONSTANT

Real/Integer: Fixed value.

PGA_MUTATION_RANGE

Real/Integer: Uniform range.

PGA_MUTATION_UNIFORM

Real: +- Uniform random no.

PGA_MUTATION_GAUSSIAN

Real: +- Gaussian random number (default for Real data type)

PGA_MUTATION_PERMUTE

Integer: Permutation (swap) (default for Integer data type)

PGA_MUTATION_DE

Differential Evolution (only real)

PGA_MUTATION_POLY

Polynomial mutation.

Constants for Optimization Direction

group const-opt-dir

Optimization Direction (Maximize/Minimize).

Defines

PGA_MAXIMIZE

specify direction for fitness calc

PGA_MINIMIZE

specify direction for fitness calc

Constants for Population Replacement Strategies

group const-poprep

Constants for population replacement variants.

Defines

PGA_POPREPL_BEST

Select best string (default)

PGA_POPREPL_RANDOM_NOREP

Select random string w/o replacement.

PGA_POPREPL_RANDOM_REP

Select random string w/ replacement.

PGA_POPREPL_RTR

Restricted tournament replacement

PGA_POPREPL_PAIRWISE_BEST

Pairwise compare old/newpop

PGA_POPREPL_NSGA_II

NSGA-II non-dominated sorting

PGA_POPREPL_NSGA_III

NSGA-III non-dominated sorting

Constants for Error Printing Flags

group const-printflags

Printing flags.

Defines

PGA_FATAL

Fatal error.

PGA_WARNING

Warning

Constants for Random Initialization of Genes

group const-randinit

Variants for random initialization of genes.

Defines

PGA_RINIT_PERCENT

real percent offset

PGA_RINIT_RANGE

real range (default)

PGA_IINIT_PERMUTE

integer permutation (default)

PGA_IINIT_RANGE

integer range (nonunique)

PGA_CINIT_LOWER

all lowercase letters (default)

PGA_CINIT_UPPER

all uppercase letters

PGA_CINIT_MIXED

both upper and lower case letters

Constants for Reporting

group const-rep

Reporting Options, multiple options can be defined.

Defines

PGA_REPORT_ONLINE

Print the online analysis

PGA_REPORT_OFFLINE

Print the offline analysis

PGA_REPORT_GENE_DISTANCE

Print the genetic distance

PGA_REPORT_HAMMING

For backwards compatibility, this used to be defined only for binary strings.

PGA_REPORT_STRING

Print the string

PGA_REPORT_WORST

Print the worst individual

PGA_REPORT_AVERAGE

Print average of the population.

Constants for Selection Types

group const-selection

Constants for selection variants.

Defines

PGA_SELECT_PROPORTIONAL

proportional selection

PGA_SELECT_SUS

stochastic universal selection

PGA_SELECT_TOURNAMENT

tournament selection (default)

PGA_SELECT_PTOURNAMENT

probabilistic tournament selection

PGA_SELECT_TRUNCATION

truncation selection

PGA_SELECT_LINEAR

linear selection

Constants for Stopping Conditions

group const-stop

Define when to stop, multiple conditions selectable.

Defines

PGA_STOP_MAXITER

Stop: for maximum iterations (default)

PGA_STOP_NOCHANGE

Stop: no change in best string

PGA_STOP_TOOSIMILAR

Stop: homogeneous population

Constants for User Functions

group const-ufun

Constants used for registering user functions.

Defines

PGA_USERFUNCTION_CREATESTRING

String create

PGA_USERFUNCTION_MUTATION

Custom Mutation

PGA_USERFUNCTION_CROSSOVER

Custom Crossover

PGA_USERFUNCTION_PRINTSTRING

Gene printing

PGA_USERFUNCTION_COPYSTRING

Gene copy

PGA_USERFUNCTION_DUPLICATE

Dupe checking

PGA_USERFUNCTION_INITSTRING

Gene init

PGA_USERFUNCTION_BUILDDATATYPE

Build MPI datatype

PGA_USERFUNCTION_STOPCOND

Stopping check

PGA_USERFUNCTION_ENDOFGEN

End of generation

PGA_USERFUNCTION_GEN_DISTANCE

Distance of genes

PGA_USERFUNCTION_GEN_DIFFERENCE

Only used for backward compatibility.

PGA_USERFUNCTION_PRE_EVAL

Start of generation.

PGA_USERFUNCTION_HASH

Gene hashing

PGA_USERFUNCTION_SERIALIZE

Serialization

PGA_USERFUNCTION_DESERIALIZE

De-serialization

PGA_USERFUNCTION_SERIALIZE_FREE

Free serialization

PGA_USERFUNCTION_CHROM_FREE

Free chromosome

PGA_NUM_USERFUNCTIONS

Count