Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages | Search for

# BitEA.cpp

    00001 #include <iostream>
    00002
    00003 #include <ga/make_ga.h>
    00004 #include <apply.h>
    00005
    00006 // EVAL
    00007 #include "binary_value.h"
    00008
    00009 // GENERAL
    00010 using namespace std;
    00011
    00012 int main(int argc, char* argv[])
    00013 {
    00014
    00015   try
    00016   {
    00017 // REPRESENTATION
    00018 //-----------------------------------------------------------------------------
    00019 // define your genotype and fitness types
    00020   typedef eoBit<double> EOT;
    00021
    00022 // PARAMETRES
    00023   eoParser parser(argc, argv);  // for user-parameter reading
    00024
    00025 // GENERAL
    00026   eoState state;    // keeps all things allocated
    00027
    00030
    00031 // EVAL
    00032   // The evaluation fn - encapsulated into an eval counter for output
    00033   eoEvalFuncPtr<EOT, double> mainEval( binary_value<EOT> );
    00034   eoEvalFuncCounter<EOT> eval(mainEval);
    00035
    00036 // REPRESENTATION
    00037   // the genotype - through a genotype initializer
    00038   eoInit<EOT>& init = make_genotype(parser, state, EOT());
    00039
    00040   // if you want to do sharing, you'll need a distance.
    00041   // here Hamming distance
    00042   eoHammingDistance<EOT> dist;
    00043
    00044 // OPERATORS
    00045   // Build the variation operator (any seq/prop construct)
    00046   eoGenOp<EOT>& op = make_op(parser, state, init);
    00047
    00048 // GENERAL
    00051
    00052   // initialize the population - and evaluate
    00053   // yes, this is representation indepedent once you have an eoInit
    00054   eoPop<EOT>& pop   = make_pop(parser, state, init);
    00055
    00056 // STOP
    00057   // stopping criteria
    00058   eoContinue<EOT> & term = make_continue(parser, state, eval);
    00059   // output
    00060   eoCheckPoint<EOT> & checkpoint = make_checkpoint(parser, state, eval, term);
    00061 // GENERATION
    00062   // algorithm (need the operator!)
    00063   eoAlgo<EOT>& ga = make_algo_scalar(parser, state, eval, checkpoint, op, &dist);
    00064
    00067 // PARAMETRES
    00068   // to be called AFTER all parameters have been read!!!
    00069   make_help(parser);
    00070
    00073 // EVAL
    00074   // evaluate intial population AFTER help and status in case it takes time
    00075   apply<EOT>(eval, pop);
    00076 // STOP
    00077   // print it out (sort witout modifying)
    00078   cout << "Initial Population\n";
    00079   pop.sortedPrintOn(cout);
    00080   cout << endl;
    00081
    00082 // GENERATION
    00083   run_ea(ga, pop); // run the ga
    00084 // STOP
    00085   // print it out (sort witout modifying)
    00086   cout << "Final Population\n";
    00087   pop.sortedPrintOn(cout);
    00088   cout << endl;
    00089 // GENERAL
    00090   }
    00091   catch(exception& e)
    00092   {
    00093     cout << e.what() << endl;
    00094   }
    00095 }