Ajout des commentaires autour de VNS
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1930 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
7870d8dcfe
commit
5a992685e2
6 changed files with 161 additions and 122 deletions
|
|
@ -34,7 +34,6 @@
|
|||
#include <neighborhood/moVariableNeighborhoodSelection.h>
|
||||
#include <eoOp.h>
|
||||
#include <acceptCrit/moAcceptanceCriterion.h>
|
||||
#include <algo/moDummyLS.h>
|
||||
|
||||
/**
|
||||
* Explorer for the "Variable Neighborhood Search" metaheuristic
|
||||
|
|
@ -47,11 +46,9 @@ public:
|
|||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param _neighborhood the neighborhood
|
||||
* @param _eval the evaluation function
|
||||
* @param _neighborComparator a neighbor comparator
|
||||
* @param _solNeighborComparator solution vs neighbor comparator
|
||||
* Default 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):
|
||||
|
|
@ -59,7 +56,7 @@ public:
|
|||
{}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* Empty destructor
|
||||
*/
|
||||
~moVNSexplorer() {
|
||||
}
|
||||
|
|
@ -92,7 +89,7 @@ public:
|
|||
virtual void terminate(EOT & _solution) {};
|
||||
|
||||
/**
|
||||
* Explore the neighborhood of a solution
|
||||
* Explore the neighborhood of a solution by the "neighborhood" search heuristics
|
||||
* @param _solution the current solution
|
||||
*/
|
||||
virtual void operator()(EOT & _solution) {
|
||||
|
|
@ -100,12 +97,8 @@ public:
|
|||
eoMonOp<EOT> & ls = selection.getLocalSearch();
|
||||
|
||||
current = _solution;
|
||||
std::cout << "current avec shake: "<< current << std::endl;
|
||||
shake(current);
|
||||
std::cout << "current apres shake: "<< current << std::endl;
|
||||
ls(current);
|
||||
std::cout << "current apres ls: "<< ls.className() ;
|
||||
std::cout << " sol: " << current << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -118,7 +111,7 @@ public:
|
|||
};
|
||||
|
||||
/**
|
||||
* move the solution with the best neighbor
|
||||
* move the solution with to current accepted solution
|
||||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void move(EOT & _solution) {
|
||||
|
|
@ -128,7 +121,7 @@ public:
|
|||
/**
|
||||
* accept test if an amelirated neighbor was be found according to acceptance criteria
|
||||
* @param _solution the solution
|
||||
* @return true if the best neighbor ameliorate the fitness
|
||||
* @return true if the neighbor ameliorate the fitness
|
||||
*/
|
||||
virtual bool accept(EOT & _solution) {
|
||||
return acceptCrit(_solution, current);
|
||||
|
|
@ -143,21 +136,11 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
//moDummyLS<Neighbor> dummyLS;
|
||||
moVariableNeighborhoodSelection<EOT>& selection;
|
||||
moAcceptanceCriterion<Neighbor>& acceptCrit;
|
||||
//eoMonOp<EOT>* ls;
|
||||
//eoMonOp<EOT>& shake;
|
||||
bool stop;
|
||||
|
||||
EOT current;
|
||||
|
||||
/*
|
||||
class moDummyEval: public eoEvalFunc<EOT>{
|
||||
public:
|
||||
void operator()(EOT& hop){}
|
||||
}dummyEval;
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,16 +32,28 @@
|
|||
|
||||
#include <neighborhood/moVectorVNSelection.h>
|
||||
|
||||
/**
|
||||
* This class is used for the Variable Neighborhood Search explorer inherits from moVectorVNSelection
|
||||
* The search heuristics are saved in vectors
|
||||
* They are given in backward order from the last ones to the first ones
|
||||
*
|
||||
*/
|
||||
template< class EOT >
|
||||
class moBackwardVectorVNSelection: public moVectorVNSelection<EOT>{
|
||||
|
||||
using moVectorVNSelection<EOT>::LSvector;
|
||||
using moVectorVNSelection<EOT>::shakeVector;
|
||||
using moVectorVNSelection<EOT>::current;
|
||||
|
||||
public:
|
||||
|
||||
moBackwardVectorVNSelection(eoMonOp<EOT>& _firstLS, eoMonOp<EOT>& _firstShake, bool _cycle):moVectorVNSelection<EOT>(_firstLS, _firstShake), cycle(_cycle){}
|
||||
/**
|
||||
* Default constructor with first search heuristics
|
||||
*
|
||||
* @param _firstLS first local search
|
||||
* @param _firstShake first heuristic which perturbs the solution
|
||||
* @param _cycle when true, the first heuristics follows the last ones. Otherwise the search stop.
|
||||
*/
|
||||
moBackwardVectorVNSelection(eoMonOp<EOT>& _firstLS, eoMonOp<EOT>& _firstShake, bool _cycle = true) : moVectorVNSelection<EOT>(_firstLS, _firstShake), cycle(_cycle){}
|
||||
|
||||
/**
|
||||
* Return the class id.
|
||||
|
|
@ -52,34 +64,35 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* test if there is still some neighborhood to explore
|
||||
* @return true if there is some neighborhood to explore
|
||||
* test if there is still some heuristics
|
||||
*
|
||||
* @param _solution the current solution
|
||||
* @return true if there is some heuristics
|
||||
*/
|
||||
virtual bool cont(EOT& _solution){
|
||||
return (cycle || (current > 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* put the current neighborhood on the first one
|
||||
* put the current heuristics on the first ones
|
||||
*
|
||||
* @param _solution the current solution
|
||||
*/
|
||||
virtual void init(EOT& _solution){
|
||||
current = LSvector.size() - 1;
|
||||
std::cout << "current LS: " << current << std::endl;
|
||||
std::cout << _solution << std::endl;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* put the current neighborhood on the next one
|
||||
* put the current heuristics on the next ones
|
||||
*
|
||||
* @param _solution the current solution
|
||||
*/
|
||||
virtual void next(EOT& _solution){
|
||||
current = (current + LSvector.size() -1) % LSvector.size();
|
||||
std::cout << "current LS: " << current << std::endl;
|
||||
std::cout << _solution << std::endl;
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
// boolean to indicate the last heuristics follow the first ones
|
||||
bool cycle;
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,16 +32,28 @@
|
|||
|
||||
#include <neighborhood/moVectorVNSelection.h>
|
||||
|
||||
/**
|
||||
* This class is used for the Variable Neighborhood Search explorer inherits from moVectorVNSelection
|
||||
* The search heuristics are saved in vectors
|
||||
* They are given in forward order from the first ones to the last ones
|
||||
*
|
||||
*/
|
||||
template< class EOT >
|
||||
class moForwardVectorVNSelection: public moVectorVNSelection<EOT>{
|
||||
|
||||
using moVectorVNSelection<EOT>::LSvector;
|
||||
using moVectorVNSelection<EOT>::shakeVector;
|
||||
using moVectorVNSelection<EOT>::current;
|
||||
|
||||
public:
|
||||
|
||||
moForwardVectorVNSelection(eoMonOp<EOT>& _firstLS, eoMonOp<EOT>& _firstShake, bool _cycle):moVectorVNSelection<EOT>(_firstLS, _firstShake), cycle(_cycle){}
|
||||
/**
|
||||
* Default constructor with first search heuristics
|
||||
*
|
||||
* @param _firstLS first local search
|
||||
* @param _firstShake first heuristic which perturbs the solution
|
||||
* @param _cycle when true, the first heuristics follows the last ones. Otherwise the search stop.
|
||||
*/
|
||||
moForwardVectorVNSelection(eoMonOp<EOT>& _firstLS, eoMonOp<EOT>& _firstShake, bool _cycle = true) : moVectorVNSelection<EOT>(_firstLS, _firstShake), cycle(_cycle){}
|
||||
|
||||
/**
|
||||
* Return the class id.
|
||||
|
|
@ -52,37 +64,35 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* test if there is still some neighborhood to explore
|
||||
* @return true if there is some neighborhood to explore
|
||||
* test if there is still some heuristics
|
||||
*
|
||||
* @param _solution the current solution
|
||||
* @return true if there is some heuristics
|
||||
*/
|
||||
virtual bool cont(EOT& _solution){
|
||||
return (cycle || (current <= (LSvector.size()-2)));
|
||||
std::cout << "current LS: " << current << std::endl;
|
||||
std::cout << _solution << std::endl;
|
||||
|
||||
return (cycle || (current <= (LSvector.size() - 2)));
|
||||
}
|
||||
|
||||
/**
|
||||
* put the current neighborhood on the first one
|
||||
* put the current heuristics on the first ones
|
||||
*
|
||||
* @param _solution the current solution
|
||||
*/
|
||||
virtual void init(EOT& _solution){
|
||||
current = 0;
|
||||
// std::cout << "current LS: " << _ls->className() << " " << current << std::endl;
|
||||
// std::cout << _solution << std::endl;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* put the current neighborhood on the next one
|
||||
* put the current heuristics on the next ones
|
||||
*
|
||||
* @param _solution the current solution
|
||||
*/
|
||||
virtual void next(EOT& _solution){
|
||||
current = (current + 1) % LSvector.size();
|
||||
std::cout << "current LS: " << current << std::endl;
|
||||
std::cout << _solution << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// boolean to indicate the first heuristics follow the last ones
|
||||
bool cycle;
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -35,16 +35,29 @@
|
|||
|
||||
#include <neighborhood/moVectorVNSelection.h>
|
||||
|
||||
/**
|
||||
* This class is used for the Variable Neighborhood Search explorer inherits from moVectorVNSelection
|
||||
* The search heuristics are saved in vectors
|
||||
* They are given in random order (at each initialization the order is changed)
|
||||
*
|
||||
*/
|
||||
template< class EOT >
|
||||
class moRndVectorVNSelection: public moVectorVNSelection<EOT>{
|
||||
|
||||
class moRndVectorVNSelection: public moVectorVNSelection<EOT>
|
||||
{
|
||||
using moVectorVNSelection<EOT>::LSvector;
|
||||
using moVectorVNSelection<EOT>::shakeVector;
|
||||
// using moVectorVNSelection<EOT>::shakeVector;
|
||||
using moVectorVNSelection<EOT>::current;
|
||||
|
||||
public:
|
||||
|
||||
moRndVectorVNSelection(eoMonOp<EOT>& _firstLS, eoMonOp<EOT>& _firstShake, bool _cycle = true):moVectorVNSelection<EOT>(_firstLS, _firstShake), cycle(_cycle){}
|
||||
/**
|
||||
* Default constructor with first search heuristics
|
||||
*
|
||||
* @param _firstLS first local search
|
||||
* @param _firstShake first heuristic which perturbs the solution
|
||||
* @param _cycle when true, the first heuristics follows the last ones. Otherwise the search stop.
|
||||
*/
|
||||
moRndVectorVNSelection(eoMonOp<EOT>& _firstLS, eoMonOp<EOT>& _firstShake, bool _cycle = true) : moVectorVNSelection<EOT>(_firstLS, _firstShake), cycle(_cycle){}
|
||||
|
||||
/**
|
||||
* Return the class id.
|
||||
|
|
@ -55,15 +68,19 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* test if there is still some neighborhood to explore
|
||||
* @return true if there is some neighborhood to explore
|
||||
* test if there is still some heuristics
|
||||
*
|
||||
* @param _solution the current solution
|
||||
* @return true if there is some heuristics
|
||||
*/
|
||||
virtual bool cont(EOT& _solution){
|
||||
return ( cycle || (currentOrder <= (order.size() - 2)) );
|
||||
}
|
||||
|
||||
/**
|
||||
* put the current neighborhood on the first one
|
||||
* put the current heuristics on the first ones
|
||||
*
|
||||
* @param _solution the current solution
|
||||
*/
|
||||
virtual void init(EOT& _solution) {
|
||||
if(order.size() == 0)
|
||||
|
|
@ -77,7 +94,9 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* put the current neighborhood on the next one
|
||||
* put the current heuristics on the next ones
|
||||
*
|
||||
* @param _solution the current solution
|
||||
*/
|
||||
virtual void next(EOT& _solution){
|
||||
currentOrder = (currentOrder + 1) % order.size();
|
||||
|
|
@ -86,10 +105,13 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
|
||||
// boolean to indicate the first heuristics follow the last ones
|
||||
bool cycle;
|
||||
// index in order vector
|
||||
unsigned int currentOrder;
|
||||
// the index of heuristics in random order
|
||||
std::vector<unsigned int> order;
|
||||
// random generator
|
||||
UF_random_generator<unsigned int> gen;
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,30 +1,30 @@
|
|||
/*
|
||||
<moVariableNeighborhoodSelection.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
<moVariableNeighborhoodSelection.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sebastien Verel, Arnaud Liefooghe, Jeremie Humeau
|
||||
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".
|
||||
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.
|
||||
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
|
||||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#ifndef _moVariableNeighborhoodSelection_h
|
||||
|
|
@ -33,34 +33,41 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
|||
#include <eoOp.h>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* This class is used for the Variable Neighborhood Search explorer
|
||||
* It gives the sequence of search heuristics based on the different "neighborhoods"
|
||||
* The class is built such as the moNeighborhood" with init, next, cont
|
||||
* and two methods to get the heuristics which shake the solution, and which give the local search
|
||||
*
|
||||
*/
|
||||
template< class EOT >
|
||||
class moVariableNeighborhoodSelection
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moVariableNeighborhoodSelection";
|
||||
}
|
||||
/**
|
||||
* Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moVariableNeighborhoodSelection";
|
||||
}
|
||||
|
||||
/**
|
||||
* test if there is still some neighborhood to explore
|
||||
* @return true if there is some neighborhood to explore
|
||||
*/
|
||||
virtual bool cont(EOT& _solution) = 0;
|
||||
/**
|
||||
* test if there is still some search heuristics to use
|
||||
* @return true if there is some neighborhood to explore
|
||||
*/
|
||||
virtual bool cont(EOT& _solution) = 0;
|
||||
|
||||
/**
|
||||
* put the current neighborhood on the first one
|
||||
*/
|
||||
virtual void init(EOT& _solution) = 0;
|
||||
/**
|
||||
* put on the first search heuristics
|
||||
*/
|
||||
virtual void init(EOT& _solution) = 0;
|
||||
|
||||
/**
|
||||
* put the current neighborhood on the next one
|
||||
*/
|
||||
virtual void next(EOT& _solution) = 0;
|
||||
/**
|
||||
* put the next search heuristics
|
||||
*/
|
||||
virtual void next(EOT& _solution) = 0;
|
||||
|
||||
/**
|
||||
* Get the current "shake" operator based on the current neighborhood
|
||||
|
|
|
|||
|
|
@ -33,17 +33,36 @@
|
|||
#include <neighborhood/moVariableNeighborhoodSelection.h>
|
||||
#include <eoOp.h>
|
||||
|
||||
/**
|
||||
* This class is used for the Variable Neighborhood Search explorer inherits from moVariableNeighborhoodSelection
|
||||
* The search heuristics are saved in vectors
|
||||
* The way to croos the vector is not defined here
|
||||
*
|
||||
*/
|
||||
template< class EOT >
|
||||
class moVectorVNSelection: public moVariableNeighborhoodSelection<EOT>{
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default constructor with first search heuristics
|
||||
*
|
||||
* @param _firstLS first local search
|
||||
* @param _firstShake first heuristic which perturbs the solution
|
||||
*/
|
||||
moVectorVNSelection(eoMonOp<EOT>& _firstLS, eoMonOp<EOT>& _firstShake){
|
||||
LSvector.push_back(&_firstLS);
|
||||
shakeVector.push_back(&_firstShake);
|
||||
current=0;
|
||||
|
||||
current = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add some search heuristics
|
||||
*
|
||||
* @param _otherLS the added local search
|
||||
* @param _otherShake the added heuristic which perturbs the solution
|
||||
*/
|
||||
void add(eoMonOp<EOT>& _otherLS, eoMonOp<EOT>& _otherShake){
|
||||
LSvector.push_back(&_otherLS);
|
||||
shakeVector.push_back(&_otherShake);
|
||||
|
|
@ -72,30 +91,15 @@ public:
|
|||
* @return current local search
|
||||
*/
|
||||
virtual eoMonOp<EOT> & getLocalSearch() {
|
||||
std::cout << "getLS : " << current << " sur " << LSvector.size() << std::endl;
|
||||
std::cout << "getLS : ls = " << LSvector[current]->className() << std::endl;
|
||||
return *(LSvector[current]);
|
||||
}
|
||||
|
||||
/**
|
||||
* test if there is still some neighborhood to explore
|
||||
* @return true if there is some neighborhood to explore
|
||||
*/
|
||||
virtual bool cont(EOT& _solution) = 0;
|
||||
|
||||
/**
|
||||
* put the current neighborhood on the first one
|
||||
*/
|
||||
virtual void init(EOT& _solution) = 0;
|
||||
|
||||
/**
|
||||
* put the current neighborhood on the next one
|
||||
*/
|
||||
virtual void next(EOT& _solution) = 0;
|
||||
|
||||
protected:
|
||||
// vector of local searches
|
||||
std::vector<eoMonOp<EOT>* > LSvector;
|
||||
// vector of "shake" heiristics which perturbs the current solution
|
||||
std::vector<eoMonOp<EOT>* > shakeVector;
|
||||
// index of the current search heuristics which is applied
|
||||
unsigned int current;
|
||||
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue