passage du code dans astyle

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

View file

@ -49,7 +49,7 @@ public:
typedef NHE NeighborhoodExplorer ;
typedef typename NeighborhoodExplorer::EOT EOT ;
typedef typename NeighborhoodExplorer::Neighborhood Neighborhood ;
/**
* Constructor of a moLocalSearch needs a NeighborhooExplorer and a Continuator
@ -61,40 +61,40 @@ public:
* @param _solution the related solution
*/
virtual bool operator() (EOT & _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 external continuator (for example the time, or the number of generations)
continuator.init(_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);
// update the parameter of the search (for ex. Temperature of the SA)
searchExplorer.updateParam(_solution);
b=continuator(_solution);
} while (b && searchExplorer.isContinue(_solution));
searchExplorer.terminate(_solution);
continuator.lastCall(_solution);
return true;
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 external continuator (for example the time, or the number of generations)
continuator.init(_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);
// update the parameter of the search (for ex. Temperature of the SA)
searchExplorer.updateParam(_solution);
b=continuator(_solution);
} while (b && searchExplorer.isContinue(_solution));
searchExplorer.terminate(_solution);
continuator.lastCall(_solution);
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){}
/**
* 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"; }
/**
* 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();
}
/**
* @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){}
/**
* Set the worst fitness in the neighborhood
* @param _sol the corresponding solution
*/
virtual void operator()(EOT & _sol){
value() = nhStat.getMin();
}
/**
* Default Constructor
* @param _nhStat a neighborhoodStat
*/
moMinNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat):
moStat<EOT, Fitness>(Fitness(), "min"), nhStat(_nhStat) {}
/**
* @return the class name
*/
virtual std::string className(void) const { return "moMinNeighborStat"; }
/**
* 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";
}
private:
/** moNeighborhoodStat */
moNeighborhoodStat<Neighborhood> & nhStat;
/** moNeighborhoodStat */
moNeighborhoodStat<Neighborhood> & nhStat;
};
#endif

View file

@ -40,42 +40,44 @@
/**
*
* From moNeighborhoodStat, to compute the number of solutions in the neighborhood
* From moNeighborhoodStat, to compute the number of solutions in the neighborhood
* with (strictly) lower fitness than the current solution
*
*
*/
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){}
/**
* 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();
}
/**
* Default Constructor
* @param _nhStat a neighborhoodStat
*/
moNbInfNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat):
moStat<EOT, unsigned>(0, "nb inf"), nhStat(_nhStat) {}
/**
* @return the class name
*/
virtual std::string className(void) const { return "moNbInfNeighborStat"; }
/**
* 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";
}
private:
/** moNeighborhoodStat */
moNeighborhoodStat<Neighborhood> & nhStat;
/** moNeighborhoodStat */
moNeighborhoodStat<Neighborhood> & nhStat;
};
#endif

View file

@ -40,42 +40,44 @@
/**
*
* From moNeighborhoodStat, to compute the number of solutions in the neighborhood
* From moNeighborhoodStat, to compute the number of solutions in the neighborhood
* with higher fitness than the current solution
*
*
*/
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){}
/**
* 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"; }
/**
* 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();
}
/**
* @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);
// init the statistics
value() = true;
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, current);
mean = current.fitness();
sd = mean * mean;
nb = 1;
nbInf = 0;
nbEqual = 0;
nbSup = 0;
// init the statistics
value() = true;
if (solNeighborComparator.equals(_solution, current))
nbEqual++;
else if (solNeighborComparator(_solution, current))
nbSup++;
else
nbInf++;
mean = current.fitness();
sd = mean * mean;
nb = 1;
nbInf = 0;
nbEqual = 0;
nbSup = 0;
//initialize the best neighbor
best = current;
lowest = current;
if (solNeighborComparator.equals(_solution, current))
nbEqual++;
else if (solNeighborComparator(_solution, current))
nbSup++;
else
nbInf++;
//test all others neighbors
while (neighborhood.cont(_solution)) {
//next neighbor
neighborhood.next(_solution, current);
//eval
eval(_solution, current);
//initialize the best neighbor
best = current;
lowest = current;
mean += current.fitness();
sd += current.fitness() * current.fitness();
nb++;
if (solNeighborComparator.equals(_solution, current))
nbEqual++;
else if (solNeighborComparator(_solution, current))
nbSup++;
else
nbInf++;
//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;
if (neighborComparator(current, lowest))
lowest = current;
}
mean += current.fitness();
sd += current.fitness() * current.fitness();
nb++;
max = best.fitness();
min = lowest.fitness();
if (solNeighborComparator.equals(_solution, current))
nbEqual++;
else if (solNeighborComparator(_solution, current))
nbSup++;
else
nbInf++;
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;
}
}
//if we found a better neighbor, update the best
if (neighborComparator(best, current))
best = current;
/**
* @return the worst fitness value found in the neighborhood
*/
Fitness getMin(){
return min;
}
if (neighborComparator(current, lowest))
lowest = current;
}
/**
* @return the best fitness value found in the neighborhood
*/
Fitness getMax(){
return max;
}
max = best.fitness();
min = lowest.fitness();
/**
* @return the mean fitness value of the neighborhood
*/
double getMean(){
return mean;
}
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 standard deviation value of the neighborhood
*/
double getSD(){
return sd;
}
/**
* @return the worst fitness value found in the neighborhood
*/
Fitness getMin() {
return min;
}
/**
* @return the size of the neighborhood
*/
unsigned getSize(){
return nb;
}
/**
* @return the best fitness value found in the neighborhood
*/
Fitness getMax() {
return max;
}
/**
* @return the number of neighbors having a better fitness than the current solution
*/
unsigned getNbSup(){
return nbSup;
}
/**
* @return the mean fitness value of the neighborhood
*/
double getMean() {
return mean;
}
/**
* @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 standard deviation value of the neighborhood
*/
double getSD() {
return sd;
}
/**
* @return the class name
*/
virtual std::string className(void) const {
return "moNeighborhoodStat";
}
/**
* @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 the same fitness than the current solution
*/
unsigned getNbEqual() {
return nbEqual;
}
/**
* @return the number of neighbors having a worst fitness than the current solution
*/
unsigned getNbInf() {
return nbInf;
}
/**
* @return the class name
*/
virtual std::string className(void) const {
return "moNeighborhoodStat";
}
private:
// 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

@ -40,41 +40,43 @@
/**
* From moNeighborhoodStat, to compute the neutral degree of the solution
* which is the number of solutions in the neighborhood
* with equals fitness
* which is the number of solutions in the neighborhood
* with equals fitness
*/
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){}
/**
* 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"; }
/**
* 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();
}
/**
* @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){}
/**
* 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"; }
/**
* 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();
}
/**
* @return the class name
*/
virtual std::string className(void) const {
return "moSecondMomentNeighborStat";
}
private:
/** moNeighborhoodStat */
moNeighborhoodStat<Neighborhood> & nhStat;
/** moNeighborhoodStat */
moNeighborhoodStat<Neighborhood> & nhStat;
};
#endif

View file

@ -40,40 +40,42 @@
/**
* From moNeighborhoodStat, to compute the number of solutions in the neighborhood
*
*
*/
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){}
/**
* 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"; }
/**
* 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();
}
/**
* @return the class name
*/
virtual std::string className(void) const {
return "moSizeNeighborStat";
}
private:
/** moNeighborhoodStat */
moNeighborhoodStat<Neighborhood> & nhStat;
/** moNeighborhoodStat */
moNeighborhoodStat<Neighborhood> & nhStat;
};
#endif

View file

@ -40,7 +40,7 @@
/**
* The statistic which only give the current solution
* be careful, the solution is given by copy
*
*
*/
template <class EOT>
class moSolutionStat : public moStat<EOT, EOT>
@ -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);
step++;
/**
* one more step
*/
virtual void updateParam(EOT & solution) {
moSimpleHCneutralExplorer<Neighborhood>::updateParam(solution);
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));
//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;
}
};
//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(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,30 +47,30 @@ 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();
}
/**
* Assignment operator
* @param _neighbor the neighbor to assign
* @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);
}
/**
* Move a solution
* @param _solution the related solution
@ -82,32 +82,34 @@ public:
* @return fitness of the neighbor
*/
const Fitness fitness() const {
return repFitness;
return repFitness;
}
/**
* Get fitness as reference, useful when fitness is set in a multi-stage way, e.g., MOFitness gets performance information, is subsequently ranked
* @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.
* Calls base class, just in case that one had something to do.
@ -116,7 +118,7 @@ public:
* @param _is a std::istream.
*/
virtual void readFrom(std::istream& _is) {
_is >> repFitness;
_is >> repFitness;
}
/**
@ -124,9 +126,9 @@ public:
* @param _os A std::ostream.
*/
virtual void printOn(std::ostream& _os) const {
_os << repFitness << std::endl;
_os << repFitness << std::endl;
}
protected:
// minimal information on the neighbor : fitness
Fitness repFitness ;

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,31 +96,31 @@ 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--;
}
/**
* test if all neighbors are explore or not,if false, there is no neighbor left to explore
* maxIndex is number of neighbors
* maxIndex is number of neighbors
* @param _solution the solution to explore
* @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

@ -2,20 +2,20 @@
<moMove.h>
Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
(C) OPAC Team, LIFL, 2002-2008
Sébastien Cahon, Jean-Charles Boisson (Jean-Charles.Boisson@lifl.fr)
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
@ -28,10 +28,10 @@
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef _moMove_h
@ -48,10 +48,10 @@
template < class EOT >
class moMove:public eoUF < EOT &, void >
{
public:
// Alias for the type
typedef EOT EOType;
public:
// 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

@ -2,20 +2,20 @@
<moMoveInit.h>
Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
(C) OPAC Team, LIFL, 2002-2008
Sébastien Cahon, Jean-Charles Boisson (Jean-Charles.Boisson@lifl.fr)
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
@ -28,7 +28,7 @@
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
@ -45,6 +45,6 @@
*/
template < class M >
class moMoveInit:public eoBF < M &, const typename M::EOType &, void >
{};
{};
#endif

View file

@ -12,58 +12,60 @@
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;
}
private:
M* move;
};
#endif

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

@ -2,20 +2,20 @@
<moNextMove.h>
Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
(C) OPAC Team, LIFL, 2002-2008
Sébastien Cahon, Jean-Charles Boisson (Jean-Charles.Boisson@lifl.fr)
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
@ -28,7 +28,7 @@
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
@ -43,8 +43,8 @@
* Useful for the explorer (for moTS or moHC).
* Does nothing... An object that herits from this class needs to be designed for being used.
*/
template < class M >
template < class M >
class moNextMove:public eoBF < M &, const typename M::EOType &, bool >
{};
{};
#endif