diff --git a/trunk/paradiseo-mo/src/mo.h b/trunk/paradiseo-mo/src/mo.h index 448080cd5..efdab5ded 100755 --- a/trunk/paradiseo-mo/src/mo.h +++ b/trunk/paradiseo-mo/src/mo.h @@ -41,11 +41,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include #include diff --git a/trunk/paradiseo-mo/src/moExpl.h b/trunk/paradiseo-mo/src/moExpl.h index b86a8d177..dc52e37ce 100644 --- a/trunk/paradiseo-mo/src/moExpl.h +++ b/trunk/paradiseo-mo/src/moExpl.h @@ -39,68 +39,75 @@ //! Description of an explorer /*! - Only a description...See moMoveLoopExpl. + This class allows to use any mutation object as a neighborhood. */ template < class EOT > class moExpl : public eoBF < const EOT &, EOT &, bool > { -public: - unsigned int i; - - //Neighborhoods vector - std::vector< eoMonOp* > explore; - - //! Generic constructor + public: + + //! Generic constructor /*! Generic constructor using a eoMonOp - \param _expl Algorithme or mutation. + \param _explorer Algorithme or mutation. */ - moExpl(eoMonOp & expl){ - i=0; - explore.resize(0); - add(expl); - } - - //! Generic constructor - /*! - Generic constructor using a eoMonOp - - \param _expl Algorithme or mutation. - - */ - - //! Procedure which launches the moExpl. + moExpl(eoMonOp & _explorer): index(0) + { + explorers.clear(); + addExplorer(_explorer); + } + + //! Procedure which launches the moExpl. /*! The exploration starts from an old solution and provides a new solution. - + \param _old_solution The current solution. \param _new_solution The new solution (result of the procedure). */ - bool operator ()(const EOT & _old, EOT & _new){ - _new=(EOT)_old; - return (*explore[i])(_new); - } - //add an algorithm or mutation to neighborhoods vector - void add(eoMonOp & expl){ - explore.push_back(&expl); - } - //setIndice make sur that the initial indice (_i) is not bigger than the explorer size. - void setIndice(unsigned int _i){ - if( _i >= explore.size() ){ - std::cout << "[" << _i << "]" << std::endl; - throw std::runtime_error("[moExpl.h]: bad index "+_i); - } - i=_i; - } + bool operator ()(const EOT & _old, EOT & _new) + { + _new=(EOT)_old; + return (*explorers[index])(_new); + } + + //! Add an algorithm or mutation to neighborhoods vector + void addExplorer(eoMonOp & _new_explorer) + { + explorers.push_back(&_new_explorer); + } + + //! Procedure which modified the current explorer to use. + /*! + \param _index Index of the explorer to use. + */ + void setCurrentExplorer(unsigned int _index) + { + if( _index >= explorers.size() ) + { + std::cout << "[" << _index << "]" << std::endl; + throw std::runtime_error("[moExpl.h]: bad index "+_index); + } + index=_index; + } + + //! Function which returns the number of explorers already saved. + /*! + \return The number of explorers contained in the moExpl. + */ + unsigned int getExplorerNumber() + { + return explorers.size(); + } + + private : - //return the size of the class - unsigned int size(){ - return explore.size(); - } + unsigned int index; + //!Neighborhoods vector + std::vector< eoMonOp* > explorers; }; #endif diff --git a/trunk/paradiseo-mo/src/moExponentialCoolingSchedule.h b/trunk/paradiseo-mo/src/moExponentialCoolingSchedule.h deleted file mode 100644 index 038f438fe..000000000 --- a/trunk/paradiseo-mo/src/moExponentialCoolingSchedule.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - - Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008 - (C) OPAC Team, LIFL, 2002-2008 - - Sébastien Cahon, Jean-Charles Boisson (Jean-Charles.Boisson@lifl.fr) - - This software is governed by the CeCILL license under French law and - abiding by the rules of distribution of free software. You can use, - modify and/ or redistribute the software under the terms of the CeCILL - license as circulated by CEA, CNRS and INRIA at the following URL - "http://www.cecill.info". - - As a counterpart to the access to the source code and rights to copy, - modify and redistribute granted by the license, users are provided only - with a limited warranty and the software's author, the holder of the - economic rights, and the successive licensors have only limited liability. - - In this respect, the user's attention is drawn to the risks associated - with loading, using, modifying and/or developing or reproducing the - software by the user in light of its specific status of free software, - that may mean that it is complicated to manipulate, and that also - therefore means that it is reserved for developers and experienced - professionals having in-depth computer knowledge. Users are therefore - encouraged to load and test the software's suitability as regards their - requirements in conditions enabling the security of their systems and/or - data to be ensured and, more generally, to use and operate it in the - same conditions as regards security. - The fact that you are presently reading this means that you have had - knowledge of the CeCILL license and that you accept its terms. - - ParadisEO WebSite : http://paradiseo.gforge.inria.fr - Contact: paradiseo-help@lists.gforge.inria.fr -*/ - -#ifndef _moExponentialCoolingSchedule_h -#define _moExponentialCoolingSchedule_h - -#include - -//! One of the possible moCoolingSchedule -/*! - An other very simple cooling schedule, the temperature decrease according to a ratio while - the temperature is greater than a given threshold. -*/ -class moExponentialCoolingSchedule: public moCoolingSchedule -{ - public: - - //! Simple constructor - /*! - \param _threshold the threshold. - \param _ratio the ratio used to descrease the temperature. - */ - moExponentialCoolingSchedule (double _threshold, double _ratio):threshold (_threshold), ratio (_ratio) - {} - - //! Function which proceeds to the cooling. - /*! - It decreases the temperature and indicates if it is greater than the threshold. - - \param _temperature the current temperature. - \return if the new temperature (current temperature * ratio) is greater than the threshold. - */ - bool operator() (double & _temperature) - { - return (_temperature *= ratio) > threshold; - } - - private: - - //! The temperature threhold. - double threshold; - - //! The decreasing factor of the temperature. - double ratio; -}; - -#endif diff --git a/trunk/paradiseo-mo/src/moSA.h b/trunk/paradiseo-mo/src/moSA.h index 296f45192..8506f799e 100755 --- a/trunk/paradiseo-mo/src/moSA.h +++ b/trunk/paradiseo-mo/src/moSA.h @@ -36,8 +36,6 @@ #ifndef _moSA_h #define _moSA_h -#include - #include #include #include diff --git a/trunk/paradiseo-mo/src/moTA.h b/trunk/paradiseo-mo/src/moTA.h index ee6f17d9b..e963c88ed 100644 --- a/trunk/paradiseo-mo/src/moTA.h +++ b/trunk/paradiseo-mo/src/moTA.h @@ -36,8 +36,6 @@ #ifndef _moTA_h #define _moTA_h -#include - #include #include #include @@ -45,9 +43,9 @@ #include #include -//! Threeshol Accepting (TA) +//! Threshold Accepting (TA) /*! - Class that describes a Threeshol Accepting algorithm. + Class that describes a Threshold Accepting algorithm. */ template < class M > class moTA:public moAlgo < typename M::EOType > @@ -63,20 +61,20 @@ class moTA:public moAlgo < typename M::EOType > //! TA constructor /*! - All the boxes used by a SA need to be given. + All the boxes used by a TA need to be given. It is equivalent to a SA object. \param _random_move_generator The move generator (generally randomly). \param _incremental_evaluation The (generally) efficient evaluation function \param _continue The stopping criterion. - \param _initial_threeshold The initial threeshold. + \param _initial_threshold The initial threshold. \param _cooling_schedule The cooling schedule, describes how the temperature is modified. \param _full_evaluation The full evaluation function. */ moTA (moRandMove < M > & _random_move_generator, moMoveIncrEval < M > & _incremental_evaluation, - moSolContinue < EOT > & _continue, double _initial_threeshold, moCoolingSchedule & _cooling_schedule, + moSolContinue < EOT > & _continue, double _initial_threshold, moCoolingSchedule & _cooling_schedule, eoEvalFunc < EOT > & _full_evaluation): random_move_generator(_random_move_generator), incremental_evaluation(_incremental_evaluation), - continu(_continue), initial_threeshold(_initial_threeshold), + continu(_continue), initial_threshold(_initial_threshold), cooling_schedule(_cooling_schedule), full_evaluation(_full_evaluation) {} @@ -91,7 +89,7 @@ class moTA:public moAlgo < typename M::EOType > { Fitness incremental_fitness, delta_fit; EOT best_solution; - double threeshold; + double threshold; M move; if (_solution.invalid()) @@ -99,7 +97,7 @@ class moTA:public moAlgo < typename M::EOType > full_evaluation (_solution); } - threeshold = initial_threeshold; + threshold = initial_threshold; best_solution = _solution; @@ -115,7 +113,7 @@ class moTA:public moAlgo < typename M::EOType > delta_fit = incremental_fitness - _solution.fitness (); - if ( threeshold > delta_fit) + if ( threshold > delta_fit) { move(_solution); @@ -131,7 +129,7 @@ class moTA:public moAlgo < typename M::EOType > } while ( continu (_solution)); } - while ( cooling_schedule (threeshold) ); + while ( cooling_schedule (threshold) ); _solution = best_solution; @@ -146,11 +144,11 @@ class moTA:public moAlgo < typename M::EOType > //! A (generally) efficient evaluation function. moMoveIncrEval < M > & incremental_evaluation; - //! Stopping criterion before threeshold update + //! Stopping criterion before threshold update moSolContinue < EOT > & continu; //! Initial temperature - double initial_threeshold; + double initial_threshold; //! The cooling schedule moCoolingSchedule & cooling_schedule; diff --git a/trunk/paradiseo-mo/src/moVNS.h b/trunk/paradiseo-mo/src/moVNS.h index 98695f27b..d200c2f31 100644 --- a/trunk/paradiseo-mo/src/moVNS.h +++ b/trunk/paradiseo-mo/src/moVNS.h @@ -36,9 +36,7 @@ #ifndef _moVNS_h #define _moVNS_h -#include -#include -#include +#include //! Variable Neighbors Search (VNS) /*! @@ -48,70 +46,86 @@ template < class EOT> class moVNS : public moAlgo < EOT> { - //! Alias for the fitness. - typedef typename EOT::Fitness Fitness; + //! Alias for the fitness. + typedef typename EOT::Fitness Fitness; -public: + public: - //! Generic constructor + //! Generic constructor /*! Generic constructor using a moExpl \param _explorer Vector of Neighborhoods. \param _full_evaluation The evaluation function. */ - - moVNS(moExpl< EOT> & _explorer, eoEvalFunc < EOT> & _full_evaluation): explorer(_explorer), full_evaluation(_full_evaluation) {} + moVNS(moExpl< EOT> & _explorer, eoEvalFunc < EOT> & _full_evaluation): explorer(_explorer), full_evaluation(_full_evaluation) {} - //! Function which launches the VNS + //! Function which launches the VNS /*! The VNS has to improve a current solution. \param _solution a current solution to improve. \return true. */ + bool operator()(EOT & _solution) + { + bool change; + unsigned int i; - bool operator()(EOT & _solution) { - bool change=false; - int i = 0; + EOT solution_prime, solution_second; + EOT solution_initial=_solution; - EOT solution_initial=_solution; - EOT solution_prime, solution_second; + change=false; + i=0; + explorer.setCurrentExplorer(i); + while( i solution_initial ) + { + solution_initial=solution_second; + change=true; + if(i!= 0) + { + i=0; + explorer.setCurrentExplorer(i); + } + } + else + { + i++; + if( i & explorer; - while(i solution_initial) { - solution_initial=solution_second; - change=true; - if(i!= 0) { - explorer.setIndice(0); - i=0; - } - } - else { - i++; - if(i & explorer; - //The full evaluation function - eoEvalFunc & full_evaluation; + //!The full evaluation function + eoEvalFunc & full_evaluation; }; #endif diff --git a/trunk/paradiseo-mo/test/CMakeLists.txt b/trunk/paradiseo-mo/test/CMakeLists.txt index 94ee35d63..4a98f0f7a 100644 --- a/trunk/paradiseo-mo/test/CMakeLists.txt +++ b/trunk/paradiseo-mo/test/CMakeLists.txt @@ -31,31 +31,31 @@ LINK_DIRECTORIES(${EO_BIN_DIR}/lib ${ParadisEO-MO_BINARY_DIR}/lib) ###################################################################################### SET (TEST_LIST t-moBestImprSelect - t-moExponentialCoolingSchedule - t-moFirstImprSelect - t-moFitComparator - t-moFitSolContinue - t-moGenSolContinue - t-moHC - t-moHC_2 - t-moHCMoveLoopExpl - t-moILS - t-moILS_HC - t-moILS_TS - t-moILS_SA - t-moImprBestFitAspirCrit - t-moItRandNextMove + t-moFirstImprSelect + t-moFitComparator + t-moFitSolContinue + t-moGenSolContinue + t-moGeometricCoolingSchedule + t-moHC + t-moHC_2 + t-moHCMoveLoopExpl + t-moILS + t-moILS_HC + t-moILS_TS + t-moILS_SA + t-moImprBestFitAspirCrit + t-moItRandNextMove t-moLinearCoolingSchedule - t-moLSCheckPoint - t-moNoAspirCrit - t-moNoFitImprSolContinue - t-moRandImprSelect - t-moSA - t-moSimpleMoveTabuList - t-moSimpleSolutionTabuList + t-moLSCheckPoint + t-moNoAspirCrit + t-moNoFitImprSolContinue + t-moRandImprSelect + t-moSA + t-moSimpleMoveTabuList + t-moSimpleSolutionTabuList t-moSteadyFitSolContinue - t-moTS - t-moTS_2 + t-moTS + t-moTS_2 t-moTSMoveLoopExpl t-moTA t-moVNS diff --git a/trunk/paradiseo-mo/test/t-moExponentialCoolingSchedule.cpp b/trunk/paradiseo-mo/test/t-moExponentialCoolingSchedule.cpp deleted file mode 100644 index 6ae395dce..000000000 --- a/trunk/paradiseo-mo/test/t-moExponentialCoolingSchedule.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* -* -* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 -* (C) OPAC Team, LIFL, 2002-2008 -* -* Sébastien Cahon, Jean-Charles Boisson (Jean-Charles.Boisson@lifl.fr) -* -* This software is governed by the CeCILL license under French law and -* abiding by the rules of distribution of free software. You can use, -* modify and/ or redistribute the software under the terms of the CeCILL -* license as circulated by CEA, CNRS and INRIA at the following URL -* "http://www.cecill.info". -* -* As a counterpart to the access to the source code and rights to copy, -* modify and redistribute granted by the license, users are provided only -* with a limited warranty and the software's author, the holder of the -* economic rights, and the successive licensors have only limited liability. -* -* In this respect, the user's attention is drawn to the risks associated -* with loading, using, modifying and/or developing or reproducing the -* software by the user in light of its specific status of free software, -* that may mean that it is complicated to manipulate, and that also -* therefore means that it is reserved for developers and experienced -* professionals having in-depth computer knowledge. Users are therefore -* encouraged to load and test the software's suitability as regards their -* requirements in conditions enabling the security of their systems and/or -* data to be ensured and, more generally, to use and operate it in the -* same conditions as regards security. -* The fact that you are presently reading this means that you have had -* knowledge of the CeCILL license and that you accept its terms. -* -* ParadisEO WebSite : http://paradiseo.gforge.inria.fr -* Contact: paradiseo-help@lists.gforge.inria.fr -* -*/ -//----------------------------------------------------------------------------- -// t-moExponentialCoolingSchedule.cpp -//----------------------------------------------------------------------------- - -#include // EO -#include // MO - -using std::cout; -using std::endl; - -//----------------------------------------------------------------------------- - - -//----------------------------------------------------------------------------- - -int -main() -{ - int return_value; - std::string test_result; - - unsigned int i; - double temperature; - - moExponentialCoolingSchedule coolingSchedule( 4.0, 0.5 ); - - temperature=10.0; - - cout << "[ moExponentialCoolingSchedule ] ==> "; - - i=0; - while( coolingSchedule(temperature) ) - { - i++; - } - - test_result=((i!=1)?"KO":"OK"); - return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); - - cout << test_result << endl; - return return_value; -} - -//----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moVNS.cpp b/trunk/paradiseo-mo/test/t-moVNS.cpp index da4164360..36fadfca0 100644 --- a/trunk/paradiseo-mo/test/t-moVNS.cpp +++ b/trunk/paradiseo-mo/test/t-moVNS.cpp @@ -112,7 +112,6 @@ int main() { std::string test_result; - int return_value; //solution solution; Route so ; @@ -120,7 +119,7 @@ main() Voisinage sol1; Voisinage sol2; Explorer explorer(sol1); - explorer.add(sol2); + explorer.addExplorer(sol2); solutionEval eval; moVNS vns(explorer, eval); @@ -135,7 +134,7 @@ main() cout << "OK" << endl; - return EXIT_SUCCESS; //return_value; + return EXIT_SUCCESS; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/tutorial/Lesson3/simulated_annealing.cpp b/trunk/paradiseo-mo/tutorial/Lesson3/simulated_annealing.cpp index 5f5274806..0905b3590 100644 --- a/trunk/paradiseo-mo/tutorial/Lesson3/simulated_annealing.cpp +++ b/trunk/paradiseo-mo/tutorial/Lesson3/simulated_annealing.cpp @@ -44,7 +44,7 @@ main (int _argc, char* _argv []) { std::string instancePath, value; unsigned int seed, maxIterations; - double threshold, exponentialRatio, linearRatio, initialTemperature; + double threshold, geometricRatio, linearRatio, initialTemperature; eoParser parser(_argc, _argv); @@ -55,7 +55,7 @@ main (int _argc, char* _argv []) maxIterations=atoi( (parser.getParamWithLongName("maxIter")->getValue()).c_str() ); initialTemperature=atof( (parser.getParamWithLongName("initialTemp")->getValue()).c_str() ); threshold=atof( (parser.getParamWithLongName("threshold")->getValue()).c_str() ); - exponentialRatio=atof( (parser.getParamWithLongName("expoRatio")->getValue()).c_str() ); + geometricRatio=atof( (parser.getParamWithLongName("geometricRatio")->getValue()).c_str() ); linearRatio=atof( (parser.getParamWithLongName("lineaRatio")->getValue()).c_str() ); value=parser.getParamWithLongName("coolSchedType")->getValue(); @@ -83,9 +83,9 @@ main (int _argc, char* _argv []) moCoolingSchedule* coolingSchedule; - if(value.compare("Expo")==0) + if(value.compare("Geometric")==0) { - coolingSchedule=new moExponentialCoolingSchedule(threshold, exponentialRatio); + coolingSchedule=new moGeometricCoolingSchedule(threshold, geometricRatio); } else if (value.compare("Linear")==0) { @@ -125,11 +125,11 @@ manage_configuration_file(eoParser & _parser) _parser.getORcreateParam((double)0.1, "threshold", "Minimum temperature allowed.", 0, "Configuration", false); - _parser.getORcreateParam((double)0.98, "expoRatio", "Ratio used if exponential cooling schedule is chosen.", 0, "Configuration", false); + _parser.getORcreateParam((double)0.98, "geometricRatio", "Ratio used if exponential cooling schedule is chosen.", 0, "Configuration", false); _parser.getORcreateParam((double)0.5, "lineaRatio", "Ratio used if linear cooling schedule is chosen.", 0, "Configuration", false); - _parser.getORcreateParam(std::string("Expo"), "coolSchedType", "Type the cooling schedule: 'Expo' or 'Linear'.", + _parser.getORcreateParam(std::string("Geometric"), "coolSchedType", "Type the cooling schedule: 'Geometric' or 'Linear'.", 0, "Configuration", false); if (_parser.userNeedsHelp()) diff --git a/trunk/paradiseo-mo/tutorial/Lesson5/variable_neighborhood_search.cpp b/trunk/paradiseo-mo/tutorial/Lesson5/variable_neighborhood_search.cpp index bbcd19e12..c03eaf256 100644 --- a/trunk/paradiseo-mo/tutorial/Lesson5/variable_neighborhood_search.cpp +++ b/trunk/paradiseo-mo/tutorial/Lesson5/variable_neighborhood_search.cpp @@ -112,8 +112,8 @@ main (int _argc, char* _argv []) //-----------neighbor vector-------------------------- moExpl explorer(perturbation); - explorer.add(hill_climbing); - explorer.add(perturbation); + explorer.addExplorer(hill_climbing); + explorer.addExplorer(perturbation); //------------VNS application--------------------------