Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/paradiseo/paradiseo
# Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
This commit is contained in:
parent
c876f0b58b
commit
b2b092bdd4
5 changed files with 151 additions and 78 deletions
|
|
@ -45,12 +45,15 @@ template <class EOT, class ValueType>
|
||||||
class moValueStat : public moStat<EOT, double>
|
class moValueStat : public moStat<EOT, double>
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
using moStat< EOT, double>::value;
|
using moStat<EOT, double>::value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
|
*
|
||||||
|
* @param _valueParam the value to report in the statistic
|
||||||
|
* @param _restart if true, the value is initialized at 0 for each init (restart)
|
||||||
*/
|
*/
|
||||||
moValueStat(eoValueParam<ValueType> & _valueParam): moStat<EOT, double>(0, "value"), valueParam(_valueParam) {
|
moValueStat(eoValueParam<ValueType> & _valueParam, bool _restart = false): moStat<EOT, double>(0, "value"), valueParam(_valueParam), restart(_restart) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -58,7 +61,12 @@ public :
|
||||||
* @param _sol a solution
|
* @param _sol a solution
|
||||||
*/
|
*/
|
||||||
virtual void init(EOT & _sol) {
|
virtual void init(EOT & _sol) {
|
||||||
value() = (double) valueParam.value();
|
if (restart)
|
||||||
|
value_start = valueParam.value();
|
||||||
|
else
|
||||||
|
value_start = 0;
|
||||||
|
|
||||||
|
value() = (double) (valueParam.value() - value_start);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -66,7 +74,7 @@ public :
|
||||||
* @param _sol a solution
|
* @param _sol a solution
|
||||||
*/
|
*/
|
||||||
virtual void operator()(EOT & _sol) {
|
virtual void operator()(EOT & _sol) {
|
||||||
value() = (double) valueParam.value() ;
|
value() = (double) (valueParam.value() - value_start);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -79,6 +87,9 @@ public :
|
||||||
private:
|
private:
|
||||||
eoValueParam<ValueType> & valueParam;
|
eoValueParam<ValueType> & valueParam;
|
||||||
|
|
||||||
|
bool restart;
|
||||||
|
ValueType value_start ;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,8 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <utils/eoParam.h>
|
#include <utils/eoParam.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Counts the number of neighbor evaluations actually performed, thus checks first
|
Counts the number of neighbor evaluations actually performed,
|
||||||
if it has to evaluate.. etc.
|
thus checks first if it has to be evaluated.. etc.
|
||||||
*/
|
*/
|
||||||
template<class Neighbor>
|
template<class Neighbor>
|
||||||
class moEvalCounter : public moEval<Neighbor>, public eoValueParam<unsigned long>
|
class moEvalCounter : public moEval<Neighbor>, public eoValueParam<unsigned long>
|
||||||
|
|
|
||||||
|
|
@ -46,12 +46,19 @@
|
||||||
#include <continuator/moMinusOneCounterStat.h>
|
#include <continuator/moMinusOneCounterStat.h>
|
||||||
#include <continuator/moStatFromStat.h>
|
#include <continuator/moStatFromStat.h>
|
||||||
#include <sampling/moSampling.h>
|
#include <sampling/moSampling.h>
|
||||||
|
#include <eval/moEvalCounter.h>
|
||||||
|
#include <eoEvalFuncCounter.h>
|
||||||
|
#include <continuator/moValueStat.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To compute the length and final solution of an adaptive walk:
|
* To compute the length and final solution of an adaptive walk:
|
||||||
* Perform a first improvement Hill-climber based on the neighborhood (adaptive walk),
|
* Perform a first improvement Hill-climber based on the neighborhood (adaptive walk),
|
||||||
* The lengths of HC are collected and the final solution which are local optima
|
* The adaptive walk is repeated several times (defined by a parameter)
|
||||||
* The adaptive walk is repeated several times
|
*
|
||||||
|
* Statistics are:
|
||||||
|
* - the length of the adaptive walk
|
||||||
|
* - the number of neighbor evaluaitons
|
||||||
|
* - the final solution which are local optimum
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
template <class Neighbor>
|
template <class Neighbor>
|
||||||
|
|
@ -64,11 +71,12 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
*
|
||||||
* @param _init initialisation method of the solution
|
* @param _init initialisation method of the solution
|
||||||
* @param _neighborhood neighborhood giving neighbor in random order
|
* @param _neighborhood neighborhood giving neighbor in random order
|
||||||
* @param _fullEval a full evaluation function
|
* @param _fullEval a full evaluation function
|
||||||
* @param _eval an incremental evaluation of neighbors
|
* @param _eval an incremental evaluation of neighbors
|
||||||
* @param _nbAdaptWalk Number of adaptive walks
|
* @param _nbAdaptWalk Number of adaptive walks (minimum value = 2)
|
||||||
*/
|
*/
|
||||||
moAdaptiveWalkSampling(eoInit<EOT> & _init,
|
moAdaptiveWalkSampling(eoInit<EOT> & _init,
|
||||||
moNeighborhood<Neighbor> & _neighborhood,
|
moNeighborhood<Neighbor> & _neighborhood,
|
||||||
|
|
@ -76,15 +84,22 @@ public:
|
||||||
moEval<Neighbor>& _eval,
|
moEval<Neighbor>& _eval,
|
||||||
unsigned int _nbAdaptWalk) :
|
unsigned int _nbAdaptWalk) :
|
||||||
moSampling<Neighbor>(initHC, * new moRandomSearch<Neighbor>(initHC, _fullEval, _nbAdaptWalk), copyStat),
|
moSampling<Neighbor>(initHC, * new moRandomSearch<Neighbor>(initHC, _fullEval, _nbAdaptWalk), copyStat),
|
||||||
copyStat(lengthStat),
|
neighborEvalCount(_eval),
|
||||||
|
nEvalStat(neighborEvalCount, true),
|
||||||
|
copyStat(lengthStat), // copy is used to report the statistic of the first walk
|
||||||
|
copyEvalStat(nEvalStat),
|
||||||
checkpoint(trueCont),
|
checkpoint(trueCont),
|
||||||
hc(_neighborhood, _fullEval, _eval, checkpoint),
|
hc(_neighborhood, _fullEval, neighborEvalCount, checkpoint),
|
||||||
initHC(_init, hc)
|
initHC(_init, hc)
|
||||||
{
|
{
|
||||||
// to count the number of step in the HC
|
// to count the number of step in the HC
|
||||||
checkpoint.add(lengthStat);
|
checkpoint.add(lengthStat);
|
||||||
|
|
||||||
|
// to count the number of evaluations
|
||||||
|
checkpoint.add(nEvalStat);
|
||||||
|
|
||||||
// add the solution into statistics
|
// add the solution into statistics
|
||||||
|
this->add(copyEvalStat);
|
||||||
this->add(solStat);
|
this->add(solStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,6 +112,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/* count the number of evaluations */
|
||||||
|
moEvalCounter<Neighbor> neighborEvalCount;
|
||||||
|
moValueStat<EOT, unsigned long> nEvalStat;
|
||||||
|
moStatFromStat<EOT, double> copyEvalStat;
|
||||||
|
|
||||||
moSolutionStat<EOT> solStat;
|
moSolutionStat<EOT> solStat;
|
||||||
moMinusOneCounterStat<EOT> lengthStat;
|
moMinusOneCounterStat<EOT> lengthStat;
|
||||||
moTrueContinuator<Neighbor> trueCont;
|
moTrueContinuator<Neighbor> trueCont;
|
||||||
|
|
@ -104,6 +124,7 @@ protected:
|
||||||
moCheckpoint<Neighbor> checkpoint;
|
moCheckpoint<Neighbor> checkpoint;
|
||||||
moFirstImprHC<Neighbor> hc;
|
moFirstImprHC<Neighbor> hc;
|
||||||
moLocalSearchInit<Neighbor> initHC;
|
moLocalSearchInit<Neighbor> initHC;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,71 +76,112 @@ template <class Neighbor>
|
||||||
class moNeutralWalkSampling : public moSampling<Neighbor>
|
class moNeutralWalkSampling : public moSampling<Neighbor>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Neighbor::EOT EOT ;
|
typedef typename Neighbor::EOT EOT ;
|
||||||
|
|
||||||
using moSampling<Neighbor>::localSearch;
|
using moSampling<Neighbor>::localSearch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param _initSol the first solution of the walk
|
* @param _initSol the first solution of the walk
|
||||||
* @param _neighborhood neighborhood giving neighbor in random order
|
* @param _neighborhood neighborhood giving neighbor in random order
|
||||||
* @param _fullEval Fitness function, full evaluation function
|
* @param _fullEval Fitness function, full evaluation function
|
||||||
* @param _eval neighbor evaluation, incremental evaluation function
|
* @param _eval neighbor evaluation, incremental evaluation function
|
||||||
* @param _distance component to measure the distance from the initial solution
|
* @param _distance component to measure the distance from the initial solution
|
||||||
* @param _nbStep Number of steps of the random walk
|
* @param _nbStep Number of steps of the random walk
|
||||||
*/
|
*/
|
||||||
moNeutralWalkSampling(EOT & _initSol,
|
moNeutralWalkSampling(EOT & _initSol,
|
||||||
moNeighborhood<Neighbor> & _neighborhood,
|
moNeighborhood<Neighbor> & _neighborhood,
|
||||||
eoEvalFunc<EOT>& _fullEval,
|
eoEvalFunc<EOT>& _fullEval,
|
||||||
moEval<Neighbor>& _eval,
|
moEval<Neighbor>& _eval,
|
||||||
eoDistance<EOT> & _distance,
|
eoDistance<EOT> & _distance,
|
||||||
unsigned int _nbStep) :
|
unsigned int _nbStep) :
|
||||||
moSampling<Neighbor>(init, * new moRandomNeutralWalk<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep), solutionStat),
|
moSampling<Neighbor>(init, * new moRandomNeutralWalk<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep), solutionStat),
|
||||||
init(_initSol),
|
init(_initSol),
|
||||||
distStat(_distance, _initSol),
|
distStat(_distance, _initSol),
|
||||||
neighborhoodStat(_neighborhood, _eval),
|
neighborhoodStat(_neighborhood, _eval),
|
||||||
minStat(neighborhoodStat),
|
minStat(neighborhoodStat),
|
||||||
averageStat(neighborhoodStat),
|
averageStat(neighborhoodStat),
|
||||||
stdStat(neighborhoodStat),
|
stdStat(neighborhoodStat),
|
||||||
maxStat(neighborhoodStat),
|
maxStat(neighborhoodStat),
|
||||||
nbSupStat(neighborhoodStat),
|
nbSupStat(neighborhoodStat),
|
||||||
nbInfStat(neighborhoodStat),
|
nbInfStat(neighborhoodStat),
|
||||||
sizeStat(neighborhoodStat),
|
sizeStat(neighborhoodStat),
|
||||||
ndStat(neighborhoodStat)
|
ndStat(neighborhoodStat)
|
||||||
{
|
{
|
||||||
this->add(neighborhoodStat, false);
|
this->add(neighborhoodStat, false);
|
||||||
this->add(distStat);
|
this->add(distStat);
|
||||||
this->add(minStat);
|
this->add(minStat);
|
||||||
this->add(averageStat);
|
this->add(averageStat);
|
||||||
this->add(stdStat);
|
this->add(stdStat);
|
||||||
this->add(maxStat);
|
this->add(maxStat);
|
||||||
this->add(sizeStat);
|
this->add(sizeStat);
|
||||||
this->add(nbInfStat);
|
this->add(nbInfStat);
|
||||||
this->add(ndStat);
|
this->add(ndStat);
|
||||||
this->add(nbSupStat);
|
this->add(nbSupStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default destructor
|
* Constructor
|
||||||
*/
|
* @param _initSol the first solution of the walk
|
||||||
~moNeutralWalkSampling() {
|
* @param _neighborhood neighborhood giving neighbor in random order
|
||||||
// delete the pointer on the local search which has been constructed in the constructor
|
* @param _fullEval Fitness function, full evaluation function
|
||||||
delete localSearch;
|
* @param _eval neighbor evaluation, incremental evaluation function
|
||||||
}
|
* @param _distance component to measure the distance from the initial solution
|
||||||
|
* @param _nbStep Number of steps of the random walk
|
||||||
|
*/
|
||||||
|
moNeutralWalkSampling(eoInit<EOT> & _init,
|
||||||
|
moNeighborhood<Neighbor> & _neighborhood,
|
||||||
|
eoEvalFunc<EOT>& _fullEval,
|
||||||
|
moEval<Neighbor>& _eval,
|
||||||
|
unsigned int _nbStep) :
|
||||||
|
moSampling<Neighbor>(_init, * new moRandomNeutralWalk<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep), solutionStat),
|
||||||
|
init(initialSol),
|
||||||
|
distStat(dummyDistance, initialSol),
|
||||||
|
neighborhoodStat(_neighborhood, _eval),
|
||||||
|
minStat(neighborhoodStat),
|
||||||
|
averageStat(neighborhoodStat),
|
||||||
|
stdStat(neighborhoodStat),
|
||||||
|
maxStat(neighborhoodStat),
|
||||||
|
nbSupStat(neighborhoodStat),
|
||||||
|
nbInfStat(neighborhoodStat),
|
||||||
|
sizeStat(neighborhoodStat),
|
||||||
|
ndStat(neighborhoodStat)
|
||||||
|
{
|
||||||
|
this->add(neighborhoodStat, false);
|
||||||
|
// this->add(distStat);
|
||||||
|
this->add(minStat);
|
||||||
|
this->add(averageStat);
|
||||||
|
this->add(stdStat);
|
||||||
|
this->add(maxStat);
|
||||||
|
this->add(sizeStat);
|
||||||
|
this->add(nbInfStat);
|
||||||
|
this->add(ndStat);
|
||||||
|
this->add(nbSupStat);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* default destructor
|
||||||
|
*/
|
||||||
|
~moNeutralWalkSampling() {
|
||||||
|
// delete the pointer on the local search which has been constructed in the constructor
|
||||||
|
delete localSearch;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
moSolInit<EOT> init;
|
EOT initialSol;
|
||||||
moSolutionStat<EOT> solutionStat;
|
eoHammingDistance<EOT> dummyDistance;
|
||||||
moDistanceStat<EOT> distStat;
|
moSolInit<EOT> init;
|
||||||
moNeighborhoodStat< Neighbor > neighborhoodStat;
|
moSolutionStat<EOT> solutionStat;
|
||||||
moMinNeighborStat< Neighbor > minStat;
|
moDistanceStat<EOT> distStat;
|
||||||
moAverageFitnessNeighborStat< Neighbor > averageStat;
|
moNeighborhoodStat< Neighbor > neighborhoodStat;
|
||||||
moStdFitnessNeighborStat< Neighbor > stdStat;
|
moMinNeighborStat< Neighbor > minStat;
|
||||||
moMaxNeighborStat< Neighbor > maxStat;
|
moAverageFitnessNeighborStat< Neighbor > averageStat;
|
||||||
moNbSupNeighborStat< Neighbor > nbSupStat;
|
moStdFitnessNeighborStat< Neighbor > stdStat;
|
||||||
moNbInfNeighborStat< Neighbor > nbInfStat;
|
moMaxNeighborStat< Neighbor > maxStat;
|
||||||
moSizeNeighborStat< Neighbor > sizeStat;
|
moNbSupNeighborStat< Neighbor > nbSupStat;
|
||||||
moNeutralDegreeNeighborStat< Neighbor > ndStat;
|
moNbInfNeighborStat< Neighbor > nbInfStat;
|
||||||
|
moSizeNeighborStat< Neighbor > sizeStat;
|
||||||
|
moNeutralDegreeNeighborStat< Neighbor > ndStat;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,12 +45,12 @@ public:
|
||||||
*
|
*
|
||||||
* @param _fileData the file name which contains the instance of QAP from QAPlib
|
* @param _fileData the file name which contains the instance of QAP from QAPlib
|
||||||
*/
|
*/
|
||||||
QAPeval(string & _fileData) {
|
QAPeval(std::string _fileData) {
|
||||||
fstream file(_fileData.c_str(), ios::in);
|
std::fstream file(_fileData.c_str(), std::ios::in);
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
string str = "QAPeval: Could not open file [" + _fileData + "]." ;
|
std::string str = "QAPeval: Could not open file [" + _fileData + "]." ;
|
||||||
throw runtime_error(str);
|
throw std::runtime_error(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned i, j;
|
unsigned i, j;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue