# ParadisEO-MOMovingObjects: moILS.h Source File

# 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)
    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   {}
    00094
    00096
    00108   moILS (moMoveInit <M> & _move_initializer, moNextMove <M> & _next_move_generator,
    00109          moMoveIncrEval <M> & _incremental_evaluation, moTabuList <M> & _tabu_list,
    00110          moAspirCrit <M> & _aspiration_criterion, moSolContinue <EOT> & _moTS_continue,
    00111          moSolContinue <EOT> & _continue, moComparator<EOT> & _acceptance_criterion, eoMonOp<EOT> & _perturbation,
    00112          eoEvalFunc<EOT> & _full_evaluation):
    00113   algorithm( *new moTS<M>(_move_initializer, _next_move_generator, _incremental_evaluation, _tabu_list, _aspiration_criterion,
    00114                      _moTS_continue, _full_evaluation) ),
    00115     continu(_continue), acceptance_criterion(_acceptance_criterion), perturbation(_perturbation), full_evaluation(_full_evaluation)
    00116   {}
    00117
    00119
    00130   moILS (moRandMove<M> & _random_move_generator, moMoveIncrEval <M> & _incremental_evaluation, moSolContinue <EOT> & _moSA_continue,
    00131          double _initial_temperature, moCoolingSchedule & _cooling_schedule, moSolContinue <EOT> & _continue,
    00132          moComparator<EOT> & _acceptance_criterion, eoMonOp<EOT> & _perturbation, eoEvalFunc<EOT> & _full_evaluation):
    00133   algorithm( *new moSA<M>(_random_move_generator, _incremental_evaluation, _moSA_continue, _initial_temperature,
    00134                      _cooling_schedule, _full_evaluation) ),
    00135     continu(_continue), acceptance_criterion(_acceptance_criterion), perturbation(_perturbation), full_evaluation(_full_evaluation)
    00136   {}
    00137
    00139
    00146   bool operator()(EOT & _solution)
    00147   {
    00148     EOT _solution_saved=_solution;
    00149
    00150     continu.init ();
    00151
    00152     // some code has been duplicated in order to avoid one perturbation and one evaluation without adding a test in the loop.
    00153     // better than a do {} while; with a test in the loop.
    00154
    00155     algorithm(_solution);
    00156
    00157     if ( acceptance_criterion(_solution, _solution_saved) )
    00158       {
    00159         _solution_saved=_solution;
    00160
    00161       }
    00162     else
    00163       {
    00164         _solution=_solution_saved;
    00165       }
    00166
    00167     while ( continu (_solution) )
    00168       {
    00169         perturbation(_solution);
    00170         full_evaluation(_solution);
    00171
    00172         algorithm(_solution);
    00173
    00174         if ( acceptance_criterion(_solution, _solution_saved) )
    00175           {
    00176             _solution_saved=_solution;
    00177           }
    00178         else
    00179           {
    00180             _solution=_solution_saved;
    00181           }
    00182       }
    00183
    00184     return true;
    00185   }
    00186
    00187  private:
    00188
    00190   moAlgo<EOT> & algorithm;
    00191
    00193   moSolContinue<EOT> & continu;
    00194
    00196   moComparator<EOT> & acceptance_criterion;
    00197
    00199   eoMonOp<EOT> & perturbation;
    00200
    00202   eoEvalFunc<EOT> & full_evaluation;
    00203 };
    00204
    00205 #endif