EvolvingObjects
|
00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- 00002 00003 //----------------------------------------------------------------------------- 00004 // make_PBILdistrib.h 00005 // (c) Marc Schoenauer, Maarten Keijzer, 2001 00006 /* 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 Contact: Marc.Schoenauer@polytechnique.fr 00022 mkeijzer@dhi.dk 00023 */ 00024 //----------------------------------------------------------------------------- 00025 00026 #ifndef _make_PBILdistrib_h 00027 #define _make_PBILdistrib_h 00028 00029 #include <ctime> // for time(0) for random seeding 00030 #include <ga/eoPBILOrg.h> 00031 #include <utils/eoRNG.h> 00032 #include <utils/eoParser.h> 00033 #include <utils/eoState.h> 00034 00035 00037 00048 template <class EOT> 00049 eoPBILDistrib<EOT> & do_make_PBILdistrib(eoParser & _parser, eoState& _state, EOT) 00050 { 00051 // First the random seed 00052 eoValueParam<uint32_t>& seedParam = _parser.createParam(uint32_t(0), "seed", "Random number seed", 'S'); 00053 if (seedParam.value() == 0) 00054 seedParam.value() = time(0); 00055 00056 // chromosome size: 00057 unsigned theSize; 00058 // but it might have been already read in the definition fo the performance 00059 eoParam* ptParam = _parser.getParamWithLongName(std::string("chromSize")); 00060 00061 if (!ptParam) // not already defined: read it here 00062 { 00063 theSize = _parser.createParam(unsigned(10), "chromSize", "The length of the bitstrings", 'n',"Problem").value(); 00064 } 00065 else // it was read before, get its value 00066 { 00067 eoValueParam<unsigned>* ptChromSize = dynamic_cast<eoValueParam<unsigned>*>(ptParam); 00068 theSize = ptChromSize->value(); 00069 } 00070 00071 eoPBILDistrib<EOT> * ptDistrib = new eoPBILDistrib<EOT>(theSize); 00072 _state.storeFunctor(ptDistrib); 00073 00074 // now the initialization: read a previously saved distribution, or random 00075 eoValueParam<std::string>& loadNameParam = _parser.createParam(std::string(""), "Load","A save file to restart from",'L', "Persistence" ); 00076 if (loadNameParam.value() != "") // something to load 00077 { 00078 // create another state for reading 00079 eoState inState; // a state for loading - WITHOUT the parser 00080 // register the rng and the distribution in the state, 00081 // so they can be loaded, 00082 // and the present run will be the exact continuation of the saved run 00083 // eventually with different parameters 00084 inState.registerObject(*ptDistrib); 00085 inState.registerObject(rng); 00086 inState.load(loadNameParam.value()); // load the distrib and the rng 00087 } 00088 else // nothing loaded from a file 00089 { 00090 rng.reseed(seedParam.value()); 00091 } 00092 00093 // for future stateSave, register the algorithm into the state 00094 _state.registerObject(_parser); 00095 _state.registerObject(*ptDistrib); 00096 _state.registerObject(rng); 00097 00098 return *ptDistrib; 00099 } 00100 00101 #endif