libfgen
0.1.15
Library for optimization using a genetic algorithm or particle swarm optimization
|
00001 /* 00002 parameters.c -- parameter setting functions. 00003 00004 fgen -- Library for optimization using a genetic algorithm or particle swarm optimization. 00005 Copyright 2012, Harm Hanemaaijer 00006 00007 This file is part of fgen. 00008 00009 fgen is free software: you can redistribute it and/or modify it 00010 under the terms of the GNU Lesser General Public License as published 00011 by the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 fgen is distributed in the hope that it will be useful, but WITHOUT 00015 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00016 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00017 License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with fgen. If not, see <http://www.gnu.org/licenses/>. 00021 00022 */ 00023 00024 /* 00025 * This file contains the basic configurable parameters for the genetic 00026 * algorithm. 00027 */ 00028 00029 #include <math.h> 00030 #include "fgen.h" 00031 #include "parameters.h" 00032 #include "error.h" 00033 #include "mutation.h" 00034 00041 void fgen_set_mutation_probability(FgenPopulation *pop, float p) { 00042 pop->mutation_probability_float = p; 00043 pop->mutation_probability = floor(p * 65536); 00044 if (pop->fgen_mutation_func == fgen_mutation_per_bit_fast || 00045 pop->fgen_mutation_func == fgen_mutation_per_bit_plus_macro_mutation_fast) 00046 SetupFastMutationCumulativeChanceArray(pop); 00047 } 00048 00055 void fgen_set_macro_mutation_probability(FgenPopulation *pop, float p) { 00056 pop->macro_mutation_probability_float = p; 00057 pop->macro_mutation_probability = floor(p * 65536); 00058 } 00059 00064 void fgen_set_crossover_probability(FgenPopulation *pop, float p) { 00065 pop->crossover_probability_float = p; 00066 pop->crossover_probability = floor(p * 256); 00067 } 00068 00078 void fgen_set_selection_fitness_type(FgenPopulation *pop, int t) { 00079 pop->selection_fitness_type = t; 00080 } 00081 00099 void fgen_set_selection_type(FgenPopulation *pop, int t) { 00100 pop->selection_type = t; 00101 } 00102 00107 void fgen_set_tournament_size(FgenPopulation *pop, int n) { 00108 pop->tournament_size = n; 00109 } 00110 00117 void fgen_set_data_element_size(FgenPopulation *pop, int n) { 00118 pop->data_element_size = n; 00119 } 00120 00126 void fgen_set_number_of_elites(FgenPopulation *pop, int n) { 00127 pop->nu_elites = n; 00128 } 00129 00134 void fgen_set_permutation_size(FgenPopulation *pop, int n) { 00135 pop->permutation_size = n; 00136 } 00137 00143 void fgen_set_user_data(FgenPopulation *pop, void *data) { 00144 pop->user_data = data; 00145 } 00146 00152 void fgen_set_migration_probability(FgenPopulation *pop, float p) { 00153 pop->migration_probability_float = p; 00154 pop->migration_probability = floor(p * 65536); 00155 } 00156 00163 void fgen_set_migration_interval(FgenPopulation *pop, int n) { 00164 pop->migration_interval = n; 00165 } 00166 00173 void fgen_set_generation_callback_interval(FgenPopulation *pop, int n) { 00174 if (n < 1) 00175 gen_error("fgen_set_generation_callback_interval: interval should be 1 or greater."); 00176 pop->generation_callback_interval = n; 00177 } 00178 00185 void fgen_set_initialization_type(FgenPopulation *pop, int v) { 00186 pop->initialization_type = v; 00187 } 00188