00001
00002
00003
00004 #ifdef _MSC_VER
00005 #pragma warning(disable:4786)
00006 #endif
00007
00008 #include <stdexcept>
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <utils/eoRNG.h>
00018 #include <ga.h>
00019 #include <utils/eoParser.h>
00020 #include <utils/eoState.h>
00021
00022
00023
00024
00025 #include <utils/checkpointing>
00026
00027 #include <utils/eoRealVectorBounds.h>
00028
00029 struct Dummy : public EO<double>
00030 {
00031 typedef double Type;
00032 };
00033
00034
00035
00036
00037 int the_main(int argc, char **argv)
00038 {
00039
00040 typedef eoBit<float> Chrom;
00041
00042 eoParser parser(argc, argv);
00043
00044
00045 eoValueParam<unsigned int> dimParam((unsigned int)(5), "dimension", "dimension");
00046 eoValueParam<double> rate(0.01, "mutationRatePerBit", "Initial value for mutation rate per bit");
00047 eoValueParam<double> factor(0.99, "mutationFactor", "Decrease factor for mutation rate");
00048 eoValueParam<uint32_t> seed(time(0), "seed", "Random number seed");
00049
00050 if (parser.isItThere(seed))
00051 std::cout << "YES\n";
00052 else
00053 std::cout << "NO\n";
00054
00055 eoValueParam<std::string> load_name("", "Load","Load",'L');
00056 eoValueParam<std::string> save_name("", "Save","Save",'S');
00057
00058
00059
00060 parser.processParam(dimParam, "Genetic Operators");
00061 parser.processParam(rate, "Genetic Operators");
00062 parser.processParam(factor, "Genetic Operators");
00063 parser.processParam(load_name, "Persistence");
00064 parser.processParam(save_name, "Persistence");
00065 parser.processParam(seed, "Rng seeding");
00066
00067
00068 eoValueParam<eoRealVectorBounds> boundParam(eoRealVectorBounds(dimParam.value(),eoDummyRealNoBounds), "bounds","bounds",'b');
00069
00070 parser.processParam(boundParam, "Genetic Operators");
00071
00072 std::cout << "Bounds: " << boundParam.value() << std::endl;
00073
00074 eoState state;
00075 state.registerObject(parser);
00076
00077
00078 if (load_name.value() != "")
00079 {
00080
00081 state.load(load_name.value());
00082 }
00083
00084
00085
00086
00087 state.registerObject(rng);
00088
00089
00090 if (parser.userNeedsHelp())
00091 {
00092 parser.printHelp(std::cout);
00093 return 0;
00094 }
00095
00096
00097 if (load_name.value() != "")
00098 {
00099 state.load(load_name.value());
00100 }
00101 else
00102 {
00103
00104
00105
00106
00107 rng.reseed(seed.value());
00108 }
00109
00110
00111
00112
00113 if (save_name.value() != "")
00114 {
00115 std::string file_name = save_name.value();
00116 save_name.value() = "";
00117 state.save(file_name);
00118 }
00119
00120 for (int i = 0; i < 100; ++i)
00121 rng.rand();
00122
00123 std::cout << "a random number is " << rng.random(1024) << std::endl;;
00124
00125 return 1;
00126 }
00127
00128 int main(int argc, char **argv)
00129 {
00130 try
00131 {
00132 the_main(argc, argv);
00133 }
00134 catch(std::exception& e)
00135 {
00136 std::cout << "Exception: " << e.what() << std::endl;
00137 }
00138
00139 }