Debut de VNS

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1729 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-03-30 15:46:16 +00:00
commit 0586fc4e2e
5 changed files with 563 additions and 0 deletions

View file

@ -0,0 +1,142 @@
/*
<moVNSexplorer.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can ue,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef _moVNSexplorer_h
#define _moVNSexplorer_h
#include <explorer/moNeighborhoodExplorer.h>
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
/**
* Explorer for Variiable Neighborhood Search
*/
template< class Neighborhood >
class moVNSexplorer : 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
*/
moVNSexplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) {
}
/**
* Destructor
*/
~moVNSexplorer() {
}
/**
* 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) {
};
/**
* 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 "moVNSexplorer";
}
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,87 @@
/*
<moBackwardVariableNeighborhood.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can ue,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef _moBackwardVariableNeighborhood_h
#define _moBackwardVariableNeighborhood_h
#include <neighborhood/moVariableNeighborhood.h>
/**
* A variable Neighborhood Search (VNS) in the Backward manner
*/
template< class Neighbor >
class moBackwardVariableNeighborhood : public moVariableNeighborhood<Neighbor>
{
public:
/**
* Define type of a solution corresponding to Neighbor
*/
typedef typename Neighbor::EOT EOT;
using moVariableNeighborhood::currentNH;
using moVariableNeighborhood::neighborhoodVector;
/**
* Construction of at least one neighborhood
* @param _firstNH first neighborhood in the vector
*/
moBackwardVariableNeighborhood(moNeighborhood<Neighbor>& _firstNH) : moVariableNeighborhood<Neighbor>(_firstNH) { }
/**
* Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moBackwardVariableNeighborhood";
}
/**
* test if there is still some neighborhood to explore
* @return true if there is some neighborhood to explore
*/
virtual bool contNeighborhood() {
return (currentNH > 0);
}
/**
* put the current neighborhood on the last one
*/
virtual void initNeighborhood() {
currentNH = neighborhoodVector.size() - 1;
}
/**
* put the current neighborhood on the next one
*/
virtual void nextNeighborhood() {
currentNH--;
}
};
#endif

View file

@ -0,0 +1,88 @@
/*
<moForwardVariableNeighborhood.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can ue,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef _moForwardVariableNeighborhood_h
#define _moForwardVariableNeighborhood_h
#include <neighborhood/moVariableNeighborhood.h>
/**
* A variable Neighborhood Search (VNS) in the forward manner
*/
template< class Neighbor >
class moForwardVariableNeighborhood : public moVariableNeighborhood<Neighbor>
{
public:
/**
* Define type of a solution corresponding to Neighbor
*/
typedef typename Neighbor::EOT EOT;
using moVariableNeighborhood::currentNH;
using moVariableNeighborhood::neighborhoodVector;
/**
* Construction of at least one neighborhood
* @param _firstNH first neighborhood in the vector
*/
moForwardVariableNeighborhood(moNeighborhood<Neighbor>& _firstNH) : moVariableNeighborhood<Neighbor>(_firstNH) { }
/**
* Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moForwardVariableNeighborhood";
}
/**
* test if there is still some neighborhood to explore
* @return true if there is some neighborhood to explore
*/
virtual bool contNeighborhood() {
return (currentNH < neighborhoodVector.size() - 1);
}
/**
* put the current neighborhood on the first one
*/
virtual void initNeighborhood() {
currentNH = 0;
}
/**
* put the current neighborhood on the next one
*/
virtual void nextNeighborhood() {
currentNH++;
}
};
#endif

View file

@ -0,0 +1,107 @@
/*
<moRndVariableNeighborhood.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can ue,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef _moRndVariableNeighborhood_h
#define _moRndVariableNeighborhood_h
#include <neighborhood/moVariableNeighborhood.h>
#include <algorithm>
/**
* A variable Neighborhood Search (VNS) in the random manner
*/
template< class Neighbor >
class moRndVariableNeighborhood : public moVariableNeighborhood<Neighbor>
{
public:
/**
* Define type of a solution corresponding to Neighbor
*/
typedef typename Neighbor::EOT EOT;
using moVariableNeighborhood::currentNH;
using moVariableNeighborhood::neighborhoodVector;
/**
* Construction of at least one neighborhood
* @param _firstNH first neighborhood in the vector
*/
moRndVariableNeighborhood(moNeighborhood<Neighbor>& _firstNH) : moVariableNeighborhood<Neighbor>(_firstNH) {
indexVector.push_back(0);
}
/**
* to add a neighborhood in the vector
* @param _nh the neighborhood to add at the end of the vector of neighborhood
*/
virtual void add(moNeighborhood<Neighbor>& _nh) {
neighborhoodVector.push_back(_nh);
indexVector.push_back(indexVector.size());
}
/**
* Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moRndVariableNeighborhood";
}
/**
* test if there is still some neighborhood to explore
* @return true if there is some neighborhood to explore
*/
virtual bool contNeighborhood() {
return (index < neighborhoodVector.size() - 1);
}
/**
* put the current neighborhood on the first one
*/
virtual void initNeighborhood() {
std::random_shuffle(indexVector.begin(), indexVector.end());
index = 0;
currentNH = indexVector[index];
}
/**
* put the current neighborhood on the next one
*/
virtual void nextNeighborhood() {
index++;
currentNH = indexVector[index];
}
private:
unsigned int index;
std::vector<unsigned int> indexVector;
};
#endif

View file

@ -0,0 +1,139 @@
/*
<moVariableNeighborhood.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can ue,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef _moVariableNeighborhood_h
#define _moVariableNeighborhood_h
#include <neighborhood/moNeighborhood.h>
/**
* A vector of neighborhood for the Variable Neighborhood Search (VNS)
*/
template< class Neighbor >
class moVariableNeighborhood : public moNeighborhood<Neighbor>
{
public:
/**
* Define type of a solution corresponding to Neighbor
*/
typedef typename Neighbor::EOT EOT;
/**
* Construction of at least one neighborhood
* @param _firstNH first neighborhood in the vector
*/
moVariableNeighborhood(moNeighborhood<Neighbor>& _firstNH) {
neighborhoodVector.push_back(_firstNH);
// the current neighborhood
currentNH = 0;
}
/**
* @return if the current neighborhood is random
*/
virtual bool isRandom() {
return neighborhoodVector[currentNH].isRandom();
}
/**
* Test if a solution has a Neighbor in the current neighborhood
* @param _solution the related solution
* @return if _solution has a Neighbor in the current neighborhood
*/
virtual bool hasNeighbor(EOT & _solution) {
return neighborhoodVector[currentNH].hasNeighbor(_solution);
}
/**
* Initialization of the current neighborhood
* @param _solution the solution to explore
* @param _current the first neighbor in the current neighborhood
*/
virtual void init(EOT & _solution, Neighbor & _current) {
neighborhoodVector[currentNH].init(_solution, _current);
}
/**
* Give the next neighbor in the current neighborhood
* @param _solution the solution to explore
* @param _current the next neighbor in the current neighborhood
*/
virtual void next(EOT & _solution, Neighbor & _current) {
neighborhoodVector[currentNH].next(_solution, _current);
}
/**
* Test if there is again a neighbor in the current neighborhood
* @param _solution the solution to explore
* @return if there is still a neighbor not explored in the current neighborhood
*/
virtual bool cont(EOT & _solution) {
neighborhoodVector[currentNH].cont(_solution);
}
/**
* Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moVariableNeighborhood";
}
/**
* to add a neighborhood in the vector
* @param _nh the neighborhood to add at the end of the vector of neighborhood
*/
virtual void add(moNeighborhood<Neighbor>& _nh) {
neighborhoodVector.push_back(_nh);
}
/**
* test if there is still some neighborhood to explore
* @return true if there is some neighborhood to explore
*/
virtual bool contNeighborhood() = 0;
/**
* put the current neighborhood on the first one
*/
virtual void initNeighborhood() = 0;
/**
* put the current neighborhood on the next one
*/
virtual void nextNeighborhood() = 0;
private:
// the vector of neighborhoods
std::vector<moNeighborhood<Neighbor>& > neighborhoodVector;
// the index of the current neighborhood
unsigned int currentNH;
};
#endif