moILS.h

00001 /*
00002   <moILS.h>
00003   Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
00004   (C) OPAC Team, LIFL, 2002-2008
00005  
00006   Sébastien Cahon, Jean-Charles Boisson (Jean-Charles.Boisson@lifl.fr)
00007  
00008   This software is governed by the CeCILL license under French law and
00009   abiding by the rules of distribution of free software.  You can  use,
00010   modify and/ or redistribute the software under the terms of the CeCILL
00011   license as circulated by CEA, CNRS and INRIA at the following URL
00012   "http://www.cecill.info".
00013  
00014   As a counterpart to the access to the source code and  rights to copy,
00015   modify and redistribute granted by the license, users are provided only
00016   with a limited warranty  and the software's author,  the holder of the
00017   economic rights,  and the successive licensors  have only  limited liability.
00018  
00019   In this respect, the user's attention is drawn to the risks associated
00020   with loading,  using,  modifying and/or developing or reproducing the
00021   software by the user in light of its specific status of free software,
00022   that may mean  that it is complicated to manipulate,  and  that  also
00023   therefore means  that it is reserved for developers  and  experienced
00024   professionals having in-depth computer knowledge. Users are therefore
00025   encouraged to load and test the software's suitability as regards their
00026   requirements in conditions enabling the security of their systems and/or
00027   data to be ensured and,  more generally, to use and operate it in the
00028   same conditions as regards security.
00029   The fact that you are presently reading this means that you have had
00030   knowledge of the CeCILL license and that you accept its terms.
00031  
00032   ParadisEO WebSite : http://paradiseo.gforge.inria.fr
00033   Contact: paradiseo-help@lists.gforge.inria.fr
00034 */
00035 
00036 #ifndef _moILS_h
00037 #define _moILS_h
00038 
00039 #include <eoEvalFunc.h>
00040 
00041 #include <moHC.h>
00042 #include <moTS.h>
00043 #include <moSA.h>
00044 
00046 
00049 template < class M >
00050 class moILS:public moAlgo < typename M::EOType >
00051 {
00053   typedef typename M::EOType EOT;
00054 
00056   typedef typename EOT::Fitness Fitness;
00057 
00058  public:
00059 
00061 
00070   moILS (moAlgo<EOT> & _algorithm, moSolContinue <EOT> & _continue, moComparator<EOT> & _acceptance_criterion, 
00071          eoMonOp<EOT> & _perturbation, eoEvalFunc<EOT> & _full_evaluation):
00072   algorithm(& _algorithm), continu(_continue), acceptance_criterion(_acceptance_criterion), 
00073     perturbation(_perturbation), full_evaluation(_full_evaluation), algorithm_memory_allocation(false)
00074   {}
00075 
00077 
00087   moILS (moMoveInit < M > & _move_initializer, moNextMove < M > & _next_move_generator, 
00088          moMoveIncrEval < M > & _incremental_evaluation, moMoveSelect < M > & _move_selection,
00089          moSolContinue <EOT> & _continue, moComparator<EOT> & _acceptance_criterion,
00090          eoMonOp<EOT> & _perturbation, eoEvalFunc<EOT> & _full_evaluation):
00091   algorithm(new moHC<M>(_move_initializer, _next_move_generator, _incremental_evaluation, _move_selection, _full_evaluation) ),
00092     continu(_continue), acceptance_criterion(_acceptance_criterion), perturbation(_perturbation), full_evaluation(_full_evaluation),
00093     algorithm_memory_allocation(true)
00094   {}
00095 
00097 
00109   moILS (moMoveInit <M> & _move_initializer, moNextMove <M> & _next_move_generator, 
00110          moMoveIncrEval <M> & _incremental_evaluation, moTabuList <M> & _tabu_list, 
00111          moAspirCrit <M> & _aspiration_criterion, moSolContinue <EOT> & _moTS_continue,
00112          moSolContinue <EOT> & _continue, moComparator<EOT> & _acceptance_criterion, eoMonOp<EOT> & _perturbation,
00113          eoEvalFunc<EOT> & _full_evaluation):
00114   algorithm(new moTS<M>(_move_initializer, _next_move_generator, _incremental_evaluation, _tabu_list, _aspiration_criterion, 
00115                      _moTS_continue, _full_evaluation) ),
00116     continu(_continue), acceptance_criterion(_acceptance_criterion), perturbation(_perturbation), full_evaluation(_full_evaluation),
00117     algorithm_memory_allocation(true)
00118   {}
00119   
00121 
00132   moILS (moRandMove<M> & _random_move_generator, moMoveIncrEval <M> & _incremental_evaluation, moSolContinue <EOT> & _moSA_continue, 
00133          double _initial_temperature, moCoolingSchedule & _cooling_schedule, moSolContinue <EOT> & _continue, 
00134          moComparator<EOT> & _acceptance_criterion, eoMonOp<EOT> & _perturbation, eoEvalFunc<EOT> & _full_evaluation):
00135   algorithm(new moSA<M>(_random_move_generator, _incremental_evaluation, _moSA_continue, _initial_temperature,
00136                         _cooling_schedule, _full_evaluation) ),
00137     continu(_continue), acceptance_criterion(_acceptance_criterion), perturbation(_perturbation), full_evaluation(_full_evaluation),
00138     algorithm_memory_allocation(true)
00139       {}
00140 
00142   ~moILS()
00143     {
00144       if(algorithm_memory_allocation)
00145         {
00146           delete(algorithm);
00147         }
00148     }
00149 
00151 
00158   bool operator()(EOT & _solution)
00159   {
00160     EOT _solution_saved=_solution;
00161 
00162     continu.init ();
00163 
00164     // some code has been duplicated in order to avoid one perturbation and one evaluation without adding a test in the loop.
00165     // better than a do {} while; with a test in the loop.
00166     
00167     (*algorithm)(_solution);
00168 
00169     if ( acceptance_criterion(_solution, _solution_saved) )
00170       {
00171         _solution_saved=_solution;
00172 
00173       }
00174     else
00175       {
00176         _solution=_solution_saved;
00177       }
00178 
00179     while ( continu (_solution) )
00180       {
00181         perturbation(_solution);
00182         full_evaluation(_solution);
00183 
00184         (*algorithm)(_solution);
00185 
00186         if ( acceptance_criterion(_solution, _solution_saved) )
00187           {
00188             _solution_saved=_solution;
00189           }
00190         else
00191           {
00192             _solution=_solution_saved;
00193           }
00194       }
00195 
00196     return true;
00197   }
00198 
00199  private:
00200 
00202   moAlgo<EOT> * algorithm;
00203 
00205   moSolContinue<EOT> & continu;
00206 
00208   moComparator<EOT> & acceptance_criterion;
00209 
00211   eoMonOp<EOT> & perturbation;
00212 
00214   eoEvalFunc<EOT> & full_evaluation;
00215 
00217   bool algorithm_memory_allocation;
00218 };
00219 
00220 #endif

Generated on Thu Mar 13 15:53:44 2008 for ParadisEO-MO-MovingObjects by  doxygen 1.4.7