Added a field for saving the fitness of the solution (useful for monitoring)
This commit is contained in:
parent
b5f15a4a3d
commit
6548a0e223
1 changed files with 108 additions and 91 deletions
|
|
@ -57,11 +57,9 @@ 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,
|
moLocalSearch(NeighborhoodExplorer& _searchExpl, moContinuator<Neighbor> & _cont, eoEvalFunc<EOT>& _fullEval)
|
||||||
moContinuator<Neighbor> & _cont, eoEvalFunc<EOT>& _fullEval) :
|
: searchExplorer(_searchExpl), cont(&_cont), fullEval(_fullEval), currentSolutionFitness(0)
|
||||||
searchExplorer(_searchExpl), cont(&_cont), fullEval(_fullEval) {
|
{ }
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the local search on a solution
|
* Run the local search on a solution
|
||||||
|
|
@ -79,7 +77,11 @@ public:
|
||||||
cont->init(_solution);
|
cont->init(_solution);
|
||||||
|
|
||||||
bool b;
|
bool b;
|
||||||
do {
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
currentSolutionFitness = _solution.fitness();
|
||||||
|
|
||||||
// explore the neighborhood of the solution
|
// explore the neighborhood of the solution
|
||||||
searchExplorer(_solution);
|
searchExplorer(_solution);
|
||||||
// if a solution in the neighborhood can be accepted
|
// if a solution in the neighborhood can be accepted
|
||||||
|
|
@ -93,7 +95,8 @@ public:
|
||||||
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);
|
||||||
|
|
||||||
|
|
@ -101,7 +104,6 @@ public:
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set an external continuator
|
* Set an external continuator
|
||||||
|
|
@ -131,7 +133,16 @@ public:
|
||||||
return searchExplorer;
|
return searchExplorer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Useful for monitoring with anb eoGetterUpdater
|
||||||
|
* @return the fitness of the last computed solution
|
||||||
|
*/
|
||||||
|
double getCurrentSolutionFitness() const {
|
||||||
|
return currentSolutionFitness;
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
|
@ -140,6 +151,12 @@ protected:
|
||||||
|
|
||||||
//full evaluation function
|
//full evaluation function
|
||||||
eoEvalFunc<EOT>& fullEval;
|
eoEvalFunc<EOT>& fullEval;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// fitness of the last computed solution
|
||||||
|
double currentSolutionFitness;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue