VNS
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1917 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
58c59fd8fa
commit
71273f1344
6 changed files with 17 additions and 356 deletions
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
<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 EOT >
|
||||
class moBackwardVariableNeighborhood : public moVariableNeighborhood<EOT>
|
||||
{
|
||||
public:
|
||||
typedef moNeighbor<EOT> Neighbor;
|
||||
|
||||
using moVariableNeighborhood<EOT>::currentNH;
|
||||
using moVariableNeighborhood<EOT>::neighborhoodVector;
|
||||
|
||||
/**
|
||||
* Construction of at least one neighborhood
|
||||
* @param _firstNH first neighborhood in the vector
|
||||
*/
|
||||
moBackwardVariableNeighborhood(moNeighborhood<Neighbor>& _firstNH) : moVariableNeighborhood<EOT>(_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
|
||||
|
|
@ -55,6 +55,10 @@ public:
|
|||
*/
|
||||
moIndexNeighborhood(unsigned int _neighborhoodSize):neighborhoodSize(_neighborhoodSize) {}
|
||||
|
||||
unsigned int size(){
|
||||
return neighborhoodSize;
|
||||
}
|
||||
|
||||
protected:
|
||||
// size of the neighborhood
|
||||
unsigned int neighborhoodSize;
|
||||
|
|
|
|||
|
|
@ -1,104 +0,0 @@
|
|||
/*
|
||||
<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 EOT, class Fitness >
|
||||
class moRndVariableNeighborhood : public moVariableNeighborhood<EOT, Fitness>
|
||||
{
|
||||
public:
|
||||
typedef moNeighbor<EOT, Fitness> Neighbor;
|
||||
|
||||
using moVariableNeighborhood<EOT, Fitness>::currentNH;
|
||||
using moVariableNeighborhood<EOT, Fitness>::neighborhoodVector;
|
||||
|
||||
/**
|
||||
* Construction of at least one neighborhood
|
||||
* @param _firstNH first neighborhood in the vector
|
||||
*/
|
||||
moRndVariableNeighborhood(moNeighborhood<Neighbor>& _firstNH) : moVariableNeighborhood<EOT, Fitness>(_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
|
||||
|
|
@ -87,6 +87,7 @@ public:
|
|||
indexVector[i]=indexVector[maxIndex-1];
|
||||
indexVector[maxIndex-1]=tmp;
|
||||
maxIndex--;
|
||||
std::cout << _neighbor.className() << ", key: " << _neighbor.index() << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -102,6 +103,8 @@ public:
|
|||
indexVector[i]=indexVector[maxIndex-1];
|
||||
indexVector[maxIndex-1]=tmp;
|
||||
maxIndex--;
|
||||
|
||||
std::cout << _neighbor.className() << ", key: " << _neighbor.index() << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,139 +0,0 @@
|
|||
/*
|
||||
<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>
|
||||
#include <neighborhood/moNeighbor.h>
|
||||
#include <neighborhood/moIndexNeighbor.h>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* A vector of neighborhood for the Variable Neighborhood Search (VNS)
|
||||
*/
|
||||
template< class EOT >
|
||||
class moVariableNeighborhood : public moNeighborhood<moNeighbor<EOT> >
|
||||
{
|
||||
public:
|
||||
|
||||
typedef moNeighbor<EOT> Neighbor;
|
||||
/**
|
||||
* 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) {
|
||||
return 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;
|
||||
|
||||
protected:
|
||||
// the vector of neighborhoods
|
||||
std::vector<moNeighborhood<Neighbor>* > neighborhoodVector;
|
||||
// the index of the current neighborhood
|
||||
unsigned int currentNH;
|
||||
|
||||
};
|
||||
#endif
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
<moForwardVariableNeighborhood.h>
|
||||
<moVariableNeighborhoodSelection.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
|
||||
|
|
@ -27,59 +27,40 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
|||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#ifndef _moForwardVariableNeighborhood_h
|
||||
#define _moForwardVariableNeighborhood_h
|
||||
#ifndef _moVariableNeighborhoodSelection_h
|
||||
#define _moVariableNeighborhoodSelection_h
|
||||
|
||||
#include <neighborhood/moVariableNeighborhood.h>
|
||||
#include <eoOp.h>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* A variable Neighborhood Search (VNS) in the forward manner
|
||||
*/
|
||||
template< class EOT >
|
||||
class moForwardVariableNeighborhood : public moVariableNeighborhood<EOT>
|
||||
class moVariableNeighborhoodSelection
|
||||
{
|
||||
public:
|
||||
|
||||
typedef moNeighbor<EOT> Neighbor;
|
||||
|
||||
using moVariableNeighborhood<EOT>::currentNH;
|
||||
using moVariableNeighborhood<EOT>::neighborhoodVector;
|
||||
|
||||
/**
|
||||
* Construction of at least one neighborhood
|
||||
* @param _firstNH first neighborhood in the vector
|
||||
*/
|
||||
moForwardVariableNeighborhood(moNeighborhood<Neighbor>& _firstNH) : moVariableNeighborhood<EOT>(_firstNH) { }
|
||||
|
||||
/**
|
||||
* Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moForwardVariableNeighborhood";
|
||||
return "moVariableNeighborhoodSelection";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
virtual bool cont(EOT& _solution, eoMonOp<EOT>& _skake, eoMonOp<EOT>& _ls) = 0;
|
||||
|
||||
/**
|
||||
* put the current neighborhood on the first one
|
||||
*/
|
||||
virtual void initNeighborhood() {
|
||||
currentNH = 0;
|
||||
}
|
||||
virtual void init(EOT& _solution, eoMonOp<EOT>& _skake, eoMonOp<EOT>& _ls) = 0;
|
||||
|
||||
/**
|
||||
* put the current neighborhood on the next one
|
||||
*/
|
||||
virtual void nextNeighborhood() {
|
||||
currentNH++;
|
||||
}
|
||||
virtual void next(EOT& _solution, eoMonOp<EOT>& _skake, eoMonOp<EOT>& _ls) = 0;
|
||||
|
||||
};
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue