Function PGASetUserFunction
Defined in File user.c
Function Documentation
-
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:
PGA_USERFUNCTION_CREATESTRING– String creationPGA_USERFUNCTION_MUTATION– MutationPGA_USERFUNCTION_CROSSOVER– CrossoverPGA_USERFUNCTION_PRINTSTRING– String OutputPGA_USERFUNCTION_COPYSTRING– DuplicationPGA_USERFUNCTION_DUPLICATE– Duplicate CheckingPGA_USERFUNCTION_GEN_DISTANCE– Genetic DistancePGA_USERFUNCTION_INITSTRING– InitializationPGA_USERFUNCTION_BUILDDATATYPE– MPI Datatype creationPGA_USERFUNCTION_HASH– Hashing of genesPGA_USERFUNCTION_CHROM_FREE– Free chromosome
The following need to be defined for serializing strings for transmission:
PGA_USERFUNCTION_SERIALIZE– Serialize userdefined genePGA_USERFUNCTION_DESERIALIZE– Deserialize userdefined genePGA_USERFUNCTION_SERIALIZE_FREE– Free serialized version
The following functions are always optional:
PGA_USERFUNCTION_STOPCOND– Stopping conditionsPGA_USERFUNCTION_ENDOFGEN– Auxiliary functions at the end of each generationPGA_USERFUNCTION_PRE_EVAL– Auxiliary functions before evaluation but after crossover and mutationPGA_USERFUNCTION_HILLCLIMB– Hillclimbing
Some of these functions 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 (for custom functions used with the builtin data types) and Custom Usage: New Data Types (for defining 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