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

This commit is contained in:
boufaras 2010-11-02 10:42:40 +00:00
commit 261fb95ed1

View file

@ -30,7 +30,7 @@
ParadisEO WebSite : http://paradiseo.gforge.inria.fr ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr Contact: paradiseo-help@lists.gforge.inria.fr
*/ */
#ifndef _moLocalSearch_h #ifndef _moLocalSearch_h
#define _moLocalSearch_h #define _moLocalSearch_h
@ -45,12 +45,11 @@
* the main algorithm of the local search * the main algorithm of the local search
*/ */
template<class Neighbor> template<class Neighbor>
class moLocalSearch: public eoMonOp<typename Neighbor::EOT> class moLocalSearch: public eoMonOp<typename Neighbor::EOT> {
{
public: public:
typedef moNeighborhood<Neighbor> Neighborhood; typedef moNeighborhood<Neighbor> Neighborhood;
typedef moNeighborhoodExplorer<Neighbor> NeighborhoodExplorer; typedef moNeighborhoodExplorer<Neighbor> NeighborhoodExplorer;
typedef typename Neighbor::EOT EOT ; typedef typename Neighbor::EOT EOT;
/** /**
* Constructor of a moLocalSearch * Constructor of a moLocalSearch
@ -58,13 +57,17 @@ public:
* @param _cont an external continuator (can be a checkpoint!) * @param _cont an external continuator (can be a checkpoint!)
* @param _fullEval a full evaluation function * @param _fullEval a full evaluation function
*/ */
moLocalSearch(NeighborhoodExplorer& _searchExpl, moContinuator<Neighbor> & _cont, eoEvalFunc<EOT>& _fullEval) : searchExplorer(_searchExpl), cont(&_cont), fullEval(_fullEval) { } ; moLocalSearch(NeighborhoodExplorer& _searchExpl,
moContinuator<Neighbor> & _cont, eoEvalFunc<EOT>& _fullEval) :
searchExplorer(_searchExpl), cont(&_cont), fullEval(_fullEval) {
}
;
/** /**
* Run the local search on a solution * Run the local search on a solution
* @param _solution the related solution * @param _solution the related solution
*/ */
virtual bool operator() (EOT & _solution) { virtual bool operator()(EOT & _solution) {
if (_solution.invalid()) if (_solution.invalid())
fullEval(_solution); fullEval(_solution);
@ -76,7 +79,6 @@ public:
cont->init(_solution); cont->init(_solution);
bool b; bool b;
do { do {
// explore the neighborhood of the solution // explore the neighborhood of the solution
searchExplorer(_solution); searchExplorer(_solution);
@ -84,29 +86,28 @@ public:
if (searchExplorer.accept(_solution)) { if (searchExplorer.accept(_solution)) {
searchExplorer.move(_solution); searchExplorer.move(_solution);
searchExplorer.moveApplied(true); searchExplorer.moveApplied(true);
} } else
else
searchExplorer.moveApplied(false); searchExplorer.moveApplied(false);
// update the parameter of the search (for ex. Temperature of the SA) // update the parameter of the search (for ex. Temperature of the SA)
searchExplorer.updateParam(_solution); searchExplorer.updateParam(_solution);
b=(*cont)(_solution); b = (*cont)(_solution);
} while (b && searchExplorer.isContinue(_solution)); }while (b && searchExplorer.isContinue(_solution));
searchExplorer.terminate(_solution); searchExplorer.terminate(_solution);
cont->lastCall(_solution); cont->lastCall(_solution);
return true; return true;
}; }
;
/** /**
* Set an external continuator * Set an external continuator
* @param _cont the external continuator * @param _cont the external continuator
*/ */
void setContinuator(moContinuator<Neighbor> & _cont) { void setContinuator(moContinuator<Neighbor> & _cont) {
cont = &_cont ; cont = &_cont;
} }
/** /**
@ -116,15 +117,15 @@ public:
* @return the external continuator * @return the external continuator
*/ */
moContinuator<Neighbor>* getContinuator() const { moContinuator<Neighbor>* getContinuator() const {
return cont ; return cont;
} }
protected: protected:
// make the exploration of the neighborhood according to a local search heuristic // make the exploration of the neighborhood according to a local search heuristic
moNeighborhoodExplorer<Neighbor>& searchExplorer ; moNeighborhoodExplorer<Neighbor>& searchExplorer;
// external continuator // external continuator
moContinuator<Neighbor> * cont ; moContinuator<Neighbor> * cont;
//full evaluation function //full evaluation function
eoEvalFunc<EOT>& fullEval; eoEvalFunc<EOT>& fullEval;