libfgen
0.1.15
Library for optimization using a genetic algorithm or particle swarm optimization
|
Data Structures | |
struct | FgenIndividual |
struct | FgenCacheEntry |
struct | FgenCache |
struct | FgenRNG |
struct | FgenPopulation |
Defines | |
#define | FGEN_RNG_STATE_SIZE 4096 |
#define | FGEN_FITNESS_PROPORTIONAL 1 |
#define | FGEN_SUBTRACT_MIN_FITNESS 2 |
#define | FGEN_SUBTRACT_MIN_FITNESS_DIV_2 3 |
#define | FGEN_STOCHASTIC_TYPE_MASK 3 |
#define | FGEN_ELITIST_ELEMENT 4 |
#define | FGEN_EXTINCTION_ELEMENT 8 |
#define | FGEN_STOCHASTIC 0 |
#define | FGEN_SUS 1 |
#define | FGEN_TOURNAMENT 2 |
#define | FGEN_RANK 3 |
#define | FGEN_KILL_TOURNAMENT_ELEMENT 16 |
#define | FGEN_ELITIST_STOCHASTIC (FGEN_STOCHASTIC | FGEN_ELITIST_ELEMENT) |
#define | FGEN_ELITIST_SUS (FGEN_SUS | FGEN_ELITIST_ELEMENT) |
#define | FGEN_ELITIST_SUS_WITH_EXTINCTION (FGEN_SUS | FGEN_ELITIST_ELEMENT | FGEN_EXTINCTION_ELEMENT) |
#define | FGEN_ELITIST_TOURNAMENT (FGEN_TOURNAMENT | FGEN_ELITIST_ELEMENT) |
#define | FGEN_ELITIST_TOURNAMENT_WITH_EXTINCTION (FGEN_TOURNAMENT | FGEN_ELITIST_ELEMENT | FGEN_EXTINCTION_ELEMENT) |
#define | FGEN_ELITIST_RANK (FGEN_RANK | FGEN_ELITIST_ELEMENT) |
#define | FGEN_KILL_TOURNAMENT (FGEN_TOURNAMENT | FGEN_KILL_TOURNAMENT_ELEMENT) |
#define | FGEN_INITIALIZATION_SEED 0 |
#define | FGEN_INITIALIZATION_CONTINUE 1 |
Typedefs | |
typedef void(* | FgenGenerationCallbackFunc )(FgenPopulation *pop, int generation) |
typedef double(* | FgenCalculateFitnessFunc )(const FgenPopulation *pop, const unsigned char *bitstring) |
typedef void(* | FgenSeedFunc )(FgenPopulation *pop, unsigned char *bitstring) |
typedef void(* | FgenMutationFunc )(FgenPopulation *pop, const unsigned char *parent, unsigned char *child) |
typedef void(* | FgenCrossoverFunc )(FgenPopulation *pop, const unsigned char *parent1, const unsigned char *parent2, unsigned char *child1, unsigned char *child2) |
Functions | |
FGEN_API FgenPopulation * | fgen_create (int population_size, int individual_size_in_bits, int data_element_size, FgenGenerationCallbackFunc fgen_generation_callback_func, FgenCalculateFitnessFunc fgen_calculate_fitness_func, FgenSeedFunc fgen_seed_func, FgenMutationFunc fgen_mutation_func, FgenCrossoverFunc fgen_crossover_func) |
FGEN_API void | fgen_initialize (FgenPopulation *pop, int population_size, int individual_size_in_bits, int data_element_size, FgenGenerationCallbackFunc fgen_generation_callback_func, FgenCalculateFitnessFunc fgen_calculate_fitness_func, FgenSeedFunc fgen_seed_func, FgenMutationFunc fgen_mutation_func, FgenCrossoverFunc fgen_crossover_func) |
FGEN_API void | fgen_set_parameters (FgenPopulation *pop, int selection_type, int selection_fitness_type, float crossover_probability_float, float mutation_per_bit_probability_float, float macro_mutation_probability_float) |
FGEN_API void | fgen_run (FgenPopulation *pop, int max_generation) |
FGEN_API void | fgen_run_threaded (FgenPopulation *pop, int max_generation) |
FGEN_API void | fgen_destroy (FgenPopulation *pop) |
FGEN_API void | fgen_run_archipelago (int nu_pops, FgenPopulation **pops, int max_generation) |
FGEN_API void | fgen_run_archipelago_threaded (int nu_pops, FgenPopulation **pops, int max_generation) |
FGEN_API void | fgen_run_steady_state (FgenPopulation *pop, int max_generation) |
FGEN_API void | fgen_run_steady_state_archipelago (int nu_pops, FgenPopulation **pops, int max_generation) |
FGEN_API void | fgen_run_steady_state_archipelago_threaded (int nu_pops, FgenPopulation **pops, int max_generation) |
FGEN_API void | fgen_set_mutation_probability (FgenPopulation *pop, float) |
FGEN_API void | fgen_set_macro_mutation_probability (FgenPopulation *pop, float) |
FGEN_API void | fgen_set_crossover_probability (FgenPopulation *pop, float) |
FGEN_API void | fgen_set_selection_fitness_type (FgenPopulation *pop, int) |
FGEN_API void | fgen_set_selection_type (FgenPopulation *pop, int) |
FGEN_API void | fgen_set_tournament_size (FgenPopulation *pop, int) |
FGEN_API void | fgen_set_data_element_size (FgenPopulation *pop, int) |
FGEN_API void | fgen_set_number_of_elites (FgenPopulation *pop, int) |
FGEN_API void | fgen_set_permutation_size (FgenPopulation *pop, int) |
FGEN_API void | fgen_set_user_data (FgenPopulation *pop, void *user_data) |
FGEN_API void | fgen_enable_cache (FgenPopulation *pop, int cache_size) |
FGEN_API void | fgen_enable_cache_on_archipelago (int nu_pops, FgenPopulation **pops, int cache_size) |
FGEN_API void | fgen_invalidate_cache (FgenPopulation *pop) |
FGEN_API void | fgen_set_migration_probability (FgenPopulation *pop, float) |
FGEN_API void | fgen_set_migration_interval (FgenPopulation *pop, int) |
FGEN_API void | fgen_set_generation_callback_interval (FgenPopulation *pop, int) |
FGEN_API void | fgen_set_initialization_type (FgenPopulation *pop, int) |
FGEN_API void | fgen_seed_random (FgenPopulation *pop, unsigned char *bitstring) |
FGEN_API void | fgen_mutation_per_bit (FgenPopulation *pop, const unsigned char *parent, unsigned char *child) |
FGEN_API void | fgen_mutation_per_bit_plus_macro_mutation (FgenPopulation *pop, const unsigned char *parent, unsigned char *child) |
FGEN_API void | fgen_mutation_per_bit_fast (FgenPopulation *pop, const unsigned char *parent, unsigned char *child) |
FGEN_API void | fgen_mutation_per_bit_plus_macro_mutation_fast (FgenPopulation *pop, const unsigned char *parent, unsigned char *child) |
FGEN_API void | fgen_crossover_one_point_per_bit (FgenPopulation *pop, const unsigned char *parent1, const unsigned char *parent2, unsigned char *child1, unsigned char *child2) |
FGEN_API void | fgen_crossover_one_point_per_element (FgenPopulation *pop, const unsigned char *parent1, const unsigned char *parent2, unsigned char *child1, unsigned char *child2) |
FGEN_API void | fgen_crossover_two_point_per_bit (FgenPopulation *pop, const unsigned char *parent1, const unsigned char *parent2, unsigned char *child1, unsigned char *child2) |
FGEN_API void | fgen_crossover_two_point_per_element (FgenPopulation *pop, const unsigned char *parent1, const unsigned char *parent2, unsigned char *child1, unsigned char *child2) |
FGEN_API void | fgen_crossover_uniform_per_bit (FgenPopulation *pop, const unsigned char *parent1, const unsigned char *parent2, unsigned char *child1, unsigned char *child2) |
FGEN_API void | fgen_crossover_uniform_per_element (FgenPopulation *pop, const unsigned char *parent1, const unsigned char *parent2, unsigned char *child1, unsigned char *child2) |
FGEN_API void | fgen_seed_permutation_random (FgenPopulation *pop, unsigned char *bitstring) |
FGEN_API void | fgen_mutation_permutation_swap (FgenPopulation *pop, const unsigned char *parent, unsigned char *child) |
FGEN_API void | fgen_mutation_permutation_insert (FgenPopulation *pop, const unsigned char *parent, unsigned char *child) |
FGEN_API void | fgen_mutation_permutation_invert (FgenPopulation *pop, const unsigned char *parent, unsigned char *child) |
FGEN_API void | fgen_crossover_permutation_order_based (FgenPopulation *pop, const unsigned char *parent1, const unsigned char *parent2, unsigned char *child1, unsigned char *child2) |
FGEN_API void | fgen_crossover_permutation_position_based (FgenPopulation *pop, const unsigned char *parent1, const unsigned char *parent2, unsigned char *child1, unsigned char *child2) |
FGEN_API void | fgen_crossover_noop (FgenPopulation *pop, const unsigned char *parent1, const unsigned char *parent2, unsigned char *child1, unsigned char *child2) |
FGEN_API FgenIndividual * | fgen_best_individual_of_population (FgenPopulation *pop) |
FGEN_API FgenIndividual * | fgen_worst_individual_of_population (FgenPopulation *pop) |
FGEN_API FgenIndividual * | fgen_best_individual_of_archipelago (int nu_pops, FgenPopulation **pops) |
FGEN_API void | fgen_update_population_fitness (FgenPopulation *pop) |
FGEN_API void | fgen_invalidate_population_fitness (FgenPopulation *pop) |
FGEN_API void | fgen_signal_stop (FgenPopulation *pop) |
FGEN_API int | fgen_individual_size_in_bytes (const FgenPopulation *pop) |
FGEN_API int | fgen_get_island (const FgenPopulation *pop) |
FGEN_API int | fgen_is_cached (const FgenPopulation *pop) |
FGEN_API double | fgen_get_cache_hit_rate (const FgenPopulation *pop) |
FGEN_API FgenRNG * | fgen_get_rng (const FgenPopulation *pop) |
FGEN_API int | fgen_get_generation (const FgenPopulation *pop) |
FGEN_API double | fgen_bitstring_uint16_to_double (const unsigned char *bitstring, double domain_min, double domain_max) |
FGEN_API double | fgen_bitstring_uint32_to_double (const unsigned char *bitstring, double domain_min, double domain_max) |
FGEN_API double | fgen_bitstring_uint64_to_double (const unsigned char *bitstring, double domain_min, double domain_max) |
FGEN_API void | fgen_decode_from_gray (const FgenPopulation *pop, const unsigned char *src_bitstring, unsigned char *dest_bitstring) |
FGEN_API void | fgen_encode_to_gray (const FgenPopulation *pop, const unsigned char *src_bitstring, unsigned char *dest_bitstring) |
FGEN_API void | fgen_mutate_bit (unsigned char *bitstring, int n) |
FGEN_API void | fgen_set_random_bitstring (FgenRNG *rng, unsigned char *bitstring, int offset, int nu_bits) |
FGEN_API int | fgen_get_bit (const unsigned char *bitstring, int n) |
FGEN_API void | fgen_copy_partial_bitstring (const unsigned char *src_bitstring, unsigned char *dest_bitstring, int offset, int nu_bits) |
FGEN_API FgenRNG * | fgen_random_create_rng () |
FGEN_API void | fgen_random_destroy_rng (FgenRNG *rng) |
FGEN_API void | fgen_random_seed_rng (FgenRNG *rng, unsigned int seed) |
FGEN_API void | fgen_random_seed_with_timer (FgenRNG *rng) |
FGEN_API int | fgen_random_2 (FgenRNG *rng) |
FGEN_API int | fgen_random_8 (FgenRNG *rng) |
FGEN_API int | fgen_random_16 (FgenRNG *rng) |
FGEN_API unsigned int | fgen_random_32 (FgenRNG *rng) |
FGEN_API int | fgen_random_n (FgenRNG *rng, int n) |
FGEN_API float | fgen_random_f (FgenRNG *rng, float range) |
FGEN_API double | fgen_random_d (FgenRNG *rng, double range) |
FGEN_API double | fgen_random_from_range_d (FgenRNG *rng, double min_bound, double max_bound) |
typedef void(* FgenGenerationCallbackFunc)(FgenPopulation *pop, int generation) |
typedef double(* FgenCalculateFitnessFunc)(const FgenPopulation *pop, const unsigned char *bitstring) |
The fitness evaluation function. The current population and the bitstring to be evaluated are passed as arguments. See fgen_create().
typedef void(* FgenSeedFunc)(FgenPopulation *pop, unsigned char *bitstring) |
typedef void(* FgenMutationFunc)(FgenPopulation *pop, const unsigned char *parent, unsigned char *child) |
typedef void(* FgenCrossoverFunc)(FgenPopulation *pop, const unsigned char *parent1, const unsigned char *parent2, unsigned char *child1, unsigned char *child2) |
FGEN_API FgenPopulation* fgen_create | ( | int | population_size, |
int | individual_size_in_bits, | ||
int | data_element_size, | ||
FgenGenerationCallbackFunc | fgen_generation_callback_func, | ||
FgenCalculateFitnessFunc | fgen_calculate_fitness_func, | ||
FgenSeedFunc | fgen_seed_func, | ||
FgenMutationFunc | fgen_mutation_func, | ||
FgenCrossoverFunc | fgen_crossover_func | ||
) |
Create an fgen population. The random number generator belonging to the population is seeded with zero.
population_size | Size of the population. |
individual_size_in_bits | Size of each individual in bits, must be a multiple of 8. |
data_element_size | Size of each data element in bits, preferably a multiple of 8 or equal to 1. This affects several types of crossover and mutation operators, as well as Gray coding. The library is optimized for values of 16, 32 or 64. |
fgen_generation_callback_func | The callback function that is called by fgen after every n generations, where n is defined by the generation callback interval. |
fgen_calculate_fitness_func | The fitness evaluation function that calculates the fitness of an individual. It should return a double floating point value where higher values indicate higher fitness. In general fitness values greater or equal to zero are advisable, although negative fitness values are allowed in some cases (when FGEN_SUBTRACT_MIN_FITNESS is set with SUS selection or with any kind of tournament selection). Infinity is allowed (INFINITY in Linux), negative infinity and NaN are not. In Windows positive infinity is defined as DBL_MAX. When a fitness evaluation returns this value, the algorithm will continue but evolution may stop, and in the case of threaded concurrent islands skip generations and generate an early generation_callback. |
fgen_seed_func | The seeding operator. This is called for every member of the population when the algorithm starts (see fgen_run()). |
fgen_mutation_func | The mutation operator. When this is called the child is allocated and already contains a copy of the parent. This function is called for every individual of the population; logic reflecting the mutation probability should be used within the mutation operator function. |
fgen_crossover_func | The crossover operator. The children are allocated but not filled in. This function is called depending on the crossover probability (so in general there is no need to use the crossover probability within the operator). |
FGEN_API void fgen_initialize | ( | FgenPopulation * | pop, |
int | population_size, | ||
int | individual_size_in_bits, | ||
int | data_element_size, | ||
FgenGenerationCallbackFunc | fgen_generation_callback_func, | ||
FgenCalculateFitnessFunc | fgen_calculate_fitness_func, | ||
FgenSeedFunc | fgen_seed_func, | ||
FgenMutationFunc | fgen_mutation_func, | ||
FgenCrossoverFunc | fgen_crossover_func | ||
) |
Initialize an fgen population. pop must be allocated first. The random number generator belonging to the population is seeded with zero. For binary compatibility between different versions of libfgen, use fgen_create() instead of this function.
pop | The population to initialize. |
population_size | Size of the population. |
individual_size_in_bits | Size of each individual in bits, must be a multiple of 8. |
data_element_size | Size of each data element in bits, preferably a multiple of 8 or 1. |
fgen_generation_callback_func | The callback function that is called by fgen after each generation. |
fgen_calculate_fitness_func | The fitness evaluation function that calculates the fitness of an individual. |
fgen_seed_func | The seeding operator. |
fgen_mutation_func | The mutation operator. |
fgen_crossover_func | The crossover operator. |
FGEN_API void fgen_set_parameters | ( | FgenPopulation * | pop, |
int | selection_type, | ||
int | selection_fitness_type, | ||
float | crossover_probability_float, | ||
float | mutation_probability_float, | ||
float | macro_mutation_probability_float | ||
) |
Set the genetic algorithm parameters for an fgen population. These values are not initialized by fgen_create(), so in general this function must be called after every population is created with fgen_create(). It is also possible to use functions that set parameters seperately.
pop | The population. It should be created or initialized before this function is called. |
selection_type | The selection type. See fgen_set_selection_type(). |
selection_fitness_type | The fitness selection type. See fgen_set_selection_fitness_type(). |
crossover_probability_float | The crossover probability per individual. |
mutation_probability_float | The mutation probability (per bit for bitstrings, per individual for permutations). |
macro_mutation_probability_float | The macro-mutation probability (per data element). |
FGEN_API void fgen_run | ( | FgenPopulation * | pop, |
int | max_generation | ||
) |
Run the genetic algorithm. First the initial population is created using the seeding function. For every generation selection, crossover and mutation are applied in that order. With a frequency defined by the generation callback interval, the generation callback function is called. Use the generation callback function to keep track of evolution (use fgen_best_individual_of_population() to get the individual with the best fitness) and print out results or draw graphics reflecting the best solution, and use fgen_signal_stop() to let the algorithm terminate.
pop | The population. |
max_generation | The maximum generation. When this is reached (or when stop is signalled) the function exits. If it is equal to - 1 the algorithm runs indefinitely and only stops when fgen_signal_stop() is called. |
FGEN_API void fgen_run_threaded | ( | FgenPopulation * | pop, |
int | max_generation | ||
) |
Run the genetic algorithm. Threaded version. Because the amount of parallellism is limited to concurrent fitness calculations, the performance is generally better with the unthreaded version for simple problems. However, with larger populations and more expensive fitness functions the speed-up can be respectable. In Linux the number of threads to use is obtained from a sysconf() system call returning the number of online processor cores in the system. On windows the number of threads is set to 4. The fitness cache should not be enabled when using this function.
pop | The population. |
max_generation | The maximum generation. When this is reached (or when stop is signalled) the function exits. A value of - 1 means the function only returns when stop is signalled. |
FGEN_API void fgen_destroy | ( | FgenPopulation * | pop | ) |
FGEN_API void fgen_run_archipelago | ( | int | nu_pops, |
FgenPopulation ** | pops, | ||
int | max_generation | ||
) |
Run the genetic algorithm on an archipelago of populations. The seeds of the random number generators of the islands after the first one are initialized with random seeds derived from the first island's random number generator. Each population in the pops[] array must have been created using fgen_create() and parameters set (usually the same parameters for each population) before calling this function. The generation callback function will be called individually for each island in the archipelago.
nu_pops | Number of islands. |
pops | An array of populations. |
max_generation | The maximum generation. When this is reached (or when stop is signalled) the function exits. A value of - 1 means the function only returns when stop is signalled. |
FGEN_API void fgen_run_archipelago_threaded | ( | int | nu_pops, |
FgenPopulation ** | pops, | ||
int | max_generation | ||
) |
Run the genetic algorithm on an archipelago of populations. Threaded version, uses one thread per island. The seeds of the random number generators of the islands after the first one are initialized with random seeds derived from the first island's random number generator. The generation callback function will be called individually for each island in the archipelago.
nu_pops | Number of islands. |
pops | An array of populations. |
max_generation | The maximum generation. When this is reached (or when stop is signalled) the function exits. A value of - 1 means the function only returns when stop is signalled. |
FGEN_API void fgen_run_steady_state | ( | FgenPopulation * | pop, |
int | max_generation | ||
) |
Run the steady state version of the genetic algorithm. In steady state evolution, only two individuals are selected for possible crossover and mutation in each "generation" and replace two random individuals in the population. Only tournament selection is supported, and elitism and extinction are not supported. The selection type must be FGEN_TOURNAMENT or FGEN_KILL_TOURNAMENT; in the latter case, the random individuals selected for replacement are selected with tournament selection of the worst individual. The generation callback interval should be set to a high value for efficiency, as a rule of thumb generation intervals should multiplied by half the population size compared to the regular genetic algorithm.
pop | The population. |
max_generation | The maximum generation. When this is reached (or when stop is signalled) the function exits. A value of - 1 means the function only returns when stop is signalled. |
Definition at line 161 of file steady_state.c.
FGEN_API void fgen_run_steady_state_archipelago | ( | int | nu_pops, |
FgenPopulation ** | pops, | ||
int | max_generation | ||
) |
Run the steady state version of the genetic algorithm on an archipelago. In steady state evolution, only two individuals are selected for possible crossover and mutation in each "generation" and replace two random individuals in the population. Only tournament selection is supported, and elitism and extinction are not supported. The selection type must be FGEN_TOURNAMENT or FGEN_KILL_TOURNAMENT; in the latter case, the random individuals selected for replacement are selected with tournament selection of the worst individual. The generation callback interval should be set to a high value for efficiency. The seeds of the random number generators of the islands after the first one are initialized with random seeds derived from the first island's random number generator.
nu_pops | Number of islands. |
pops | An array of populations. |
max_generation | The maximum generation. When this is reached (or when stop is signalled) the function exits. A value of - 1 means the function only returns when stop is signalled. |
Definition at line 205 of file steady_state.c.
FGEN_API void fgen_run_steady_state_archipelago_threaded | ( | int | nu_pops, |
FgenPopulation ** | pops, | ||
int | max_generation | ||
) |
Run the steady state genetic algorithm on an archipelago of populations. Threaded version, uses one thread per island. The seeds of the random number generators of the islands after the first one are initialized with random seeds derived from the first island's random number generator.
nu_pops | Number of islands. |
pops | An array of populations. |
max_generation | The maximum generation. When this is reached (or when stop is signalled) the function exits. A value of - 1 means the function only returns when stop is signalled. |
Definition at line 340 of file steady_state.c.
FGEN_API void fgen_set_mutation_probability | ( | FgenPopulation * | pop, |
float | p | ||
) |
Set the mutation probability to a floating value from 0 to 1.0. Note that the mutation operator function is called for every individual regardless of the mutation probability. The operator itself uses the probability to apply mutations. The precise meaning of the probability (per bit, or per individual for example) varies between operators.
Definition at line 41 of file parameters.c.
FGEN_API void fgen_set_macro_mutation_probability | ( | FgenPopulation * | pop, |
float | p | ||
) |
Set the macro-mutation probability to a floating point value from 0 to 1.0. Only has meaning if fgen_mutation_per_bit_plus_macro_mutation() or fgen_mutation_per_bit_plus_macro_mutation_fast() is the mutation operator. May also be used as a parameter for a custom operator.
Definition at line 55 of file parameters.c.
FGEN_API void fgen_set_crossover_probability | ( | FgenPopulation * | pop, |
float | p | ||
) |
Set the crossover probability to a floating point value forom 0 to 1.0.
Definition at line 64 of file parameters.c.
FGEN_API void fgen_set_selection_fitness_type | ( | FgenPopulation * | pop, |
int | t | ||
) |
Set the selection fitness type.
pop | The population. |
t | One of FGEN_FITNESS_PROPORTIONAL, FGEN_SUBTRACT_MIN_FITNESS (the minimum fitness of the population is subtracted from all fitness values), or FGEN_SUBTRACT_FITNESS_DIV_2 (the minimum fitness divided by two is subtracted). In general FGEN_SUBTRACT_MIN_FITNESS is recommended. |
Definition at line 78 of file parameters.c.
FGEN_API void fgen_set_selection_type | ( | FgenPopulation * | pop, |
int | t | ||
) |
Set the selection type. In general elitist SUS or elitist tournament selection is recommended.
pop | The population. |
t | One of the following:
|
Definition at line 99 of file parameters.c.
FGEN_API void fgen_set_tournament_size | ( | FgenPopulation * | pop, |
int | n | ||
) |
Set the tournament size for tournament selection. The default value is 3.
Definition at line 107 of file parameters.c.
FGEN_API void fgen_set_data_element_size | ( | FgenPopulation * | pop, |
int | n | ||
) |
Set the data element size in bits. Each individual can be divided into chromosomes (for example 32-bit values that encode an integer or real number). The "per element" crossover operators as well as macro mutation operate with data element boundaries.
Definition at line 117 of file parameters.c.
FGEN_API void fgen_set_number_of_elites | ( | FgenPopulation * | pop, |
int | n | ||
) |
Set the number of elite individuals (with the best fitness) that will always survive selection when elitism is enabled. The default value is the population size divided by 64.
Definition at line 126 of file parameters.c.
FGEN_API void fgen_set_permutation_size | ( | FgenPopulation * | pop, |
int | n | ||
) |
Set the permutation size used by the permutation mutation and crossover operators.
Definition at line 134 of file parameters.c.
FGEN_API void fgen_set_user_data | ( | FgenPopulation * | pop, |
void * | data | ||
) |
Set the user_data pointer field of the population. This is used by ffit. When using fgen it may be used to conveniently tie an auxilliary data structure to a population.
Definition at line 143 of file parameters.c.
FGEN_API void fgen_enable_cache | ( | FgenPopulation * | pop, |
int | size | ||
) |
Enable fitness cache on population. Size is the number of entries. Memory used is roughly the number of entries times the size of the bitstring of an individual. The cache imposes overhead, but for combinatorial problems with an expensive fitness function it should be beneficial. For real-valued optimization problems, it is not effective. When running an archipelago of GAs, it is safe to use a seperate cache for each population.
FGEN_API void fgen_enable_cache_on_archipelago | ( | int | nu_pops, |
FgenPopulation ** | pops, | ||
int | size | ||
) |
Enable one cache shared between all archipelagos. This only works with the unthreaded fgen_run_archipelago().
FGEN_API void fgen_invalidate_cache | ( | FgenPopulation * | pop | ) |
FGEN_API void fgen_set_migration_probability | ( | FgenPopulation * | pop, |
float | p | ||
) |
Set the migration probability per individual during a generation when migration is allowed. This probability must be set seperately for each island.
Definition at line 152 of file parameters.c.
FGEN_API void fgen_set_migration_interval | ( | FgenPopulation * | pop, |
int | n | ||
) |
Set the migration interval. A value of 1 means migration happens every generation, a value of 50 means migration happens only every 50th generation. The default is 1. A value of 0 means no migration. The migration interval of the first population in an archipelago (pops[0]) is currently used for all islands.
Definition at line 163 of file parameters.c.
FGEN_API void fgen_set_generation_callback_interval | ( | FgenPopulation * | pop, |
int | n | ||
) |
Set the interval at which the generation callback function is called. A value of 1 means it is called every generation, a value of 50 means it is called only every 50th generation. The default is 1. Higher values are beneficial for threaded execution.
Definition at line 173 of file parameters.c.
FGEN_API void fgen_set_initialization_type | ( | FgenPopulation * | pop, |
int | v | ||
) |
Set the initialization type, which selects whether to continue with an existing population at the start of fgen_run() and variants, if it exists, or whether to seed a new population. FGEN_INITIALIZATION_SEED or FGEN_INITIALIZATION_CONTINUE are valid values, the default is FGEN_INITIALIZATION_SEED.
Definition at line 185 of file parameters.c.
FGEN_API void fgen_seed_random | ( | FgenPopulation * | pop, |
unsigned char * | bitstring | ||
) |
FGEN_API void fgen_mutation_per_bit | ( | FgenPopulation * | pop, |
const unsigned char * | parent, | ||
unsigned char * | child | ||
) |
Bit-wise mutation operator. Each bit is toggled with the preset mutation probability per bit.
Definition at line 317 of file mutation.c.
FGEN_API void fgen_mutation_per_bit_plus_macro_mutation | ( | FgenPopulation * | pop, |
const unsigned char * | parent, | ||
unsigned char * | child | ||
) |
Mutation operator that performs both a bit-wise mutation and a macro mutation where a random data element is entirely replaced with a random value. The preset macro mutation probability is applied per data element.
Definition at line 346 of file mutation.c.
FGEN_API void fgen_mutation_per_bit_fast | ( | FgenPopulation * | pop, |
const unsigned char * | parent, | ||
unsigned char * | child | ||
) |
Fast bit-wise mutation operator. A predefined random number of bits is mutated. There is a chance that the same bit is toggled more than once, but because the mutation rate per bit is low it is not that important.
Definition at line 333 of file mutation.c.
FGEN_API void fgen_mutation_per_bit_plus_macro_mutation_fast | ( | FgenPopulation * | pop, |
const unsigned char * | parent, | ||
unsigned char * | child | ||
) |
Mutation operator that performs both a bit-wise mutation and a macro mutation where a random data element is entirely replaced with a random value. The preset macro mutation probability is applied per data element. Fast version.
Definition at line 369 of file mutation.c.
FGEN_API void fgen_crossover_one_point_per_bit | ( | FgenPopulation * | pop, |
const unsigned char * | parent1, | ||
const unsigned char * | parent2, | ||
unsigned char * | child1, | ||
unsigned char * | child2 | ||
) |
Bit-wise one-point crossover operator.
Definition at line 115 of file crossover.c.
FGEN_API void fgen_crossover_one_point_per_element | ( | FgenPopulation * | pop, |
const unsigned char * | parent1, | ||
const unsigned char * | parent2, | ||
unsigned char * | child1, | ||
unsigned char * | child2 | ||
) |
Per element one-point crossover operator that respects data element boundaries.
Definition at line 90 of file crossover.c.
FGEN_API void fgen_crossover_two_point_per_bit | ( | FgenPopulation * | pop, |
const unsigned char * | parent1, | ||
const unsigned char * | parent2, | ||
unsigned char * | child1, | ||
unsigned char * | child2 | ||
) |
Bit-wise two-point crossover operator.
Definition at line 168 of file crossover.c.
FGEN_API void fgen_crossover_two_point_per_element | ( | FgenPopulation * | pop, |
const unsigned char * | parent1, | ||
const unsigned char * | parent2, | ||
unsigned char * | child1, | ||
unsigned char * | child2 | ||
) |
Per-element two-point crossover operator that respects data element boundaries.
Definition at line 132 of file crossover.c.
FGEN_API void fgen_crossover_uniform_per_bit | ( | FgenPopulation * | pop, |
const unsigned char * | parent1, | ||
const unsigned char * | parent2, | ||
unsigned char * | child1, | ||
unsigned char * | child2 | ||
) |
Bit-wise uniform crossover operator. Each bit is randomly selected from one of the two parents.
Definition at line 193 of file crossover.c.
FGEN_API void fgen_crossover_uniform_per_element | ( | FgenPopulation * | pop, |
const unsigned char * | parent1, | ||
const unsigned char * | parent2, | ||
unsigned char * | child1, | ||
unsigned char * | child2 | ||
) |
Crossover operator that respects data element boundaries. Each data element is selected randomly from one of the two parents. This is also called discrete recombination.
Definition at line 244 of file crossover.c.
FGEN_API void fgen_seed_permutation_random | ( | FgenPopulation * | pop, |
unsigned char * | bitstring | ||
) |
Seeding operator that initializes an individual with a random permutation corresponding to the size set by fgen_set_permutation_size().
FGEN_API void fgen_mutation_permutation_swap | ( | FgenPopulation * | pop, |
const unsigned char * | parent, | ||
unsigned char * | child | ||
) |
Simple mutation operator for permutations.
Definition at line 409 of file mutation.c.
FGEN_API void fgen_mutation_permutation_insert | ( | FgenPopulation * | pop, |
const unsigned char * | parent, | ||
unsigned char * | child | ||
) |
Insert mutation operator for permutations. Takes a random element from the permutation and reinserts it at a random location in the permutation.
Definition at line 427 of file mutation.c.
FGEN_API void fgen_mutation_permutation_invert | ( | FgenPopulation * | pop, |
const unsigned char * | parent, | ||
unsigned char * | child | ||
) |
Invert mutation operator for permutations that inverts a random subroute within the permutation.
Definition at line 458 of file mutation.c.
FGEN_API void fgen_crossover_permutation_order_based | ( | FgenPopulation * | pop, |
const unsigned char * | parent1, | ||
const unsigned char * | parent2, | ||
unsigned char * | child1, | ||
unsigned char * | child2 | ||
) |
Order based (OX1) crossover operator for permutations.
Definition at line 309 of file crossover.c.
FGEN_API void fgen_crossover_permutation_position_based | ( | FgenPopulation * | pop, |
const unsigned char * | parent1, | ||
const unsigned char * | parent2, | ||
unsigned char * | child1, | ||
unsigned char * | child2 | ||
) |
Position-based crossover operator for permutations. Effective for the travelling salesman problem.
Definition at line 395 of file crossover.c.
FGEN_API void fgen_crossover_noop | ( | FgenPopulation * | pop, |
const unsigned char * | parent1, | ||
const unsigned char * | parent2, | ||
unsigned char * | child1, | ||
unsigned char * | child2 | ||
) |
Crossover operator that does nothing.
Definition at line 441 of file crossover.c.
FGEN_API FgenIndividual* fgen_best_individual_of_population | ( | FgenPopulation * | pop | ) |
Returns the best individual of the population (the one with the highest fitness)
pop | The population. |
Definition at line 229 of file population.c.
FGEN_API FgenIndividual* fgen_worst_individual_of_population | ( | FgenPopulation * | pop | ) |
Returns the worst individual of the population (the one with the lowest fitness).
pop | The population. |
Definition at line 249 of file population.c.
FGEN_API FgenIndividual* fgen_best_individual_of_archipelago | ( | int | nu_pops, |
FgenPopulation ** | pops | ||
) |
Returns the best individual of an archipelago of populations (the individual with the highest fitness). This function generally only makes sense when the fitness function is the same between the different individual populations that make up the archipelago.
nu_pops | The number of islands in the archipelago. |
pops | The archipelago (an array of populations). |
Definition at line 272 of file population.c.
FGEN_API void fgen_update_population_fitness | ( | FgenPopulation * | pop | ) |
Update the fitness of every individual in the population.
Definition at line 292 of file population.c.
FGEN_API void fgen_invalidate_population_fitness | ( | FgenPopulation * | pop | ) |
Invalidate the fitness of every individual so that it will be recalculated (because the fitness function has changed).
Definition at line 301 of file population.c.
FGEN_API void fgen_signal_stop | ( | FgenPopulation * | pop | ) |
FGEN_API int fgen_individual_size_in_bytes | ( | const FgenPopulation * | pop | ) |
Returns the size of the bitstring (genetic data) of an individual in bytes.
Definition at line 313 of file population.c.
FGEN_API int fgen_get_island | ( | const FgenPopulation * | pop | ) |
FGEN_API int fgen_is_cached | ( | const FgenPopulation * | pop | ) |
FGEN_API double fgen_get_cache_hit_rate | ( | const FgenPopulation * | pop | ) |
FGEN_API FgenRNG* fgen_get_rng | ( | const FgenPopulation * | pop | ) |
FGEN_API int fgen_get_generation | ( | const FgenPopulation * | pop | ) |
FGEN_API double fgen_bitstring_uint16_to_double | ( | const unsigned char * | bitstring, |
double | domain_min, | ||
double | domain_max | ||
) |
FGEN_API double fgen_bitstring_uint32_to_double | ( | const unsigned char * | bitstring, |
double | domain_min, | ||
double | domain_max | ||
) |
FGEN_API double fgen_bitstring_uint64_to_double | ( | const unsigned char * | bitstring, |
double | domain_min, | ||
double | domain_max | ||
) |
FGEN_API void fgen_decode_from_gray | ( | const FgenPopulation * | pop, |
const unsigned char * | src_bitstring, | ||
unsigned char * | dest_bitstring | ||
) |
Decode the source bitstring from Gray-code and store it in the destination bitstring. Each gray coded value corresponds to a data element (data element boundaries as set by fgen_create() are respected).
FGEN_API void fgen_encode_to_gray | ( | const FgenPopulation * | pop, |
const unsigned char * | src_bitstring, | ||
unsigned char * | dest_bitstring | ||
) |
Encode the source bitstring to Gray-code and store it in the destination bitstring. Each gray coded value corresponds to a data element (data element boundaries as set by fgen_create() are respected).
FGEN_API void fgen_mutate_bit | ( | unsigned char * | bitstring, |
int | bitnumber | ||
) |
Mutate (toggle) the bit at offset bitnumber in bitstring. bitnumber must be >= 0 but may be greater than 7.
Definition at line 89 of file bitstring.c.
FGEN_API void fgen_set_random_bitstring | ( | FgenRNG * | rng, |
unsigned char * | bitstring, | ||
int | offset, | ||
int | nu_bits | ||
) |
Set a number of bits at position offset in bitstring each to a random value (1 or 0). offset must be >= 0 but may be greater than 7. For good performance offset and nu_bits are preferably a multiple of 8.
Definition at line 70 of file bitstring.c.
FGEN_API int fgen_get_bit | ( | const unsigned char * | bitstring, |
int | bitnumber | ||
) |
Returns the value (1 or 0) of the bit at offset bitnumber in bitstring. bitnumber must be >= 0.
Definition at line 97 of file bitstring.c.
FGEN_API void fgen_copy_partial_bitstring | ( | const unsigned char * | src, |
unsigned char * | dest, | ||
int | bitoffset, | ||
int | number_of_bits | ||
) |
Copy the part of the source bitstring at offset bitoffset of length number_of_bits to the same position in the destination bitstring.
Definition at line 107 of file bitstring.c.
FGEN_API FgenRNG* fgen_random_create_rng | ( | ) |
Create a random number generator data structure and returns it. The RNG is initialized with a seed of 0. Although normally called by fgen_create(), it is possible to use this function to create a random number generator not tied to any population and use it on its own.
FGEN_API void fgen_random_destroy_rng | ( | FgenRNG * | rng | ) |
FGEN_API void fgen_random_seed_rng | ( | FgenRNG * | rng, |
unsigned int | seed | ||
) |
FGEN_API void fgen_random_seed_with_timer | ( | FgenRNG * | rng | ) |
FGEN_API int fgen_random_2 | ( | FgenRNG * | rng | ) |
FGEN_API int fgen_random_8 | ( | FgenRNG * | rng | ) |
FGEN_API int fgen_random_16 | ( | FgenRNG * | rng | ) |
FGEN_API unsigned int fgen_random_32 | ( | FgenRNG * | rng | ) |
FGEN_API int fgen_random_n | ( | FgenRNG * | rng, |
int | n | ||
) |
FGEN_API float fgen_random_f | ( | FgenRNG * | rng, |
float | range | ||
) |
FGEN_API double fgen_random_d | ( | FgenRNG * | rng, |
double | range | ||
) |
FGEN_API double fgen_random_from_range_d | ( | FgenRNG * | rng, |
double | min_bound, | ||
double | max_bound | ||
) |