From 8c6610ec67558df7ee3c4bdb23a1c679e5652781 Mon Sep 17 00:00:00 2001 From: LPTK Date: Mon, 1 Jul 2013 16:36:10 +0200 Subject: [PATCH] intermediate commit 4 --- eo/src/utils/eoUpdater.h | 23 +++ mo/src/algo/moMetropolisHasting.h | 110 ---------- mo/src/algo/moSA.h | 79 ++++---- mo/src/continuator/moUpdater.h | 5 +- .../coolingSchedule/moTrikiCoolingSchedule.h | 69 ++++++- mo/src/explorer/moMetropolisHastingExplorer.h | 190 ------------------ mo/src/explorer/moNeighborhoodExplorer.h | 10 +- mo/src/mo.h | 7 +- .../sampling/moMHBestFitnessCloudSampling.h | 4 +- mo/src/sampling/moMHRndFitnessCloudSampling.h | 4 +- mo/test/CMakeLists.txt | 6 +- mo/test/t-moMetropolisHasting.cpp | 65 ------ mo/test/t-moMetropolisHastingExplorer.cpp | 97 --------- mo/test/t-moSAexplorer.cpp | 87 -------- 14 files changed, 149 insertions(+), 607 deletions(-) delete mode 100644 mo/src/algo/moMetropolisHasting.h delete mode 100644 mo/src/explorer/moMetropolisHastingExplorer.h delete mode 100644 mo/test/t-moMetropolisHasting.cpp delete mode 100644 mo/test/t-moMetropolisHastingExplorer.cpp delete mode 100644 mo/test/t-moSAexplorer.cpp diff --git a/eo/src/utils/eoUpdater.h b/eo/src/utils/eoUpdater.h index 072b9a9bb..e86225950 100644 --- a/eo/src/utils/eoUpdater.h +++ b/eo/src/utils/eoUpdater.h @@ -50,6 +50,29 @@ public: eoUpdater& addTo(eoCheckPoint& cp) { cp.add(*this); return *this; } }; +/** + an eoUpdater that simply calls a function with no arguments + + @ingroup Utilities +*/ +class eoFunctionCaller : public eoUpdater +{public : + /** Default Ctor - requires a pointer to the function to call */ + eoFunctionCaller(void (*_fct)()) + : fct(_fct) + { } + + /** Simply increments */ + virtual void operator()() + { + (*fct)(); + } + + virtual std::string className(void) const { return "eoFunctionCaller"; } +private: + void (*fct)(); +}; + /** an eoUpdater that simply increments a counter diff --git a/mo/src/algo/moMetropolisHasting.h b/mo/src/algo/moMetropolisHasting.h deleted file mode 100644 index 5b4292459..000000000 --- a/mo/src/algo/moMetropolisHasting.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - -Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 - -Sebastien Verel, Arnaud Liefooghe, Jeremie Humeau - -This software is governed by the CeCILL license under French law and -abiding by the rules of distribution of free software. You can ue, -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". - -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 _moMetropolisHasting_h -#define _moMetropolisHasting_h - -#include -#include -#include -#include -#include - -/** - * Metropolis-Hasting local search - * Only the symetric case is considered when Q(x,y) = Q(y,x) - * Fitness must be > 0 - * - * At each iteration, - * one of the random solution in the neighborhood is selected - * if the selected neighbor have higher or equal fitness than the current solution - * then the solution is replaced by the selected neighbor - * if a random number from [0,1] is lower than fitness(neighbor) / fitness(solution) - * then the solution is replaced by the selected neighbor - * the algorithm stops when the number of iterations is too large - */ -template -class moMetropolisHasting: public moLocalSearch -{ -public: - typedef typename Neighbor::EOT EOT; - typedef moNeighborhood Neighborhood ; - - /** - * Basic constructor of the Metropolis-Hasting - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _nbStep maximum step to do - */ - moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep): - moLocalSearch(explorer, trueCont, _fullEval), - explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep) - {} - - /** - * Simple constructor of the Metropolis-Hasting - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _nbStep maximum step to do - * @param _cont an external continuator - */ - moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep, moContinuator& _cont): - moLocalSearch(explorer, _cont, _fullEval), - explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep) - {} - - /** - * General constructor of the Metropolis-Hasting - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _nbStep maximum step to do - * @param _cont an external continuator - * @param _compN a neighbor vs neighbor comparator - * @param _compSN a solution vs neighbor comparator - */ - moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep, moContinuator& _cont, moNeighborComparator& _compN, moSolNeighborComparator& _compSN): - moLocalSearch(explorer, _cont, _fullEval), - explorer(_neighborhood, _eval, _compN, _compSN, _nbStep) - {} - -private: - // always true continuator - moTrueContinuator trueCont; - // compare the fitness values of neighbors - moNeighborComparator defaultNeighborComp; - // compare the fitness values of the solution and the neighbor - moSolNeighborComparator defaultSolNeighborComp; - // MetropolisHasting explorer - moMetropolisHastingExplorer explorer; -}; - -#endif diff --git a/mo/src/algo/moSA.h b/mo/src/algo/moSA.h index 89c61ad3a..0914f0db0 100644 --- a/mo/src/algo/moSA.h +++ b/mo/src/algo/moSA.h @@ -2,7 +2,7 @@ Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 -Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau +Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau, Lionel Parreaux This software is governed by the CeCILL license under French law and abiding by the rules of distribution of free software. You can ue, @@ -31,7 +31,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr #define _moSA_h #include -#include +#include #include #include #include @@ -64,16 +64,16 @@ public: /*moSA(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, double _initT=10, double _alpha=0.9, unsigned _span=100, double _finalT=0.01) : defaultCool(_initT, _alpha, _span, _finalT), explorer(_neighborhood, _eval, defaultSolNeighborComp, defaultCool), - moLocalSearch(explorer, trueCont, _fullEval) + moLocalSearch(explorer, defaultContinuator, _fullEval) { }*/ moSA(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, double _initT=10, double _alpha=0.9, unsigned _span=100, double _finalT=0.01) : moLocalSearch ( - explorer_ptr = defaultExplorer = new moSAexplorer(_neighborhood, _eval, NULL, *(defaultCool = new moSimpleCoolingSchedule(_initT, _alpha, _span, _finalT))), - *(trueCont = new moTrueContinuator()), + explorer_ptr = defaultExplorer = new moSAExplorer(_neighborhood, _eval, /*NULL,*/ *(defaultCool = new moSimpleCoolingSchedule(_initT, _alpha, _span, _finalT)), NULL), + *(defaultContinuator = new moTrueContinuator()), _fullEval ), explorer(*explorer_ptr), //defaultCool(), - default_eval(NULL) // removed in C++11 with unique_ptr + defaultEval(NULL) // removed in C++11 with unique_ptr //defaultSolNeighborComp(new moSolNeighborComparator()) //explorer(_neighborhood, _eval, *defaultSolNeighborComp, *defaultCool) { } @@ -86,7 +86,7 @@ public: // * @param _cool a cooling schedule // */ // moSA(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, moCoolingSchedule& _cool): -// moLocalSearch(explorer, trueCont, _fullEval), +// moLocalSearch(explorer, defaultContinuator, _fullEval), // defaultCool(0, 0, 0, 0), // explorer(_neighborhood, _eval, defaultSolNeighborComp, _cool) // {} @@ -137,56 +137,59 @@ public: eoOptional< moContinuator > _cont = NULL, eoOptional< moSolNeighborComparator > _comp = NULL ) - /*: moLocalSearch(explorer, _cont.hasValue()? _cont.get(): *(trueCont = new moTrueContinuator()), _fullEval), + /*: moLocalSearch(explorer, _cont.hasValue()? _cont.get(): *(defaultContinuator = new moTrueContinuator()), _fullEval), defaultCool(NULL), // removed in C++11 with unique_ptr - default_eval(NULL), // removed in C++11 with unique_ptr + defaultEval(NULL), // removed in C++11 with unique_ptr defaultSolNeighborComp(NULL), // removed in C++11 with unique_ptr - trueCont(NULL), // removed in C++11 with unique_ptr + defaultContinuator(NULL), // removed in C++11 with unique_ptr explorer ( _neighborhood, - _eval.hasValue()? _eval.get(): *(default_eval = new moFullEvalByCopy(_fullEval)), - // C++11: _eval.hasValue()? _eval.get(): default_eval = new moFullEvalByCopy(), + _eval.hasValue()? _eval.get(): *(defaultEval = new moFullEvalByCopy(_fullEval)), + // C++11: _eval.hasValue()? _eval.get(): defaultEval = new moFullEvalByCopy(), _comp.hasValue()? _comp.get(): *(defaultSolNeighborComp = new moSolNeighborComparator()), _cool ) { }*/ : moLocalSearch ( - explorer_ptr = defaultExplorer = new moSAexplorer ( + explorer_ptr = defaultExplorer = new moSAExplorer ( _neighborhood, - //_eval, //_eval.hasValue()? _eval.get(): *(default_eval = new moFullEvalByCopy(_fullEval)), - _eval.hasValue()? default_eval = NULL, _eval.get(): *(default_eval = new moFullEvalByCopy(_fullEval)), - // C++11: _eval.hasValue()? _eval.get(): default_eval = new moFullEvalByCopy(), - _comp, //_comp.hasValue()? _comp.get(): *(defaultSolNeighborComp = new moSolNeighborComparator()), - _cool ), - _cont.hasValue()? trueCont = NULL, _cont.get(): *(trueCont = new moTrueContinuator()), + //_eval, //_eval.hasValue()? _eval.get(): *(defaultEval = new moFullEvalByCopy(_fullEval)), + _eval.hasValue()? defaultEval = NULL, _eval.get(): *(defaultEval = new moFullEvalByCopy(_fullEval)), + // C++11: _eval.hasValue()? _eval.get(): defaultEval = new moFullEvalByCopy(), + //_comp, //_comp.hasValue()? _comp.get(): *(defaultSolNeighborComp = new moSolNeighborComparator()), + //_cool ), + _cool, + _comp ), + // ), + _cont.hasValue()? defaultContinuator = NULL, _cont.get(): *(defaultContinuator = new moTrueContinuator()), _fullEval ), explorer(*explorer_ptr), defaultCool(NULL) // removed in C++11 with unique_ptr - //default_eval(NULL), // removed in C++11 with unique_ptr - //trueCont(NULL) // removed in C++11 with unique_ptr + //defaultEval(NULL), // removed in C++11 with unique_ptr + //defaultContinuator(NULL) // removed in C++11 with unique_ptr //defaultSolNeighborComp(NULL) // removed in C++11 with unique_ptr { } moSA ( eoEvalFunc& _fullEval, - moSAexplorer& _explorer, + moSAExplorer& _explorer, eoOptional< moContinuator > _cont = NULL ) : moLocalSearch ( *(explorer_ptr = &_explorer), - _cont.hasValue()? _cont.get(): *(trueCont = new moTrueContinuator()), _fullEval ), + _cont.hasValue()? _cont.get(): *(defaultContinuator = new moTrueContinuator()), _fullEval ), defaultExplorer(NULL), // removed in C++11 with unique_ptr explorer(*explorer_ptr), defaultCool(NULL), // removed in C++11 with unique_ptr - //default_eval(NULL), // removed in C++11 with unique_ptr - trueCont(NULL) // removed in C++11 with unique_ptr + //defaultEval(NULL), // removed in C++11 with unique_ptr + defaultContinuator(NULL) // removed in C++11 with unique_ptr //defaultSolNeighborComp(NULL) // removed in C++11 with unique_ptr { } /* moSA ( eoEvalFunc& _fullEval, - moSAexplorer& _explorer, + moSAExplorer& _explorer, moContinuator _cont ) : moLocalSearch ( @@ -194,8 +197,8 @@ public: _cont, _fullEval ), defaultExplorer(NULL), // removed in C++11 with unique_ptr defaultCool(NULL), // removed in C++11 with unique_ptr - //default_eval(NULL), // removed in C++11 with unique_ptr - trueCont(NULL) // removed in C++11 with unique_ptr + //defaultEval(NULL), // removed in C++11 with unique_ptr + defaultContinuator(NULL) // removed in C++11 with unique_ptr //defaultSolNeighborComp(NULL) // removed in C++11 with unique_ptr { } */ @@ -207,22 +210,22 @@ public: virtual ~moSA () { // Note: using unique_ptr would allow us to remove this explicit destructor, but they were only introduced in C++11 - if (trueCont != NULL) - delete trueCont; + if (defaultContinuator != NULL) + delete defaultContinuator; if (defaultExplorer != NULL) delete defaultExplorer; - if (default_eval != NULL) - delete default_eval; + if (defaultEval != NULL) + delete defaultEval; } private: - moFullEvalByCopy* default_eval; - moSAexplorer* defaultExplorer; - moSAexplorer* explorer_ptr; // Not NULL - moSAexplorer& explorer; + moFullEvalByCopy* defaultEval; + moSAExplorer* defaultExplorer; + moSAExplorer* explorer_ptr; // Not NULL + moSAExplorer& explorer; moSimpleCoolingSchedule* defaultCool; // C++11: const std::unique_ptr> - //moFullEvalByCopy* default_eval; - moTrueContinuator* trueCont; + //moFullEvalByCopy* defaultEval; + moTrueContinuator* defaultContinuator; //moSolNeighborComparator* defaultSolNeighborComp; }; diff --git a/mo/src/continuator/moUpdater.h b/mo/src/continuator/moUpdater.h index 0be846d38..37a26a04f 100644 --- a/mo/src/continuator/moUpdater.h +++ b/mo/src/continuator/moUpdater.h @@ -39,9 +39,8 @@ #include /** - * Base class for to update what ever you want - * similar to eoUpdater - * But there is an init method ! + * Base class for updating whatever you want. + * Similar to eoUpdater, but there is an "init" method ! */ class moUpdater : public eoF { diff --git a/mo/src/coolingSchedule/moTrikiCoolingSchedule.h b/mo/src/coolingSchedule/moTrikiCoolingSchedule.h index 5c1e7e0c8..900e3b189 100644 --- a/mo/src/coolingSchedule/moTrikiCoolingSchedule.h +++ b/mo/src/coolingSchedule/moTrikiCoolingSchedule.h @@ -132,6 +132,7 @@ public: void update(double& _temp, bool _acceptedMove, EOT & _solution) { //cout << _temp << " g " << generated << endl; + prevTemp = _temp; generated++; @@ -147,9 +148,12 @@ public: //cout << _solution.fitness() << " avgCost=" << momentStat.value().first << endl; } + markovChainEnded = false; if (accepted > max_accepted || generated > max_generated) { + markovChainEnded = true; + if (accepted == 0) // ADDED! Otherwise the computed std dev is null; we're probably at equilibrium { /// @@ -301,9 +305,24 @@ public: return frozen < theta && !terminated ; // ADDED! because 'frozen' doesn't terminate anything } + + + bool markovChainJustEnded() + { + return markovChainEnded; + } -//private: -public://FIXME add friend + MarkovChainStats& getMarkovChainStats() + { + return markovChainStats; + } + + + + + +private: +//public://FIXME add friend //moNeighborhoodStat nhStat; //moStdFitnessNeighborStat stdDevStat; const double @@ -325,7 +344,8 @@ public://FIXME add friend stdDev, prevAvgCost, expectedDecreaseInCost, // delta - costs_sum + costs_sum, + prevTemp ; const int max_accepted, @@ -339,7 +359,7 @@ public://FIXME add friend negative_temp, frozen ; - bool reinitializing, terminated; + bool reinitializing, terminated, markovChainEnded; //moFitnessVarianceStat varStat; moFitnessMomentsStat momentStat; @@ -347,7 +367,48 @@ public://FIXME add friend ofstream outf; + +protected: + + class Monitor { + public: + + Monitor(moTrikiCoolingSchedule& _cooling) + : cooling(_cooling) + { } + + /*void setTemperatureOstream(ostream& os) + { + + }*/ + void getLatestTemperature() + { + return cooling.prevTemp; + } + + void printCurrentStatus(ostream& os) + { + if (accepted >= max_accepted || generated >= max_generated) + { + os << "Markov chain finished. Temp was " << getLatestTemperature(); // chain number + + } + } + + private: + moTrikiCoolingSchedule& cooling; + }; + }; #endif + + + + + + + + + diff --git a/mo/src/explorer/moMetropolisHastingExplorer.h b/mo/src/explorer/moMetropolisHastingExplorer.h deleted file mode 100644 index ee6169d99..000000000 --- a/mo/src/explorer/moMetropolisHastingExplorer.h +++ /dev/null @@ -1,190 +0,0 @@ -/* - - Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 - - Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau - - 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 _moMetropolisHastingExplorer_h -#define _moMetropolisHastingExplorer_h - -#include - -#include -#include -#include -#include - -#include - -/** - * Explorer for the Metropolis-Hasting Sampling. - * Only the symetric case is considered when Q(x,y) = Q(y,x) - * Fitness must be > 0 - */ -template< class Neighbor > -class moMetropolisHastingExplorer : public moNeighborhoodExplorer -{ -public: - typedef typename Neighbor::EOT EOT ; - typedef moNeighborhood Neighborhood ; - - using moNeighborhoodExplorer::neighborhood; - using moNeighborhoodExplorer::eval; - using moNeighborhoodExplorer::selectedNeighbor; - - /** - * Constructor - * @param _neighborhood the neighborhood - * @param _eval the evaluation function - * @param _neighborComparator a neighbor comparator - * @param _solNeighborComparator a solution vs neighbor comparator - * @param _nbStep maximum number of step to do - */ - moMetropolisHastingExplorer( - Neighborhood& _neighborhood, - moEval& _eval, - moNeighborComparator& _neighborComparator, - moSolNeighborComparator& _solNeighborComparator, - unsigned int _nbStep - ): moNeighborhoodExplorer(_neighborhood, _eval), - neighborComparator(_neighborComparator), - solNeighborComparator(_solNeighborComparator), - nbStep(_nbStep) - { - isAccept = false; - if (!neighborhood.isRandom()) { - std::cout << "moMetropolisHastingExplorer::Warning -> the neighborhood used is not random" << std::endl; - } - } - - /** - * Destructor - */ - ~moMetropolisHastingExplorer() { - } - - /** - * initialization of the number of step to be done - * @param _solution unused solution - */ - virtual void initParam(EOT & _solution) { - step = 0; - isAccept = true; - }; - - /** - * increase the number of step - * @param _solution unused solution - */ - virtual void updateParam(EOT & _solution) { - step++; - }; - - /** - * terminate: NOTHING TO DO - * @param _solution unused solution - */ - virtual void terminate(EOT & _solution) {}; - - /** - * Explore the neighborhood of a solution - * @param _solution - */ - virtual void operator()(EOT & _solution) { - //Test if _solution has a Neighbor - if (neighborhood.hasNeighbor(_solution)) { - //init the first neighbor - neighborhood.init(_solution, selectedNeighbor); - - //eval the _solution moved with the neighbor and stock the result in the neighbor - eval(_solution, selectedNeighbor); - } - else { - //if _solution hasn't neighbor, - isAccept=false; - } - }; - - /** - * continue if there is a neighbor and it is remainds some steps to do - * @param _solution the solution - * @return true there is some steps to do - */ - virtual bool isContinue(EOT & _solution) { - return (step < nbStep) ; - }; - - /** - * accept test if an ameliorated neighbor was found - * @param _solution the solution - * @return true if the best neighbor ameliorate the fitness - */ - virtual bool accept(EOT & _solution) { - double alpha=0.0; - if (neighborhood.hasNeighbor(_solution)) { - if (solNeighborComparator(_solution, selectedNeighbor)) - isAccept = true; - else { - if (_solution.fitness() != 0) { - if ( (double)selectedNeighbor.fitness() < (double)_solution.fitness()) // maximizing - alpha = (double) selectedNeighbor.fitness() / (double) _solution.fitness(); - else //minimizing - alpha = (double) _solution.fitness() / (double) selectedNeighbor.fitness(); - isAccept = (rng.uniform() < alpha) ; - } - else { - if ( (double) selectedNeighbor.fitness() < (double) _solution.fitness()) // maximizing - isAccept = true; - else - isAccept = false; - } - } - } - return isAccept; - }; - -private: - // comparator betwenn solution and neighbor or between neighbors - moNeighborComparator& neighborComparator; - moSolNeighborComparator& solNeighborComparator; - - // current number of step - unsigned int step; - - // maximum number of steps to do - unsigned int nbStep; - - // true if the move is accepted - bool isAccept ; -}; - - -#endif diff --git a/mo/src/explorer/moNeighborhoodExplorer.h b/mo/src/explorer/moNeighborhoodExplorer.h index 8b4113b7a..76ee12af7 100644 --- a/mo/src/explorer/moNeighborhoodExplorer.h +++ b/mo/src/explorer/moNeighborhoodExplorer.h @@ -65,15 +65,19 @@ public: typedef typename Neighbor::EOT EOT; typedef typename EOT::Fitness Fitness ; - moNeighborhoodExplorer():neighborhood(dummyNeighborhood), eval(dummyEval), isMoved(false) {} + moNeighborhoodExplorer() + : neighborhood(dummyNeighborhood), eval(dummyEval), isMoved(false) + { } /** * Constructor with a Neighborhood and evaluation function * @param _neighborhood the neighborhood * @param _eval the evaluation function */ - moNeighborhoodExplorer(Neighborhood& _neighborhood, moEval& _eval):neighborhood(_neighborhood), eval(_eval), isMoved(false) {} - + moNeighborhoodExplorer(Neighborhood& _neighborhood, moEval& _eval) + : neighborhood(_neighborhood), eval(_eval), isMoved(false) + { } + /** * Init Search parameters * @param _solution the solution to explore diff --git a/mo/src/mo.h b/mo/src/mo.h index 3e65f8081..ef83384be 100755 --- a/mo/src/mo.h +++ b/mo/src/mo.h @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include #include #include @@ -118,14 +118,15 @@ #include #include #include -#include +#include #include #include #include #include #include #include -#include +#include +//#include #include #include #include diff --git a/mo/src/sampling/moMHBestFitnessCloudSampling.h b/mo/src/sampling/moMHBestFitnessCloudSampling.h index ebba8a3b9..e9c71f35b 100644 --- a/mo/src/sampling/moMHBestFitnessCloudSampling.h +++ b/mo/src/sampling/moMHBestFitnessCloudSampling.h @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include @@ -87,7 +87,7 @@ public: delete localSearch; // Metropolis-Hasting sampling - localSearch = new moMetropolisHasting(_neighborhood, _fullEval, _eval, _nbStep); + localSearch = new moMetropolisHastings(_neighborhood, _fullEval, _eval, _nbStep); // delete the checkpoint with the wrong continuator delete checkpoint; diff --git a/mo/src/sampling/moMHRndFitnessCloudSampling.h b/mo/src/sampling/moMHRndFitnessCloudSampling.h index 292d42344..2a3cca639 100644 --- a/mo/src/sampling/moMHRndFitnessCloudSampling.h +++ b/mo/src/sampling/moMHRndFitnessCloudSampling.h @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include @@ -87,7 +87,7 @@ public: delete localSearch; // Metropolis-Hasting sampling - localSearch = new moMetropolisHasting(_neighborhood, _fullEval, _eval, _nbStep); + localSearch = new moMetropolisHastings(_neighborhood, _fullEval, _eval, _nbStep); // delete the checkpoint with the wrong continuator delete checkpoint; diff --git a/mo/test/CMakeLists.txt b/mo/test/CMakeLists.txt index 319ffb0c9..898e6e22d 100644 --- a/mo/test/CMakeLists.txt +++ b/mo/test/CMakeLists.txt @@ -38,7 +38,7 @@ set (TEST_LIST t-moNeutralHCexplorer t-moFirstImprHCexplorer t-moRandomWalkExplorer - t-moMetropolisHastingExplorer + t-moMetropolisHastingsExplorer t-moRandomNeutralWalkExplorer t-moTSexplorer t-moSolComparator @@ -52,7 +52,7 @@ set (TEST_LIST t-moMonOpPerturb t-moRestartPerturb t-moNeighborhoodPerturb - t-moSAexplorer + t-moSAExplorer t-moSA t-moLocalSearch t-moILSexplorer @@ -65,7 +65,7 @@ set (TEST_LIST t-moILS t-moDummyLS t-moRandomSearch - t-moMetropolisHasting + t-moMetropolisHastings t-moNeutralHC t-moRandomWalk t-moRandomNeutralWalk diff --git a/mo/test/t-moMetropolisHasting.cpp b/mo/test/t-moMetropolisHasting.cpp deleted file mode 100644 index 638c64bd8..000000000 --- a/mo/test/t-moMetropolisHasting.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - -Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 - -Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau - -This software is governed by the CeCILL license under French law and -abiding by the rules of distribution of free software. You can ue, -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". - -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 -*/ - -#include -#include -#include - -#include -#include "moTestClass.h" -#include -#include -#include -#include - -int main() { - - std::cout << "[t-moMetropolisHasting] => START" << std::endl; - - bitNeighborhood nh(4); - oneMaxEval fullEval; - evalOneMax eval(4); - moTrueContinuator cont; - moSolNeighborComparator sncomp; - moNeighborComparator ncomp; - - //test du 1er constructeur - moMetropolisHasting test1(nh, fullEval, eval, 3); - - //test du 2eme constructeur - moMetropolisHasting test2(nh, fullEval, eval, 3, cont); - - //test du 3eme constructeur - moMetropolisHasting test3(nh, fullEval, eval, 3, cont, ncomp, sncomp); - - std::cout << "[t-moMetropolisHasting] => OK" << std::endl; - - return EXIT_SUCCESS; -} - diff --git a/mo/test/t-moMetropolisHastingExplorer.cpp b/mo/test/t-moMetropolisHastingExplorer.cpp deleted file mode 100644 index 6214465a1..000000000 --- a/mo/test/t-moMetropolisHastingExplorer.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - -Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 - -Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau - -This software is governed by the CeCILL license under French law and -abiding by the rules of distribution of free software. You can ue, -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". - -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 -*/ - -#include -#include "moTestClass.h" - -#include -#include -#include - -int main() { - - std::cout << "[t-moMetropolisHastingExplorer] => START" << std::endl; - - //Instanciation - eoBit sol(4, true); - sol.fitness(4); - bitNeighborhood nh(4); - evalOneMax eval(4); - moNeighborComparator ncomp; - moSolNeighborComparator sncomp; - - moMetropolisHastingExplorer test(nh, eval, ncomp, sncomp, 3); - - //test de l'acceptation d'un voisin améliorant - test.initParam(sol); - test(sol); - assert(test.accept(sol)); - test.move(sol); - assert(sol.fitness()==3); - test.updateParam(sol); - assert(test.isContinue(sol)); - - unsigned int oui=0, non=0; - - //test de l'acceptation d'un voisin non améliorant - for (unsigned int i=0; i<1000; i++) { - test(sol); - if (test.accept(sol)) - oui++; - else - non++; - } - std::cout << "Attention test en fonction d'une proba \"p\" uniforme dans [0,1] , oui si p < 3/4, non sinon -> resultat sur 1000 essai" << std::endl; - std::cout << "oui: " << oui << std::endl; - std::cout << "non: " << non << std::endl; - - assert(oui > 700 && oui < 800); //verification grossiere - - //test du critere d'arret - test.updateParam(sol); - assert(test.isContinue(sol)); - test.updateParam(sol); - assert(!test.isContinue(sol)); - - //test de l'acceptation d'un voisin - sol[0]=false; - sol[1]=false; - sol[2]=false; - sol[3]=false; - sol.fitness(0); - - test.initParam(sol); - test(sol); - assert(!test.accept(sol)); - - std::cout << "[t-moMetropolisHastingExplorer] => OK" << std::endl; - - return EXIT_SUCCESS; -} - diff --git a/mo/test/t-moSAexplorer.cpp b/mo/test/t-moSAexplorer.cpp deleted file mode 100644 index 4c619ff88..000000000 --- a/mo/test/t-moSAexplorer.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - -Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 - -Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau - -This software is governed by the CeCILL license under French law and -abiding by the rules of distribution of free software. You can ue, -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". - -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 -*/ - -#include -#include -#include - -#include "moTestClass.h" -#include -#include - -int main() { - - std::cout << "[t-moSAexplorer] => START" << std::endl; - - eoBit sol(4, true); - sol.fitness(4); - bitNeighborhood nh(4); - bitNeighborhood emptyNH(0); - evalOneMax eval(4); - moSolNeighborComparator sncomp; - moSimpleCoolingSchedule cool(10,0.1,2,0.1); - - moSAexplorer test1(emptyNH, eval, sncomp, cool); - moSAexplorer test2(nh, eval, sncomp, cool); - - //test d'un voisinage vide - test1.initParam(sol); - test1(sol); - assert(!test1.accept(sol)); - assert(test1.getTemperature()==10.0); - - //test d'un voisinage "normal" - test2.initParam(sol); - test2(sol); - assert(test2.accept(sol)); - test2.updateParam(sol); - assert(test2.isContinue(sol)); - test2.move(sol); - assert(sol.fitness()==3); - unsigned int ok=0; - unsigned int ko=0; - for (unsigned int i=0; i<1000; i++) { - test2(sol); - if (test2.isContinue(sol)) - test2.updateParam(sol); - if (test2.accept(sol)) - ok++; - else - ko++; - test2.move(sol); - } - assert((ok>0) && (ko>0)); - - - - std::cout << "[t-moSAexplorer] => OK" << std::endl; - - return EXIT_SUCCESS; -} -