moILS.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 // "moILS.h"
00004 
00005 // (c) OPAC Team, LIFL, 2003-2007
00006 
00007 /* LICENCE TEXT
00008    
00009    Contact: paradiseo-help@lists.gforge.inria.fr
00010 */
00011 
00012 #ifndef __moILS_h
00013 #define __moILS_h
00014 
00015 #include <eoEvalFunc.h>
00016 
00017 #include "moHC.h"
00018 #include "moTS.h"
00019 #include "moSA.h"
00020 
00022 
00025 template < class M > class moILS:public moAlgo < typename M::EOType >
00026 {
00027 
00029   typedef typename M::EOType EOT;
00030   
00032   typedef typename EOT::Fitness Fitness;
00033 
00034 public:
00035 
00037 
00046   moILS (moAlgo<EOT> &__algo, moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion, eoMonOp<EOT> &__perturbation, 
00047          eoEvalFunc<EOT> &__full_eval):
00048     algo(__algo), cont(__continue), acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
00049   {}
00050 
00052 
00062   moILS (moMoveInit < M > &__move_init, moNextMove < M > &__next_move, moMoveIncrEval < M > &__incr_eval,
00063          moMoveSelect < M > &__move_select, moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion, 
00064          eoMonOp<EOT> &__perturbation, eoEvalFunc<EOT> &__full_eval):
00065     algo(*new moHC<M>(__move_init, __next_move, __incr_eval, __move_select, __full_eval)), cont(__continue), 
00066     acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
00067   {}
00068 
00070 
00082   moILS (moMoveInit <M> &__move_init, moNextMove <M> &__next_move, moMoveIncrEval <M> &__incr_eval,
00083          moTabuList <M> &__tabu_list, moAspirCrit <M> &__aspir_crit, moSolContinue <EOT> &__moTS_continue, 
00084          moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion, eoMonOp<EOT> &__perturbation, 
00085          eoEvalFunc<EOT> &__full_eval):
00086     algo(*new moTS<M>(__move_init, __next_move, __incr_eval, __tabu_list, __aspir_crit, __moTS_continue, __full_eval)), 
00087     cont(__continue), acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
00088   {}
00089 
00091 
00102   moILS (moRandMove<M> &__move_rand, moMoveIncrEval <M> &__incr_eval, moSolContinue <EOT> &__moSA_continue, double __init_temp,
00103          moCoolingSchedule & __cool_sched, moSolContinue <EOT> &__continue, moComparator<EOT> &__acceptance_criterion, 
00104          eoMonOp<EOT> &__perturbation, eoEvalFunc<EOT> &__full_eval):
00105     algo(*new moSA<M>(__move_rand, __incr_eval, __moSA_continue, init_temp, __cool_sched, __full_eval)), 
00106     cont(__continue), acceptance_criterion(__acceptance_criterion), perturbation(__perturbation), full_eval(__full_eval)
00107   {}
00108 
00109 
00110 
00112 
00119   bool operator()(EOT & __sol)
00120   {
00121     EOT __sol_saved=__sol;
00122             
00123     cont.init ();
00124 
00125     //some code has been duplicated in order to avoid one perturbation and one evaluation without adding a test in the loop.
00126 
00127     //std::cout << "Before intensification: " << __sol.fitness() << std::endl; 
00128     algo(__sol);
00129     //std::cout << "After intensification: " << __sol.fitness() << std::endl; 
00130     
00131     if(acceptance_criterion(__sol, __sol_saved))
00132       {
00133         std::cout << "Accepted: " << __sol.fitness() << std::endl;
00134         __sol_saved=__sol;
00135         
00136       }
00137     else
00138       {
00139         //std::cout << "Refused" << std::endl;
00140         __sol=__sol_saved;
00141       }
00142     
00143     while (cont (__sol))
00144     {
00145       perturbation(__sol);
00146       full_eval(__sol);
00147       
00148       //std::cout << "Before intensification: " << __sol.fitness() << std::endl; 
00149       algo(__sol);
00150       //std::cout << "After intensification: " << __sol.fitness() << std::endl; 
00151       
00152       if(acceptance_criterion(__sol, __sol_saved))
00153         {
00154           std::cout << "Accepted: " << __sol.fitness() << std::endl;
00155           __sol_saved=__sol;
00156         }
00157       else
00158         {
00159           //std::cout << "Refused" << std::endl;
00160           __sol=__sol_saved;
00161         }
00162     }
00163     
00164     return true;
00165   }
00166 
00167 private:
00168 
00170   moAlgo<EOT> &algo;
00171 
00173   moSolContinue<EOT> &cont;
00174 
00176   moComparator<EOT> &acceptance_criterion;
00177 
00179   eoMonOp<EOT> &perturbation;
00180   
00182   eoEvalFunc<EOT> &full_eval;
00183 };
00184 
00185 #endif

Generated on Thu Sep 20 11:30:28 2007 for ParadisEO-MOMovingObjects by  doxygen 1.5.2