ILS v1 :)

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1727 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-03-29 15:58:25 +00:00
commit 6bb2a4a822
21 changed files with 330 additions and 60 deletions

View file

@ -40,7 +40,7 @@ template< class Neighbor >
class moAlwaysAcceptCrit : public moAcceptanceCriterion<Neighbor>, public moDummyMemory<Neighbor>{
public:
typedef typename Neighor::EOT EOT;
typedef typename Neighbor::EOT EOT;
/**
* Always accept the new solution

View file

@ -0,0 +1,70 @@
/*
<moIterContinuator.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 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 _moIterContinuator_h
#define _moIterContinuator_h
#include <continuator/moContinuator.h>
/**
* Continue until a maximum fixed number of iterations is reached
*/
template< class NH >
class moIterContinuator : public moContinuator<NH>
{
public:
typedef typename NH::EOT EOT ;
/**
* @param _maxIter number maximum of iterations
*/
moIterContinuator(unsigned int _maxIter): maxIter(_maxIter){}
/**
*@param _solution a solution
*@return true if counter < maxIter
*/
virtual bool operator()(EOT & _solution) {
return (cpt++ < maxIter);
}
/**
* reset the counter of iteration
* @param _solution a solution
*/
virtual void init(EOT & _solution) {
cpt=0;
}
private:
unsigned int maxIter;
unsigned int cpt;
};
#endif

View file

@ -35,6 +35,8 @@
#ifndef _moCoolingSchedule_h
#define _moCoolingSchedule_h
#include <eoFunctor.h>
/**
* Cooling Schedule of the temperature in the simulated algorithm
*
@ -47,20 +49,14 @@ public:
* Initial temperature
* @param _solution initial solution
*/
double init(EOT & _solution) = 0;
virtual double init(EOT & _solution) = 0;
/**
* update the temperature
* @param _temp current temperature to update
*/
void update(double& _temp) = 0;
virtual void update(double& _temp) = 0;
/**
* test the ending of the process
* @param _temp current temperature
* @return true if the process could be continue
*/
// bool operator()(double _temp) = 0;
};

View file

@ -43,7 +43,7 @@
*
*/
template< class EOT >
class moSimpleCoolingSchedule : public eoUF<double, bool>
class moSimpleCoolingSchedule : public moCoolingSchedule<EOT>
{
public:
/**
@ -91,18 +91,14 @@ public:
private:
// initial temperature
double initT;
// threshold temperature
double finalT;
// coefficient of decrease
double alpha;
// maximum number of iterations at the same temperature
unisgned span;
unsigned int span;
// threshold temperature
double finalT;
// number of steps with the same temperature
unsigned step;
unsigned int step;
};

View file

@ -0,0 +1,52 @@
/*
<moDummyEval.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 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 _moDummyEval_h
#define _moDummyEval_h
#include <eval/moEval.h>
/**
* Dummy Evaluation function
*/
template<class N>
class moDummyEval : public moEval<N>{
public:
typedef typename N::EOT EOT;
typedef typename EOT::Fitness Fitness;
/**
* NOTHING TO DO
* @param _sol a solution
*/
void operator()(EOT& _sol, N& _n){}
};
#endif

View file

@ -41,20 +41,21 @@
#include <algo/moLocalSearch.h>
#include <perturb/moPerturbation.h>
#include <acceptCrit/moAcceptanceCriterion.h>
#include <neighborhood/moDummyNeighborhood.h>
#include <neighborhood/moDummyNeighbor.h>
/**
* Explorer for an Iterated Local Search
*/
template< class NHE >
class moILSexplorer : public moNeighborhoodExplorer<typename NHE::Neighborhood>
class moILSexplorer : public moNeighborhoodExplorer<moDummyNeighborhood<moDummyNeighbor<typename NHE::Neighborhood::EOT, typename NHE::Neighborhood::EOT::Fitness> > >
{
public:
typedef typename NHE::Neighborhood Neighborhood ;
typedef typename Neighborhood::EOT EOT ;
typedef typename Neighborhood::Neighbor Neighbor ;
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::eval;
typedef moDummyNeighbor<EOT,typename EOT::Fitness> dummyNeighbor;
typedef moDummyNeighborhood<dummyNeighbor> dummyNeighborhood;
/**
* Constructor
@ -62,7 +63,7 @@ public:
* @param _perturb a perturbation operator
* @param _acceptCrit a acceptance criteria
*/
moILSexplorer(moLocalSearch<NHE>& _ls, moPerturbation<Neighbor>& _perturb, moAcceptanceCriterion<Neighbor>& _acceptCrit) : ls(_ls), perturb(_perturb), acceptCrit(_acceptCrit){
moILSexplorer(moLocalSearch<NHE>& _ls, moPerturbation<Neighbor>& _perturb, moAcceptanceCriterion<Neighbor>& _acceptCrit) : moNeighborhoodExplorer<dummyNeighborhood>(), ls(_ls), perturb(_perturb), acceptCrit(_acceptCrit){
firstIteration=true;
}
@ -88,7 +89,7 @@ public:
* @param _solution the current solution
*/
virtual void updateParam(EOT & _solution){
if((*this).isMoved()){
if((*this).moveApplied()){
perturb.add(_solution,emptyNeighbor);
acceptCrit.add(_solution,emptyNeighbor);
}
@ -110,8 +111,10 @@ public:
current=_solution;
//perturb solution exept at the first iteration
if(!firstIteration)
if(!firstIteration){
perturb(current);
}
else
firstIteration=false;

View file

@ -40,6 +40,9 @@
#include <neighborhood/moNeighborhood.h>
#include <eval/moEval.h>
//#include <neighborhood/moDummyNeighbor.h>
#include <neighborhood/moDummyNeighborhood.h>
#include <eval/moDummyEval.h>
/**
* Explore the neighborhood
@ -50,8 +53,11 @@ class moNeighborhoodExplorer : public eoUF<typename NH::EOT&, void>
public:
typedef NH Neighborhood ;
typedef typename Neighborhood::EOT EOT ;
typedef typename EOT::Fitness Fitness ;
typedef typename Neighborhood::Neighbor Neighbor ;
moNeighborhoodExplorer():neighborhood(dummyNeighborhood), eval(dummyEval), isMoved(false) {}
/**
* Constructor with a Neighborhood and evaluation function
* @param _neighborhood the neighborhood
@ -123,6 +129,8 @@ public:
}
protected:
moDummyNeighborhood<Neighbor> dummyNeighborhood;
moDummyEval<Neighbor> dummyEval;
Neighborhood & neighborhood;
moEval<Neighbor>& eval;
bool isMoved;

View file

@ -67,7 +67,7 @@ public:
* @param _solNeighborComparator a solution vs neighbor comparator
* @param _nbStep maximum number of step to do
*/
moSAexplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moSolNeighborComparator<Neighbor>& _solNeighborComparator, moCoolingSchedule<EOT> _coolingSchedule) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), solNeighborComparator(_solNeighborComparator), coolingSchedule(_coolingSchedule) {
moSAexplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moSolNeighborComparator<Neighbor>& _solNeighborComparator, moCoolingSchedule<EOT>& _coolingSchedule) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), solNeighborComparator(_solNeighborComparator), coolingSchedule(_coolingSchedule) {
isAccept = false;
if (!neighborhood.isRandom()) {
@ -168,11 +168,9 @@ private:
// comparator betwenn solution and neighbor
moSolNeighborComparator<Neighbor>& solNeighborComparator;
// current number of step
unsigned int step;
moCoolingSchedule<EOT>& coolingSchedule;
// maximum number of steps to do
unsigned int nbStep;
double temperature;
//Pointer on the best and the current neighbor
Neighbor current;

View file

@ -58,6 +58,7 @@
#include <continuator/moStat.h>
#include <continuator/moStatBase.h>
#include <continuator/moTrueContinuator.h>
#include <continuator/moIterContinuator.h>
#include <eval/moEval.h>
#include <eval/moFullEvalByCopy.h>
@ -103,8 +104,8 @@
#include <acceptCrit/moAcceptanceCriterion.h>
#include <acceptCrit/moAlwaysAcceptCrit.h>
#include <coolingschedule/moCoolingSchedule.h>
#include <coolingschedule/moSimpleCoolingSchedule.h>
#include <coolingSchedule/moCoolingSchedule.h>
#include <coolingSchedule/moSimpleCoolingSchedule.h>
//#include <old/moMove.h>
//#include <old/moMoveIncrEval.h>

View file

@ -0,0 +1,48 @@
/*
<moDummyNeighbor.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 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 _moDummyNeighbor_h
#define _moDummyNeighbor_h
#include <neighborhood/moNeighbor.h>
/**
* Dummy Neighborhood
*/
template< class EOT , class Fitness >
class moDummyNeighbor : public moNeighbor< EOT,Fitness>{
public:
/**
* NOTHING TO DO
* @param _solution the related solution
*/
virtual void move(EOT& _solution){}
};
#endif

View file

@ -0,0 +1,78 @@
/*
<moDummyNeighborhood.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 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 _moDummyNeighborhood_h
#define _moDummyNeighborhood_h
#include <neighborhood/moDummyNeighbor.h>
/**
* Dummy Neighborhood
*/
template< class N >
class moDummyNeighborhood : public moNeighborhood<N>{
public:
typedef N Neighbor;
typedef typename Neighbor::EOT EOT;
/**
* NOTHING TO DO
* @param _solution the related solution
* @return always false
*/
virtual bool hasNeighbor(EOT & _solution){
return false;
}
/**
* NOTHING TO DO
* @param _solution the solution to explore
* @param _current the first neighbor
*/
virtual void init(EOT & _solution, Neighbor & _current){}
/**
* NOTHING TO DO
* @param _solution the solution to explore
* @param _current the next neighbor
*/
virtual void next(EOT & _solution, Neighbor & _current){}
/**
* NOTHING TO DO
* @param _solution the solution to explore
* @return always false
*/
virtual bool cont(EOT & _solution){
return false;
}
};
#endif

View file

@ -30,8 +30,10 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#ifndef _moMonOpPerturb_h
#define _moMonOpPerturb_h
#include <eoEvalFunc.h>
#include <eoOp.h>
#include <perturb/moPerturbation.h>
#include <memory/moDummyMemory.h>
/**
* Perturbation operator using only a eoMonOp
@ -46,7 +48,7 @@ public:
* Default Constructor
* @param _monOp an eoMonOp (pertubation operator)
*/
moMonOpPerturb(eoMonOp<EOT>& _monOp):monOp(_monOp){}
moMonOpPerturb(eoMonOp<EOT>& _monOp, eoEvalFunc<EOT>& _fullEval):monOp(_monOp), fullEval(_fullEval){}
/**
* Apply monOp on the solution
@ -54,12 +56,15 @@ public:
* @return value of monOp
*/
bool operator()(EOT& _solution){
return monOp(_solution);
bool res = monOp(_solution);
fullEval(_solution);
return res;
}
private:
/** monOp */
eoMonOp<EOT>& monOp;
eoEvalFunc<EOT>& fullEval;
};
#endif

View file

@ -63,7 +63,7 @@ typedef moDummyRndNeighborhood bitNeighborhood ;
typedef EO<int> Solution;
class moDummyNeighbor : public moNeighbor<Solution,int> {
class moDummyNeighborTest : public moNeighbor<Solution,int> {
public:
virtual void move(Solution & _solution) {}
};
@ -74,11 +74,11 @@ public:
virtual void moveBack(Solution & _solution) {}
};
class moDummyNeighborhood : public moNeighborhood<moDummyNeighbor> {
class moDummyNeighborhoodTest : public moNeighborhood<moDummyNeighborTest> {
public:
typedef moDummyNeighbor Neighbor;
typedef moDummyNeighborTest Neighbor;
moDummyNeighborhood():i(0),j(0) {}
moDummyNeighborhoodTest():i(0),j(0) {}
virtual bool hasNeighbor(EOT & _solution) {
bool res;
@ -100,7 +100,7 @@ private:
int i,j;
};
class moDummyEval: public eoEvalFunc<Solution> {
class moDummyEvalTest: public eoEvalFunc<Solution> {
public:
void operator()(Solution& _sol) {
if (_sol.invalid())

View file

@ -45,11 +45,11 @@ int main() {
std::cout << "[t-moFullEvalByCopy] => START" << std::endl;
Solution sol;
moDummyNeighbor neighbor;
moDummyEval eval;
moDummyNeighborTest neighbor;
moDummyEvalTest eval;
//verif constructor
moFullEvalByCopy<moDummyNeighbor> test(eval);
moFullEvalByCopy<moDummyNeighborTest> test(eval);
sol.fitness(3);

View file

@ -46,7 +46,7 @@ int main() {
Solution sol;
moDummyBackableNeighbor neighbor;
moDummyEval eval;
moDummyEvalTest eval;
//verif constructor
moFullEvalByModif<moDummyBackableNeighbor> test(eval);

View file

@ -42,7 +42,7 @@ int main() {
std::cout << "[t-moNeighbor] => START" << std::endl;
//test constructor
moDummyNeighbor test1, test2;
moDummyNeighborTest test1, test2;
test1.fitness(3);
//test operateur d'affectation
@ -50,7 +50,7 @@ int main() {
assert(test1.fitness()==test2.fitness());
//test operateur de copy
moDummyNeighbor test3(test1);
moDummyNeighborTest test3(test1);
assert(test1.fitness()==test3.fitness());
test1.printOn(std::cout);

View file

@ -48,15 +48,15 @@ int main() {
std::cout << "[t-moSimpleHCexplorer] => START" << std::endl;
Solution sol;
moDummyNeighbor neighbor;
moDummyEval eval;
moDummyNeighborhood nh;
moFullEvalByCopy<moDummyNeighbor> fulleval(eval);
moNeighborComparator<moDummyNeighbor> comp;
moSolNeighborComparator<moDummyNeighbor> solNeighborComp;
moDummyNeighborTest neighbor;
moDummyEvalTest eval;
moDummyNeighborhoodTest nh;
moFullEvalByCopy<moDummyNeighborTest> fulleval(eval);
moNeighborComparator<moDummyNeighborTest> comp;
moSolNeighborComparator<moDummyNeighborTest> solNeighborComp;
//verif constructor
moSimpleHCexplorer<moDummyNeighborhood> test(nh, fulleval, comp, solNeighborComp);
moSimpleHCexplorer<moDummyNeighborhoodTest> test(nh, fulleval, comp, solNeighborComp);
//verif operator() et accept: le neigorhood est construit pour qu'on tombe dans les 3 cas suivants:
//hasNeighbor() retourne faux a l'entrée de l'operator() donc on doit pas continuer

View file

@ -43,7 +43,7 @@ int main() {
std::cout << "[t-moTrueContinuator] => START" << std::endl;
moTrueContinuator<moDummyNeighborhood> test;
moTrueContinuator<moDummyNeighborhoodTest> test;
Solution s;
assert(test(s));

View file

@ -18,6 +18,7 @@
// the general include for eo
#include <eo>
#include <ga.h>
#include <ga/eoBitOp.h>
using namespace std;
@ -37,11 +38,16 @@ using namespace std;
#include <explorer/moSimpleHCexplorer.h>
#include <explorer/moILSexplorer.h>
#include <perturb/moMonOpPerturb.h>
#include <acceptCrit/moAlwaysAcceptCrit.h>
#include <continuator/moIterContinuator.h>
// REPRESENTATION
//-----------------------------------------------------------------------------
typedef eoBit<unsigned> Indi;
typedef moBitNeighbor<unsigned int> Neighbor ; // incremental evaluation
typedef moOrderNeighborhood<Neighbor> Neighborhood ;
typedef moSimpleHCexplorer<Neighborhood> NHE;
void main_function(int argc, char **argv)
{
@ -161,7 +167,20 @@ void main_function(int argc, char **argv)
moTrueContinuator<Neighborhood> continuator;//always continue
moLocalSearch< moSimpleHCexplorer<Neighborhood> > localSearch(explorer, continuator, eval);
moLocalSearch< NHE > hc(explorer, continuator, eval);
eoBitMutation<Indi> monOp(1.0/vecSize);
moMonOpPerturb<Neighbor> perturb(monOp, eval);
moAlwaysAcceptCrit<Neighbor> accept;
moILSexplorer< NHE > explorerILS(hc, perturb, accept);
moIterContinuator<Neighborhood> continuatorILS(10);
moLocalSearch< moILSexplorer< moSimpleHCexplorer<Neighborhood> > >localSearch(explorerILS, continuatorILS, eval);
/* =========================================================
*

View file

@ -66,10 +66,6 @@ void main_function(int argc, char **argv)
parser.processParam( vecSizeParam, "Representation" );
unsigned vecSize = vecSizeParam.value();
eoValueParam<unsigned int> stepParam(10, "nbStep", "Number of steps of the random walk", 'n');
parser.processParam( stepParam, "Representation" );
unsigned nbStep = stepParam.value();
// the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
@ -154,7 +150,7 @@ void main_function(int argc, char **argv)
* ========================================================= */
// initial temp, factor of decrease, number of steps without decrease, final temp.
moSimpleCoolingSchdedule<Indi> coolingSchedule(10, 0.9, 1, 0.01);
moSimpleCoolingSchedule<Indi> coolingSchedule(10, 0.9, 1, 0.01);
/* =========================================================
*
@ -172,7 +168,7 @@ void main_function(int argc, char **argv)
moTrueContinuator<Neighborhood> continuator;//always continue
moLocalSearch< moMetropolisHastingExplorer<Neighborhood> > localSearch(explorer, continuator, eval);
moLocalSearch< moSAexplorer<Neighborhood> > localSearch(explorer, continuator, eval);
/* =========================================================
*