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

@ -62,39 +62,39 @@ public:
*/ */
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 * Set the worst 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.getMin(); value() = nhStat.getMin();
} }
/** /**
* @return the class name * @return the class name
*/ */
virtual std::string className(void) const { return "moMinNeighborStat"; } virtual std::string className(void) const {
return "moMinNeighborStat";
}
private: private:
/** moNeighborhoodStat */ /** moNeighborhoodStat */
moNeighborhoodStat<Neighborhood> & nhStat; moNeighborhoodStat<Neighborhood> & nhStat;
}; };
#endif #endif

View file

@ -48,34 +48,36 @@ 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 * Set the number of solutions in the neighborhood with (strictly) lower 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.getNbInf(); value() = nhStat.getNbInf();
} }
/** /**
* @return the class name * @return the class name
*/ */
virtual std::string className(void) const { return "moNbInfNeighborStat"; } virtual std::string className(void) const {
return "moNbInfNeighborStat";
}
private: private:
/** moNeighborhoodStat */ /** moNeighborhoodStat */
moNeighborhoodStat<Neighborhood> & nhStat; moNeighborhoodStat<Neighborhood> & nhStat;
}; };
#endif #endif

View file

@ -48,34 +48,36 @@ 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 // init the statistics
value() = true; value() = true;
mean = current.fitness(); mean = current.fitness();
sd = mean * mean; sd = mean * mean;
nb = 1; nb = 1;
nbInf = 0; nbInf = 0;
nbEqual = 0; nbEqual = 0;
nbSup = 0; nbSup = 0;
if (solNeighborComparator.equals(_solution, current)) if (solNeighborComparator.equals(_solution, current))
nbEqual++; nbEqual++;
else if (solNeighborComparator(_solution, current)) else if (solNeighborComparator(_solution, current))
nbSup++; nbSup++;
else else
nbInf++; nbInf++;
//initialize the best neighbor //initialize the best neighbor
best = current; best = current;
lowest = current; lowest = current;
//test all others neighbors //test all others neighbors
while (neighborhood.cont(_solution)) { while (neighborhood.cont(_solution)) {
//next neighbor //next neighbor
neighborhood.next(_solution, current); neighborhood.next(_solution, current);
//eval //eval
eval(_solution, current); eval(_solution, current);
mean += current.fitness(); mean += current.fitness();
sd += current.fitness() * current.fitness(); sd += current.fitness() * current.fitness();
nb++; nb++;
if (solNeighborComparator.equals(_solution, current)) if (solNeighborComparator.equals(_solution, current))
nbEqual++; nbEqual++;
else if (solNeighborComparator(_solution, current)) else if (solNeighborComparator(_solution, current))
nbSup++; nbSup++;
else else
nbInf++; nbInf++;
//if we found a better neighbor, update the best //if we found a better neighbor, update the best
if (neighborComparator(best, current)) if (neighborComparator(best, current))
best = current; best = current;
if (neighborComparator(current, lowest)) if (neighborComparator(current, lowest))
lowest = current; lowest = current;
} }
max = best.fitness(); max = best.fitness();
min = lowest.fitness(); min = lowest.fitness();
mean /= nb; mean /= nb;
if (nb > 1) if (nb > 1)
sd = sqrt( (sd - nb * mean * mean) / (nb - 1.0) ); sd = sqrt( (sd - nb * mean * mean) / (nb - 1.0) );
else else
sd = 0.0; sd = 0.0;
} }
else{ else {
//if _solution hasn't neighbor, //if _solution hasn't neighbor,
value() = false; value() = false;
} }
} }
/** /**
* @return the worst fitness value found in the neighborhood * @return the worst fitness value found in the neighborhood
*/ */
Fitness getMin(){ Fitness getMin() {
return min; return min;
} }
/** /**
* @return the best fitness value found in the neighborhood * @return the best fitness value found in the neighborhood
*/ */
Fitness getMax(){ Fitness getMax() {
return max; return max;
} }
/** /**
* @return the mean fitness value of the neighborhood * @return the mean fitness value of the neighborhood
*/ */
double getMean(){ double getMean() {
return mean; return mean;
} }
/** /**
* @return the standard deviation value of the neighborhood * @return the standard deviation value of the neighborhood
*/ */
double getSD(){ double getSD() {
return sd; return sd;
} }
/** /**
* @return the size of the neighborhood * @return the size of the neighborhood
*/ */
unsigned getSize(){ unsigned getSize() {
return nb; return nb;
} }
/** /**
* @return the number of neighbors having a better fitness than the current solution * @return the number of neighbors having a better fitness than the current solution
*/ */
unsigned getNbSup(){ unsigned getNbSup() {
return nbSup; return nbSup;
} }
/** /**
* @return the number of neighbors having the same fitness than the current solution * @return the number of neighbors having the same fitness than the current solution
*/ */
unsigned getNbEqual(){ unsigned getNbEqual() {
return nbEqual; return nbEqual;
} }
/** /**
* @return the number of neighbors having a worst fitness than the current solution * @return the number of neighbors having a worst fitness than the current solution
*/ */
unsigned getNbInf() { unsigned getNbInf() {
return nbInf; return nbInf;
} }
/** /**
* @return the class name * @return the class name
*/ */
virtual std::string className(void) const { virtual std::string className(void) const {
return "moNeighborhoodStat"; 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

@ -47,34 +47,36 @@ 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

@ -46,34 +46,36 @@ 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

@ -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

View file

@ -54,7 +54,7 @@ public:
*@return always true *@return always true
*/ */
virtual bool operator()(EOT & _solution) { virtual bool operator()(EOT & _solution) {
return true; return true;
} }
/** /**

View file

@ -44,8 +44,8 @@ template<class Neighbor>
class moEval : public eoBF<typename Neighbor::EOT &, Neighbor&, void> class moEval : public eoBF<typename Neighbor::EOT &, Neighbor&, void>
{ {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
typedef typename EOT::Fitness Fitness; typedef typename EOT::Fitness Fitness;
}; };
#endif #endif

View file

@ -45,37 +45,37 @@ template<class Neighbor>
class moFullEvalByCopy : public moEval<Neighbor> class moFullEvalByCopy : public moEval<Neighbor>
{ {
public: public:
typedef typename moEval<Neighbor>::EOT EOT; typedef typename moEval<Neighbor>::EOT EOT;
typedef typename moEval<Neighbor>::Fitness Fitness; typedef typename moEval<Neighbor>::Fitness Fitness;
/** /**
* Ctor * Ctor
* @param _eval the full evaluation object * @param _eval the full evaluation object
*/ */
moFullEvalByCopy(eoEvalFunc<EOT> & _eval) : eval(_eval) {} moFullEvalByCopy(eoEvalFunc<EOT> & _eval) : eval(_eval) {}
/** /**
* Full evaluation of the neighbor by copy * Full evaluation of the neighbor by copy
* @param _sol current solution * @param _sol current solution
* @param _neighbor the neighbor to be evaluated * @param _neighbor the neighbor to be evaluated
*/ */
void operator()(EOT & _sol, Neighbor & _neighbor) void operator()(EOT & _sol, Neighbor & _neighbor)
{ {
// tmp solution // tmp solution
EOT tmp(_sol); EOT tmp(_sol);
// move tmp solution wrt _neighbor // move tmp solution wrt _neighbor
_neighbor.move(tmp); _neighbor.move(tmp);
// eval copy // eval copy
tmp.invalidate(); tmp.invalidate();
eval(tmp); eval(tmp);
// set the fitness value to the neighbor // set the fitness value to the neighbor
_neighbor.fitness(tmp.fitness()); _neighbor.fitness(tmp.fitness());
} }
private: private:
/** the full evaluation object */ /** the full evaluation object */
eoEvalFunc<EOT> & eval; eoEvalFunc<EOT> & eval;
}; };

View file

@ -45,50 +45,50 @@ template<class BackableNeighbor>
class moFullEvalByModif : public moEval<BackableNeighbor> class moFullEvalByModif : public moEval<BackableNeighbor>
{ {
public: public:
typedef typename moEval<BackableNeighbor>::EOT EOT; typedef typename moEval<BackableNeighbor>::EOT EOT;
typedef typename moEval<BackableNeighbor>::Fitness Fitness; typedef typename moEval<BackableNeighbor>::Fitness Fitness;
/** /**
* Ctor * Ctor
* @param _eval the full evaluation object * @param _eval the full evaluation object
*/ */
moFullEvalByModif(eoEvalFunc<EOT>& _eval) : eval(_eval) {} moFullEvalByModif(eoEvalFunc<EOT>& _eval) : eval(_eval) {}
/** /**
* Full evaluation of the neighbor by copy * Full evaluation of the neighbor by copy
* @param _sol current solution * @param _sol current solution
* @param _neighbor the neighbor to be evaluated * @param _neighbor the neighbor to be evaluated
*/ */
void operator()(EOT & _sol, BackableNeighbor & _neighbor) void operator()(EOT & _sol, BackableNeighbor & _neighbor)
{ {
// tmp fitness value of the current solution // tmp fitness value of the current solution
Fitness tmpFit; Fitness tmpFit;
// save current fitness value // save current fitness value
tmpFit = _sol.fitness(); tmpFit = _sol.fitness();
// move the current solution wrt _neighbor // move the current solution wrt _neighbor
_neighbor.move(_sol); _neighbor.move(_sol);
// eval the modified solution // eval the modified solution
_sol.invalidate(); _sol.invalidate();
eval(_sol); eval(_sol);
// set the fitness value to the neighbor // set the fitness value to the neighbor
_neighbor.fitness(_sol.fitness()); _neighbor.fitness(_sol.fitness());
// move the current solution back // move the current solution back
_neighbor.moveBack(_sol); _neighbor.moveBack(_sol);
// set the fitness back // set the fitness back
_sol.fitness(tmpFit); _sol.fitness(tmpFit);
} }
private: private:
/** the full evaluation object */ /** the full evaluation object */
eoEvalFunc<EOT> & eval; eoEvalFunc<EOT> & eval;
}; };

View file

@ -52,66 +52,66 @@ public:
using moNeighborhoodExplorer<Neighborhood>::neighborhood; using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::eval; using moNeighborhoodExplorer<Neighborhood>::eval;
/** /**
* Constructor * Constructor
* @param _neighborhood the neighborhood * @param _neighborhood the neighborhood
* @param _eval the evaluation function * @param _eval the evaluation function
* @param _neighborComparator a neighbor comparator * @param _neighborComparator a neighbor comparator
* @param _solNeighborComparator a solution vs neighbor comparator * @param _solNeighborComparator a solution vs neighbor comparator
*/ */
moFirstImprExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) { moFirstImprExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) {
isAccept = false; isAccept = false;
current=new Neighbor(); current=new Neighbor();
} }
/** /**
* Destructor * Destructor
*/ */
~moFirstImprExplorer(){ ~moFirstImprExplorer() {
delete current; delete current;
} }
/** /**
* initParam: NOTHING TO DO * initParam: NOTHING TO DO
*/ */
virtual void initParam(EOT & solution){}; virtual void initParam(EOT & solution) {};
/** /**
* updateParam: NOTHING TO DO * updateParam: NOTHING TO DO
*/ */
virtual void updateParam(EOT & solution){}; virtual void updateParam(EOT & solution) {};
/** /**
* 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) {
//Test if _solution has a Neighbor //Test if _solution has a Neighbor
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));
//test all others neighbors //test all others neighbors
while (! solNeighborComparator(_solution, *current) && neighborhood.cont(_solution)) { while (! solNeighborComparator(_solution, *current) && neighborhood.cont(_solution)) {
//next neighbor //next neighbor
neighborhood.next(_solution, (*current)); neighborhood.next(_solution, (*current));
//eval //eval
eval(_solution, (*current)); eval(_solution, (*current));
} }
} }
else{ else {
//if _solution hasn't neighbor, //if _solution hasn't neighbor,
isAccept=false; isAccept=false;
} }
}; };
/** /**
@ -120,7 +120,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 isAccept ;
}; };
/** /**
@ -128,10 +128,10 @@ 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 //move the solution
(*current).move(_solution); (*current).move(_solution);
//update its fitness //update its fitness
_solution.fitness((*current).fitness()); _solution.fitness((*current).fitness());
}; };
/** /**
@ -140,10 +140,10 @@ 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) {
if(neighborhood.hasNeighbor(_solution)){ if (neighborhood.hasNeighbor(_solution)) {
isAccept = solNeighborComparator(_solution, (*current)) ; isAccept = solNeighborComparator(_solution, (*current)) ;
} }
return isAccept; return isAccept;
}; };
private: private:

View file

@ -56,49 +56,49 @@ public:
using moSimpleHCneutralExplorer<Neighborhood>::initParam; using moSimpleHCneutralExplorer<Neighborhood>::initParam;
using moSimpleHCneutralExplorer<Neighborhood>::updateParam; using moSimpleHCneutralExplorer<Neighborhood>::updateParam;
/** /**
* Constructor * Constructor
* @param _neighborhood the neighborhood * @param _neighborhood the neighborhood
* @param _eval the evaluation function * @param _eval the evaluation function
* @param _neighborComparator a neighbor comparator * @param _neighborComparator a neighbor comparator
* @param _solNeighborComparator a solution vs neighbor comparator * @param _solNeighborComparator a solution vs neighbor comparator
* @param _nbStep maximum step to do * @param _nbStep maximum step to do
*/ */
moHCneutralExplorer(Neighborhood& _neighborhood, moHCneutralExplorer(Neighborhood& _neighborhood,
moEval<Neighbor>& _eval, moEval<Neighbor>& _eval,
moNeighborComparator<Neighbor>& _neighborComparator, moNeighborComparator<Neighbor>& _neighborComparator,
moSolNeighborComparator<Neighbor>& _solNeighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator,
unsigned _nbStep) : unsigned _nbStep) :
moSimpleHCneutralExplorer<Neighborhood>(_neighborhood, _eval, _neighborComparator, _solNeighborComparator), moSimpleHCneutralExplorer<Neighborhood>(_neighborhood, _eval, _neighborComparator, _solNeighborComparator),
nbStep(_nbStep){ nbStep(_nbStep) {
//Some cycle is possible with equals fitness solutions if the neighborhood is not random //Some cycle is possible with equals fitness solutions if the neighborhood is not random
if(!neighborhood.isRandom()){ if (!neighborhood.isRandom()) {
std::cout << "moHCneutralExplorer::Warning -> the neighborhood used is not random" << std::endl; std::cout << "moHCneutralExplorer::Warning -> the neighborhood used is not random" << std::endl;
} }
} }
/** /**
* Destructor * Destructor
*/ */
~moHCneutralExplorer(){ ~moHCneutralExplorer() {
} }
/** /**
* initial number of step * initial number of step
*/ */
virtual void initParam(EOT & solution){ virtual void initParam(EOT & solution) {
moSimpleHCneutralExplorer<Neighborhood>::initParam(solution); moSimpleHCneutralExplorer<Neighborhood>::initParam(solution);
step = 0; step = 0;
}; };
/** /**
* one more step * one more step
*/ */
virtual void updateParam(EOT & solution){ virtual void updateParam(EOT & solution) {
moSimpleHCneutralExplorer<Neighborhood>::updateParam(solution); moSimpleHCneutralExplorer<Neighborhood>::updateParam(solution);
step++; step++;
}; };
/** /**
@ -107,7 +107,7 @@ public:
* @return true there is some steps to do * @return true there is some steps to do
*/ */
virtual bool isContinue(EOT & _solution) { virtual bool isContinue(EOT & _solution) {
return (step < nbStep) && isAccept ; return (step < nbStep) && isAccept ;
}; };
/** /**
@ -116,9 +116,9 @@ public:
* @return true if the best neighbor ameliorate the fitness or is equals * @return true if the best neighbor ameliorate the fitness or is equals
*/ */
virtual bool accept(EOT & _solution) { virtual bool accept(EOT & _solution) {
if(neighborhood.hasNeighbor(_solution)) if (neighborhood.hasNeighbor(_solution))
isAccept = solNeighborComparator(_solution, bestVector[0]) || solNeighborComparator.equals(_solution, bestVector[0]) ; isAccept = solNeighborComparator(_solution, bestVector[0]) || solNeighborComparator.equals(_solution, bestVector[0]) ;
return isAccept; return isAccept;
}; };
private: private:

View file

@ -58,69 +58,69 @@ public:
using moNeighborhoodExplorer<Neighborhood>::neighborhood; using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::eval; using moNeighborhoodExplorer<Neighborhood>::eval;
/** /**
* Constructor * Constructor
* @param _neighborhood the neighborhood * @param _neighborhood the neighborhood
* @param _eval the evaluation function * @param _eval the evaluation function
* @param _neighborComparator a neighbor comparator * @param _neighborComparator a neighbor comparator
* @param _solNeighborComparator a solution vs neighbor comparator * @param _solNeighborComparator a solution vs neighbor comparator
* @param _nbStep maximum number of step to do * @param _nbStep maximum number of step to do
*/ */
moMetropolisHastingExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator, unsigned int _nbStep) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator), nbStep(_nbStep) { moMetropolisHastingExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator, unsigned int _nbStep) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator), nbStep(_nbStep) {
isAccept = false; isAccept = false;
current=new Neighbor(); current=new Neighbor();
if(!neighborhood.isRandom()){ if (!neighborhood.isRandom()) {
std::cout << "moMetropolisHastingExplorer::Warning -> the neighborhood used is not random" << std::endl; std::cout << "moMetropolisHastingExplorer::Warning -> the neighborhood used is not random" << std::endl;
} }
} }
/** /**
* Destructor * Destructor
*/ */
~moMetropolisHastingExplorer(){ ~moMetropolisHastingExplorer() {
delete current; delete current;
} }
/** /**
* initialization of the number of step to be done * initialization of the number of step to be done
* @param _solution the solution (unused here) * @param _solution the solution (unused here)
*/ */
virtual void initParam(EOT & _solution){ virtual void initParam(EOT & _solution) {
step = 0; step = 0;
isAccept = true; isAccept = true;
}; };
/** /**
* increase the number of step * increase the number of step
* @param _solution the solution (unused here) * @param _solution the solution (unused here)
*/ */
virtual void updateParam(EOT & _solution){ virtual void updateParam(EOT & _solution) {
step++; step++;
}; };
/** /**
* terminate: NOTHING TO DO * terminate: NOTHING TO DO
* @param _solution the solution (unused here) * @param _solution the solution (unused here)
*/ */
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) {
//Test if _solution has a Neighbor //Test if _solution has a Neighbor
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));
} }
else{ else {
//if _solution hasn't neighbor, //if _solution hasn't neighbor,
isAccept=false; isAccept=false;
} }
}; };
/** /**
@ -129,7 +129,7 @@ public:
* @return true there is some steps to do * @return true there is some steps to do
*/ */
virtual bool isContinue(EOT & _solution) { virtual bool isContinue(EOT & _solution) {
return (step < nbStep) ; return (step < nbStep) ;
}; };
/** /**
@ -137,10 +137,10 @@ 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 //move the solution
(*current).move(_solution); (*current).move(_solution);
//update its fitness //update its fitness
_solution.fitness((*current).fitness()); _solution.fitness((*current).fitness());
}; };
/** /**
@ -149,27 +149,27 @@ 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) {
double alpha=0.0; double alpha=0.0;
if(neighborhood.hasNeighbor(_solution)){ if (neighborhood.hasNeighbor(_solution)) {
if (solNeighborComparator(_solution, *current)) if (solNeighborComparator(_solution, *current))
isAccept = true; isAccept = true;
else{ else {
if(_solution.fitness() != 0){ if (_solution.fitness() != 0) {
if( (double)current->fitness() < (double)_solution.fitness()) // maximizing if ( (double)current->fitness() < (double)_solution.fitness()) // maximizing
alpha = (double) current->fitness() / (double) _solution.fitness(); alpha = (double) current->fitness() / (double) _solution.fitness();
else //minimizing else //minimizing
alpha = (double) _solution.fitness() / (double) current->fitness(); alpha = (double) _solution.fitness() / (double) current->fitness();
isAccept = (rng.uniform() < alpha) ; isAccept = (rng.uniform() < alpha) ;
} }
else{ else {
if( (double)current->fitness() < (double)_solution.fitness()) // maximizing if ( (double)current->fitness() < (double)_solution.fitness()) // maximizing
isAccept = true; isAccept = true;
else else
isAccept = false; isAccept = false;
} }
} }
} }
return isAccept; return isAccept;
}; };
private: private:

View file

@ -102,16 +102,16 @@ public:
* Getter for variable "isMoved" * Getter for variable "isMoved"
* @return true if move is applied * @return true if move is applied
*/ */
bool moveApplied(){ bool moveApplied() {
return isMoved; return isMoved;
} }
/** /**
* Setter for variable "isMoved" * Setter for variable "isMoved"
* @param _isMoved * @param _isMoved
*/ */
void moveApplied(bool _isMoved){ void moveApplied(bool _isMoved) {
isMoved=_isMoved; isMoved=_isMoved;
} }
/** /**
@ -119,7 +119,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 "moNeighborhoodExplorer"; return "moNeighborhoodExplorer";
} }
protected: protected:

View file

@ -54,79 +54,79 @@ public:
using moNeighborhoodExplorer<Neighborhood>::neighborhood; using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::eval; using moNeighborhoodExplorer<Neighborhood>::eval;
/** /**
* Constructor * Constructor
* @param _neighborhood the neighborhood * @param _neighborhood the neighborhood
* @param _eval the evaluation function * @param _eval the evaluation function
* @param _solNeighborComparator a solution vs neighbor comparator * @param _solNeighborComparator a solution vs neighbor comparator
* @param _nbStep maximum number of step to do * @param _nbStep maximum number of step to do
*/ */
moRandomNeutralWalkExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moRandomNeutralWalkExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval,
moSolNeighborComparator<Neighbor>& _solNeighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator,
unsigned _nbStep): unsigned _nbStep):
moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval),
solNeighborComparator(_solNeighborComparator), solNeighborComparator(_solNeighborComparator),
nbStep(_nbStep) { nbStep(_nbStep) {
isAccept = false; isAccept = false;
current=new Neighbor(); current=new Neighbor();
if(!neighborhood.isRandom()){ if (!neighborhood.isRandom()) {
std::cout << "moRandomNeutralWalkExplorer::Warning -> the neighborhood used is not random" << std::endl; std::cout << "moRandomNeutralWalkExplorer::Warning -> the neighborhood used is not random" << std::endl;
} }
} }
/** /**
* Destructor * Destructor
*/ */
~moRandomNeutralWalkExplorer(){ ~moRandomNeutralWalkExplorer() {
delete current; delete current;
} }
/** /**
* initialization of the number of step to be done * initialization of the number of step to be done
*/ */
virtual void initParam(EOT & solution){ virtual void initParam(EOT & solution) {
step = 0; step = 0;
isAccept = true; isAccept = true;
}; };
/** /**
* increase the number of step * increase the number of step
*/ */
virtual void updateParam(EOT & solution){ virtual void updateParam(EOT & solution) {
step++; step++;
}; };
/** /**
* 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) {
//Test if _solution has a Neighbor //Test if _solution has a Neighbor
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));
//test all others neighbors //test all others neighbors
while (! solNeighborComparator.equals(_solution, *current) && neighborhood.cont(_solution)) { while (! solNeighborComparator.equals(_solution, *current) && neighborhood.cont(_solution)) {
//next neighbor //next neighbor
neighborhood.next(_solution, (*current)); neighborhood.next(_solution, (*current));
//eval //eval
eval(_solution, (*current)); eval(_solution, (*current));
} }
} }
else{ else {
//if _solution hasn't neighbor, //if _solution hasn't neighbor,
isAccept=false; isAccept=false;
} }
}; };
/** /**
* continue if there is a neighbor and it is remainds some steps to do * continue if there is a neighbor and it is remainds some steps to do
@ -134,7 +134,7 @@ public:
* @return true there is some steps to do * @return true there is some steps to do
*/ */
virtual bool isContinue(EOT & _solution) { virtual bool isContinue(EOT & _solution) {
return (step < nbStep) && isAccept ; return (step < nbStep) && isAccept ;
}; };
/** /**
@ -142,10 +142,10 @@ 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 //move the solution
(*current).move(_solution); (*current).move(_solution);
//update its fitness //update its fitness
_solution.fitness((*current).fitness()); _solution.fitness((*current).fitness());
}; };
/** /**
@ -154,9 +154,9 @@ 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) {
if(neighborhood.hasNeighbor(_solution)) if (neighborhood.hasNeighbor(_solution))
isAccept = solNeighborComparator.equals(_solution, (*current)) ; isAccept = solNeighborComparator.equals(_solution, (*current)) ;
return isAccept; return isAccept;
}; };
private: private:

View file

@ -52,69 +52,69 @@ public:
using moNeighborhoodExplorer<Neighborhood>::neighborhood; using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::eval; using moNeighborhoodExplorer<Neighborhood>::eval;
/** /**
* Constructor * Constructor
* @param _neighborhood the neighborhood * @param _neighborhood the neighborhood
* @param _eval the evaluation function * @param _eval the evaluation function
* @param _nbStep maximum number of step to do * @param _nbStep maximum number of step to do
*/ */
moRandomWalkExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, unsigned _nbStep) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), nbStep(_nbStep) { moRandomWalkExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, unsigned _nbStep) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), nbStep(_nbStep) {
isAccept = false; isAccept = false;
current=new Neighbor(); current=new Neighbor();
// number of step done // number of step done
step = 0; step = 0;
if(!neighborhood.isRandom()){ if (!neighborhood.isRandom()) {
std::cout << "moRandomWalkExplorer::Warning -> the neighborhood used is not random" << std::endl; std::cout << "moRandomWalkExplorer::Warning -> the neighborhood used is not random" << std::endl;
} }
} }
/** /**
* Destructor * Destructor
*/ */
~moRandomWalkExplorer(){ ~moRandomWalkExplorer() {
delete current; delete current;
} }
/** /**
* initialization of the number of step to be done * initialization of the number of step to be done
*/ */
virtual void initParam(EOT & solution){ virtual void initParam(EOT & solution) {
step = 0; step = 0;
isAccept = true; isAccept = true;
}; };
/** /**
* increase the number of step * increase the number of step
*/ */
virtual void updateParam(EOT & solution){ virtual void updateParam(EOT & solution) {
step++; step++;
}; };
/** /**
* terminate: NOTHING TO DO * terminate: NOTHING TO DO
*/ */
virtual void terminate(EOT & solution){}; virtual void terminate(EOT & solution) {};
/** /**
* Explore the neighborhood with only one random solution * Explore the neighborhood with only one random solution
* @param _solution * @param _solution
*/ */
virtual void operator()(EOT & _solution){ virtual void operator()(EOT & _solution) {
//Test if _solution has a Neighbor //Test if _solution has a Neighbor
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));
isAccept = true; isAccept = true;
} }
else{ else {
//if _solution hasn't neighbor, //if _solution hasn't neighbor,
isAccept=false; isAccept=false;
} }
}; };
/** /**
@ -123,7 +123,7 @@ public:
* @return true there is some steps to do * @return true there is some steps to do
*/ */
virtual bool isContinue(EOT & _solution) { virtual bool isContinue(EOT & _solution) {
return (step < nbStep) && isAccept ; return (step < nbStep) && isAccept ;
}; };
/** /**
@ -131,10 +131,10 @@ 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 //move the solution
(*current).move(_solution); (*current).move(_solution);
//update its fitness //update its fitness
_solution.fitness((*current).fitness()); _solution.fitness((*current).fitness());
}; };
/** /**
@ -143,9 +143,9 @@ 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) {
if(neighborhood.hasNeighbor(_solution)) if (neighborhood.hasNeighbor(_solution))
isAccept = true ; isAccept = true ;
return isAccept; return isAccept;
}; };
private: private:

View file

@ -52,77 +52,77 @@ public:
using moNeighborhoodExplorer<Neighborhood>::neighborhood; using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::eval; using moNeighborhoodExplorer<Neighborhood>::eval;
/** /**
* Constructor * Constructor
* @param _neighborhood the neighborhood * @param _neighborhood the neighborhood
* @param _eval the evaluation function * @param _eval the evaluation function
* @param _neighborComparator a neighbor comparator * @param _neighborComparator a neighbor comparator
* @param _solNeighborComparator solution vs neighbor comparator * @param _solNeighborComparator solution vs neighbor comparator
*/ */
moSimpleHCexplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) { moSimpleHCexplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) {
isAccept = false; isAccept = false;
current=new Neighbor(); current=new Neighbor();
best=new Neighbor(); best=new Neighbor();
} }
/** /**
* Destructor * Destructor
*/ */
~moSimpleHCexplorer(){ ~moSimpleHCexplorer() {
delete current; delete current;
delete best; delete best;
} }
/** /**
* initParam: NOTHING TO DO * initParam: NOTHING TO DO
*/ */
virtual void initParam(EOT & solution){}; virtual void initParam(EOT & solution) {};
/** /**
* updateParam: NOTHING TO DO * updateParam: NOTHING TO DO
*/ */
virtual void updateParam(EOT & solution){}; virtual void updateParam(EOT & solution) {};
/** /**
* 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) {
//est qu'on peut initializer //est qu'on peut initializer
//Test if _solution has a Neighbor //Test if _solution has a Neighbor
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));
//initialize the best neighbor //initialize the best neighbor
(*best) = (*current); (*best) = (*current);
//test all others neighbors //test all others neighbors
while (neighborhood.cont(_solution)) { while (neighborhood.cont(_solution)) {
//next neighbor //next neighbor
neighborhood.next(_solution, (*current)); neighborhood.next(_solution, (*current));
//eval //eval
eval(_solution, (*current)); eval(_solution, (*current));
//if we found a better neighbor, update the best //if we found a better neighbor, update the best
if (neighborComparator((*best), (*current))) { if (neighborComparator((*best), (*current))) {
(*best) = (*current); (*best) = (*current);
} }
} }
} }
else{ else {
//if _solution hasn't neighbor, //if _solution hasn't neighbor,
isAccept=false; isAccept=false;
} }
}; };
/** /**
@ -131,7 +131,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 isAccept ;
}; };
/** /**
@ -139,10 +139,10 @@ 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 //move the solution
(*best).move(_solution); (*best).move(_solution);
//update its fitness //update its fitness
_solution.fitness((*best).fitness()); _solution.fitness((*best).fitness());
}; };
/** /**
@ -151,10 +151,10 @@ 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) {
if(neighborhood.hasNeighbor(_solution)){ if (neighborhood.hasNeighbor(_solution)) {
isAccept = solNeighborComparator(_solution, (*best)) ; isAccept = solNeighborComparator(_solution, (*best)) ;
} }
return isAccept; return isAccept;
}; };
/** /**
@ -162,7 +162,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 "moSimpleHCexplorer"; return "moSimpleHCexplorer";
} }
private: private:

View file

@ -54,91 +54,91 @@ public:
using moNeighborhoodExplorer<Neighborhood>::neighborhood; using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::eval; using moNeighborhoodExplorer<Neighborhood>::eval;
/** /**
* Constructor * Constructor
* @param _neighborhood the neighborhood * @param _neighborhood the neighborhood
* @param _eval the evaluation function * @param _eval the evaluation function
* @param _neighborComparator a neighbor comparator * @param _neighborComparator a neighbor comparator
* @param _solNeighborComparator solution vs neighbor comparator * @param _solNeighborComparator solution vs neighbor comparator
*/ */
moSimpleHCneutralExplorer(Neighborhood& _neighborhood, moSimpleHCneutralExplorer(Neighborhood& _neighborhood,
moEval<Neighbor>& _eval, moEval<Neighbor>& _eval,
moNeighborComparator<Neighbor>& _neighborComparator, moNeighborComparator<Neighbor>& _neighborComparator,
moSolNeighborComparator<Neighbor>& _solNeighborComparator) : moSolNeighborComparator<Neighbor>& _solNeighborComparator) :
moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval),
neighborComparator(_neighborComparator), neighborComparator(_neighborComparator),
solNeighborComparator(_solNeighborComparator) { solNeighborComparator(_solNeighborComparator) {
isAccept = false; isAccept = false;
current=new Neighbor(); current=new Neighbor();
} }
/** /**
* Destructor * Destructor
*/ */
~moSimpleHCneutralExplorer(){ ~moSimpleHCneutralExplorer() {
delete current; delete current;
} }
/** /**
* empty the vector of best solutions * empty the vector of best solutions
*/ */
virtual void initParam(EOT & solution){ virtual void initParam(EOT & solution) {
// delete all the best solutions // delete all the best solutions
bestVector.clear(); bestVector.clear();
}; };
/** /**
* empty the vector of best solutions * empty the vector of best solutions
*/ */
virtual void updateParam(EOT & solution){ virtual void updateParam(EOT & solution) {
// delete all the best solutions // delete all the best solutions
bestVector.clear(); bestVector.clear();
}; };
/** /**
* 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) {
//Test if _solution has a Neighbor //Test if _solution has a Neighbor
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));
//initialize the best neighbor //initialize the best neighbor
bestVector.push_back(*current); bestVector.push_back(*current);
//test all others neighbors //test all others neighbors
while (neighborhood.cont(_solution)) { while (neighborhood.cont(_solution)) {
//next neighbor //next neighbor
neighborhood.next(_solution, (*current)); neighborhood.next(_solution, (*current));
//eval //eval
eval(_solution, (*current)); eval(_solution, (*current));
//if we found a better neighbor, update the best //if we found a better neighbor, update the best
if (neighborComparator(bestVector[0], (*current))) { if (neighborComparator(bestVector[0], (*current))) {
bestVector.clear(); bestVector.clear();
bestVector.push_back(*current); bestVector.push_back(*current);
} }
else if (neighborComparator.equals((*current), bestVector[0])) //if the current is equals to previous best solutions then update vector of the best solution else if (neighborComparator.equals((*current), bestVector[0])) //if the current is equals to previous best solutions then update vector of the best solution
bestVector.push_back(*current); bestVector.push_back(*current);
} }
} }
else { else {
//if _solution hasn't neighbor, //if _solution hasn't neighbor,
isAccept=false; isAccept=false;
} }
}; };
/** /**
* continue if a move is accepted * continue if a move is accepted
@ -146,7 +146,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 isAccept ;
}; };
/** /**
@ -154,14 +154,14 @@ public:
* @param _solution the solution to move * @param _solution the solution to move
*/ */
virtual void move(EOT & _solution) { virtual void move(EOT & _solution) {
// choose randomly one of the best solutions // choose randomly one of the best solutions
unsigned int i = rng.random(bestVector.size()); unsigned int i = rng.random(bestVector.size());
//move the solution //move the solution
bestVector[i].move(_solution); bestVector[i].move(_solution);
//update its fitness //update its fitness
_solution.fitness(bestVector[i].fitness()); _solution.fitness(bestVector[i].fitness());
}; };
/** /**
@ -170,9 +170,9 @@ 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) {
if(neighborhood.hasNeighbor(_solution)) if (neighborhood.hasNeighbor(_solution))
isAccept = solNeighborComparator(_solution, bestVector[0]) ; isAccept = solNeighborComparator(_solution, bestVector[0]) ;
return isAccept; return isAccept;
}; };
protected: protected:

View file

@ -54,81 +54,81 @@ public:
typedef typename Neighborhood::EOT EOT ; typedef typename Neighborhood::EOT EOT ;
typedef typename Neighborhood::Neighbor Neighbor ; typedef typename Neighborhood::Neighbor Neighbor ;
/** /**
* Constructor * Constructor
* @param _neighborhood the neighborhood * @param _neighborhood the neighborhood
* @param _eval the evaluation function * @param _eval the 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
* @param _tabuList the tabu list * @param _tabuList the tabu list
* @param _intensification the intensification box * @param _intensification the intensification box
* @param _diversification the diversification box * @param _diversification the diversification box
* @param _aspiration the aspiration criteria * @param _aspiration the aspiration criteria
*/ */
moTSExplorer(Neighborhood& _neighborhood, moTSExplorer(Neighborhood& _neighborhood,
moEval<Neighbor>& _eval, moEval<Neighbor>& _eval,
moNeighborComparator<Neighbor>& _neighborComparator, moNeighborComparator<Neighbor>& _neighborComparator,
moSolNeighborComparator<Neighbor>& _solNeighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator,
moTabuList<Neighbor> & _tabuList, moTabuList<Neighbor> & _tabuList,
moIntensification<Neighbor> & _intensification, moIntensification<Neighbor> & _intensification,
moDiversification<Neighbor> & _diversification, moDiversification<Neighbor> & _diversification,
moAspiration<Neighbor> & _aspiration moAspiration<Neighbor> & _aspiration
) : ) :
moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator), moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator),
tabuList(_tabuList), intensification(_intensification), diversification(_diversification), aspiration(_aspiration) tabuList(_tabuList), intensification(_intensification), diversification(_diversification), aspiration(_aspiration)
{ {
isAccept = false; isAccept = false;
current=new Neighbor(); current=new Neighbor();
best=new Neighbor(); best=new Neighbor();
} }
/** /**
* Destructor * Destructor
*/ */
~moTSExplorer(){ ~moTSExplorer() {
delete current; delete current;
delete best; delete best;
} }
/** /**
* init tabu list, intensification box, diversification box and aspiration criteria * init tabu list, intensification box, diversification box and aspiration criteria
* @param _solution * @param _solution
*/ */
virtual void initParam(EOT& _solution) virtual void initParam(EOT& _solution)
{ {
tabuList.init(_solution); tabuList.init(_solution);
intensification.init(_solution); intensification.init(_solution);
diversification.init(_solution); diversification.init(_solution);
aspiration.init(_solution); aspiration.init(_solution);
bestSoFar=_solution; bestSoFar=_solution;
}; };
/** /**
* update params of tabu list, intensification box, diversification box and aspiration criteria * update params of tabu list, intensification box, diversification box and aspiration criteria
* @param _solution * @param _solution
*/ */
virtual void updateParam(EOT& _solution) virtual void updateParam(EOT& _solution)
{ {
if ((*this).moveApplied()){ if ((*this).moveApplied()) {
tabuList.add(_solution, *best); tabuList.add(_solution, *best);
intensification.add(_solution, *best); intensification.add(_solution, *best);
diversification.add(_solution, *best); diversification.add(_solution, *best);
if(_solution.fitness() > bestSoFar.fitness()) if (_solution.fitness() > bestSoFar.fitness())
bestSoFar = _solution; bestSoFar = _solution;
} }
tabuList.update(_solution, *best); tabuList.update(_solution, *best);
intensification.update(_solution, *best); intensification.update(_solution, *best);
diversification.update(_solution, *best); diversification.update(_solution, *best);
aspiration.update(_solution, *best); aspiration.update(_solution, *best);
}; };
/** /**
* terminate : _solution becomes the best so far * terminate : _solution becomes the best so far
*/ */
virtual void terminate(EOT & _solution){ virtual void terminate(EOT & _solution) {
_solution= bestSoFar; _solution= bestSoFar;
}; };
@ -138,56 +138,56 @@ public:
*/ */
virtual void operator()(EOT & _solution) virtual void operator()(EOT & _solution)
{ {
bool found=false; bool found=false;
intensification(_solution); intensification(_solution);
diversification(_solution); diversification(_solution);
if(neighborhood.hasNeighbor(_solution)) if (neighborhood.hasNeighbor(_solution))
{ {
//init the current neighbor //init the current neighbor
neighborhood.init(_solution, *current); neighborhood.init(_solution, *current);
//eval the current neighbor //eval the current neighbor
eval(_solution, *current); eval(_solution, *current);
//Find the first non-tabu element //Find the first non-tabu element
if ( (!tabuList.check(_solution, *current)) || aspiration(_solution, *current) ){ if ( (!tabuList.check(_solution, *current)) || aspiration(_solution, *current) ) {
// set best // set best
(*best)= (*current); (*best)= (*current);
found=true; found=true;
} }
while(neighborhood.cont(_solution) && !found){ while (neighborhood.cont(_solution) && !found) {
//next neighbor //next neighbor
neighborhood.next(_solution, (*current)); neighborhood.next(_solution, (*current));
//eval //eval
eval(_solution, (*current)); eval(_solution, (*current));
if ( (!tabuList.check(_solution, *current)) || aspiration(_solution, *current) ){ if ( (!tabuList.check(_solution, *current)) || aspiration(_solution, *current) ) {
// set best // set best
(*best)=(*current); (*best)=(*current);
found=true; found=true;
} }
} }
//Explore the neighborhood //Explore the neighborhood
if(found){ if (found) {
isAccept=true; isAccept=true;
while(neighborhood.cont(_solution)){ while (neighborhood.cont(_solution)) {
//next neighbor //next neighbor
neighborhood.next(_solution, (*current)); neighborhood.next(_solution, (*current));
//eval //eval
eval(_solution, (*current)); eval(_solution, (*current));
//check if the current is better than the best and is not tabu or if it is aspirat (by the aspiration criteria of course) //check if the current is better than the best and is not tabu or if it is aspirat (by the aspiration criteria of course)
if ( (!tabuList.check(_solution, *current) || aspiration(_solution, (*current))) && neighborComparator((*best),(*current))){ if ( (!tabuList.check(_solution, *current) || aspiration(_solution, (*current))) && neighborComparator((*best),(*current))) {
// set best // set best
(*best)=(*current); (*best)=(*current);
} }
} }
} }
else{ else {
isAccept=false; isAccept=false;
} }
} }
else{ else {
isAccept=false; isAccept=false;
} }
}; };
@ -196,8 +196,8 @@ public:
* @param _solution the solution * @param _solution the solution
* @return true * @return true
*/ */
virtual bool isContinue(EOT & _solution){ virtual bool isContinue(EOT & _solution) {
return true; return true;
}; };
@ -206,10 +206,10 @@ 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 //move the solution
best->move(_solution); best->move(_solution);
//update its fitness //update its fitness
_solution.fitness(best->fitness()); _solution.fitness(best->fitness());
}; };
@ -218,8 +218,8 @@ public:
* @param _solution the solution * @param _solution the solution
* @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 isAccept; return isAccept;
}; };
@ -236,11 +236,11 @@ protected:
// Tabu components // Tabu components
moTabuList<Neighbor> & tabuList; moTabuList<Neighbor> & tabuList;
moIntensification<Neighbor> & intensification; moIntensification<Neighbor> & intensification;
moDiversification<Neighbor> & diversification; moDiversification<Neighbor> & diversification;
moAspiration<Neighbor> & aspiration; moAspiration<Neighbor> & aspiration;
//Current and best neighbor //Current and best neighbor
Neighbor* best; Neighbor* best;
Neighbor* current; Neighbor* current;
//Best so far Solution //Best so far Solution

View file

@ -10,10 +10,10 @@ template< class Neighbor >
class moAspiration : public eoBF<typename Neighbor::EOT &, Neighbor &, bool> class moAspiration : public eoBF<typename Neighbor::EOT &, Neighbor &, bool>
{ {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
virtual void init(EOT & _sol) = 0; virtual void init(EOT & _sol) = 0;
virtual void update(EOT & _sol, Neighbor & _neighbor) = 0; virtual void update(EOT & _sol, Neighbor & _neighbor) = 0;
}; };
#endif #endif

View file

@ -11,47 +11,47 @@ class moBestImprAspiration : public moAspiration<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
/** /**
* init the best solution * init the best solution
* @param _sol the best solution found * @param _sol the best solution found
*/ */
void init(EOT & _sol){ void init(EOT & _sol) {
bestFoundSoFar = _sol; bestFoundSoFar = _sol;
} }
/** /**
* update the "bestFoundSoFar" if a best solution is found * update the "bestFoundSoFar" if a best solution is found
* @param _sol a solution * @param _sol a solution
* @param _neighbor a neighbor * @param _neighbor a neighbor
*/ */
void update(EOT & _sol, Neighbor & _neighbor){ void update(EOT & _sol, Neighbor & _neighbor) {
if (bestFoundSoFar.fitness() < _sol.fitness()) if (bestFoundSoFar.fitness() < _sol.fitness())
bestFoundSoFar = _sol; bestFoundSoFar = _sol;
} }
/** /**
* Test the tabu feature of the neighbor: * Test the tabu feature of the neighbor:
* test if the neighbor's fitness is better than the "bestFoundSoFar" fitness * test if the neighbor's fitness is better than the "bestFoundSoFar" fitness
* @param _sol a solution * @param _sol a solution
* @param _neighbor a neighbor * @param _neighbor a neighbor
* @return true if _neighbor fitness is better than the "bestFoundSoFar" * @return true if _neighbor fitness is better than the "bestFoundSoFar"
*/ */
bool operator()(EOT & _sol, Neighbor & _neighbor){ bool operator()(EOT & _sol, Neighbor & _neighbor) {
return (bestFoundSoFar.fitness() < _neighbor.fitness()); return (bestFoundSoFar.fitness() < _neighbor.fitness());
} }
/** /**
* Getter * Getter
* @return a reference on the best found so far solution * @return a reference on the best found so far solution
*/ */
EOT& getBest(){ EOT& getBest() {
return bestFoundSoFar; return bestFoundSoFar;
} }
private: private:
EOT bestFoundSoFar; EOT bestFoundSoFar;
}; };
#endif #endif

View file

@ -9,6 +9,6 @@
*/ */
template< class Neighbor > template< class Neighbor >
class moDiversification : public moMemory<Neighbor>, public eoUF<typename Neighbor::EOT &,bool> class moDiversification : public moMemory<Neighbor>, public eoUF<typename Neighbor::EOT &,bool>
{}; {};
#endif #endif

View file

@ -10,34 +10,34 @@ template< class Neighbor >
class moDummyDiversification : public moDiversification<Neighbor> class moDummyDiversification : public moDiversification<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
/** /**
* Init : NOTHIING TO DO * Init : NOTHIING TO DO
*/ */
void init(EOT & _sol) {} void init(EOT & _sol) {}
/** /**
* Add : NOTHIING TO DO * Add : NOTHIING TO DO
*/ */
void add(EOT & _sol, Neighbor & _neighbor) {} void add(EOT & _sol, Neighbor & _neighbor) {}
/** /**
* Update : NOTHIING TO DO * Update : NOTHIING TO DO
*/ */
void update(EOT & _sol, Neighbor & _neighbor) {} void update(EOT & _sol, Neighbor & _neighbor) {}
/** /**
* ClearMemory : NOTHIING TO DO * ClearMemory : NOTHIING TO DO
*/ */
void clearMemory() {} void clearMemory() {}
/** /**
* @return always false * @return always false
*/ */
bool operator()(EOT &){ bool operator()(EOT &) {
return false; return false;
} }
}; };
#endif #endif

View file

@ -10,34 +10,34 @@ template< class Neighbor >
class moDummyIntensification : public moIntensification<Neighbor> class moDummyIntensification : public moIntensification<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
/** /**
* Init : NOTHIING TO DO * Init : NOTHIING TO DO
*/ */
void init(EOT & _sol) {} void init(EOT & _sol) {}
/** /**
* Add : NOTHIING TO DO * Add : NOTHIING TO DO
*/ */
void add(EOT & _sol, Neighbor & _neighbor) {} void add(EOT & _sol, Neighbor & _neighbor) {}
/** /**
* Update : NOTHIING TO DO * Update : NOTHIING TO DO
*/ */
void update(EOT & _sol, Neighbor & _neighbor) {} void update(EOT & _sol, Neighbor & _neighbor) {}
/** /**
* ClearMemory : NOTHIING TO DO * ClearMemory : NOTHIING TO DO
*/ */
void clearMemory() {} void clearMemory() {}
/** /**
* @return always false * @return always false
*/ */
bool operator()(EOT &){ bool operator()(EOT &) {
return false; return false;
} }
}; };
#endif #endif

View file

@ -9,6 +9,6 @@
*/ */
template< class Neighbor > template< class Neighbor >
class moIntensification : public moMemory<Neighbor>, public eoUF<typename Neighbor::EOT &,bool> class moIntensification : public moMemory<Neighbor>, public eoUF<typename Neighbor::EOT &,bool>
{}; {};
#endif #endif

View file

@ -8,32 +8,32 @@ template< class Neighbor >
class moMemory //: public eoObject class moMemory //: public eoObject
{ {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
/** /**
* Init the memory * Init the memory
* @param _sol the current solution * @param _sol the current solution
*/ */
virtual void init(EOT & _sol) = 0; virtual void init(EOT & _sol) = 0;
/** /**
* Add data in the memory * Add data in the memory
* @param _sol the current solution * @param _sol the current solution
* @param _neighbor the current neighbor * @param _neighbor the current neighbor
*/ */
virtual void add(EOT & _sol, Neighbor & _neighbor) = 0; virtual void add(EOT & _sol, Neighbor & _neighbor) = 0;
/** /**
* update the memory * update the memory
* @param _sol the current solution * @param _sol the current solution
* @param _neighbor the current neighbor * @param _neighbor the current neighbor
*/ */
virtual void update(EOT & _sol, Neighbor & _neighbor) = 0; virtual void update(EOT & _sol, Neighbor & _neighbor) = 0;
/** /**
* clear the memory * clear the memory
*/ */
virtual void clearMemory() = 0; virtual void clearMemory() = 0;
}; };

View file

@ -12,91 +12,91 @@ template<class Neighbor >
class moSolVectorTabuList : public moTabuList<Neighbor> class moSolVectorTabuList : public moTabuList<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
/** /**
* Constructor * Constructor
* @param _maxSize maximum size of the tabu list * @param _maxSize maximum size of the tabu list
* @param _howlong how many iteration a move is tabu * @param _howlong how many iteration a move is tabu
*/ */
moSolVectorTabuList(unsigned int _maxSize, unsigned int _howlong) : maxSize(_maxSize), howlong(_howlong){ moSolVectorTabuList(unsigned int _maxSize, unsigned int _howlong) : maxSize(_maxSize), howlong(_howlong) {
tabuList.reserve(_maxSize); tabuList.reserve(_maxSize);
tabuList.resize(0); tabuList.resize(0);
} }
/** /**
* init the tabuList by clearing the memory * init the tabuList by clearing the memory
* @param _sol the current solution * @param _sol the current solution
*/ */
virtual void init(EOT & _sol){ virtual void init(EOT & _sol) {
clearMemory(); clearMemory();
} }
/** /**
* add a new solution in the tabuList * add a new solution in the tabuList
* @param _sol the current solution * @param _sol the current solution
* @param _neighbor the current neighbor (unused) * @param _neighbor the current neighbor (unused)
*/ */
virtual void add(EOT & _sol, Neighbor & _neighbor){ virtual void add(EOT & _sol, Neighbor & _neighbor) {
if(tabuList.size() < maxSize){ if (tabuList.size() < maxSize) {
std::pair<EOT, unsigned int> tmp; std::pair<EOT, unsigned int> tmp;
tmp.first=_sol; tmp.first=_sol;
tmp.second=howlong; tmp.second=howlong;
tabuList.push_back(tmp); tabuList.push_back(tmp);
} }
else{ else {
tabuList[index%maxSize].first = _sol; tabuList[index%maxSize].first = _sol;
tabuList[index%maxSize].second = howlong; tabuList[index%maxSize].second = howlong;
index++; index++;
} }
} }
/** /**
* update the tabulist: NOTHING TO DO * update the tabulist: NOTHING TO DO
* @param _sol the current solution * @param _sol the current solution
* @param _neighbor the current neighbor (unused) * @param _neighbor the current neighbor (unused)
*/ */
virtual void update(EOT & _sol, Neighbor & _neighbor){ virtual void update(EOT & _sol, Neighbor & _neighbor) {
for(unsigned int i=0; i<tabuList.size(); i++) for (unsigned int i=0; i<tabuList.size(); i++)
tabuList[i].second--; tabuList[i].second--;
} }
/** /**
* check if the solution is tabu * check if the solution is tabu
* @param _sol the current solution * @param _sol the current solution
* @param _neighbor the current neighbor (unused) * @param _neighbor the current neighbor (unused)
* @return true if tabuList contains _sol * @return true if tabuList contains _sol
*/ */
virtual bool check(EOT & _sol, Neighbor & _neighbor){ virtual bool check(EOT & _sol, Neighbor & _neighbor) {
EOT tmp=_sol; EOT tmp=_sol;
_neighbor.move(tmp); _neighbor.move(tmp);
for(unsigned int i=0; i<tabuList.size(); i++){ for (unsigned int i=0; i<tabuList.size(); i++) {
if ((howlong > 0 && tabuList[i].second > 0 && tabuList[i].first == tmp) || (howlong==0 && tabuList[i].first==tmp)) if ((howlong > 0 && tabuList[i].second > 0 && tabuList[i].first == tmp) || (howlong==0 && tabuList[i].first==tmp))
return true; return true;
} }
return false; return false;
} }
/** /**
* clearMemory: remove all solution of the tabuList * clearMemory: remove all solution of the tabuList
*/ */
virtual void clearMemory(){ virtual void clearMemory() {
tabuList.resize(0); tabuList.resize(0);
index = 0; index = 0;
} }
private: private:
//tabu list //tabu list
std::vector< std::pair<EOT, unsigned int> > tabuList; std::vector< std::pair<EOT, unsigned int> > tabuList;
//maximum size of the tabu list //maximum size of the tabu list
unsigned int maxSize; unsigned int maxSize;
//how many iteration a move is tabu //how many iteration a move is tabu
unsigned int howlong; unsigned int howlong;
//index on the tabulist //index on the tabulist
unsigned long index; unsigned long index;
}; };

View file

@ -10,15 +10,15 @@ template< class Neighbor >
class moTabuList : public moMemory<Neighbor> class moTabuList : public moMemory<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
/** /**
* Check if a neighbor is tabu or not * Check if a neighbor is tabu or not
* @param _sol the current solution * @param _sol the current solution
* @param _neighbor the neighbor * @param _neighbor the neighbor
* @return true if the neighbor is tabu * @return true if the neighbor is tabu
*/ */
virtual bool check(EOT & _sol, Neighbor & _neighbor) = 0; virtual bool check(EOT & _sol, Neighbor & _neighbor) = 0;
}; };
#endif #endif

View file

@ -45,10 +45,10 @@ class moBackableNeighbor : virtual public moNeighbor<EOT, Fitness>
{ {
public: public:
/** /**
* the move back function * the move back function
* @param _solution the solution to moveBack * @param _solution the solution to moveBack
*/ */
virtual void moveBack(EOT & _solution)=0; virtual void moveBack(EOT & _solution)=0;
}; };

View file

@ -56,7 +56,7 @@ public:
* @param _solution the solution to move * @param _solution the solution to move
*/ */
virtual void move(EOT & _solution) { virtual void move(EOT & _solution) {
_solution[key] = !_solution[key]; _solution[key] = !_solution[key];
} }
/** /**
@ -64,7 +64,7 @@ public:
* @param _solution the solution to move back * @param _solution the solution to move back
*/ */
virtual void moveBack(EOT & _solution) { virtual void moveBack(EOT & _solution) {
_solution[key] = !_solution[key]; _solution[key] = !_solution[key];
} }
/** /**
@ -72,39 +72,39 @@ 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 "moBitNeighbor"; return "moBitNeighbor";
} }
/** /**
* Read object.\ \ * Read object.\ \
* Calls base class, just in case that one had something to do. * Calls base class, just in case that one had something to do.
* The read and print methods should be compatible and have the same format. * The read and print methods should be compatible and have the same format.
* In principle, format is "plain": they just print a number * In principle, format is "plain": they just print a number
* @param _is a std::istream. * @param _is a std::istream.
* @throw runtime_std::exception If a valid object can't be read. * @throw runtime_std::exception If a valid object can't be read.
*/ */
virtual void readFrom(std::istream& _is) { virtual void readFrom(std::istream& _is) {
std::string fitness_str; std::string fitness_str;
int pos = _is.tellg(); int pos = _is.tellg();
_is >> fitness_str; _is >> fitness_str;
if (fitness_str == "INVALID"){ if (fitness_str == "INVALID") {
throw std::runtime_error("invalid fitness"); throw std::runtime_error("invalid fitness");
} }
else{ else {
Fitness repFit ; Fitness repFit ;
_is.seekg(pos); // rewind _is.seekg(pos); // rewind
_is >> repFit; _is >> repFit;
_is >> key; _is >> key;
fitness(repFit); fitness(repFit);
} }
} }
/** /**
* Write object. Called printOn since it prints the object _on_ a stream. * Write object. Called printOn since it prints the object _on_ a stream.
* @param _os A std::ostream. * @param _os A std::ostream.
*/ */
virtual void printOn(std::ostream& _os) const { virtual void printOn(std::ostream& _os) const {
_os << fitness() << ' ' << key << std::endl; _os << fitness() << ' ' << key << std::endl;
} }
}; };

View file

@ -50,22 +50,22 @@ public:
/** /**
* Default Constructor * Default Constructor
*/ */
moIndexNeighbor() : moNeighbor<EOT, Fitness>(), key(0){} moIndexNeighbor() : moNeighbor<EOT, Fitness>(), key(0) {}
/** /**
* Copy Constructor * Copy Constructor
*/ */
moIndexNeighbor(const moIndexNeighbor& _n) : moNeighbor<EOT, Fitness>(_n) { moIndexNeighbor(const moIndexNeighbor& _n) : moNeighbor<EOT, Fitness>(_n) {
this->key = _n.key ; this->key = _n.key ;
} }
/** /**
* Assignment operator * Assignment operator
*/ */
virtual moIndexNeighbor<EOT, Fitness> & operator=(const moIndexNeighbor<EOT, Fitness> & _source) { virtual moIndexNeighbor<EOT, Fitness> & operator=(const moIndexNeighbor<EOT, Fitness> & _source) {
moNeighbor<EOT, Fitness>::operator=(_source); moNeighbor<EOT, Fitness>::operator=(_source);
this->key = _source.key ; this->key = _source.key ;
return *this ; return *this ;
} }
/** /**
@ -73,23 +73,23 @@ 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 "moIndexNeighbor"; return "moIndexNeighbor";
} }
/** /**
* Getter * Getter
* @return index of the IndexNeighbor * @return index of the IndexNeighbor
*/ */
unsigned int index(){ unsigned int index() {
return key; return key;
} }
/** /**
* Setter * Setter
* @param _key index of the IndexNeighbor * @param _key index of the IndexNeighbor
*/ */
void index(unsigned int _key){ void index(unsigned int _key) {
key=_key; key=_key;
} }
protected: protected:

View file

@ -44,23 +44,23 @@ template< class Neighbor >
class moIndexNeighborhood : virtual public moNeighborhood<Neighbor> class moIndexNeighborhood : virtual public moNeighborhood<Neighbor>
{ {
public: public:
/** /**
* Define type of a solution corresponding to Neighbor * Define type of a solution corresponding to Neighbor
*/ */
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
/** /**
* Constructor * Constructor
* @param _neighborhoodSize the size of the neighborhood * @param _neighborhoodSize the size of the neighborhood
*/ */
moIndexNeighborhood(unsigned int _neighborhoodSize):neighborhoodSize(_neighborhoodSize){} moIndexNeighborhood(unsigned int _neighborhoodSize):neighborhoodSize(_neighborhoodSize) {}
/** /**
* Return the class id. * Return the class id.
* @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 "moIndexNeighborhood"; return "moIndexNeighborhood";
} }
protected: protected:

View file

@ -47,18 +47,18 @@ template< class EOType , class Fitness >
class moNeighbor : public eoObject, public eoPersistent class moNeighbor : public eoObject, public eoPersistent
{ {
public: public:
typedef EOType EOT; typedef EOType EOT;
/** /**
* Default Constructor * Default Constructor
*/ */
moNeighbor(){} moNeighbor() {}
/** /**
* Copy Constructor * Copy Constructor
* @param _neighbor to copy * @param _neighbor to copy
*/ */
moNeighbor(const moNeighbor<EOT, Fitness>& _neighbor) { moNeighbor(const moNeighbor<EOT, Fitness>& _neighbor) {
repFitness = _neighbor.fitness(); repFitness = _neighbor.fitness();
} }
/** /**
@ -67,8 +67,8 @@ public:
* @return a neighbor equal to the other * @return a neighbor equal to the other
*/ */
virtual moNeighbor<EOT, Fitness>& operator=(const moNeighbor<EOT, Fitness>& _neighbor) { virtual moNeighbor<EOT, Fitness>& operator=(const moNeighbor<EOT, Fitness>& _neighbor) {
repFitness = _neighbor.fitness(); repFitness = _neighbor.fitness();
return (*this); return (*this);
} }
/** /**
@ -82,7 +82,7 @@ public:
* @return fitness of the neighbor * @return fitness of the neighbor
*/ */
const Fitness fitness() const { const Fitness fitness() const {
return repFitness; return repFitness;
} }
@ -91,22 +91,24 @@ public:
* @return fitness as reference of the neighbor * @return fitness as reference of the neighbor
*/ */
Fitness& fitnessReference() { Fitness& fitnessReference() {
return repFitness; return repFitness;
} }
/** /**
* Set fitness. At the same time, validates it. * Set fitness. At the same time, validates it.
* @param _fitness new fitness value. * @param _fitness new fitness value.
*/ */
void fitness(const Fitness& _fitness){ void fitness(const Fitness& _fitness) {
repFitness = _fitness; repFitness = _fitness;
} }
/** /**
* Return the class id. * Return the class id.
* @return the class name as a std::string * @return the class name as a std::string
*/ */
virtual std::string className() const { return "moNeighbor"; } virtual std::string className() const {
return "moNeighbor";
}
/** /**
* Read object. * Read object.
@ -116,7 +118,7 @@ public:
* @param _is a std::istream. * @param _is a std::istream.
*/ */
virtual void readFrom(std::istream& _is) { virtual void readFrom(std::istream& _is) {
_is >> repFitness; _is >> repFitness;
} }
/** /**
@ -124,7 +126,7 @@ public:
* @param _os A std::ostream. * @param _os A std::ostream.
*/ */
virtual void printOn(std::ostream& _os) const { virtual void printOn(std::ostream& _os) const {
_os << repFitness << std::endl; _os << repFitness << std::endl;
} }
protected: protected:

View file

@ -44,21 +44,21 @@ template< class Neighbor >
class moNeighborhood : public eoObject class moNeighborhood : public eoObject
{ {
public: public:
/** /**
* Define type of a solution corresponding to Neighbor * Define type of a solution corresponding to Neighbor
*/ */
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
/** /**
* Default Constructor * Default Constructor
*/ */
moNeighborhood(){} moNeighborhood() {}
/** /**
* @return if the neighborhood is random * @return if the neighborhood is random
*/ */
virtual bool isRandom(){ virtual bool isRandom() {
return false; return false;
} }
/** /**
@ -94,7 +94,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 "moNeighborhood"; return "moNeighborhood";
} }
}; };

View file

@ -45,21 +45,21 @@ class moOrderNeighborhood : public moIndexNeighborhood<N>
{ {
public: public:
/** /**
* Define type of a solution corresponding to Neighbor * Define type of a solution corresponding to Neighbor
*/ */
typedef N Neighbor; typedef N Neighbor;
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
using moIndexNeighborhood<Neighbor>::neighborhoodSize; using moIndexNeighborhood<Neighbor>::neighborhoodSize;
/** /**
* Constructor * Constructor
* @param _neighborhoodSize the size of the neighborhood * @param _neighborhoodSize the size of the neighborhood
*/ */
moOrderNeighborhood(unsigned int _neighborhoodSize): moIndexNeighborhood<Neighbor>(_neighborhoodSize), currentIndex(0){} moOrderNeighborhood(unsigned int _neighborhoodSize): moIndexNeighborhood<Neighbor>(_neighborhoodSize), currentIndex(0) {}
/** /**
* Test if it exist a neighbor * Test if it exist a neighbor
@ -67,7 +67,7 @@ public:
* @return true if the neighborhood was not empty * @return true if the neighborhood was not empty
*/ */
virtual bool hasNeighbor(EOT& _solution) { virtual bool hasNeighbor(EOT& _solution) {
return neighborhoodSize > 0; return neighborhoodSize > 0;
} }
/** /**
@ -76,8 +76,8 @@ public:
* @param _neighbor the first neighbor * @param _neighbor the first neighbor
*/ */
virtual void init(EOT & _solution, Neighbor & _neighbor) { virtual void init(EOT & _solution, Neighbor & _neighbor) {
currentIndex = 0 ; currentIndex = 0 ;
_neighbor.index(currentIndex) ; _neighbor.index(currentIndex) ;
} }
/** /**
@ -86,8 +86,8 @@ public:
* @param _neighbor the next neighbor * @param _neighbor the next neighbor
*/ */
virtual void next(EOT & _solution, Neighbor & _neighbor) { virtual void next(EOT & _solution, Neighbor & _neighbor) {
currentIndex++ ; currentIndex++ ;
_neighbor.index(currentIndex); _neighbor.index(currentIndex);
} }
/** /**
@ -98,15 +98,15 @@ public:
* @return true if there is again a neighbor to explore * @return true if there is again a neighbor to explore
*/ */
virtual bool cont(EOT & _solution) { virtual bool cont(EOT & _solution) {
return (currentIndex < neighborhoodSize - 1) ; return (currentIndex < neighborhoodSize - 1) ;
} }
/** /**
* Getter * Getter
* @return the position in the Neighborhood * @return the position in the Neighborhood
*/ */
unsigned int position(){ unsigned int position() {
return currentIndex; return currentIndex;
} }
/** /**
@ -114,7 +114,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 "moOrderNeighborhood"; return "moOrderNeighborhood";
} }
private: private:

View file

@ -33,13 +33,13 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <neighborhood/moNeighborhood.h> #include <neighborhood/moNeighborhood.h>
template< class Neighbor > template< class Neighbor >
class moRndNeighborhood : virtual public moNeighborhood<Neighbor>{ class moRndNeighborhood : virtual public moNeighborhood<Neighbor> {
public: public:
bool isRandom(){ bool isRandom() {
return true; return true;
} }
}; };
#endif #endif

View file

@ -47,20 +47,20 @@ class moRndWithReplNeighborhood : public moIndexNeighborhood<N>, public moRndNei
{ {
public: public:
/** /**
* Define type of a solution corresponding to Neighbor * Define type of a solution corresponding to Neighbor
*/ */
typedef N Neighbor; typedef N Neighbor;
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
using moIndexNeighborhood<Neighbor>::neighborhoodSize; using moIndexNeighborhood<Neighbor>::neighborhoodSize;
/** /**
* Constructor * Constructor
* @param _neighborhoodSize the size of the neighborhood * @param _neighborhoodSize the size of the neighborhood
*/ */
moRndWithReplNeighborhood(unsigned int _neighborhoodSize): moIndexNeighborhood<Neighbor>(_neighborhoodSize){} moRndWithReplNeighborhood(unsigned int _neighborhoodSize): moIndexNeighborhood<Neighbor>(_neighborhoodSize) {}
/** /**
* Test if it exist a neighbor * Test if it exist a neighbor
@ -68,7 +68,7 @@ public:
* @return true if the neighborhood was not empty * @return true if the neighborhood was not empty
*/ */
virtual bool hasNeighbor(EOT& _solution) { virtual bool hasNeighbor(EOT& _solution) {
return neighborhoodSize > 0; return neighborhoodSize > 0;
} }
/** /**
@ -77,7 +77,7 @@ public:
* @param _neighbor the first neighbor * @param _neighbor the first neighbor
*/ */
virtual void init(EOT & _solution, Neighbor & _neighbor) { virtual void init(EOT & _solution, Neighbor & _neighbor) {
_neighbor.index(rng.random(neighborhoodSize)); _neighbor.index(rng.random(neighborhoodSize));
} }
/** /**
@ -86,7 +86,7 @@ public:
* @param _neighbor the next neighbor * @param _neighbor the next neighbor
*/ */
virtual void next(EOT & _solution, Neighbor & _neighbor) { virtual void next(EOT & _solution, Neighbor & _neighbor) {
_neighbor.index(rng.random(neighborhoodSize)); _neighbor.index(rng.random(neighborhoodSize));
} }
/** /**
@ -95,7 +95,7 @@ public:
* @return true if there is again a neighbor to explore * @return true if there is again a neighbor to explore
*/ */
virtual bool cont(EOT & _solution) { virtual bool cont(EOT & _solution) {
return neighborhoodSize > 0; return neighborhoodSize > 0;
} }
/** /**
@ -103,7 +103,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 "moRndWithReplNeighborhood"; return "moRndWithReplNeighborhood";
} }
}; };

View file

@ -47,22 +47,22 @@ class moRndWithoutReplNeighborhood : public moIndexNeighborhood<N>, public moRnd
{ {
public: public:
/** /**
* Define type of a solution corresponding to Neighbor * Define type of a solution corresponding to Neighbor
*/ */
typedef N Neighbor; typedef N Neighbor;
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
using moIndexNeighborhood<Neighbor>::neighborhoodSize; using moIndexNeighborhood<Neighbor>::neighborhoodSize;
/** /**
* Constructor * Constructor
* @param _neighborhoodSize the size of the neighborhood * @param _neighborhoodSize the size of the neighborhood
*/ */
moRndWithoutReplNeighborhood(unsigned int _neighborhoodSize): moIndexNeighborhood<Neighbor>(_neighborhoodSize), maxIndex(0){ moRndWithoutReplNeighborhood(unsigned int _neighborhoodSize): moIndexNeighborhood<Neighbor>(_neighborhoodSize), maxIndex(0) {
for(unsigned int i=0; i < neighborhoodSize; i++) for (unsigned int i=0; i < neighborhoodSize; i++)
indexVector.push_back(i); indexVector.push_back(i);
} }
/** /**
@ -71,7 +71,7 @@ public:
* @return true if the neighborhood was not empty * @return true if the neighborhood was not empty
*/ */
virtual bool hasNeighbor(EOT& _solution) { virtual bool hasNeighbor(EOT& _solution) {
return neighborhoodSize > 0; return neighborhoodSize > 0;
} }
/** /**
@ -80,14 +80,14 @@ public:
* @param _neighbor the first neighbor * @param _neighbor the first neighbor
*/ */
virtual void init(EOT & _solution, Neighbor & _neighbor) { virtual void init(EOT & _solution, Neighbor & _neighbor) {
unsigned int i, tmp; unsigned int i, tmp;
maxIndex = neighborhoodSize ; maxIndex = neighborhoodSize ;
i = rng.random(maxIndex); i = rng.random(maxIndex);
_neighbor.index(indexVector[i]); _neighbor.index(indexVector[i]);
tmp=indexVector[i]; tmp=indexVector[i];
indexVector[i]=indexVector[maxIndex-1]; indexVector[i]=indexVector[maxIndex-1];
indexVector[maxIndex-1]=tmp; indexVector[maxIndex-1]=tmp;
maxIndex--; maxIndex--;
} }
/** /**
@ -96,13 +96,13 @@ public:
* @param _neighbor the next neighbor * @param _neighbor the next neighbor
*/ */
virtual void next(EOT & _solution, Neighbor & _neighbor) { virtual void next(EOT & _solution, Neighbor & _neighbor) {
unsigned int i, tmp; unsigned int i, tmp;
i = rng.random(maxIndex); i = rng.random(maxIndex);
_neighbor.index(indexVector[i]); _neighbor.index(indexVector[i]);
tmp=indexVector[i]; tmp=indexVector[i];
indexVector[i]=indexVector[maxIndex-1]; indexVector[i]=indexVector[maxIndex-1];
indexVector[maxIndex-1]=tmp; indexVector[maxIndex-1]=tmp;
maxIndex--; maxIndex--;
} }
/** /**
@ -112,15 +112,15 @@ public:
* @return true if there is again a neighbor to explore * @return true if there is again a neighbor to explore
*/ */
virtual bool cont(EOT & _solution) { virtual bool cont(EOT & _solution) {
return (maxIndex > 0) ; return (maxIndex > 0) ;
} }
/** /**
* Getter * Getter
* @return the position in the Neighborhood * @return the position in the Neighborhood
*/ */
unsigned int position(){ unsigned int position() {
return indexVector[maxIndex]; return indexVector[maxIndex];
} }
/** /**
@ -128,7 +128,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 "moRndWithoutReplNeighborhood"; return "moRndWithoutReplNeighborhood";
} }
private: private:

View file

@ -12,22 +12,22 @@ template<class MoveNeighbor, class M>
class moIncrEvalWrapper : public moEval<MoveNeighbor> class moIncrEvalWrapper : public moEval<MoveNeighbor>
{ {
public: public:
using moEval<BackableNeighbor>::EOT EOT; using moEval<BackableNeighbor>::EOT EOT;
using moEval<BackableNeighbor>::Fitness Fitness; using moEval<BackableNeighbor>::Fitness Fitness;
moIncrEvalWrapper(moIncrEval<M>& _incr):incr(_incr){} moIncrEvalWrapper(moIncrEval<M>& _incr):incr(_incr) {}
/* /*
* make the evaluation of the current neighbor and update the information on this neighbor * make the evaluation of the current neighbor and update the information on this neighbor
* the evaluation could be incremental * the evaluation could be incremental
*/ */
virtual void eval(MoveNeighbor& _neighbor,EOT & _solution){ virtual void eval(MoveNeighbor& _neighbor,EOT & _solution) {
_neighbor.fitness(incrEval(*(_neighbor.getMove()), _solution)); _neighbor.fitness(incrEval(*(_neighbor.getMove()), _solution));
} }
private: private:
/** the full evaluation object */ /** the full evaluation object */
moIncrEval<M> & incrEval; moIncrEval<M> & incrEval;
}; };

View file

@ -48,10 +48,10 @@
template < class EOT > template < class EOT >
class moMove:public eoUF < EOT &, void > class moMove:public eoUF < EOT &, void >
{ {
public: public:
// Alias for the type // Alias for the type
typedef EOT EOType; typedef EOT EOType;
}; };
#endif #endif

View file

@ -47,6 +47,6 @@
*/ */
template < class M, class Objective = typename M::EOType::Fitness> template < class M, class Objective = typename M::EOType::Fitness>
class moMoveIncrEval:public eoBF < const M &, const typename M::EOType &, Objective > class moMoveIncrEval:public eoBF < const M &, const typename M::EOType &, Objective >
{}; {};
#endif #endif

View file

@ -45,6 +45,6 @@
*/ */
template < class M > template < class M >
class moMoveInit:public eoBF < M &, const typename M::EOType &, void > class moMoveInit:public eoBF < M &, const typename M::EOType &, void >
{}; {};
#endif #endif

View file

@ -12,52 +12,54 @@
contener of the neighbor informations contener of the neighbor informations
*/ */
template< class M , class Fitness > template< class M , class Fitness >
class moMoveNeighbor : public moNeighbor <typename M::EOType, Fitness> class moMoveNeighbor : public moNeighbor <typename M::EOType, Fitness>
{ {
public: public:
typedef typename M::EOType EOT; typedef typename M::EOType EOT;
// empty constructor // empty constructor
moMoveNeighbor() { moMoveNeighbor() {
move=new M(); move=new M();
}; };
~moMoveNeighbor() { ~moMoveNeighbor() {
delete move; delete move;
}; };
// copy constructeur // copy constructeur
moMoveNeighbor(const moMoveNeighbor<M, Fitness> & _n) { moMoveNeighbor(const moMoveNeighbor<M, Fitness> & _n) {
moNeighbor<EOT, Fitness>::operator=(_n); moNeighbor<EOT, Fitness>::operator=(_n);
(*move) = *(_n.getMove()); (*move) = *(_n.getMove());
} }
// assignment operator // assignment operator
virtual moMoveNeighbor<M, Fitness> & operator=(const moMoveNeighbor<M, Fitness> & _n) { virtual moMoveNeighbor<M, Fitness> & operator=(const moMoveNeighbor<M, Fitness> & _n) {
moNeighbor <EOT, Fitness>::operator=(_n); moNeighbor <EOT, Fitness>::operator=(_n);
(*move) = *(_n.getMove()); (*move) = *(_n.getMove());
return *this ; return *this ;
} }
/* /*
* move the solution * move the solution
*/ */
virtual void move(EOT & _solution){ virtual void move(EOT & _solution) {
(*move)(_solution); (*move)(_solution);
} }
/** Return the class id. /** Return the class id.
* @return the class name as a std::string * @return the class name as a std::string
*/ */
virtual std::string className() const { return "moMoveNeighbor"; } virtual std::string className() const {
return "moMoveNeighbor";
void setMove(M* _move){
move=_move;
} }
M* getMove(){ void setMove(M* _move) {
return move; move=_move;
}
M* getMove() {
return move;
} }

View file

@ -8,47 +8,49 @@
#include <move/moNextMove.h> #include <move/moNextMove.h>
template< class M, class Fitness > template< class M, class Fitness >
class moMoveNeighborhood : public moNeighborhood <moMoveNeighbor<M, Fitness> > class moMoveNeighborhood : public moNeighborhood <moMoveNeighbor<M, Fitness> >
{ {
public: public:
typedef moMoveNeighbor<M, Fitness> Neighbor; typedef moMoveNeighbor<M, Fitness> Neighbor;
typedef typename M::EOType EOT; typedef typename M::EOType EOT;
moMoveNeighborhood(moMoveInit<M>& i, moNextMove<M>& n):_init(i), _next(n), isContinue(true) {} moMoveNeighborhood(moMoveInit<M>& i, moNextMove<M>& n):_init(i), _next(n), isContinue(true) {}
virtual bool hasNeighbor(EOT & solution){ virtual bool hasNeighbor(EOT & solution) {
return true; return true;
} }
/* /*
initialisation of the neighborhood initialisation of the neighborhood
*/ */
virtual void init(EOT & solution, Neighbor & current){ virtual void init(EOT & solution, Neighbor & current) {
_init(*(current._move), solution); _init(*(current._move), solution);
isContinue=true; isContinue=true;
} }
/* /*
Give the next neighbor Give the next neighbor
*/ */
virtual void next(EOT & solution, Neighbor & current){ virtual void next(EOT & solution, Neighbor & current) {
isContinue=_next(*(current._move), solution); isContinue=_next(*(current._move), solution);
} }
/* /*
if false, there is no neighbor left to explore if false, there is no neighbor left to explore
*/ */
virtual bool cont(EOT & solution){ virtual bool cont(EOT & solution) {
return isContinue; return isContinue;
} }
/** Return the class id. /** Return the class id.
* @return the class name as a std::string * @return the class name as a std::string
*/ */
virtual std::string className() const { return "moMoveNeighborhood"; } virtual std::string className() const {
return "moMoveNeighborhood";
}
private: private:
moMoveInit<M>& _init; moMoveInit<M>& _init;
moNextMove<M>& _next; moNextMove<M>& _next;
bool isContinue; bool isContinue;

View file

@ -45,6 +45,6 @@
*/ */
template < class M > template < class M >
class moNextMove:public eoBF < M &, const typename M::EOType &, bool > class moNextMove:public eoBF < M &, const typename M::EOType &, bool >
{}; {};
#endif #endif

View file

@ -54,151 +54,151 @@
typedef eoBit<eoMinimizingFitness> bitVector; typedef eoBit<eoMinimizingFitness> bitVector;
typedef moBitNeighbor<eoMinimizingFitness> bitNeighbor ; typedef moBitNeighbor<eoMinimizingFitness> bitNeighbor ;
class moDummyRndNeighborhood: public moOrderNeighborhood<bitNeighbor>/*, public moRndNeighborhood<bitNeighbor>*/{ class moDummyRndNeighborhood: public moOrderNeighborhood<bitNeighbor>/*, public moRndNeighborhood<bitNeighbor>*/ {
public: public:
moDummyRndNeighborhood(unsigned int a): moOrderNeighborhood<bitNeighbor>(a){} moDummyRndNeighborhood(unsigned int a): moOrderNeighborhood<bitNeighbor>(a) {}
}; };
typedef moDummyRndNeighborhood bitNeighborhood ; typedef moDummyRndNeighborhood bitNeighborhood ;
typedef EO<int> Solution; typedef EO<int> Solution;
class moDummyNeighbor : public moNeighbor<Solution,int>{ class moDummyNeighbor : public moNeighbor<Solution,int> {
public: public:
virtual void move(Solution & _solution){} virtual void move(Solution & _solution) {}
}; };
class moDummyBackableNeighbor : public moBackableNeighbor<Solution,int>{ class moDummyBackableNeighbor : public moBackableNeighbor<Solution,int> {
public: public:
virtual void move(Solution & _solution){} virtual void move(Solution & _solution) {}
virtual void moveBack(Solution & _solution){} virtual void moveBack(Solution & _solution) {}
}; };
class moDummyNeighborhood : public moNeighborhood<moDummyNeighbor>{ class moDummyNeighborhood : public moNeighborhood<moDummyNeighbor> {
public: public:
typedef moDummyNeighbor Neighbor; typedef moDummyNeighbor Neighbor;
moDummyNeighborhood():i(0),j(0){} moDummyNeighborhood():i(0),j(0) {}
virtual bool hasNeighbor(EOT & _solution){ virtual bool hasNeighbor(EOT & _solution) {
bool res; bool res;
if(i%3==0) if (i%3==0)
res=false; res=false;
else else
res=true; res=true;
i++; i++;
return res; return res;
} }
virtual void init(EOT & _solution, Neighbor & _current){} virtual void init(EOT & _solution, Neighbor & _current) {}
virtual void next(EOT & _solution, Neighbor & _current){} virtual void next(EOT & _solution, Neighbor & _current) {}
virtual bool cont(EOT & _solution){ virtual bool cont(EOT & _solution) {
j++; j++;
return (j%10!=0); return (j%10!=0);
} }
private: private:
int i,j; int i,j;
}; };
class moDummyEval: public eoEvalFunc<Solution>{ class moDummyEval: public eoEvalFunc<Solution> {
public: public:
void operator()(Solution& _sol){ void operator()(Solution& _sol) {
if(_sol.invalid()) if (_sol.invalid())
_sol.fitness(100); _sol.fitness(100);
else else
_sol.fitness(_sol.fitness()+50); _sol.fitness(_sol.fitness()+50);
} }
}; };
class evalOneMax : public moEval< bitNeighbor > class evalOneMax : public moEval< bitNeighbor >
{ {
private: private:
unsigned size; unsigned size;
public: public:
evalOneMax(unsigned _size) : size(_size) {}; evalOneMax(unsigned _size) : size(_size) {};
~evalOneMax(void) {} ; ~evalOneMax(void) {} ;
void operator() (bitVector& _sol, bitNeighbor& _n) { void operator() (bitVector& _sol, bitNeighbor& _n) {
unsigned int fit = _sol.fitness(); unsigned int fit = _sol.fitness();
if(_sol[_n.index()]) if (_sol[_n.index()])
fit--; fit--;
else else
fit++; fit++;
_n.fitness(fit); _n.fitness(fit);
} }
}; };
class dummyEvalOneMax : public moEval< bitNeighbor > class dummyEvalOneMax : public moEval< bitNeighbor >
{ {
private: private:
unsigned size; unsigned size;
public: public:
dummyEvalOneMax(unsigned _size) : size(_size) {}; dummyEvalOneMax(unsigned _size) : size(_size) {};
~dummyEvalOneMax(void) {} ; ~dummyEvalOneMax(void) {} ;
void operator() (bitVector& _sol, bitNeighbor& _n) { void operator() (bitVector& _sol, bitNeighbor& _n) {
unsigned int fit = _sol.fitness(); unsigned int fit = _sol.fitness();
_n.fitness(fit); _n.fitness(fit);
} }
}; };
class monitor1 : public eoMonitor class monitor1 : public eoMonitor
{ {
public: public:
monitor1(unsigned int& _a): a(_a){} monitor1(unsigned int& _a): a(_a) {}
eoMonitor& operator()(){ eoMonitor& operator()() {
a++; a++;
return *this; return *this;
} }
void lastCall(){ void lastCall() {
a++; a++;
} }
private: private:
unsigned int& a; unsigned int& a;
}; };
class monitor2 : public eoMonitor class monitor2 : public eoMonitor
{ {
public: public:
monitor2(unsigned int& _a): a(_a){} monitor2(unsigned int& _a): a(_a) {}
eoMonitor& operator()(){ eoMonitor& operator()() {
a++; a++;
return *this; return *this;
} }
void lastCall(){ void lastCall() {
a++; a++;
} }
private: private:
unsigned int& a; unsigned int& a;
}; };
class updater1: public eoUpdater class updater1: public eoUpdater
{ {
public: public:
updater1(unsigned int& _a): a(_a){} updater1(unsigned int& _a): a(_a) {}
void operator()(){ void operator()() {
a++; a++;
} }
void lastCall(){ void lastCall() {
a++; a++;
} }
private: private:
unsigned int& a; unsigned int& a;
}; };
#endif #endif

View file

@ -33,46 +33,46 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moBestImprAspiration] => START" << std::endl; std::cout << "[t-moBestImprAspiration] => START" << std::endl;
moBestImprAspiration<bitNeighbor> test; moBestImprAspiration<bitNeighbor> test;
eoBit<eoMinimizingFitness> sol1(4); eoBit<eoMinimizingFitness> sol1(4);
eoBit<eoMinimizingFitness> sol2(4); eoBit<eoMinimizingFitness> sol2(4);
eoBit<eoMinimizingFitness> sol3(4); eoBit<eoMinimizingFitness> sol3(4);
eoBit<eoMinimizingFitness> sol4(4); eoBit<eoMinimizingFitness> sol4(4);
bitNeighbor n1; bitNeighbor n1;
bitNeighbor n2; bitNeighbor n2;
bitNeighbor n3; bitNeighbor n3;
bitNeighbor n4; bitNeighbor n4;
sol3[0]=true; sol3[0]=true;
sol4[3]=true; sol4[3]=true;
sol1.fitness(4); sol1.fitness(4);
sol2.fitness(5); sol2.fitness(5);
sol3.fitness(3); sol3.fitness(3);
sol4.fitness(3); sol4.fitness(3);
n1.fitness(4); n1.fitness(4);
n2.fitness(5); n2.fitness(5);
n3.fitness(3); n3.fitness(3);
n4.fitness(3); n4.fitness(3);
//verification qu'on update bien le best so far quand il faut //verification qu'on update bien le best so far quand il faut
test.init(sol1); test.init(sol1);
assert(test.getBest()==sol1); assert(test.getBest()==sol1);
assert(!test(sol2,n2)); assert(!test(sol2,n2));
assert(test(sol3,n3)); assert(test(sol3,n3));
test.update(sol3,n3); test.update(sol3,n3);
assert(test.getBest()==sol3); assert(test.getBest()==sol3);
assert(!test(sol4,n4)); assert(!test(sol4,n4));
test.update(sol4,n4); test.update(sol4,n4);
assert(test.getBest()==sol3); assert(test.getBest()==sol3);
std::cout << "[t-moBestImprAspiration] => OK" << std::endl; std::cout << "[t-moBestImprAspiration] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -37,49 +37,49 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moBitNeighbor] => START" << std::endl; std::cout << "[t-moBitNeighbor] => START" << std::endl;
//init sol //init sol
eoBit<int> sol; eoBit<int> sol;
sol.push_back(true); sol.push_back(true);
sol.push_back(false); sol.push_back(false);
sol.push_back(true); sol.push_back(true);
//verif du constructeur vide //verif du constructeur vide
moBitNeighbor<int> test1; moBitNeighbor<int> test1;
assert(test1.index()==0); assert(test1.index()==0);
//verif du setter d'index et du constructeur de copy //verif du setter d'index et du constructeur de copy
test1.index(6); test1.index(6);
test1.fitness(2); test1.fitness(2);
moBitNeighbor<int> test2(test1); moBitNeighbor<int> test2(test1);
assert(test2.index()==6); assert(test2.index()==6);
assert(test2.fitness()==2); assert(test2.fitness()==2);
//verif du getter //verif du getter
assert(test1.index()==6); assert(test1.index()==6);
//verif de l'operateur= //verif de l'operateur=
test1.fitness(8); test1.fitness(8);
test1.index(2); test1.index(2);
test2=test1; test2=test1;
assert(test2.fitness()==8); assert(test2.fitness()==8);
assert(test2.index()==2); assert(test2.index()==2);
//verif de move //verif de move
test2.move(sol); test2.move(sol);
assert(!sol[2]); assert(!sol[2]);
//verif de moveBack //verif de moveBack
test2.moveBack(sol); test2.moveBack(sol);
assert(sol[2]); assert(sol[2]);
test1.printOn(std::cout); test1.printOn(std::cout);
test2.printOn(std::cout); test2.printOn(std::cout);
assert(test1.className()=="moBitNeighbor"); assert(test1.className()=="moBitNeighbor");
std::cout << "[t-moBitNeighbor] => OK" << std::endl; std::cout << "[t-moBitNeighbor] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -36,87 +36,87 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moCheckpoint] => START" << std::endl; std::cout << "[t-moCheckpoint] => START" << std::endl;
unsigned int a=2; unsigned int a=2;
unsigned int b=15; unsigned int b=15;
unsigned int c= 10; unsigned int c= 10;
unsigned int d= 47; unsigned int d= 47;
eoBit<eoMinimizingFitness> s(3); eoBit<eoMinimizingFitness> s(3);
s[0]=true; s[0]=true;
s[1]=true; s[1]=true;
s[2]=false; s[2]=false;
s.fitness(17); s.fitness(17);
//verification que toutes les operateurs sont bien apellés //verification que toutes les operateurs sont bien apellés
moSolutionStat< eoBit< eoMinimizingFitness > > stat; moSolutionStat< eoBit< eoMinimizingFitness > > stat;
updater1 up1(a); updater1 up1(a);
updater1 up2(b); updater1 up2(b);
monitor1 mon1(c); monitor1 mon1(c);
monitor2 mon2(d); monitor2 mon2(d);
moTrueContinuator< bitNeighborhood > cont; moTrueContinuator< bitNeighborhood > cont;
moCheckpoint< bitNeighborhood> test1(cont); moCheckpoint< bitNeighborhood> test1(cont);
moCheckpoint< bitNeighborhood> test2(cont, 3); moCheckpoint< bitNeighborhood> test2(cont, 3);
test1.add(up1); test1.add(up1);
test1.add(up2); test1.add(up2);
test1.add(mon1); test1.add(mon1);
test1.add(mon2); test1.add(mon2);
test1.add(stat); test1.add(stat);
test2.add(up1); test2.add(up1);
test2.add(up2); test2.add(up2);
test2.add(mon1); test2.add(mon1);
test2.add(mon2); test2.add(mon2);
test2.add(stat); test2.add(stat);
test1.init(s); test1.init(s);
test1(s); test1(s);
assert(a==3 && b==16 && c==11 && d==48); assert(a==3 && b==16 && c==11 && d==48);
assert(stat.value()[0]); assert(stat.value()[0]);
assert(stat.value()[1]); assert(stat.value()[1]);
assert(!stat.value()[2]); assert(!stat.value()[2]);
assert(stat.value().fitness()==17); assert(stat.value().fitness()==17);
test1(s); test1(s);
assert(a==4 && b==17 && c==12 && d==49); assert(a==4 && b==17 && c==12 && d==49);
assert(stat.value()[0]); assert(stat.value()[0]);
assert(stat.value()[1]); assert(stat.value()[1]);
assert(!stat.value()[2]); assert(!stat.value()[2]);
assert(stat.value().fitness()==17); assert(stat.value().fitness()==17);
s.fitness(4); s.fitness(4);
test2.init(s); test2.init(s);
test2(s); test2(s);
assert(a==5 && b==18 && c==13 && d==50); assert(a==5 && b==18 && c==13 && d==50);
assert(stat.value()[0]); assert(stat.value()[0]);
assert(stat.value()[1]); assert(stat.value()[1]);
assert(!stat.value()[2]); assert(!stat.value()[2]);
assert(stat.value().fitness()==4); assert(stat.value().fitness()==4);
s.fitness(6); s.fitness(6);
test2(s); test2(s);
assert(stat.value().fitness()==4); assert(stat.value().fitness()==4);
test2(s); test2(s);
assert(stat.value().fitness()==4); assert(stat.value().fitness()==4);
test2(s); test2(s);
assert(stat.value().fitness()==6); assert(stat.value().fitness()==6);
test1.lastCall(s); test1.lastCall(s);
assert(a==9 && b==22 && c==17 && d==54); assert(a==9 && b==22 && c==17 && d==54);
test2.lastCall(s); test2.lastCall(s);
assert(a==10 && b==23 && c==18 && d==55); assert(a==10 && b==23 && c==18 && d==55);
assert(test1.className()=="moCheckpoint"); assert(test1.className()=="moCheckpoint");
std::cout << "[t-moCheckpoint] => OK" << std::endl; std::cout << "[t-moCheckpoint] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -35,37 +35,37 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moCounterMonitorSaver] => START" << std::endl; std::cout << "[t-moCounterMonitorSaver] => START" << std::endl;
unsigned int a=1; unsigned int a=1;
unsigned int b=10; unsigned int b=10;
monitor1 mon1(a); monitor1 mon1(a);
monitor2 mon2(b); monitor2 mon2(b);
moCounterMonitorSaver test(3, mon1); moCounterMonitorSaver test(3, mon1);
test.add(mon2); test.add(mon2);
//on verifie qu'on apelle les moniteurs seulement tout les 3 itération //on verifie qu'on apelle les moniteurs seulement tout les 3 itération
test(); test();
assert(a==2 && b==11); assert(a==2 && b==11);
test(); test();
assert(a==2 && b==11); assert(a==2 && b==11);
test(); test();
assert(a==2 && b==11); assert(a==2 && b==11);
test(); test();
assert(a==3 && b==12); assert(a==3 && b==12);
//test du lastCall //test du lastCall
test.lastCall(); test.lastCall();
assert(a==4 && b==13); assert(a==4 && b==13);
assert(test.className()=="moCounterMonitorSaver"); assert(test.className()=="moCounterMonitorSaver");
std::cout << "[t-moCounterMonitorSaver] => OK" << std::endl; std::cout << "[t-moCounterMonitorSaver] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -35,39 +35,39 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moDistanceStat] => START" << std::endl; std::cout << "[t-moDistanceStat] => START" << std::endl;
eoBit<int> sol1; eoBit<int> sol1;
eoBit<int> sol2; eoBit<int> sol2;
eoBit<int> sol3; eoBit<int> sol3;
sol1.push_back(true); sol1.push_back(true);
sol1.push_back(false); sol1.push_back(false);
sol1.push_back(true); sol1.push_back(true);
sol2.push_back(true); sol2.push_back(true);
sol2.push_back(true); sol2.push_back(true);
sol2.push_back(false); sol2.push_back(false);
sol3.push_back(true); sol3.push_back(true);
sol3.push_back(true); sol3.push_back(true);
sol3.push_back(true); sol3.push_back(true);
//verification de la stat avec une distance de Hamming //verification de la stat avec une distance de Hamming
eoHammingDistance< eoBit<int> > dist; eoHammingDistance< eoBit<int> > dist;
moDistanceStat< eoBit<int> > test(dist, sol1); moDistanceStat< eoBit<int> > test(dist, sol1);
test(sol2); test(sol2);
assert(test.value()==2); assert(test.value()==2);
test(sol3); test(sol3);
assert(test.value()==1); assert(test.value()==1);
assert(test.className()=="moDistanceStat"); assert(test.className()=="moDistanceStat");
std::cout << "[t-moDistanceStat] => OK" << std::endl; std::cout << "[t-moDistanceStat] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -35,29 +35,29 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moDummyMemory] => START" << std::endl; std::cout << "[t-moDummyMemory] => START" << std::endl;
eoBit<eoMinimizingFitness> sol(4); eoBit<eoMinimizingFitness> sol(4);
bitNeighbor n; bitNeighbor n;
moDummyDiversification<bitNeighbor> test1; moDummyDiversification<bitNeighbor> test1;
test1.init(sol); test1.init(sol);
test1.add(sol, n); test1.add(sol, n);
test1.update(sol, n); test1.update(sol, n);
test1.clearMemory(); test1.clearMemory();
assert(!test1(sol)); assert(!test1(sol));
moDummyIntensification<bitNeighbor> test2; moDummyIntensification<bitNeighbor> test2;
test2.init(sol); test2.init(sol);
test2.add(sol, n); test2.add(sol, n);
test2.update(sol, n); test2.update(sol, n);
test2.clearMemory(); test2.clearMemory();
assert(!test2(sol)); assert(!test2(sol));
std::cout << "[t-moDummyMemory] => OK" << std::endl; std::cout << "[t-moDummyMemory] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -36,58 +36,58 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moFirstImprExplorer] => START" << std::endl; std::cout << "[t-moFirstImprExplorer] => START" << std::endl;
//Instanciation //Instanciation
eoBit<eoMinimizingFitness> sol(4, true); eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4); sol.fitness(4);
bitNeighborhood nh(4); bitNeighborhood nh(4);
evalOneMax eval(4); evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp; moNeighborComparator<bitNeighbor> ncomp;
moSolNeighborComparator<bitNeighbor> sncomp; moSolNeighborComparator<bitNeighbor> sncomp;
moFirstImprExplorer<bitNeighborhood> test(nh, eval, ncomp, sncomp); moFirstImprExplorer<bitNeighborhood> test(nh, eval, ncomp, sncomp);
//on verifie qu'on améliore peut continuer à explorer tant qu'on améliore la solution //on verifie qu'on améliore peut continuer à explorer tant qu'on améliore la solution
test(sol); test(sol);
assert(test.accept(sol)); assert(test.accept(sol));
test.move(sol); test.move(sol);
assert(sol.fitness()==3); assert(sol.fitness()==3);
assert(!sol[0]); assert(!sol[0]);
assert(test.isContinue(sol)); assert(test.isContinue(sol));
test(sol); test(sol);
assert(test.accept(sol)); assert(test.accept(sol));
test.move(sol); test.move(sol);
assert(sol.fitness()==2); assert(sol.fitness()==2);
assert(!sol[1]); assert(!sol[1]);
assert(test.isContinue(sol)); assert(test.isContinue(sol));
test(sol); test(sol);
assert(test.accept(sol)); assert(test.accept(sol));
test.move(sol); test.move(sol);
assert(sol.fitness()==1); assert(sol.fitness()==1);
assert(!sol[2]); assert(!sol[2]);
assert(test.isContinue(sol)); assert(test.isContinue(sol));
test(sol); test(sol);
assert(test.accept(sol)); assert(test.accept(sol));
test.move(sol); test.move(sol);
assert(sol.fitness()==0); assert(sol.fitness()==0);
assert(!sol[3]); assert(!sol[3]);
assert(test.isContinue(sol)); assert(test.isContinue(sol));
test(sol); test(sol);
assert(!test.accept(sol)); assert(!test.accept(sol));
assert(sol.fitness()==0); assert(sol.fitness()==0);
assert(!test.isContinue(sol)); assert(!test.isContinue(sol));
std::cout << "[t-moFirstImprExplorer] => OK" << std::endl; std::cout << "[t-moFirstImprExplorer] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -34,24 +34,24 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moFitnessStat] => START" << std::endl; std::cout << "[t-moFitnessStat] => START" << std::endl;
eoBit<int> sol; eoBit<int> sol;
moFitnessStat< eoBit<int> > test; moFitnessStat< eoBit<int> > test;
sol.fitness(3); sol.fitness(3);
test(sol); test(sol);
assert(test.value()==3); assert(test.value()==3);
sol.fitness(12); sol.fitness(12);
test(sol); test(sol);
assert(test.value()==12); assert(test.value()==12);
assert(test.className()=="moFitnessStat"); assert(test.className()=="moFitnessStat");
std::cout << "[t-moFitnessStat] => OK" << std::endl; std::cout << "[t-moFitnessStat] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -38,26 +38,26 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
//Pas grand chose à faire: le gros du travail est fait par le voisin et l'eval //Pas grand chose à faire: le gros du travail est fait par le voisin et l'eval
std::cout << "[t-moFullEvalByCopy] => START" << std::endl; std::cout << "[t-moFullEvalByCopy] => START" << std::endl;
Solution sol; Solution sol;
moDummyNeighbor neighbor; moDummyNeighbor neighbor;
moDummyEval eval; moDummyEval eval;
//verif constructor //verif constructor
moFullEvalByCopy<moDummyNeighbor> test(eval); moFullEvalByCopy<moDummyNeighbor> test(eval);
sol.fitness(3); sol.fitness(3);
//verif operator() //verif operator()
test(sol,neighbor); test(sol,neighbor);
assert(sol.fitness()==3); assert(sol.fitness()==3);
std::cout << "[t-moFullEvalByCopy] => OK" << std::endl; std::cout << "[t-moFullEvalByCopy] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -38,26 +38,26 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
//Pas grand chose à faire: le gros du travail est fait par le voisin et l'eval //Pas grand chose à faire: le gros du travail est fait par le voisin et l'eval
std::cout << "[t-moFullEvalByModif] => START" << std::endl; std::cout << "[t-moFullEvalByModif] => START" << std::endl;
Solution sol; Solution sol;
moDummyBackableNeighbor neighbor; moDummyBackableNeighbor neighbor;
moDummyEval eval; moDummyEval eval;
//verif constructor //verif constructor
moFullEvalByModif<moDummyBackableNeighbor> test(eval); moFullEvalByModif<moDummyBackableNeighbor> test(eval);
sol.fitness(3); sol.fitness(3);
//verif operator() //verif operator()
test(sol,neighbor); test(sol,neighbor);
assert(sol.fitness()==3); assert(sol.fitness()==3);
std::cout << "[t-moFullEvalByModif] => OK" << std::endl; std::cout << "[t-moFullEvalByModif] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -36,57 +36,57 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moHCneutralExplorer] => START" << std::endl; std::cout << "[t-moHCneutralExplorer] => START" << std::endl;
//Instanciation //Instanciation
eoBit<eoMinimizingFitness> sol(4, true); eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4); sol.fitness(4);
bitNeighborhood nh(4); bitNeighborhood nh(4);
evalOneMax eval(4); evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp; moNeighborComparator<bitNeighbor> ncomp;
moSolNeighborComparator<bitNeighbor> sncomp; moSolNeighborComparator<bitNeighbor> sncomp;
moHCneutralExplorer<bitNeighborhood> test(nh, eval, ncomp, sncomp,3); moHCneutralExplorer<bitNeighborhood> test(nh, eval, ncomp, sncomp,3);
//on verifie qu'on ameliore bien la solution et que l'exploration dure 3 itérations //on verifie qu'on ameliore bien la solution et que l'exploration dure 3 itérations
test.initParam(sol); test.initParam(sol);
test(sol); test(sol);
assert(test.accept(sol)); assert(test.accept(sol));
test.move(sol); test.move(sol);
assert(sol.fitness()==3); assert(sol.fitness()==3);
test.updateParam(sol); test.updateParam(sol);
assert(test.isContinue(sol)); assert(test.isContinue(sol));
//les affichages permettent de voir qu'on prend pas toujours les mm voisins(lancer plusieurs fois l'exe) //les affichages permettent de voir qu'on prend pas toujours les mm voisins(lancer plusieurs fois l'exe)
std::cout << sol << std::endl; std::cout << sol << std::endl;
test(sol); test(sol);
assert(test.accept(sol)); assert(test.accept(sol));
test.move(sol); test.move(sol);
assert(sol.fitness()==2); assert(sol.fitness()==2);
test.updateParam(sol); test.updateParam(sol);
assert(test.isContinue(sol)); assert(test.isContinue(sol));
std::cout << sol << std::endl; std::cout << sol << std::endl;
test(sol); test(sol);
assert(test.accept(sol)); assert(test.accept(sol));
test.move(sol); test.move(sol);
assert(sol.fitness()==1); assert(sol.fitness()==1);
test.updateParam(sol); test.updateParam(sol);
assert(!test.isContinue(sol)); assert(!test.isContinue(sol));
std::cout << sol << std::endl; std::cout << sol << std::endl;
std::cout << "[t-moHCneutralExplorer] => OK" << std::endl; std::cout << "[t-moHCneutralExplorer] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -34,64 +34,64 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moMetropolisHastingExplorer] => START" << std::endl; std::cout << "[t-moMetropolisHastingExplorer] => START" << std::endl;
//Instanciation //Instanciation
eoBit<eoMinimizingFitness> sol(4, true); eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4); sol.fitness(4);
bitNeighborhood nh(4); bitNeighborhood nh(4);
evalOneMax eval(4); evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp; moNeighborComparator<bitNeighbor> ncomp;
moSolNeighborComparator<bitNeighbor> sncomp; moSolNeighborComparator<bitNeighbor> sncomp;
moMetropolisHastingExplorer<bitNeighborhood> test(nh, eval, ncomp, sncomp, 3); moMetropolisHastingExplorer<bitNeighborhood> test(nh, eval, ncomp, sncomp, 3);
//test de l'acceptation d'un voisin améliorant //test de l'acceptation d'un voisin améliorant
test.initParam(sol); test.initParam(sol);
test(sol); test(sol);
assert(test.accept(sol)); assert(test.accept(sol));
test.move(sol); test.move(sol);
assert(sol.fitness()==3); assert(sol.fitness()==3);
test.updateParam(sol); test.updateParam(sol);
assert(test.isContinue(sol)); assert(test.isContinue(sol));
unsigned int oui=0, non=0; unsigned int oui=0, non=0;
//test de l'acceptation d'un voisin non améliorant //test de l'acceptation d'un voisin non améliorant
for(unsigned int i=0; i<1000; i++){ for (unsigned int i=0; i<1000; i++) {
test(sol); test(sol);
if(test.accept(sol)) if (test.accept(sol))
oui++; oui++;
else else
non++; non++;
} }
std::cout << "Attention test en fonction d'une proba \"p\" uniforme dans [0,1] , oui si p < 3/4, non sinon -> resultat sur 1000 essai" << std::endl; std::cout << "Attention test en fonction d'une proba \"p\" uniforme dans [0,1] , oui si p < 3/4, non sinon -> resultat sur 1000 essai" << std::endl;
std::cout << "oui: " << oui << std::endl; std::cout << "oui: " << oui << std::endl;
std::cout << "non: " << non << std::endl; std::cout << "non: " << non << std::endl;
assert(oui > 700 && oui < 800); //verification grossiere assert(oui > 700 && oui < 800); //verification grossiere
//test du critere d'arret //test du critere d'arret
test.updateParam(sol); test.updateParam(sol);
assert(test.isContinue(sol)); assert(test.isContinue(sol));
test.updateParam(sol); test.updateParam(sol);
assert(!test.isContinue(sol)); assert(!test.isContinue(sol));
//test de l'acceptation d'un voisin //test de l'acceptation d'un voisin
sol[0]=false; sol[0]=false;
sol[1]=false; sol[1]=false;
sol[2]=false; sol[2]=false;
sol[3]=false; sol[3]=false;
sol.fitness(0); sol.fitness(0);
test.initParam(sol); test.initParam(sol);
test(sol); test(sol);
assert(!test.accept(sol)); assert(!test.accept(sol));
std::cout << "[t-moMetropolisHastingExplorer] => OK" << std::endl; std::cout << "[t-moMetropolisHastingExplorer] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -37,28 +37,28 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moNeighbor] => START" << std::endl; std::cout << "[t-moNeighbor] => START" << std::endl;
//test constructor //test constructor
moDummyNeighbor test1, test2; moDummyNeighbor test1, test2;
test1.fitness(3); test1.fitness(3);
//test operateur d'affectation //test operateur d'affectation
test2=test1; test2=test1;
assert(test1.fitness()==test2.fitness()); assert(test1.fitness()==test2.fitness());
//test operateur de copy //test operateur de copy
moDummyNeighbor test3(test1); moDummyNeighbor test3(test1);
assert(test1.fitness()==test3.fitness()); assert(test1.fitness()==test3.fitness());
test1.printOn(std::cout); test1.printOn(std::cout);
test2.printOn(std::cout); test2.printOn(std::cout);
test3.printOn(std::cout); test3.printOn(std::cout);
assert(test1.className()=="moNeighbor"); assert(test1.className()=="moNeighbor");
std::cout << "[t-moNeighbor] => OK" << std::endl; std::cout << "[t-moNeighbor] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -40,29 +40,29 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moNeighborComparator] => START" << std::endl; std::cout << "[t-moNeighborComparator] => START" << std::endl;
moBitNeighbor<eoMinimizingFitness> neighbor1; moBitNeighbor<eoMinimizingFitness> neighbor1;
moBitNeighbor<eoMinimizingFitness> neighbor2; moBitNeighbor<eoMinimizingFitness> neighbor2;
moNeighborComparator< moBitNeighbor<eoMinimizingFitness> > test; moNeighborComparator< moBitNeighbor<eoMinimizingFitness> > test;
neighbor1.fitness(3); neighbor1.fitness(3);
neighbor2.fitness(2); neighbor2.fitness(2);
//test with a minimizing fitness neighbor2 must be better than neighbor1 and reversly //test with a minimizing fitness neighbor2 must be better than neighbor1 and reversly
assert(test(neighbor1, neighbor2)); assert(test(neighbor1, neighbor2));
assert(!test(neighbor2, neighbor1)); assert(!test(neighbor2, neighbor1));
//test equals //test equals
assert(!test.equals(neighbor1,neighbor2)); assert(!test.equals(neighbor1,neighbor2));
neighbor2.fitness(3); neighbor2.fitness(3);
assert(test.equals(neighbor1,neighbor2)); assert(test.equals(neighbor1,neighbor2));
assert(test.className()=="moNeighborComparator"); assert(test.className()=="moNeighborComparator");
std::cout << "[t-moNeighborComparator] => OK" << std::endl; std::cout << "[t-moNeighborComparator] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -46,107 +46,107 @@ Contact: paradiseo-help@lists.gforge.inria.fr
/* /*
* Tests all classes depending of moNeighborhoodStat.h * Tests all classes depending of moNeighborhoodStat.h
*/ */
int main(){ int main() {
//test de moNeighborhoodStat.h //test de moNeighborhoodStat.h
std::cout << "[t-moNeighborhoodStat] => START" << std::endl; std::cout << "[t-moNeighborhoodStat] => START" << std::endl;
moNeighborComparator<bitNeighbor> neighborComp; moNeighborComparator<bitNeighbor> neighborComp;
moSolNeighborComparator<bitNeighbor> solNeighborComp; moSolNeighborComparator<bitNeighbor> solNeighborComp;
evalOneMax eval(10); evalOneMax eval(10);
bitNeighborhood n(10); bitNeighborhood n(10);
bitVector sol; bitVector sol;
sol.push_back(true); sol.push_back(true);
sol.push_back(false); sol.push_back(false);
sol.push_back(true); sol.push_back(true);
sol.push_back(true); sol.push_back(true);
sol.push_back(false); sol.push_back(false);
sol.push_back(true); sol.push_back(true);
sol.push_back(false); sol.push_back(false);
sol.push_back(true); sol.push_back(true);
sol.push_back(true); sol.push_back(true);
sol.push_back(true); sol.push_back(true);
sol.fitness(7); sol.fitness(7);
moNeighborhoodStat<bitNeighborhood> test(n, eval, neighborComp, solNeighborComp); moNeighborhoodStat<bitNeighborhood> test(n, eval, neighborComp, solNeighborComp);
test(sol); test(sol);
assert(test.getMin()==8); assert(test.getMin()==8);
assert(test.getMax()==6); assert(test.getMax()==6);
assert(test.getMean()==6.6); assert(test.getMean()==6.6);
double sd=test.getSD(); double sd=test.getSD();
assert(test.getSD()>0.966 && test.getSD()<0.967); assert(sd>0.966 && sd<0.967);
assert(test.getSize()==10); assert(test.getSize()==10);
assert(test.getNbSup()==7); assert(test.getNbSup()==7);
assert(test.getNbInf()==3); assert(test.getNbInf()==3);
assert(test.getNbEqual()==0); assert(test.getNbEqual()==0);
assert(test.className()=="moNeighborhoodStat"); assert(test.className()=="moNeighborhoodStat");
std::cout << "[t-moNeighborhoodStat] => OK" << std::endl; std::cout << "[t-moNeighborhoodStat] => OK" << std::endl;
//test of moMaxNeighborStat.h //test of moMaxNeighborStat.h
std::cout << "[t-moMaxNeighborStat] => START" << std::endl; std::cout << "[t-moMaxNeighborStat] => START" << std::endl;
moMaxNeighborStat<bitNeighborhood> test2(test); moMaxNeighborStat<bitNeighborhood> test2(test);
test2(sol); test2(sol);
assert(test2.value()==6); assert(test2.value()==6);
assert(test2.className()=="moMaxNeighborStat"); assert(test2.className()=="moMaxNeighborStat");
std::cout << "[t-moMaxNeighborStat] => OK" << std::endl; std::cout << "[t-moMaxNeighborStat] => OK" << std::endl;
//test of moMinNeighborStat.h //test of moMinNeighborStat.h
std::cout << "[t-moMinNeighborStat] => START" << std::endl; std::cout << "[t-moMinNeighborStat] => START" << std::endl;
moMinNeighborStat<bitNeighborhood> test3(test); moMinNeighborStat<bitNeighborhood> test3(test);
test3(sol); test3(sol);
assert(test3.value()==8); assert(test3.value()==8);
assert(test3.className()=="moMinNeighborStat"); assert(test3.className()=="moMinNeighborStat");
std::cout << "[t-moMinNeighborStat] => OK" << std::endl; std::cout << "[t-moMinNeighborStat] => OK" << std::endl;
//test of moNbInfNeighborStat.h //test of moNbInfNeighborStat.h
std::cout << "[t-moNbInfNeighborStat] => START" << std::endl; std::cout << "[t-moNbInfNeighborStat] => START" << std::endl;
moNbInfNeighborStat<bitNeighborhood> test4(test); moNbInfNeighborStat<bitNeighborhood> test4(test);
test4(sol); test4(sol);
assert(test4.value()==3); assert(test4.value()==3);
assert(test4.className()=="moNbInfNeighborStat"); assert(test4.className()=="moNbInfNeighborStat");
std::cout << "[t-moNbInfNeighborStat] => OK" << std::endl; std::cout << "[t-moNbInfNeighborStat] => OK" << std::endl;
//test of moNbSupNeighborStat.h //test of moNbSupNeighborStat.h
std::cout << "[t-moNbSupNeighborStat] => START" << std::endl; std::cout << "[t-moNbSupNeighborStat] => START" << std::endl;
moNbSupNeighborStat<bitNeighborhood> test5(test); moNbSupNeighborStat<bitNeighborhood> test5(test);
test5(sol); test5(sol);
assert(test5.value()==7); assert(test5.value()==7);
assert(test5.className()=="moNbSupNeighborStat"); assert(test5.className()=="moNbSupNeighborStat");
std::cout << "[t-moNbSupNeighborStat] => OK" << std::endl; std::cout << "[t-moNbSupNeighborStat] => OK" << std::endl;
//test of moNeutralDegreeNeighborStat.h //test of moNeutralDegreeNeighborStat.h
std::cout << "[t-moNeutralDegreeNeighborStat] => START" << std::endl; std::cout << "[t-moNeutralDegreeNeighborStat] => START" << std::endl;
moNeutralDegreeNeighborStat<bitNeighborhood> test6(test); moNeutralDegreeNeighborStat<bitNeighborhood> test6(test);
test6(sol); test6(sol);
assert(test6.value()==0); assert(test6.value()==0);
assert(test6.className()=="moNeutralDegreeNeighborStat"); assert(test6.className()=="moNeutralDegreeNeighborStat");
std::cout << "[t-moNeutralDegreeNeighborStat] => OK" << std::endl; std::cout << "[t-moNeutralDegreeNeighborStat] => OK" << std::endl;
//test of moSecondMomentNeighborStat.h //test of moSecondMomentNeighborStat.h
std::cout << "[t-moSecondMomentNeighborStat] => START" << std::endl; std::cout << "[t-moSecondMomentNeighborStat] => START" << std::endl;
moSecondMomentNeighborStat<bitNeighborhood> test7(test); moSecondMomentNeighborStat<bitNeighborhood> test7(test);
test7(sol); test7(sol);
assert(test7.value().first==6.6); assert(test7.value().first==6.6);
assert(test7.value().second > 0.966 && test7.value().second < 0.967); assert(test7.value().second > 0.966 && test7.value().second < 0.967);
assert(test7.className()=="moSecondMomentNeighborStat"); assert(test7.className()=="moSecondMomentNeighborStat");
std::cout << "[t-moSecondMomentNeighborStat] => OK" << std::endl; std::cout << "[t-moSecondMomentNeighborStat] => OK" << std::endl;
//test of moSizeNeighborStat.h //test of moSizeNeighborStat.h
std::cout << "[t-moSizeNeighborStat] => START" << std::endl; std::cout << "[t-moSizeNeighborStat] => START" << std::endl;
moSizeNeighborStat<bitNeighborhood> test8(test); moSizeNeighborStat<bitNeighborhood> test8(test);
test8(sol); test8(sol);
assert(test8.value()==10); assert(test8.value()==10);
assert(test8.className()=="moSizeNeighborStat"); assert(test8.className()=="moSizeNeighborStat");
std::cout << "[t-moSizeNeighborStat] => OK" << std::endl; std::cout << "[t-moSizeNeighborStat] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -39,42 +39,42 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moOrderNeighborhood] => START" << std::endl; std::cout << "[t-moOrderNeighborhood] => START" << std::endl;
//init sol //init sol
eoBit<int> sol; eoBit<int> sol;
sol.push_back(true); sol.push_back(true);
sol.push_back(false); sol.push_back(false);
sol.push_back(true); sol.push_back(true);
moBitNeighbor<int> neighbor; moBitNeighbor<int> neighbor;
//verif du constructeur vide //verif du constructeur vide
moOrderNeighborhood<moBitNeighbor<int> > test(3); moOrderNeighborhood<moBitNeighbor<int> > test(3);
assert(test.position()==0); assert(test.position()==0);
//verif du hasneighbor //verif du hasneighbor
assert(test.hasNeighbor(sol)); assert(test.hasNeighbor(sol));
//verif de init //verif de init
test.init(sol, neighbor); test.init(sol, neighbor);
assert(neighbor.index()==0); assert(neighbor.index()==0);
assert(test.position()==0); assert(test.position()==0);
//verif du next //verif du next
test.next(sol, neighbor); test.next(sol, neighbor);
assert(neighbor.index()==1); assert(neighbor.index()==1);
assert(test.position()==1); assert(test.position()==1);
//verif du cont //verif du cont
assert(test.cont(sol)); assert(test.cont(sol));
test.next(sol, neighbor); test.next(sol, neighbor);
assert(!test.cont(sol)); assert(!test.cont(sol));
assert(test.className()=="moOrderNeighborhood"); assert(test.className()=="moOrderNeighborhood");
std::cout << "[t-moOrderNeighborhood] => OK" << std::endl; std::cout << "[t-moOrderNeighborhood] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -34,55 +34,55 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moRandomNeutralWalkExplorer] => START" << std::endl; std::cout << "[t-moRandomNeutralWalkExplorer] => START" << std::endl;
eoBit<eoMinimizingFitness> sol(4, true); eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4); sol.fitness(4);
bitNeighborhood nh(4); bitNeighborhood nh(4);
evalOneMax eval(4); evalOneMax eval(4);
dummyEvalOneMax eval2(4); dummyEvalOneMax eval2(4);
moSolNeighborComparator<bitNeighbor> sncomp; moSolNeighborComparator<bitNeighbor> sncomp;
//test avec la fonction d'eval classique //test avec la fonction d'eval classique
//on verifie qu'on ne trouve pas de voisin de mm fitness //on verifie qu'on ne trouve pas de voisin de mm fitness
moRandomNeutralWalkExplorer<bitNeighborhood> test(nh, eval, sncomp, 3); moRandomNeutralWalkExplorer<bitNeighborhood> test(nh, eval, sncomp, 3);
test.initParam(sol); test.initParam(sol);
test(sol); test(sol);
assert(!test.accept(sol)); assert(!test.accept(sol));
assert(!test.isContinue(sol)); assert(!test.isContinue(sol));
//test avec une fonction d'eval bidon qui renvoie toujours la mm fitness //test avec une fonction d'eval bidon qui renvoie toujours la mm fitness
//on peut donc verifier qu'on s'arette au bout des 3 itérations. //on peut donc verifier qu'on s'arette au bout des 3 itérations.
moRandomNeutralWalkExplorer<bitNeighborhood> test2(nh, eval2, sncomp, 3); moRandomNeutralWalkExplorer<bitNeighborhood> test2(nh, eval2, sncomp, 3);
sol.fitness(2); sol.fitness(2);
test2.initParam(sol); test2.initParam(sol);
test2(sol); test2(sol);
assert(test2.accept(sol)); assert(test2.accept(sol));
test2.move(sol); test2.move(sol);
assert(sol.fitness()==2); assert(sol.fitness()==2);
test2.updateParam(sol); test2.updateParam(sol);
assert(test2.isContinue(sol)); assert(test2.isContinue(sol));
test2(sol); test2(sol);
assert(test2.accept(sol)); assert(test2.accept(sol));
test2.move(sol); test2.move(sol);
assert(sol.fitness()==2); assert(sol.fitness()==2);
test2.updateParam(sol); test2.updateParam(sol);
assert(test2.isContinue(sol)); assert(test2.isContinue(sol));
test2(sol); test2(sol);
assert(test2.accept(sol)); assert(test2.accept(sol));
test2.move(sol); test2.move(sol);
assert(sol.fitness()==2); assert(sol.fitness()==2);
test2.updateParam(sol); test2.updateParam(sol);
assert(!test2.isContinue(sol)); assert(!test2.isContinue(sol));
std::cout << "[t-moRandomNeutralWalkExplorer] => OK" << std::endl; std::cout << "[t-moRandomNeutralWalkExplorer] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -34,46 +34,46 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moRandomWalkExplorer] => START" << std::endl; std::cout << "[t-moRandomWalkExplorer] => START" << std::endl;
eoBit<eoMinimizingFitness> sol(4, true); eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4); sol.fitness(4);
bitNeighborhood nh(4); bitNeighborhood nh(4);
evalOneMax eval(4); evalOneMax eval(4);
//test avec un neighbordhood ordonné //test avec un neighbordhood ordonné
//Du coup on verifie juste qu'on a bien une evolution de la solution et qu'on fait 3 pas avant d'arreter l'exploration //Du coup on verifie juste qu'on a bien une evolution de la solution et qu'on fait 3 pas avant d'arreter l'exploration
moRandomWalkExplorer<bitNeighborhood> test(nh, eval, 3); moRandomWalkExplorer<bitNeighborhood> test(nh, eval, 3);
test.initParam(sol); test.initParam(sol);
test(sol); test(sol);
assert(test.accept(sol)); assert(test.accept(sol));
test.move(sol); test.move(sol);
assert(sol.fitness()==3); assert(sol.fitness()==3);
test.updateParam(sol); test.updateParam(sol);
assert(test.isContinue(sol)); assert(test.isContinue(sol));
test(sol); test(sol);
assert(test.accept(sol)); assert(test.accept(sol));
test.move(sol); test.move(sol);
assert(sol.fitness()==4); assert(sol.fitness()==4);
test.updateParam(sol); test.updateParam(sol);
assert(test.isContinue(sol)); assert(test.isContinue(sol));
test(sol); test(sol);
assert(test.accept(sol)); assert(test.accept(sol));
test.move(sol); test.move(sol);
assert(sol.fitness()==3); assert(sol.fitness()==3);
assert(!sol[0]); assert(!sol[0]);
test.updateParam(sol); test.updateParam(sol);
assert(!test.isContinue(sol)); assert(!test.isContinue(sol));
std::cout << "[t-moRandomWalkExplorer] => OK" << std::endl; std::cout << "[t-moRandomWalkExplorer] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -35,41 +35,41 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moRndWithReplNeighborhood] => START" << std::endl; std::cout << "[t-moRndWithReplNeighborhood] => START" << std::endl;
unsigned int a, b; unsigned int a, b;
eoBit<int> sol; eoBit<int> sol;
moBitNeighbor<int> n; moBitNeighbor<int> n;
moRndWithReplNeighborhood< moBitNeighbor<int> > test(3); moRndWithReplNeighborhood< moBitNeighbor<int> > test(3);
moRndWithReplNeighborhood< moBitNeighbor<int> > test2(0); moRndWithReplNeighborhood< moBitNeighbor<int> > test2(0);
assert(test.hasNeighbor(sol)); assert(test.hasNeighbor(sol));
assert(!test2.hasNeighbor(sol)); assert(!test2.hasNeighbor(sol));
test.init(sol,n); test.init(sol,n);
//on s'assure qu'on a bien toujours bien l'index 0, 1 ou 2 qui est renvoyé //on s'assure qu'on a bien toujours bien l'index 0, 1 ou 2 qui est renvoyé
for(unsigned int i=0; i<100; i++){ for (unsigned int i=0; i<100; i++) {
a=n.index(); a=n.index();
test.next(sol,n); test.next(sol,n);
b=n.index(); b=n.index();
assert(a==0 || a==1 || a==2); assert(a==0 || a==1 || a==2);
assert(b==0 || b==1 || b==2); assert(b==0 || b==1 || b==2);
assert(test.cont(sol)); assert(test.cont(sol));
assert(!test2.cont(sol)); assert(!test2.cont(sol));
assert(test.cont(sol)); assert(test.cont(sol));
} }
assert(test.className()=="moRndWithReplNeighborhood"); assert(test.className()=="moRndWithReplNeighborhood");
std::cout << "[t-moRndWithReplNeighborhood] => OK" << std::endl; std::cout << "[t-moRndWithReplNeighborhood] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -35,42 +35,42 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moRndWithoutReplNeighborhood] => START" << std::endl; std::cout << "[t-moRndWithoutReplNeighborhood] => START" << std::endl;
unsigned int a, b, c; unsigned int a, b, c;
eoBit<int> sol; eoBit<int> sol;
moBitNeighbor<int> n; moBitNeighbor<int> n;
//instanciation //instanciation
moRndWithoutReplNeighborhood< moBitNeighbor<int> > test(3); moRndWithoutReplNeighborhood< moBitNeighbor<int> > test(3);
moRndWithoutReplNeighborhood< moBitNeighbor<int> > test2(0); moRndWithoutReplNeighborhood< moBitNeighbor<int> > test2(0);
//on verifie que test a bien des voisins et que test2 n'en a pas //on verifie que test a bien des voisins et que test2 n'en a pas
assert(test.hasNeighbor(sol)); assert(test.hasNeighbor(sol));
assert(!test2.hasNeighbor(sol)); assert(!test2.hasNeighbor(sol));
//on recupere successivement les index //on recupere successivement les index
test.init(sol, n); test.init(sol, n);
assert(test.cont(sol)); assert(test.cont(sol));
a=test.position(); a=test.position();
test.next(sol, n); test.next(sol, n);
assert(test.cont(sol)); assert(test.cont(sol));
b=test.position(); b=test.position();
test.next(sol,n); test.next(sol,n);
assert(!test.cont(sol)); assert(!test.cont(sol));
c=test.position(); c=test.position();
//on s'assure qu'on a bien 0, 1 et 2 (dans un ordre aléatoire) //on s'assure qu'on a bien 0, 1 et 2 (dans un ordre aléatoire)
assert(a==0 || b==0 || c==0); assert(a==0 || b==0 || c==0);
assert(a==1 || b==1 || c==1); assert(a==1 || b==1 || c==1);
assert(a==2 || b==2 || c==2); assert(a==2 || b==2 || c==2);
assert(test.className()=="moRndWithoutReplNeighborhood"); assert(test.className()=="moRndWithoutReplNeighborhood");
std::cout << "[t-moRndWithoutReplNeighborhood] => OK" << std::endl; std::cout << "[t-moRndWithoutReplNeighborhood] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -41,52 +41,52 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
//Pas grand chose à faire: le gros du travail est fait par le voisin et l'eval //Pas grand chose à faire: le gros du travail est fait par le voisin et l'eval
std::cout << "[t-moSimpleHCexplorer] => START" << std::endl; std::cout << "[t-moSimpleHCexplorer] => START" << std::endl;
Solution sol; Solution sol;
moDummyNeighbor neighbor; moDummyNeighbor neighbor;
moDummyEval eval; moDummyEval eval;
moDummyNeighborhood nh; moDummyNeighborhood nh;
moFullEvalByCopy<moDummyNeighbor> fulleval(eval); moFullEvalByCopy<moDummyNeighbor> fulleval(eval);
moNeighborComparator<moDummyNeighbor> comp; moNeighborComparator<moDummyNeighbor> comp;
moSolNeighborComparator<moDummyNeighbor> solNeighborComp; moSolNeighborComparator<moDummyNeighbor> solNeighborComp;
//verif constructor //verif constructor
moSimpleHCexplorer<moDummyNeighborhood> test(nh, fulleval, comp, solNeighborComp); moSimpleHCexplorer<moDummyNeighborhood> test(nh, fulleval, comp, solNeighborComp);
//verif operator() et accept: le neigorhood est construit pour qu'on tombe dans les 3 cas suivants: //verif operator() et accept: le neigorhood est construit pour qu'on tombe dans les 3 cas suivants:
//hasNeighbor() retourne faux a l'entrée de l'operator() donc on doit pas continuer //hasNeighbor() retourne faux a l'entrée de l'operator() donc on doit pas continuer
sol.fitness(3); sol.fitness(3);
test(sol); test(sol);
test.accept(sol); test.accept(sol);
assert(!test.isContinue(sol)); assert(!test.isContinue(sol));
//hasNeighbor() retourne faux a l'entrée de accept() donc on doit pas continuer //hasNeighbor() retourne faux a l'entrée de accept() donc on doit pas continuer
test(sol); test(sol);
test.accept(sol); test.accept(sol);
assert(!test.isContinue(sol)); assert(!test.isContinue(sol));
//hasNeighbor() retourne vrai et on ameliore la fitness donc on doit continuer //hasNeighbor() retourne vrai et on ameliore la fitness donc on doit continuer
test(sol); test(sol);
test.accept(sol); test.accept(sol);
assert(test.isContinue(sol)); assert(test.isContinue(sol));
//verif de move -> on affecte la fitness du best d'avant //verif de move -> on affecte la fitness du best d'avant
test.move(sol); test.move(sol);
//hasNeighbor() retourne vrai et on ameliore pas la fitness donc on doit pas continuer //hasNeighbor() retourne vrai et on ameliore pas la fitness donc on doit pas continuer
test(sol); test(sol);
test(sol); test(sol);
test.accept(sol); test.accept(sol);
assert(!test.isContinue(sol)); assert(!test.isContinue(sol));
assert(test.className()=="moSimpleHCexplorer"); assert(test.className()=="moSimpleHCexplorer");
std::cout << "[t-moSimpleHCexplorer] => OK" << std::endl; std::cout << "[t-moSimpleHCexplorer] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -36,66 +36,66 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moSimpleHCneutralExplorer] => START" << std::endl; std::cout << "[t-moSimpleHCneutralExplorer] => START" << std::endl;
//instanciation //instanciation
eoBit<eoMinimizingFitness> sol(4, true); eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4); sol.fitness(4);
bitNeighborhood nh(4); bitNeighborhood nh(4);
evalOneMax eval(4); evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp; moNeighborComparator<bitNeighbor> ncomp;
moSolNeighborComparator<bitNeighbor> sncomp; moSolNeighborComparator<bitNeighbor> sncomp;
moSimpleHCneutralExplorer<bitNeighborhood> test(nh, eval, ncomp, sncomp); moSimpleHCneutralExplorer<bitNeighborhood> test(nh, eval, ncomp, sncomp);
//test qu'on ameliore bien a chaque itération //test qu'on ameliore bien a chaque itération
test.initParam(sol); test.initParam(sol);
test(sol); test(sol);
assert(test.accept(sol)); assert(test.accept(sol));
test.move(sol); test.move(sol);
assert(sol.fitness()==3); assert(sol.fitness()==3);
assert(test.isContinue(sol)); assert(test.isContinue(sol));
test.updateParam(sol); test.updateParam(sol);
//les affichages permettent de voir qu'on choisit pas toujours les mm voisins améliorant (lancer plusieurs fois l'exe) //les affichages permettent de voir qu'on choisit pas toujours les mm voisins améliorant (lancer plusieurs fois l'exe)
std::cout << sol << std::endl; std::cout << sol << std::endl;
test(sol); test(sol);
assert(test.accept(sol)); assert(test.accept(sol));
test.move(sol); test.move(sol);
assert(sol.fitness()==2); assert(sol.fitness()==2);
assert(test.isContinue(sol)); assert(test.isContinue(sol));
test.updateParam(sol); test.updateParam(sol);
std::cout << sol << std::endl; std::cout << sol << std::endl;
test(sol); test(sol);
assert(test.accept(sol)); assert(test.accept(sol));
test.move(sol); test.move(sol);
assert(sol.fitness()==1); assert(sol.fitness()==1);
assert(test.isContinue(sol)); assert(test.isContinue(sol));
test.updateParam(sol); test.updateParam(sol);
std::cout << sol << std::endl; std::cout << sol << std::endl;
test(sol); test(sol);
assert(test.accept(sol)); assert(test.accept(sol));
test.move(sol); test.move(sol);
assert(sol.fitness()==0); assert(sol.fitness()==0);
assert(test.isContinue(sol)); assert(test.isContinue(sol));
test.updateParam(sol); test.updateParam(sol);
test(sol); test(sol);
assert(!test.accept(sol)); assert(!test.accept(sol));
assert(sol.fitness()==0); assert(sol.fitness()==0);
assert(!test.isContinue(sol)); assert(!test.isContinue(sol));
test.updateParam(sol); test.updateParam(sol);
std::cout << "[t-moSimpleHCneutralExplorer] => OK" << std::endl; std::cout << "[t-moSimpleHCneutralExplorer] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -40,33 +40,33 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moSolNeighborComparator] => START" << std::endl; std::cout << "[t-moSolNeighborComparator] => START" << std::endl;
moBitNeighbor<eoMinimizingFitness> neighbor; moBitNeighbor<eoMinimizingFitness> neighbor;
eoBit<eoMinimizingFitness> sol; eoBit<eoMinimizingFitness> sol;
moSolNeighborComparator< moBitNeighbor<eoMinimizingFitness> > test; moSolNeighborComparator< moBitNeighbor<eoMinimizingFitness> > test;
neighbor.fitness(3); neighbor.fitness(3);
sol.fitness(2); sol.fitness(2);
//test with a minimizing fitness, neighbor must not be better than sol //test with a minimizing fitness, neighbor must not be better than sol
assert(!test(sol, neighbor)); assert(!test(sol, neighbor));
//reversly //reversly
neighbor.fitness(2); neighbor.fitness(2);
sol.fitness(3); sol.fitness(3);
assert(test(sol, neighbor)); assert(test(sol, neighbor));
//test equals //test equals
assert(!test.equals(sol, neighbor)); assert(!test.equals(sol, neighbor));
neighbor.fitness(3); neighbor.fitness(3);
assert(test.equals(sol, neighbor)); assert(test.equals(sol, neighbor));
assert(test.className()=="moSolNeighborComparator"); assert(test.className()=="moSolNeighborComparator");
std::cout << "[t-moSolNeighborComparator] => OK" << std::endl; std::cout << "[t-moSolNeighborComparator] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -34,121 +34,121 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moSolVectorTabuList] => START" << std::endl; std::cout << "[t-moSolVectorTabuList] => START" << std::endl;
//test without countdown //test without countdown
moSolVectorTabuList<bitNeighbor> test(2,0); moSolVectorTabuList<bitNeighbor> test(2,0);
bitNeighbor n1; bitNeighbor n1;
bitNeighbor n2; bitNeighbor n2;
bitNeighbor n3; bitNeighbor n3;
bitNeighbor n4; bitNeighbor n4;
n1.index(0); n1.index(0);
n2.index(1); n2.index(1);
n3.index(2); n3.index(2);
n4.index(3); n4.index(3);
eoBit<eoMinimizingFitness> sol1(4, true); eoBit<eoMinimizingFitness> sol1(4, true);
eoBit<eoMinimizingFitness> sol2(4, true); eoBit<eoMinimizingFitness> sol2(4, true);
eoBit<eoMinimizingFitness> sol3(4, true); eoBit<eoMinimizingFitness> sol3(4, true);
eoBit<eoMinimizingFitness> sol4(4, true); eoBit<eoMinimizingFitness> sol4(4, true);
sol2[0]=false; sol2[0]=false;
sol3[1]=false; sol3[1]=false;
sol4[0]=false; sol4[0]=false;
sol4[1]=false; sol4[1]=false;
//init //init
test.init(sol1); test.init(sol1);
//ajout d'une sol tabu //ajout d'une sol tabu
test.add(sol1,n1); test.add(sol1,n1);
//verification des voisins de chaques sol //verification des voisins de chaques sol
assert(test.check(sol2,n1)); assert(test.check(sol2,n1));
assert(!test.check(sol2,n2)); assert(!test.check(sol2,n2));
assert(!test.check(sol2,n3)); assert(!test.check(sol2,n3));
assert(!test.check(sol2,n4)); assert(!test.check(sol2,n4));
assert(!test.check(sol3,n1)); assert(!test.check(sol3,n1));
assert(test.check(sol3,n2)); assert(test.check(sol3,n2));
assert(!test.check(sol3,n3)); assert(!test.check(sol3,n3));
assert(!test.check(sol3,n4)); assert(!test.check(sol3,n4));
assert(!test.check(sol4,n1)); assert(!test.check(sol4,n1));
assert(!test.check(sol4,n2)); assert(!test.check(sol4,n2));
assert(!test.check(sol4,n3)); assert(!test.check(sol4,n3));
assert(!test.check(sol4,n4)); assert(!test.check(sol4,n4));
test.init(sol1); test.init(sol1);
assert(!test.check(sol2,n1)); assert(!test.check(sol2,n1));
assert(!test.check(sol3,n2)); assert(!test.check(sol3,n2));
test.update(sol1,n1); test.update(sol1,n1);
test.add(sol1,n1); test.add(sol1,n1);
test.add(sol2,n1); test.add(sol2,n1);
assert(test.check(sol2,n1)); assert(test.check(sol2,n1));
test.add(sol4,n1); test.add(sol4,n1);
assert(!test.check(sol2,n1)); assert(!test.check(sol2,n1));
assert(test.check(sol2,n2)); assert(test.check(sol2,n2));
//test with a countdown at 3 //test with a countdown at 3
moSolVectorTabuList<bitNeighbor> test2(2,2); moSolVectorTabuList<bitNeighbor> test2(2,2);
test2.init(sol1); test2.init(sol1);
test2.add(sol1,n1); test2.add(sol1,n1);
assert(test2.check(sol2,n1)); assert(test2.check(sol2,n1));
assert(!test2.check(sol2,n2)); assert(!test2.check(sol2,n2));
assert(!test2.check(sol2,n3)); assert(!test2.check(sol2,n3));
assert(!test2.check(sol2,n4)); assert(!test2.check(sol2,n4));
assert(!test2.check(sol3,n1)); assert(!test2.check(sol3,n1));
assert(test2.check(sol3,n2)); assert(test2.check(sol3,n2));
assert(!test2.check(sol3,n3)); assert(!test2.check(sol3,n3));
assert(!test2.check(sol3,n4)); assert(!test2.check(sol3,n4));
assert(!test2.check(sol4,n1)); assert(!test2.check(sol4,n1));
assert(!test2.check(sol4,n2)); assert(!test2.check(sol4,n2));
assert(!test2.check(sol4,n3)); assert(!test2.check(sol4,n3));
assert(!test2.check(sol4,n4)); assert(!test2.check(sol4,n4));
//coutdown sol1 -> 1 //coutdown sol1 -> 1
test2.update(sol1,n1); test2.update(sol1,n1);
assert(test2.check(sol2,n1)); assert(test2.check(sol2,n1));
assert(!test2.check(sol2,n2)); assert(!test2.check(sol2,n2));
assert(!test2.check(sol2,n3)); assert(!test2.check(sol2,n3));
assert(!test2.check(sol2,n4)); assert(!test2.check(sol2,n4));
assert(!test2.check(sol3,n1)); assert(!test2.check(sol3,n1));
assert(test2.check(sol3,n2)); assert(test2.check(sol3,n2));
assert(!test2.check(sol3,n3)); assert(!test2.check(sol3,n3));
assert(!test2.check(sol3,n4)); assert(!test2.check(sol3,n4));
assert(!test2.check(sol4,n1)); assert(!test2.check(sol4,n1));
assert(!test2.check(sol4,n2)); assert(!test2.check(sol4,n2));
assert(!test2.check(sol4,n3)); assert(!test2.check(sol4,n3));
assert(!test2.check(sol4,n4)); assert(!test2.check(sol4,n4));
//coutdown sol1 -> 0 : sol1 is no longer tabu //coutdown sol1 -> 0 : sol1 is no longer tabu
test2.update(sol1,n1); test2.update(sol1,n1);
assert(!test2.check(sol2,n1)); assert(!test2.check(sol2,n1));
assert(!test2.check(sol2,n2)); assert(!test2.check(sol2,n2));
assert(!test2.check(sol2,n3)); assert(!test2.check(sol2,n3));
assert(!test2.check(sol2,n4)); assert(!test2.check(sol2,n4));
assert(!test2.check(sol3,n1)); assert(!test2.check(sol3,n1));
assert(!test2.check(sol3,n2)); assert(!test2.check(sol3,n2));
assert(!test2.check(sol3,n3)); assert(!test2.check(sol3,n3));
assert(!test2.check(sol3,n4)); assert(!test2.check(sol3,n4));
assert(!test2.check(sol4,n1)); assert(!test2.check(sol4,n1));
assert(!test2.check(sol4,n2)); assert(!test2.check(sol4,n2));
assert(!test2.check(sol4,n3)); assert(!test2.check(sol4,n3));
assert(!test2.check(sol4,n4)); assert(!test2.check(sol4,n4));
std::cout << "[t-moSolVectorTabuList] => OK" << std::endl; std::cout << "[t-moSolVectorTabuList] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -34,31 +34,31 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moSolutionStat] => START" << std::endl; std::cout << "[t-moSolutionStat] => START" << std::endl;
eoBit<unsigned int> s(3); eoBit<unsigned int> s(3);
s[0]=true; s[0]=true;
s[1]=true; s[1]=true;
s[2]=false; s[2]=false;
s.fitness(17); s.fitness(17);
moSolutionStat< eoBit<unsigned int > > test; moSolutionStat< eoBit<unsigned int > > test;
test(s); test(s);
//on verifie que la solution est bien enregistré //on verifie que la solution est bien enregistré
assert(test.value()[0]); assert(test.value()[0]);
assert(test.value()[1]); assert(test.value()[1]);
assert(!test.value()[2]); assert(!test.value()[2]);
assert(test.value().fitness()==17); assert(test.value().fitness()==17);
assert(test.className()=="moSolutionStat"); assert(test.className()=="moSolutionStat");
std::cout << "[t-moSolutionStat] => OK" << std::endl; std::cout << "[t-moSolutionStat] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -38,128 +38,128 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moTSExplorer] => START" << std::endl; std::cout << "[t-moTSExplorer] => START" << std::endl;
//instansiation //instansiation
eoBit<eoMinimizingFitness> sol(4, true); eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4); sol.fitness(4);
bitNeighborhood nh(4); bitNeighborhood nh(4);
bitNeighborhood emptyNH(0); bitNeighborhood emptyNH(0);
evalOneMax eval(4); evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp; moNeighborComparator<bitNeighbor> ncomp;
moSolNeighborComparator<bitNeighbor> sncomp; moSolNeighborComparator<bitNeighbor> sncomp;
moDummyIntensification<bitNeighbor> intens; moDummyIntensification<bitNeighbor> intens;
moDummyDiversification<bitNeighbor> diver; moDummyDiversification<bitNeighbor> diver;
moSolVectorTabuList<bitNeighbor> tabuList(4,0); moSolVectorTabuList<bitNeighbor> tabuList(4,0);
moBestImprAspiration<bitNeighbor> aspir; moBestImprAspiration<bitNeighbor> aspir;
moTSExplorer<bitNeighborhood> test(nh, eval, ncomp, sncomp, tabuList, intens, diver, aspir); moTSExplorer<bitNeighborhood> test(nh, eval, ncomp, sncomp, tabuList, intens, diver, aspir);
moTSExplorer<bitNeighborhood> test2(emptyNH, eval, ncomp, sncomp, tabuList, intens, diver, aspir); moTSExplorer<bitNeighborhood> test2(emptyNH, eval, ncomp, sncomp, tabuList, intens, diver, aspir);
//test d'un voisinage vide //test d'un voisinage vide
test2.initParam(sol); test2.initParam(sol);
test2(sol); test2(sol);
assert(!test2.accept(sol)); assert(!test2.accept(sol));
//test le comportement classique de la taboo //test le comportement classique de la taboo
test.initParam(sol); test.initParam(sol);
assert(aspir.getBest()==sol); assert(aspir.getBest()==sol);
test(sol); test(sol);
test.updateParam(sol); test.updateParam(sol);
assert(aspir.getBest()==sol); assert(aspir.getBest()==sol);
//on ameliore et on stock une sol tabou 0111 //on ameliore et on stock une sol tabou 0111
test(sol); test(sol);
test.move(sol); test.move(sol);
test.moveApplied(true); test.moveApplied(true);
test.updateParam(sol); test.updateParam(sol);
assert(aspir.getBest()==sol); assert(aspir.getBest()==sol);
//on ameliore et on stock une autre sol tabou 0011 //on ameliore et on stock une autre sol tabou 0011
test(sol); test(sol);
test.move(sol); test.move(sol);
test.moveApplied(true); test.moveApplied(true);
test.updateParam(sol); test.updateParam(sol);
assert(aspir.getBest()==sol); assert(aspir.getBest()==sol);
//pareil on stock 0001 met pdt la recherche on se rend compte que 0111 est tabou //pareil on stock 0001 met pdt la recherche on se rend compte que 0111 est tabou
test(sol); test(sol);
test.move(sol); test.move(sol);
test.moveApplied(true); test.moveApplied(true);
test.updateParam(sol); test.updateParam(sol);
assert(aspir.getBest()==sol); assert(aspir.getBest()==sol);
//on modifie la sol en 1001(fitness 2) pour que la 1er sol exploré(0001) soit tabou //on modifie la sol en 1001(fitness 2) pour que la 1er sol exploré(0001) soit tabou
//De plus on change la solution mais elle est pas meilleure que la best so Far //De plus on change la solution mais elle est pas meilleure que la best so Far
sol[0]=true; sol[0]=true;
std::cout << sol << std::endl; std::cout << sol << std::endl;
sol.fitness(2); sol.fitness(2);
test(sol); test(sol);
test.move(sol); test.move(sol);
test.moveApplied(true); test.moveApplied(true);
test.updateParam(sol); test.updateParam(sol);
assert( sol[0] && !sol[1] && !sol[2] && !sol[3]); assert( sol[0] && !sol[1] && !sol[2] && !sol[3]);
sol[0]=false; sol[0]=false;
sol[3]=true; sol[3]=true;
assert(aspir.getBest()==sol); assert(aspir.getBest()==sol);
//test du isContinue //test du isContinue
assert(test.isContinue(sol)); assert(test.isContinue(sol));
//test du terminate //test du terminate
test.initParam(sol); test.initParam(sol);
sol[0]=true; sol[0]=true;
sol[1]=true; sol[1]=true;
sol[2]=true; sol[2]=true;
sol[3]=true; sol[3]=true;
sol.fitness(4); sol.fitness(4);
test(sol); test(sol);
test.move(sol); test.move(sol);
test.moveApplied(true); test.moveApplied(true);
test.updateParam(sol); test.updateParam(sol);
assert( !sol[0] && sol[1] && sol[2] && sol[3]); assert( !sol[0] && sol[1] && sol[2] && sol[3]);
test.terminate(sol); test.terminate(sol);
assert( !sol[0] && !sol[1] && !sol[2] && sol[3]); assert( !sol[0] && !sol[1] && !sol[2] && sol[3]);
//test pour avoir que des mouvement taboo //test pour avoir que des mouvement taboo
eoBit<eoMinimizingFitness> sol2(2, true); eoBit<eoMinimizingFitness> sol2(2, true);
sol2.fitness(2); sol2.fitness(2);
bitNeighborhood nh2(2); bitNeighborhood nh2(2);
evalOneMax eval2(2); evalOneMax eval2(2);
moTSExplorer<bitNeighborhood> test3(nh2, eval2, ncomp, sncomp, tabuList, intens, diver, aspir); moTSExplorer<bitNeighborhood> test3(nh2, eval2, ncomp, sncomp, tabuList, intens, diver, aspir);
test3.initParam(sol2); test3.initParam(sol2);
test3(sol2); test3(sol2);
test3.move(sol2); test3.move(sol2);
test3.moveApplied(true); test3.moveApplied(true);
test3.updateParam(sol2); test3.updateParam(sol2);
test3(sol2); test3(sol2);
test3.move(sol2); test3.move(sol2);
test3.moveApplied(true); test3.moveApplied(true);
test3.updateParam(sol2); test3.updateParam(sol2);
test3(sol2); test3(sol2);
test3.move(sol2); test3.move(sol2);
test3.moveApplied(true); test3.moveApplied(true);
test3.updateParam(sol2); test3.updateParam(sol2);
test3(sol2); test3(sol2);
test3.move(sol2); test3.move(sol2);
test3.moveApplied(true); test3.moveApplied(true);
test3.updateParam(sol2); test3.updateParam(sol2);
//on a rempli la liste tabu pour que tout les voisins soit tabu //on a rempli la liste tabu pour que tout les voisins soit tabu
test3(sol2); test3(sol2);
assert(!test3.accept(sol2)); assert(!test3.accept(sol2));
std::cout << "[t-moTSExplorer] => OK" << std::endl; std::cout << "[t-moTSExplorer] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -39,15 +39,15 @@
#include <cassert> #include <cassert>
int main(){ int main() {
std::cout << "[t-moTrueContinuator] => START" << std::endl; std::cout << "[t-moTrueContinuator] => START" << std::endl;
moTrueContinuator<moDummyNeighborhood> test; moTrueContinuator<moDummyNeighborhood> test;
Solution s; Solution s;
assert(test(s)); assert(test(s));
std::cout << "[t-moTrueContinuator] => OK" << std::endl; std::cout << "[t-moTrueContinuator] => OK" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -44,142 +44,142 @@ typedef moRndWithoutReplNeighborhood<Neighbor> Neighborhood ;
void main_function(int argc, char **argv) void main_function(int argc, char **argv)
{ {
/* ========================================================= /* =========================================================
* *
* Parameters * Parameters
* *
* ========================================================= */ * ========================================================= */
// First define a parser from the command-line arguments // First define a parser from the command-line arguments
eoParser parser(argc, argv); eoParser parser(argc, argv);
// For each parameter, define Parameter, read it through the parser, // For each parameter, define Parameter, read it through the parser,
// and assign the value to the variable // and assign the value to the variable
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S'); eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam ); parser.processParam( seedParam );
unsigned seed = seedParam.value(); unsigned seed = seedParam.value();
// description of genotype // description of genotype
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V'); eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
parser.processParam( vecSizeParam, "Representation" ); parser.processParam( vecSizeParam, "Representation" );
unsigned vecSize = vecSizeParam.value(); unsigned vecSize = vecSizeParam.value();
// the name of the "status" file where all actual parameter values will be saved // the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file"); eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
parser.processParam( statusParam, "Persistence" ); parser.processParam( statusParam, "Persistence" );
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
// i.e. in case you need parameters somewhere else, postpone these // i.e. in case you need parameters somewhere else, postpone these
if (parser.userNeedsHelp()){ if (parser.userNeedsHelp()) {
parser.printHelp(cout); parser.printHelp(cout);
exit(1); exit(1);
} }
if (statusParam.value() != ""){ if (statusParam.value() != "") {
ofstream os(statusParam.value().c_str()); ofstream os(statusParam.value().c_str());
os << parser;// and you can use that file as parameter file os << parser;// and you can use that file as parameter file
} }
/* ========================================================= /* =========================================================
* *
* Random seed * Random seed
* *
* ========================================================= */ * ========================================================= */
//reproducible random seed: if you don't change SEED above, //reproducible random seed: if you don't change SEED above,
// you'll aways get the same result, NOT a random run // you'll aways get the same result, NOT a random run
rng.reseed(seed); rng.reseed(seed);
/* ========================================================= /* =========================================================
* *
* Eval fitness function * Eval fitness function
* *
* ========================================================= */ * ========================================================= */
FuncOneMax<Indi> eval(vecSize); FuncOneMax<Indi> eval(vecSize);
/* ========================================================= /* =========================================================
* *
* Initilisation of the solution * Initilisation of the solution
* *
* ========================================================= */ * ========================================================= */
// a Indi random initializer // a Indi random initializer
eoUniformGenerator<bool> uGen; eoUniformGenerator<bool> uGen;
eoInitFixedLength<Indi> random(vecSize, uGen); eoInitFixedLength<Indi> random(vecSize, uGen);
/* ========================================================= /* =========================================================
* *
* evaluation of a neighbor solution * evaluation of a neighbor solution
* *
* ========================================================= */ * ========================================================= */
moFullEvalByModif<Neighbor> fulleval(eval); moFullEvalByModif<Neighbor> fulleval(eval);
//An eval by copy can be used instead of the eval by modif //An eval by copy can be used instead of the eval by modif
//moFullEvalByCopy<Neighbor> fulleval(eval); //moFullEvalByCopy<Neighbor> fulleval(eval);
/* ========================================================= /* =========================================================
* *
* Comparator of neighbors * Comparator of neighbors
* *
* ========================================================= */ * ========================================================= */
moNeighborComparator<Neighbor> comparator; moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator; moSolNeighborComparator<Neighbor> solComparator;
/* ========================================================= /* =========================================================
* *
* the neighborhood of a solution * the neighborhood of a solution
* *
* ========================================================= */ * ========================================================= */
Neighborhood neighborhood(vecSize); Neighborhood neighborhood(vecSize);
/* ========================================================= /* =========================================================
* *
* a neighborhood explorer solution * a neighborhood explorer solution
* *
* ========================================================= */ * ========================================================= */
moFirstImprExplorer<Neighborhood> explorer(neighborhood, fulleval, comparator, solComparator); moFirstImprExplorer<Neighborhood> explorer(neighborhood, fulleval, comparator, solComparator);
/* ========================================================= /* =========================================================
* *
* the local search algorithm * the local search algorithm
* *
* ========================================================= */ * ========================================================= */
moTrueContinuator<Neighborhood> continuator;//always continue moTrueContinuator<Neighborhood> continuator;//always continue
moLocalSearch< moFirstImprExplorer<Neighborhood> > localSearch(explorer, continuator, eval); moLocalSearch< moFirstImprExplorer<Neighborhood> > localSearch(explorer, continuator, eval);
/* ========================================================= /* =========================================================
* *
* execute the local search from random sollution * execute the local search from random sollution
* *
* ========================================================= */ * ========================================================= */
Indi solution; Indi solution;
random(solution); random(solution);
//Can be eval here, else it will be done at the beginning of the localSearch //Can be eval here, else it will be done at the beginning of the localSearch
//eval(solution); //eval(solution);
std::cout << "initial: " << solution << std::endl ; std::cout << "initial: " << solution << std::endl ;
localSearch(solution); localSearch(solution);
std::cout << "final: " << solution << std::endl ; std::cout << "final: " << solution << std::endl ;
} }
@ -187,11 +187,11 @@ void main_function(int argc, char **argv)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
try{ try {
main_function(argc, argv); main_function(argc, argv);
} }
catch(exception& e){ catch (exception& e) {
cout << "Exception: " << e.what() << '\n'; cout << "Exception: " << e.what() << '\n';
} }
return 1; return 1;
} }

View file

@ -44,146 +44,146 @@ typedef moOrderNeighborhood<Neighbor> Neighborhood ;
void main_function(int argc, char **argv) void main_function(int argc, char **argv)
{ {
/* ========================================================= /* =========================================================
* *
* Parameters * Parameters
* *
* ========================================================= */ * ========================================================= */
// First define a parser from the command-line arguments // First define a parser from the command-line arguments
eoParser parser(argc, argv); eoParser parser(argc, argv);
// For each parameter, define Parameter, read it through the parser, // For each parameter, define Parameter, read it through the parser,
// and assign the value to the variable // and assign the value to the variable
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S'); eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam ); parser.processParam( seedParam );
unsigned seed = seedParam.value(); unsigned seed = seedParam.value();
// description of genotype // description of genotype
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V'); eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
parser.processParam( vecSizeParam, "Representation" ); parser.processParam( vecSizeParam, "Representation" );
unsigned vecSize = vecSizeParam.value(); unsigned vecSize = vecSizeParam.value();
eoValueParam<unsigned int> stepParam(10, "nbStep", "Number of steps of the random walk", 'n'); eoValueParam<unsigned int> stepParam(10, "nbStep", "Number of steps of the random walk", 'n');
parser.processParam( stepParam, "Representation" ); parser.processParam( stepParam, "Representation" );
unsigned nbStep = stepParam.value(); unsigned nbStep = stepParam.value();
// the name of the "status" file where all actual parameter values will be saved // the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file"); eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
parser.processParam( statusParam, "Persistence" ); parser.processParam( statusParam, "Persistence" );
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
// i.e. in case you need parameters somewhere else, postpone these // i.e. in case you need parameters somewhere else, postpone these
if (parser.userNeedsHelp()){ if (parser.userNeedsHelp()) {
parser.printHelp(cout); parser.printHelp(cout);
exit(1); exit(1);
} }
if (statusParam.value() != ""){ if (statusParam.value() != "") {
ofstream os(statusParam.value().c_str()); ofstream os(statusParam.value().c_str());
os << parser;// and you can use that file as parameter file os << parser;// and you can use that file as parameter file
} }
/* ========================================================= /* =========================================================
* *
* Random seed * Random seed
* *
* ========================================================= */ * ========================================================= */
//reproducible random seed: if you don't change SEED above, //reproducible random seed: if you don't change SEED above,
// you'll aways get the same result, NOT a random run // you'll aways get the same result, NOT a random run
rng.reseed(seed); rng.reseed(seed);
/* ========================================================= /* =========================================================
* *
* Eval fitness function * Eval fitness function
* *
* ========================================================= */ * ========================================================= */
FuncOneMax<Indi> eval(vecSize); FuncOneMax<Indi> eval(vecSize);
/* ========================================================= /* =========================================================
* *
* Initilisation of the solution * Initilisation of the solution
* *
* ========================================================= */ * ========================================================= */
// a Indi random initializer // a Indi random initializer
eoUniformGenerator<bool> uGen; eoUniformGenerator<bool> uGen;
eoInitFixedLength<Indi> random(vecSize, uGen); eoInitFixedLength<Indi> random(vecSize, uGen);
/* ========================================================= /* =========================================================
* *
* evaluation of a neighbor solution * evaluation of a neighbor solution
* *
* ========================================================= */ * ========================================================= */
moFullEvalByModif<Neighbor> fulleval(eval); moFullEvalByModif<Neighbor> fulleval(eval);
//An eval by copy can be used instead of the eval by modif //An eval by copy can be used instead of the eval by modif
//moFullEvalByCopy<Neighbor> fulleval(eval); //moFullEvalByCopy<Neighbor> fulleval(eval);
/* ========================================================= /* =========================================================
* *
* Comparator of neighbors * Comparator of neighbors
* *
* ========================================================= */ * ========================================================= */
moNeighborComparator<Neighbor> comparator; moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator; moSolNeighborComparator<Neighbor> solComparator;
/* ========================================================= /* =========================================================
* *
* the neighborhood of a solution * the neighborhood of a solution
* *
* ========================================================= */ * ========================================================= */
Neighborhood neighborhood(vecSize); Neighborhood neighborhood(vecSize);
/* ========================================================= /* =========================================================
* *
* a neighborhood explorer solution * a neighborhood explorer solution
* *
* ========================================================= */ * ========================================================= */
moHCneutralExplorer<Neighborhood> explorer(neighborhood, fulleval, comparator, solComparator, nbStep); moHCneutralExplorer<Neighborhood> explorer(neighborhood, fulleval, comparator, solComparator, nbStep);
/* ========================================================= /* =========================================================
* *
* the local search algorithm * the local search algorithm
* *
* ========================================================= */ * ========================================================= */
moTrueContinuator<Neighborhood> continuator;//always continue moTrueContinuator<Neighborhood> continuator;//always continue
moLocalSearch< moHCneutralExplorer<Neighborhood> > localSearch(explorer, continuator, eval); moLocalSearch< moHCneutralExplorer<Neighborhood> > localSearch(explorer, continuator, eval);
/* ========================================================= /* =========================================================
* *
* execute the local search from random sollution * execute the local search from random sollution
* *
* ========================================================= */ * ========================================================= */
Indi solution; Indi solution;
random(solution); random(solution);
//Can be eval here, else it will be done at the beginning of the localSearch //Can be eval here, else it will be done at the beginning of the localSearch
//eval(solution); //eval(solution);
std::cout << "initial: " << solution << std::endl ; std::cout << "initial: " << solution << std::endl ;
localSearch(solution); localSearch(solution);
std::cout << "final: " << solution << std::endl ; std::cout << "final: " << solution << std::endl ;
} }
@ -191,11 +191,11 @@ void main_function(int argc, char **argv)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
try{ try {
main_function(argc, argv); main_function(argc, argv);
} }
catch(exception& e){ catch (exception& e) {
cout << "Exception: " << e.what() << '\n'; cout << "Exception: " << e.what() << '\n';
} }
return 1; return 1;
} }

View file

@ -44,146 +44,146 @@ typedef moRndWithReplNeighborhood<Neighbor> Neighborhood ;
void main_function(int argc, char **argv) void main_function(int argc, char **argv)
{ {
/* ========================================================= /* =========================================================
* *
* Parameters * Parameters
* *
* ========================================================= */ * ========================================================= */
// First define a parser from the command-line arguments // First define a parser from the command-line arguments
eoParser parser(argc, argv); eoParser parser(argc, argv);
// For each parameter, define Parameter, read it through the parser, // For each parameter, define Parameter, read it through the parser,
// and assign the value to the variable // and assign the value to the variable
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S'); eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam ); parser.processParam( seedParam );
unsigned seed = seedParam.value(); unsigned seed = seedParam.value();
// description of genotype // description of genotype
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V'); eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
parser.processParam( vecSizeParam, "Representation" ); parser.processParam( vecSizeParam, "Representation" );
unsigned vecSize = vecSizeParam.value(); unsigned vecSize = vecSizeParam.value();
eoValueParam<unsigned int> stepParam(10, "nbStep", "Number of steps of the random walk", 'n'); eoValueParam<unsigned int> stepParam(10, "nbStep", "Number of steps of the random walk", 'n');
parser.processParam( stepParam, "Representation" ); parser.processParam( stepParam, "Representation" );
unsigned nbStep = stepParam.value(); unsigned nbStep = stepParam.value();
// the name of the "status" file where all actual parameter values will be saved // the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file"); eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
parser.processParam( statusParam, "Persistence" ); parser.processParam( statusParam, "Persistence" );
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
// i.e. in case you need parameters somewhere else, postpone these // i.e. in case you need parameters somewhere else, postpone these
if (parser.userNeedsHelp()){ if (parser.userNeedsHelp()) {
parser.printHelp(cout); parser.printHelp(cout);
exit(1); exit(1);
} }
if (statusParam.value() != ""){ if (statusParam.value() != "") {
ofstream os(statusParam.value().c_str()); ofstream os(statusParam.value().c_str());
os << parser;// and you can use that file as parameter file os << parser;// and you can use that file as parameter file
} }
/* ========================================================= /* =========================================================
* *
* Random seed * Random seed
* *
* ========================================================= */ * ========================================================= */
//reproducible random seed: if you don't change SEED above, //reproducible random seed: if you don't change SEED above,
// you'll aways get the same result, NOT a random run // you'll aways get the same result, NOT a random run
rng.reseed(seed); rng.reseed(seed);
/* ========================================================= /* =========================================================
* *
* Eval fitness function * Eval fitness function
* *
* ========================================================= */ * ========================================================= */
FuncOneMax<Indi> eval(vecSize); FuncOneMax<Indi> eval(vecSize);
/* ========================================================= /* =========================================================
* *
* Initilisation of the solution * Initilisation of the solution
* *
* ========================================================= */ * ========================================================= */
// a Indi random initializer // a Indi random initializer
eoUniformGenerator<bool> uGen; eoUniformGenerator<bool> uGen;
eoInitFixedLength<Indi> random(vecSize, uGen); eoInitFixedLength<Indi> random(vecSize, uGen);
/* ========================================================= /* =========================================================
* *
* evaluation of a neighbor solution * evaluation of a neighbor solution
* *
* ========================================================= */ * ========================================================= */
moFullEvalByModif<Neighbor> fulleval(eval); moFullEvalByModif<Neighbor> fulleval(eval);
//An eval by copy can be used instead of the eval by modif //An eval by copy can be used instead of the eval by modif
//moFullEvalByCopy<Neighbor> fulleval(eval); //moFullEvalByCopy<Neighbor> fulleval(eval);
/* ========================================================= /* =========================================================
* *
* Comparator of neighbors * Comparator of neighbors
* *
* ========================================================= */ * ========================================================= */
moNeighborComparator<Neighbor> comparator; moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator; moSolNeighborComparator<Neighbor> solComparator;
/* ========================================================= /* =========================================================
* *
* the neighborhood of a solution * the neighborhood of a solution
* *
* ========================================================= */ * ========================================================= */
Neighborhood neighborhood(vecSize); Neighborhood neighborhood(vecSize);
/* ========================================================= /* =========================================================
* *
* a neighborhood explorer solution * a neighborhood explorer solution
* *
* ========================================================= */ * ========================================================= */
moMetropolisHastingExplorer<Neighborhood> explorer(neighborhood, fulleval, comparator, solComparator, nbStep); moMetropolisHastingExplorer<Neighborhood> explorer(neighborhood, fulleval, comparator, solComparator, nbStep);
/* ========================================================= /* =========================================================
* *
* the local search algorithm * the local search algorithm
* *
* ========================================================= */ * ========================================================= */
moTrueContinuator<Neighborhood> continuator;//always continue moTrueContinuator<Neighborhood> continuator;//always continue
moLocalSearch< moMetropolisHastingExplorer<Neighborhood> > localSearch(explorer, continuator, eval); moLocalSearch< moMetropolisHastingExplorer<Neighborhood> > localSearch(explorer, continuator, eval);
/* ========================================================= /* =========================================================
* *
* execute the local search from random sollution * execute the local search from random sollution
* *
* ========================================================= */ * ========================================================= */
Indi solution; Indi solution;
random(solution); random(solution);
//Can be eval here, else it will be done at the beginning of the localSearch //Can be eval here, else it will be done at the beginning of the localSearch
//eval(solution); //eval(solution);
std::cout << "initial: " << solution << std::endl ; std::cout << "initial: " << solution << std::endl ;
localSearch(solution); localSearch(solution);
std::cout << "final: " << solution << std::endl ; std::cout << "final: " << solution << std::endl ;
} }
@ -191,11 +191,11 @@ void main_function(int argc, char **argv)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
try{ try {
main_function(argc, argv); main_function(argc, argv);
} }
catch(exception& e){ catch (exception& e) {
cout << "Exception: " << e.what() << '\n'; cout << "Exception: " << e.what() << '\n';
} }
return 1; return 1;
} }

View file

@ -58,209 +58,209 @@ typedef moRndWithoutReplNeighborhood<Neighbor> Neighborhood ;
void main_function(int argc, char **argv) void main_function(int argc, char **argv)
{ {
/* ========================================================= /* =========================================================
* *
* Parameters * Parameters
* *
* ========================================================= */ * ========================================================= */
// First define a parser from the command-line arguments // First define a parser from the command-line arguments
eoParser parser(argc, argv); eoParser parser(argc, argv);
// For each parameter, define Parameter, read it through the parser, // For each parameter, define Parameter, read it through the parser,
// and assign the value to the variable // and assign the value to the variable
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S'); eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam ); parser.processParam( seedParam );
unsigned seed = seedParam.value(); unsigned seed = seedParam.value();
// description of genotype // description of genotype
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V'); eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
parser.processParam( vecSizeParam, "Representation" ); parser.processParam( vecSizeParam, "Representation" );
unsigned vecSize = vecSizeParam.value(); unsigned vecSize = vecSizeParam.value();
eoValueParam<unsigned int> blockSizeParam(2, "blockSize", "Size of block in the royal road", 'k'); eoValueParam<unsigned int> blockSizeParam(2, "blockSize", "Size of block in the royal road", 'k');
parser.processParam( blockSizeParam, "Representation" ); parser.processParam( blockSizeParam, "Representation" );
unsigned blockSize = blockSizeParam.value(); unsigned blockSize = blockSizeParam.value();
eoValueParam<unsigned int> stepParam(10, "nbStep", "Number of steps of the random walk", 'n'); eoValueParam<unsigned int> stepParam(10, "nbStep", "Number of steps of the random walk", 'n');
parser.processParam( stepParam, "Representation" ); parser.processParam( stepParam, "Representation" );
unsigned nbStep = stepParam.value(); unsigned nbStep = stepParam.value();
// the name of the "status" file where all actual parameter values will be saved // the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file"); eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
parser.processParam( statusParam, "Persistence" ); parser.processParam( statusParam, "Persistence" );
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
// i.e. in case you need parameters somewhere else, postpone these // i.e. in case you need parameters somewhere else, postpone these
if (parser.userNeedsHelp()){ if (parser.userNeedsHelp()) {
parser.printHelp(cout); parser.printHelp(cout);
exit(1); exit(1);
} }
if (statusParam.value() != ""){ if (statusParam.value() != "") {
ofstream os(statusParam.value().c_str()); ofstream os(statusParam.value().c_str());
os << parser;// and you can use that file as parameter file os << parser;// and you can use that file as parameter file
} }
/* ========================================================= /* =========================================================
* *
* Random seed * Random seed
* *
* ========================================================= */ * ========================================================= */
//reproducible random seed: if you don't change SEED above, //reproducible random seed: if you don't change SEED above,
// you'll aways get the same result, NOT a random run // you'll aways get the same result, NOT a random run
rng.reseed(seed); rng.reseed(seed);
/* ========================================================= /* =========================================================
* *
* Eval fitness function * Eval fitness function
* *
* ========================================================= */ * ========================================================= */
FuncRoyalRoad<Indi> eval(vecSize / blockSize, blockSize); FuncRoyalRoad<Indi> eval(vecSize / blockSize, blockSize);
/* ========================================================= /* =========================================================
* *
* Initilisazor of the solution * Initilisazor of the solution
* *
* ========================================================= */ * ========================================================= */
// a Indi random initializer // a Indi random initializer
eoUniformGenerator<bool> uGen; eoUniformGenerator<bool> uGen;
eoInitFixedLength<Indi> random(vecSize, uGen); eoInitFixedLength<Indi> random(vecSize, uGen);
/* ========================================================= /* =========================================================
* *
* Evaluation of a neighbor solution * Evaluation of a neighbor solution
* *
* ========================================================= */ * ========================================================= */
moFullEvalByModif<Neighbor> nhEval(eval); moFullEvalByModif<Neighbor> nhEval(eval);
//An eval by copy can be used instead of the eval by modif //An eval by copy can be used instead of the eval by modif
//moFullEvalByCopy<Neighbor> nhEval(eval); //moFullEvalByCopy<Neighbor> nhEval(eval);
/* ========================================================= /* =========================================================
* *
* Comparator of neighbors * Comparator of neighbors
* *
* ========================================================= */ * ========================================================= */
moNeighborComparator<Neighbor> comparator; moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator; moSolNeighborComparator<Neighbor> solComparator;
/* ========================================================= /* =========================================================
* *
* the neighborhood of a solution * the neighborhood of a solution
* *
* ========================================================= */ * ========================================================= */
Neighborhood neighborhood(vecSize); Neighborhood neighborhood(vecSize);
/* ========================================================= /* =========================================================
* *
* a neighborhood explorer solution * a neighborhood explorer solution
* *
* ========================================================= */ * ========================================================= */
moRandomNeutralWalkExplorer<Neighborhood> explorer(neighborhood, nhEval, solComparator, nbStep); moRandomNeutralWalkExplorer<Neighborhood> explorer(neighborhood, nhEval, solComparator, nbStep);
/* ========================================================= /* =========================================================
* *
* initial random solution * initial random solution
* *
* ========================================================= */ * ========================================================= */
Indi solution; Indi solution;
random(solution); random(solution);
//Can be eval here, else it will be done at the beginning of the localSearch //Can be eval here, else it will be done at the beginning of the localSearch
eval(solution); eval(solution);
/* ========================================================= /* =========================================================
* *
* the continuator and the checkpoint * the continuator and the checkpoint
* *
* ========================================================= */ * ========================================================= */
moTrueContinuator<Neighborhood> continuator;//always continue moTrueContinuator<Neighborhood> continuator;//always continue
moCheckpoint<Neighborhood> checkpoint(continuator); moCheckpoint<Neighborhood> checkpoint(continuator);
moFitnessStat<Indi, unsigned> fStat; moFitnessStat<Indi, unsigned> fStat;
eoHammingDistance<Indi> distance; eoHammingDistance<Indi> distance;
moDistanceStat<Indi, unsigned> distStat(distance, solution); // distance from the intial solution moDistanceStat<Indi, unsigned> distStat(distance, solution); // distance from the intial solution
moOrderNeighborhood<Neighbor> nh(vecSize); moOrderNeighborhood<Neighbor> nh(vecSize);
moNeighborhoodStat< moOrderNeighborhood<Neighbor> > neighborhoodStat(nh, nhEval, comparator, solComparator); moNeighborhoodStat< moOrderNeighborhood<Neighbor> > neighborhoodStat(nh, nhEval, comparator, solComparator);
moMinNeighborStat< moOrderNeighborhood<Neighbor> > minStat(neighborhoodStat); moMinNeighborStat< moOrderNeighborhood<Neighbor> > minStat(neighborhoodStat);
moSecondMomentNeighborStat< moOrderNeighborhood<Neighbor> > secondMomentStat(neighborhoodStat); moSecondMomentNeighborStat< moOrderNeighborhood<Neighbor> > secondMomentStat(neighborhoodStat);
moMaxNeighborStat< moOrderNeighborhood<Neighbor> > maxStat(neighborhoodStat); moMaxNeighborStat< moOrderNeighborhood<Neighbor> > maxStat(neighborhoodStat);
moNbSupNeighborStat< moOrderNeighborhood<Neighbor> > nbSupStat(neighborhoodStat); moNbSupNeighborStat< moOrderNeighborhood<Neighbor> > nbSupStat(neighborhoodStat);
moNbInfNeighborStat< moOrderNeighborhood<Neighbor> > nbInfStat(neighborhoodStat); moNbInfNeighborStat< moOrderNeighborhood<Neighbor> > nbInfStat(neighborhoodStat);
moNeutralDegreeNeighborStat< moOrderNeighborhood<Neighbor> > ndStat(neighborhoodStat); moNeutralDegreeNeighborStat< moOrderNeighborhood<Neighbor> > ndStat(neighborhoodStat);
moSizeNeighborStat< moOrderNeighborhood<Neighbor> > sizeStat(neighborhoodStat); moSizeNeighborStat< moOrderNeighborhood<Neighbor> > sizeStat(neighborhoodStat);
eoValueParam<unsigned int> genCounter(-1,"Gen"); eoValueParam<unsigned int> genCounter(-1,"Gen");
eoIncrementor<unsigned int> increm(genCounter.value()); eoIncrementor<unsigned int> increm(genCounter.value());
checkpoint.add(fStat); checkpoint.add(fStat);
checkpoint.add(distStat); checkpoint.add(distStat);
checkpoint.add(neighborhoodStat); checkpoint.add(neighborhoodStat);
checkpoint.add(minStat); checkpoint.add(minStat);
checkpoint.add(secondMomentStat); checkpoint.add(secondMomentStat);
checkpoint.add(maxStat); checkpoint.add(maxStat);
checkpoint.add(nbInfStat); checkpoint.add(nbInfStat);
checkpoint.add(ndStat); checkpoint.add(ndStat);
checkpoint.add(nbSupStat); checkpoint.add(nbSupStat);
checkpoint.add(sizeStat); checkpoint.add(sizeStat);
checkpoint.add(increm); checkpoint.add(increm);
eoFileMonitor outputfile("out.dat", " "); eoFileMonitor outputfile("out.dat", " ");
checkpoint.add(outputfile); checkpoint.add(outputfile);
outputfile.add(genCounter); outputfile.add(genCounter);
outputfile.add(fStat); outputfile.add(fStat);
outputfile.add(distStat); outputfile.add(distStat);
outputfile.add(minStat); outputfile.add(minStat);
outputfile.add(secondMomentStat); outputfile.add(secondMomentStat);
outputfile.add(maxStat); outputfile.add(maxStat);
outputfile.add(nbInfStat); outputfile.add(nbInfStat);
outputfile.add(ndStat); outputfile.add(ndStat);
outputfile.add(nbSupStat); outputfile.add(nbSupStat);
outputfile.add(sizeStat); outputfile.add(sizeStat);
/* ========================================================= /* =========================================================
* *
* the local search algorithm * the local search algorithm
* *
* ========================================================= */ * ========================================================= */
moLocalSearch< moRandomNeutralWalkExplorer<Neighborhood> > localSearch(explorer, checkpoint, eval); moLocalSearch< moRandomNeutralWalkExplorer<Neighborhood> > localSearch(explorer, checkpoint, eval);
/* ========================================================= /* =========================================================
* *
* execute the local search from random sollution * execute the local search from random sollution
* *
* ========================================================= */ * ========================================================= */
std::cout << "initial: " << solution << std::endl ; std::cout << "initial: " << solution << std::endl ;
localSearch(solution); localSearch(solution);
std::cout << "final: " << solution << std::endl ; std::cout << "final: " << solution << std::endl ;
} }
@ -268,11 +268,11 @@ void main_function(int argc, char **argv)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
try{ try {
main_function(argc, argv); main_function(argc, argv);
} }
catch(exception& e){ catch (exception& e) {
cout << "Exception: " << e.what() << '\n'; cout << "Exception: " << e.what() << '\n';
} }
return 1; return 1;
} }

View file

@ -50,182 +50,182 @@ typedef moRndWithReplNeighborhood<Neighbor> Neighborhood ;
void main_function(int argc, char **argv) void main_function(int argc, char **argv)
{ {
/* ========================================================= /* =========================================================
* *
* Parameters * Parameters
* *
* ========================================================= */ * ========================================================= */
// First define a parser from the command-line arguments // First define a parser from the command-line arguments
eoParser parser(argc, argv); eoParser parser(argc, argv);
// For each parameter, define Parameter, read it through the parser, // For each parameter, define Parameter, read it through the parser,
// and assign the value to the variable // and assign the value to the variable
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S'); eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam ); parser.processParam( seedParam );
unsigned seed = seedParam.value(); unsigned seed = seedParam.value();
// description of genotype // description of genotype
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V'); eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
parser.processParam( vecSizeParam, "Representation" ); parser.processParam( vecSizeParam, "Representation" );
unsigned vecSize = vecSizeParam.value(); unsigned vecSize = vecSizeParam.value();
eoValueParam<unsigned int> stepParam(10, "nbStep", "Number of steps of the random walk", 'n'); eoValueParam<unsigned int> stepParam(10, "nbStep", "Number of steps of the random walk", 'n');
parser.processParam( stepParam, "Representation" ); parser.processParam( stepParam, "Representation" );
unsigned nbStep = stepParam.value(); unsigned nbStep = stepParam.value();
// the name of the "status" file where all actual parameter values will be saved // the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file"); eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
parser.processParam( statusParam, "Persistence" ); parser.processParam( statusParam, "Persistence" );
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
// i.e. in case you need parameters somewhere else, postpone these // i.e. in case you need parameters somewhere else, postpone these
if (parser.userNeedsHelp()){ if (parser.userNeedsHelp()) {
parser.printHelp(cout); parser.printHelp(cout);
exit(1); exit(1);
} }
if (statusParam.value() != ""){ if (statusParam.value() != "") {
ofstream os(statusParam.value().c_str()); ofstream os(statusParam.value().c_str());
os << parser;// and you can use that file as parameter file os << parser;// and you can use that file as parameter file
} }
/* ========================================================= /* =========================================================
* *
* Random seed * Random seed
* *
* ========================================================= */ * ========================================================= */
//reproducible random seed: if you don't change SEED above, //reproducible random seed: if you don't change SEED above,
// you'll aways get the same result, NOT a random run // you'll aways get the same result, NOT a random run
rng.reseed(seed); rng.reseed(seed);
/* ========================================================= /* =========================================================
* *
* Eval fitness function * Eval fitness function
* *
* ========================================================= */ * ========================================================= */
FuncOneMax<Indi> eval(vecSize); FuncOneMax<Indi> eval(vecSize);
/* ========================================================= /* =========================================================
* *
* Initilisation of the solution * Initilisation of the solution
* *
* ========================================================= */ * ========================================================= */
// a Indi random initializer // a Indi random initializer
eoUniformGenerator<bool> uGen; eoUniformGenerator<bool> uGen;
eoInitFixedLength<Indi> random(vecSize, uGen); eoInitFixedLength<Indi> random(vecSize, uGen);
/* ========================================================= /* =========================================================
* *
* evaluation of a neighbor solution * evaluation of a neighbor solution
* *
* ========================================================= */ * ========================================================= */
moFullEvalByModif<Neighbor> nhEval(eval); moFullEvalByModif<Neighbor> nhEval(eval);
//An eval by copy can be used instead of the eval by modif //An eval by copy can be used instead of the eval by modif
//moFullEvalByCopy<Neighbor> nhEval(eval); //moFullEvalByCopy<Neighbor> nhEval(eval);
/* ========================================================= /* =========================================================
* *
* the neighborhood of a solution * the neighborhood of a solution
* *
* ========================================================= */ * ========================================================= */
Neighborhood neighborhood(vecSize); Neighborhood neighborhood(vecSize);
/* ========================================================= /* =========================================================
* *
* a neighborhood explorer solution * a neighborhood explorer solution
* *
* ========================================================= */ * ========================================================= */
moRandomWalkExplorer<Neighborhood> explorer(neighborhood, nhEval, nbStep); moRandomWalkExplorer<Neighborhood> explorer(neighborhood, nhEval, nbStep);
/* ========================================================= /* =========================================================
* *
* the continuator and the checkpoint * the continuator and the checkpoint
* *
* ========================================================= */ * ========================================================= */
moTrueContinuator<Neighborhood> continuator;//always continue moTrueContinuator<Neighborhood> continuator;//always continue
moCheckpoint<Neighborhood> checkpoint(continuator); moCheckpoint<Neighborhood> checkpoint(continuator);
moFitnessStat<Indi, unsigned> fStat; moFitnessStat<Indi, unsigned> fStat;
eoHammingDistance<Indi> distance; eoHammingDistance<Indi> distance;
Indi bestSolution(vecSize, true); Indi bestSolution(vecSize, true);
moDistanceStat<Indi, unsigned> distStat(distance, bestSolution); moDistanceStat<Indi, unsigned> distStat(distance, bestSolution);
// moSolutionStat<Indi> solStat; // moSolutionStat<Indi> solStat;
checkpoint.add(fStat); checkpoint.add(fStat);
checkpoint.add(distStat); checkpoint.add(distStat);
// checkpoint.add(solStat); // checkpoint.add(solStat);
eoValueParam<unsigned int> genCounter(-1,"Gen"); eoValueParam<unsigned int> genCounter(-1,"Gen");
eoIncrementor<unsigned int> increm(genCounter.value()); eoIncrementor<unsigned int> increm(genCounter.value());
checkpoint.add(increm); checkpoint.add(increm);
eoFileMonitor outputfile("out.dat", " "); eoFileMonitor outputfile("out.dat", " ");
checkpoint.add(outputfile); checkpoint.add(outputfile);
outputfile.add(genCounter); outputfile.add(genCounter);
outputfile.add(fStat); outputfile.add(fStat);
outputfile.add(distStat); outputfile.add(distStat);
// outputfile.add(solStat); // outputfile.add(solStat);
Indi solution; // current solution of the search process Indi solution; // current solution of the search process
/* /*
// to save the solution at each iteration // to save the solution at each iteration
eoState outState; eoState outState;
// Register the algorithm into the state (so it has something to save!! // Register the algorithm into the state (so it has something to save!!
outState.registerObject(solution); outState.registerObject(solution);
// and feed the state to state savers // and feed the state to state savers
// save state every 10th iteration // save state every 10th iteration
eoCountedStateSaver stateSaver(10, outState, "iteration"); eoCountedStateSaver stateSaver(10, outState, "iteration");
// Don't forget to add the two savers to the checkpoint // Don't forget to add the two savers to the checkpoint
checkpoint.add(stateSaver); checkpoint.add(stateSaver);
*/ */
/* ========================================================= /* =========================================================
* *
* the local search algorithm * the local search algorithm
* *
* ========================================================= */ * ========================================================= */
moLocalSearch< moRandomWalkExplorer<Neighborhood> > localSearch(explorer, checkpoint, eval); moLocalSearch< moRandomWalkExplorer<Neighborhood> > localSearch(explorer, checkpoint, eval);
/* ========================================================= /* =========================================================
* *
* execute the local search from random sollution * execute the local search from random sollution
* *
* ========================================================= */ * ========================================================= */
random(solution); random(solution);
//Can be eval here, else it will be done at the beginning of the localSearch //Can be eval here, else it will be done at the beginning of the localSearch
//eval(solution); //eval(solution);
std::cout << "initial: " << solution << std::endl ; std::cout << "initial: " << solution << std::endl ;
localSearch(solution); localSearch(solution);
std::cout << "final: " << solution << std::endl ; std::cout << "final: " << solution << std::endl ;
} }
@ -233,11 +233,11 @@ void main_function(int argc, char **argv)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
try{ try {
main_function(argc, argv); main_function(argc, argv);
} }
catch(exception& e){ catch (exception& e) {
cout << "Exception: " << e.what() << '\n'; cout << "Exception: " << e.what() << '\n';
} }
return 1; return 1;
} }

View file

@ -44,142 +44,142 @@ typedef moOrderNeighborhood<Neighbor> Neighborhood ;
void main_function(int argc, char **argv) void main_function(int argc, char **argv)
{ {
/* ========================================================= /* =========================================================
* *
* Parameters * Parameters
* *
* ========================================================= */ * ========================================================= */
// First define a parser from the command-line arguments // First define a parser from the command-line arguments
eoParser parser(argc, argv); eoParser parser(argc, argv);
// For each parameter, define Parameter, read it through the parser, // For each parameter, define Parameter, read it through the parser,
// and assign the value to the variable // and assign the value to the variable
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S'); eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam ); parser.processParam( seedParam );
unsigned seed = seedParam.value(); unsigned seed = seedParam.value();
// description of genotype // description of genotype
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V'); eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
parser.processParam( vecSizeParam, "Representation" ); parser.processParam( vecSizeParam, "Representation" );
unsigned vecSize = vecSizeParam.value(); unsigned vecSize = vecSizeParam.value();
// the name of the "status" file where all actual parameter values will be saved // the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file"); eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
parser.processParam( statusParam, "Persistence" ); parser.processParam( statusParam, "Persistence" );
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
// i.e. in case you need parameters somewhere else, postpone these // i.e. in case you need parameters somewhere else, postpone these
if (parser.userNeedsHelp()){ if (parser.userNeedsHelp()) {
parser.printHelp(cout); parser.printHelp(cout);
exit(1); exit(1);
} }
if (statusParam.value() != ""){ if (statusParam.value() != "") {
ofstream os(statusParam.value().c_str()); ofstream os(statusParam.value().c_str());
os << parser;// and you can use that file as parameter file os << parser;// and you can use that file as parameter file
} }
/* ========================================================= /* =========================================================
* *
* Random seed * Random seed
* *
* ========================================================= */ * ========================================================= */
//reproducible random seed: if you don't change SEED above, //reproducible random seed: if you don't change SEED above,
// you'll aways get the same result, NOT a random run // you'll aways get the same result, NOT a random run
rng.reseed(seed); rng.reseed(seed);
/* ========================================================= /* =========================================================
* *
* Eval fitness function * Eval fitness function
* *
* ========================================================= */ * ========================================================= */
FuncOneMax<Indi> eval(vecSize); FuncOneMax<Indi> eval(vecSize);
/* ========================================================= /* =========================================================
* *
* Initilisation of the solution * Initilisation of the solution
* *
* ========================================================= */ * ========================================================= */
// a Indi random initializer // a Indi random initializer
eoUniformGenerator<bool> uGen; eoUniformGenerator<bool> uGen;
eoInitFixedLength<Indi> random(vecSize, uGen); eoInitFixedLength<Indi> random(vecSize, uGen);
/* ========================================================= /* =========================================================
* *
* evaluation of a neighbor solution * evaluation of a neighbor solution
* *
* ========================================================= */ * ========================================================= */
moFullEvalByModif<Neighbor> fulleval(eval); moFullEvalByModif<Neighbor> fulleval(eval);
//An eval by copy can be used instead of the eval by modif //An eval by copy can be used instead of the eval by modif
//moFullEvalByCopy<Neighbor> fulleval(eval); //moFullEvalByCopy<Neighbor> fulleval(eval);
/* ========================================================= /* =========================================================
* *
* Comparator of neighbors * Comparator of neighbors
* *
* ========================================================= */ * ========================================================= */
moNeighborComparator<Neighbor> comparator; moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator; moSolNeighborComparator<Neighbor> solComparator;
/* ========================================================= /* =========================================================
* *
* the neighborhood of a solution * the neighborhood of a solution
* *
* ========================================================= */ * ========================================================= */
Neighborhood neighborhood(vecSize); Neighborhood neighborhood(vecSize);
/* ========================================================= /* =========================================================
* *
* a neighborhood explorer solution * a neighborhood explorer solution
* *
* ========================================================= */ * ========================================================= */
moSimpleHCexplorer<Neighborhood> explorer(neighborhood, fulleval, comparator, solComparator); moSimpleHCexplorer<Neighborhood> explorer(neighborhood, fulleval, comparator, solComparator);
/* ========================================================= /* =========================================================
* *
* the local search algorithm * the local search algorithm
* *
* ========================================================= */ * ========================================================= */
moTrueContinuator<Neighborhood> continuator;//always continue moTrueContinuator<Neighborhood> continuator;//always continue
moLocalSearch< moSimpleHCexplorer<Neighborhood> > localSearch(explorer, continuator, eval); moLocalSearch< moSimpleHCexplorer<Neighborhood> > localSearch(explorer, continuator, eval);
/* ========================================================= /* =========================================================
* *
* execute the local search from random sollution * execute the local search from random sollution
* *
* ========================================================= */ * ========================================================= */
Indi solution; Indi solution;
random(solution); random(solution);
//Can be eval here, else it will be done at the beginning of the localSearch //Can be eval here, else it will be done at the beginning of the localSearch
//eval(solution); //eval(solution);
std::cout << "initial: " << solution << std::endl ; std::cout << "initial: " << solution << std::endl ;
localSearch(solution); localSearch(solution);
std::cout << "final: " << solution << std::endl ; std::cout << "final: " << solution << std::endl ;
} }
@ -187,11 +187,11 @@ void main_function(int argc, char **argv)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
try{ try {
main_function(argc, argv); main_function(argc, argv);
} }
catch(exception& e){ catch (exception& e) {
cout << "Exception: " << e.what() << '\n'; cout << "Exception: " << e.what() << '\n';
} }
return 1; return 1;
} }

View file

@ -44,142 +44,142 @@ typedef moOrderNeighborhood<Neighbor> Neighborhood ;
void main_function(int argc, char **argv) void main_function(int argc, char **argv)
{ {
/* ========================================================= /* =========================================================
* *
* Parameters * Parameters
* *
* ========================================================= */ * ========================================================= */
// First define a parser from the command-line arguments // First define a parser from the command-line arguments
eoParser parser(argc, argv); eoParser parser(argc, argv);
// For each parameter, define Parameter, read it through the parser, // For each parameter, define Parameter, read it through the parser,
// and assign the value to the variable // and assign the value to the variable
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S'); eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam ); parser.processParam( seedParam );
unsigned seed = seedParam.value(); unsigned seed = seedParam.value();
// description of genotype // description of genotype
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V'); eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
parser.processParam( vecSizeParam, "Representation" ); parser.processParam( vecSizeParam, "Representation" );
unsigned vecSize = vecSizeParam.value(); unsigned vecSize = vecSizeParam.value();
// the name of the "status" file where all actual parameter values will be saved // the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file"); eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
parser.processParam( statusParam, "Persistence" ); parser.processParam( statusParam, "Persistence" );
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
// i.e. in case you need parameters somewhere else, postpone these // i.e. in case you need parameters somewhere else, postpone these
if (parser.userNeedsHelp()){ if (parser.userNeedsHelp()) {
parser.printHelp(cout); parser.printHelp(cout);
exit(1); exit(1);
} }
if (statusParam.value() != ""){ if (statusParam.value() != "") {
ofstream os(statusParam.value().c_str()); ofstream os(statusParam.value().c_str());
os << parser;// and you can use that file as parameter file os << parser;// and you can use that file as parameter file
} }
/* ========================================================= /* =========================================================
* *
* Random seed * Random seed
* *
* ========================================================= */ * ========================================================= */
//reproducible random seed: if you don't change SEED above, //reproducible random seed: if you don't change SEED above,
// you'll aways get the same result, NOT a random run // you'll aways get the same result, NOT a random run
rng.reseed(seed); rng.reseed(seed);
/* ========================================================= /* =========================================================
* *
* Eval fitness function * Eval fitness function
* *
* ========================================================= */ * ========================================================= */
FuncOneMax<Indi> eval(vecSize); FuncOneMax<Indi> eval(vecSize);
/* ========================================================= /* =========================================================
* *
* Initilisation of the solution * Initilisation of the solution
* *
* ========================================================= */ * ========================================================= */
// a Indi random initializer // a Indi random initializer
eoUniformGenerator<bool> uGen; eoUniformGenerator<bool> uGen;
eoInitFixedLength<Indi> random(vecSize, uGen); eoInitFixedLength<Indi> random(vecSize, uGen);
/* ========================================================= /* =========================================================
* *
* evaluation of a neighbor solution * evaluation of a neighbor solution
* *
* ========================================================= */ * ========================================================= */
moFullEvalByModif<Neighbor> fulleval(eval); moFullEvalByModif<Neighbor> fulleval(eval);
//An eval by copy can be used instead of the eval by modif //An eval by copy can be used instead of the eval by modif
//moFullEvalByCopy<Neighbor> fulleval(eval); //moFullEvalByCopy<Neighbor> fulleval(eval);
/* ========================================================= /* =========================================================
* *
* Comparator of neighbors * Comparator of neighbors
* *
* ========================================================= */ * ========================================================= */
moNeighborComparator<Neighbor> comparator; moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator; moSolNeighborComparator<Neighbor> solComparator;
/* ========================================================= /* =========================================================
* *
* the neighborhood of a solution * the neighborhood of a solution
* *
* ========================================================= */ * ========================================================= */
Neighborhood neighborhood(vecSize); Neighborhood neighborhood(vecSize);
/* ========================================================= /* =========================================================
* *
* a neighborhood explorer solution * a neighborhood explorer solution
* *
* ========================================================= */ * ========================================================= */
moSimpleHCneutralExplorer<Neighborhood> explorer(neighborhood, fulleval, comparator, solComparator); moSimpleHCneutralExplorer<Neighborhood> explorer(neighborhood, fulleval, comparator, solComparator);
/* ========================================================= /* =========================================================
* *
* the local search algorithm * the local search algorithm
* *
* ========================================================= */ * ========================================================= */
moTrueContinuator<Neighborhood> continuator;//always continue moTrueContinuator<Neighborhood> continuator;//always continue
moLocalSearch< moSimpleHCneutralExplorer<Neighborhood> > localSearch(explorer, continuator, eval); moLocalSearch< moSimpleHCneutralExplorer<Neighborhood> > localSearch(explorer, continuator, eval);
/* ========================================================= /* =========================================================
* *
* execute the local search from random sollution * execute the local search from random sollution
* *
* ========================================================= */ * ========================================================= */
Indi solution; Indi solution;
random(solution); random(solution);
//Can be eval here, else it will be done at the beginning of the localSearch //Can be eval here, else it will be done at the beginning of the localSearch
//eval(solution); //eval(solution);
std::cout << "initial: " << solution << std::endl ; std::cout << "initial: " << solution << std::endl ;
localSearch(solution); localSearch(solution);
std::cout << "final: " << solution << std::endl ; std::cout << "final: " << solution << std::endl ;
} }
@ -187,11 +187,11 @@ void main_function(int argc, char **argv)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
try{ try {
main_function(argc, argv); main_function(argc, argv);
} }
catch(exception& e){ catch (exception& e) {
cout << "Exception: " << e.what() << '\n'; cout << "Exception: " << e.what() << '\n';
} }
return 1; return 1;
} }

View file

@ -46,146 +46,146 @@ typedef moOrderNeighborhood<Neighbor> Neighborhood ;
void main_function(int argc, char **argv) void main_function(int argc, char **argv)
{ {
/* ========================================================= /* =========================================================
* *
* Parameters * Parameters
* *
* ========================================================= */ * ========================================================= */
// First define a parser from the command-line arguments // First define a parser from the command-line arguments
eoParser parser(argc, argv); eoParser parser(argc, argv);
// For each parameter, define Parameter, read it through the parser, // For each parameter, define Parameter, read it through the parser,
// and assign the value to the variable // and assign the value to the variable
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S'); eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam ); parser.processParam( seedParam );
unsigned seed = seedParam.value(); unsigned seed = seedParam.value();
// description of genotype // description of genotype
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V'); eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
parser.processParam( vecSizeParam, "Representation" ); parser.processParam( vecSizeParam, "Representation" );
unsigned vecSize = vecSizeParam.value(); unsigned vecSize = vecSizeParam.value();
// the name of the "status" file where all actual parameter values will be saved // the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file"); eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
parser.processParam( statusParam, "Persistence" ); parser.processParam( statusParam, "Persistence" );
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
// i.e. in case you need parameters somewhere else, postpone these // i.e. in case you need parameters somewhere else, postpone these
if (parser.userNeedsHelp()){ if (parser.userNeedsHelp()) {
parser.printHelp(cout); parser.printHelp(cout);
exit(1); exit(1);
} }
if (statusParam.value() != ""){ if (statusParam.value() != "") {
ofstream os(statusParam.value().c_str()); ofstream os(statusParam.value().c_str());
os << parser;// and you can use that file as parameter file os << parser;// and you can use that file as parameter file
} }
/* ========================================================= /* =========================================================
* *
* Random seed * Random seed
* *
* ========================================================= */ * ========================================================= */
//reproducible random seed: if you don't change SEED above, //reproducible random seed: if you don't change SEED above,
// you'll aways get the same result, NOT a random run // you'll aways get the same result, NOT a random run
rng.reseed(seed); rng.reseed(seed);
/* ========================================================= /* =========================================================
* *
* Eval fitness function * Eval fitness function
* *
* ========================================================= */ * ========================================================= */
FuncOneMax<Indi> fulleval(vecSize); FuncOneMax<Indi> fulleval(vecSize);
/* ========================================================= /* =========================================================
* *
* Initilisation of the solution * Initilisation of the solution
* *
* ========================================================= */ * ========================================================= */
// a Indi random initializer // a Indi random initializer
eoUniformGenerator<bool> uGen; eoUniformGenerator<bool> uGen;
eoInitFixedLength<Indi> random(vecSize, uGen); eoInitFixedLength<Indi> random(vecSize, uGen);
/* ========================================================= /* =========================================================
* *
* evaluation of a neighbor solution * evaluation of a neighbor solution
* *
* ========================================================= */ * ========================================================= */
moFullEvalByModif<Neighbor> eval(fulleval); moFullEvalByModif<Neighbor> eval(fulleval);
//An eval by copy can be used instead of the eval by modif //An eval by copy can be used instead of the eval by modif
//moFullEvalByCopy<Neighbor> fulleval(eval); //moFullEvalByCopy<Neighbor> fulleval(eval);
/* ========================================================= /* =========================================================
* *
* Comparator of neighbors * Comparator of neighbors
* *
* ========================================================= */ * ========================================================= */
moNeighborComparator<Neighbor> comparator; moNeighborComparator<Neighbor> comparator;
moSolNeighborComparator<Neighbor> solComparator; moSolNeighborComparator<Neighbor> solComparator;
/* ========================================================= /* =========================================================
* *
* the neighborhood of a solution * the neighborhood of a solution
* *
* ========================================================= */ * ========================================================= */
Neighborhood neighborhood(vecSize); Neighborhood neighborhood(vecSize);
/* ========================================================= /* =========================================================
* *
* a neighborhood explorer solution * a neighborhood explorer solution
* *
* ========================================================= */ * ========================================================= */
moSolVectorTabuList<Neighbor> tl(10,10); moSolVectorTabuList<Neighbor> tl(10,10);
moDummyIntensification<Neighbor> inten; moDummyIntensification<Neighbor> inten;
moDummyDiversification<Neighbor> div; moDummyDiversification<Neighbor> div;
moBestImprAspiration<Neighbor> asp; moBestImprAspiration<Neighbor> asp;
moTSExplorer<Neighborhood> explorer(neighborhood, eval, comparator, solComparator, tl, inten, div, asp); moTSExplorer<Neighborhood> explorer(neighborhood, eval, comparator, solComparator, tl, inten, div, asp);
/* ========================================================= /* =========================================================
* *
* the local search algorithm * the local search algorithm
* *
* ========================================================= */ * ========================================================= */
moTrueContinuator<Neighborhood> continuator;//always continue moTrueContinuator<Neighborhood> continuator;//always continue
moLocalSearch< moTSExplorer<Neighborhood> > localSearch(explorer, continuator, fulleval); moLocalSearch< moTSExplorer<Neighborhood> > localSearch(explorer, continuator, fulleval);
/* ========================================================= /* =========================================================
* *
* execute the local search from random sollution * execute the local search from random sollution
* *
* ========================================================= */ * ========================================================= */
Indi solution; Indi solution;
random(solution); random(solution);
//Can be eval here, else it will be done at the beginning of the localSearch //Can be eval here, else it will be done at the beginning of the localSearch
//eval(solution); //eval(solution);
std::cout << "initial: " << solution << std::endl ; std::cout << "initial: " << solution << std::endl ;
localSearch(solution); localSearch(solution);
std::cout << "final: " << solution << std::endl ; std::cout << "final: " << solution << std::endl ;
} }
@ -193,11 +193,11 @@ void main_function(int argc, char **argv)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
try{ try {
main_function(argc, argv); main_function(argc, argv);
} }
catch(exception& e){ catch (exception& e) {
cout << "Exception: " << e.what() << '\n'; cout << "Exception: " << e.what() << '\n';
} }
return 1; return 1;
} }

View file

@ -61,138 +61,138 @@ typedef moMoveNeighborhood<BitMove<Indi>, unsigned> Neighborhood ;
void main_function(int argc, char **argv) void main_function(int argc, char **argv)
{ {
/* ========================================================= /* =========================================================
* *
* Parameters * Parameters
* *
* ========================================================= */ * ========================================================= */
// First define a parser from the command-line arguments // First define a parser from the command-line arguments
eoParser parser(argc, argv); eoParser parser(argc, argv);
// For each parameter, define Parameter, read it through the parser, // For each parameter, define Parameter, read it through the parser,
// and assign the value to the variable // and assign the value to the variable
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S'); eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
parser.processParam( seedParam ); parser.processParam( seedParam );
unsigned seed = seedParam.value(); unsigned seed = seedParam.value();
// description of genotype // description of genotype
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V'); eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
parser.processParam( vecSizeParam, "Representation" ); parser.processParam( vecSizeParam, "Representation" );
unsigned vecSize = vecSizeParam.value(); unsigned vecSize = vecSizeParam.value();
string fileOut("out.dat"); string fileOut("out.dat");
eoValueParam<string> fileStatParam(fileOut.c_str(), "out", "A file to export results", 'o'); eoValueParam<string> fileStatParam(fileOut.c_str(), "out", "A file to export results", 'o');
parser.processParam( fileStatParam, "Persistence" ); parser.processParam( fileStatParam, "Persistence" );
fileOut = fileStatParam.value(); fileOut = fileStatParam.value();
// the name of the "status" file where all actual parameter values will be saved // the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value string str_status = parser.ProgramName() + ".status"; // default value
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file"); eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
parser.processParam( statusParam, "Persistence" ); parser.processParam( statusParam, "Persistence" );
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
// i.e. in case you need parameters somewhere else, postpone these // i.e. in case you need parameters somewhere else, postpone these
if (parser.userNeedsHelp()) if (parser.userNeedsHelp())
{ {
parser.printHelp(cout); parser.printHelp(cout);
exit(1); exit(1);
} }
if (statusParam.value() != "") if (statusParam.value() != "")
{ {
ofstream os(statusParam.value().c_str()); ofstream os(statusParam.value().c_str());
os << parser; // and you can use that file as parameter file os << parser; // and you can use that file as parameter file
} }
/* ========================================================= /* =========================================================
* *
* Random seed * Random seed
* *
* ========================================================= */ * ========================================================= */
//reproducible random seed: if you don't change SEED above, //reproducible random seed: if you don't change SEED above,
// you'll aways get the same result, NOT a random run // you'll aways get the same result, NOT a random run
rng.reseed(seed); rng.reseed(seed);
/* ========================================================= /* =========================================================
* *
* Eval fitness function * Eval fitness function
* *
* ========================================================= */ * ========================================================= */
FuncOneMax<Indi> eval(vecSize); FuncOneMax<Indi> eval(vecSize);
OneMaxIncrEval<Indi> incrEval; OneMaxIncrEval<Indi> incrEval;
Neighbor::setIncrEval(incrEval); Neighbor::setIncrEval(incrEval);
/* ========================================================= /* =========================================================
* *
* Initilisation of the solution * Initilisation of the solution
* *
* ========================================================= */ * ========================================================= */
// a Indi random initializer // a Indi random initializer
eoUniformGenerator<bool> uGen; eoUniformGenerator<bool> uGen;
eoInitFixedLength<Indi> random(vecSize, uGen); eoInitFixedLength<Indi> random(vecSize, uGen);
/* ========================================================= /* =========================================================
* *
* evaluation of a neighbor solution * evaluation of a neighbor solution
* *
* ========================================================= */ * ========================================================= */
// no need if incremental evaluation with OneMaxBitNeighbor // no need if incremental evaluation with OneMaxBitNeighbor
// Neighbor::setFullEvalFunc(eval); // Neighbor::setFullEvalFunc(eval);
/* ========================================================= /* =========================================================
* *
* the neighborhood of a solution * the neighborhood of a solution
* *
* ========================================================= */ * ========================================================= */
BitMove_init<Indi> init; BitMove_init<Indi> init;
BitMove_next<Indi> next; BitMove_next<Indi> next;
Neighborhood neighborhood(init, next); Neighborhood neighborhood(init, next);
/* ========================================================= /* =========================================================
* *
* a neighborhood explorator solution * a neighborhood explorator solution
* *
* ========================================================= */ * ========================================================= */
moSimpleHCexplorer<Neighborhood> explorer(neighborhood); moSimpleHCexplorer<Neighborhood> explorer(neighborhood);
/* ========================================================= /* =========================================================
* *
* the local search algorithm * the local search algorithm
* *
* ========================================================= */ * ========================================================= */
moTrueContinuator<Neighborhood> continuator; moTrueContinuator<Neighborhood> continuator;
moLocalSearch< moSimpleHCexplorer<Neighborhood> > localSearch(explorer, continuator); moLocalSearch< moSimpleHCexplorer<Neighborhood> > localSearch(explorer, continuator);
/* ========================================================= /* =========================================================
* *
* execute the local search from random sollution * execute the local search from random sollution
* *
* ========================================================= */ * ========================================================= */
Indi solution; Indi solution;
random(solution); random(solution);
eval(solution); eval(solution);
std::cout << "initial: " << solution << std::endl ; std::cout << "initial: " << solution << std::endl ;
localSearch(solution); localSearch(solution);
std::cout << "final: " << solution << std::endl ; std::cout << "final: " << solution << std::endl ;
} }
@ -205,7 +205,7 @@ int main(int argc, char **argv)
{ {
main_function(argc, argv); main_function(argc, argv);
} }
catch(exception& e) catch (exception& e)
{ {
cout << "Exception: " << e.what() << '\n'; cout << "Exception: " << e.what() << '\n';
} }

View file

@ -13,21 +13,21 @@ class BitMove : public moMove <EOT> {
public : public :
typedef EOT EOType; typedef EOT EOType;
unsigned bit; unsigned bit;
BitMove() { BitMove() {
bit = 0; bit = 0;
} }
BitMove(unsigned _bit) : bit(_bit) { } BitMove(unsigned _bit) : bit(_bit) { }
void operator () (EOT & chrom) void operator () (EOT & chrom)
{ {
chrom[bit] = !chrom[bit]; chrom[bit] = !chrom[bit];
}; };
} ; } ;

View file

@ -12,16 +12,16 @@ template <class EOT>
class OneMaxIncrEval : public moMoveIncrEval < BitMove<EOT> > { class OneMaxIncrEval : public moMoveIncrEval < BitMove<EOT> > {
public : public :
OneMaxIncrEval(){ }; OneMaxIncrEval() { };
typename EOT::Fitness operator () (const BitMove<EOT> & move, const EOT & chrom) { typename EOT::Fitness operator () (const BitMove<EOT> & move, const EOT & chrom) {
if(chrom[move.bit]==0){ if (chrom[move.bit]==0) {
return chrom.fitness()+1; return chrom.fitness()+1;
} }
else{ else {
return chrom.fitness()-1; return chrom.fitness()-1;
} }
}; };
}; };
#endif #endif

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