/* ---------------------------------------------------------------------------- ex23.C mbwall 5jan96 Copyright (c) 1995-1996 Massachusetts Institute of Technology DESCRIPTION: This example shows how to use max/min feature of GAlib to maximize or minimize your objective functions. ---------------------------------------------------------------------------- */ #include #include #include #include #include #include #include #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #define MIN_VALUE -2 #define MAX_VALUE 2 #define INC 0.005 float Objective(GAGenome &); float Comparator(const GAGenome&, const GAGenome&); int main(int argc, char** argv) { cout << "Example 23\n\n"; cout << "This program tries to maximize or minimize, depending on the\n"; cout << "command line argument that you give it. Use the command-line\n"; cout << "argument 'mm -1' to minimize (the default for this example), or\n"; cout << "'mm 1' to maximize. The objective function is a simple \n"; cout << "sinusoidal.\n\n"; cout.flush(); // See if we've been given a seed to use (for testing purposes). When you // specify a random seed, the evolution will be exactly the same each time // you use that seed number. for(int jj=1; jj