VNS modif et template de moLocalSearch Modifié
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1730 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
0586fc4e2e
commit
bd92e945f8
6 changed files with 82 additions and 29 deletions
|
|
@ -50,11 +50,10 @@ public:
|
||||||
typedef typename NeighborhoodExplorer::EOT EOT ;
|
typedef typename NeighborhoodExplorer::EOT EOT ;
|
||||||
typedef typename NeighborhoodExplorer::Neighborhood Neighborhood ;
|
typedef typename NeighborhoodExplorer::Neighborhood Neighborhood ;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of a moLocalSearch needs a NeighborhooExplorer and a Continuator
|
* Constructor of a moLocalSearch needs a NeighborhooExplorer and a Continuator
|
||||||
*/
|
*/
|
||||||
moLocalSearch(NeighborhoodExplorer& _searchExpl, moContinuator<Neighborhood> & _continuator, eoEvalFunc<EOT>& _fullEval) : searchExplorer(_searchExpl), continuator(_continuator), fullEval(_fullEval) { } ;
|
moLocalSearch(moNeighborhoodExplorer<Neighborhood>& _searchExpl, moContinuator<Neighborhood> & _continuator, eoEvalFunc<EOT>& _fullEval) : searchExplorer(_searchExpl), continuator(_continuator), fullEval(_fullEval) { } ;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the local search on a solution
|
* Run the local search on a solution
|
||||||
|
|
@ -99,7 +98,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// make the exploration of the neighborhood according to a local search heuristic
|
// make the exploration of the neighborhood according to a local search heuristic
|
||||||
NeighborhoodExplorer& searchExplorer ;
|
moNeighborhoodExplorer<Neighborhood>& searchExplorer ;
|
||||||
|
|
||||||
// external continuator
|
// external continuator
|
||||||
moContinuator<Neighborhood>& continuator ;
|
moContinuator<Neighborhood>& continuator ;
|
||||||
|
|
|
||||||
|
|
@ -35,23 +35,21 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
/**
|
/**
|
||||||
* A variable Neighborhood Search (VNS) in the forward manner
|
* A variable Neighborhood Search (VNS) in the forward manner
|
||||||
*/
|
*/
|
||||||
template< class Neighbor >
|
template< class EOT, class Fitness >
|
||||||
class moForwardVariableNeighborhood : public moVariableNeighborhood<Neighbor>
|
class moForwardVariableNeighborhood : public moVariableNeighborhood<EOT, Fitness>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* Define type of a solution corresponding to Neighbor
|
|
||||||
*/
|
|
||||||
typedef typename Neighbor::EOT EOT;
|
|
||||||
|
|
||||||
using moVariableNeighborhood::currentNH;
|
typedef moNeighbor<EOT, Fitness> Neighbor;
|
||||||
using moVariableNeighborhood::neighborhoodVector;
|
|
||||||
|
using moVariableNeighborhood<EOT, Fitness>::currentNH;
|
||||||
|
using moVariableNeighborhood<EOT, Fitness>::neighborhoodVector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construction of at least one neighborhood
|
* Construction of at least one neighborhood
|
||||||
* @param _firstNH first neighborhood in the vector
|
* @param _firstNH first neighborhood in the vector
|
||||||
*/
|
*/
|
||||||
moForwardVariableNeighborhood(moNeighborhood<Neighbor>& _firstNH) : moVariableNeighborhood<Neighbor>(_firstNH) { }
|
moForwardVariableNeighborhood(moNeighborhood<Neighbor>& _firstNH) : moVariableNeighborhood<EOT, Fitness>(_firstNH) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the class id.
|
* Return the class id.
|
||||||
|
|
|
||||||
|
|
@ -31,25 +31,25 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#define _moVariableNeighborhood_h
|
#define _moVariableNeighborhood_h
|
||||||
|
|
||||||
#include <neighborhood/moNeighborhood.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)
|
* A vector of neighborhood for the Variable Neighborhood Search (VNS)
|
||||||
*/
|
*/
|
||||||
template< class Neighbor >
|
template< class EOT, class Fitness >
|
||||||
class moVariableNeighborhood : public moNeighborhood<Neighbor>
|
class moVariableNeighborhood : public moNeighborhood<moNeighbor<EOT, Fitness> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* Define type of a solution corresponding to Neighbor
|
|
||||||
*/
|
|
||||||
typedef typename Neighbor::EOT EOT;
|
|
||||||
|
|
||||||
|
typedef moNeighbor<EOT, Fitness> Neighbor;
|
||||||
/**
|
/**
|
||||||
* Construction of at least one neighborhood
|
* Construction of at least one neighborhood
|
||||||
* @param _firstNH first neighborhood in the vector
|
* @param _firstNH first neighborhood in the vector
|
||||||
*/
|
*/
|
||||||
moVariableNeighborhood(moNeighborhood<Neighbor>& _firstNH) {
|
moVariableNeighborhood(moNeighborhood<Neighbor>& _firstNH) {
|
||||||
neighborhoodVector.push_back(_firstNH);
|
neighborhoodVector.push_back(&_firstNH);
|
||||||
// the current neighborhood
|
// the current neighborhood
|
||||||
currentNH = 0;
|
currentNH = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +58,7 @@ public:
|
||||||
* @return if the current neighborhood is random
|
* @return if the current neighborhood is random
|
||||||
*/
|
*/
|
||||||
virtual bool isRandom() {
|
virtual bool isRandom() {
|
||||||
return neighborhoodVector[currentNH].isRandom();
|
return neighborhoodVector[currentNH]->isRandom();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -67,7 +67,7 @@ public:
|
||||||
* @return if _solution has a Neighbor in the current neighborhood
|
* @return if _solution has a Neighbor in the current neighborhood
|
||||||
*/
|
*/
|
||||||
virtual bool hasNeighbor(EOT & _solution) {
|
virtual bool hasNeighbor(EOT & _solution) {
|
||||||
return neighborhoodVector[currentNH].hasNeighbor(_solution);
|
return neighborhoodVector[currentNH]->hasNeighbor(_solution);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -76,7 +76,7 @@ public:
|
||||||
* @param _current the first neighbor in the current neighborhood
|
* @param _current the first neighbor in the current neighborhood
|
||||||
*/
|
*/
|
||||||
virtual void init(EOT & _solution, Neighbor & _current) {
|
virtual void init(EOT & _solution, Neighbor & _current) {
|
||||||
neighborhoodVector[currentNH].init(_solution, _current);
|
neighborhoodVector[currentNH]->init(_solution, _current);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -85,7 +85,7 @@ public:
|
||||||
* @param _current the next neighbor in the current neighborhood
|
* @param _current the next neighbor in the current neighborhood
|
||||||
*/
|
*/
|
||||||
virtual void next(EOT & _solution, Neighbor & _current) {
|
virtual void next(EOT & _solution, Neighbor & _current) {
|
||||||
neighborhoodVector[currentNH].next(_solution, _current);
|
neighborhoodVector[currentNH]->next(_solution, _current);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -94,7 +94,7 @@ public:
|
||||||
* @return if there is still a neighbor not explored in the current neighborhood
|
* @return if there is still a neighbor not explored in the current neighborhood
|
||||||
*/
|
*/
|
||||||
virtual bool cont(EOT & _solution) {
|
virtual bool cont(EOT & _solution) {
|
||||||
neighborhoodVector[currentNH].cont(_solution);
|
return neighborhoodVector[currentNH]->cont(_solution);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -110,7 +110,7 @@ public:
|
||||||
* @param _nh the neighborhood to add at the end of the vector of neighborhood
|
* @param _nh the neighborhood to add at the end of the vector of neighborhood
|
||||||
*/
|
*/
|
||||||
virtual void add(moNeighborhood<Neighbor>& _nh) {
|
virtual void add(moNeighborhood<Neighbor>& _nh) {
|
||||||
neighborhoodVector.push_back(_nh);
|
neighborhoodVector.push_back(&_nh);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -129,9 +129,9 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual void nextNeighborhood() = 0;
|
virtual void nextNeighborhood() = 0;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
// the vector of neighborhoods
|
// the vector of neighborhoods
|
||||||
std::vector<moNeighborhood<Neighbor>& > neighborhoodVector;
|
std::vector<moNeighborhood<Neighbor>* > neighborhoodVector;
|
||||||
// the index of the current neighborhood
|
// the index of the current neighborhood
|
||||||
unsigned int currentNH;
|
unsigned int currentNH;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ SET (TEST_LIST
|
||||||
t-moMetropolisHastingExplorer
|
t-moMetropolisHastingExplorer
|
||||||
t-moRandomNeutralWalkExplorer
|
t-moRandomNeutralWalkExplorer
|
||||||
t-moTSExplorer
|
t-moTSExplorer
|
||||||
|
t-moForwardVariableNeighborhood
|
||||||
)
|
)
|
||||||
|
|
||||||
FOREACH (test ${TEST_LIST})
|
FOREACH (test ${TEST_LIST})
|
||||||
|
|
|
||||||
55
trunk/paradiseo-mo/test/t-moForwardVariableNeighborhood.cpp
Normal file
55
trunk/paradiseo-mo/test/t-moForwardVariableNeighborhood.cpp
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
<t-moForwardVariableNeighborhood.cpp>
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
#include <neighborhood/moRndWithoutReplNeighborhood.h>
|
||||||
|
#include <neighborhood/moForwardVariableNeighborhood.h>
|
||||||
|
#include "moTestClass.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
|
||||||
|
std::cout << "[t-moForwardVariableNeighborhood] => START" << std::endl;
|
||||||
|
|
||||||
|
moRndWithoutReplNeighborhood<bitNeighbor> rndNH(8);
|
||||||
|
moOrderNeighborhood<moIndexNeighbor<eoBit<eoMinimizingFitness>, eoMinimizingFitness> > orderNH(8);
|
||||||
|
|
||||||
|
|
||||||
|
//moForwardVariableNeighborhood<eoBit<eoMinimizingFitness>, eoMinimizingFitness> test(orderNH);
|
||||||
|
|
||||||
|
|
||||||
|
std::cout << "[t-moForwardVariableNeighborhood] => OK" << std::endl;
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -13,7 +13,7 @@ ADD_EXECUTABLE(testMetropolisHasting testMetropolisHasting.cpp)
|
||||||
#ADD_EXECUTABLE(testWithMove testWithMove.cpp)
|
#ADD_EXECUTABLE(testWithMove testWithMove.cpp)
|
||||||
ADD_EXECUTABLE(testSimpleTS testSimpleTS.cpp)
|
ADD_EXECUTABLE(testSimpleTS testSimpleTS.cpp)
|
||||||
ADD_EXECUTABLE(testRandomNeutralWalk testRandomNeutralWalk.cpp)
|
ADD_EXECUTABLE(testRandomNeutralWalk testRandomNeutralWalk.cpp)
|
||||||
ADD_EXECUTABLE(testILS testILS.cpp)
|
#ADD_EXECUTABLE(testILS testILS.cpp)
|
||||||
ADD_EXECUTABLE(testSimulatedAnnealing testSimulatedAnnealing.cpp)
|
ADD_EXECUTABLE(testSimulatedAnnealing testSimulatedAnnealing.cpp)
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES(testSimpleHC eoutils ga eo)
|
TARGET_LINK_LIBRARIES(testSimpleHC eoutils ga eo)
|
||||||
|
|
@ -25,7 +25,7 @@ TARGET_LINK_LIBRARIES(testMetropolisHasting eoutils ga eo)
|
||||||
#TARGET_LINK_LIBRARIES(testWithMove eoutils ga eo)
|
#TARGET_LINK_LIBRARIES(testWithMove eoutils ga eo)
|
||||||
TARGET_LINK_LIBRARIES(testSimpleTS eoutils ga eo)
|
TARGET_LINK_LIBRARIES(testSimpleTS eoutils ga eo)
|
||||||
TARGET_LINK_LIBRARIES(testRandomNeutralWalk eoutils ga eo)
|
TARGET_LINK_LIBRARIES(testRandomNeutralWalk eoutils ga eo)
|
||||||
TARGET_LINK_LIBRARIES(testILS eoutils ga eo)
|
#TARGET_LINK_LIBRARIES(testILS eoutils ga eo)
|
||||||
TARGET_LINK_LIBRARIES(testSimulatedAnnealing eoutils ga eo)
|
TARGET_LINK_LIBRARIES(testSimulatedAnnealing eoutils ga eo)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue