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

# make_continue_pareto.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // make_continue_pareto.h
    00005 // (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2000
    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: todos@geneura.ugr.es, http://geneura.ugr.es
    00022              Marc.Schoenauer@inria.fr
    00023              mkeijzer@dhi.dk
    00024  */
    00025 //-----------------------------------------------------------------------------
    00026
    00027 #ifndef _make_continue_pareto_h
    00028 #define _make_continue_pareto_h
    00029
    00030 /*
    00031 Contains the templatized version of parser-based choice of stopping criterion
    00032 for Pareto optimization (e.g. no "... without improvement" criterion
    00033 It can then be instantiated, and compiled on its own for a given EOType
    00034 (see e.g. in dir ga, ga.cpp)
    00035 */
    00036
    00037 // Continuators - all include eoContinue.h
    00038 #include <eoCombinedContinue.h>
    00039 #include <eoGenContinue.h>
    00040 #include <eoEvalContinue.h>
    00041 #include <eoFitContinue.h>
    00042 #ifndef _MSC_VER
    00043 #include <eoCtrlCContinue.h>  // CtrlC handling (using 2 global variables!)
    00044 #endif
    00045
    00046   // also need the parser and param includes
    00047 #include <utils/eoParser.h>
    00048 #include <utils/eoState.h>
    00049
    00050
    00052 template <class Indi>
    00053 eoCombinedContinue<Indi> * make_combinedContinue(eoCombinedContinue<Indi> *_combined, eoContinue<Indi> *_cont)
    00054 {
    00055   if (_combined)                   // already exists
    00056     _combined->add(*_cont);
    00057   else
    00058     _combined = new eoCombinedContinue<Indi>(*_cont);
    00059   return _combined;
    00060 }
    00061
    00063 template <class Indi>
    00064 eoContinue<Indi> & do_make_continue_pareto(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi> & _eval)
    00065 {
    00067   // the combined continue - to be filled
    00068   eoCombinedContinue<Indi> *continuator = NULL;
    00069
    00070   // for each possible criterion, check if wanted, otherwise do nothing
    00071
    00072   // First the eoGenContinue - need a default value so you can run blind
    00073   // but we also need to be able to avoid it <--> 0
    00074   eoValueParam<unsigned>& maxGenParam = _parser.createParam(unsigned(100), "maxGen", "Maximum number of generations () = none)",'G',"Stopping criterion");
    00075
    00076     if (maxGenParam.value()) // positive: -> define and store
    00077       {
    00078         eoGenContinue<Indi> *genCont = new eoGenContinue<Indi>(maxGenParam.value());
    00079         _state.storeFunctor(genCont);
    00080         // and "add" to combined
    00081         continuator = make_combinedContinue<Indi>(continuator, genCont);
    00082       }
    00083
    00084 #ifndef _MSC_VER
    00085     // the CtrlC interception (Linux only I'm afraid)
    00086     eoCtrlCContinue<Indi> *ctrlCCont;
    00087     eoValueParam<bool>& ctrlCParam = _parser.createParam(true, "CtrlC", "Terminate current generation upon Ctrl C",'C', "Stopping criterion");
    00088     if (_parser.isItThere(ctrlCParam))
    00089       {
    00090         ctrlCCont = new eoCtrlCContinue<Indi>;
    00091         // store
    00092         _state.storeFunctor(ctrlCCont);
    00093         // add to combinedContinue
    00094         continuator = make_combinedContinue<Indi>(continuator, ctrlCCont);
    00095       }
    00096 #endif
    00097
    00098     // now check that there is at least one!
    00099     if (!continuator)
    00100       throw std::runtime_error("You MUST provide a stopping criterion");
    00101   // OK, it's there: store in the eoState
    00102   _state.storeFunctor(continuator);
    00103
    00104   // and return
    00105     return *continuator;
    00106 }
    00107
    00108 #endif