Function PGAEvalCompare

Function Documentation

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