Migration from SVN

This commit is contained in:
quemy 2012-08-30 11:30:11 +02:00
commit 8cd56f37db
29069 changed files with 0 additions and 4096888 deletions

View file

@ -0,0 +1,111 @@
/*
<moDummyExplorer.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 _moDummyExplorer_h
#define _moDummyExplorer_h
#include <explorer/moNeighborhoodExplorer.h>
/**
* Dummy Explorer the neighborhood: nothing is explored
*/
template< class Neighbor >
class moDummyExplorer : public moNeighborhoodExplorer<Neighbor>
{
public:
typedef moNeighborhood<Neighbor> Neighborhood;
typedef typename Neighbor::EOT EOT;
typedef typename EOT::Fitness Fitness ;
moDummyExplorer(): moNeighborhoodExplorer<Neighbor>() { }
/**
* NOTHING TO DO
* @param _solution unused solution
*/
void initParam (EOT& _solution) { } ;
/**
* NOTHING TO DO
* @param _solution unused solution
*/
void updateParam (EOT& _solution) { } ;
/**
* NOTHING TO DO
* @param _solution unused solution
* @return always false
*/
bool isContinue(EOT& _solution) {
return false;
} ;
/**
* NOTHING TO DO
* @param _solution unused solution
*/
void move(EOT& _solution) { } ;
/**
* NOTHING TO DO
* @param _solution unused solution
* @return always false
*/
virtual bool accept(EOT& _solution) {
return false;
} ;
/**
* NOTHING TO DO
* @param _solution unused solution
*/
virtual void terminate(EOT& _solution) { } ;
/**
* NOTHING TO DO
* @param _solution unused solution
*/
void operator()(EOT & _solution) { }
/**
* Return the class name
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moDummyExplorer";
}
};
#endif

View file

@ -0,0 +1,171 @@
/*
<moFirstImprHCexplorer.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 _moFirstImprHCexplorer_h
#define _moFirstImprHCexplorer_h
#include <explorer/moNeighborhoodExplorer.h>
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
#include <neighborhood/moNeighborhood.h>
/**
* Explorer for a first improvement heuristic
*/
template< class Neighbor>
class moFirstImprHCexplorer : public moNeighborhoodExplorer<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
typedef moNeighborhood<Neighbor> Neighborhood ;
using moNeighborhoodExplorer<Neighbor>::neighborhood;
using moNeighborhoodExplorer<Neighbor>::eval;
using moNeighborhoodExplorer<Neighbor>::currentNeighbor;
using moNeighborhoodExplorer<Neighbor>::selectedNeighbor;
/**
* Constructor
* @param _neighborhood the neighborhood
* @param _eval the evaluation function
* @param _neighborComparator a neighbor comparator
* @param _solNeighborComparator a solution vs neighbor comparator
*/
moFirstImprHCexplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator) : moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) {
isAccept = false;
stop = true;
}
/**
* Destructor
*/
~moFirstImprHCexplorer() {
}
/**
* to never stop the hill climbing
*
*/
virtual void alwaysContinue() {
stop = false;
}
/**
* initParam: NOTHING TO DO
* @param _solution unused solution
*/
virtual void initParam(EOT & _solution) {};
/**
* updateParam: NOTHING TO DO
* @param _solution unused solution
*/
virtual void updateParam(EOT & _solution) {};
/**
* terminate: NOTHING TO DO
* @param _solution unused solution
*/
virtual void terminate(EOT & _solution) {};
/**
* Explore the neighborhood of a solution until an ameliorated neighbor is found
* @param _solution
*/
virtual void operator()(EOT & _solution) {
//Test if _solution has a Neighbor
if (neighborhood.hasNeighbor(_solution)) {
//init the first neighbor
neighborhood.init(_solution, currentNeighbor);
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, currentNeighbor);
//test all others neighbors
while (! solNeighborComparator(_solution, currentNeighbor) && neighborhood.cont(_solution)) {
//next neighbor
neighborhood.next(_solution, currentNeighbor);
//eval
eval(_solution, currentNeighbor);
}
// the selected neighbor
selectedNeighbor = currentNeighbor;
}
else {
//if _solution hasn't neighbor,
isAccept=false;
}
};
/**
* continue if a move is accepted, or according to the flag 'stop'
* @param _solution the solution
* @return true if an ameliorated neighbor was found
*/
virtual bool isContinue(EOT & _solution) {
if (stop)
return isAccept ;
else
return true;
};
/**
* 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) {
if (neighborhood.hasNeighbor(_solution)) {
isAccept = solNeighborComparator(_solution, selectedNeighbor) ;
}
return isAccept;
};
private:
// comparator betwenn solution and neighbor or between neighbors
moNeighborComparator<Neighbor>& neighborComparator;
moSolNeighborComparator<Neighbor>& solNeighborComparator;
// true if the move is accepted
bool isAccept ;
// if true the HC stop when to improving solution is found
// if false : never stop, always continue (external continuator)
bool stop ;
};
#endif

View file

@ -0,0 +1,179 @@
/*
<moILSexplorer.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 _moILSexplorer_h
#define _moILSexplorer_h
#include <explorer/moNeighborhoodExplorer.h>
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
#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 Neighbor >
//class moILSexplorer : public moNeighborhoodExplorer< moDummyNeighbor<typename Neighbor::EOT> >
template< class Neighbor, class NeighborLO >
class moILSexplorer : public moNeighborhoodExplorer< NeighborLO >
{
public:
typedef moNeighborhood<Neighbor> Neighborhood ;
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<NeighborLO> NeighborhoodLO;
//typedef moDummyNeighbor<EOT> dummyNeighbor;
//typedef moDummyNeighborhood<dummyNeighbor> dummyNeighborhood;
/**
* Constructor
* @param _ls a local search
* @param _perturb a perturbation operator
* @param _acceptCrit a acceptance criteria
*/
moILSexplorer(moLocalSearch<Neighbor>& _ls, moPerturbation<Neighbor>& _perturb, moAcceptanceCriterion<Neighbor>& _acceptCrit) : moNeighborhoodExplorer<NeighborLO>(), ls(_ls), perturb(_perturb), acceptCrit(_acceptCrit) {
firstIteration=true;
}
/**
* Destructor
*/
~moILSexplorer() {
}
/**
* Init perturbation and acceptance criteria
* @param _solution the current solution
*/
virtual void initParam(EOT & _solution) {
firstIteration=true;
perturb.init(_solution);
acceptCrit.init(_solution);
};
/**
* Update perturbation and acceptance criteria
* @param _solution the current solution
*/
virtual void updateParam(EOT & _solution) {
if ((*this).moveApplied()) {
perturb.add(_solution,emptyNeighbor);
acceptCrit.add(_solution,emptyNeighbor);
}
perturb.update(_solution, emptyNeighbor);
acceptCrit.update(_solution, emptyNeighbor);
};
/**
* terminate: NOTHING TO DO
* @param _solution a solution (unused)
*/
virtual void terminate(EOT & _solution) {};
/**
* Perturb and apply local search on a solution
* @param _solution the solution
*/
virtual void operator()(EOT & _solution) {
//copy the solution to perform new local search
currentSol=_solution;
//perturb solution exept at the first iteration
if (!firstIteration) {
perturb(currentSol);
}
else
firstIteration=false;
//apply the local search on the copy
ls(currentSol);
// std::cout << "(solution)\t" << current << std::endl;
};
/**
* Always continue
* @param _solution the solution
* @return always true
*/
virtual bool isContinue(EOT & _solution) {
return true;
};
/**
* copy the solution found by the local search
* @param _solution the solution
*/
virtual void move(EOT & _solution) {
_solution=currentSol;
};
/**
* accept test if an ameliorated neighbor was found
* @param _solution the solution
* @return true if acceptance criteria is verified
*/
virtual bool accept(EOT & _solution) {
return acceptCrit(_solution, currentSol);
};
/**
* Return the class Name
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moILSexplorer";
}
private:
//Usefull to use the momory of tabuSearch
Neighbor emptyNeighbor;
EOT currentSol;
moLocalSearch<Neighbor>& ls;
moPerturbation<Neighbor> & perturb;
moAcceptanceCriterion<Neighbor>& acceptCrit;
bool firstIteration;
};
#endif

View file

@ -0,0 +1,180 @@
/*
<moMetropolisHastingExplorer.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 _moMetropolisHastingExplorer_h
#define _moMetropolisHastingExplorer_h
#include <cstdlib>
#include <explorer/moNeighborhoodExplorer.h>
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
#include <neighborhood/moNeighborhood.h>
#include <utils/eoRNG.h>
/**
* 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<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
typedef moNeighborhood<Neighbor> Neighborhood ;
using moNeighborhoodExplorer<Neighbor>::neighborhood;
using moNeighborhoodExplorer<Neighbor>::eval;
using moNeighborhoodExplorer<Neighbor>::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<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator, unsigned int _nbStep) : moNeighborhoodExplorer<Neighbor>(_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<Neighbor>& neighborComparator;
moSolNeighborComparator<Neighbor>& 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

View file

@ -0,0 +1,178 @@
/*
<moNeighborhoodExplorer.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 _neighborhoodExplorer_h
#define _neighborhoodExplorer_h
//EO inclusion
#include <eoFunctor.h>
#include <neighborhood/moNeighborhood.h>
#include <eval/moEval.h>
#include <neighborhood/moDummyNeighborhood.h>
#include <eval/moDummyEval.h>
/**
* Explore the neighborhood according to the local search algorithm
*
* During this exploration,
* the parameters are updated
* one neighbor is selected
* a comparason with the solution is made to acccept or not this new neighbor
*
* The current neighbor (currentNeigbor) is the neighbor under consideration during the search (in operator()(EOT &))
*
* The selected neighbor (selectedNeighbor) is the neighbor selected in method operator()(EOT &).
* If this neighbor is accepted, then the solution is moved on this neighbor (in move(EOT &))
*
*/
template< class Neighbor >
class moNeighborhoodExplorer : public eoUF<typename Neighbor::EOT&, void>
{
public:
typedef moNeighborhood<Neighbor> Neighborhood;
typedef typename Neighbor::EOT EOT;
typedef typename EOT::Fitness Fitness ;
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<Neighbor>& _eval):neighborhood(_neighborhood), eval(_eval), isMoved(false) {}
/**
* Init Search parameters
* @param _solution the solution to explore
*/
virtual void initParam (EOT& _solution) = 0 ;
/**
* Update Search parameters
* @param _solution the solution to explore
*/
virtual void updateParam (EOT& _solution) = 0 ;
/**
* Test if the exploration continue or not
* @param _solution the solution to explore
* @return true if the exploration continue, else return false
*/
virtual bool isContinue(EOT& _solution) = 0 ;
/**
* Move a solution on the selected neighbor
* This method can be re-defined according to the metaheuritic
*
* @param _solution the solution to explore
*/
virtual void move(EOT& _solution) {
// move the solution
selectedNeighbor.move(_solution);
// update the fitness
_solution.fitness(selectedNeighbor.fitness());
}
/**
* Test if a solution is accepted
* @param _solution the solution to explore
* @return true if the solution is accepted, else return false
*/
virtual bool accept(EOT& _solution) = 0 ;
/**
* Terminate the search
* @param _solution the solution to explore
*/
virtual void terminate(EOT& _solution) = 0 ;
/**
* Getter of "isMoved"
* @return true if move is applied
*/
bool moveApplied() {
return isMoved;
}
/**
* Setter of "isMoved"
* @param _isMoved
*/
void moveApplied(bool _isMoved) {
isMoved=_isMoved;
}
/**
* Getter of the current neighbor
* @return current neighbor
*/
Neighbor & getCurrentNeighbor() {
return currentNeighbor;
}
/**
* Getter of the selected neighbor
* @return selected neighbor
*/
Neighbor & getSelectedNeighbor() {
return selectedNeighbor;
}
protected:
// default class for the empty constructor
moDummyNeighborhood<Neighbor> dummyNeighborhood;
// default class for the empty constructor
moDummyEval<Neighbor> dummyEval;
// the neighborhood which is explored
Neighborhood & neighborhood;
// evaluation of a neighbor
moEval<Neighbor>& eval;
// flag : true a the neighbor is accepted and the movement is made
bool isMoved;
// the current neighbor of the exploration : common features of algorithm
Neighbor currentNeighbor;
// the selected neighbor after the exploration of the neighborhood
Neighbor selectedNeighbor;
};
#endif

View file

@ -0,0 +1,133 @@
/*
<moNeutralHCexplorer.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 _moNeutralHCexplorer_h
#define _moNeutralHCexplorer_h
#include <explorer/moRandomBestHCexplorer.h>
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
#include <neighborhood/moNeighborhood.h>
/**
* Explorer for a neutral Hill-climbing
*/
template< class Neighbor >
class moNeutralHCexplorer : public moRandomBestHCexplorer<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
typedef moNeighborhood<Neighbor> Neighborhood ;
using moNeighborhoodExplorer<Neighbor>::neighborhood;
using moRandomBestHCexplorer<Neighbor>::solNeighborComparator;
using moRandomBestHCexplorer<Neighbor>::isAccept;
using moRandomBestHCexplorer<Neighbor>::bestVector;
using moRandomBestHCexplorer<Neighbor>::initParam;
using moRandomBestHCexplorer<Neighbor>::updateParam;
/**
* 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 step to do
*/
moNeutralHCexplorer(Neighborhood& _neighborhood,
moEval<Neighbor>& _eval,
moNeighborComparator<Neighbor>& _neighborComparator,
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
unsigned _nbStep) :
moRandomBestHCexplorer<Neighbor>(_neighborhood, _eval, _neighborComparator, _solNeighborComparator),nbStep(_nbStep) {
//Some cycle is possible with equals fitness solutions if the neighborhood is not random
}
/**
* Destructor
*/
~moNeutralHCexplorer() {
}
/**
* initial number of step
* @param _solution the current solution
*/
virtual void initParam(EOT & _solution) {
moRandomBestHCexplorer<Neighbor>::initParam(_solution);
step = 0;
};
/**
* one more step
* @param _solution the current solution
*/
virtual void updateParam(EOT & _solution) {
moRandomBestHCexplorer<Neighbor>::updateParam(_solution);
step++;
};
/**
* continue if there is a neighbor and it is remains some steps to do
* @param _solution the solution
* @return true there is some steps to do
*/
virtual bool isContinue(EOT & _solution) {
return (step < nbStep) && isAccept ;
};
/**
* accept test if an ameliorated or an equal neighbor was be found
* @param _solution the solution
* @return true if the best neighbor ameliorate the fitness or is equals
*/
virtual bool accept(EOT & _solution) {
if (neighborhood.hasNeighbor(_solution))
isAccept = solNeighborComparator(_solution, bestVector[0]) || solNeighborComparator.equals(_solution, bestVector[0]) ;
return isAccept;
};
private:
// current number of step
unsigned int step;
// maximum number of steps to do
unsigned int nbStep;
};
#endif

View file

@ -0,0 +1,204 @@
/*
<moRandomBestHCexplorer.h>
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 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 _moRandomBestHCexplorer_h
#define _moRandomBestHCexplorer_h
#include <explorer/moNeighborhoodExplorer.h>
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
#include <neighborhood/moNeighborhood.h>
#include <vector>
#include <utils/eoRNG.h>
/**
* Explorer for Hill-Climbing
* which choose randomly one of the best solution in the neighborhood at each iteration
*/
template< class Neighbor >
class moRandomBestHCexplorer : public moNeighborhoodExplorer<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
typedef moNeighborhood<Neighbor> Neighborhood ;
using moNeighborhoodExplorer<Neighbor>::neighborhood;
using moNeighborhoodExplorer<Neighbor>::eval;
using moNeighborhoodExplorer<Neighbor>::currentNeighbor;
using moNeighborhoodExplorer<Neighbor>::selectedNeighbor;
/**
* Constructor
* @param _neighborhood the neighborhood
* @param _eval the evaluation function
* @param _neighborComparator a neighbor comparator
* @param _solNeighborComparator solution vs neighbor comparator
*/
moRandomBestHCexplorer(Neighborhood& _neighborhood,
moEval<Neighbor>& _eval,
moNeighborComparator<Neighbor>& _neighborComparator,
moSolNeighborComparator<Neighbor>& _solNeighborComparator) :
moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval),
neighborComparator(_neighborComparator),
solNeighborComparator(_solNeighborComparator) {
isAccept = false;
}
/**
* Destructor
*/
~moRandomBestHCexplorer() {
}
/**
* empty the vector of best solutions
* @param _solution unused solution
*/
virtual void initParam(EOT & _solution) {
// delete all the best solutions
bestVector.clear();
};
/**
* empty the vector of best solutions
* @param _solution unused solution
*/
virtual void updateParam(EOT & _solution) {
// delete all the best solutions
bestVector.clear();
};
/**
* terminate: NOTHING TO DO
* @param _solution unused solution
*/
virtual void terminate(EOT & _solution) {};
/**
* Explore the neighborhood of a solution
* @param _solution the current solution
*/
virtual void operator()(EOT & _solution) {
//Test if _solution has a Neighbor
if (neighborhood.hasNeighbor(_solution)) {
//init the first neighbor
neighborhood.init(_solution, currentNeighbor);
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, currentNeighbor);
//initialize the best neighbor
bestVector.push_back(currentNeighbor);
//test all others neighbors
while (neighborhood.cont(_solution)) {
//next neighbor
neighborhood.next(_solution, currentNeighbor);
//eval
eval(_solution, currentNeighbor);
//if we found a better neighbor, update the best
if (neighborComparator(bestVector[0], currentNeighbor)) {
bestVector.clear();
bestVector.push_back(currentNeighbor);
}
else if (neighborComparator.equals(currentNeighbor, bestVector[0])) //if the current is equals to previous best solutions then update vector of the best solution
bestVector.push_back(currentNeighbor);
}
// choose randomly one of the best solutions
unsigned int i = rng.random(bestVector.size());
// the selected Neighbor
selectedNeighbor = bestVector[i];
}
else {
//if _solution hasn't neighbor,
isAccept=false;
}
};
/**
* continue if a move is accepted
* @param _solution the solution
* @return true if an ameliorated neighbor was be found
*/
virtual bool isContinue(EOT & _solution) {
return isAccept ;
};
/**
* move the solution with the best neighbor
* @param _solution the solution to move
*/
/*
virtual void move(EOT & _solution) {
// choose randomly one of the best solutions
unsigned int i = rng.random(bestVector.size());
//move the solution
bestVector[i].move(_solution);
//update its fitness
_solution.fitness(bestVector[i].fitness());
};
*/
/**
* accept test if an amelirated neighbor was found
* @param _solution the solution
* @return true if the best neighbor ameliorate the fitness
*/
virtual bool accept(EOT & _solution) {
if (neighborhood.hasNeighbor(_solution))
isAccept = solNeighborComparator(_solution, selectedNeighbor) ;
return isAccept;
};
protected:
// comparator betwenn solution and neighbor or between neighbors
moNeighborComparator<Neighbor>& neighborComparator;
moSolNeighborComparator<Neighbor>& solNeighborComparator;
// the best solutions in the neighborhood
std::vector<Neighbor> bestVector;
// true if the move is accepted
bool isAccept ;
};
#endif

View file

@ -0,0 +1,175 @@
/*
<moRandomNeutralWalkExplorer.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 _moRandomNeutralWalkexplorer_h
#define _moRandomNeutralWalkexplorer_h
#include <explorer/moNeighborhoodExplorer.h>
#include <comparator/moSolNeighborComparator.h>
#include <neighborhood/moNeighborhood.h>
/**
* Explorer for a random neutral walk
* accept the movement when the neighbor has the same fitnes
* To sample the neutral networks by random walk, there is no memory
* neighborhood must be explored in random order
*/
template< class Neighbor >
class moRandomNeutralWalkExplorer : public moNeighborhoodExplorer<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood;
using moNeighborhoodExplorer<Neighbor>::neighborhood;
using moNeighborhoodExplorer<Neighbor>::eval;
using moNeighborhoodExplorer<Neighbor>::currentNeighbor;
using moNeighborhoodExplorer<Neighbor>::selectedNeighbor;
/**
* Constructor
* @param _neighborhood the neighborhood
* @param _eval the evaluation function
* @param _solNeighborComparator a solution vs neighbor comparator
* @param _nbStep maximum number of step to do
*/
moRandomNeutralWalkExplorer(Neighborhood& _neighborhood,
moEval<Neighbor>& _eval,
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
unsigned _nbStep):
moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval),
solNeighborComparator(_solNeighborComparator),
nbStep(_nbStep) {
isAccept = false;
if (!neighborhood.isRandom()) {
std::cout << "moRandomNeutralWalkExplorer::Warning -> the neighborhood used is not random" << std::endl;
}
}
/**
* Destructor
*/
~moRandomNeutralWalkExplorer() {
}
/**
* 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, currentNeighbor);
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, currentNeighbor);
//test all others neighbors
while (! solNeighborComparator.equals(_solution, currentNeighbor) && neighborhood.cont(_solution)) {
//next neighbor
neighborhood.next(_solution, currentNeighbor);
//eval
eval(_solution, currentNeighbor);
}
// the selected neighbor
selectedNeighbor = currentNeighbor;
}
else {
//if _solution hasn't neighbor,
isAccept=false;
}
};
/**
* continue if there is a neighbor and it is remains some steps to do
* @param _solution the solution
* @return true there is some steps to do
*/
virtual bool isContinue(EOT & _solution) {
return (step < nbStep) && isAccept ;
};
/**
* accept test if an equals neighbor was be found
* @param _solution the solution
* @return true if the best neighbor ameliorate the fitness
*/
virtual bool accept(EOT & _solution) {
if (neighborhood.hasNeighbor(_solution))
isAccept = solNeighborComparator.equals(_solution, selectedNeighbor) ;
return isAccept;
};
private:
// comparator betwenn solution and neighbor or between neighbors
moSolNeighborComparator<Neighbor>& 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

View file

@ -0,0 +1,150 @@
/*
<moRandomSearchExplorer.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 _moRandomSearchexplorer_h
#define _moRandomSearchexplorer_h
#include <explorer/moNeighborhoodExplorer.h>
#include <neighborhood/moNeighborhood.h>
#include <eoEvalFunc.h>
#include <eoInit.h>
/**
* Explorer for a pure random search:
* the solution is initialized at each step
*/
template< class Neighbor >
class moRandomSearchExplorer : public moNeighborhoodExplorer<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
typedef moNeighborhood<Neighbor> Neighborhood ;
using moNeighborhoodExplorer<Neighbor>::neighborhood;
using moNeighborhoodExplorer<Neighbor>::eval;
/**
* Constructor
* @param _init the solution initializer, to explore at random the search space
* @param _fulleval the evaluation function
* @param _nbStep maximum number of step to do
*/
moRandomSearchExplorer(eoInit<EOT>& _init, eoEvalFunc<EOT>& _fulleval, unsigned _nbStep) : moNeighborhoodExplorer<Neighbor>(), init(_init), fulleval(_fulleval), nbStep(_nbStep) {
// number of step done
step = 0;
}
/**
* Destructor
*/
~moRandomSearchExplorer() {}
/**
* initialization of the number of step to be done
* @param _solution unused solution
*/
virtual void initParam(EOT & _solution) {
step = 0;
};
/**
* 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 with only one random solution
* we supposed that the first neighbor is uniformly selected in the neighborhood
* @param _solution
*/
virtual void operator()(EOT & _solution) {
//init the first neighbor
init(_solution);
//eval the _solution moved with the neighbor and stock the result in the neighbor
if (_solution.invalid())
fulleval(_solution);
};
/**
* continue if it is remains some steps to do
* @param _solution the solution
* @return true there is some steps to do
*/
virtual bool isContinue(EOT & _solution) {
return (step < nbStep) ;
};
/**
* move the solution with the best neighbor
* @param _solution the solution to move
*/
virtual void move(EOT & _solution) {
// the solution is already move. So nothing to do !
};
/**
* accept test : always accept
* @param _solution the solution
* @return true if the best neighbor ameliorate the fitness
*/
virtual bool accept(EOT & _solution) {
return true;
};
private:
// initialization method to explore at random the search space
eoInit<EOT> & init;
// the full eval function
eoEvalFunc<EOT> & fulleval;
// current number of step
unsigned int step;
// maximum number of steps to do
unsigned int nbStep;
};
#endif

View file

@ -0,0 +1,151 @@
/*
<moRandomWalkExplorer.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 _moRandomWalkexplorer_h
#define _moRandomWalkexplorer_h
#include <explorer/moNeighborhoodExplorer.h>
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
#include <neighborhood/moNeighborhood.h>
/**
* Explorer for a random walk
*
* Choose at each step a random neighbor's solution
* So the neighborhood have to be "random"
*
* The number of steps of the walk is not limited in the explorer
*/
template< class Neighbor >
class moRandomWalkExplorer : public moNeighborhoodExplorer<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
typedef moNeighborhood<Neighbor> Neighborhood ;
using moNeighborhoodExplorer<Neighbor>::neighborhood;
using moNeighborhoodExplorer<Neighbor>::eval;
using moNeighborhoodExplorer<Neighbor>::currentNeighbor;
using moNeighborhoodExplorer<Neighbor>::selectedNeighbor;
/**
* Constructor
* @param _neighborhood the neighborhood (which have to be random)
* @param _eval the evaluation function
*/
moRandomWalkExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval) : moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval) {
isAccept = false;
if (!neighborhood.isRandom()) {
std::cout << "moRandomWalkExplorer::Warning -> the neighborhood used is not random" << std::endl;
}
}
/**
* Destructor
*/
~moRandomWalkExplorer() {
}
/**
* initialization of the number of step to be done
* @param _solution unused solution
*/
virtual void initParam(EOT & _solution) {
isAccept = true;
};
/**
* increase the number of step
* @param _solution unused solution
*/
virtual void updateParam(EOT & _solution) {
};
/**
* terminate: NOTHING TO DO
* @param _solution unused solution
*/
virtual void terminate(EOT & _solution) {};
/**
* Explore the neighborhood with only one random solution
* we supposed that the first neighbor is uniformly selected in the neighborhood
* @param _solution a 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);
isAccept = true;
}
else {
//if _solution hasn't neighbor,
isAccept=false;
}
};
/**
* continue if there is a neighbor and it is remains some steps to do
* @param _solution the solution
* @return true there is some steps to do
*/
virtual bool isContinue(EOT & _solution) {
return isAccept ;
};
/**
* accept test if an amelirated neighbor was be found
* @param _solution the solution
* @return true if the best neighbor ameliorate the fitness
*/
virtual bool accept(EOT & _solution) {
if (neighborhood.hasNeighbor(_solution))
isAccept = true ;
return isAccept;
};
private:
// true if the move is accepted
bool isAccept ;
};
#endif

View file

@ -0,0 +1,182 @@
/*
<moSAexplorer.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 _moSAexplorer_h
#define _moSAexplorer_h
#include <cstdlib>
#include <explorer/moNeighborhoodExplorer.h>
#include <comparator/moSolNeighborComparator.h>
#include <coolingSchedule/moCoolingSchedule.h>
#include <neighborhood/moNeighborhood.h>
#include <utils/eoRNG.h>
/**
* Explorer for the Simulated Annealing
* Only the symetric case is considered when Q(x,y) = Q(y,x)
* Fitness must be > 0
*
*/
template< class Neighbor >
class moSAexplorer : public moNeighborhoodExplorer<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
typedef moNeighborhood<Neighbor> Neighborhood ;
using moNeighborhoodExplorer<Neighbor>::neighborhood;
using moNeighborhoodExplorer<Neighbor>::eval;
using moNeighborhoodExplorer<Neighbor>::selectedNeighbor;
/**
* Constructor
* @param _neighborhood the neighborhood
* @param _eval the evaluation function
* @param _solNeighborComparator a solution vs neighbor comparator
* @param _coolingSchedule the cooling schedule
*/
moSAexplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moSolNeighborComparator<Neighbor>& _solNeighborComparator, moCoolingSchedule<EOT>& _coolingSchedule) : moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval), solNeighborComparator(_solNeighborComparator), coolingSchedule(_coolingSchedule) {
isAccept = false;
if (!neighborhood.isRandom()) {
std::cout << "moSAexplorer::Warning -> the neighborhood used is not random" << std::endl;
}
}
/**
* Destructor
*/
~moSAexplorer() {
}
/**
* initialization of the initial temperature
* @param _solution the solution
*/
virtual void initParam(EOT & _solution) {
temperature = coolingSchedule.init(_solution);
isAccept = false;
};
/**
* decrease the temperature if necessary
* @param _solution unused solution
*/
virtual void updateParam(EOT & _solution) {
coolingSchedule.update(temperature, this->moveApplied());
};
/**
* terminate: NOTHING TO DO
* @param _solution unused solution
*/
virtual void terminate(EOT & _solution) {};
/**
* Explore one random solution in the neighborhood
* @param _solution the solution
*/
virtual void operator()(EOT & _solution) {
//Test if _solution has a Neighbor
if (neighborhood.hasNeighbor(_solution)) {
//init on the first neighbor: supposed to be random solution in the neighborhood
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 the temperature is not too low
* @param _solution the solution
* @return true if the criteria from the cooling schedule is true
*/
virtual bool isContinue(EOT & _solution) {
return coolingSchedule(temperature);
};
/**
* acceptance criterion according to the boltzmann criterion
* @param _solution the solution
* @return true if better neighbor or rnd < exp(delta f / T)
*/
virtual bool accept(EOT & _solution) {
if (neighborhood.hasNeighbor(_solution)) {
if (solNeighborComparator(_solution, selectedNeighbor)) // accept if the current neighbor is better than the solution
isAccept = true;
else {
double alpha=0.0;
double fit1, fit2;
fit1=(double)selectedNeighbor.fitness();
fit2=(double)_solution.fitness();
if (fit1 < fit2) // this is a maximization
alpha = exp((fit1 - fit2) / temperature );
else // this is a minimization
alpha = exp((fit2 - fit1) / temperature );
isAccept = (rng.uniform() < alpha) ;
}
}
return isAccept;
};
/**
* Getter
* @return the temperature
*/
double getTemperature() {
return temperature;
}
private:
// comparator betwenn solution and neighbor
moSolNeighborComparator<Neighbor>& solNeighborComparator;
moCoolingSchedule<EOT>& coolingSchedule;
// temperatur of the process
double temperature;
// true if the move is accepted
bool isAccept ;
};
#endif

View file

@ -0,0 +1,167 @@
/*
<moSimpleHCExplorer.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 _moSimpleHCexplorer_h
#define _moSimpleHCexplorer_h
#include <explorer/moNeighborhoodExplorer.h>
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
#include <neighborhood/moNeighborhood.h>
/**
* Explorer for a simple Hill-climbing
*/
template< class Neighbor >
class moSimpleHCexplorer : public moNeighborhoodExplorer<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
typedef moNeighborhood<Neighbor> Neighborhood ;
using moNeighborhoodExplorer<Neighbor>::neighborhood;
using moNeighborhoodExplorer<Neighbor>::eval;
using moNeighborhoodExplorer<Neighbor>::currentNeighbor;
using moNeighborhoodExplorer<Neighbor>::selectedNeighbor;
/**
* Constructor
* @param _neighborhood the neighborhood
* @param _eval the evaluation function
* @param _neighborComparator a neighbor comparator
* @param _solNeighborComparator solution vs neighbor comparator
*/
moSimpleHCexplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator) : moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) {
isAccept = false;
}
/**
* Destructor
*/
~moSimpleHCexplorer() {
}
/**
* initParam: NOTHING TO DO
* @param _solution unused solution
*/
virtual void initParam(EOT & _solution) {};
/**
* updateParam: NOTHING TO DO
* @param _solution unused solution
*/
virtual void updateParam(EOT & _solution) {};
/**
* terminate: NOTHING TO DO
* @param _solution unused solution
*/
virtual void terminate(EOT & _solution) {};
/**
* Explore the neighborhood of a solution
* @param _solution the current solution
*/
virtual void operator()(EOT & _solution) {
//Test if _solution has a Neighbor
if (neighborhood.hasNeighbor(_solution)) {
//init the first neighbor
neighborhood.init(_solution, currentNeighbor);
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, currentNeighbor);
//initialize the best neighbor
selectedNeighbor = currentNeighbor;
//test all others neighbors
while (neighborhood.cont(_solution)) {
//next neighbor
neighborhood.next(_solution, currentNeighbor);
//eval
eval(_solution, currentNeighbor);
//if we found a better neighbor, update the best
if (neighborComparator(selectedNeighbor, currentNeighbor)) {
selectedNeighbor = currentNeighbor;
}
}
}
else {
//if _solution hasn't neighbor,
isAccept=false;
}
};
/**
* continue if a move is accepted
* @param _solution the solution
* @return true if an ameliorated neighbor was be found
*/
virtual bool isContinue(EOT & _solution) {
return isAccept ;
};
/**
* accept test if an amelirated neighbor was be found
* @param _solution the solution
* @return true if the best neighbor ameliorate the fitness
*/
virtual bool accept(EOT & _solution) {
if (neighborhood.hasNeighbor(_solution)) {
isAccept = solNeighborComparator(_solution, selectedNeighbor) ;
}
return isAccept;
};
/**
* Return the class Name
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moSimpleHCexplorer";
}
private:
// comparator betwenn solution and neighbor or between neighbors
moNeighborComparator<Neighbor>& neighborComparator;
moSolNeighborComparator<Neighbor>& solNeighborComparator;
// true if the move is accepted
bool isAccept ;
};
#endif

View file

@ -0,0 +1,247 @@
/*
<moTSexplorer.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 _moTSexplorer_h
#define _moTSexplorer_h
#include <explorer/moNeighborhoodExplorer.h>
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
#include <memory/moAspiration.h>
#include <memory/moTabuList.h>
#include <memory/moIntensification.h>
#include <memory/moDiversification.h>
#include <neighborhood/moNeighborhood.h>
/**
* Explorer for a Tabu Search
*/
template< class Neighbor >
class moTSexplorer : public moNeighborhoodExplorer<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
typedef moNeighborhood<Neighbor> Neighborhood ;
using moNeighborhoodExplorer<Neighbor>::currentNeighbor;
using moNeighborhoodExplorer<Neighbor>::selectedNeighbor;
/**
* Constructor
* @param _neighborhood the neighborhood
* @param _eval the evaluation function
* @param _neighborComparator a neighbor comparator
* @param _solNeighborComparator a comparator between a solution and a neighbor
* @param _tabuList the tabu list
* @param _intensification the intensification box
* @param _diversification the diversification box
* @param _aspiration the aspiration criteria
*/
moTSexplorer(Neighborhood& _neighborhood,
moEval<Neighbor>& _eval,
moNeighborComparator<Neighbor>& _neighborComparator,
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
moTabuList<Neighbor> & _tabuList,
moIntensification<Neighbor> & _intensification,
moDiversification<Neighbor> & _diversification,
moAspiration<Neighbor> & _aspiration
) :
moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator),
tabuList(_tabuList), intensification(_intensification), diversification(_diversification), aspiration(_aspiration)
{
isAccept = false;
}
/**
* Destructor
*/
~moTSexplorer() {
}
/**
* init tabu list, intensification box, diversification box and aspiration criteria
* @param _solution
*/
virtual void initParam(EOT& _solution)
{
tabuList.init(_solution);
intensification.init(_solution);
diversification.init(_solution);
aspiration.init(_solution);
bestSoFar=_solution;
};
/**
* update params of tabu list, intensification box, diversification box and aspiration criteria
* @param _solution
*/
virtual void updateParam(EOT& _solution)
{
if ((*this).moveApplied()) {
tabuList.add(_solution, selectedNeighbor);
intensification.add(_solution, selectedNeighbor);
diversification.add(_solution, selectedNeighbor);
if (_solution.fitness() > bestSoFar.fitness())
bestSoFar = _solution;
}
tabuList.update(_solution, selectedNeighbor);
intensification.update(_solution, selectedNeighbor);
diversification.update(_solution, selectedNeighbor);
aspiration.update(_solution, selectedNeighbor);
};
/**
* terminate : _solution becomes the best so far
*/
virtual void terminate(EOT & _solution) {
_solution= bestSoFar;
};
/**
* Explore the neighborhood of a solution
* @param _solution
*/
virtual void operator()(EOT & _solution)
{
bool found=false;
intensification(_solution);
diversification(_solution);
if (neighborhood.hasNeighbor(_solution))
{
//init the current neighbor
neighborhood.init(_solution, currentNeighbor);
//eval the current neighbor
eval(_solution, currentNeighbor);
//Find the first non-tabu element
if ( (!tabuList.check(_solution, currentNeighbor)) || aspiration(_solution, currentNeighbor) ) {
// set selectedNeighbor
selectedNeighbor = currentNeighbor;
found=true;
}
while (neighborhood.cont(_solution) && !found) {
//next neighbor
neighborhood.next(_solution, currentNeighbor);
//eval
eval(_solution, currentNeighbor);
if ( (!tabuList.check(_solution, currentNeighbor)) || aspiration(_solution, currentNeighbor) ) {
// set selectedNeighbor
selectedNeighbor = currentNeighbor;
found=true;
}
}
//Explore the neighborhood
if (found) {
isAccept=true;
while (neighborhood.cont(_solution)) {
//next neighbor
neighborhood.next(_solution, currentNeighbor);
//eval
eval(_solution, currentNeighbor);
//check if the current is better than the best and is not tabu or if it is aspirat (by the aspiration criteria of course)
if ( (!tabuList.check(_solution, currentNeighbor) || aspiration(_solution, currentNeighbor)) && neighborComparator(selectedNeighbor, currentNeighbor)) {
// set selectedNeighbor
selectedNeighbor = currentNeighbor;
}
}
}
else {
isAccept=false;
}
}
else {
isAccept=false;
}
};
/**
* always continue
* @param _solution the solution
* @return true
*/
virtual bool isContinue(EOT & _solution) {
return true;
};
/**
* 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) {
return isAccept;
};
/**
* Give the current best found so far
* @return the best solution so far
*/
const EOT& getBest() {
return bestSoFar;
};
protected:
using moNeighborhoodExplorer<Neighbor>::neighborhood;
using moNeighborhoodExplorer<Neighbor>::eval;
// comparator between solution and neighbor or between neighbors
moNeighborComparator<Neighbor>& neighborComparator;
moSolNeighborComparator<Neighbor>& solNeighborComparator;
// Tabu components
moTabuList<Neighbor> & tabuList;
moIntensification<Neighbor> & intensification;
moDiversification<Neighbor> & diversification;
moAspiration<Neighbor> & aspiration;
// Best neighbor
// Neighbor best;
//Best so far Solution
EOT bestSoFar;
// true if the move is accepted
bool isAccept ;
};
#endif

View file

@ -0,0 +1,172 @@
/*
<moVNSexplorer.h>
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 _moVNSexplorer_h
#define _moVNSexplorer_h
#include <explorer/moNeighborhoodExplorer.h>
#include <neighborhood/moVariableNeighborhoodSelection.h>
#include <eoOp.h>
#include <acceptCrit/moAcceptanceCriterion.h>
/**
* Explorer for the "Variable Neighborhood Search" metaheuristic
*/
template< class Neighbor>
class moVNSexplorer : public moNeighborhoodExplorer< Neighbor >
{
public:
typedef typename Neighbor::EOT EOT;
/**
* Default constructor
*/
moVNSexplorer() {}
/**
* Constructor
* @param _selection selection the "neighborhood" search heuristics during the search
* @param _acceptCrit acceptance criteria which compare and accept or not the two solutions
*/
moVNSexplorer(moVariableNeighborhoodSelection<EOT> & _selection,
moAcceptanceCriterion<Neighbor>& _acceptCrit):
moNeighborhoodExplorer<Neighbor>(), selection(_selection), acceptCrit(_acceptCrit), stop(false), first(true)
{}
/**
* Empty destructor
*/
~moVNSexplorer() {
}
/**
* Initialization on the initial search opeartors based on the "first" neighborhood
* @param _solution the current solution
*/
virtual void initParam(EOT& _solution) {
// the best solution found
bestSoFar = _solution;
// initialization of the LS
selection.init(_solution);
// for the first ls, the solution will be improved, so the next ls must be applied
first = true;
}
/**
* Change the search operators on the next neighborhood search.
* @param _solution the current solution
*/
virtual void updateParam(EOT & _solution) {
if (!first && (*this).moveApplied()) {
first = false;
selection.init(_solution);
} else
if (selection.cont(currentSol)) {
selection.next(_solution);
} else
stop = true;
}
/**
* terminate: return the best solution found
*/
virtual void terminate(EOT & _solution) {
_solution = bestSoFar;
}
/**
* Explore the neighborhood of a solution by the "neighborhood" search heuristics
* @param _solution the current solution
*/
virtual void operator()(EOT & _solution) {
eoMonOp<EOT> & shake = selection.getShake();
eoMonOp<EOT> & ls = selection.getLocalSearch();
currentSol = _solution;
shake(currentSol);
ls(currentSol);
// update the best solution found
if (bestSoFar.fitness() < currentSol.fitness())
bestSoFar = currentSol;
}
/**
* continue if a move is accepted
* @param _solution the solution
* @return true if an ameliorated neighbor was be found
*/
virtual bool isContinue(EOT & _solution) {
return !stop;
};
/**
* move the solution with to current accepted solution
* @param _solution the solution to move
*/
virtual void move(EOT & _solution) {
_solution = currentSol;
};
/**
* accept test if an amelirated neighbor was be found according to acceptance criteria
* @param _solution the solution
* @return true if the neighbor ameliorate the fitness
*/
virtual bool accept(EOT & _solution) {
return acceptCrit(_solution, currentSol);
};
/**
* Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moVNSexplorer";
}
private:
/** the set of LS and shake operators to applied */
moVariableNeighborhoodSelection<EOT>& selection;
/** Acceptance criterium between two LS */
moAcceptanceCriterion<Neighbor>& acceptCrit;
/** stopping criterium flag */
bool stop;
/** the current solution */
EOT currentSol;
/** Best solution found during the search */
EOT bestSoFar;
/** first LS flag */
bool first;
};
#endif