Passage du code dans un pretty printer

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1813 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-05-17 14:56:42 +00:00
commit 3d8057ac4d
88 changed files with 2726 additions and 2720 deletions

View file

@ -38,44 +38,44 @@
#include <continuator/moStat.h>
/**
* The statistic which save the best solution found during the search
* The statistic which save the best solution found during the search
*/
template <class EOT>
class moBestSoFarStat : public moStat<EOT, EOT&>
{
public :
using moStat< EOT , EOT& >::value;
/**
* Default Constructor
*/
moBestSoFarStat(): moStat<EOT, EOT&>(EOT(), "best") {
}
/**
* Initialization of the best solution on the first one
* @param _sol the first solution
*/
virtual void init(EOT & _sol) {
value() = _sol;
}
/**
* Update the best solution
* @param _sol the current solution
*/
virtual void operator()(EOT & _sol) {
if (value().fitness() < _sol.fitness())
value() = _sol;
}
/**
* @return name of the class
*/
virtual std::string className(void) const {
return "moBestSoFarStat";
}
using moStat< EOT , EOT& >::value;
/**
* Default Constructor
*/
moBestSoFarStat(): moStat<EOT, EOT&>(EOT(), "best") {
}
/**
* Initialization of the best solution on the first one
* @param _sol the first solution
*/
virtual void init(EOT & _sol) {
value() = _sol;
}
/**
* Update the best solution
* @param _sol the current solution
*/
virtual void operator()(EOT & _sol) {
if (value().fitness() < _sol.fitness())
value() = _sol;
}
/**
* @return name of the class
*/
virtual std::string className(void) const {
return "moBestSoFarStat";
}
};
#endif

View file

@ -42,52 +42,52 @@ template< class Neighbor >
class moCombinedContinuator : public moContinuator<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
typedef typename Neighbor::EOT EOT ;
/**
* Default constructor (moCheckpoint must have at least one continuator)
* @param _cont a continuator
*/
moCombinedContinuator(moContinuator<Neighbor>& _cont) {
continuators.push_back(&_cont);
}
/**
* Default constructor (moCheckpoint must have at least one continuator)
* @param _cont a continuator
*/
moCombinedContinuator(moContinuator<Neighbor>& _cont) {
continuators.push_back(&_cont);
}
/**
* add a continuator to the combined continuator
* @param _cont a continuator
*/
void add(moContinuator<Neighbor>& _cont) {
continuators.push_back(&_cont);
}
/**
* init all continuators
* @param _solution a solution
*/
virtual void init(EOT & _solution) {
for(unsigned int i = 0; i < continuators.size(); ++i)
continuators[i]->init(_solution);
}
/**
* add a continuator to the combined continuator
* @param _cont a continuator
*/
void add(moContinuator<Neighbor>& _cont) {
continuators.push_back(&_cont);
}
/**
*@param _solution a solution
*@return true all the continuators are true
*/
virtual bool operator()(EOT & _solution) {
bool bContinue = true;
/**
* init all continuators
* @param _solution a solution
*/
virtual void init(EOT & _solution) {
for (unsigned int i = 0; i < continuators.size(); ++i)
continuators[i]->init(_solution);
}
/**
*@param _solution a solution
*@return true all the continuators are true
*/
virtual bool operator()(EOT & _solution) {
bool bContinue = true;
// some data may be update in each continuator.
// So, all continuators are tested
for (unsigned int i = 0; i < continuators.size(); ++i)
if ( !(*continuators[i])(_solution) )
bContinue = false;
return bContinue;
}
// some data may be update in each continuator.
// So, all continuators are tested
for(unsigned int i = 0; i < continuators.size(); ++i)
if ( !(*continuators[i])(_solution) )
bContinue = false;
return bContinue;
}
private:
/** continuators vector */
std::vector< moContinuator<Neighbor>* > continuators;
/** continuators vector */
std::vector< moContinuator<Neighbor>* > continuators;
};
#endif

View file

@ -44,37 +44,37 @@ template <class EOT>
class moCounterStat : public moStat<EOT, unsigned int>
{
public :
using moStat< EOT, unsigned int>::value;
/**
* Default Constructor
*/
moCounterStat(): moStat<EOT, unsigned int>(0, "counter") {
}
/**
* Give the number of iteration
* @param _sol a solution
*/
virtual void init(EOT & _sol) {
value() = 0;
}
/**
* Give the number of iteration
* @param _sol a solution
*/
virtual void operator()(EOT & _sol) {
value() = value() + 1;
}
/**
* @return name of the class
*/
virtual std::string className(void) const {
return "moCounterStat";
}
using moStat< EOT, unsigned int>::value;
/**
* Default Constructor
*/
moCounterStat(): moStat<EOT, unsigned int>(0, "counter") {
}
/**
* Give the number of iteration
* @param _sol a solution
*/
virtual void init(EOT & _sol) {
value() = 0;
}
/**
* Give the number of iteration
* @param _sol a solution
*/
virtual void operator()(EOT & _sol) {
value() = value() + 1;
}
/**
* @return name of the class
*/
virtual std::string className(void) const {
return "moCounterStat";
}
};
#endif

View file

@ -60,9 +60,9 @@ public :
* Compute distance between the first solution and the reference solution
* @param _sol the first solution
*/
virtual void init(EOT & _sol) {
value() = dist(_sol, refSolution);
}
virtual void init(EOT & _sol) {
value() = dist(_sol, refSolution);
}
/**
* Compute distance between a solution and the reference solution

View file

@ -40,24 +40,24 @@ template< class Neighbor >
class moFitContinuator : public moContinuator<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
typedef typename EOT::Fitness Fitness ;
typedef typename Neighbor::EOT EOT ;
typedef typename EOT::Fitness Fitness ;
/**
* @param _maxFit maximum fitness to reach
*/
moFitContinuator(Fitness _maxFit): maxFit(_maxFit) {}
/**
*@param _solution a solution
*@return true if counter < maxFit
*/
virtual bool operator()(EOT & _solution) {
return (_solution.fitness() < maxFit);
}
/**
* @param _maxFit maximum fitness to reach
*/
moFitContinuator(Fitness _maxFit): maxFit(_maxFit){}
/**
*@param _solution a solution
*@return true if counter < maxFit
*/
virtual bool operator()(EOT & _solution) {
return (_solution.fitness() < maxFit);
}
private:
Fitness maxFit;
Fitness maxFit;
};
#endif

View file

@ -44,40 +44,40 @@ template <class EOT>
class moFitnessStat : public moStat<EOT, typename EOT::Fitness>
{
public :
typedef typename EOT::Fitness Fitness;
using moStat< EOT, Fitness >::value;
typedef typename EOT::Fitness Fitness;
using moStat< EOT, Fitness >::value;
/**
* Default Constructor
* @param _description a description of the stat
*/
moFitnessStat(std::string _description = "fitness"):
moStat<EOT, Fitness>(Fitness(), _description) {}
/**
* store the initial fitness value
* @param _sol the initial solution
*/
virtual void init(EOT & _sol)
{
value() = _sol.fitness();
}
/**
* store fitness value
* @param _sol the corresponding solution
*/
virtual void operator()(EOT & _sol)
{
value() = _sol.fitness();
}
/**
* @return the name of the class
*/
virtual std::string className(void) const {
return "moFitnessStat";
}
/**
* Default Constructor
* @param _description a description of the stat
*/
moFitnessStat(std::string _description = "fitness"):
moStat<EOT, Fitness>(Fitness(), _description) {}
/**
* store the initial fitness value
* @param _sol the initial solution
*/
virtual void init(EOT & _sol)
{
value() = _sol.fitness();
}
/**
* store fitness value
* @param _sol the corresponding solution
*/
virtual void operator()(EOT & _sol)
{
value() = _sol.fitness();
}
/**
* @return the name of the class
*/
virtual std::string className(void) const {
return "moFitnessStat";
}
};
#endif

View file

@ -37,53 +37,53 @@ Contact: paradiseo-help@lists.gforge.inria.fr
/**
* Continue until a maximum fixed number of full evaluation is reached
*
* Becareful 1: The number of full evaluations considered is within the local search (not before it)
* Becareful 1: The number of full evaluations considered is within the local search (not before it)
* Becareful 2: Can not be used if the evaluation function is used in parallel
*/
template< class Neighbor >
class moFullEvalContinuator : public moContinuator<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
typedef typename Neighbor::EOT EOT ;
/**
* Default constructor
* @param _eval evaluation function to count
* @param _maxFullEval number maximum of iterations
*/
moFullEvalContinuator(eoEvalFuncCounter<EOT> & _eval, unsigned int _maxFullEval): eval(_eval), maxFullEval(_maxFullEval) {
nbEval_start = eval.value();
}
/**
* Test if continue
* @param _solution a solution
* @return true if number of evaluations < maxFullEval
*/
virtual bool operator()(EOT & _solution) {
return (eval.value() - nbEval_start < maxFullEval);
}
/**
* Reset the number of evaluations
* @param _solution a solution
*/
virtual void init(EOT & _solution) {
nbEval_start = eval.value();
}
/**
* Default constructor
* @param _eval evaluation function to count
* @param _maxFullEval number maximum of iterations
*/
moFullEvalContinuator(eoEvalFuncCounter<EOT> & _eval, unsigned int _maxFullEval): eval(_eval), maxFullEval(_maxFullEval) {
nbEval_start = eval.value();
}
/**
* Test if continue
* @param _solution a solution
* @return true if number of evaluations < maxFullEval
*/
virtual bool operator()(EOT & _solution) {
return (eval.value() - nbEval_start < maxFullEval);
}
/**
* Reset the number of evaluations
* @param _solution a solution
*/
virtual void init(EOT & _solution) {
nbEval_start = eval.value();
}
/**
* the current number of evaluation from the begining
* @return the number of evaluation
*/
unsigned int value() {
return eval.value() - nbEval_start ;
return eval.value() - nbEval_start ;
}
private:
eoEvalFuncCounter<EOT> & eval;
unsigned int nbEval_start ;
unsigned int maxFullEval ;
eoEvalFuncCounter<EOT> & eval;
unsigned int nbEval_start ;
unsigned int maxFullEval ;
};
#endif

View file

@ -42,23 +42,23 @@ class moIterContinuator : public moContinuator<Neighbor>
public:
typedef typename Neighbor::EOT EOT ;
/**
* @param _maxIter number maximum of iterations
* @param _verbose true/false : verbose mode on/off
*/
moIterContinuator(unsigned int _maxIter, bool _verbose=true): maxIter(_maxIter), verbose(_verbose){}
/**
* @param _maxIter number maximum of iterations
* @param _verbose true/false : verbose mode on/off
*/
moIterContinuator(unsigned int _maxIter, bool _verbose=true): maxIter(_maxIter), verbose(_verbose) {}
/**
*@param _solution a solution
*@return true if counter < maxIter
*/
virtual bool operator()(EOT & _solution) {
bool res;
cpt++;
res = (cpt < maxIter);
if(!res && verbose)
std::cout << "STOP in moIterContinuator: Reached maximum number of iterations [" << cpt << "/" << maxIter << "]" << std::endl;
return res;
bool res;
cpt++;
res = (cpt < maxIter);
if (!res && verbose)
std::cout << "STOP in moIterContinuator: Reached maximum number of iterations [" << cpt << "/" << maxIter << "]" << std::endl;
return res;
}
/**
@ -66,7 +66,7 @@ public:
* @param _solution a solution
*/
virtual void init(EOT & _solution) {
cpt = 0;
cpt = 0;
}
/**
@ -74,7 +74,7 @@ public:
* @return the number of iteration
*/
unsigned int value() {
return cpt ;
return cpt ;
}
private:

View file

@ -45,46 +45,46 @@ template <class EOT>
class moMinusOneCounterStat : public moStat<EOT, unsigned int>
{
public :
using moStat< EOT, unsigned int>::value;
/**
* Default Constructor
*/
moMinusOneCounterStat(): moStat<EOT, unsigned int>(0, "counter") {
counter = 0;
}
/**
* Give the number of iteration
* @param _sol a solution
*/
virtual void init(EOT & _sol) {
counter = 0;
value() = 0;
}
/**
* Give the number of iteration
* @param _sol a solution
*/
virtual void operator()(EOT & _sol) {
counter++;
if (counter > 0)
value() = counter - 1;
else
value() = 0;
}
/**
* @return name of the class
*/
virtual std::string className(void) const {
return "moMinusOneCounterStat";
}
using moStat< EOT, unsigned int>::value;
/**
* Default Constructor
*/
moMinusOneCounterStat(): moStat<EOT, unsigned int>(0, "counter") {
counter = 0;
}
/**
* Give the number of iteration
* @param _sol a solution
*/
virtual void init(EOT & _sol) {
counter = 0;
value() = 0;
}
/**
* Give the number of iteration
* @param _sol a solution
*/
virtual void operator()(EOT & _sol) {
counter++;
if (counter > 0)
value() = counter - 1;
else
value() = 0;
}
/**
* @return name of the class
*/
virtual std::string className(void) const {
return "moMinusOneCounterStat";
}
private:
unsigned int counter;
unsigned int counter;
};
#endif

View file

@ -63,12 +63,12 @@ public :
* @param _solNeighborComparator a comparator between a solution and a neighbor
* @param _k number of neighbors visited
*/
moNeighborBestStat(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator, unsigned int _k = 0):
moStat<EOT, Fitness>(true, "neighborhood"),
neighborhood(_neighborhood), eval(_eval),
neighborComparator(_neighborComparator),
solNeighborComparator(_solNeighborComparator),
kmax(_k)
moNeighborBestStat(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator, unsigned int _k = 0):
moStat<EOT, Fitness>(true, "neighborhood"),
neighborhood(_neighborhood), eval(_eval),
neighborComparator(_neighborComparator),
solNeighborComparator(_solNeighborComparator),
kmax(_k)
{}
/**
@ -79,12 +79,12 @@ public :
* @param _eval an evaluation function
* @param _k number of neighbors visited (default all)
*/
moNeighborBestStat(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, unsigned _k = 0):
moStat<EOT, Fitness>(Fitness(), "best"),
neighborhood(_neighborhood), eval(_eval),
neighborComparator(defaultNeighborComp),
solNeighborComparator(defaultSolNeighborComp),
kmax(_k)
moNeighborBestStat(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, unsigned _k = 0):
moStat<EOT, Fitness>(Fitness(), "best"),
neighborhood(_neighborhood), eval(_eval),
neighborComparator(defaultNeighborComp),
solNeighborComparator(defaultSolNeighborComp),
kmax(_k)
{}
/**
@ -92,7 +92,7 @@ public :
* @param _solution the first solution
*/
virtual void init(EOT & _solution) {
operator()(_solution);
operator()(_solution);
}
/**
@ -113,8 +113,8 @@ public :
//initialize the best neighbor
best = current;
// number of visited neighbors
unsigned int k = 1;
// number of visited neighbors
unsigned int k = 1;
//test all others neighbors
while ( ( (kmax == 0) || (k < kmax) ) && neighborhood.cont(_solution)) {
@ -127,14 +127,14 @@ public :
if (neighborComparator(best, current))
best = current;
k++;
k++;
}
value() = best.fitness();
}
else {
//if _solution hasn't neighbor,
value() = Fitness();
value() = Fitness();
}
}
@ -146,22 +146,22 @@ public :
}
private:
// to explore the neighborhood
Neighborhood& neighborhood ;
moEval<Neighbor>& eval;
// comparator betwenn solution and neighbor or between neighbors
moNeighborComparator<Neighbor>& neighborComparator;
moSolNeighborComparator<Neighbor>& solNeighborComparator;
// default comparators
// compare the fitness values of neighbors: true is strictly greater
moNeighborComparator<Neighbor> defaultNeighborComp;
// compare the fitness values of the solution and the neighbor: true if strictly greater
moSolNeighborComparator<Neighbor> defaultSolNeighborComp;
// number of neighbor to explore
unsigned int kmax;
// to explore the neighborhood
Neighborhood& neighborhood ;
moEval<Neighbor>& eval;
// comparator betwenn solution and neighbor or between neighbors
moNeighborComparator<Neighbor>& neighborComparator;
moSolNeighborComparator<Neighbor>& solNeighborComparator;
// default comparators
// compare the fitness values of neighbors: true is strictly greater
moNeighborComparator<Neighbor> defaultNeighborComp;
// compare the fitness values of the solution and the neighbor: true if strictly greater
moSolNeighborComparator<Neighbor> defaultSolNeighborComp;
// number of neighbor to explore
unsigned int kmax;
};
#endif

View file

@ -37,7 +37,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
/**
* Continue until a maximum fixed number of neighbor evaluation is reached
*
* Becareful 1: The number of full evaluations considered is within the local search (not before it)
* Becareful 1: The number of full evaluations considered is within the local search (not before it)
* Becareful 2: Can not be used if the evaluation function is used in parallel
*/
template< class Neighbor >
@ -46,42 +46,42 @@ class moNeighborEvalContinuator : public moContinuator<Neighbor>
public:
typedef typename Neighbor::EOT EOT ;
/**
* Default constructor
* @param _eval neighbor evaluation function to count
* @param _maxNeighborEval number maximum of iterations
*/
moNeighborEvalContinuator(moEvalCounter<Neighbor> & _eval, unsigned int _maxNeighborEval): eval(_eval), maxNeighborEval(_maxNeighborEval){}
/**
* Default constructor
* @param _eval neighbor evaluation function to count
* @param _maxNeighborEval number maximum of iterations
*/
moNeighborEvalContinuator(moEvalCounter<Neighbor> & _eval, unsigned int _maxNeighborEval): eval(_eval), maxNeighborEval(_maxNeighborEval) {}
/**
* Test if continue
* @param _solution a solution
* @return true if number of evaluations < maxNeighborEval
*/
virtual bool operator()(EOT & _solution) {
return (eval.value() - nbEval_start < maxNeighborEval);
}
/**
* Reset the number of evaluations
* @param _solution a solution
*/
virtual void init(EOT & _solution) {
nbEval_start = eval.value();
}
/**
* the current number of evaluation from the begining
* @return the number of evaluation
*/
unsigned int value() {
return eval.value() - nbEval_start ;
}
/**
* Test if continue
* @param _solution a solution
* @return true if number of evaluations < maxNeighborEval
*/
virtual bool operator()(EOT & _solution) {
return (eval.value() - nbEval_start < maxNeighborEval);
}
/**
* Reset the number of evaluations
* @param _solution a solution
*/
virtual void init(EOT & _solution) {
nbEval_start = eval.value();
}
/**
* the current number of evaluation from the begining
* @return the number of evaluation
*/
unsigned int value() {
return eval.value() - nbEval_start ;
}
private:
moEvalCounter<Neighbor> & eval;
unsigned int maxNeighborEval;
unsigned int nbEval_start ;
moEvalCounter<Neighbor> & eval;
unsigned int maxNeighborEval;
unsigned int nbEval_start ;
};
#endif

View file

@ -46,67 +46,67 @@ template< class Neighbor >
class moNeighborFitnessStat : public moStat<typename Neighbor::EOT, typename Neighbor::EOT::Fitness>
{
public :
typedef typename Neighbor::EOT EOT ;
typedef moNeighborhood<Neighbor> Neighborhood ;
typedef typename EOT::Fitness Fitness ;
typedef typename Neighbor::EOT EOT ;
typedef moNeighborhood<Neighbor> Neighborhood ;
typedef typename EOT::Fitness Fitness ;
using moStat< EOT, Fitness >::value;
using moStat< EOT, Fitness >::value;
/**
* Default Constructor
* @param _neighborhood a neighborhood
* @param _eval an evaluation function
*/
moNeighborFitnessStat(Neighborhood& _neighborhood, moEval<Neighbor>& _eval):
moStat<EOT, Fitness>(Fitness(), "neighborhood"),
neighborhood(_neighborhood), eval(_eval)
{
if (!neighborhood.isRandom()) {
std::cout << "moNeighborFitnessStat::Warning -> the neighborhood used is not random, the neighbor will not be random" << std::endl;
}
}
/**
* Compute the fitness of one random neighbor
* @param _solution the first solution
*/
virtual void init(EOT & _solution) {
operator()(_solution);
}
/**
* Compute the fitness of one random neighbor
* @param _solution the corresponding solution
*/
virtual void operator()(EOT & _solution) {
if (neighborhood.hasNeighbor(_solution)) {
Neighbor current ;
//init the first neighbor which is suppoed to be random
neighborhood.init(_solution, current);
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, current);
// the fitness value is collected
value() = current.fitness();
} else {
//if _solution hasn't neighbor,
value() = Fitness();
/**
* Default Constructor
* @param _neighborhood a neighborhood
* @param _eval an evaluation function
*/
moNeighborFitnessStat(Neighborhood& _neighborhood, moEval<Neighbor>& _eval):
moStat<EOT, Fitness>(Fitness(), "neighborhood"),
neighborhood(_neighborhood), eval(_eval)
{
if (!neighborhood.isRandom()) {
std::cout << "moNeighborFitnessStat::Warning -> the neighborhood used is not random, the neighbor will not be random" << std::endl;
}
}
}
/**
* @return the class name
*/
virtual std::string className(void) const {
return "moNeighborFitnessStat";
}
/**
* Compute the fitness of one random neighbor
* @param _solution the first solution
*/
virtual void init(EOT & _solution) {
operator()(_solution);
}
/**
* Compute the fitness of one random neighbor
* @param _solution the corresponding solution
*/
virtual void operator()(EOT & _solution) {
if (neighborhood.hasNeighbor(_solution)) {
Neighbor current ;
//init the first neighbor which is suppoed to be random
neighborhood.init(_solution, current);
//eval the _solution moved with the neighbor and stock the result in the neighbor
eval(_solution, current);
// the fitness value is collected
value() = current.fitness();
} else {
//if _solution hasn't neighbor,
value() = Fitness();
}
}
/**
* @return the class name
*/
virtual std::string className(void) const {
return "moNeighborFitnessStat";
}
private:
// to explore the neighborhood
Neighborhood& neighborhood ;
moEval<Neighbor>& eval;
// to explore the neighborhood
Neighborhood& neighborhood ;
moEval<Neighbor>& eval;
};

View file

@ -89,7 +89,7 @@ public :
* @param _solution the first solution
*/
virtual void init(EOT & _solution) {
operator()(_solution);
operator()(_solution);
}
/**
@ -246,7 +246,7 @@ private:
// default comparators
// compare the fitness values of neighbors: true is strictly greater
moNeighborComparator<Neighbor> defaultNeighborComp;
// compare the fitness values of the solution and the neighbor: true if strictly greater
// compare the fitness values of the solution and the neighbor: true if strictly greater
moSolNeighborComparator<Neighbor> defaultSolNeighborComp;
// the stastics of the fitness

View file

@ -54,7 +54,7 @@ public:
/**
* first call of a statistical operator
*/
virtual void init(EOT &){}
virtual void init(EOT &) {}
};

View file

@ -44,40 +44,40 @@ template <class EOT, class T>
class moStatFromStat : public moStat<EOT, T>
{
public :
using moStat< EOT , T >::value;
/**
* Default Constructor
* @param _stat a stat
*/
moStatFromStat(moStat<EOT,T> & _stat): moStat<EOT, T>(0, _stat.description()), stat(_stat) {
}
/**
* The value of this stat is a copy of the value of the initial stat
* @param _sol a solution
*/
virtual void init(EOT & _sol) {
value() = stat.value();
}
/**
* The value of this stat is a copy of the value of the initial stat
* @param _sol a solution
*/
virtual void operator()(EOT & _sol) {
value() = stat.value();
}
/**
* @return name of the class
*/
virtual std::string className(void) const {
return "moStatFromStat";
}
using moStat< EOT , T >::value;
/**
* Default Constructor
* @param _stat a stat
*/
moStatFromStat(moStat<EOT,T> & _stat): moStat<EOT, T>(0, _stat.description()), stat(_stat) {
}
/**
* The value of this stat is a copy of the value of the initial stat
* @param _sol a solution
*/
virtual void init(EOT & _sol) {
value() = stat.value();
}
/**
* The value of this stat is a copy of the value of the initial stat
* @param _sol a solution
*/
virtual void operator()(EOT & _sol) {
value() = stat.value();
}
/**
* @return name of the class
*/
virtual std::string className(void) const {
return "moStatFromStat";
}
private:
moStat<EOT, T> & stat;
moStat<EOT, T> & stat;
};
#endif

View file

@ -40,14 +40,14 @@ class moTimeContinuator: public moContinuator<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT;
typedef typename Neighbor::EOT EOT;
/**
* Ctor.
* @param _max maximum running time$
* @param _verbose verbose mode true/false -> on/off
*/
moTimeContinuator(time_t _max, bool _verbose=true): max(_max), verbose(_verbose){
moTimeContinuator(time_t _max, bool _verbose=true): max(_max), verbose(_verbose) {
start = time(NULL);
}
@ -58,11 +58,11 @@ public:
*/
virtual bool operator() (EOT& _sol)
{
bool res;
bool res;
time_t elapsed = (time_t) difftime(time(NULL), start);
res = (elapsed < max);
if(!res && verbose)
std::cout << "STOP in moTimeContinuator: Reached maximum time [" << elapsed << "/" << max << "]" << std::endl;
if (!res && verbose)
std::cout << "STOP in moTimeContinuator: Reached maximum time [" << elapsed << "/" << max << "]" << std::endl;
return res;
}

View file

@ -42,165 +42,165 @@
/**
* To save the values of the same type (double, unsigned int, or EOT) in a vector
* It is similar to eoFileMonitor
*
*
*/
template <class EOT>
class moVectorMonitor : public eoMonitor
{
public:
/**
* Default Constructor
* @param _param the parameter of type double to save in the vector
*/
moVectorMonitor(eoValueParam<double> & _param) : doubleParam(&_param), intParam(NULL), eotParam(NULL)
{ }
/**
* Default Constructor
* @param _param the parameter of type unsigned int to save in the vector
*/
moVectorMonitor(eoValueParam<unsigned int> & _param) : doubleParam(NULL), intParam(&_param), eotParam(NULL)
{ }
/**
* Default Constructor
* @param _param the parameter of type double to save in the vector
*/
moVectorMonitor(eoValueParam<double> & _param) : doubleParam(&_param), intParam(NULL), eotParam(NULL)
{ }
/**
* Default Constructor
* @param _param the parameter of type EOT to save in the vector
*/
moVectorMonitor(eoValueParam<EOT> & _param) : doubleParam(NULL), intParam(NULL), eotParam(&_param)
{ }
/**
* Default Constructor
* @param _param the parameter of type unsigned int to save in the vector
*/
moVectorMonitor(eoValueParam<unsigned int> & _param) : doubleParam(NULL), intParam(&_param), eotParam(NULL)
{ }
/**
* Default Constructor
* @param _param the parameter of type eoScalarFitness to save in the vector
*/
template <class ScalarType, class Compare>
moVectorMonitor(eoValueParam<eoScalarFitness<ScalarType, Compare> > & _param) : doubleParam( & (eoValueParam<double>&)_param), intParam(NULL), eotParam(NULL)
{ }
/**
* Default Constructor
* @param _param the parameter of type EOT to save in the vector
*/
moVectorMonitor(eoValueParam<EOT> & _param) : doubleParam(NULL), intParam(NULL), eotParam(&_param)
{ }
/**
* Default Constructor
* @param _param unvalid Parameter
*/
template <class T>
moVectorMonitor(eoValueParam<T> & _param) : doubleParam(NULL), intParam(NULL), eotParam(NULL)
{
std::cerr << "Sorry the type can not be in a vector of moVectorMonitor" << std::endl;
}
/**
* Default Constructor
* @param _param the parameter of type eoScalarFitness to save in the vector
*/
template <class ScalarType, class Compare>
moVectorMonitor(eoValueParam<eoScalarFitness<ScalarType, Compare> > & _param) : doubleParam( & (eoValueParam<double>&)_param), intParam(NULL), eotParam(NULL)
{ }
/**
* To test if the value are basic type (double or unsigned int), or EOT type
*
* @return true if the type is a EOT type
*/
bool solutionType() {
return eotParam != NULL;
}
/**
* To "print" the value of the parameter in the vector
*
* @return this monitor (sorry I don't why, but it is like this in EO)
*/
eoMonitor& operator()(void) {
if (doubleParam != NULL)
valueVec.push_back(doubleParam->value());
else
if (intParam != NULL)
valueVec.push_back((double) intParam->value());
else
eotVec.push_back(eotParam->value());
return *this ;
}
/**
* To have all the values
*
* @return the vector of values
*/
const std::vector<double>& getValues() const {
return valueVec;
}
/**
* To have all the solutions
*
* @return the vector of solutions
*/
const std::vector<EOT>& getSolutions() const {
return eotVec;
}
/**
* to get the value out.
* @return the string of the value
*/
std::string getValue(unsigned int i) const {
std::ostringstream os;
if (eotParam == NULL)
os << (valueVec[i]) ;
else
os << (eotVec[i]) ;
return os.str();
}
/**
* clear the vector
*/
void clear() {
valueVec.clear();
eotVec.clear();
}
/**
* number of value
* @return size of the vector
*/
unsigned int size() {
if (eotParam == NULL)
return valueVec.size();
else
return eotVec.size();
}
/**
* to export the vector of values into one file
* @param _filename file name
*/
void fileExport(std::string _filename) {
// create file
std::ofstream os(_filename.c_str());
if (!os) {
std::string str = "moVectorMonitor: Could not open " + _filename;
throw std::runtime_error(str);
/**
* Default Constructor
* @param _param unvalid Parameter
*/
template <class T>
moVectorMonitor(eoValueParam<T> & _param) : doubleParam(NULL), intParam(NULL), eotParam(NULL)
{
std::cerr << "Sorry the type can not be in a vector of moVectorMonitor" << std::endl;
}
/**
* To test if the value are basic type (double or unsigned int), or EOT type
*
* @return true if the type is a EOT type
*/
bool solutionType() {
return eotParam != NULL;
}
/**
* To "print" the value of the parameter in the vector
*
* @return this monitor (sorry I don't why, but it is like this in EO)
*/
eoMonitor& operator()(void) {
if (doubleParam != NULL)
valueVec.push_back(doubleParam->value());
else
if (intParam != NULL)
valueVec.push_back((double) intParam->value());
else
eotVec.push_back(eotParam->value());
return *this ;
}
/**
* To have all the values
*
* @return the vector of values
*/
const std::vector<double>& getValues() const {
return valueVec;
}
/**
* To have all the solutions
*
* @return the vector of solutions
*/
const std::vector<EOT>& getSolutions() const {
return eotVec;
}
/**
* to get the value out.
* @return the string of the value
*/
std::string getValue(unsigned int i) const {
std::ostringstream os;
if (eotParam == NULL)
os << (valueVec[i]) ;
else
os << (eotVec[i]) ;
return os.str();
}
/**
* clear the vector
*/
void clear() {
valueVec.clear();
eotVec.clear();
}
/**
* number of value
* @return size of the vector
*/
unsigned int size() {
if (eotParam == NULL)
return valueVec.size();
else
return eotVec.size();
}
/**
* to export the vector of values into one file
* @param _filename file name
*/
void fileExport(std::string _filename) {
// create file
std::ofstream os(_filename.c_str());
if (!os) {
std::string str = "moVectorMonitor: Could not open " + _filename;
throw std::runtime_error(str);
}
for (unsigned int i = 0; i < size(); i++) {
os << getValue(i);
os << std::endl ;
}
}
/**
* @return name of the class
*/
virtual std::string className(void) const {
return "moVectorMonitor";
}
for(unsigned int i = 0; i < size(); i++) {
os << getValue(i);
os << std::endl ;
}
}
/**
* @return name of the class
*/
virtual std::string className(void) const {
return "moVectorMonitor";
}
protected:
eoValueParam<double> * doubleParam ;
eoValueParam<unsigned int> * intParam ;
eoValueParam<EOT> * eotParam ;
eoValueParam<double> * doubleParam ;
eoValueParam<unsigned int> * intParam ;
eoValueParam<EOT> * eotParam ;
std::vector<double> valueVec;
std::vector<EOT> eotVec;
std::vector<double> valueVec;
std::vector<EOT> eotVec;
};