Documentation
Currentlly there is not documentation that specify all of the features
in the library. However, there are some examples in testcases.h
that might be useful for any programmer.
Here is one of the examples, test case 2 of the famous DeJong tests.
First, define the function that is to be minimized or maximized.
//
De Jong function F2
double fcn_u2(double* v,void* d) {
double a=(v[0]*v[0]-v[1]);
double b=1-v[0];
return (100*a*a+b*b);
};
After that, prepare the solver and add variables
and finaly run the optimazation.
void test_case_u2(ostream& s=cout) {
simple_ga ga;
function fcn;
fcn.add_variable(variable(-2.048,2.048,0.01,"x1"));
fcn.add_variable(variable(-2.048,2.048,0.01,"x2"));
fcn.add_function(fcn_u2);
fcn.name="De Jong function F2";
fcn.comment="Standard test case for optimazation algorithms, quite
hard to solve";
fcn.implementation="minimize y=100*((x1)^2-(x2))^2 + (1-(x1))^2";
ga.minimize();
s << endl;
s << "Test 2" << endl;
s << fcn.name.c_str() << endl;
s << fcn.comment.c_str() << endl;
s << fcn.implementation.c_str() << endl;
ga.init(20,10000,&fcn);
ga.init_random(1234);
s << "population
size: " << ga.get_population_size() << endl;
ga.run();
ga.report_text(s);
ofstream f;
f.open("test_case_u2.res");
ga.report_function_values(f);
f.close();
};
The results are sent to stdout.
Web administrator: Magnus Sethson
This project is hosted at Sourceforge.
|