git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1915 331e1502-861f-0410-8da2-ba01fb791d7f

This commit is contained in:
jhumeau 2010-08-26 09:16:29 +00:00
commit b97a685fd0

View file

@ -31,22 +31,18 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#define _moVNSexplorer_h #define _moVNSexplorer_h
#include <explorer/moNeighborhoodExplorer.h> #include <explorer/moNeighborhoodExplorer.h>
#include <comparator/moNeighborComparator.h> #include <neighborhood/moVariableNeighborhoodSelection.h>
#include <comparator/moSolNeighborComparator.h> #include <eoOp.h>
/** /**
* Explorer for Variiable Neighborhood Search * Explorer for Variiable Neighborhood Search
*/ */
template< class EOT > template< class Neighbor>
class moVNSexplorer : public moNeighborhoodExplorer< moNeighborhood< moNeighbor<EOT, typename EOT::Fitness> > > class moVNSexplorer : public moNeighborhoodExplorer< Neighbor >
{ {
public: public:
typedef typename EOT::Fitness Fitness ;
typedef moNeighbor<EOT, Fitness> Neighbor ;
typedef moNeighborhood<Neighbor> Neighborhood ;
using moNeighborhoodExplorer<Neighborhood>::neighborhood; typedef typename Neighbor::EOT EOT;
using moNeighborhoodExplorer<Neighborhood>::eval;
/** /**
* Constructor * Constructor
@ -55,8 +51,11 @@ public:
* @param _neighborComparator a neighbor comparator * @param _neighborComparator a neighbor comparator
* @param _solNeighborComparator solution vs 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) { moVNSexplorer(
} moVariableNeighborhoodSelection<EOT> & _selection,
moAcceptanceCriterion<Neighbor>& _acceptCrit):
moNeighborhoodExplorer<Neighbor>(), selection(_selection), shake(NULL), ls(NULL), acceptCrit(_acceptCrit), stop(false)
{}
/** /**
* Destructor * Destructor
@ -67,23 +66,37 @@ public:
/** /**
* initParam: NOTHING TO DO * initParam: NOTHING TO DO
*/ */
virtual void initParam(EOT & solution) {}; virtual void initParam(EOT & _solution) {
_selection.init(_solution, *shake, *ls);
};
/** /**
* updateParam: NOTHING TO DO * updateParam: NOTHING TO DO
*/ */
virtual void updateParam(EOT & solution) {}; virtual void updateParam(EOT & _solution) {
if ((*this).moveApplied()) {
_selection.init(_solution, *shake, *ls);
}
else if (_selection.cont(_solution, *shake, *ls)){
_selection.next(_solution, *shake, *ls);
}
else
stop=true;
};
/** /**
* terminate: NOTHING TO DO * terminate: NOTHING TO DO
*/ */
virtual void terminate(EOT & solution) {}; virtual void terminate(EOT & _solution) {};
/** /**
* Explore the neighborhood of a solution * Explore the neighborhood of a solution
* @param _solution * @param _solution
*/ */
virtual void operator()(EOT & _solution) { virtual void operator()(EOT & _solution) {
current=_solution;
(*shake)(current);
(*ls)(current);
}; };
/** /**
@ -92,7 +105,7 @@ public:
* @return true if an ameliorated neighbor was be found * @return true if an ameliorated neighbor was be found
*/ */
virtual bool isContinue(EOT & _solution) { virtual bool isContinue(EOT & _solution) {
return isAccept ; return !stop;
}; };
/** /**
@ -100,10 +113,7 @@ public:
* @param _solution the solution to move * @param _solution the solution to move
*/ */
virtual void move(EOT & _solution) { virtual void move(EOT & _solution) {
//move the solution _solution=current;
(*best).move(_solution);
//update its fitness
_solution.fitness((*best).fitness());
}; };
/** /**
@ -112,6 +122,7 @@ public:
* @return true if the best neighbor ameliorate the fitness * @return true if the best neighbor ameliorate the fitness
*/ */
virtual bool accept(EOT & _solution) { virtual bool accept(EOT & _solution) {
return acceptCrit(_solution, current);
}; };
/** /**
@ -123,9 +134,13 @@ public:
} }
private: private:
// comparator betwenn solution and neighbor or between neighbors moVariableNeighborhoodSelection<EOT>& selection;
moNeighborComparator<Neighbor>& neighborComparator; eoMonOp<EOT>* ls;
moSolNeighborComparator<Neighbor>& solNeighborComparator; eoMonOp<EOT>* shake;
moAcceptanceCriterion<Neighbor>& acceptCrit;
bool stop;
EOT current;
}; };