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) {
if(_solution.invalid())
fullEval(_solution);
if (_solution.invalid())
fullEval(_solution);
// initialization of the parameter of the search (for example fill empty the tabu list)
searchExplorer.initParam(_solution);
// initialization of the parameter of the search (for example fill empty the tabu list)
searchExplorer.initParam(_solution);
// initialization of the external continuator (for example the time, or the number of generations)
continuator.init(_solution);
// initialization of the external continuator (for example the time, or the number of generations)
continuator.init(_solution);
bool b=continuator(_solution);
bool b=continuator(_solution);
do {
// explore the neighborhood of the solution
searchExplorer(_solution);
// if a solution in the neighborhood can be accepted
if (searchExplorer.accept(_solution)){
searchExplorer.move(_solution);
searchExplorer.moveApplied(true);
}
else
searchExplorer.moveApplied(false);
do {
// explore the neighborhood of the solution
searchExplorer(_solution);
// if a solution in the neighborhood can be accepted
if (searchExplorer.accept(_solution)) {
searchExplorer.move(_solution);
searchExplorer.moveApplied(true);
}
else
searchExplorer.moveApplied(false);
// update the parameter of the search (for ex. Temperature of the SA)
searchExplorer.updateParam(_solution);
// update the parameter of the search (for ex. Temperature of the SA)
searchExplorer.updateParam(_solution);
b=continuator(_solution);
} while (b && searchExplorer.isContinue(_solution));
b=continuator(_solution);
} while (b && searchExplorer.isContinue(_solution));
searchExplorer.terminate(_solution);
searchExplorer.terminate(_solution);
continuator.lastCall(_solution);
continuator.lastCall(_solution);
return true;
return true;
};
private:

View file

@ -65,7 +65,7 @@ public:
* @return the class name as a std::string
*/
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
*/
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
*/
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
*/
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>
{
public:
typedef typename Neighbor::EOT EOT ;
typedef typename Neighbor::EOT EOT ;
/**
* Compare two neighbors
@ -58,7 +58,7 @@ public:
* @return true if the neighbor is better than sol
*/
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
*/
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
*/
virtual std::string className() const {
return "moSolNeighborComparator";
return "moSolNeighborComparator";
}
};

View file

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

View file

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

View file

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

View file

@ -54,20 +54,22 @@ public :
* @param _dist a distance
* @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
* @param _sol a solution
*/
virtual void operator()(EOT & _sol){
value() = dist(_sol, refSolution);
virtual void operator()(EOT & _sol) {
value() = dist(_sol, refSolution);
}
/**
* @return name of the class
*/
virtual std::string className(void) const { return "moDistanceStat"; }
virtual std::string className(void) const {
return "moDistanceStat";
}
private:
/** the distance */
@ -76,7 +78,7 @@ private:
* the reference solution does not change during the run
* 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
*/
moFitnessStat(std::string _description = "fitness"):
moStat<EOT, Fitness>(Fitness(), _description){}
moStat<EOT, Fitness>(Fitness(), _description) {}
/**
* store fitness value
@ -62,13 +62,15 @@ public :
*/
virtual void operator()(EOT & _sol)
{
value() = _sol.fitness();
value() = _sol.fitness();
}
/**
* @return the name of the class
*/
virtual std::string className(void) const { return "moFitnessStat"; }
virtual std::string className(void) const {
return "moFitnessStat";
}
};
#endif

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -53,21 +53,21 @@ public :
* @param _description a description of the parameter
*/
moSolutionStat(std::string _description = "solution"):
moStat<EOT, EOT>(EOT(), _description){}
moStat<EOT, EOT>(EOT(), _description) {}
/**
* Set the solution by copy
* @param _sol the corresponding solution
*/
virtual void operator()(EOT & _sol){
value() = _sol;
virtual void operator()(EOT & _sol) {
value() = _sol;
}
/**
* @return name of the class
*/
virtual std::string className(void) const{
return "moSolutionStat";
virtual std::string className(void) const {
return "moSolutionStat";
}
};

View file

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

View file

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

View file

@ -54,7 +54,7 @@ public:
*@return always true
*/
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>
{
public:
typedef typename Neighbor::EOT EOT;
typedef typename EOT::Fitness Fitness;
typedef typename Neighbor::EOT EOT;
typedef typename EOT::Fitness Fitness;
};
#endif

View file

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

View file

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

View file

@ -52,66 +52,66 @@ public:
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::eval;
/**
* Constructor
* @param _neighborhood the neighborhood
* @param _eval the evaluation function
* @param _neighborComparator a neighbor comparator
* @param _solNeighborComparator a solution vs neighbor comparator
*/
/**
* Constructor
* @param _neighborhood the neighborhood
* @param _eval the evaluation function
* @param _neighborComparator a 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) {
isAccept = false;
current=new Neighbor();
isAccept = false;
current=new Neighbor();
}
/**
* Destructor
*/
~moFirstImprExplorer(){
delete current;
/**
* Destructor
*/
~moFirstImprExplorer() {
delete current;
}
/**
* initParam: NOTHING TO DO
*/
virtual void initParam(EOT & solution){};
/**
* initParam: NOTHING TO DO
*/
virtual void initParam(EOT & solution) {};
/**
* updateParam: NOTHING TO DO
*/
virtual void updateParam(EOT & solution){};
/**
* updateParam: NOTHING TO DO
*/
virtual void updateParam(EOT & solution) {};
/**
* terminate: NOTHING TO DO
*/
virtual void terminate(EOT & solution){};
/**
* terminate: NOTHING TO DO
*/
virtual void terminate(EOT & solution) {};
/**
* Explore the neighborhood of a solution
* @param _solution
*/
virtual void operator()(EOT & _solution){
virtual void operator()(EOT & _solution) {
//Test if _solution has a Neighbor
if(neighborhood.hasNeighbor(_solution)){
//init the first neighbor
neighborhood.init(_solution, (*current));
//Test if _solution has a Neighbor
if (neighborhood.hasNeighbor(_solution)) {
//init the first neighbor
neighborhood.init(_solution, (*current));
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, (*current));
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, (*current));
//test all others neighbors
while (! solNeighborComparator(_solution, *current) && neighborhood.cont(_solution)) {
//next neighbor
neighborhood.next(_solution, (*current));
//eval
eval(_solution, (*current));
}
}
else{
//if _solution hasn't neighbor,
isAccept=false;
}
//test all others neighbors
while (! solNeighborComparator(_solution, *current) && neighborhood.cont(_solution)) {
//next neighbor
neighborhood.next(_solution, (*current));
//eval
eval(_solution, (*current));
}
}
else {
//if _solution hasn't neighbor,
isAccept=false;
}
};
/**
@ -120,7 +120,7 @@ public:
* @return true if an ameliorated neighbor was be found
*/
virtual bool isContinue(EOT & _solution) {
return isAccept ;
return isAccept ;
};
/**
@ -128,10 +128,10 @@ public:
* @param _solution the solution to move
*/
virtual void move(EOT & _solution) {
//move the solution
(*current).move(_solution);
//update its fitness
_solution.fitness((*current).fitness());
//move the solution
(*current).move(_solution);
//update its fitness
_solution.fitness((*current).fitness());
};
/**
@ -140,10 +140,10 @@ public:
* @return true if the best neighbor ameliorate the fitness
*/
virtual bool accept(EOT & _solution) {
if(neighborhood.hasNeighbor(_solution)){
isAccept = solNeighborComparator(_solution, (*current)) ;
}
return isAccept;
if (neighborhood.hasNeighbor(_solution)) {
isAccept = solNeighborComparator(_solution, (*current)) ;
}
return isAccept;
};
private:

View file

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

View file

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

View file

@ -102,16 +102,16 @@ public:
* Getter for variable "isMoved"
* @return true if move is applied
*/
bool moveApplied(){
return isMoved;
bool moveApplied() {
return isMoved;
}
/**
* Setter for variable "isMoved"
* @param _isMoved
*/
void moveApplied(bool _isMoved){
isMoved=_isMoved;
void moveApplied(bool _isMoved) {
isMoved=_isMoved;
}
/**
@ -119,7 +119,7 @@ public:
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moNeighborhoodExplorer";
return "moNeighborhoodExplorer";
}
protected:

View file

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

View file

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

View file

@ -52,77 +52,77 @@ public:
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::eval;
/**
* Constructor
* @param _neighborhood the neighborhood
* @param _eval the evaluation function
* @param _neighborComparator a 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) {
isAccept = false;
current=new Neighbor();
best=new Neighbor();
/**
* Constructor
* @param _neighborhood the neighborhood
* @param _eval the evaluation function
* @param _neighborComparator a 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) {
isAccept = false;
current=new Neighbor();
best=new Neighbor();
}
/**
* Destructor
*/
~moSimpleHCexplorer(){
delete current;
delete best;
/**
* Destructor
*/
~moSimpleHCexplorer() {
delete current;
delete best;
}
/**
* initParam: NOTHING TO DO
*/
virtual void initParam(EOT & solution){};
/**
* initParam: NOTHING TO DO
*/
virtual void initParam(EOT & solution) {};
/**
* updateParam: NOTHING TO DO
*/
virtual void updateParam(EOT & solution){};
/**
* updateParam: NOTHING TO DO
*/
virtual void updateParam(EOT & solution) {};
/**
* terminate: NOTHING TO DO
*/
virtual void terminate(EOT & solution){};
/**
* terminate: NOTHING TO DO
*/
virtual void terminate(EOT & solution) {};
/**
* Explore the neighborhood of a solution
* @param _solution
*/
virtual void operator()(EOT & _solution){
virtual void operator()(EOT & _solution) {
//est qu'on peut initializer
//Test if _solution has a Neighbor
if(neighborhood.hasNeighbor(_solution)){
//init the first neighbor
neighborhood.init(_solution, (*current));
//est qu'on peut initializer
//Test if _solution has a Neighbor
if (neighborhood.hasNeighbor(_solution)) {
//init the first neighbor
neighborhood.init(_solution, (*current));
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, (*current));
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, (*current));
//initialize the best neighbor
(*best) = (*current);
//initialize the best neighbor
(*best) = (*current);
//test all others neighbors
while (neighborhood.cont(_solution)) {
//next neighbor
neighborhood.next(_solution, (*current));
//eval
eval(_solution, (*current));
//if we found a better neighbor, update the best
if (neighborComparator((*best), (*current))) {
(*best) = (*current);
}
}
//test all others neighbors
while (neighborhood.cont(_solution)) {
//next neighbor
neighborhood.next(_solution, (*current));
//eval
eval(_solution, (*current));
//if we found a better neighbor, update the best
if (neighborComparator((*best), (*current))) {
(*best) = (*current);
}
}
}
else{
//if _solution hasn't neighbor,
isAccept=false;
}
}
else {
//if _solution hasn't neighbor,
isAccept=false;
}
};
/**
@ -131,7 +131,7 @@ public:
* @return true if an ameliorated neighbor was be found
*/
virtual bool isContinue(EOT & _solution) {
return isAccept ;
return isAccept ;
};
/**
@ -139,10 +139,10 @@ public:
* @param _solution the solution to move
*/
virtual void move(EOT & _solution) {
//move the solution
(*best).move(_solution);
//update its fitness
_solution.fitness((*best).fitness());
//move the solution
(*best).move(_solution);
//update its fitness
_solution.fitness((*best).fitness());
};
/**
@ -151,10 +151,10 @@ public:
* @return true if the best neighbor ameliorate the fitness
*/
virtual bool accept(EOT & _solution) {
if(neighborhood.hasNeighbor(_solution)){
isAccept = solNeighborComparator(_solution, (*best)) ;
}
return isAccept;
if (neighborhood.hasNeighbor(_solution)) {
isAccept = solNeighborComparator(_solution, (*best)) ;
}
return isAccept;
};
/**
@ -162,7 +162,7 @@ public:
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moSimpleHCexplorer";
return "moSimpleHCexplorer";
}
private:

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -56,7 +56,7 @@ public:
* @param _solution the solution to move
*/
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
*/
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
*/
virtual std::string className() const {
return "moBitNeighbor";
return "moBitNeighbor";
}
/**
* Read object.\ \
* 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.
* In principle, format is "plain": they just print a number
* @param _is a std::istream.
* @throw runtime_std::exception If a valid object can't be read.
*/
virtual void readFrom(std::istream& _is) {
std::string fitness_str;
int pos = _is.tellg();
_is >> fitness_str;
if (fitness_str == "INVALID"){
throw std::runtime_error("invalid fitness");
}
else{
Fitness repFit ;
_is.seekg(pos); // rewind
_is >> repFit;
_is >> key;
fitness(repFit);
}
}
/**
* Read object.\ \
* 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.
* In principle, format is "plain": they just print a number
* @param _is a std::istream.
* @throw runtime_std::exception If a valid object can't be read.
*/
virtual void readFrom(std::istream& _is) {
std::string fitness_str;
int pos = _is.tellg();
_is >> fitness_str;
if (fitness_str == "INVALID") {
throw std::runtime_error("invalid fitness");
}
else {
Fitness repFit ;
_is.seekg(pos); // rewind
_is >> repFit;
_is >> key;
fitness(repFit);
}
}
/**
* Write object. Called printOn since it prints the object _on_ a stream.
* @param _os A std::ostream.
*/
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
*/
moIndexNeighbor() : moNeighbor<EOT, Fitness>(), key(0){}
moIndexNeighbor() : moNeighbor<EOT, Fitness>(), key(0) {}
/**
* Copy Constructor
*/
moIndexNeighbor(const moIndexNeighbor& _n) : moNeighbor<EOT, Fitness>(_n) {
this->key = _n.key ;
this->key = _n.key ;
}
/**
* Assignment operator
*/
virtual moIndexNeighbor<EOT, Fitness> & operator=(const moIndexNeighbor<EOT, Fitness> & _source) {
moNeighbor<EOT, Fitness>::operator=(_source);
this->key = _source.key ;
return *this ;
moNeighbor<EOT, Fitness>::operator=(_source);
this->key = _source.key ;
return *this ;
}
/**
@ -73,23 +73,23 @@ public:
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moIndexNeighbor";
return "moIndexNeighbor";
}
/**
* Getter
* @return index of the IndexNeighbor
*/
unsigned int index(){
return key;
unsigned int index() {
return key;
}
/**
* Setter
* @param _key index of the IndexNeighbor
*/
void index(unsigned int _key){
key=_key;
void index(unsigned int _key) {
key=_key;
}
protected:

View file

@ -44,23 +44,23 @@ template< class Neighbor >
class moIndexNeighborhood : virtual public moNeighborhood<Neighbor>
{
public:
/**
* Define type of a solution corresponding to Neighbor
*/
/**
* Define type of a solution corresponding to Neighbor
*/
typedef typename Neighbor::EOT EOT;
/**
* Constructor
* @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 name as a std::string
*/
virtual std::string className() const {
return "moIndexNeighborhood";
return "moIndexNeighborhood";
}
protected:

View file

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

View file

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

View file

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

View file

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

View file

@ -47,20 +47,20 @@ class moRndWithReplNeighborhood : public moIndexNeighborhood<N>, public moRndNei
{
public:
/**
* Define type of a solution corresponding to Neighbor
*/
/**
* Define type of a solution corresponding to Neighbor
*/
typedef N Neighbor;
typedef typename Neighbor::EOT EOT;
using moIndexNeighborhood<Neighbor>::neighborhoodSize;
using moIndexNeighborhood<Neighbor>::neighborhoodSize;
/**
* Constructor
* @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
@ -68,7 +68,7 @@ public:
* @return true if the neighborhood was not empty
*/
virtual bool hasNeighbor(EOT& _solution) {
return neighborhoodSize > 0;
return neighborhoodSize > 0;
}
/**
@ -77,7 +77,7 @@ public:
* @param _neighbor the first 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
*/
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
*/
virtual bool cont(EOT & _solution) {
return neighborhoodSize > 0;
return neighborhoodSize > 0;
}
/**
@ -103,7 +103,7 @@ public:
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moRndWithReplNeighborhood";
return "moRndWithReplNeighborhood";
}
};

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -33,46 +33,46 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib>
#include <cassert>
int main(){
int main() {
std::cout << "[t-moBestImprAspiration] => START" << std::endl;
std::cout << "[t-moBestImprAspiration] => START" << std::endl;
moBestImprAspiration<bitNeighbor> test;
eoBit<eoMinimizingFitness> sol1(4);
eoBit<eoMinimizingFitness> sol2(4);
eoBit<eoMinimizingFitness> sol3(4);
eoBit<eoMinimizingFitness> sol4(4);
bitNeighbor n1;
bitNeighbor n2;
bitNeighbor n3;
bitNeighbor n4;
moBestImprAspiration<bitNeighbor> test;
eoBit<eoMinimizingFitness> sol1(4);
eoBit<eoMinimizingFitness> sol2(4);
eoBit<eoMinimizingFitness> sol3(4);
eoBit<eoMinimizingFitness> sol4(4);
bitNeighbor n1;
bitNeighbor n2;
bitNeighbor n3;
bitNeighbor n4;
sol3[0]=true;
sol4[3]=true;
sol3[0]=true;
sol4[3]=true;
sol1.fitness(4);
sol2.fitness(5);
sol3.fitness(3);
sol4.fitness(3);
n1.fitness(4);
n2.fitness(5);
n3.fitness(3);
n4.fitness(3);
sol1.fitness(4);
sol2.fitness(5);
sol3.fitness(3);
sol4.fitness(3);
n1.fitness(4);
n2.fitness(5);
n3.fitness(3);
n4.fitness(3);
//verification qu'on update bien le best so far quand il faut
test.init(sol1);
assert(test.getBest()==sol1);
assert(!test(sol2,n2));
assert(test(sol3,n3));
test.update(sol3,n3);
assert(test.getBest()==sol3);
assert(!test(sol4,n4));
test.update(sol4,n4);
assert(test.getBest()==sol3);
//verification qu'on update bien le best so far quand il faut
test.init(sol1);
assert(test.getBest()==sol1);
assert(!test(sol2,n2));
assert(test(sol3,n3));
test.update(sol3,n3);
assert(test.getBest()==sol3);
assert(!test(sol4,n4));
test.update(sol4,n4);
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 <cassert>
int main(){
int main() {
std::cout << "[t-moBitNeighbor] => START" << std::endl;
std::cout << "[t-moBitNeighbor] => START" << std::endl;
//init sol
eoBit<int> sol;
sol.push_back(true);
sol.push_back(false);
sol.push_back(true);
//init sol
eoBit<int> sol;
sol.push_back(true);
sol.push_back(false);
sol.push_back(true);
//verif du constructeur vide
moBitNeighbor<int> test1;
assert(test1.index()==0);
//verif du constructeur vide
moBitNeighbor<int> test1;
assert(test1.index()==0);
//verif du setter d'index et du constructeur de copy
test1.index(6);
test1.fitness(2);
moBitNeighbor<int> test2(test1);
assert(test2.index()==6);
assert(test2.fitness()==2);
//verif du setter d'index et du constructeur de copy
test1.index(6);
test1.fitness(2);
moBitNeighbor<int> test2(test1);
assert(test2.index()==6);
assert(test2.fitness()==2);
//verif du getter
assert(test1.index()==6);
//verif du getter
assert(test1.index()==6);
//verif de l'operateur=
test1.fitness(8);
test1.index(2);
test2=test1;
assert(test2.fitness()==8);
assert(test2.index()==2);
//verif de l'operateur=
test1.fitness(8);
test1.index(2);
test2=test1;
assert(test2.fitness()==8);
assert(test2.index()==2);
//verif de move
test2.move(sol);
assert(!sol[2]);
//verif de move
test2.move(sol);
assert(!sol[2]);
//verif de moveBack
test2.moveBack(sol);
assert(sol[2]);
//verif de moveBack
test2.moveBack(sol);
assert(sol[2]);
test1.printOn(std::cout);
test2.printOn(std::cout);
test1.printOn(std::cout);
test2.printOn(std::cout);
assert(test1.className()=="moBitNeighbor");
std::cout << "[t-moBitNeighbor] => OK" << std::endl;
return EXIT_SUCCESS;
assert(test1.className()=="moBitNeighbor");
std::cout << "[t-moBitNeighbor] => OK" << std::endl;
return EXIT_SUCCESS;
}

View file

@ -36,87 +36,87 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib>
#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 b=15;
unsigned int c= 10;
unsigned int d= 47;
unsigned int a=2;
unsigned int b=15;
unsigned int c= 10;
unsigned int d= 47;
eoBit<eoMinimizingFitness> s(3);
s[0]=true;
s[1]=true;
s[2]=false;
eoBit<eoMinimizingFitness> s(3);
s[0]=true;
s[1]=true;
s[2]=false;
s.fitness(17);
s.fitness(17);
//verification que toutes les operateurs sont bien apellés
moSolutionStat< eoBit< eoMinimizingFitness > > stat;
updater1 up1(a);
updater1 up2(b);
monitor1 mon1(c);
monitor2 mon2(d);
moTrueContinuator< bitNeighborhood > cont;
//verification que toutes les operateurs sont bien apellés
moSolutionStat< eoBit< eoMinimizingFitness > > stat;
updater1 up1(a);
updater1 up2(b);
monitor1 mon1(c);
monitor2 mon2(d);
moTrueContinuator< bitNeighborhood > cont;
moCheckpoint< bitNeighborhood> test1(cont);
moCheckpoint< bitNeighborhood> test2(cont, 3);
moCheckpoint< bitNeighborhood> test1(cont);
moCheckpoint< bitNeighborhood> test2(cont, 3);
test1.add(up1);
test1.add(up2);
test1.add(mon1);
test1.add(mon2);
test1.add(stat);
test1.add(up1);
test1.add(up2);
test1.add(mon1);
test1.add(mon2);
test1.add(stat);
test2.add(up1);
test2.add(up2);
test2.add(mon1);
test2.add(mon2);
test2.add(stat);
test2.add(up1);
test2.add(up2);
test2.add(mon1);
test2.add(mon2);
test2.add(stat);
test1.init(s);
test1(s);
assert(a==3 && b==16 && c==11 && d==48);
assert(stat.value()[0]);
assert(stat.value()[1]);
assert(!stat.value()[2]);
assert(stat.value().fitness()==17);
test1.init(s);
test1(s);
assert(a==3 && b==16 && c==11 && d==48);
assert(stat.value()[0]);
assert(stat.value()[1]);
assert(!stat.value()[2]);
assert(stat.value().fitness()==17);
test1(s);
assert(a==4 && b==17 && c==12 && d==49);
assert(stat.value()[0]);
assert(stat.value()[1]);
assert(!stat.value()[2]);
assert(stat.value().fitness()==17);
test1(s);
assert(a==4 && b==17 && c==12 && d==49);
assert(stat.value()[0]);
assert(stat.value()[1]);
assert(!stat.value()[2]);
assert(stat.value().fitness()==17);
s.fitness(4);
s.fitness(4);
test2.init(s);
test2(s);
assert(a==5 && b==18 && c==13 && d==50);
assert(stat.value()[0]);
assert(stat.value()[1]);
assert(!stat.value()[2]);
assert(stat.value().fitness()==4);
test2.init(s);
test2(s);
assert(a==5 && b==18 && c==13 && d==50);
assert(stat.value()[0]);
assert(stat.value()[1]);
assert(!stat.value()[2]);
assert(stat.value().fitness()==4);
s.fitness(6);
test2(s);
assert(stat.value().fitness()==4);
test2(s);
assert(stat.value().fitness()==4);
test2(s);
assert(stat.value().fitness()==6);
s.fitness(6);
test2(s);
assert(stat.value().fitness()==4);
test2(s);
assert(stat.value().fitness()==4);
test2(s);
assert(stat.value().fitness()==6);
test1.lastCall(s);
assert(a==9 && b==22 && c==17 && d==54);
test2.lastCall(s);
assert(a==10 && b==23 && c==18 && d==55);
test1.lastCall(s);
assert(a==9 && b==22 && c==17 && d==54);
test2.lastCall(s);
assert(a==10 && b==23 && c==18 && d==55);
assert(test1.className()=="moCheckpoint");
std::cout << "[t-moCheckpoint] => OK" << std::endl;
assert(test1.className()=="moCheckpoint");
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>
int main(){
int main() {
std::cout << "[t-moCounterMonitorSaver] => START" << std::endl;
std::cout << "[t-moCounterMonitorSaver] => START" << std::endl;
unsigned int a=1;
unsigned int b=10;
unsigned int a=1;
unsigned int b=10;
monitor1 mon1(a);
monitor2 mon2(b);
monitor1 mon1(a);
monitor2 mon2(b);
moCounterMonitorSaver test(3, mon1);
test.add(mon2);
moCounterMonitorSaver test(3, mon1);
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();
assert(a==2 && b==11);
test();
assert(a==2 && b==11);
test();
assert(a==2 && b==11);
test();
assert(a==3 && b==12);
test();
assert(a==2 && b==11);
test();
assert(a==2 && b==11);
test();
assert(a==2 && b==11);
test();
assert(a==3 && b==12);
//test du lastCall
test.lastCall();
assert(a==4 && b==13);
//test du lastCall
test.lastCall();
assert(a==4 && b==13);
assert(test.className()=="moCounterMonitorSaver");
std::cout << "[t-moCounterMonitorSaver] => OK" << std::endl;
assert(test.className()=="moCounterMonitorSaver");
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 <cassert>
int main(){
int main() {
std::cout << "[t-moDistanceStat] => START" << std::endl;
std::cout << "[t-moDistanceStat] => START" << std::endl;
eoBit<int> sol1;
eoBit<int> sol2;
eoBit<int> sol3;
sol1.push_back(true);
sol1.push_back(false);
sol1.push_back(true);
eoBit<int> sol1;
eoBit<int> sol2;
eoBit<int> sol3;
sol1.push_back(true);
sol1.push_back(false);
sol1.push_back(true);
sol2.push_back(true);
sol2.push_back(true);
sol2.push_back(false);
sol2.push_back(true);
sol2.push_back(true);
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);
assert(test.value()==2);
test(sol3);
assert(test.value()==1);
test(sol2);
assert(test.value()==2);
test(sol3);
assert(test.value()==1);
assert(test.className()=="moDistanceStat");
std::cout << "[t-moDistanceStat] => OK" << std::endl;
assert(test.className()=="moDistanceStat");
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 <cassert>
int main(){
int main() {
std::cout << "[t-moDummyMemory] => START" << std::endl;
std::cout << "[t-moDummyMemory] => START" << std::endl;
eoBit<eoMinimizingFitness> sol(4);
bitNeighbor n;
moDummyDiversification<bitNeighbor> test1;
test1.init(sol);
test1.add(sol, n);
test1.update(sol, n);
test1.clearMemory();
assert(!test1(sol));
eoBit<eoMinimizingFitness> sol(4);
bitNeighbor n;
moDummyDiversification<bitNeighbor> test1;
test1.init(sol);
test1.add(sol, n);
test1.update(sol, n);
test1.clearMemory();
assert(!test1(sol));
moDummyIntensification<bitNeighbor> test2;
test2.init(sol);
test2.add(sol, n);
test2.update(sol, n);
test2.clearMemory();
assert(!test2(sol));
moDummyIntensification<bitNeighbor> test2;
test2.init(sol);
test2.add(sol, n);
test2.update(sol, n);
test2.clearMemory();
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 <cassert>
int main(){
int main() {
std::cout << "[t-moFirstImprExplorer] => START" << std::endl;
std::cout << "[t-moFirstImprExplorer] => START" << std::endl;
//Instanciation
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp;
moSolNeighborComparator<bitNeighbor> sncomp;
//Instanciation
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp;
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);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==3);
assert(!sol[0]);
assert(test.isContinue(sol));
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==3);
assert(!sol[0]);
assert(test.isContinue(sol));
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==2);
assert(!sol[1]);
assert(test.isContinue(sol));
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==2);
assert(!sol[1]);
assert(test.isContinue(sol));
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==1);
assert(!sol[2]);
assert(test.isContinue(sol));
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==1);
assert(!sol[2]);
assert(test.isContinue(sol));
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==0);
assert(!sol[3]);
assert(test.isContinue(sol));
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==0);
assert(!sol[3]);
assert(test.isContinue(sol));
test(sol);
assert(!test.accept(sol));
assert(sol.fitness()==0);
assert(!test.isContinue(sol));
test(sol);
assert(!test.accept(sol));
assert(sol.fitness()==0);
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 <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;
sol.fitness(3);
test(sol);
assert(test.value()==3);
moFitnessStat< eoBit<int> > test;
sol.fitness(3);
test(sol);
assert(test.value()==3);
sol.fitness(12);
test(sol);
assert(test.value()==12);
sol.fitness(12);
test(sol);
assert(test.value()==12);
assert(test.className()=="moFitnessStat");
std::cout << "[t-moFitnessStat] => OK" << std::endl;
assert(test.className()=="moFitnessStat");
std::cout << "[t-moFitnessStat] => OK" << std::endl;
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}

View file

@ -38,26 +38,26 @@
#include <cstdlib>
#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;
moDummyNeighbor neighbor;
moDummyEval eval;
Solution sol;
moDummyNeighbor neighbor;
moDummyEval eval;
//verif constructor
moFullEvalByCopy<moDummyNeighbor> test(eval);
//verif constructor
moFullEvalByCopy<moDummyNeighbor> test(eval);
sol.fitness(3);
sol.fitness(3);
//verif operator()
test(sol,neighbor);
assert(sol.fitness()==3);
//verif operator()
test(sol,neighbor);
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 <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;
moDummyBackableNeighbor neighbor;
moDummyEval eval;
Solution sol;
moDummyBackableNeighbor neighbor;
moDummyEval eval;
//verif constructor
moFullEvalByModif<moDummyBackableNeighbor> test(eval);
//verif constructor
moFullEvalByModif<moDummyBackableNeighbor> test(eval);
sol.fitness(3);
sol.fitness(3);
//verif operator()
test(sol,neighbor);
assert(sol.fitness()==3);
//verif operator()
test(sol,neighbor);
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 <cassert>
int main(){
int main() {
std::cout << "[t-moHCneutralExplorer] => START" << std::endl;
std::cout << "[t-moHCneutralExplorer] => START" << std::endl;
//Instanciation
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp;
moSolNeighborComparator<bitNeighbor> sncomp;
//Instanciation
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp;
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(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==3);
test.updateParam(sol);
assert(test.isContinue(sol));
test.initParam(sol);
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==3);
test.updateParam(sol);
assert(test.isContinue(sol));
//les affichages permettent de voir qu'on prend pas toujours les mm voisins(lancer plusieurs fois l'exe)
std::cout << sol << std::endl;
//les affichages permettent de voir qu'on prend pas toujours les mm voisins(lancer plusieurs fois l'exe)
std::cout << sol << std::endl;
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==2);
test.updateParam(sol);
assert(test.isContinue(sol));
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==2);
test.updateParam(sol);
assert(test.isContinue(sol));
std::cout << sol << std::endl;
std::cout << sol << std::endl;
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==1);
test.updateParam(sol);
assert(!test.isContinue(sol));
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==1);
test.updateParam(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 <cassert>
int main(){
int main() {
std::cout << "[t-moMetropolisHastingExplorer] => START" << std::endl;
std::cout << "[t-moMetropolisHastingExplorer] => START" << std::endl;
//Instanciation
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp;
moSolNeighborComparator<bitNeighbor> sncomp;
//Instanciation
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp;
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.initParam(sol);
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==3);
test.updateParam(sol);
assert(test.isContinue(sol));
//test de l'acceptation d'un voisin améliorant
test.initParam(sol);
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==3);
test.updateParam(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
for(unsigned int i=0; i<1000; i++){
test(sol);
if(test.accept(sol))
oui++;
else
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 << "oui: " << oui << std::endl;
std::cout << "non: " << non << std::endl;
//test de l'acceptation d'un voisin non améliorant
for (unsigned int i=0; i<1000; i++) {
test(sol);
if (test.accept(sol))
oui++;
else
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 << "oui: " << oui << 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.updateParam(sol);
assert(test.isContinue(sol));
test.updateParam(sol);
assert(!test.isContinue(sol));
//test du critere d'arret
test.updateParam(sol);
assert(test.isContinue(sol));
test.updateParam(sol);
assert(!test.isContinue(sol));
//test de l'acceptation d'un voisin
sol[0]=false;
sol[1]=false;
sol[2]=false;
sol[3]=false;
sol.fitness(0);
//test de l'acceptation d'un voisin
sol[0]=false;
sol[1]=false;
sol[2]=false;
sol[3]=false;
sol.fitness(0);
test.initParam(sol);
test(sol);
assert(!test.accept(sol));
test.initParam(sol);
test(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 <cassert>
int main(){
int main() {
std::cout << "[t-moNeighbor] => START" << std::endl;
std::cout << "[t-moNeighbor] => START" << std::endl;
//test constructor
moDummyNeighbor test1, test2;
//test constructor
moDummyNeighbor test1, test2;
test1.fitness(3);
//test operateur d'affectation
test2=test1;
assert(test1.fitness()==test2.fitness());
test1.fitness(3);
//test operateur d'affectation
test2=test1;
assert(test1.fitness()==test2.fitness());
//test operateur de copy
moDummyNeighbor test3(test1);
assert(test1.fitness()==test3.fitness());
//test operateur de copy
moDummyNeighbor test3(test1);
assert(test1.fitness()==test3.fitness());
test1.printOn(std::cout);
test2.printOn(std::cout);
test3.printOn(std::cout);
test1.printOn(std::cout);
test2.printOn(std::cout);
test3.printOn(std::cout);
assert(test1.className()=="moNeighbor");
std::cout << "[t-moNeighbor] => OK" << std::endl;
assert(test1.className()=="moNeighbor");
std::cout << "[t-moNeighbor] => OK" << std::endl;
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}

View file

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

View file

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

View file

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

View file

@ -34,55 +34,55 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib>
#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);
sol.fitness(4);
bitNeighborhood nh(4);
evalOneMax eval(4);
dummyEvalOneMax eval2(4);
moSolNeighborComparator<bitNeighbor> sncomp;
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
evalOneMax eval(4);
dummyEvalOneMax eval2(4);
moSolNeighborComparator<bitNeighbor> sncomp;
//test avec la fonction d'eval classique
//on verifie qu'on ne trouve pas de voisin de mm fitness
moRandomNeutralWalkExplorer<bitNeighborhood> test(nh, eval, sncomp, 3);
//test avec la fonction d'eval classique
//on verifie qu'on ne trouve pas de voisin de mm fitness
moRandomNeutralWalkExplorer<bitNeighborhood> test(nh, eval, sncomp, 3);
test.initParam(sol);
test(sol);
assert(!test.accept(sol));
assert(!test.isContinue(sol));
test.initParam(sol);
test(sol);
assert(!test.accept(sol));
assert(!test.isContinue(sol));
//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.
moRandomNeutralWalkExplorer<bitNeighborhood> test2(nh, eval2, sncomp, 3);
//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.
moRandomNeutralWalkExplorer<bitNeighborhood> test2(nh, eval2, sncomp, 3);
sol.fitness(2);
test2.initParam(sol);
test2(sol);
assert(test2.accept(sol));
test2.move(sol);
assert(sol.fitness()==2);
test2.updateParam(sol);
assert(test2.isContinue(sol));
sol.fitness(2);
test2.initParam(sol);
test2(sol);
assert(test2.accept(sol));
test2.move(sol);
assert(sol.fitness()==2);
test2.updateParam(sol);
assert(test2.isContinue(sol));
test2(sol);
assert(test2.accept(sol));
test2.move(sol);
assert(sol.fitness()==2);
test2.updateParam(sol);
assert(test2.isContinue(sol));
test2(sol);
assert(test2.accept(sol));
test2.move(sol);
assert(sol.fitness()==2);
test2.updateParam(sol);
assert(test2.isContinue(sol));
test2(sol);
assert(test2.accept(sol));
test2.move(sol);
assert(sol.fitness()==2);
test2.updateParam(sol);
assert(!test2.isContinue(sol));
test2(sol);
assert(test2.accept(sol));
test2.move(sol);
assert(sol.fitness()==2);
test2.updateParam(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 <cassert>
int main(){
int main() {
std::cout << "[t-moRandomWalkExplorer] => START" << std::endl;
std::cout << "[t-moRandomWalkExplorer] => START" << std::endl;
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
evalOneMax eval(4);
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
evalOneMax eval(4);
//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
moRandomWalkExplorer<bitNeighborhood> test(nh, eval, 3);
//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
moRandomWalkExplorer<bitNeighborhood> test(nh, eval, 3);
test.initParam(sol);
test.initParam(sol);
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==3);
test.updateParam(sol);
assert(test.isContinue(sol));
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==3);
test.updateParam(sol);
assert(test.isContinue(sol));
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==4);
test.updateParam(sol);
assert(test.isContinue(sol));
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==4);
test.updateParam(sol);
assert(test.isContinue(sol));
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==3);
assert(!sol[0]);
test.updateParam(sol);
assert(!test.isContinue(sol));
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==3);
assert(!sol[0]);
test.updateParam(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 <cassert>
int main(){
int main() {
std::cout << "[t-moRndWithReplNeighborhood] => START" << std::endl;
std::cout << "[t-moRndWithReplNeighborhood] => START" << std::endl;
unsigned int a, b;
eoBit<int> sol;
moBitNeighbor<int> n;
unsigned int a, b;
eoBit<int> sol;
moBitNeighbor<int> n;
moRndWithReplNeighborhood< moBitNeighbor<int> > test(3);
moRndWithReplNeighborhood< moBitNeighbor<int> > test2(0);
moRndWithReplNeighborhood< moBitNeighbor<int> > test(3);
moRndWithReplNeighborhood< moBitNeighbor<int> > test2(0);
assert(test.hasNeighbor(sol));
assert(!test2.hasNeighbor(sol));
assert(test.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é
for(unsigned int i=0; i<100; i++){
//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++) {
a=n.index();
test.next(sol,n);
b=n.index();
a=n.index();
test.next(sol,n);
b=n.index();
assert(a==0 || a==1 || a==2);
assert(b==0 || b==1 || b==2);
assert(test.cont(sol));
assert(!test2.cont(sol));
assert(test.cont(sol));
assert(a==0 || a==1 || a==2);
assert(b==0 || b==1 || b==2);
assert(test.cont(sol));
assert(!test2.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 <cassert>
int main(){
int main() {
std::cout << "[t-moRndWithoutReplNeighborhood] => START" << std::endl;
std::cout << "[t-moRndWithoutReplNeighborhood] => START" << std::endl;
unsigned int a, b, c;
eoBit<int> sol;
moBitNeighbor<int> n;
unsigned int a, b, c;
eoBit<int> sol;
moBitNeighbor<int> n;
//instanciation
moRndWithoutReplNeighborhood< moBitNeighbor<int> > test(3);
moRndWithoutReplNeighborhood< moBitNeighbor<int> > test2(0);
//instanciation
moRndWithoutReplNeighborhood< moBitNeighbor<int> > test(3);
moRndWithoutReplNeighborhood< moBitNeighbor<int> > test2(0);
//on verifie que test a bien des voisins et que test2 n'en a pas
assert(test.hasNeighbor(sol));
assert(!test2.hasNeighbor(sol));
//on verifie que test a bien des voisins et que test2 n'en a pas
assert(test.hasNeighbor(sol));
assert(!test2.hasNeighbor(sol));
//on recupere successivement les index
test.init(sol, n);
assert(test.cont(sol));
a=test.position();
test.next(sol, n);
assert(test.cont(sol));
b=test.position();
test.next(sol,n);
assert(!test.cont(sol));
c=test.position();
//on recupere successivement les index
test.init(sol, n);
assert(test.cont(sol));
a=test.position();
test.next(sol, n);
assert(test.cont(sol));
b=test.position();
test.next(sol,n);
assert(!test.cont(sol));
c=test.position();
//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==1 || b==1 || c==1);
assert(a==2 || b==2 || c==2);
//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==1 || b==1 || c==1);
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 <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;
moDummyNeighbor neighbor;
moDummyEval eval;
moDummyNeighborhood nh;
moFullEvalByCopy<moDummyNeighbor> fulleval(eval);
moNeighborComparator<moDummyNeighbor> comp;
moSolNeighborComparator<moDummyNeighbor> solNeighborComp;
Solution sol;
moDummyNeighbor neighbor;
moDummyEval eval;
moDummyNeighborhood nh;
moFullEvalByCopy<moDummyNeighbor> fulleval(eval);
moNeighborComparator<moDummyNeighbor> comp;
moSolNeighborComparator<moDummyNeighbor> solNeighborComp;
//verif constructor
moSimpleHCexplorer<moDummyNeighborhood> test(nh, fulleval, comp, solNeighborComp);
//verif constructor
moSimpleHCexplorer<moDummyNeighborhood> test(nh, fulleval, comp, solNeighborComp);
//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
sol.fitness(3);
test(sol);
test.accept(sol);
assert(!test.isContinue(sol));
//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
sol.fitness(3);
test(sol);
test.accept(sol);
assert(!test.isContinue(sol));
//hasNeighbor() retourne faux a l'entrée de accept() donc on doit pas continuer
test(sol);
test.accept(sol);
assert(!test.isContinue(sol));
//hasNeighbor() retourne faux a l'entrée de accept() donc on doit pas continuer
test(sol);
test.accept(sol);
assert(!test.isContinue(sol));
//hasNeighbor() retourne vrai et on ameliore la fitness donc on doit continuer
test(sol);
test.accept(sol);
assert(test.isContinue(sol));
//hasNeighbor() retourne vrai et on ameliore la fitness donc on doit continuer
test(sol);
test.accept(sol);
assert(test.isContinue(sol));
//verif de move -> on affecte la fitness du best d'avant
test.move(sol);
//verif de move -> on affecte la fitness du best d'avant
test.move(sol);
//hasNeighbor() retourne vrai et on ameliore pas la fitness donc on doit pas continuer
test(sol);
test(sol);
test.accept(sol);
assert(!test.isContinue(sol));
//hasNeighbor() retourne vrai et on ameliore pas la fitness donc on doit pas continuer
test(sol);
test(sol);
test.accept(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 <cassert>
int main(){
int main() {
std::cout << "[t-moSimpleHCneutralExplorer] => START" << std::endl;
std::cout << "[t-moSimpleHCneutralExplorer] => START" << std::endl;
//instanciation
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp;
moSolNeighborComparator<bitNeighbor> sncomp;
//instanciation
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp;
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.initParam(sol);
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==3);
assert(test.isContinue(sol));
test.updateParam(sol);
//test qu'on ameliore bien a chaque itération
test.initParam(sol);
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==3);
assert(test.isContinue(sol));
test.updateParam(sol);
//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;
//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;
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==2);
assert(test.isContinue(sol));
test.updateParam(sol);
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==2);
assert(test.isContinue(sol));
test.updateParam(sol);
std::cout << sol << std::endl;
std::cout << sol << std::endl;
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==1);
assert(test.isContinue(sol));
test.updateParam(sol);
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==1);
assert(test.isContinue(sol));
test.updateParam(sol);
std::cout << sol << std::endl;
std::cout << sol << std::endl;
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==0);
assert(test.isContinue(sol));
test.updateParam(sol);
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==0);
assert(test.isContinue(sol));
test.updateParam(sol);
test(sol);
assert(!test.accept(sol));
assert(sol.fitness()==0);
assert(!test.isContinue(sol));
test.updateParam(sol);
test(sol);
assert(!test.accept(sol));
assert(sol.fitness()==0);
assert(!test.isContinue(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 <cassert>
int main(){
int main() {
std::cout << "[t-moSolNeighborComparator] => START" << std::endl;
std::cout << "[t-moSolNeighborComparator] => START" << std::endl;
moBitNeighbor<eoMinimizingFitness> neighbor;
eoBit<eoMinimizingFitness> sol;
moBitNeighbor<eoMinimizingFitness> neighbor;
eoBit<eoMinimizingFitness> sol;
moSolNeighborComparator< moBitNeighbor<eoMinimizingFitness> > test;
moSolNeighborComparator< moBitNeighbor<eoMinimizingFitness> > test;
neighbor.fitness(3);
sol.fitness(2);
//test with a minimizing fitness, neighbor must not be better than sol
assert(!test(sol, neighbor));
neighbor.fitness(3);
sol.fitness(2);
//test with a minimizing fitness, neighbor must not be better than sol
assert(!test(sol, neighbor));
//reversly
neighbor.fitness(2);
sol.fitness(3);
assert(test(sol, neighbor));
//reversly
neighbor.fitness(2);
sol.fitness(3);
assert(test(sol, neighbor));
//test equals
assert(!test.equals(sol, neighbor));
//test equals
assert(!test.equals(sol, neighbor));
neighbor.fitness(3);
assert(test.equals(sol, neighbor));
neighbor.fitness(3);
assert(test.equals(sol, neighbor));
assert(test.className()=="moSolNeighborComparator");
assert(test.className()=="moSolNeighborComparator");
std::cout << "[t-moSolNeighborComparator] => OK" << std::endl;
return EXIT_SUCCESS;
std::cout << "[t-moSolNeighborComparator] => OK" << std::endl;
return EXIT_SUCCESS;
}

View file

@ -34,121 +34,121 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <cstdlib>
#include <cassert>
int main(){
int main() {
std::cout << "[t-moSolVectorTabuList] => START" << std::endl;
std::cout << "[t-moSolVectorTabuList] => START" << std::endl;
//test without countdown
moSolVectorTabuList<bitNeighbor> test(2,0);
bitNeighbor n1;
bitNeighbor n2;
bitNeighbor n3;
bitNeighbor n4;
n1.index(0);
n2.index(1);
n3.index(2);
n4.index(3);
//test without countdown
moSolVectorTabuList<bitNeighbor> test(2,0);
bitNeighbor n1;
bitNeighbor n2;
bitNeighbor n3;
bitNeighbor n4;
n1.index(0);
n2.index(1);
n3.index(2);
n4.index(3);
eoBit<eoMinimizingFitness> sol1(4, true);
eoBit<eoMinimizingFitness> sol2(4, true);
eoBit<eoMinimizingFitness> sol3(4, true);
eoBit<eoMinimizingFitness> sol4(4, true);
eoBit<eoMinimizingFitness> sol1(4, true);
eoBit<eoMinimizingFitness> sol2(4, true);
eoBit<eoMinimizingFitness> sol3(4, true);
eoBit<eoMinimizingFitness> sol4(4, true);
sol2[0]=false;
sol3[1]=false;
sol4[0]=false;
sol4[1]=false;
sol2[0]=false;
sol3[1]=false;
sol4[0]=false;
sol4[1]=false;
//init
test.init(sol1);
//init
test.init(sol1);
//ajout d'une sol tabu
test.add(sol1,n1);
//ajout d'une sol tabu
test.add(sol1,n1);
//verification des voisins de chaques sol
assert(test.check(sol2,n1));
assert(!test.check(sol2,n2));
assert(!test.check(sol2,n3));
assert(!test.check(sol2,n4));
//verification des voisins de chaques sol
assert(test.check(sol2,n1));
assert(!test.check(sol2,n2));
assert(!test.check(sol2,n3));
assert(!test.check(sol2,n4));
assert(!test.check(sol3,n1));
assert(test.check(sol3,n2));
assert(!test.check(sol3,n3));
assert(!test.check(sol3,n4));
assert(!test.check(sol3,n1));
assert(test.check(sol3,n2));
assert(!test.check(sol3,n3));
assert(!test.check(sol3,n4));
assert(!test.check(sol4,n1));
assert(!test.check(sol4,n2));
assert(!test.check(sol4,n3));
assert(!test.check(sol4,n4));
assert(!test.check(sol4,n1));
assert(!test.check(sol4,n2));
assert(!test.check(sol4,n3));
assert(!test.check(sol4,n4));
test.init(sol1);
assert(!test.check(sol2,n1));
assert(!test.check(sol3,n2));
test.init(sol1);
assert(!test.check(sol2,n1));
assert(!test.check(sol3,n2));
test.update(sol1,n1);
test.update(sol1,n1);
test.add(sol1,n1);
test.add(sol2,n1);
assert(test.check(sol2,n1));
test.add(sol4,n1);
assert(!test.check(sol2,n1));
assert(test.check(sol2,n2));
test.add(sol1,n1);
test.add(sol2,n1);
assert(test.check(sol2,n1));
test.add(sol4,n1);
assert(!test.check(sol2,n1));
assert(test.check(sol2,n2));
//test with a countdown at 3
moSolVectorTabuList<bitNeighbor> test2(2,2);
test2.init(sol1);
test2.add(sol1,n1);
assert(test2.check(sol2,n1));
assert(!test2.check(sol2,n2));
assert(!test2.check(sol2,n3));
assert(!test2.check(sol2,n4));
//test with a countdown at 3
moSolVectorTabuList<bitNeighbor> test2(2,2);
test2.init(sol1);
test2.add(sol1,n1);
assert(test2.check(sol2,n1));
assert(!test2.check(sol2,n2));
assert(!test2.check(sol2,n3));
assert(!test2.check(sol2,n4));
assert(!test2.check(sol3,n1));
assert(test2.check(sol3,n2));
assert(!test2.check(sol3,n3));
assert(!test2.check(sol3,n4));
assert(!test2.check(sol3,n1));
assert(test2.check(sol3,n2));
assert(!test2.check(sol3,n3));
assert(!test2.check(sol3,n4));
assert(!test2.check(sol4,n1));
assert(!test2.check(sol4,n2));
assert(!test2.check(sol4,n3));
assert(!test2.check(sol4,n4));
assert(!test2.check(sol4,n1));
assert(!test2.check(sol4,n2));
assert(!test2.check(sol4,n3));
assert(!test2.check(sol4,n4));
//coutdown sol1 -> 1
test2.update(sol1,n1);
assert(test2.check(sol2,n1));
assert(!test2.check(sol2,n2));
assert(!test2.check(sol2,n3));
assert(!test2.check(sol2,n4));
//coutdown sol1 -> 1
test2.update(sol1,n1);
assert(test2.check(sol2,n1));
assert(!test2.check(sol2,n2));
assert(!test2.check(sol2,n3));
assert(!test2.check(sol2,n4));
assert(!test2.check(sol3,n1));
assert(test2.check(sol3,n2));
assert(!test2.check(sol3,n3));
assert(!test2.check(sol3,n4));
assert(!test2.check(sol3,n1));
assert(test2.check(sol3,n2));
assert(!test2.check(sol3,n3));
assert(!test2.check(sol3,n4));
assert(!test2.check(sol4,n1));
assert(!test2.check(sol4,n2));
assert(!test2.check(sol4,n3));
assert(!test2.check(sol4,n4));
assert(!test2.check(sol4,n1));
assert(!test2.check(sol4,n2));
assert(!test2.check(sol4,n3));
assert(!test2.check(sol4,n4));
//coutdown sol1 -> 0 : sol1 is no longer tabu
test2.update(sol1,n1);
assert(!test2.check(sol2,n1));
assert(!test2.check(sol2,n2));
assert(!test2.check(sol2,n3));
assert(!test2.check(sol2,n4));
//coutdown sol1 -> 0 : sol1 is no longer tabu
test2.update(sol1,n1);
assert(!test2.check(sol2,n1));
assert(!test2.check(sol2,n2));
assert(!test2.check(sol2,n3));
assert(!test2.check(sol2,n4));
assert(!test2.check(sol3,n1));
assert(!test2.check(sol3,n2));
assert(!test2.check(sol3,n3));
assert(!test2.check(sol3,n4));
assert(!test2.check(sol3,n1));
assert(!test2.check(sol3,n2));
assert(!test2.check(sol3,n3));
assert(!test2.check(sol3,n4));
assert(!test2.check(sol4,n1));
assert(!test2.check(sol4,n2));
assert(!test2.check(sol4,n3));
assert(!test2.check(sol4,n4));
assert(!test2.check(sol4,n1));
assert(!test2.check(sol4,n2));
assert(!test2.check(sol4,n3));
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 <cassert>
int main(){
int main() {
std::cout << "[t-moSolutionStat] => START" << std::endl;
std::cout << "[t-moSolutionStat] => START" << std::endl;
eoBit<unsigned int> s(3);
s[0]=true;
s[1]=true;
s[2]=false;
eoBit<unsigned int> s(3);
s[0]=true;
s[1]=true;
s[2]=false;
s.fitness(17);
s.fitness(17);
moSolutionStat< eoBit<unsigned int > > test;
moSolutionStat< eoBit<unsigned int > > test;
test(s);
//on verifie que la solution est bien enregistré
test(s);
//on verifie que la solution est bien enregistré
assert(test.value()[0]);
assert(test.value()[1]);
assert(!test.value()[2]);
assert(test.value().fitness()==17);
assert(test.value()[0]);
assert(test.value()[1]);
assert(!test.value()[2]);
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 <cassert>
int main(){
int main() {
std::cout << "[t-moTSExplorer] => START" << std::endl;
std::cout << "[t-moTSExplorer] => START" << std::endl;
//instansiation
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
bitNeighborhood emptyNH(0);
evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp;
moSolNeighborComparator<bitNeighbor> sncomp;
moDummyIntensification<bitNeighbor> intens;
moDummyDiversification<bitNeighbor> diver;
moSolVectorTabuList<bitNeighbor> tabuList(4,0);
moBestImprAspiration<bitNeighbor> aspir;
//instansiation
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
bitNeighborhood emptyNH(0);
evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp;
moSolNeighborComparator<bitNeighbor> sncomp;
moDummyIntensification<bitNeighbor> intens;
moDummyDiversification<bitNeighbor> diver;
moSolVectorTabuList<bitNeighbor> tabuList(4,0);
moBestImprAspiration<bitNeighbor> 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> test(nh, eval, ncomp, sncomp, tabuList, intens, diver, aspir);
moTSExplorer<bitNeighborhood> test2(emptyNH, eval, ncomp, sncomp, tabuList, intens, diver, aspir);
//test d'un voisinage vide
test2.initParam(sol);
test2(sol);
assert(!test2.accept(sol));
//test d'un voisinage vide
test2.initParam(sol);
test2(sol);
assert(!test2.accept(sol));
//test le comportement classique de la taboo
test.initParam(sol);
assert(aspir.getBest()==sol);
//test le comportement classique de la taboo
test.initParam(sol);
assert(aspir.getBest()==sol);
test(sol);
test.updateParam(sol);
assert(aspir.getBest()==sol);
test(sol);
test.updateParam(sol);
assert(aspir.getBest()==sol);
//on ameliore et on stock une sol tabou 0111
test(sol);
test.move(sol);
test.moveApplied(true);
test.updateParam(sol);
assert(aspir.getBest()==sol);
//on ameliore et on stock une sol tabou 0111
test(sol);
test.move(sol);
test.moveApplied(true);
test.updateParam(sol);
assert(aspir.getBest()==sol);
//on ameliore et on stock une autre sol tabou 0011
test(sol);
test.move(sol);
test.moveApplied(true);
test.updateParam(sol);
assert(aspir.getBest()==sol);
//on ameliore et on stock une autre sol tabou 0011
test(sol);
test.move(sol);
test.moveApplied(true);
test.updateParam(sol);
assert(aspir.getBest()==sol);
//pareil on stock 0001 met pdt la recherche on se rend compte que 0111 est tabou
test(sol);
test.move(sol);
test.moveApplied(true);
test.updateParam(sol);
assert(aspir.getBest()==sol);
//pareil on stock 0001 met pdt la recherche on se rend compte que 0111 est tabou
test(sol);
test.move(sol);
test.moveApplied(true);
test.updateParam(sol);
assert(aspir.getBest()==sol);
//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
sol[0]=true;
std::cout << sol << std::endl;
sol.fitness(2);
test(sol);
test.move(sol);
test.moveApplied(true);
test.updateParam(sol);
assert( sol[0] && !sol[1] && !sol[2] && !sol[3]);
sol[0]=false;
sol[3]=true;
assert(aspir.getBest()==sol);
//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
sol[0]=true;
std::cout << sol << std::endl;
sol.fitness(2);
test(sol);
test.move(sol);
test.moveApplied(true);
test.updateParam(sol);
assert( sol[0] && !sol[1] && !sol[2] && !sol[3]);
sol[0]=false;
sol[3]=true;
assert(aspir.getBest()==sol);
//test du isContinue
assert(test.isContinue(sol));
//test du isContinue
assert(test.isContinue(sol));
//test du terminate
test.initParam(sol);
sol[0]=true;
sol[1]=true;
sol[2]=true;
sol[3]=true;
sol.fitness(4);
test(sol);
test.move(sol);
test.moveApplied(true);
test.updateParam(sol);
assert( !sol[0] && sol[1] && sol[2] && sol[3]);
test.terminate(sol);
assert( !sol[0] && !sol[1] && !sol[2] && sol[3]);
//test du terminate
test.initParam(sol);
sol[0]=true;
sol[1]=true;
sol[2]=true;
sol[3]=true;
sol.fitness(4);
test(sol);
test.move(sol);
test.moveApplied(true);
test.updateParam(sol);
assert( !sol[0] && sol[1] && sol[2] && sol[3]);
test.terminate(sol);
assert( !sol[0] && !sol[1] && !sol[2] && sol[3]);
//test pour avoir que des mouvement taboo
eoBit<eoMinimizingFitness> sol2(2, true);
sol2.fitness(2);
bitNeighborhood nh2(2);
evalOneMax eval2(2);
//test pour avoir que des mouvement taboo
eoBit<eoMinimizingFitness> sol2(2, true);
sol2.fitness(2);
bitNeighborhood nh2(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(sol2);
test3.move(sol2);
test3.moveApplied(true);
test3.updateParam(sol2);
test3.initParam(sol2);
test3(sol2);
test3.move(sol2);
test3.moveApplied(true);
test3.updateParam(sol2);
test3(sol2);
test3.move(sol2);
test3.moveApplied(true);
test3.updateParam(sol2);
test3(sol2);
test3.move(sol2);
test3.moveApplied(true);
test3.updateParam(sol2);
test3(sol2);
test3.move(sol2);
test3.moveApplied(true);
test3.updateParam(sol2);
test3(sol2);
test3.move(sol2);
test3.moveApplied(true);
test3.updateParam(sol2);
test3(sol2);
test3.move(sol2);
test3.moveApplied(true);
test3.updateParam(sol2);
test3(sol2);
test3.move(sol2);
test3.moveApplied(true);
test3.updateParam(sol2);
//on a rempli la liste tabu pour que tout les voisins soit tabu
test3(sol2);
assert(!test3.accept(sol2));
//on a rempli la liste tabu pour que tout les voisins soit tabu
test3(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>
int main(){
int main() {
std::cout << "[t-moTrueContinuator] => START" << std::endl;
std::cout << "[t-moTrueContinuator] => START" << std::endl;
moTrueContinuator<moDummyNeighborhood> test;
Solution s;
moTrueContinuator<moDummyNeighborhood> test;
Solution s;
assert(test(s));
assert(test(s));
std::cout << "[t-moTrueContinuator] => OK" << std::endl;
return EXIT_SUCCESS;
std::cout << "[t-moTrueContinuator] => OK" << std::endl;
return EXIT_SUCCESS;
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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