Continuator et chekpoint ajoutées :)

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1674 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-01-25 15:24:40 +00:00
commit 476a59e1e7
18 changed files with 492 additions and 24 deletions

View file

@ -42,19 +42,19 @@
/**
* the main algorithm of the local search
*/
template< class NHE , class C >
template<class NHE>
class moLocalSearch: public eoMonOp<typename NHE::EOT>
{
public:
typedef NHE NeighborhoodExplorer ;
typedef C Continuator ;
typedef typename NeighborhoodExplorer::EOT EOT ;
typedef typename NeighborhoodExplorer::Neighborhood Neighborhood ;
/**
* Constructor of a moLocalSearch needs a NeighborhooExplorer and a Continuator
*/
moLocalSearch(NeighborhoodExplorer& _searchExpl, Continuator & _continuator, eoEvalFunc<EOT>& _fullEval) : searchExplorer(_searchExpl), continuator(_continuator), fullEval(_fullEval) { } ;
moLocalSearch(NeighborhoodExplorer& _searchExpl, moContinuator<Neighborhood> & _continuator, eoEvalFunc<EOT>& _fullEval) : searchExplorer(_searchExpl), continuator(_continuator), fullEval(_fullEval) { } ;
/**
* Run the local search on a solution
@ -64,15 +64,14 @@ public:
if(_solution.invalid())
fullEval(_solution);
// initialization of the external continuator (for example the time, or the number of generations)
continuator.init(_solution);
// initialization of the parameter of the search (for example fill empty the tabu list)
searchExplorer.initParam(_solution);
//A virer par la suite
unsigned int num = 0;
// initialization of the external continuator (for example the time, or the number of generations)
continuator.init(_solution);
bool b=continuator(_solution);
do{
// explore the neighborhood of the solution
@ -85,14 +84,13 @@ public:
// update the parameter of the search (for ex. Temperature of the SA)
searchExplorer.updateParam(_solution);
//A virer par la suite
std::cout << num << " : " << _solution << std::endl ;
num++;
}while (continuator(_solution) && searchExplorer.isContinue(_solution));
b=continuator(_solution);
}while (b && searchExplorer.isContinue(_solution));
searchExplorer.terminate(_solution);
continuator.lastCall(_solution);
//A CHANGER
return true;
@ -103,7 +101,7 @@ private:
NeighborhoodExplorer& searchExplorer ;
// external continuator
Continuator& continuator ;
moContinuator<Neighborhood>& continuator ;
//full evaluation function
eoEvalFunc<EOT>& fullEval;

View file

@ -0,0 +1,106 @@
/*
<moCheckpoint.h>
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 moCheckpoint_h
#define moCheckpoint_h
#include <continuator/moContinuator.h>
#include <utils/eoMonitor.h>
#include <continuator/moStatBase.h>
template <class NH>
class moCheckpoint : public moContinuator<NH> {
public :
typedef NH Neighborhood ;
typedef typename Neighborhood::EOT EOT ;
moCheckpoint(moContinuator<Neighborhood>& _cont) {
continuators.push_back(&_cont);
}
void add(moContinuator<Neighborhood>& _cont) { continuators.push_back(&_cont); }
void add(moStatBase<EOT>& _stat) { stats.push_back(&_stat); }
void add(eoMonitor& _mon) { monitors.push_back(&_mon); }
void add(eoUpdater& _upd) { updaters.push_back(&_upd); }
virtual void init(EOT& _sol) {
for(unsigned i = 0; i < continuators.size(); ++i)
continuators[i]->init(_sol);
}
virtual std::string className(void) const { return "moCheckPoint"; }
bool operator()(EOT & _sol) {
unsigned i;
bool bContinue = true;
for (i = 0; i < stats.size(); ++i)
(*stats[i])(_sol);
for (i = 0; i < updaters.size(); ++i)
(*updaters[i])();
for (i = 0; i < monitors.size(); ++i)
(*monitors[i])();
for (i = 0; i < continuators.size(); ++i)
if ( !(*continuators[i])(_sol) )
bContinue = false;
return bContinue;
}
void lastCall(EOT& _sol){
unsigned int i;
for (i = 0; i < stats.size(); ++i)
stats[i]->lastCall(_sol);
for (i = 0; i < updaters.size(); ++i)
updaters[i]->lastCall();
for (i = 0; i < monitors.size(); ++i)
monitors[i]->lastCall();
}
private :
std::vector<moContinuator<Neighborhood>*> continuators;
std::vector<moStatBase<EOT>*> stats;
std::vector<eoMonitor*> monitors;
std::vector<eoUpdater*> updaters;
};
#endif

View file

@ -52,6 +52,12 @@ public:
* @param _solution the related solution
*/
virtual void init(EOT& _solution) = 0 ;
/**
* Last Call to terminate the checkpoint
* @param _solution the related solution
*/
virtual void lastCall(EOT& _solution){}
};
#endif

View file

@ -0,0 +1,79 @@
/*
<moCounterMonitorSaver.h>
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 moCounterMonitorSaver_h
#define moCounterMonitorSaver_h
#include <utils/eoUpdater.h>
#include <utils/eoMonitor.h>
/**
* The actual class that will be used as base for all statistics
* that need to be calculated over the solution
* It is a moStatBase AND an eoValueParam so it can be used in Monitors.
*/
class moCounterMonitorSaver : public eoUpdater {
public :
moCounterMonitorSaver(unsigned _interval, eoMonitor& _mon) : interval(_interval), counter(0) {
monitors.push_back(&_mon);
}
void operator()(void) {
if (++counter % interval == 0)
for (unsigned i = 0; i < monitors.size(); ++i)
(*monitors[i])();
}
void lastCall(void) {
for (unsigned i = 0; i < monitors.size(); ++i)
monitors[i]->lastCall();
}
void add(eoMonitor& _mon) {
monitors.push_back(&_mon);
}
virtual std::string className(void) const { return "moCounterMonitorSaver"; }
private :
unsigned interval, counter;
std::vector<eoMonitor*> monitors;
};
#endif

View file

@ -0,0 +1,72 @@
/*
<moFitnessStat.h>
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 moCounterStat_h
#define moCoutnerStat_h
#include <continuator/moStat.h>
/**
* The actual class that will be used as base for all statistics
* that need to be calculated over the solution
* It is a moStatBase AND an eoValueParam so it can be used in Monitors.
*/
template <class EOT, class T>
class moCounterStat : public moStat< EOT, T >
{
public :
moCounterStat(unsigned int _interval, moStat<EOT, T> & _solStat): moStat<EOT, T >(0, "every"), interval(_interval){
solStats.push_back(&_solStat);
}
void add(moStat<EOT, T>& _stat) {
solStats.push_back(&_stat);
}
virtual void operator()(EOT & _sol) {
if (++counter % interval == 0)
for (unsigned i = 0; i < solStats.size(); ++i)
(*solStats[i])(_sol);
}
virtual std::string className(void) const { return "moCounterStat"; }
private:
unsigned int counter, interval;
std::vector<moStat<EOT, T>* > solStats;
};
#endif

View file

@ -0,0 +1,64 @@
/*
<moFitnessStat.h>
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 moFitnessStat_h
#define moFitnessStat_h
#include <continuator/moStat.h>
/**
* The actual class that will be used as base for all statistics
* that need to be calculated over the solution
* It is a moStatBase AND an eoValueParam so it can be used in Monitors.
*/
template <class EOT, class T=typename EOT::Fitness>
class moFitnessStat : public moStat<EOT, T>
{
public :
typedef T Fitness;
using moStat< EOT, Fitness >::value;
moFitnessStat(std::string _description = "fitness")
: moStat<EOT, Fitness>(Fitness(), _description)
{}
virtual void operator()(EOT & _sol)
{
value() = _sol.fitness();
}
virtual std::string className(void) const { return "moFitnessStat"; }
};
#endif

View file

@ -0,0 +1,59 @@
/*
<moStat.h>
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 moStat_h
#define moStat_h
#include <continuator/moStatBase.h>
/**
* The actual class that will be used as base for all statistics
* that need to be calculated over the solution
* It is a moStatBase AND an eoValueParam so it can be used in Monitors.
*/
template <class EOT, class T>
class moStat : public eoValueParam<T>, public moStatBase<EOT>
{
public:
moStat(T _value, std::string _description)
: eoValueParam<T>(_value, _description)
{}
virtual std::string className(void) const
{ return "moStat"; }
};
#endif

View file

@ -0,0 +1,56 @@
/*
<moStatBase.h>
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 moStatBase_h
#define moStatBase_h
#include <eoFunctor.h>
#include <utils/eoParam.h>
/**
* Base class for all statistics that need to be calculated
* over the solution
* (I guess it is not really necessary? MS.
* Depstd::ends, there might be reasons to have a stat that is not an eoValueParam,
* but maybe I'm just kidding myself, MK)
*/
template <class EOT>
class moStatBase : public eoUF<EOT &, void>
{
public:
virtual void lastCall(EOT &) {}
virtual std::string className(void) const { return "moStatBase"; }
};
#endif

View file

@ -36,7 +36,7 @@
#define _moRndWithReplNeighborhood_h
#include <neighborhood/moIndexNeighborhood.h>
#include <utils/eoRng.h>
#include <utils/eoRNG.h>
/**
* A Random With replacement Neighborhood

View file

@ -36,7 +36,7 @@
#define _moRndWithoutReplNeighborhood_h
#include <neighborhood/moIndexNeighborhood.h>
#include <utils/eoRng.h>
#include <utils/eoRNG.h>
/**
* A Random without replacement Neighborhood

View file

@ -43,6 +43,12 @@
#include <continuator/moContinuator.h>
#include <continuator/moTrueContinuator.h>
#include <continuator/moCheckpoint.h>
#include <continuator/moCounterMonitorSaver.h>
#include <continuator/moConnterStat.h>
#include <continuator/moFitnessStat.h>
#include <continuator/moStat.h>
#include <continuator/moStatBase.h>
#include <eval/moEval.h>
#include <eval/moFullEvalByCopy.h>
@ -50,6 +56,12 @@
#include <explorer/moNeighborhoodExplorer.h>
#include <explorer/moSimpleHCexplorer.h>
#include <explorer/moFirstImprExplorer.h>
#include <explorer/moHCneutralExplorer.h>
#include <explorer/moSimpleHCneutralExplorer.h>
#include <explorer/moMetropolisHastingExplorer.h>
#include <explorer/moRandomWalkExplorer.h>
#include <neighborhood/moBackableNeighbor.h>
#include <neighborhood/moBitNeighbor.h>

View file

@ -160,7 +160,7 @@ void main_function(int argc, char **argv)
moTrueContinuator<Neighborhood> continuator;//always continue
moLocalSearch< moFirstImprExplorer<Neighborhood>, moTrueContinuator<Neighborhood> > localSearch(explorer, continuator, eval);
moLocalSearch< moFirstImprExplorer<Neighborhood> > localSearch(explorer, continuator, eval);
/* =========================================================
*

View file

@ -164,7 +164,7 @@ void main_function(int argc, char **argv)
moTrueContinuator<Neighborhood> continuator;//always continue
moLocalSearch< moHCneutralExplorer<Neighborhood>, moTrueContinuator<Neighborhood> > localSearch(explorer, continuator, eval);
moLocalSearch< moHCneutralExplorer<Neighborhood> > localSearch(explorer, continuator, eval);
/* =========================================================
*

View file

@ -164,7 +164,7 @@ void main_function(int argc, char **argv)
moTrueContinuator<Neighborhood> continuator;//always continue
moLocalSearch< moMetropolisHastingExplorer<Neighborhood>, moTrueContinuator<Neighborhood> > localSearch(explorer, continuator, eval);
moLocalSearch< moMetropolisHastingExplorer<Neighborhood> > localSearch(explorer, continuator, eval);
/* =========================================================
*

View file

@ -33,6 +33,12 @@ using namespace std;
#include <continuator/moTrueContinuator.h>
#include <algo/moLocalSearch.h>
#include <explorer/moRandomWalkExplorer.h>
#include <continuator/moCheckpoint.h>
#include <continuator/moFitnessStat.h>
#include <utils/eoFileMonitor.h>
#include <utils/eoUpdater.h>
// REPRESENTATION
//-----------------------------------------------------------------------------
@ -151,8 +157,18 @@ void main_function(int argc, char **argv)
* ========================================================= */
moTrueContinuator<Neighborhood> continuator;//always continue
moFitnessStat<Indi, unsigned> fStat;
moCheckpoint<Neighborhood> checkpoint(continuator);
eoFileMonitor outputfile("out.dat", " ");
checkpoint.add(outputfile);
checkpoint.add(fStat);
eoValueParam<unsigned int> genCounter(-1,"Gen");
eoIncrementor<unsigned int> increm(genCounter.value());
checkpoint.add(increm);
outputfile.add(genCounter);
outputfile.add(fStat);
moLocalSearch< moRandomWalkExplorer<Neighborhood>, moTrueContinuator<Neighborhood> > localSearch(explorer, continuator, eval);
moLocalSearch< moRandomWalkExplorer<Neighborhood> > localSearch(explorer, checkpoint, eval);
/* =========================================================
*

View file

@ -160,7 +160,7 @@ void main_function(int argc, char **argv)
moTrueContinuator<Neighborhood> continuator;//always continue
moLocalSearch< moSimpleHCexplorer<Neighborhood>, moTrueContinuator<Neighborhood> > localSearch(explorer, continuator, eval);
moLocalSearch< moSimpleHCexplorer<Neighborhood> > localSearch(explorer, continuator, eval);
/* =========================================================
*

View file

@ -160,7 +160,7 @@ void main_function(int argc, char **argv)
moTrueContinuator<Neighborhood> continuator;//always continue
moLocalSearch< moSimpleHCneutralExplorer<Neighborhood>, moTrueContinuator<Neighborhood> > localSearch(explorer, continuator, eval);
moLocalSearch< moSimpleHCneutralExplorer<Neighborhood> > localSearch(explorer, continuator, eval);
/* =========================================================
*

View file

@ -174,7 +174,7 @@ void main_function(int argc, char **argv)
moTrueContinuator<Neighborhood> continuator;
moLocalSearch< moSimpleHCexplorer<Neighborhood>, moTrueContinuator<Neighborhood> > localSearch(explorer, continuator);
moLocalSearch< moSimpleHCexplorer<Neighborhood> > localSearch(explorer, continuator);
/* =========================================================
*