From f3535911a2af230608d97a96e7b7d86fcd71f156 Mon Sep 17 00:00:00 2001 From: evomarc Date: Mon, 8 Apr 2002 18:03:35 +0000 Subject: [PATCH] I suddenly realized that BitEA.html was NOT in the repository! --- eo/tutorial/html/BitEA.html | 261 ++++++++++++++++++++++++++++++++++++ 1 file changed, 261 insertions(+) create mode 100644 eo/tutorial/html/BitEA.html diff --git a/eo/tutorial/html/BitEA.html b/eo/tutorial/html/BitEA.html new file mode 100644 index 000000000..7d75bec5b --- /dev/null +++ b/eo/tutorial/html/BitEA.html @@ -0,0 +1,261 @@ + + + + + + BitEA.cpp + + +Back to Lesson 4 - Tutorial +main page - Top-Down page - Bottom-up +page - Programming hints - EO +documentation +
+
+
+

+BitEA.cpp

+Click on the figure to see the corresponding code.
+In the code, the colors are meaningfull
+The actual code is in boldface and the comment in normal face. +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
  + + + + + +
+#include <iostream>
+#include <ga/make_ga.h>
+#include <apply.h>
+
+
+ + + + +
+ +#include "binary_value.h"
+
+
+ + + + +
+ +using namespace std;
+int main(int argc, char* argv[])
+{
+  try
+  {
+
+
+ + + + +
+ +//-----------------------------------------------------------------------------
+// define your genotype and fitness types
+  typedef eoBit<double> EOT;
+
+
+ + + + +
+ +  eoParser parser(argc, argv);  // for user-parameter reading
+
+
+ + + + +
+ +  eoState state;      // keeps all things allocated
+  ///// FIRST, problem or representation dependent stuff
+  //////////////////////////////////////////////////////
+
+
+ + + + +
+ +  // The evaluation fn - encapsulated into an eval counter for output
+  eoEvalFuncPtr<EOT, float> mainEval( binary_value<EOT> );
+  eoEvalFuncCounter<EOT> eval(mainEval);
+
+
+ + + + +
+ +  // the genotype - through a genotype initializer
+  eoInit<EOT>& init = make_genotype(parser, state, EOT());
+
+
+ + + + +
+ +  // Build the variation operator (any seq/prop construct)
+  eoGenOp<EOT>& op = make_op(parser, state, init);
+
+
+ + + + +
+ +  //// Now the representation-independent things
+  //////////////////////////////////////////////
+  // initialize the population - and evaluate
+  // yes, this is representation indepedent once you have an eoInit
+  eoPop<EOT>& pop    = make_pop(parser, state, init);
+
+
+ + + + +
+ +  // stopping criteria
+  eoContinue<EOT> & term = make_continue(parser, state, eval);
+  // output
+  eoCheckPoint<EOT> & checkpoint = make_checkpoint(parser, state, eval, term);
+
+
+ + + + +
+ +  // algorithm (need the operator!)
+  eoAlgo<EOT>& ga = make_algo_scalar(parser, state, eval, checkpoint, op);
+  ///// End of construction of the algorith
+  /////////////////////////////////////////
+
+
+ + + + +
+ +  // to be called AFTER all parameters have been read!!!
+  make_help(parser);
+  //// GO
+  ///////
+
+
+ + + + +
+ +  // evaluate intial population AFTER help and status in case it takes time
+  apply(eval, pop);
+
+
+ + + + +
+ +  // print it out (sort witout modifying)
+  cout << "Initial Population\n";
+  pop.sortedPrintOn(cout);
+  cout << endl;
+
+
+ + + + +
+ +  run_ea(ga, pop); // run the ga
+
+
+ + + + +
+ +  // print it out (sort witout modifying)
+  cout << "Final Population\n";
+  pop.sortedPrintOn(cout);
+  cout << endl;
+
+
+ + + + +
+ +  }
+  catch(exception& e)
+  {
+      cout << e.what() << endl;
+  }
+}
+
+
Back to Lesson 4 - Tutorial +main page - Top-Down page - Bottom-up +page - Programming hints - EO +documentation +
+
+Marc Schoenauer
+
Last +modified: Wed Mar 6 05:40:27 2002 + + +