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

# t-eoGA.cpp

    00001 #include <iostream>
    00002
    00003 #include <ga/make_ga.h>
    00004 #include <eoEvalFuncPtr.h>
    00005 #include "binary_value.h"
    00006 #include <apply.h>
    00007
    00008 using namespace std;
    00009
    00010 int main(int argc, char* argv[])
    00011 {
    00012
    00013   try
    00014   {
    00015   typedef eoBit<double> EOT;
    00016
    00017   eoParser parser(argc, argv);  // for user-parameter reading
    00018
    00019   eoState state;    // keeps all things allocated
    00020
    00023
    00024   // The evaluation fn - encapsulated into an eval counter for output
    00025   eoEvalFuncPtr<EOT, double> mainEval( binary_value<EOT> );
    00026   eoEvalFuncCounter<EOT> eval(mainEval);
    00027
    00028   // the genotype - through a genotype initializer
    00029   eoInit<EOT>& init = make_genotype(parser, state, EOT());
    00030
    00031   // Build the variation operator (any seq/prop construct)
    00032   eoGenOp<EOT>& op = make_op(parser, state, init);
    00033
    00036
    00037   // initialize the population - and evaluate
    00038   // yes, this is representation indepedent once you have an eoInit
    00039   eoPop<EOT>& pop   = make_pop(parser, state, init);
    00040
    00041   // stopping criteria
    00042   eoContinue<EOT> & term = make_continue(parser, state, eval);
    00043   // output
    00044   eoCheckPoint<EOT> & checkpoint = make_checkpoint(parser, state, eval, term);
    00045   // algorithm (need the operator!)
    00046   eoAlgo<EOT>& ga = make_algo_scalar(parser, state, eval, checkpoint, op);
    00047
    00050   // to be called AFTER all parameters have been read!!!
    00051   make_help(parser);
    00052
    00055   // evaluate intial population AFTER help and status in case it takes time
    00056   apply<EOT>(eval, pop);
    00057   // print it out
    00058   std::cout << "Initial Population\n";
    00059   pop.sortedPrintOn(std::cout);
    00060   std::cout << std::endl;
    00061
    00062   run_ea(ga, pop); // run the ga
    00063
    00064   std::cout << "Final Population\n";
    00065   pop.sortedPrintOn(std::cout);
    00066   std::cout << std::endl;
    00067   }
    00068   catch(std::exception& e)
    00069   {
    00070     std::cout << e.what() << std::endl;
    00071   }
    00072 }