passage du code dans astyle

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1713 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-03-24 10:25:33 +00:00
commit dd66b5e4bd
105 changed files with 3950 additions and 3924 deletions

View file

@ -49,7 +49,7 @@ public:
typedef NHE NeighborhoodExplorer ; typedef NHE NeighborhoodExplorer ;
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
@ -61,40 +61,40 @@ public:
* @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);
// initialization of the parameter of the search (for example fill empty the tabu list) // initialization of the parameter of the search (for example fill empty the tabu list)
searchExplorer.initParam(_solution); searchExplorer.initParam(_solution);
// initialization of the external continuator (for example the time, or the number of generations) // initialization of the external continuator (for example the time, or the number of generations)
continuator.init(_solution); continuator.init(_solution);
bool b=continuator(_solution); bool b=continuator(_solution);
do { do {
// 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
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=continuator(_solution); b=continuator(_solution);
} while (b && searchExplorer.isContinue(_solution)); } while (b && searchExplorer.isContinue(_solution));
searchExplorer.terminate(_solution); searchExplorer.terminate(_solution);
continuator.lastCall(_solution); continuator.lastCall(_solution);
return true; return true;
}; };
private: private:

View file

@ -65,7 +65,7 @@ public:
* @return the class name as a std::string * @return the class name as a std::string
*/ */
virtual std::string className() const { virtual std::string className() const {
return "moComparator"; return "moComparator";
} }
}; };

View file

@ -57,7 +57,7 @@ public:
* @return true if the neighbor2 is better than neighbor1 * @return true if the neighbor2 is better than neighbor1
*/ */
virtual bool operator()(const Neighbor& _neighbor1, const Neighbor& _neighbor2) { virtual bool operator()(const Neighbor& _neighbor1, const Neighbor& _neighbor2) {
return (_neighbor1.fitness() < _neighbor2.fitness()); return (_neighbor1.fitness() < _neighbor2.fitness());
} }
/** /**
@ -67,7 +67,7 @@ public:
* @return true if the neighbor2 is equal to neighbor1 * @return true if the neighbor2 is equal to neighbor1
*/ */
virtual bool equals(const Neighbor& _neighbor1, const Neighbor& _neighbor2) { virtual bool equals(const Neighbor& _neighbor1, const Neighbor& _neighbor2) {
return (_neighbor1.fitness() == _neighbor2.fitness()); return (_neighbor1.fitness() == _neighbor2.fitness());
} }
/** /**
@ -75,7 +75,7 @@ public:
* @return the class name as a std::string * @return the class name as a std::string
*/ */
virtual std::string className() const { virtual std::string className() const {
return "moNeighborComparator"; return "moNeighborComparator";
} }
}; };

View file

@ -49,7 +49,7 @@ template< class Neighbor >
class moSolNeighborComparator : public moComparator<typename Neighbor::EOT, Neighbor> class moSolNeighborComparator : public moComparator<typename Neighbor::EOT, Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT ; typedef typename Neighbor::EOT EOT ;
/** /**
* Compare two neighbors * Compare two neighbors
@ -58,7 +58,7 @@ public:
* @return true if the neighbor is better than sol * @return true if the neighbor is better than sol
*/ */
virtual bool operator()(const EOT& _sol, const Neighbor& _neighbor) { virtual bool operator()(const EOT& _sol, const Neighbor& _neighbor) {
return (_sol.fitness() < _neighbor.fitness()); return (_sol.fitness() < _neighbor.fitness());
} }
/** /**
@ -68,7 +68,7 @@ public:
* @return true if the neighbor is equal to the solution * @return true if the neighbor is equal to the solution
*/ */
virtual bool equals(const EOT& _sol, const Neighbor& _neighbor) { virtual bool equals(const EOT& _sol, const Neighbor& _neighbor) {
return (_sol.fitness() == _neighbor.fitness()); return (_sol.fitness() == _neighbor.fitness());
} }
/** /**
@ -76,7 +76,7 @@ public:
* @return the class name as a std::string * @return the class name as a std::string
*/ */
virtual std::string className() const { virtual std::string className() const {
return "moSolNeighborComparator"; return "moSolNeighborComparator";
} }
}; };

View file

@ -55,8 +55,8 @@ public :
* @param _cont a continuator * @param _cont a continuator
* @param _interval frequency to compute statistical operators * @param _interval frequency to compute statistical operators
*/ */
moCheckpoint(moContinuator<Neighborhood>& _cont, unsigned int _interval=1):interval(_interval), counter(0){ moCheckpoint(moContinuator<Neighborhood>& _cont, unsigned int _interval=1):interval(_interval), counter(0) {
continuators.push_back(&_cont); continuators.push_back(&_cont);
} }
/** /**
@ -64,7 +64,7 @@ public :
* @param _cont a continuator * @param _cont a continuator
*/ */
void add(moContinuator<Neighborhood>& _cont) { void add(moContinuator<Neighborhood>& _cont) {
continuators.push_back(&_cont); continuators.push_back(&_cont);
} }
/** /**
@ -72,7 +72,7 @@ public :
* @param _stat a statistic operator * @param _stat a statistic operator
*/ */
void add(moStatBase<EOT>& _stat) { void add(moStatBase<EOT>& _stat) {
stats.push_back(&_stat); stats.push_back(&_stat);
} }
/** /**
@ -80,7 +80,7 @@ public :
* @param _mon a monitor * @param _mon a monitor
*/ */
void add(eoMonitor& _mon) { void add(eoMonitor& _mon) {
monitors.push_back(&_mon); monitors.push_back(&_mon);
} }
/** /**
@ -88,7 +88,7 @@ public :
* @param _upd an updater * @param _upd an updater
*/ */
void add(eoUpdater& _upd) { void add(eoUpdater& _upd) {
updaters.push_back(&_upd); updaters.push_back(&_upd);
} }
/** /**
@ -96,60 +96,60 @@ public :
* @param _sol the corresponding solution * @param _sol the corresponding solution
*/ */
virtual void init(EOT& _sol) { virtual void init(EOT& _sol) {
for(unsigned i = 0; i < continuators.size(); ++i) for (unsigned i = 0; i < continuators.size(); ++i)
continuators[i]->init(_sol); continuators[i]->init(_sol);
} }
/** /**
* @return class name * @return class name
*/ */
virtual std::string className(void) const { virtual std::string className(void) const {
return "moCheckpoint"; return "moCheckpoint";
} }
/** /**
* apply operator of checkpoint's containers * apply operator of checkpoint's containers
* @param _sol reference of the solution * @param _sol reference of the solution
* @return true if all continuator return true * @return true if all continuator return true
*/ */
bool operator()(EOT & _sol) { bool operator()(EOT & _sol) {
unsigned i; unsigned i;
bool bContinue = true; bool bContinue = true;
for (i = 0; i < stats.size(); ++i){ for (i = 0; i < stats.size(); ++i) {
if(counter % interval == 0) if (counter % interval == 0)
(*stats[i])(_sol); (*stats[i])(_sol);
counter++; counter++;
} }
for (i = 0; i < updaters.size(); ++i) for (i = 0; i < updaters.size(); ++i)
(*updaters[i])(); (*updaters[i])();
for (i = 0; i < monitors.size(); ++i) for (i = 0; i < monitors.size(); ++i)
(*monitors[i])(); (*monitors[i])();
for (i = 0; i < continuators.size(); ++i) for (i = 0; i < continuators.size(); ++i)
if ( !(*continuators[i])(_sol) ) if ( !(*continuators[i])(_sol) )
bContinue = false; bContinue = false;
return bContinue; return bContinue;
} }
/** /**
* last call of statistic operators, monitors and updaters * last call of statistic operators, monitors and updaters
* @param _sol reference of the solution * @param _sol reference of the solution
*/ */
void lastCall(EOT& _sol){ void lastCall(EOT& _sol) {
unsigned int i; unsigned int i;
for (i = 0; i < stats.size(); ++i) for (i = 0; i < stats.size(); ++i)
stats[i]->lastCall(_sol); stats[i]->lastCall(_sol);
for (i = 0; i < updaters.size(); ++i) for (i = 0; i < updaters.size(); ++i)
updaters[i]->lastCall(); updaters[i]->lastCall();
for (i = 0; i < monitors.size(); ++i) for (i = 0; i < monitors.size(); ++i)
monitors[i]->lastCall(); monitors[i]->lastCall();
} }
private : private :
/** continuators vector */ /** continuators vector */

View file

@ -51,13 +51,13 @@ public:
* Init Continuator parameters * Init Continuator parameters
* @param _solution the related solution * @param _solution the related solution
*/ */
virtual void init(EOT& _solution){}; virtual void init(EOT& _solution) {};
/** /**
* Last Call to terminate the checkpoint * Last Call to terminate the checkpoint
* @param _solution the related solution * @param _solution the related solution
*/ */
virtual void lastCall(EOT& _solution){}; virtual void lastCall(EOT& _solution) {};
}; };
#endif #endif

View file

@ -46,51 +46,53 @@
class moCounterMonitorSaver : public eoUpdater { class moCounterMonitorSaver : public eoUpdater {
public : public :
/** /**
* Default Constructor * Default Constructor
* @param _interval frequency to call monitors * @param _interval frequency to call monitors
* @param _mon a monitor * @param _mon a monitor
*/ */
moCounterMonitorSaver(unsigned _interval, eoMonitor& _mon) : interval(_interval), counter(0) { moCounterMonitorSaver(unsigned _interval, eoMonitor& _mon) : interval(_interval), counter(0) {
monitors.push_back(&_mon); monitors.push_back(&_mon);
} }
/** /**
* call monitors if interval is reach by a counter * call monitors if interval is reach by a counter
*/ */
void operator()(void) { void operator()(void) {
if (counter++ % interval == 0) if (counter++ % interval == 0)
for (unsigned i = 0; i < monitors.size(); i++) for (unsigned i = 0; i < monitors.size(); i++)
(*monitors[i])(); (*monitors[i])();
} }
/** /**
* last call of monitors * last call of monitors
*/ */
void lastCall(void) { void lastCall(void) {
for (unsigned i = 0; i < monitors.size(); i++) for (unsigned i = 0; i < monitors.size(); i++)
monitors[i]->lastCall(); monitors[i]->lastCall();
} }
/** /**
* attach another monitor to this class * attach another monitor to this class
* @param _mon the monitor to attach * @param _mon the monitor to attach
*/ */
void add(eoMonitor& _mon) { void add(eoMonitor& _mon) {
monitors.push_back(&_mon); monitors.push_back(&_mon);
} }
/** /**
* @return name of the class * @return name of the class
*/ */
virtual std::string className(void) const { return "moCounterMonitorSaver"; } virtual std::string className(void) const {
return "moCounterMonitorSaver";
}
private : private :
/** interval and counter value */ /** interval and counter value */
unsigned int interval, counter; unsigned int interval, counter;
/** monitor's vector */ /** monitor's vector */
std::vector<eoMonitor*> monitors; std::vector<eoMonitor*> monitors;
}; };

View file

@ -54,20 +54,22 @@ public :
* @param _dist a distance * @param _dist a distance
* @param _ref the reference solution * @param _ref the reference solution
*/ */
moDistanceStat(eoDistance<EOT> & _dist, EOT & _ref): moStat<EOT, T>(0, "distance"), dist(_dist), refSolution(_ref){} moDistanceStat(eoDistance<EOT> & _dist, EOT & _ref): moStat<EOT, T>(0, "distance"), dist(_dist), refSolution(_ref) {}
/** /**
* Compute distance between a solution and the reference solution * Compute distance between a solution and the reference solution
* @param _sol a solution * @param _sol a solution
*/ */
virtual void operator()(EOT & _sol){ virtual void operator()(EOT & _sol) {
value() = dist(_sol, refSolution); value() = dist(_sol, refSolution);
} }
/** /**
* @return name of the class * @return name of the class
*/ */
virtual std::string className(void) const { return "moDistanceStat"; } virtual std::string className(void) const {
return "moDistanceStat";
}
private: private:
/** the distance */ /** the distance */
@ -76,7 +78,7 @@ private:
* the reference solution does not change during the run * the reference solution does not change during the run
* it could be the best solution knowed of the problem * it could be the best solution knowed of the problem
*/ */
EOT refSolution; EOT refSolution;
}; };

View file

@ -54,7 +54,7 @@ public :
* @param _description a description of the stat * @param _description a description of the stat
*/ */
moFitnessStat(std::string _description = "fitness"): moFitnessStat(std::string _description = "fitness"):
moStat<EOT, Fitness>(Fitness(), _description){} moStat<EOT, Fitness>(Fitness(), _description) {}
/** /**
* store fitness value * store fitness value
@ -62,13 +62,15 @@ public :
*/ */
virtual void operator()(EOT & _sol) virtual void operator()(EOT & _sol)
{ {
value() = _sol.fitness(); value() = _sol.fitness();
} }
/** /**
* @return the name of the class * @return the name of the class
*/ */
virtual std::string className(void) const { return "moFitnessStat"; } virtual std::string className(void) const {
return "moFitnessStat";
}
}; };
#endif #endif

View file

@ -45,34 +45,36 @@ template< class Neighborhood >
class moMaxNeighborStat : public moStat<typename Neighborhood::EOT, typename Neighborhood::EOT::Fitness> class moMaxNeighborStat : public moStat<typename Neighborhood::EOT, typename Neighborhood::EOT::Fitness>
{ {
public : public :
typedef typename Neighborhood::EOT EOT ; typedef typename Neighborhood::EOT EOT ;
typedef typename EOT::Fitness Fitness ; typedef typename EOT::Fitness Fitness ;
using moStat< EOT, Fitness >::value; using moStat< EOT, Fitness >::value;
/** /**
* Default Constructor * Default Constructor
* @param _nhStat a neighborhoodStat * @param _nhStat a neighborhoodStat
*/ */
moMaxNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat): moMaxNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat):
moStat<EOT, Fitness>(Fitness(), "min"), nhStat(_nhStat){} moStat<EOT, Fitness>(Fitness(), "min"), nhStat(_nhStat) {}
/** /**
* Set the max fitness in the neighborhood * Set the max fitness in the neighborhood
* @param _sol the corresponding solution * @param _sol the corresponding solution
*/ */
virtual void operator()(EOT & _sol){ virtual void operator()(EOT & _sol) {
value() = nhStat.getMax(); value() = nhStat.getMax();
} }
/** /**
* @return the class name * @return the class name
*/ */
virtual std::string className(void) const { return "moMaxNeighborStat"; } virtual std::string className(void) const {
return "moMaxNeighborStat";
}
private: private:
/** moNeighborhoodStat */ /** moNeighborhoodStat */
moNeighborhoodStat<Neighborhood> & nhStat; moNeighborhoodStat<Neighborhood> & nhStat;
}; };
#endif #endif

View file

@ -45,34 +45,36 @@ template< class Neighborhood >
class moMinNeighborStat : public moStat<typename Neighborhood::EOT, typename Neighborhood::EOT::Fitness> class moMinNeighborStat : public moStat<typename Neighborhood::EOT, typename Neighborhood::EOT::Fitness>
{ {
public : public :
typedef typename Neighborhood::EOT EOT ; typedef typename Neighborhood::EOT EOT ;
typedef typename EOT::Fitness Fitness ; typedef typename EOT::Fitness Fitness ;
using moStat< EOT, Fitness >::value; using moStat< EOT, Fitness >::value;
/** /**
* Default Constructor * Default Constructor
* @param _nhStat a neighborhoodStat * @param _nhStat a neighborhoodStat
*/ */
moMinNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat): moMinNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat):
moStat<EOT, Fitness>(Fitness(), "min"), nhStat(_nhStat){} moStat<EOT, Fitness>(Fitness(), "min"), nhStat(_nhStat) {}
/**
* Set the worst fitness in the neighborhood
* @param _sol the corresponding solution
*/
virtual void operator()(EOT & _sol){
value() = nhStat.getMin();
}
/** /**
* @return the class name * Set the worst fitness in the neighborhood
*/ * @param _sol the corresponding solution
virtual std::string className(void) const { return "moMinNeighborStat"; } */
virtual void operator()(EOT & _sol) {
value() = nhStat.getMin();
}
/**
* @return the class name
*/
virtual std::string className(void) const {
return "moMinNeighborStat";
}
private: private:
/** moNeighborhoodStat */ /** moNeighborhoodStat */
moNeighborhoodStat<Neighborhood> & nhStat; moNeighborhoodStat<Neighborhood> & nhStat;
}; };
#endif #endif

View file

@ -40,42 +40,44 @@
/** /**
* *
* From moNeighborhoodStat, to compute the number of solutions in the neighborhood * From moNeighborhoodStat, to compute the number of solutions in the neighborhood
* with (strictly) lower fitness than the current solution * with (strictly) lower fitness than the current solution
* *
*/ */
template< class Neighborhood > template< class Neighborhood >
class moNbInfNeighborStat : public moStat<typename Neighborhood::EOT, unsigned> class moNbInfNeighborStat : public moStat<typename Neighborhood::EOT, unsigned>
{ {
public : public :
typedef typename Neighborhood::EOT EOT ; typedef typename Neighborhood::EOT EOT ;
typedef typename EOT::Fitness Fitness ; typedef typename EOT::Fitness Fitness ;
using moStat< EOT, unsigned >::value; using moStat< EOT, unsigned >::value;
/** /**
* Default Constructor * Default Constructor
* @param _nhStat a neighborhoodStat * @param _nhStat a neighborhoodStat
*/ */
moNbInfNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat): moNbInfNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat):
moStat<EOT, unsigned>(0, "nb inf"), nhStat(_nhStat){} moStat<EOT, unsigned>(0, "nb inf"), nhStat(_nhStat) {}
/**
* Set the number of solutions in the neighborhood with (strictly) lower fitness than the current solution
* @param _sol the corresponding solution
*/
virtual void operator()(EOT & _sol){
value() = nhStat.getNbInf();
}
/** /**
* @return the class name * Set the number of solutions in the neighborhood with (strictly) lower fitness than the current solution
*/ * @param _sol the corresponding solution
virtual std::string className(void) const { return "moNbInfNeighborStat"; } */
virtual void operator()(EOT & _sol) {
value() = nhStat.getNbInf();
}
/**
* @return the class name
*/
virtual std::string className(void) const {
return "moNbInfNeighborStat";
}
private: private:
/** moNeighborhoodStat */ /** moNeighborhoodStat */
moNeighborhoodStat<Neighborhood> & nhStat; moNeighborhoodStat<Neighborhood> & nhStat;
}; };
#endif #endif

View file

@ -40,42 +40,44 @@
/** /**
* *
* From moNeighborhoodStat, to compute the number of solutions in the neighborhood * From moNeighborhoodStat, to compute the number of solutions in the neighborhood
* with higher fitness than the current solution * with higher fitness than the current solution
* *
*/ */
template< class Neighborhood > template< class Neighborhood >
class moNbSupNeighborStat : public moStat<typename Neighborhood::EOT, unsigned> class moNbSupNeighborStat : public moStat<typename Neighborhood::EOT, unsigned>
{ {
public : public :
typedef typename Neighborhood::EOT EOT ; typedef typename Neighborhood::EOT EOT ;
typedef typename EOT::Fitness Fitness ; typedef typename EOT::Fitness Fitness ;
using moStat< EOT, unsigned >::value; using moStat< EOT, unsigned >::value;
/** /**
* Default Constructor * Default Constructor
* @param _nhStat a neighborhoodStat * @param _nhStat a neighborhoodStat
*/ */
moNbSupNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat): moNbSupNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat):
moStat<EOT, unsigned>(0, "nb sup"), nhStat(_nhStat){} moStat<EOT, unsigned>(0, "nb sup"), nhStat(_nhStat) {}
/** /**
* Set the number of solutions in the neighborhood with better fitness than the current solution * Set the number of solutions in the neighborhood with better fitness than the current solution
* @param _sol the corresponding solution * @param _sol the corresponding solution
*/ */
virtual void operator()(EOT & _sol){ virtual void operator()(EOT & _sol) {
value() = nhStat.getNbSup(); value() = nhStat.getNbSup();
} }
/** /**
* @return the class name * @return the class name
*/ */
virtual std::string className(void) const { return "moNbSupNeighborStat"; } virtual std::string className(void) const {
return "moNbSupNeighborStat";
}
private: private:
/** moNeighborhoodStat */ /** moNeighborhoodStat */
moNeighborhoodStat<Neighborhood> & nhStat; moNeighborhoodStat<Neighborhood> & nhStat;
}; };
#endif #endif

View file

@ -49,187 +49,187 @@ template< class Neighborhood >
class moNeighborhoodStat : public moStat<typename Neighborhood::EOT, bool> class moNeighborhoodStat : public moStat<typename Neighborhood::EOT, bool>
{ {
public : public :
typedef typename Neighborhood::EOT EOT ; typedef typename Neighborhood::EOT EOT ;
typedef typename Neighborhood::Neighbor Neighbor ; typedef typename Neighborhood::Neighbor Neighbor ;
typedef typename EOT::Fitness Fitness ; typedef typename EOT::Fitness Fitness ;
using moStat< EOT, bool >::value; using moStat< EOT, bool >::value;
/** /**
* Default Constructor * Default Constructor
* @param _neighborhood a neighborhood * @param _neighborhood a neighborhood
* @param _eval an evaluation function * @param _eval an evaluation function
* @param _neighborComparator a neighbor Comparator * @param _neighborComparator a neighbor Comparator
* @param _solNeighborComparator a comparator between a solution and a neighbor * @param _solNeighborComparator a comparator between a solution and a neighbor
*/ */
moNeighborhoodStat(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator): moNeighborhoodStat(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator):
moStat<EOT, bool>(true, "neighborhood"), moStat<EOT, bool>(true, "neighborhood"),
neighborhood(_neighborhood), eval(_eval), neighborhood(_neighborhood), eval(_eval),
neighborComparator(_neighborComparator), neighborComparator(_neighborComparator),
solNeighborComparator(_solNeighborComparator) solNeighborComparator(_solNeighborComparator)
{} {}
/** /**
* Compute classical statistics of a solution's neighborhood * Compute classical statistics of a solution's neighborhood
* @param _solution the corresponding solution * @param _solution the corresponding solution
*/ */
virtual void operator()(EOT & _solution){ virtual void operator()(EOT & _solution) {
Neighbor current ; Neighbor current ;
Neighbor best ; Neighbor best ;
Neighbor lowest ; Neighbor lowest ;
if(neighborhood.hasNeighbor(_solution)){ if (neighborhood.hasNeighbor(_solution)) {
//init the first neighbor //init the first neighbor
neighborhood.init(_solution, current); neighborhood.init(_solution, current);
//eval the _solution moved with the neighbor and stock the result in the neighbor //eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, current); eval(_solution, current);
// init the statistics
value() = true;
mean = current.fitness(); // init the statistics
sd = mean * mean; value() = true;
nb = 1;
nbInf = 0;
nbEqual = 0;
nbSup = 0;
if (solNeighborComparator.equals(_solution, current)) mean = current.fitness();
nbEqual++; sd = mean * mean;
else if (solNeighborComparator(_solution, current)) nb = 1;
nbSup++; nbInf = 0;
else nbEqual = 0;
nbInf++; nbSup = 0;
//initialize the best neighbor if (solNeighborComparator.equals(_solution, current))
best = current; nbEqual++;
lowest = current; else if (solNeighborComparator(_solution, current))
nbSup++;
else
nbInf++;
//test all others neighbors //initialize the best neighbor
while (neighborhood.cont(_solution)) { best = current;
//next neighbor lowest = current;
neighborhood.next(_solution, current);
//eval
eval(_solution, current);
mean += current.fitness(); //test all others neighbors
sd += current.fitness() * current.fitness(); while (neighborhood.cont(_solution)) {
nb++; //next neighbor
neighborhood.next(_solution, current);
if (solNeighborComparator.equals(_solution, current)) //eval
nbEqual++; eval(_solution, current);
else if (solNeighborComparator(_solution, current))
nbSup++;
else
nbInf++;
//if we found a better neighbor, update the best mean += current.fitness();
if (neighborComparator(best, current)) sd += current.fitness() * current.fitness();
best = current; nb++;
if (neighborComparator(current, lowest))
lowest = current;
}
max = best.fitness(); if (solNeighborComparator.equals(_solution, current))
min = lowest.fitness(); nbEqual++;
else if (solNeighborComparator(_solution, current))
nbSup++;
else
nbInf++;
mean /= nb; //if we found a better neighbor, update the best
if (nb > 1) if (neighborComparator(best, current))
sd = sqrt( (sd - nb * mean * mean) / (nb - 1.0) ); best = current;
else
sd = 0.0;
}
else{
//if _solution hasn't neighbor,
value() = false;
}
}
/** if (neighborComparator(current, lowest))
* @return the worst fitness value found in the neighborhood lowest = current;
*/ }
Fitness getMin(){
return min;
}
/** max = best.fitness();
* @return the best fitness value found in the neighborhood min = lowest.fitness();
*/
Fitness getMax(){
return max;
}
/** mean /= nb;
* @return the mean fitness value of the neighborhood if (nb > 1)
*/ sd = sqrt( (sd - nb * mean * mean) / (nb - 1.0) );
double getMean(){ else
return mean; sd = 0.0;
} }
else {
//if _solution hasn't neighbor,
value() = false;
}
}
/** /**
* @return the standard deviation value of the neighborhood * @return the worst fitness value found in the neighborhood
*/ */
double getSD(){ Fitness getMin() {
return sd; return min;
} }
/** /**
* @return the size of the neighborhood * @return the best fitness value found in the neighborhood
*/ */
unsigned getSize(){ Fitness getMax() {
return nb; return max;
} }
/** /**
* @return the number of neighbors having a better fitness than the current solution * @return the mean fitness value of the neighborhood
*/ */
unsigned getNbSup(){ double getMean() {
return nbSup; return mean;
} }
/** /**
* @return the number of neighbors having the same fitness than the current solution * @return the standard deviation value of the neighborhood
*/ */
unsigned getNbEqual(){ double getSD() {
return nbEqual; return sd;
} }
/**
* @return the number of neighbors having a worst fitness than the current solution
*/
unsigned getNbInf() {
return nbInf;
}
/** /**
* @return the class name * @return the size of the neighborhood
*/ */
virtual std::string className(void) const { unsigned getSize() {
return "moNeighborhoodStat"; return nb;
} }
/**
* @return the number of neighbors having a better fitness than the current solution
*/
unsigned getNbSup() {
return nbSup;
}
/**
* @return the number of neighbors having the same fitness than the current solution
*/
unsigned getNbEqual() {
return nbEqual;
}
/**
* @return the number of neighbors having a worst fitness than the current solution
*/
unsigned getNbInf() {
return nbInf;
}
/**
* @return the class name
*/
virtual std::string className(void) const {
return "moNeighborhoodStat";
}
private: private:
// to explore the neighborhood // to explore the neighborhood
Neighborhood& neighborhood ; Neighborhood& neighborhood ;
moEval<Neighbor>& eval; moEval<Neighbor>& eval;
// comparator betwenn solution and neighbor or between neighbors // comparator betwenn solution and neighbor or between neighbors
moNeighborComparator<Neighbor>& neighborComparator; moNeighborComparator<Neighbor>& neighborComparator;
moSolNeighborComparator<Neighbor>& solNeighborComparator; moSolNeighborComparator<Neighbor>& solNeighborComparator;
// the stastics of the fitness // the stastics of the fitness
Fitness max, min; Fitness max, min;
//mean and standard deviation //mean and standard deviation
double mean, sd ; double mean, sd ;
// number of neighbors in the neighborhood; // number of neighbors in the neighborhood;
unsigned int nb; unsigned int nb;
// number of neighbors with lower, equal and higher fitness // number of neighbors with lower, equal and higher fitness
unsigned int nbInf, nbEqual, nbSup ; unsigned int nbInf, nbEqual, nbSup ;
}; };
#endif #endif

View file

@ -40,41 +40,43 @@
/** /**
* From moNeighborhoodStat, to compute the neutral degree of the solution * From moNeighborhoodStat, to compute the neutral degree of the solution
* which is the number of solutions in the neighborhood * which is the number of solutions in the neighborhood
* with equals fitness * with equals fitness
*/ */
template< class Neighborhood > template< class Neighborhood >
class moNeutralDegreeNeighborStat : public moStat<typename Neighborhood::EOT, unsigned> class moNeutralDegreeNeighborStat : public moStat<typename Neighborhood::EOT, unsigned>
{ {
public : public :
typedef typename Neighborhood::EOT EOT ; typedef typename Neighborhood::EOT EOT ;
typedef typename EOT::Fitness Fitness ; typedef typename EOT::Fitness Fitness ;
using moStat< EOT, unsigned >::value; using moStat< EOT, unsigned >::value;
/** /**
* Default Constructor * Default Constructor
* @param _nhStat a neighborhoodStat * @param _nhStat a neighborhoodStat
*/ */
moNeutralDegreeNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat): moNeutralDegreeNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat):
moStat<EOT, unsigned>(0, "neutral degree"), nhStat(_nhStat){} moStat<EOT, unsigned>(0, "neutral degree"), nhStat(_nhStat) {}
/** /**
* Set the neutral degree of the solution which is the number of solutions in the neighborhood with equals fitness * Set the neutral degree of the solution which is the number of solutions in the neighborhood with equals fitness
* @param _sol the corresponding solution * @param _sol the corresponding solution
*/ */
virtual void operator()(EOT & _sol){ virtual void operator()(EOT & _sol) {
value() = nhStat.getNbEqual(); value() = nhStat.getNbEqual();
} }
/** /**
* @return the class name * @return the class name
*/ */
virtual std::string className(void) const { return "moNeutralDegreeNeighborStat"; } virtual std::string className(void) const {
return "moNeutralDegreeNeighborStat";
}
private: private:
/** moNeighborhoodStat */ /** moNeighborhoodStat */
moNeighborhoodStat<Neighborhood> & nhStat; moNeighborhoodStat<Neighborhood> & nhStat;
}; };
#endif #endif

View file

@ -45,35 +45,37 @@ template< class Neighborhood >
class moSecondMomentNeighborStat : public moStat<typename Neighborhood::EOT, std::pair<double, double> > class moSecondMomentNeighborStat : public moStat<typename Neighborhood::EOT, std::pair<double, double> >
{ {
public : public :
typedef typename Neighborhood::EOT EOT ; typedef typename Neighborhood::EOT EOT ;
typedef typename EOT::Fitness Fitness ; typedef typename EOT::Fitness Fitness ;
using moStat< EOT, std::pair<double, double> >::value; using moStat< EOT, std::pair<double, double> >::value;
/** /**
* Default Constructor * Default Constructor
* @param _nhStat a neighborhoodStat * @param _nhStat a neighborhoodStat
*/ */
moSecondMomentNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat): moSecondMomentNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat):
moStat<EOT, std::pair<double, double> >(std::make_pair(0.0,0.0), "average and stdev"), nhStat(_nhStat){} moStat<EOT, std::pair<double, double> >(std::make_pair(0.0,0.0), "average and stdev"), nhStat(_nhStat) {}
/** /**
* Set the average and the standard deviation of fitness in the neighborhood * Set the average and the standard deviation of fitness in the neighborhood
* @param _sol the corresponding solution * @param _sol the corresponding solution
*/ */
virtual void operator()(EOT & _sol){ virtual void operator()(EOT & _sol) {
value().first = nhStat.getMean(); value().first = nhStat.getMean();
value().second = nhStat.getSD(); value().second = nhStat.getSD();
} }
/** /**
* @return the class name * @return the class name
*/ */
virtual std::string className(void) const { return "moSecondMomentNeighborStat"; } virtual std::string className(void) const {
return "moSecondMomentNeighborStat";
}
private: private:
/** moNeighborhoodStat */ /** moNeighborhoodStat */
moNeighborhoodStat<Neighborhood> & nhStat; moNeighborhoodStat<Neighborhood> & nhStat;
}; };
#endif #endif

View file

@ -40,40 +40,42 @@
/** /**
* From moNeighborhoodStat, to compute the number of solutions in the neighborhood * From moNeighborhoodStat, to compute the number of solutions in the neighborhood
* *
*/ */
template< class Neighborhood > template< class Neighborhood >
class moSizeNeighborStat : public moStat<typename Neighborhood::EOT, unsigned> class moSizeNeighborStat : public moStat<typename Neighborhood::EOT, unsigned>
{ {
public : public :
typedef typename Neighborhood::EOT EOT ; typedef typename Neighborhood::EOT EOT ;
typedef typename EOT::Fitness Fitness ; typedef typename EOT::Fitness Fitness ;
using moStat< EOT, unsigned >::value; using moStat< EOT, unsigned >::value;
/** /**
* Default Constructor * Default Constructor
* @param _nhStat a neighborhoodStat * @param _nhStat a neighborhoodStat
*/ */
moSizeNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat): moSizeNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat):
moStat<EOT, unsigned>(0, "size"), nhStat(_nhStat){} moStat<EOT, unsigned>(0, "size"), nhStat(_nhStat) {}
/** /**
* Set the number of solutions in the neighborhood * Set the number of solutions in the neighborhood
* @param _sol the corresponding solution * @param _sol the corresponding solution
*/ */
virtual void operator()(EOT & _sol){ virtual void operator()(EOT & _sol) {
value() = nhStat.getSize(); value() = nhStat.getSize();
} }
/** /**
* @return the class name * @return the class name
*/ */
virtual std::string className(void) const { return "moSizeNeighborStat"; } virtual std::string className(void) const {
return "moSizeNeighborStat";
}
private: private:
/** moNeighborhoodStat */ /** moNeighborhoodStat */
moNeighborhoodStat<Neighborhood> & nhStat; moNeighborhoodStat<Neighborhood> & nhStat;
}; };
#endif #endif

View file

@ -40,7 +40,7 @@
/** /**
* The statistic which only give the current solution * The statistic which only give the current solution
* be careful, the solution is given by copy * be careful, the solution is given by copy
* *
*/ */
template <class EOT> template <class EOT>
class moSolutionStat : public moStat<EOT, EOT> class moSolutionStat : public moStat<EOT, EOT>
@ -53,21 +53,21 @@ public :
* @param _description a description of the parameter * @param _description a description of the parameter
*/ */
moSolutionStat(std::string _description = "solution"): moSolutionStat(std::string _description = "solution"):
moStat<EOT, EOT>(EOT(), _description){} moStat<EOT, EOT>(EOT(), _description) {}
/** /**
* Set the solution by copy * Set the solution by copy
* @param _sol the corresponding solution * @param _sol the corresponding solution
*/ */
virtual void operator()(EOT & _sol){ virtual void operator()(EOT & _sol) {
value() = _sol; value() = _sol;
} }
/** /**
* @return name of the class * @return name of the class
*/ */
virtual std::string className(void) const{ virtual std::string className(void) const {
return "moSolutionStat"; return "moSolutionStat";
} }
}; };

View file

@ -47,19 +47,19 @@ class moStat : public eoValueParam<T>, public moStatBase<EOT>
{ {
public: public:
/** /**
* Default Constructor * Default Constructor
* @param _value a default parameter's value * @param _value a default parameter's value
* @param _description a description of the parameter * @param _description a description of the parameter
*/ */
moStat(T _value, std::string _description): moStat(T _value, std::string _description):
eoValueParam<T>(_value, _description){} eoValueParam<T>(_value, _description) {}
/** /**
* @return name of the class * @return name of the class
*/ */
virtual std::string className(void) const{ virtual std::string className(void) const {
return "moStat"; return "moStat";
} }
}; };

View file

@ -49,17 +49,17 @@ template <class EOT>
class moStatBase : public eoUF<EOT &, void> class moStatBase : public eoUF<EOT &, void>
{ {
public: public:
/** /**
* last call of a statistical operator * last call of a statistical operator
*/ */
virtual void lastCall(EOT &) {} virtual void lastCall(EOT &) {}
/** /**
* @return name of the class * @return name of the class
*/ */
virtual std::string className(void) const{ virtual std::string className(void) const {
return "moStatBase"; return "moStatBase";
} }
}; };
#endif #endif

Some files were not shown because too many files have changed in this diff Show more