paradiseo new mo added

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1712 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-03-24 10:07:28 +00:00
commit d7496cafff
116 changed files with 12034 additions and 0 deletions

View file

@ -0,0 +1,162 @@
/*
<moFirstImprExplorer.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 _moFirstImprexplorer_h
#define _moFirstImprexplorer_h
#include <explorer/moNeighborhoodExplorer.h>
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
/**
* Explorer for a first imporvement heuristic
*/
template< class Neighborhood >
class moFirstImprExplorer : public moNeighborhoodExplorer<Neighborhood>
{
public:
typedef typename Neighborhood::EOT EOT ;
typedef typename Neighborhood::Neighbor Neighbor ;
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::eval;
/**
* Constructor
* @param _neighborhood the neighborhood
* @param _eval the evaluation function
* @param _neighborComparator a neighbor comparator
* @param _solNeighborComparator a solution vs neighbor comparator
*/
moFirstImprExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) {
isAccept = false;
current=new Neighbor();
}
/**
* Destructor
*/
~moFirstImprExplorer(){
delete current;
}
/**
* initParam: NOTHING TO DO
*/
virtual void initParam(EOT & solution){};
/**
* updateParam: NOTHING TO DO
*/
virtual void updateParam(EOT & solution){};
/**
* terminate: NOTHING TO DO
*/
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, (*current));
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, (*current));
//test all others neighbors
while (! solNeighborComparator(_solution, *current) && neighborhood.cont(_solution)) {
//next neighbor
neighborhood.next(_solution, (*current));
//eval
eval(_solution, (*current));
}
}
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) {
//move the solution
(*current).move(_solution);
//update its fitness
_solution.fitness((*current).fitness());
};
/**
* 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, (*current)) ;
}
return isAccept;
};
private:
// comparator betwenn solution and neighbor or between neighbors
moNeighborComparator<Neighbor>& neighborComparator;
moSolNeighborComparator<Neighbor>& solNeighborComparator;
//Pointer on the best and the current neighbor
Neighbor* current;
// true if the move is accepted
bool isAccept ;
};
#endif

View file

@ -0,0 +1,134 @@
/*
<moHCneutralExplorer.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 _moHCneutralExplorer_h
#define _moHCneutralExplorer_h
#include <explorer/moSimpleHCneutralExplorer.h>
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
/**
* Explorer for a neutral Hill-climbing
*/
template< class Neighborhood >
class moHCneutralExplorer : public moSimpleHCneutralExplorer<Neighborhood>
{
public:
typedef typename Neighborhood::EOT EOT ;
typedef typename Neighborhood::Neighbor Neighbor ;
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moSimpleHCneutralExplorer<Neighborhood>::solNeighborComparator;
using moSimpleHCneutralExplorer<Neighborhood>::isAccept;
using moSimpleHCneutralExplorer<Neighborhood>::bestVector;
using moSimpleHCneutralExplorer<Neighborhood>::initParam;
using moSimpleHCneutralExplorer<Neighborhood>::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
*/
moHCneutralExplorer(Neighborhood& _neighborhood,
moEval<Neighbor>& _eval,
moNeighborComparator<Neighbor>& _neighborComparator,
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
unsigned _nbStep) :
moSimpleHCneutralExplorer<Neighborhood>(_neighborhood, _eval, _neighborComparator, _solNeighborComparator),
nbStep(_nbStep){
//Some cycle is possible with equals fitness solutions if the neighborhood is not random
if(!neighborhood.isRandom()){
std::cout << "moHCneutralExplorer::Warning -> the neighborhood used is not random" << std::endl;
}
}
/**
* Destructor
*/
~moHCneutralExplorer(){
}
/**
* initial number of step
*/
virtual void initParam(EOT & solution){
moSimpleHCneutralExplorer<Neighborhood>::initParam(solution);
step = 0;
};
/**
* one more step
*/
virtual void updateParam(EOT & solution){
moSimpleHCneutralExplorer<Neighborhood>::updateParam(solution);
step++;
};
/**
* 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) && isAccept ;
};
/**
* accept test if an ameliorated 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,194 @@
/*
<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 <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 Neighborhood >
class moMetropolisHastingExplorer : public moNeighborhoodExplorer<Neighborhood>
{
public:
typedef typename Neighborhood::EOT EOT ;
typedef typename Neighborhood::Neighbor Neighbor ;
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::eval;
/**
* 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<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator), nbStep(_nbStep) {
isAccept = false;
current=new Neighbor();
if(!neighborhood.isRandom()){
std::cout << "moMetropolisHastingExplorer::Warning -> the neighborhood used is not random" << std::endl;
}
}
/**
* Destructor
*/
~moMetropolisHastingExplorer(){
delete current;
}
/**
* initialization of the number of step to be done
* @param _solution the solution (unused here)
*/
virtual void initParam(EOT & _solution){
step = 0;
isAccept = true;
};
/**
* increase the number of step
* @param _solution the solution (unused here)
*/
virtual void updateParam(EOT & _solution){
step++;
};
/**
* terminate: NOTHING TO DO
* @param _solution the solution (unused here)
*/
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, (*current));
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, (*current));
}
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) ;
};
/**
* move the solution with the best neighbor
* @param _solution the solution to move
*/
virtual void move(EOT & _solution) {
//move the solution
(*current).move(_solution);
//update its fitness
_solution.fitness((*current).fitness());
};
/**
* accept test if an ameliorated neighbor was be 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, *current))
isAccept = true;
else{
if(_solution.fitness() != 0){
if( (double)current->fitness() < (double)_solution.fitness()) // maximizing
alpha = (double) current->fitness() / (double) _solution.fitness();
else //minimizing
alpha = (double) _solution.fitness() / (double) current->fitness();
isAccept = (rng.uniform() < alpha) ;
}
else{
if( (double)current->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;
//Pointer on the best and the current neighbor
Neighbor* current;
// true if the move is accepted
bool isAccept ;
};
#endif

View file

@ -0,0 +1,131 @@
/*
<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>
/**
* Explore the neighborhood
*/
template< class NH >
class moNeighborhoodExplorer : public eoUF<typename NH::EOT&, void>
{
public:
typedef NH Neighborhood ;
typedef typename Neighborhood::EOT EOT ;
typedef typename Neighborhood::Neighbor Neighbor ;
/**
* 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
* @param _solution the solution to explore
*/
virtual void move(EOT& _solution) = 0 ;
/**
* 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 for variable "isMoved"
* @return true if move is applied
*/
bool moveApplied(){
return isMoved;
}
/**
* Setter for variable "isMoved"
* @param _isMoved
*/
void moveApplied(bool _isMoved){
isMoved=_isMoved;
}
/**
* Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moNeighborhoodExplorer";
}
protected:
Neighborhood & neighborhood;
moEval<Neighbor>& eval;
bool isMoved;
};
#endif

View file

@ -0,0 +1,180 @@
/*
<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>
/**
* 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 Neighborhood >
class moRandomNeutralWalkExplorer : public moNeighborhoodExplorer<Neighborhood>
{
public:
typedef typename Neighborhood::EOT EOT ;
typedef typename Neighborhood::Neighbor Neighbor ;
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::eval;
/**
* 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<Neighborhood>(_neighborhood, _eval),
solNeighborComparator(_solNeighborComparator),
nbStep(_nbStep) {
isAccept = false;
current=new Neighbor();
if(!neighborhood.isRandom()){
std::cout << "moRandomNeutralWalkExplorer::Warning -> the neighborhood used is not random" << std::endl;
}
}
/**
* Destructor
*/
~moRandomNeutralWalkExplorer(){
delete current;
}
/**
* initialization of the number of step to be done
*/
virtual void initParam(EOT & solution){
step = 0;
isAccept = true;
};
/**
* increase the number of step
*/
virtual void updateParam(EOT & solution){
step++;
};
/**
* terminate: NOTHING TO DO
*/
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, (*current));
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, (*current));
//test all others neighbors
while (! solNeighborComparator.equals(_solution, *current) && neighborhood.cont(_solution)) {
//next neighbor
neighborhood.next(_solution, (*current));
//eval
eval(_solution, (*current));
}
}
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) && isAccept ;
};
/**
* move the solution with the best neighbor
* @param _solution the solution to move
*/
virtual void move(EOT & _solution) {
//move the solution
(*current).move(_solution);
//update its fitness
_solution.fitness((*current).fitness());
};
/**
* accept test if an ameliorated 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, (*current)) ;
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;
//Pointer on the best and the current neighbor
Neighbor* current;
// true if the move is accepted
bool isAccept ;
};
#endif

View file

@ -0,0 +1,166 @@
/*
<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>
/**
* Explorer for a random walk explorer
*/
template< class Neighborhood >
class moRandomWalkExplorer : public moNeighborhoodExplorer<Neighborhood>
{
public:
typedef typename Neighborhood::EOT EOT ;
typedef typename Neighborhood::Neighbor Neighbor ;
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::eval;
/**
* Constructor
* @param _neighborhood the neighborhood
* @param _eval the evaluation function
* @param _nbStep maximum number of step to do
*/
moRandomWalkExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, unsigned _nbStep) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), nbStep(_nbStep) {
isAccept = false;
current=new Neighbor();
// number of step done
step = 0;
if(!neighborhood.isRandom()){
std::cout << "moRandomWalkExplorer::Warning -> the neighborhood used is not random" << std::endl;
}
}
/**
* Destructor
*/
~moRandomWalkExplorer(){
delete current;
}
/**
* initialization of the number of step to be done
*/
virtual void initParam(EOT & solution){
step = 0;
isAccept = true;
};
/**
* increase the number of step
*/
virtual void updateParam(EOT & solution){
step++;
};
/**
* terminate: NOTHING TO DO
*/
virtual void terminate(EOT & solution){};
/**
* Explore the neighborhood with only one random 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, (*current));
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, (*current));
isAccept = true;
}
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) && isAccept ;
};
/**
* move the solution with the best neighbor
* @param _solution the solution to move
*/
virtual void move(EOT & _solution) {
//move the solution
(*current).move(_solution);
//update its fitness
_solution.fitness((*current).fitness());
};
/**
* 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:
// current number of step
unsigned int step;
// maximum number of steps to do
unsigned int nbStep;
//Pointer on the best and the current neighbor
Neighbor* current;
// true if the move is accepted
bool isAccept ;
};
#endif

View file

@ -0,0 +1,182 @@
/*
<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>
/**
* Explorer for a simple Hill-climbing
*/
template< class Neighborhood >
class moSimpleHCexplorer : public moNeighborhoodExplorer<Neighborhood>
{
public:
typedef typename Neighborhood::EOT EOT ;
typedef typename Neighborhood::Neighbor Neighbor ;
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::eval;
/**
* 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<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) {
isAccept = false;
current=new Neighbor();
best=new Neighbor();
}
/**
* Destructor
*/
~moSimpleHCexplorer(){
delete current;
delete best;
}
/**
* initParam: NOTHING TO DO
*/
virtual void initParam(EOT & solution){};
/**
* updateParam: NOTHING TO DO
*/
virtual void updateParam(EOT & solution){};
/**
* terminate: NOTHING TO DO
*/
virtual void terminate(EOT & solution){};
/**
* Explore the neighborhood of a solution
* @param _solution
*/
virtual void operator()(EOT & _solution){
//est qu'on peut initializer
//Test if _solution has a Neighbor
if(neighborhood.hasNeighbor(_solution)){
//init the first neighbor
neighborhood.init(_solution, (*current));
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, (*current));
//initialize the best neighbor
(*best) = (*current);
//test all others neighbors
while (neighborhood.cont(_solution)) {
//next neighbor
neighborhood.next(_solution, (*current));
//eval
eval(_solution, (*current));
//if we found a better neighbor, update the best
if (neighborComparator((*best), (*current))) {
(*best) = (*current);
}
}
}
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) {
//move the solution
(*best).move(_solution);
//update its fitness
_solution.fitness((*best).fitness());
};
/**
* 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, (*best)) ;
}
return isAccept;
};
/**
* Return the class id.
* @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;
//Pointer on the best and the current neighbor
Neighbor* best;
Neighbor* current;
// true if the move is accepted
bool isAccept ;
};
#endif

View file

@ -0,0 +1,193 @@
/*
<moSimpleHCneutralExplorer.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 _moSimpleHCneutralExplorer_h
#define _moSimpleHCneutralExplorer_h
#include <explorer/moNeighborhoodExplorer.h>
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
#include <vector>
#include <utils/eoRNG.h>
/**
* Explorer for a simple neutral Hill-climbing
*/
template< class Neighborhood >
class moSimpleHCneutralExplorer : public moNeighborhoodExplorer<Neighborhood>
{
public:
typedef typename Neighborhood::EOT EOT ;
typedef typename Neighborhood::Neighbor Neighbor ;
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::eval;
/**
* Constructor
* @param _neighborhood the neighborhood
* @param _eval the evaluation function
* @param _neighborComparator a neighbor comparator
* @param _solNeighborComparator solution vs neighbor comparator
*/
moSimpleHCneutralExplorer(Neighborhood& _neighborhood,
moEval<Neighbor>& _eval,
moNeighborComparator<Neighbor>& _neighborComparator,
moSolNeighborComparator<Neighbor>& _solNeighborComparator) :
moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval),
neighborComparator(_neighborComparator),
solNeighborComparator(_solNeighborComparator) {
isAccept = false;
current=new Neighbor();
}
/**
* Destructor
*/
~moSimpleHCneutralExplorer(){
delete current;
}
/**
* empty the vector of best solutions
*/
virtual void initParam(EOT & solution){
// delete all the best solutions
bestVector.clear();
};
/**
* empty the vector of best solutions
*/
virtual void updateParam(EOT & solution){
// delete all the best solutions
bestVector.clear();
};
/**
* terminate: NOTHING TO DO
*/
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, (*current));
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, (*current));
//initialize the best neighbor
bestVector.push_back(*current);
//test all others neighbors
while (neighborhood.cont(_solution)) {
//next neighbor
neighborhood.next(_solution, (*current));
//eval
eval(_solution, (*current));
//if we found a better neighbor, update the best
if (neighborComparator(bestVector[0], (*current))) {
bestVector.clear();
bestVector.push_back(*current);
}
else if (neighborComparator.equals((*current), bestVector[0])) //if the current is equals to previous best solutions then update vector of the best solution
bestVector.push_back(*current);
}
}
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 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, bestVector[0]) ;
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;
//Pointer on the current neighbor
Neighbor* current;
// true if the move is accepted
bool isAccept ;
};
#endif

View file

@ -0,0 +1,255 @@
/*
<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>
/**
* Explorer for a Tabu Search
*/
template< class Neighborhood >
class moTSExplorer : public moNeighborhoodExplorer<Neighborhood>
{
public:
typedef typename Neighborhood::EOT EOT ;
typedef typename Neighborhood::Neighbor Neighbor ;
/**
* 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<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator),
tabuList(_tabuList), intensification(_intensification), diversification(_diversification), aspiration(_aspiration)
{
isAccept = false;
current=new Neighbor();
best=new Neighbor();
}
/**
* Destructor
*/
~moTSExplorer(){
delete current;
delete best;
}
/**
* 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, *best);
intensification.add(_solution, *best);
diversification.add(_solution, *best);
if(_solution.fitness() > bestSoFar.fitness())
bestSoFar = _solution;
}
tabuList.update(_solution, *best);
intensification.update(_solution, *best);
diversification.update(_solution, *best);
aspiration.update(_solution, *best);
};
/**
* 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, *current);
//eval the current neighbor
eval(_solution, *current);
//Find the first non-tabu element
if ( (!tabuList.check(_solution, *current)) || aspiration(_solution, *current) ){
// set best
(*best)= (*current);
found=true;
}
while(neighborhood.cont(_solution) && !found){
//next neighbor
neighborhood.next(_solution, (*current));
//eval
eval(_solution, (*current));
if ( (!tabuList.check(_solution, *current)) || aspiration(_solution, *current) ){
// set best
(*best)=(*current);
found=true;
}
}
//Explore the neighborhood
if(found){
isAccept=true;
while(neighborhood.cont(_solution)){
//next neighbor
neighborhood.next(_solution, (*current));
//eval
eval(_solution, (*current));
//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, *current) || aspiration(_solution, (*current))) && neighborComparator((*best),(*current))){
// set best
(*best)=(*current);
}
}
}
else{
isAccept=false;
}
}
else{
isAccept=false;
}
};
/**
* always continue
* @param _solution the solution
* @return true
*/
virtual bool isContinue(EOT & _solution){
return true;
};
/**
* move the solution with the best neighbor
* @param _solution the solution to move
*/
virtual void move(EOT & _solution) {
//move the solution
best->move(_solution);
//update its fitness
_solution.fitness(best->fitness());
};
/**
* accept test if an ameliorated neighbor was be found
* @param _solution the solution
* @return true if the best neighbor ameliorate the fitness
*/
virtual bool accept(EOT & _solution){
return isAccept;
};
protected:
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::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;
//Current and best neighbor
Neighbor* best;
Neighbor* current;
//Best so far Solution
EOT bestSoFar;
// true if the move is accepted
bool isAccept ;
};
#endif