MCPcopy Create free account
hub / github.com/Arash-codedev/openGA / main

Function main

examples/so-bind/example_bind.cpp:145–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143};
144
145int main()
146{
147 MyClass myobject("./bin/result_so_bind.txt");
148
149 EA::Chronometer timer;
150 timer.tic();
151
152 using std::bind;
153 using std::placeholders::_1;
154 using std::placeholders::_2;
155 using std::placeholders::_3;
156
157 GA_Type ga_obj;
158 ga_obj.problem_mode= EA::GA_MODE::SOGA;
159 ga_obj.multi_threading=true;
160 ga_obj.idle_delay_us=1; // switch between threads quickly
161 ga_obj.verbose=false;
162 ga_obj.population=20;
163 ga_obj.generation_max=1000;
164 ga_obj.calculate_SO_total_fitness=bind(&MyClass::calculate_SO_total_fitness, &myobject, _1);
165 ga_obj.init_genes= bind(&MyClass::init_genes, &myobject, _1, _2);
166 ga_obj.eval_solution= bind(&MyClass::eval_solution, &myobject, _1, _2);
167 ga_obj.mutate= bind(&MyClass::mutate, &myobject, _1, _2, _3);
168 ga_obj.crossover= bind(&MyClass::crossover, &myobject, _1, _2, _3);
169 ga_obj.SO_report_generation= bind(&MyClass::SO_report_generation, &myobject, _1, _2, _3);
170 ga_obj.best_stall_max=10;
171 ga_obj.elite_count=10;
172 ga_obj.crossover_fraction=0.7;
173 ga_obj.mutation_rate=0.4;
174 ga_obj.solve();
175
176 std::cout<<"The problem is optimized in "<<timer.toc()<<" seconds."<<std::endl;
177 std::cout<<"This is a trivial example of openGA usage with std::bind."<<std::endl;
178
179 return 0;
180}

Callers

nothing calls this directly

Calls 3

ticMethod · 0.80
solveMethod · 0.80
tocMethod · 0.80

Tested by

no test coverage detected