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

@ -48,51 +48,55 @@ public:
typedef typename Neighbor::EOT EOT;
typedef typename EOT::Fitness Fitness ;
moDummyExplorer(): moNeighborhoodExplorer<Neighbor>() { }
moDummyExplorer(): moNeighborhoodExplorer<Neighbor>() { }
/**
* NOTHING TO DO
* @param _solution a solution (unused)
*/
void initParam (EOT& _solution) { } ;
void initParam (EOT& _solution) { } ;
/**
* NOTHING TO DO
* @param _solution a solution (unused)
*/
void updateParam (EOT& _solution) { } ;
void updateParam (EOT& _solution) { } ;
/**
* NOTHING TO DO
* @param _solution a solution (unused)
* @return always false
*/
bool isContinue(EOT& _solution) { return false; } ;
bool isContinue(EOT& _solution) {
return false;
} ;
/**
* NOTHING TO DO
* @param _solution a solution (unused)
*/
void move(EOT& _solution) { } ;
void move(EOT& _solution) { } ;
/**
* NOTHING TO DO
* @param _solution a solution (unused)
* @return always false
*/
virtual bool accept(EOT& _solution) { return false; } ;
virtual bool accept(EOT& _solution) {
return false;
} ;
/**
* NOTHING TO DO
* @param _solution a solution (unused)
*/
virtual void terminate(EOT& _solution) { } ;
virtual void terminate(EOT& _solution) { } ;
/**
* NOTHING TO DO
* @param _solution a solution (unused)
*/
void operator()(EOT & _solution) { }
void operator()(EOT & _solution) { }
/**
* Return the class id.

View file

@ -53,73 +53,73 @@ class moILSexplorer : public moNeighborhoodExplorer< moDummyNeighbor<typename Ne
public:
typedef moNeighborhood<Neighbor> Neighborhood ;
typedef typename Neighbor::EOT EOT;
typedef moDummyNeighbor<EOT> dummyNeighbor;
typedef moDummyNeighborhood<dummyNeighbor> dummyNeighborhood;
typedef moDummyNeighbor<EOT> dummyNeighbor;
typedef moDummyNeighborhood<dummyNeighbor> dummyNeighborhood;
/**
* Constructor
* @param _ls a local search
* @param _perturb a perturbation operator
* @param _acceptCrit a acceptance criteria
*/
moILSexplorer(moLocalSearch<Neighbor>& _ls, moPerturbation<Neighbor>& _perturb, moAcceptanceCriterion<Neighbor>& _acceptCrit) : moNeighborhoodExplorer<dummyNeighbor>(), ls(_ls), perturb(_perturb), acceptCrit(_acceptCrit){
firstIteration=true;
/**
* Constructor
* @param _ls a local search
* @param _perturb a perturbation operator
* @param _acceptCrit a acceptance criteria
*/
moILSexplorer(moLocalSearch<Neighbor>& _ls, moPerturbation<Neighbor>& _perturb, moAcceptanceCriterion<Neighbor>& _acceptCrit) : moNeighborhoodExplorer<dummyNeighbor>(), ls(_ls), perturb(_perturb), acceptCrit(_acceptCrit) {
firstIteration=true;
}
/**
* Destructor
*/
~moILSexplorer(){
/**
* Destructor
*/
~moILSexplorer() {
}
/**
* Init perturbation and acceptance criteria
* @param _solution the current solution
*/
virtual void initParam(EOT & _solution){
firstIteration=true;
perturb.init(_solution);
acceptCrit.init(_solution);
/**
* Init perturbation and acceptance criteria
* @param _solution the current solution
*/
virtual void initParam(EOT & _solution) {
firstIteration=true;
perturb.init(_solution);
acceptCrit.init(_solution);
};
/**
* Update perturbation and acceptance criteria
* @param _solution the current solution
*/
virtual void updateParam(EOT & _solution){
if((*this).moveApplied()){
perturb.add(_solution,emptyNeighbor);
acceptCrit.add(_solution,emptyNeighbor);
}
perturb.update(_solution, emptyNeighbor);
acceptCrit.update(_solution, emptyNeighbor);
/**
* Update perturbation and acceptance criteria
* @param _solution the current solution
*/
virtual void updateParam(EOT & _solution) {
if ((*this).moveApplied()) {
perturb.add(_solution,emptyNeighbor);
acceptCrit.add(_solution,emptyNeighbor);
}
perturb.update(_solution, emptyNeighbor);
acceptCrit.update(_solution, emptyNeighbor);
};
/**
* terminate: NOTHING TO DO
/**
* terminate: NOTHING TO DO
* @param _solution a solution (unused)
*/
virtual void terminate(EOT & _solution){};
*/
virtual void terminate(EOT & _solution) {};
/**
* Perturb and apply local search on a solution
* @param _solution the solution
*/
virtual void operator()(EOT & _solution){
//copy the solution to perform new local search
current=_solution;
virtual void operator()(EOT & _solution) {
//copy the solution to perform new local search
current=_solution;
//perturb solution exept at the first iteration
if(!firstIteration){
perturb(current);
//perturb solution exept at the first iteration
if (!firstIteration) {
perturb(current);
}
else
firstIteration=false;
}
else
firstIteration=false;
//apply the local search on the copy
ls(current);
//apply the local search on the copy
ls(current);
};
@ -129,7 +129,7 @@ public:
* @return always true
*/
virtual bool isContinue(EOT & _solution) {
return true;
return true;
};
/**
@ -137,7 +137,7 @@ public:
* @param _solution the solution
*/
virtual void move(EOT & _solution) {
_solution=current;
_solution=current;
};
/**
@ -146,7 +146,7 @@ public:
* @return true if acceptance criteria is verified
*/
virtual bool accept(EOT & _solution) {
return acceptCrit(_solution, current);
return acceptCrit(_solution, current);
};
/**
@ -154,12 +154,12 @@ public:
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moILSexplorer";
return "moILSexplorer";
}
private:
//Usefull to use the momory of tabuSearch
Neighbor emptyNeighbor;
Neighbor emptyNeighbor;
EOT current;
moLocalSearch<Neighbor>& ls;
moPerturbation<Neighbor> & perturb;

View file

@ -70,7 +70,7 @@ public:
moNeighborComparator<Neighbor>& _neighborComparator,
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
unsigned _nbStep) :
moRandomBestHCexplorer<Neighbor>(_neighborhood, _eval, _neighborComparator, _solNeighborComparator),nbStep(_nbStep) {
moRandomBestHCexplorer<Neighbor>(_neighborhood, _eval, _neighborComparator, _solNeighborComparator),nbStep(_nbStep) {
//Some cycle is possible with equals fitness solutions if the neighborhood is not random
}
@ -85,7 +85,7 @@ public:
* @param _solution the current solution
*/
virtual void initParam(EOT & _solution) {
moRandomBestHCexplorer<Neighbor>::initParam(_solution);
moRandomBestHCexplorer<Neighbor>::initParam(_solution);
step = 0;
};
@ -95,7 +95,7 @@ public:
* @param _solution the current solution
*/
virtual void updateParam(EOT & _solution) {
moRandomBestHCexplorer<Neighbor>::updateParam(_solution);
moRandomBestHCexplorer<Neighbor>::updateParam(_solution);
step++;
};

View file

@ -43,7 +43,7 @@
#include <utils/eoRNG.h>
/**
* Explorer for Hill-Climbing
* Explorer for Hill-Climbing
* which choose randomly one of the best solution in the neighborhood at each iteration
*/
template< class Neighbor >
@ -64,9 +64,9 @@ public:
* @param _solNeighborComparator solution vs neighbor comparator
*/
moRandomBestHCexplorer(Neighborhood& _neighborhood,
moEval<Neighbor>& _eval,
moNeighborComparator<Neighbor>& _neighborComparator,
moSolNeighborComparator<Neighbor>& _solNeighborComparator) :
moEval<Neighbor>& _eval,
moNeighborComparator<Neighbor>& _neighborComparator,
moSolNeighborComparator<Neighbor>& _solNeighborComparator) :
moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval),
neighborComparator(_neighborComparator),
solNeighborComparator(_solNeighborComparator) {

View file

@ -63,7 +63,7 @@ public:
* @param _nbStep maximum number of step to do
*/
moRandomNeutralWalkExplorer(Neighborhood& _neighborhood,
moEval<Neighbor>& _eval,
moEval<Neighbor>& _eval,
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
unsigned _nbStep):
moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval),

View file

@ -48,101 +48,101 @@ template< class Neighbor >
class moRandomSearchExplorer : public moNeighborhoodExplorer<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
typedef moNeighborhood<Neighbor> Neighborhood ;
using moNeighborhoodExplorer<Neighbor>::neighborhood;
using moNeighborhoodExplorer<Neighbor>::eval;
/**
* Constructor
* @param _init the solution initializer, to explore at random the search space
* @param _fulleval the evaluation function
* @param _nbStep maximum number of step to do
*/
moRandomSearchExplorer(eoInit<EOT>& _init, eoEvalFunc<EOT>& _fulleval, unsigned _nbStep) : moNeighborhoodExplorer<Neighbor>(), init(_init), fulleval(_fulleval), nbStep(_nbStep) {
// number of step done
step = 0;
}
typedef typename Neighbor::EOT EOT ;
typedef moNeighborhood<Neighbor> Neighborhood ;
using moNeighborhoodExplorer<Neighbor>::neighborhood;
using moNeighborhoodExplorer<Neighbor>::eval;
/**
* Constructor
* @param _init the solution initializer, to explore at random the search space
* @param _fulleval the evaluation function
* @param _nbStep maximum number of step to do
*/
moRandomSearchExplorer(eoInit<EOT>& _init, eoEvalFunc<EOT>& _fulleval, unsigned _nbStep) : moNeighborhoodExplorer<Neighbor>(), init(_init), fulleval(_fulleval), nbStep(_nbStep) {
// number of step done
step = 0;
}
/**
* Destructor
*/
~moRandomSearchExplorer() {}
/**
* initialization of the number of step to be done
* @param _solution a solution (unused)
*/
virtual void initParam(EOT & _solution) {
step = 0;
};
/**
* increase the number of step
* @param _solution a solution (unused)
*/
virtual void updateParam(EOT & _solution) {
step++;
};
/**
* terminate: NOTHING TO DO
* @param _solution a solution (unused)
*/
virtual void terminate(EOT & _solution) {};
/**
* Explore the neighborhood with only one random solution
* we supposed that the first neighbor is uniformly selected in the neighborhood
* @param _solution
*/
virtual void operator()(EOT & _solution) {
//init the first neighbor
init(_solution);
//eval the _solution moved with the neighbor and stock the result in the neighbor
fulleval(_solution);
};
/**
* continue if it is remainds some steps to do
* @param _solution the solution
* @return true there is some steps to do
*/
virtual bool isContinue(EOT & _solution) {
return (step < nbStep) ;
};
/**
* move the solution with the best neighbor
* @param _solution the solution to move
*/
virtual void move(EOT & _solution) {
// the solution is already move. So nothing to do !
};
/**
* accept test : always accept
* @param _solution the solution
* @return true if the best neighbor ameliorate the fitness
*/
virtual bool accept(EOT & _solution) {
return true;
};
/**
* Destructor
*/
~moRandomSearchExplorer() {}
/**
* initialization of the number of step to be done
* @param _solution a solution (unused)
*/
virtual void initParam(EOT & _solution) {
step = 0;
};
/**
* increase the number of step
* @param _solution a solution (unused)
*/
virtual void updateParam(EOT & _solution) {
step++;
};
/**
* terminate: NOTHING TO DO
* @param _solution a solution (unused)
*/
virtual void terminate(EOT & _solution) {};
/**
* Explore the neighborhood with only one random solution
* we supposed that the first neighbor is uniformly selected in the neighborhood
* @param _solution
*/
virtual void operator()(EOT & _solution) {
//init the first neighbor
init(_solution);
//eval the _solution moved with the neighbor and stock the result in the neighbor
fulleval(_solution);
};
/**
* continue if it is remainds some steps to do
* @param _solution the solution
* @return true there is some steps to do
*/
virtual bool isContinue(EOT & _solution) {
return (step < nbStep) ;
};
/**
* move the solution with the best neighbor
* @param _solution the solution to move
*/
virtual void move(EOT & _solution) {
// the solution is already move. So nothing to do !
};
/**
* accept test : always accept
* @param _solution the solution
* @return true if the best neighbor ameliorate the fitness
*/
virtual bool accept(EOT & _solution) {
return true;
};
private:
// initialization method to explore at random the search space
eoInit<EOT> & init;
// initialization method to explore at random the search space
eoInit<EOT> & init;
// the full eval function
eoEvalFunc<EOT> & fulleval;
// the full eval function
eoEvalFunc<EOT> & fulleval;
// current number of step
unsigned int step;
// maximum number of steps to do
unsigned int nbStep;
// current number of step
unsigned int step;
// maximum number of steps to do
unsigned int nbStep;
};

View file

@ -48,7 +48,7 @@
* Explorer for the Simulated Annealing
* Only the symetric case is considered when Q(x,y) = Q(y,x)
* Fitness must be > 0
*
*
*/
template< class Neighbor >
class moSAexplorer : public moNeighborhoodExplorer<Neighbor>
@ -67,7 +67,7 @@ public:
* @param _solNeighborComparator a solution vs neighbor comparator
* @param _coolingSchedule the cooling schedule
*/
moSAexplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moSolNeighborComparator<Neighbor>& _solNeighborComparator, moCoolingSchedule<EOT>& _coolingSchedule) : moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval), solNeighborComparator(_solNeighborComparator), coolingSchedule(_coolingSchedule) {
moSAexplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moSolNeighborComparator<Neighbor>& _solNeighborComparator, moCoolingSchedule<EOT>& _coolingSchedule) : moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval), solNeighborComparator(_solNeighborComparator), coolingSchedule(_coolingSchedule) {
isAccept = false;
if (!neighborhood.isRandom()) {
@ -83,11 +83,11 @@ public:
/**
* initialization of the initial temperature
* @param _solution the solution
* @param _solution the solution
*/
virtual void initParam(EOT & _solution) {
temperature = coolingSchedule.init(_solution);
isAccept = true;
temperature = coolingSchedule.init(_solution);
isAccept = true;
};
/**
@ -95,7 +95,7 @@ public:
* @param _solution the solution (unused here)
*/
virtual void updateParam(EOT & _solution) {
coolingSchedule.update(temperature);
coolingSchedule.update(temperature);
};
/**
@ -129,7 +129,7 @@ public:
* @return true if the criteria from the cooling schedule is true
*/
virtual bool isContinue(EOT & _solution) {
return coolingSchedule(temperature);
return coolingSchedule(temperature);
};
/**
@ -152,16 +152,16 @@ public:
double alpha=0.0;
double fit1, fit2;
if (neighborhood.hasNeighbor(_solution)) {
if (solNeighborComparator(_solution, current)) // accept if the current neighbor is better than the solution
if (solNeighborComparator(_solution, current)) // accept if the current neighbor is better than the solution
isAccept = true;
else {
fit1=(double)current.fitness();
fit2=(double)_solution.fitness();
if (fit1 < fit2) // this is a maximization
alpha = exp((fit1 - fit2) / temperature );
else // this is a minimization
alpha = exp((fit2 - fit1) / temperature );
isAccept = (rng.uniform() < alpha) ;
fit1=(double)current.fitness();
fit2=(double)_solution.fitness();
if (fit1 < fit2) // this is a maximization
alpha = exp((fit1 - fit2) / temperature );
else // this is a minimization
alpha = exp((fit2 - fit1) / temperature );
isAccept = (rng.uniform() < alpha) ;
}
}
return isAccept;
@ -171,8 +171,8 @@ public:
* Getter
* @return the temperature
*/
double getTemperature(){
return temperature;
double getTemperature() {
return temperature;
}
private:

View file

@ -41,92 +41,92 @@ template< class EOT >
class moVNSexplorer : public moNeighborhoodExplorer< moNeighborhood< moNeighbor<EOT, typename EOT::Fitness> > >
{
public:
typedef typename EOT::Fitness Fitness ;
typedef moNeighbor<EOT, Fitness> Neighbor ;
typedef moNeighborhood<Neighbor> Neighborhood ;
typedef typename EOT::Fitness Fitness ;
typedef moNeighbor<EOT, Fitness> Neighbor ;
typedef moNeighborhood<Neighbor> Neighborhood ;
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::eval;
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
*/
moVNSexplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) {
}
/**
* Constructor
* @param _neighborhood the neighborhood
* @param _eval the evaluation function
* @param _neighborComparator a neighbor comparator
* @param _solNeighborComparator solution vs neighbor comparator
*/
moVNSexplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) {
}
/**
* Destructor
*/
~moVNSexplorer() {
}
/**
* initParam: NOTHING TO DO
*/
virtual void initParam(EOT & solution) {};
/**
* updateParam: NOTHING TO DO
*/
virtual void updateParam(EOT & solution) {};
/**
* terminate: NOTHING TO DO
*/
virtual void terminate(EOT & solution) {};
/**
* Explore the neighborhood of a solution
* @param _solution
*/
virtual void operator()(EOT & _solution) {
};
/**
* continue if a move is accepted
* @param _solution the solution
* @return true if an ameliorated neighbor was be found
*/
virtual bool isContinue(EOT & _solution) {
return isAccept ;
};
/**
* move the solution with the best neighbor
* @param _solution the solution to move
*/
virtual void move(EOT & _solution) {
//move the solution
(*best).move(_solution);
//update its fitness
_solution.fitness((*best).fitness());
};
/**
* accept test if an amelirated neighbor was be found
* @param _solution the solution
* @return true if the best neighbor ameliorate the fitness
*/
virtual bool accept(EOT & _solution) {
};
/**
* Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moVNSexplorer";
}
/**
* Destructor
*/
~moVNSexplorer() {
}
/**
* initParam: NOTHING TO DO
*/
virtual void initParam(EOT & solution) {};
/**
* updateParam: NOTHING TO DO
*/
virtual void updateParam(EOT & solution) {};
/**
* terminate: NOTHING TO DO
*/
virtual void terminate(EOT & solution) {};
/**
* Explore the neighborhood of a solution
* @param _solution
*/
virtual void operator()(EOT & _solution) {
};
/**
* continue if a move is accepted
* @param _solution the solution
* @return true if an ameliorated neighbor was be found
*/
virtual bool isContinue(EOT & _solution) {
return isAccept ;
};
/**
* move the solution with the best neighbor
* @param _solution the solution to move
*/
virtual void move(EOT & _solution) {
//move the solution
(*best).move(_solution);
//update its fitness
_solution.fitness((*best).fitness());
};
/**
* accept test if an amelirated neighbor was be found
* @param _solution the solution
* @return true if the best neighbor ameliorate the fitness
*/
virtual bool accept(EOT & _solution) {
};
/**
* Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moVNSexplorer";
}
private:
// 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;
};