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

@ -37,7 +37,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
* Abstract class for Acceptance criteria
*/
template< class Neighbor >
class moAcceptanceCriterion : public eoBF<typename Neighbor::EOT&, typename Neighbor::EOT&, bool>, virtual public moMemory<Neighbor>{
class moAcceptanceCriterion : public eoBF<typename Neighbor::EOT&, typename Neighbor::EOT&, bool>, virtual public moMemory<Neighbor> {
};

View file

@ -37,20 +37,20 @@ Contact: paradiseo-help@lists.gforge.inria.fr
* Acceptance Criterion for extreme diversification : always accept new solution
*/
template< class Neighbor >
class moAlwaysAcceptCrit : public moAcceptanceCriterion<Neighbor>, public moDummyMemory<Neighbor>{
class moAlwaysAcceptCrit : public moAcceptanceCriterion<Neighbor>, public moDummyMemory<Neighbor> {
public:
typedef typename Neighbor::EOT EOT;
typedef typename Neighbor::EOT EOT;
/**
* Always accept the new solution
* @param _sol1 the previous solution
* @param _sol2 the new solution after local search
* @return always true
*/
bool operator()(EOT& _sol1, EOT& _sol2){
return true;
}
/**
* Always accept the new solution
* @param _sol1 the previous solution
* @param _sol2 the new solution after local search
* @return always true
*/
bool operator()(EOT& _sol1, EOT& _sol2) {
return true;
}
};

View file

@ -38,25 +38,25 @@ Contact: paradiseo-help@lists.gforge.inria.fr
* Acceptance Criterion for extreme intensification : accept if the new solution is better than previous one
*/
template< class Neighbor >
class moBetterAcceptCrit : public moAcceptanceCriterion<Neighbor>, public moDummyMemory<Neighbor>{
class moBetterAcceptCrit : public moAcceptanceCriterion<Neighbor>, public moDummyMemory<Neighbor> {
public:
typedef typename Neighbor::EOT EOT;
typedef typename Neighbor::EOT EOT;
moBetterAcceptCrit(moSolComparator<EOT>& _comparator):comparator(_comparator){}
moBetterAcceptCrit(moSolComparator<EOT>& _comparator):comparator(_comparator) {}
/**
* Accept if the new solution is better than previous one
* @param _sol1 the previous solution
* @param _sol2 the new solution after local search
* @return true if the new solution is better than previous one
*/
bool operator()(EOT& _sol1, EOT& _sol2){
return comparator(_sol1, _sol2);
}
/**
* Accept if the new solution is better than previous one
* @param _sol1 the previous solution
* @param _sol2 the new solution after local search
* @return true if the new solution is better than previous one
*/
bool operator()(EOT& _sol1, EOT& _sol2) {
return comparator(_sol1, _sol2);
}
private:
moSolComparator<EOT>& comparator;
moSolComparator<EOT>& comparator;
};

View file

@ -36,36 +36,36 @@ Contact: paradiseo-help@lists.gforge.inria.fr
/**
* Dummy Local Search:
*
*
* To do nothing, only the full evaluation of the solution if necessary ;-)
*/
template<class Neighbor>
class moDummyLS: public moLocalSearch<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
/**
* Simple constructor
* @param _fullEval the full evaluation function
*/
moDummyLS(eoEvalFunc<EOT>& _fullEval):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval)
{}
/**
* @return name of the class
*/
virtual std::string className(void) const {
return "moDummyLS";
}
/**
* Simple constructor
* @param _fullEval the full evaluation function
*/
moDummyLS(eoEvalFunc<EOT>& _fullEval):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval)
{}
/**
* @return name of the class
*/
virtual std::string className(void) const {
return "moDummyLS";
}
private:
// always true continuator
moTrueContinuator<Neighbor> trueCont;
// the explorer of the simple HC
moDummyExplorer<Neighbor> explorer;
// always true continuator
moTrueContinuator<Neighbor> trueCont;
// the explorer of the simple HC
moDummyExplorer<Neighbor> explorer;
};
#endif

View file

@ -39,7 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
/**
* First improvement HC:
* Hill-Climber local search
*
*
* At each iteration,
* one of the random solution in the neighborhood is selected
* if the selected neighbor have higher fitness than the current solution
@ -50,55 +50,55 @@ template<class Neighbor>
class moFirstImprHC: public moLocalSearch<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
/**
* Basic constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
*/
moFirstImprHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
{}
/**
* Simple constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _cont an external continuator
*/
moFirstImprHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
{}
/**
* General constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _cont an external continuator
* @param _compN a neighbor vs neighbor comparator
* @param _compSN a solution vs neighbor comparator
*/
moFirstImprHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont, moNeighborComparator<Neighbor>& _compN, moSolNeighborComparator<Neighbor>& _compSN):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, _compN, _compSN)
{}
/**
* Basic constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
*/
moFirstImprHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
{}
/**
* Simple constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _cont an external continuator
*/
moFirstImprHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
{}
/**
* General constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _cont an external continuator
* @param _compN a neighbor vs neighbor comparator
* @param _compSN a solution vs neighbor comparator
*/
moFirstImprHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont, moNeighborComparator<Neighbor>& _compN, moSolNeighborComparator<Neighbor>& _compSN):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, _compN, _compSN)
{}
private:
// always true continuator
moTrueContinuator<Neighbor> trueCont;
// 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;
// the explorer of the first improvement HC
moFirstImprHCexplorer<Neighbor> explorer;
// always true continuator
moTrueContinuator<Neighbor> trueCont;
// 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;
// the explorer of the first improvement HC
moFirstImprHCexplorer<Neighbor> explorer;
};
#endif

View file

@ -49,7 +49,7 @@ class moILS: public moLocalSearch<moDummyNeighbor<typename Neighbor::EOT> >
{
public:
typedef typename Neighbor::EOT EOT;
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
/**
@ -59,12 +59,12 @@ public:
* @param _op the operator used to perturb solution
* @param _nbIteration the time limit for search
*/
moILS(moLocalSearch<Neighbor>& _ls, eoEvalFunc<EOT>& _fullEval, eoMonOp<EOT>& _op, unsigned int _nbIteration):
moLocalSearch<moDummyNeighbor<EOT> >(explorer, iterCont, _fullEval),
iterCont(_nbIteration),
defaultPerturb(_op, _fullEval),
explorer(_ls, defaultPerturb, defaultAccept)
{}
moILS(moLocalSearch<Neighbor>& _ls, eoEvalFunc<EOT>& _fullEval, eoMonOp<EOT>& _op, unsigned int _nbIteration):
moLocalSearch<moDummyNeighbor<EOT> >(explorer, iterCont, _fullEval),
iterCont(_nbIteration),
defaultPerturb(_op, _fullEval),
explorer(_ls, defaultPerturb, defaultAccept)
{}
/**
* Simple constructor for Iterated Local Search
@ -73,12 +73,12 @@ public:
* @param _op the operator used to perturb solution
* @param _cont a continuator
*/
moILS(moLocalSearch<Neighbor>& _ls, eoEvalFunc<EOT>& _fullEval, eoMonOp<EOT>& _op, moContinuator<moDummyNeighbor<EOT> >& _cont):
moLocalSearch<moDummyNeighbor<EOT> >(explorer, _cont, _fullEval),
iterCont(0),
defaultPerturb(_op, _fullEval),
explorer(_ls, defaultPerturb, defaultAccept)
{}
moILS(moLocalSearch<Neighbor>& _ls, eoEvalFunc<EOT>& _fullEval, eoMonOp<EOT>& _op, moContinuator<moDummyNeighbor<EOT> >& _cont):
moLocalSearch<moDummyNeighbor<EOT> >(explorer, _cont, _fullEval),
iterCont(0),
defaultPerturb(_op, _fullEval),
explorer(_ls, defaultPerturb, defaultAccept)
{}
/**
* General constructor for Iterated Local Search
@ -88,23 +88,25 @@ public:
* @param _perturb a perturbation operator
* @param _accept a acceptance criteria
*/
moILS(moLocalSearch<Neighbor>& _ls, eoEvalFunc<EOT>& _fullEval, moContinuator<moDummyNeighbor<EOT> >& _cont, moMonOpPerturb<Neighbor>& _perturb, moAcceptanceCriterion<Neighbor>& _accept):
moLocalSearch<moDummyNeighbor<EOT> >(explorer, _cont, _fullEval),
iterCont(0),
defaultPerturb(dummyOp, _fullEval),
explorer(_ls, _perturb, _accept)
{}
moILS(moLocalSearch<Neighbor>& _ls, eoEvalFunc<EOT>& _fullEval, moContinuator<moDummyNeighbor<EOT> >& _cont, moMonOpPerturb<Neighbor>& _perturb, moAcceptanceCriterion<Neighbor>& _accept):
moLocalSearch<moDummyNeighbor<EOT> >(explorer, _cont, _fullEval),
iterCont(0),
defaultPerturb(dummyOp, _fullEval),
explorer(_ls, _perturb, _accept)
{}
private:
class dummmyMonOp: public eoMonOp<EOT>{
public:
bool operator()(EOT&){return false;}
}dummyOp;
moIterContinuator<moDummyNeighbor<EOT> > iterCont;
moMonOpPerturb<Neighbor> defaultPerturb;
moAlwaysAcceptCrit<Neighbor> defaultAccept;
moILSexplorer<Neighbor> explorer;
class dummmyMonOp: public eoMonOp<EOT> {
public:
bool operator()(EOT&) {
return false;
}
}dummyOp;
moIterContinuator<moDummyNeighbor<EOT> > iterCont;
moMonOpPerturb<Neighbor> defaultPerturb;
moAlwaysAcceptCrit<Neighbor> defaultAccept;
moILSexplorer<Neighbor> explorer;
};

View file

@ -48,9 +48,9 @@ template<class Neighbor>
class moLocalSearch: public eoMonOp<typename Neighbor::EOT>
{
public:
typedef moNeighborhood<Neighbor> Neighborhood;
typedef moNeighborhoodExplorer<Neighbor> NeighborhoodExplorer;
typedef typename Neighbor::EOT EOT ;
typedef moNeighborhood<Neighbor> Neighborhood;
typedef moNeighborhoodExplorer<Neighbor> NeighborhoodExplorer;
typedef typename Neighbor::EOT EOT ;
/**
* Constructor of a moLocalSearch
@ -101,23 +101,23 @@ public:
return true;
};
/**
/**
* Set an external continuator
* @param _cont the external continuator
*/
void setContinuator(moContinuator<Neighbor> & _cont) {
cont = &_cont ;
}
void setContinuator(moContinuator<Neighbor> & _cont) {
cont = &_cont ;
}
/**
/**
* external continuator object
*
*
* @overload
* @return the external continuator
* @return the external continuator
*/
moContinuator<Neighbor>* getContinuator() const {
return cont ;
}
moContinuator<Neighbor>* getContinuator() const {
return cont ;
}
protected:
// make the exploration of the neighborhood according to a local search heuristic

View file

@ -40,7 +40,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
* Metropolis-Hasting local search
* Only the symetric case is considered when Q(x,y) = Q(y,x)
* Fitness must be > 0
*
*
* At each iteration,
* one of the random solution in the neighborhood is selected
* if the selected neighbor have higher or equal fitness than the current solution
@ -53,58 +53,58 @@ template<class Neighbor>
class moMetropolisHasting: public moLocalSearch<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
/**
* Basic constructor of the Metropolis-Hasting
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStep maximum step to do
*/
moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep)
{}
/**
* Simple constructor of the Metropolis-Hasting
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStep maximum step to do
* @param _cont an external continuator
*/
moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep, moContinuator<Neighbor>& _cont):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep)
{}
/**
* General constructor of the Metropolis-Hasting
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStep maximum step to do
* @param _cont an external continuator
* @param _compN a neighbor vs neighbor comparator
* @param _compSN a solution vs neighbor comparator
*/
moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep, moContinuator<Neighbor>& _cont, moNeighborComparator<Neighbor>& _compN, moSolNeighborComparator<Neighbor>& _compSN):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, _compN, _compSN, _nbStep)
{}
/**
* Basic constructor of the Metropolis-Hasting
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStep maximum step to do
*/
moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep)
{}
/**
* Simple constructor of the Metropolis-Hasting
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStep maximum step to do
* @param _cont an external continuator
*/
moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep, moContinuator<Neighbor>& _cont):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep)
{}
/**
* General constructor of the Metropolis-Hasting
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStep maximum step to do
* @param _cont an external continuator
* @param _compN a neighbor vs neighbor comparator
* @param _compSN a solution vs neighbor comparator
*/
moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep, moContinuator<Neighbor>& _cont, moNeighborComparator<Neighbor>& _compN, moSolNeighborComparator<Neighbor>& _compSN):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, _compN, _compSN, _nbStep)
{}
private:
// always true continuator
moTrueContinuator<Neighbor> trueCont;
// 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;
// the explorer of the HC with neutral move (equals fitness move)
moMetropolisHastingExplorer<Neighbor> explorer;
// always true continuator
moTrueContinuator<Neighbor> trueCont;
// 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;
// the explorer of the HC with neutral move (equals fitness move)
moMetropolisHastingExplorer<Neighbor> explorer;
};
#endif

View file

@ -49,58 +49,58 @@ template<class Neighbor>
class moNeutralHC: public moLocalSearch<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
/**
* Basic constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStep maximum step to do
*/
moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep)
{}
/**
* Simple constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStep maximum step to do
* @param _cont an external continuator
*/
moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep, moContinuator<Neighbor>& _cont):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep)
{}
/**
* General constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStep maximum step to do
* @param _cont an external continuator
* @param _compN a neighbor vs neighbor comparator
* @param _compSN a solution vs neighbor comparator
*/
moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep, moContinuator<Neighbor>& _cont, moNeighborComparator<Neighbor>& _compN, moSolNeighborComparator<Neighbor>& _compSN):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, _compN, _compSN, _nbStep)
{}
/**
* Basic constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStep maximum step to do
*/
moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep)
{}
/**
* Simple constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStep maximum step to do
* @param _cont an external continuator
*/
moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep, moContinuator<Neighbor>& _cont):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep)
{}
/**
* General constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStep maximum step to do
* @param _cont an external continuator
* @param _compN a neighbor vs neighbor comparator
* @param _compSN a solution vs neighbor comparator
*/
moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep, moContinuator<Neighbor>& _cont, moNeighborComparator<Neighbor>& _compN, moSolNeighborComparator<Neighbor>& _compSN):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, _compN, _compSN, _nbStep)
{}
private:
// always true continuator
moTrueContinuator<Neighbor> trueCont;
// 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;
// the explorer of the HC with neutral move (equals fitness move)
moNeutralHCexplorer<Neighbor> explorer;
// always true continuator
moTrueContinuator<Neighbor> trueCont;
// 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;
// the explorer of the HC with neutral move (equals fitness move)
moNeutralHCexplorer<Neighbor> explorer;
};
#endif

View file

@ -39,7 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
/**
* Random Best HC:
* Hill-Climber local search
*
*
* At each iteration,
* one of the random best solution in the neighborhood is selected
* if the selected neighbor have higher fitness than the current solution
@ -50,55 +50,55 @@ template<class Neighbor>
class moRandomBestHC: public moLocalSearch<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
/**
* Basic constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
*/
moRandomBestHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
{}
/**
* Simple constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _cont an external continuator
*/
moRandomBestHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
{}
/**
* General constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _cont an external continuator
* @param _compN a neighbor vs neighbor comparator
* @param _compSN a solution vs neighbor comparator
*/
moRandomBestHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont, moNeighborComparator<Neighbor>& _compN, moSolNeighborComparator<Neighbor>& _compSN):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, _compN, _compSN)
{}
/**
* Basic constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
*/
moRandomBestHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
{}
/**
* Simple constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _cont an external continuator
*/
moRandomBestHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
{}
/**
* General constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _cont an external continuator
* @param _compN a neighbor vs neighbor comparator
* @param _compSN a solution vs neighbor comparator
*/
moRandomBestHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont, moNeighborComparator<Neighbor>& _compN, moSolNeighborComparator<Neighbor>& _compSN):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, _compN, _compSN)
{}
private:
// always true continuator
moTrueContinuator<Neighbor> trueCont;
// 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;
// the explorer of the HC with random choice of the best solution
moRandomBestHCexplorer<Neighbor> explorer;
// always true continuator
moTrueContinuator<Neighbor> trueCont;
// 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;
// the explorer of the HC with random choice of the best solution
moRandomBestHCexplorer<Neighbor> explorer;
};
#endif

View file

@ -39,7 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
/**
* Random Neutral Walk:
* Random Neutral walk local search
*
*
* At each iteration,
* one random neighbor with the same fitness is selected and replace the current solution
* the algorithm stops when the number of steps is reached
@ -48,55 +48,55 @@ template<class Neighbor>
class moRandomNeutralWalk: public moLocalSearch<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
/**
* Basic constructor for a random walk
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStepMax number of step of the walk
*/
moRandomNeutralWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
explorer(_neighborhood, _eval, defaultSolNeighborComp, _nbStepMax)
{}
/**
* Simple constructor for a random walk
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStepMax number of step of the walk
* @param _cont an external continuator
*/
moRandomNeutralWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax, moContinuator<Neighbor>& _cont):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, defaultSolNeighborComp, _nbStepMax)
{}
/**
* General constructor for a random walk
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStepMax number of step of the walk
* @param _cont an external continuator
* @param _comp a solution vs neighbor comparator
*/
moRandomNeutralWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax, moContinuator<Neighbor>& _cont, moSolNeighborComparator<Neighbor>& _comp):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, _comp, _nbStepMax)
{}
/**
* Basic constructor for a random walk
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStepMax number of step of the walk
*/
moRandomNeutralWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
explorer(_neighborhood, _eval, defaultSolNeighborComp, _nbStepMax)
{}
/**
* Simple constructor for a random walk
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStepMax number of step of the walk
* @param _cont an external continuator
*/
moRandomNeutralWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax, moContinuator<Neighbor>& _cont):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, defaultSolNeighborComp, _nbStepMax)
{}
/**
* General constructor for a random walk
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStepMax number of step of the walk
* @param _cont an external continuator
* @param _comp a solution vs neighbor comparator
*/
moRandomNeutralWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax, moContinuator<Neighbor>& _cont, moSolNeighborComparator<Neighbor>& _comp):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, _comp, _nbStepMax)
{}
private:
// always true continuator
moTrueContinuator<Neighbor> trueCont;
// the explorer of the random walk
moRandomNeutralWalkExplorer<Neighbor> explorer;
// compare the fitness values of the solution and the neighbor: true if strictly greater
moSolNeighborComparator<Neighbor> defaultSolNeighborComp;
// always true continuator
moTrueContinuator<Neighbor> trueCont;
// the explorer of the random walk
moRandomNeutralWalkExplorer<Neighbor> explorer;
// compare the fitness values of the solution and the neighbor: true if strictly greater
moSolNeighborComparator<Neighbor> defaultSolNeighborComp;
};
#endif

View file

@ -39,7 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
/**
* Random Search:
* Pure random search local search
*
*
* At each iteration,
* one random solution is selected and replace the current solution
* the algorithm stops when the number of solution is reached
@ -48,43 +48,43 @@ template<class Neighbor>
class moRandomSearch: public moLocalSearch<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT;
typedef typename Neighbor::EOT EOT;
/**
* Simple constructor for a random search
* @param _init the solution initializer, to explore at random the search space
* @param _fullEval the full evaluation function
* @param _nbSolMax number of solutions
*/
moRandomSearch(eoInit<EOT> & _init, eoEvalFunc<EOT>& _fullEval, unsigned _nbSolMax):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
explorer(_init, _fullEval, _nbSolMax>0?_nbSolMax - 1:0)
{}
/**
* General constructor for a random search
* @param _init the solution initializer, to explore at random the search space
* @param _fullEval the full evaluation function
* @param _nbSolMax number of solutions
* @param _cont external continuator
*/
moRandomSearch(eoInit<EOT> & _init, eoEvalFunc<EOT>& _fullEval, unsigned _nbSolMax, moContinuator<Neighbor>& _cont):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_init, _fullEval, _nbSolMax>0?_nbSolMax - 1:0)
{}
/**
* @return name of the class
*/
virtual std::string className(void) const {
return "moRandomSearch";
}
/**
* Simple constructor for a random search
* @param _init the solution initializer, to explore at random the search space
* @param _fullEval the full evaluation function
* @param _nbSolMax number of solutions
*/
moRandomSearch(eoInit<EOT> & _init, eoEvalFunc<EOT>& _fullEval, unsigned _nbSolMax):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
explorer(_init, _fullEval, _nbSolMax>0?_nbSolMax - 1:0)
{}
/**
* General constructor for a random search
* @param _init the solution initializer, to explore at random the search space
* @param _fullEval the full evaluation function
* @param _nbSolMax number of solutions
* @param _cont external continuator
*/
moRandomSearch(eoInit<EOT> & _init, eoEvalFunc<EOT>& _fullEval, unsigned _nbSolMax, moContinuator<Neighbor>& _cont):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_init, _fullEval, _nbSolMax>0?_nbSolMax - 1:0)
{}
/**
* @return name of the class
*/
virtual std::string className(void) const {
return "moRandomSearch";
}
private:
// always true continuator
moTrueContinuator<Neighbor> trueCont;
// the explorer of the random walk
moRandomSearchExplorer<Neighbor> explorer;
// always true continuator
moTrueContinuator<Neighbor> trueCont;
// the explorer of the random walk
moRandomSearchExplorer<Neighbor> explorer;
};
#endif

View file

@ -39,7 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
/**
* Random Walk:
* Random walk local search
*
*
* At each iteration,
* one random neighbor is selected and replace the current solution
* the algorithm stops when the number of steps is reached
@ -48,39 +48,39 @@ template<class Neighbor>
class moRandomWalk: public moLocalSearch<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
/**
* Simple constructor for a random walk
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStepMax number of step of the walk
*/
moRandomWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
explorer(_neighborhood, _eval, _nbStepMax)
{}
/**
* General constructor for a random walk
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStepMax number of step of the walk
* @param _cont an external continuator
*/
moRandomWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax, moContinuator<Neighbor>& _cont):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, _nbStepMax)
{}
/**
* Simple constructor for a random walk
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStepMax number of step of the walk
*/
moRandomWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
explorer(_neighborhood, _eval, _nbStepMax)
{}
/**
* General constructor for a random walk
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _nbStepMax number of step of the walk
* @param _cont an external continuator
*/
moRandomWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax, moContinuator<Neighbor>& _cont):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, _nbStepMax)
{}
private:
// always true continuator
moTrueContinuator<Neighbor> trueCont;
// the explorer of the random walk
moRandomWalkExplorer<Neighbor> explorer;
// always true continuator
moTrueContinuator<Neighbor> trueCont;
// the explorer of the random walk
moRandomWalkExplorer<Neighbor> explorer;
};
#endif

View file

@ -46,7 +46,7 @@ class moSA: public moLocalSearch<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT;
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
@ -60,11 +60,11 @@ public:
* @param _span number of iteration with equal temperature for cooling schedule (default = 100)
* @param _finalT final temperature, threshold of the stopping criteria for cooling schedule (default = 0.01)
*/
moSA(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, double _initT=10, double _alpha=0.9, unsigned _span=100, double _finalT=0.01):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
defaultCool(_initT, _alpha, _span, _finalT),
explorer(_neighborhood, _eval, defaultSolNeighborComp, defaultCool)
{}
moSA(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, double _initT=10, double _alpha=0.9, unsigned _span=100, double _finalT=0.01):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
defaultCool(_initT, _alpha, _span, _finalT),
explorer(_neighborhood, _eval, defaultSolNeighborComp, defaultCool)
{}
/**
* Simple constructor for a simulated annealing
@ -73,11 +73,11 @@ public:
* @param _eval neighbor's evaluation function
* @param _cool a cooling schedule
*/
moSA(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moCoolingSchedule<EOT>& _cool):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
defaultCool(0, 0, 0, 0),
explorer(_neighborhood, _eval, defaultSolNeighborComp, _cool)
{}
moSA(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moCoolingSchedule<EOT>& _cool):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
defaultCool(0, 0, 0, 0),
explorer(_neighborhood, _eval, defaultSolNeighborComp, _cool)
{}
/**
* General constructor for a simulated annealing
@ -88,19 +88,19 @@ public:
* @param _comp a solution vs neighbor comparator
* @param _cont an external continuator
*/
moSA(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moCoolingSchedule<EOT>& _cool, moSolNeighborComparator<Neighbor>& _comp, moContinuator<Neighbor>& _cont):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
defaultCool(0, 0, 0, 0),
explorer(_neighborhood, _eval, _comp, _cool)
{}
moSA(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moCoolingSchedule<EOT>& _cool, moSolNeighborComparator<Neighbor>& _comp, moContinuator<Neighbor>& _cont):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
defaultCool(0, 0, 0, 0),
explorer(_neighborhood, _eval, _comp, _cool)
{}
private:
moTrueContinuator<Neighbor> trueCont;
moSimpleCoolingSchedule<EOT> defaultCool;
moSolNeighborComparator<Neighbor> defaultSolNeighborComp;
moSAexplorer<Neighbor> explorer;
moTrueContinuator<Neighbor> trueCont;
moSimpleCoolingSchedule<EOT> defaultCool;
moSolNeighborComparator<Neighbor> defaultSolNeighborComp;
moSAexplorer<Neighbor> explorer;
};
#endif

View file

@ -39,7 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
/**
* Simple HC:
* Hill-Climber local search
*
*
* At each iteration,
* the first best solution in the neighborhood is selected
* if the selected neighbor have higher fitness than the current solution
@ -50,55 +50,55 @@ template<class Neighbor>
class moSimpleHC: public moLocalSearch<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
/**
* Simple constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
*/
moSimpleHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
{}
/**
* Simple constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _cont an external continuator
*/
moSimpleHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
{}
/**
* Simple constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _cont an external continuator
* @param _compN a neighbor vs neighbor comparator
* @param _compSN a solution vs neighbor comparator
*/
moSimpleHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont, moNeighborComparator<Neighbor>& _compN, moSolNeighborComparator<Neighbor>& _compSN):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, _compN, _compSN)
{}
/**
* Simple constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
*/
moSimpleHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval):
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
{}
/**
* Simple constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _cont an external continuator
*/
moSimpleHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
{}
/**
* Simple constructor for a hill-climber
* @param _neighborhood the neighborhood
* @param _fullEval the full evaluation function
* @param _eval neighbor's evaluation function
* @param _cont an external continuator
* @param _compN a neighbor vs neighbor comparator
* @param _compSN a solution vs neighbor comparator
*/
moSimpleHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont, moNeighborComparator<Neighbor>& _compN, moSolNeighborComparator<Neighbor>& _compSN):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
explorer(_neighborhood, _eval, _compN, _compSN)
{}
private:
// always true continuator
moTrueContinuator<Neighbor> trueCont;
// 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;
// the explorer of the simple HC
moSimpleHCexplorer<Neighbor> explorer;
// always true continuator
moTrueContinuator<Neighbor> trueCont;
// 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;
// the explorer of the simple HC
moSimpleHCexplorer<Neighbor> explorer;
};
#endif

View file

@ -51,7 +51,7 @@ class moTS: public moLocalSearch<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT;
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ;
/**
@ -62,17 +62,17 @@ public:
* @param _time the time limit for stopping criteria
* @param _tabuListSize the size of the tabu list
*/
moTS(Neighborhood& _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _time,
unsigned int _tabuListSize
):
moLocalSearch<Neighbor>(explorer, timeCont, _fullEval),
timeCont(_time),
tabuList(_tabuListSize,0),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, tabuList, dummyIntensification, dummyDiversification, defaultAspiration)
{}
moTS(Neighborhood& _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _time,
unsigned int _tabuListSize
):
moLocalSearch<Neighbor>(explorer, timeCont, _fullEval),
timeCont(_time),
tabuList(_tabuListSize,0),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, tabuList, dummyIntensification, dummyDiversification, defaultAspiration)
{}
/**
* Simple constructor for a tabu search
@ -82,16 +82,16 @@ public:
* @param _time the time limit for stopping criteria
* @param _tabuList the tabu list
*/
moTS(Neighborhood& _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _time,
moTabuList<Neighbor>& _tabuList):
moLocalSearch<Neighbor>(explorer, timeCont, _fullEval),
timeCont(_time),
tabuList(0,0),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _tabuList, dummyIntensification, dummyDiversification, defaultAspiration)
{}
moTS(Neighborhood& _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _time,
moTabuList<Neighbor>& _tabuList):
moLocalSearch<Neighbor>(explorer, timeCont, _fullEval),
timeCont(_time),
tabuList(0,0),
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _tabuList, dummyIntensification, dummyDiversification, defaultAspiration)
{}
/**
* General constructor for a tabu search
@ -106,31 +106,31 @@ public:
* @param _diversification the diversification strategy
* @param _aspiration the aspiration Criteria
*/
moTS(Neighborhood& _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
moNeighborComparator<Neighbor>& _neighborComp,
moSolNeighborComparator<Neighbor>& _solNeighborComp,
moContinuator<Neighbor>& _cont,
moTabuList<Neighbor>& _tabuList,
moIntensification<Neighbor>& _intensification,
moDiversification<Neighbor>& _diversification,
moAspiration<Neighbor>& _aspiration):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
timeCont(0),
tabuList(0,0),
explorer(_neighborhood, _eval, _neighborComp, _solNeighborComp, _tabuList, _intensification, _diversification, _aspiration)
{}
moTS(Neighborhood& _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
moNeighborComparator<Neighbor>& _neighborComp,
moSolNeighborComparator<Neighbor>& _solNeighborComp,
moContinuator<Neighbor>& _cont,
moTabuList<Neighbor>& _tabuList,
moIntensification<Neighbor>& _intensification,
moDiversification<Neighbor>& _diversification,
moAspiration<Neighbor>& _aspiration):
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
timeCont(0),
tabuList(0,0),
explorer(_neighborhood, _eval, _neighborComp, _solNeighborComp, _tabuList, _intensification, _diversification, _aspiration)
{}
private:
moTimeContinuator<Neighbor> timeCont;
moNeighborComparator<Neighbor> defaultNeighborComp;
moSolNeighborComparator<Neighbor> defaultSolNeighborComp;
moNeighborVectorTabuList<Neighbor> tabuList;
moDummyIntensification<Neighbor> dummyIntensification;
moDummyDiversification<Neighbor> dummyDiversification;
moBestImprAspiration<Neighbor> defaultAspiration;
moTSexplorer<Neighbor> explorer;
moTimeContinuator<Neighbor> timeCont;
moNeighborComparator<Neighbor> defaultNeighborComp;
moSolNeighborComparator<Neighbor> defaultSolNeighborComp;
moNeighborVectorTabuList<Neighbor> tabuList;
moDummyIntensification<Neighbor> dummyIntensification;
moDummyDiversification<Neighbor> dummyDiversification;
moBestImprAspiration<Neighbor> defaultAspiration;
moTSexplorer<Neighbor> explorer;
};
#endif

View file

@ -47,11 +47,11 @@ class moComparator : public eoBF<const T1 & , const T2 & , bool>
{
public:
/**
* @param _ref1 a reference on a variable of type T1
* @param _ref2 a reference on a variable of type T2
* @return true if _ref1 and _ref2 are equals
*/
/**
* @param _ref1 a reference on a variable of type T1
* @param _ref2 a reference on a variable of type T2
* @return true if _ref1 and _ref2 are equals
*/
virtual bool equals(const T1& _ref1, const T2& _ref2) = 0;
};

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;
};

View file

@ -39,23 +39,23 @@
/**
* Cooling Schedule of the temperature in the simulated algorithm
*
*
*/
template< class EOT >
class moCoolingSchedule : public eoUF<double, bool>
{
public:
/**
* Initial temperature
* @param _solution initial solution
*/
virtual double init(EOT & _solution) = 0;
/**
* Initial temperature
* @param _solution initial solution
*/
virtual double init(EOT & _solution) = 0;
/**
* update the temperature
* @param _temp current temperature to update
*/
virtual void update(double& _temp) = 0;
/**
* update the temperature
* @param _temp current temperature to update
*/
virtual void update(double& _temp) = 0;
};

View file

@ -39,86 +39,86 @@
/**
* Cooling Schedule of the temperature in the simulated algorithm
*
*
*/
template< class EOT >
class moDynSpanCoolingSchedule : public moCoolingSchedule<EOT>
{
public:
/**
* default constructor
* @param _initT initial temperature
* @param _alpha factor of decreasing
* @param _spanMove maximum number of move with equal temperature
* @param _spanNoMove maximum number of no improvement with equal temperature
* @param _nbSpan maximum number of span with no improvmement before stopping the search
*/
moDynSpanCoolingSchedule(double _initT, double _alpha, unsigned int _spanMove, unsigned int _spanNoMove, unsigned int _nbSpan) : initT(_initT), alpha(_alpha), spanMove(_spanMove), spanNoMove(_spanNoMove), nbSpan(_nbSpan) {
}
/**
* Initial temperature
* @param _solution initial solution
*/
virtual double init(EOT & _solution) {
// number of successive moves since the last temperature change
nbMove = 0;
// number of no improvement since the last temperature change
nbNoMove = 0;
// number of span with no improvement
nbSpan = 0;
return initT;
}
/**
* update the temperature by a factor
* @param _temp current temperature to update
*/
virtual void update(double& _temp) {
if (nbMove >= spanMove || nbNoMove >= spanNoMove) {
_temp *= alpha;
nbMove = 0;
nbNoMove = 0;
} else {
nbMove++;
nbNoMove++;
/**
* default constructor
* @param _initT initial temperature
* @param _alpha factor of decreasing
* @param _spanMove maximum number of move with equal temperature
* @param _spanNoMove maximum number of no improvement with equal temperature
* @param _nbSpan maximum number of span with no improvmement before stopping the search
*/
moDynSpanCoolingSchedule(double _initT, double _alpha, unsigned int _spanMove, unsigned int _spanNoMove, unsigned int _nbSpan) : initT(_initT), alpha(_alpha), spanMove(_spanMove), spanNoMove(_spanNoMove), nbSpan(_nbSpan) {
}
}
/**
* compare the temperature to the threshold
* @param _temp current temperature
* @return true if the current temperature is over the threshold (final temperature)
*/
virtual bool operator()(double _temp) {
return _temp > finalT;
}
/**
* Initial temperature
* @param _solution initial solution
*/
virtual double init(EOT & _solution) {
// number of successive moves since the last temperature change
nbMove = 0;
// number of no improvement since the last temperature change
nbNoMove = 0;
// number of span with no improvement
nbSpan = 0;
return initT;
}
/**
* update the temperature by a factor
* @param _temp current temperature to update
*/
virtual void update(double& _temp) {
if (nbMove >= spanMove || nbNoMove >= spanNoMove) {
_temp *= alpha;
nbMove = 0;
nbNoMove = 0;
} else {
nbMove++;
nbNoMove++;
}
}
/**
* compare the temperature to the threshold
* @param _temp current temperature
* @return true if the current temperature is over the threshold (final temperature)
*/
virtual bool operator()(double _temp) {
return _temp > finalT;
}
private:
// initial temperature
double initT;
// initial temperature
double initT;
// coefficient of decrease
double alpha;
// coefficient of decrease
double alpha;
//
unsigned int spanMove;
//
unsigned int spanMove;
//
unsigned int spanNoMove;
//
unsigned int spanNoMove;
// maximum number of iterations at the same temperature
unsigned int nbSpan;
// maximum number of iterations at the same temperature
unsigned int nbSpan;
// threshold temperature
double finalT;
// threshold temperature
double finalT;
// number of steps with the same temperature
unsigned int step;
// number of steps with the same temperature
unsigned int step;
};

View file

@ -39,65 +39,65 @@
/**
* Classical cooling Schedule of the temperature in the simulated algorithm with initial and final temperature and a factor of decrease
*
*
*/
template< class EOT >
class moSimpleCoolingSchedule : public moCoolingSchedule<EOT>
{
public:
/**
* default constructor
* @param _initT initial temperature
* @param _alpha factor of decreasing
* @param _span number of iteration with equal temperature
* @param _finalT final temperature, threshold of the stopping criteria
*/
moSimpleCoolingSchedule(double _initT, double _alpha, unsigned _span, double _finalT) : initT(_initT), alpha(_alpha), span(_span), finalT(_finalT) {}
/**
* default constructor
* @param _initT initial temperature
* @param _alpha factor of decreasing
* @param _span number of iteration with equal temperature
* @param _finalT final temperature, threshold of the stopping criteria
*/
moSimpleCoolingSchedule(double _initT, double _alpha, unsigned _span, double _finalT) : initT(_initT), alpha(_alpha), span(_span), finalT(_finalT) {}
/**
* Initial temperature
* @param _solution initial solution
* @return the initial temperature
*/
virtual double init(EOT & _solution) {
// number of iteration with the same temperature
step = 0;
/**
* Initial temperature
* @param _solution initial solution
* @return the initial temperature
*/
virtual double init(EOT & _solution) {
// number of iteration with the same temperature
step = 0;
return initT;
}
return initT;
}
/**
* update the temperature by a factor
* @param _temp current temperature to update
*/
virtual void update(double& _temp) {
if (step >= span) {
_temp *= alpha;
step = 0;
} else
step++;
}
/**
* update the temperature by a factor
* @param _temp current temperature to update
*/
virtual void update(double& _temp) {
if (step >= span) {
_temp *= alpha;
step = 0;
} else
step++;
}
/**
* compare the temperature to the threshold
* @param _temp current temperature
* @return true if the current temperature is over the threshold (final temperature)
*/
virtual bool operator()(double _temp) {
return _temp > finalT;
}
/**
* compare the temperature to the threshold
* @param _temp current temperature
* @return true if the current temperature is over the threshold (final temperature)
*/
virtual bool operator()(double _temp) {
return _temp > finalT;
}
private:
// initial temperature
double initT;
// coefficient of decrease
double alpha;
// maximum number of iterations at the same temperature
unsigned int span;
// threshold temperature
double finalT;
// number of steps with the same temperature
unsigned int step;
// initial temperature
double initT;
// coefficient of decrease
double alpha;
// maximum number of iterations at the same temperature
unsigned int span;
// threshold temperature
double finalT;
// number of steps with the same temperature
unsigned int step;
};

View file

@ -36,17 +36,17 @@ Contact: paradiseo-help@lists.gforge.inria.fr
* Dummy Evaluation function
*/
template<class Neighbor>
class moDummyEval : public moEval<Neighbor>{
class moDummyEval : public moEval<Neighbor> {
public:
typedef typename Neighbor::EOT EOT;
typedef typename EOT::Fitness Fitness;
/**
* NOTHING TO DO
* @param _sol a solution (unused)
* @param _n a neighbor (unused)
*/
void operator()(EOT& _sol, Neighbor& _n){}
* NOTHING TO DO
* @param _sol a solution (unused)
* @param _n a neighbor (unused)
*/
void operator()(EOT& _sol, Neighbor& _n) {}
};

View file

@ -33,7 +33,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <eval/moEval.h>
#include <utils/eoParam.h>
/**
/**
Counts the number of neighbor evaluations actually performed, thus checks first
if it has to evaluate.. etc.
*/
@ -41,25 +41,25 @@ template<class Neighbor>
class moEvalCounter : public moEval<Neighbor>, public eoValueParam<unsigned long>
{
public:
typedef typename Neighbor::EOT EOT;
typedef typename EOT::Fitness Fitness;
moEvalCounter(moEval<Neighbor>& _eval, std::string _name = "Neighbor Eval. ")
: eoValueParam<unsigned long>(0, _name), eval(_eval) {}
/**
* Increase the number of neighbor evaluations and perform the evaluation
*
* @param _solution a solution
* @param _neighbor a neighbor
*/
void operator()(EOT& _solution, Neighbor& _neighbor) {
value()++;
eval(_solution, _neighbor);
}
typedef typename Neighbor::EOT EOT;
typedef typename EOT::Fitness Fitness;
moEvalCounter(moEval<Neighbor>& _eval, std::string _name = "Neighbor Eval. ")
: eoValueParam<unsigned long>(0, _name), eval(_eval) {}
/**
* Increase the number of neighbor evaluations and perform the evaluation
*
* @param _solution a solution
* @param _neighbor a neighbor
*/
void operator()(EOT& _solution, Neighbor& _neighbor) {
value()++;
eval(_solution, _neighbor);
}
private:
moEval<Neighbor> & eval;
moEval<Neighbor> & eval;
};

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;
};

View file

@ -36,19 +36,19 @@ Contact: paradiseo-help@lists.gforge.inria.fr
* Count the number of move, noMove and the number of successive stagnation since the last Move
*/
template< class Neighbor >
class moCountMoveMemory : virtual public moMemory<Neighbor>{
class moCountMoveMemory : virtual public moMemory<Neighbor> {
public:
typedef typename Neighbor::EOT EOT;
typedef typename Neighbor::EOT EOT;
/**
* Init all the counters
* @param _sol unused solution
*/
void init(EOT & _sol) {
nbMove=0;
nbNoMove=0;
counter=0;
nbMove=0;
nbNoMove=0;
counter=0;
}
/**
@ -56,8 +56,8 @@ public:
* @param _neighbor unused neighbor
*/
void add(EOT & _sol, Neighbor & _neighbor) {
nbMove++;
counter=0;
nbMove++;
counter=0;
}
/**
@ -65,48 +65,48 @@ public:
* @param _neighbor unused neighbor
*/
void update(EOT & _sol, Neighbor & _neighbor) {
nbNoMove++;
counter++;
nbNoMove++;
counter++;
}
/**
* ClearMemory : Reinit all the counters
*/
void clearMemory() {
nbMove=0;
nbNoMove=0;
counter=0;
nbMove=0;
nbNoMove=0;
counter=0;
}
/**
* Getter of the number of move
* @return the counter
*/
unsigned int getNbMove(){
return nbMove;
unsigned int getNbMove() {
return nbMove;
}
/**
* Getter of the number of no move
* @return the counter
*/
unsigned int getNbNoMove(){
return nbNoMove;
unsigned int getNbNoMove() {
return nbNoMove;
}
/**
* Getter of the number of successive stagnation since the last Move
* @return the counter
*/
unsigned int getCounter(){
return counter;
unsigned int getCounter() {
return counter;
}
/**
* Init counter
*/
void initCounter(){
counter=0;
void initCounter() {
counter=0;
}
private:

View file

@ -37,6 +37,6 @@ Contact: paradiseo-help@lists.gforge.inria.fr
* Abstract class for diversification strategy
*/
template< class Neighbor >
class moDiversification : virtual public moMemory<Neighbor>, public eoUF<typename Neighbor::EOT &,bool>{};
class moDiversification : virtual public moMemory<Neighbor>, public eoUF<typename Neighbor::EOT &,bool> {};
#endif

View file

@ -36,10 +36,10 @@ Contact: paradiseo-help@lists.gforge.inria.fr
* Dummy memory to make an empty memory
*/
template< class Neighbor >
class moDummyMemory : virtual public moMemory<Neighbor>{
class moDummyMemory : virtual public moMemory<Neighbor> {
public:
typedef typename Neighbor::EOT EOT;
typedef typename Neighbor::EOT EOT;
/**
* Init : NOTHIING TO DO

View file

@ -37,6 +37,6 @@ Contact: paradiseo-help@lists.gforge.inria.fr
* Abstract class for intensification strategy
*/
template< class Neighbor >
class moIntensification : virtual public moMemory<Neighbor>, public eoUF<typename Neighbor::EOT &,bool>{};
class moIntensification : virtual public moMemory<Neighbor>, public eoUF<typename Neighbor::EOT &,bool> {};
#endif

View file

@ -45,28 +45,28 @@ class moMonOpDiversification : public moDiversification<Neighbor>, public moDumm
public:
typedef typename Neighbor::EOT EOT;
/**
* Default Constructor
* @param _monOp an eoMonOp (diversification operator)
* @param _fullEval a full evaluation function
*/
moMonOpDiversification(eoMonOp<EOT>& _monOp, eoEvalFunc<EOT>& _fullEval):monOp(_monOp), fullEval(_fullEval){}
/**
* Default Constructor
* @param _monOp an eoMonOp (diversification operator)
* @param _fullEval a full evaluation function
*/
moMonOpDiversification(eoMonOp<EOT>& _monOp, eoEvalFunc<EOT>& _fullEval):monOp(_monOp), fullEval(_fullEval) {}
/**
* Apply monOp on the solution
* @param _solution to diversify
* @return value of monOp
*/
bool operator()(EOT& _solution){
bool res = monOp(_solution);
fullEval(_solution);
return res;
}
/**
* Apply monOp on the solution
* @param _solution to diversify
* @return value of monOp
*/
bool operator()(EOT& _solution) {
bool res = monOp(_solution);
fullEval(_solution);
return res;
}
private:
/** monOp */
eoMonOp<EOT>& monOp;
eoEvalFunc<EOT>& fullEval;
/** monOp */
eoMonOp<EOT>& monOp;
eoEvalFunc<EOT>& fullEval;
};
#endif

View file

@ -88,10 +88,10 @@ public:
* @param _neighbor the current neighbor (unused)
*/
virtual void update(EOT & _sol, Neighbor & _neighbor) {
if(howlong > 0)
for (unsigned int i=0; i<tabuList.size(); i++)
if(tabuList[i].second > 0)
tabuList[i].second--;
if (howlong > 0)
for (unsigned int i=0; i<tabuList.size(); i++)
if (tabuList[i].second > 0)
tabuList[i].second--;
}
/**

View file

@ -88,10 +88,10 @@ public:
* @param _neighbor the current neighbor (unused)
*/
virtual void update(EOT & _sol, Neighbor & _neighbor) {
if(howlong > 0)
for (unsigned int i=0; i<tabuList.size(); i++)
if(tabuList[i].second > 0)
tabuList[i].second--;
if (howlong > 0)
for (unsigned int i=0; i<tabuList.size(); i++)
if (tabuList[i].second > 0)
tabuList[i].second--;
}
/**

View file

@ -39,7 +39,7 @@ template< class EOT >
class moBackwardVariableNeighborhood : public moVariableNeighborhood<EOT>
{
public:
typedef moNeighbor<EOT> Neighbor;
typedef moNeighbor<EOT> Neighbor;
using moVariableNeighborhood<EOT>::currentNH;
using moVariableNeighborhood<EOT>::neighborhoodVector;
@ -63,21 +63,21 @@ public:
* @return true if there is some neighborhood to explore
*/
virtual bool contNeighborhood() {
return (currentNH > 0);
return (currentNH > 0);
}
/**
* put the current neighborhood on the last one
*/
virtual void initNeighborhood() {
currentNH = neighborhoodVector.size() - 1;
currentNH = neighborhoodVector.size() - 1;
}
/**
* put the current neighborhood on the next one
*/
virtual void nextNeighborhood() {
currentNH--;
currentNH--;
}
};

View file

@ -36,13 +36,13 @@ Contact: paradiseo-help@lists.gforge.inria.fr
* Dummy Neighborhood
*/
template< class EOT >
class moDummyNeighbor : public moNeighbor< EOT >{
class moDummyNeighbor : public moNeighbor< EOT > {
public:
/**
* NOTHING TO DO
* @param _solution the related solution
*/
virtual void move(EOT& _solution){}
virtual void move(EOT& _solution) {}
};
#endif

View file

@ -37,7 +37,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
* Dummy Neighborhood
*/
template< class Neighbor >
class moDummyNeighborhood : public moNeighborhood<Neighbor>{
class moDummyNeighborhood : public moNeighborhood<Neighbor> {
public:
typedef typename Neighbor::EOT EOT;
@ -46,8 +46,8 @@ public:
* @param _solution a solution (unused)
* @return always false
*/
virtual bool hasNeighbor(EOT & _solution){
return false;
virtual bool hasNeighbor(EOT & _solution) {
return false;
}
/**
@ -55,22 +55,22 @@ public:
* @param _solution a solution (unused)
* @param _current a neighbor (unused)
*/
virtual void init(EOT & _solution, Neighbor & _current){}
virtual void init(EOT & _solution, Neighbor & _current) {}
/**
* NOTHING TO DO
* @param _solution a solution (unused)
* @param _current a neighbor (unused)
*/
virtual void next(EOT & _solution, Neighbor & _current){}
virtual void next(EOT & _solution, Neighbor & _current) {}
/**
* NOTHING TO DO
* @param _solution a solution (unused)
* @return always false
*/
virtual bool cont(EOT & _solution){
return false;
virtual bool cont(EOT & _solution) {
return false;
}
};

View file

@ -40,7 +40,7 @@ class moForwardVariableNeighborhood : public moVariableNeighborhood<EOT>
{
public:
typedef moNeighbor<EOT> Neighbor;
typedef moNeighbor<EOT> Neighbor;
using moVariableNeighborhood<EOT>::currentNH;
using moVariableNeighborhood<EOT>::neighborhoodVector;
@ -64,21 +64,21 @@ public:
* @return true if there is some neighborhood to explore
*/
virtual bool contNeighborhood() {
return (currentNH < neighborhoodVector.size() - 1);
return (currentNH < neighborhoodVector.size() - 1);
}
/**
* put the current neighborhood on the first one
*/
virtual void initNeighborhood() {
currentNH = 0;
currentNH = 0;
}
/**
* put the current neighborhood on the next one
*/
virtual void nextNeighborhood() {
currentNH++;
currentNH++;
}
};

View file

@ -98,8 +98,8 @@ public:
* @param _neighbor a neighbor
* @return if _neighbor and this one are equals
*/
virtual bool equals(moIndexNeighbor<EOT>& _neighbor){
return (key==_neighbor.index());
virtual bool equals(moIndexNeighbor<EOT>& _neighbor) {
return (key==_neighbor.index());
}
protected:

View file

@ -107,8 +107,8 @@ public:
* @param _neighbor a neighbor
* @return if _neighbor and this one are equals
*/
virtual bool equals(moNeighbor<EOT>& _neighbor){
return false;
virtual bool equals(moNeighbor<EOT>& _neighbor) {
return false;
}
/**

View file

@ -40,9 +40,9 @@ class moRndNeighborhood : virtual public moNeighborhood<Neighbor> {
public:
/**
* @return true
*/
/**
* @return true
*/
bool isRandom() {
return true;
}

View file

@ -40,7 +40,7 @@ template< class EOT, class Fitness >
class moRndVariableNeighborhood : public moVariableNeighborhood<EOT, Fitness>
{
public:
typedef moNeighbor<EOT, Fitness> Neighbor;
typedef moNeighbor<EOT, Fitness> Neighbor;
using moVariableNeighborhood<EOT, Fitness>::currentNH;
using moVariableNeighborhood<EOT, Fitness>::neighborhoodVector;
@ -50,7 +50,7 @@ public:
* @param _firstNH first neighborhood in the vector
*/
moRndVariableNeighborhood(moNeighborhood<Neighbor>& _firstNH) : moVariableNeighborhood<EOT, Fitness>(_firstNH) {
indexVector.push_back(0);
indexVector.push_back(0);
}
/**
@ -58,8 +58,8 @@ public:
* @param _nh the neighborhood to add at the end of the vector of neighborhood
*/
virtual void add(moNeighborhood<Neighbor>& _nh) {
neighborhoodVector.push_back(_nh);
indexVector.push_back(indexVector.size());
neighborhoodVector.push_back(_nh);
indexVector.push_back(indexVector.size());
}
@ -76,24 +76,24 @@ public:
* @return true if there is some neighborhood to explore
*/
virtual bool contNeighborhood() {
return (index < neighborhoodVector.size() - 1);
return (index < neighborhoodVector.size() - 1);
}
/**
* put the current neighborhood on the first one
*/
virtual void initNeighborhood() {
std::random_shuffle(indexVector.begin(), indexVector.end());
index = 0;
currentNH = indexVector[index];
std::random_shuffle(indexVector.begin(), indexVector.end());
index = 0;
currentNH = indexVector[index];
}
/**
* put the current neighborhood on the next one
*/
virtual void nextNeighborhood() {
index++;
currentNH = indexVector[index];
index++;
currentNH = indexVector[index];
}
private:

View file

@ -43,15 +43,15 @@ class moVariableNeighborhood : public moNeighborhood<moNeighbor<EOT> >
{
public:
typedef moNeighbor<EOT> Neighbor;
typedef moNeighbor<EOT> Neighbor;
/**
* Construction of at least one neighborhood
* @param _firstNH first neighborhood in the vector
*/
moVariableNeighborhood(moNeighborhood<Neighbor>& _firstNH) {
neighborhoodVector.push_back(&_firstNH);
// the current neighborhood
currentNH = 0;
neighborhoodVector.push_back(&_firstNH);
// the current neighborhood
currentNH = 0;
}
/**
@ -67,7 +67,7 @@ public:
* @return if _solution has a Neighbor in the current neighborhood
*/
virtual bool hasNeighbor(EOT & _solution) {
return neighborhoodVector[currentNH]->hasNeighbor(_solution);
return neighborhoodVector[currentNH]->hasNeighbor(_solution);
}
/**
@ -76,7 +76,7 @@ public:
* @param _current the first neighbor in the current neighborhood
*/
virtual void init(EOT & _solution, Neighbor & _current) {
neighborhoodVector[currentNH]->init(_solution, _current);
neighborhoodVector[currentNH]->init(_solution, _current);
}
/**
@ -85,7 +85,7 @@ public:
* @param _current the next neighbor in the current neighborhood
*/
virtual void next(EOT & _solution, Neighbor & _current) {
neighborhoodVector[currentNH]->next(_solution, _current);
neighborhoodVector[currentNH]->next(_solution, _current);
}
/**
@ -94,7 +94,7 @@ public:
* @return if there is still a neighbor not explored in the current neighborhood
*/
virtual bool cont(EOT & _solution) {
return neighborhoodVector[currentNH]->cont(_solution);
return neighborhoodVector[currentNH]->cont(_solution);
}
/**
@ -110,7 +110,7 @@ public:
* @param _nh the neighborhood to add at the end of the vector of neighborhood
*/
virtual void add(moNeighborhood<Neighbor>& _nh) {
neighborhoodVector.push_back(&_nh);
neighborhoodVector.push_back(&_nh);
}
/**

View file

@ -39,28 +39,28 @@ Contact: paradiseo-help@lists.gforge.inria.fr
template< class Neighbor >
class moLocalSearchInit : public eoInit<typename Neighbor::EOT> {
public:
typedef typename Neighbor::EOT EOT;
/**
* Default Constructor
* @param _init initialization of the solution before the local search
* @param _ls the local search to apply to the solution
*/
moLocalSearchInit(eoInit<EOT>& _init, moLocalSearch<Neighbor>& _ls) : init(_init), ls(_ls) {
}
/**
* Apply the local search on the solution
* @param _solution to perturb
*/
void operator()(EOT& _solution){
init(_solution);
ls(_solution);
}
typedef typename Neighbor::EOT EOT;
/**
* Default Constructor
* @param _init initialization of the solution before the local search
* @param _ls the local search to apply to the solution
*/
moLocalSearchInit(eoInit<EOT>& _init, moLocalSearch<Neighbor>& _ls) : init(_init), ls(_ls) {
}
/**
* Apply the local search on the solution
* @param _solution to perturb
*/
void operator()(EOT& _solution) {
init(_solution);
ls(_solution);
}
private:
eoInit<EOT>& init;
moLocalSearch<Neighbor> & ls;
eoInit<EOT>& init;
moLocalSearch<Neighbor> & ls;
};
#endif

View file

@ -42,30 +42,30 @@ template< class Neighbor >
class moMonOpPerturb : public moPerturbation<Neighbor>, public moDummyMemory<Neighbor> {
public:
typedef typename Neighbor::EOT EOT;
typedef typename Neighbor::EOT EOT;
/**
* Default Constructor
* @param _monOp an eoMonOp (pertubation operator)
* @param _fullEval a full evaluation function
*/
moMonOpPerturb(eoMonOp<EOT>& _monOp, eoEvalFunc<EOT>& _fullEval):monOp(_monOp), fullEval(_fullEval){}
/**
* Default Constructor
* @param _monOp an eoMonOp (pertubation operator)
* @param _fullEval a full evaluation function
*/
moMonOpPerturb(eoMonOp<EOT>& _monOp, eoEvalFunc<EOT>& _fullEval):monOp(_monOp), fullEval(_fullEval) {}
/**
* Apply monOp on the solution
* @param _solution to perturb
* @return value of monOp
*/
bool operator()(EOT& _solution){
bool res = monOp(_solution);
fullEval(_solution);
return res;
}
/**
* Apply monOp on the solution
* @param _solution to perturb
* @return value of monOp
*/
bool operator()(EOT& _solution) {
bool res = monOp(_solution);
fullEval(_solution);
return res;
}
private:
/** monOp */
eoMonOp<EOT>& monOp;
eoEvalFunc<EOT>& fullEval;
/** monOp */
eoMonOp<EOT>& monOp;
eoEvalFunc<EOT>& fullEval;
};
#endif

View file

@ -38,40 +38,40 @@ Contact: paradiseo-help@lists.gforge.inria.fr
* Neighborhood Perturbation: explore the neighborhood to perturb the solution (the neighborhood could be different as the one used in the Local Search)
*/
template< class Neighbor, class OtherNeighbor >
class moNeighborhoodPerturb : public moPerturbation<Neighbor>{
class moNeighborhoodPerturb : public moPerturbation<Neighbor> {
public:
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<OtherNeighbor> OtherNH;
typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<OtherNeighbor> OtherNH;
/**
* Default Constructor
* @param _otherNeighborhood a neighborhood
* @param _eval an Evaluation Function
*/
moNeighborhoodPerturb(OtherNH& _otherNeighborhood, moEval<OtherNeighbor>& _eval): otherNeighborhood(_otherNeighborhood), eval(_eval){}
/**
* Default Constructor
* @param _otherNeighborhood a neighborhood
* @param _eval an Evaluation Function
*/
moNeighborhoodPerturb(OtherNH& _otherNeighborhood, moEval<OtherNeighbor>& _eval): otherNeighborhood(_otherNeighborhood), eval(_eval) {}
/**
* Apply move on the solution
* @param _solution the current solution
* @return true
*/
virtual bool operator()(EOT& _solution){
if(otherNeighborhood.hasNeighbor(_solution)){
eval(_solution, current);
current.move(_solution);
_solution.fitness(current.fitness());
}
return true;
}
/**
* Apply move on the solution
* @param _solution the current solution
* @return true
*/
virtual bool operator()(EOT& _solution) {
if (otherNeighborhood.hasNeighbor(_solution)) {
eval(_solution, current);
current.move(_solution);
_solution.fitness(current.fitness());
}
return true;
}
/**
* Init the neighborhood
* @param _sol the current solution
*/
virtual void init(EOT & _sol){
if(otherNeighborhood.hasNeighbor(_sol))
otherNeighborhood.init(_sol, current);
virtual void init(EOT & _sol) {
if (otherNeighborhood.hasNeighbor(_sol))
otherNeighborhood.init(_sol, current);
}
/**
@ -79,8 +79,8 @@ public:
* @param _sol the current solution
* @param _neighbor unused neighbor (always empty)
*/
virtual void add(EOT & _sol, Neighbor & _neighbor){
(*this).init(_sol);
virtual void add(EOT & _sol, Neighbor & _neighbor) {
(*this).init(_sol);
}
/**
@ -88,22 +88,22 @@ public:
* @param _sol the current solution
* @param _neighbor unused neighbor (always empty)
*/
virtual void update(EOT & _sol, Neighbor & _neighbor){
if(otherNeighborhood.cont(_sol))
otherNeighborhood.next(_sol, current);
else
(*this).init(_sol);
virtual void update(EOT & _sol, Neighbor & _neighbor) {
if (otherNeighborhood.cont(_sol))
otherNeighborhood.next(_sol, current);
else
(*this).init(_sol);
}
/**
* NOTHING TO DO
*/
virtual void clearMemory(){}
virtual void clearMemory() {}
private:
OtherNH& otherNeighborhood;
moEval<OtherNeighbor>& eval;
OtherNeighbor current;
OtherNH& otherNeighborhood;
moEval<OtherNeighbor>& eval;
OtherNeighbor current;
};
#endif

View file

@ -43,34 +43,34 @@ template< class Neighbor >
class moRestartPerturb : public moPerturbation<Neighbor>, public moCountMoveMemory<Neighbor> {
public:
typedef typename Neighbor::EOT EOT;
typedef typename Neighbor::EOT EOT;
/**
* Default Constructor
* @param _initializer an initializer of solution
* @param _fullEval a full evaluation function
* @param _threshold maximum number of iteration with no improvement
*/
moRestartPerturb(eoInit<EOT>& _initializer, eoEvalFunc<EOT>& _fullEval, unsigned int _threshold):initializer(_initializer), fullEval(_fullEval), threshold(_threshold) {}
/**
* Default Constructor
* @param _initializer an initializer of solution
* @param _fullEval a full evaluation function
* @param _threshold maximum number of iteration with no improvement
*/
moRestartPerturb(eoInit<EOT>& _initializer, eoEvalFunc<EOT>& _fullEval, unsigned int _threshold):initializer(_initializer), fullEval(_fullEval), threshold(_threshold) {}
/**
* Apply restart when necessary
* @param _solution to restart
* @return true
*/
bool operator()(EOT& _solution){
if((*this).getCounter()>= threshold){
initializer(_solution);
fullEval(_solution);
(*this).initCounter();
}
return true;
}
/**
* Apply restart when necessary
* @param _solution to restart
* @return true
*/
bool operator()(EOT& _solution) {
if ((*this).getCounter()>= threshold) {
initializer(_solution);
fullEval(_solution);
(*this).initCounter();
}
return true;
}
private:
eoInit<EOT>& initializer;
eoEvalFunc<EOT>& fullEval;
unsigned int threshold;
eoInit<EOT>& initializer;
eoEvalFunc<EOT>& fullEval;
unsigned int threshold;
};

View file

@ -39,22 +39,22 @@ template< class EOT >
class moSolInit : public eoInit<EOT> {
public:
/**
* Default Constructor
* @param _extSol external solution of the intiialization
*/
moSolInit(EOT & _extSol) : extSol(_extSol) {}
/**
* Initialization on the externatl solution
* @param _solution to initialize
*/
void operator()(EOT& _solution){
_solution = extSol;
}
/**
* Default Constructor
* @param _extSol external solution of the intiialization
*/
moSolInit(EOT & _extSol) : extSol(_extSol) {}
/**
* Initialization on the externatl solution
* @param _solution to initialize
*/
void operator()(EOT& _solution) {
_solution = extSol;
}
private:
EOT& extSol;
EOT& extSol;
};
#endif

View file

@ -39,83 +39,83 @@ Contact: paradiseo-help@lists.gforge.inria.fr
template <class Neighbor>
class moMaxSATincrEval : public moEval <Neighbor> {
public :
typedef typename Neighbor::EOT EOT;
moMaxSATincrEval(MaxSATeval<EOT> & _fulleval) : fulleval(_fulleval) {
nbClauses = _fulleval.nbClauses;
nbVar = _fulleval.nbVar;
typedef typename Neighbor::EOT EOT;
clauses = _fulleval.clauses;
variables = _fulleval.variables;
}
moMaxSATincrEval(MaxSATeval<EOT> & _fulleval) : fulleval(_fulleval) {
nbClauses = _fulleval.nbClauses;
nbVar = _fulleval.nbVar;
/*
* incremental evaluation of the neighbor for the max SAT problem
* @param _solution the solution (of type bit string) to move
* @param _neighbor the neighbor (of type moBitNeigbor) to consider
*/
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
// the difference of fitness
int delta = 0;
// the flipped bit
unsigned int bit = _neighbor.index();
// clauses which can be modified by the flipped bit
const vector<int> & modifiedClauses = variables[bit + 1] ; // remember that the variables start at index 1 and not 0
unsigned int size = modifiedClauses.size();
int nc;
bool litt;
for(unsigned int k = 0; k < size; k++) {
// number of the clause
nc = modifiedClauses[k];
// negative means that the not(variable) is in the clause
if (nc < 0) {
nc = - nc;
litt = !_solution[bit];
} else
litt = _solution[bit];
if (litt) {
// the litteral was true and becomes false
_solution[bit] = !_solution[bit];
if (!fulleval.clauseEval(nc, _solution))
// the clause was true and becomes false
delta--;
_solution[bit] = !_solution[bit];
} else {
// the litteral was false and becomes true
if (!fulleval.clauseEval(nc, _solution))
// the clause was false and becomes true
delta++;
}
clauses = _fulleval.clauses;
variables = _fulleval.variables;
}
/*
* incremental evaluation of the neighbor for the max SAT problem
* @param _solution the solution (of type bit string) to move
* @param _neighbor the neighbor (of type moBitNeigbor) to consider
*/
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
// the difference of fitness
int delta = 0;
// the flipped bit
unsigned int bit = _neighbor.index();
// clauses which can be modified by the flipped bit
const vector<int> & modifiedClauses = variables[bit + 1] ; // remember that the variables start at index 1 and not 0
unsigned int size = modifiedClauses.size();
int nc;
bool litt;
for (unsigned int k = 0; k < size; k++) {
// number of the clause
nc = modifiedClauses[k];
// negative means that the not(variable) is in the clause
if (nc < 0) {
nc = - nc;
litt = !_solution[bit];
} else
litt = _solution[bit];
if (litt) {
// the litteral was true and becomes false
_solution[bit] = !_solution[bit];
if (!fulleval.clauseEval(nc, _solution))
// the clause was true and becomes false
delta--;
_solution[bit] = !_solution[bit];
} else {
// the litteral was false and becomes true
if (!fulleval.clauseEval(nc, _solution))
// the clause was false and becomes true
delta++;
}
}
_neighbor.fitness(_solution.fitness() + delta);
}
_neighbor.fitness(_solution.fitness() + delta);
}
protected:
// number of variables
unsigned int nbVar;
// number of clauses
unsigned int nbClauses;
// number of variables
unsigned int nbVar;
// number of clauses
unsigned int nbClauses;
// list of clauses:
// each clause has the number of the variable (from 1 to nbVar)
// when the value, litteral = not(variable)
vector<int> * clauses;
// list of clauses:
// each clause has the number of the variable (from 1 to nbVar)
// when the value, litteral = not(variable)
vector<int> * clauses;
// list of variables:
// for each variable, the list of clauses
vector<int> * variables;
//full eval of the max SAT
MaxSATeval<EOT> & fulleval;
// list of variables:
// for each variable, the list of clauses
vector<int> * variables;
//full eval of the max SAT
MaxSATeval<EOT> & fulleval;
};
#endif

View file

@ -47,10 +47,10 @@ public:
* @param _neighbor the neighbor to consider (of type moBitNeigbor)
*/
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
if (_solution[_neighbor.index()] == 0)
_neighbor.fitness(_solution.fitness() + 1);
else
_neighbor.fitness(_solution.fitness() - 1);
if (_solution[_neighbor.index()] == 0)
_neighbor.fitness(_solution.fitness() + 1);
else
_neighbor.fitness(_solution.fitness() - 1);
}
};

View file

@ -40,48 +40,48 @@ template< class Neighbor >
class moRoyalRoadIncrEval : public moEval<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT;
typedef typename Neighbor::EOT EOT;
/**
* Default constructor
* @param _rr full evaluation of the Royal Road (to have the same block size)
*/
moRoyalRoadIncrEval(RoyalRoadEval<EOT> & _rr) : k(_rr.blockSize()) {}
/**
* Default constructor
* @param _rr full evaluation of the Royal Road (to have the same block size)
*/
moRoyalRoadIncrEval(RoyalRoadEval<EOT> & _rr) : k(_rr.blockSize()) {}
/*
* incremental evaluation of the neighbor for the Royal Road problem
* @param _solution the solution to move (bit string)
* @param _neighbor the neighbor to consider (of type moBitNeigbor)
*/
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
// which block can be changed?
unsigned int n = _neighbor.index() / k;
// complete block?
unsigned int offset = n * k;
unsigned int j = 0;
while (_solution[offset + j] && j < k) j++;
if (j == k) // the block is complete, so the fitness decreases from one
_neighbor.fitness(_solution.fitness() - 1);
else {
if ((_solution[_neighbor.index()] == 0) && (offset + j == _neighbor.index())) { // can the block be filled?
j++; // next bit
while (_solution[offset + j] && j < k) j++;
/*
* incremental evaluation of the neighbor for the Royal Road problem
* @param _solution the solution to move (bit string)
* @param _neighbor the neighbor to consider (of type moBitNeigbor)
*/
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
// which block can be changed?
unsigned int n = _neighbor.index() / k;
if (j == k) // the block can be filled, so the fitness increases from one
_neighbor.fitness(_solution.fitness() + 1);
else
_neighbor.fitness(_solution.fitness());
} else
_neighbor.fitness(_solution.fitness());
// complete block?
unsigned int offset = n * k;
unsigned int j = 0;
while (_solution[offset + j] && j < k) j++;
if (j == k) // the block is complete, so the fitness decreases from one
_neighbor.fitness(_solution.fitness() - 1);
else {
if ((_solution[_neighbor.index()] == 0) && (offset + j == _neighbor.index())) { // can the block be filled?
j++; // next bit
while (_solution[offset + j] && j < k) j++;
if (j == k) // the block can be filled, so the fitness increases from one
_neighbor.fitness(_solution.fitness() + 1);
else
_neighbor.fitness(_solution.fitness());
} else
_neighbor.fitness(_solution.fitness());
}
}
}
protected:
// size of the blocks
unsigned int k;
// size of the blocks
unsigned int k;
};
#endif

View file

@ -40,10 +40,10 @@ class oneMaxFullEval : public eoEvalFunc<EOT>
{
public:
/**
* Count the number of 1 in a bitString
* @param _sol the solution to evaluate
*/
/**
* Count the number of 1 in a bitString
* @param _sol the solution to evaluate
*/
void operator() (EOT& _sol) {
unsigned int sum = 0;
for (unsigned int i = 0; i < _sol.size(); i++)

View file

@ -40,75 +40,75 @@ class moShiftNeighbor: public moIndexNeighbor<EOT>
{
public:
using moIndexNeighbor<EOT>::key;
using moIndexNeighbor<EOT>::key;
/**
* Apply move on a solution regarding a key
* @param _sol the solution to move
*/
virtual void move(EOT & _sol){
unsigned int tmp ;
size=_sol.size();
translate(key+1);
// keep the first component to change
tmp = _sol[first];
// shift
if (first < second){
for (unsigned int i=first; i<second-1; i++)
_sol[i] = _sol[i+1];
// shift the first component
_sol[second-1] = tmp;
}
else{ /* first > second*/
for (unsigned int i=first; i>second; i--)
_sol[i] = _sol[i-1];
// shift the first component
_sol[second] = tmp;
}
_sol.invalidate();
}
/**
* Apply move on a solution regarding a key
* @param _sol the solution to move
*/
virtual void move(EOT & _sol) {
unsigned int tmp ;
size=_sol.size();
translate(key+1);
// keep the first component to change
tmp = _sol[first];
// shift
if (first < second) {
for (unsigned int i=first; i<second-1; i++)
_sol[i] = _sol[i+1];
// shift the first component
_sol[second-1] = tmp;
}
else { /* first > second*/
for (unsigned int i=first; i>second; i--)
_sol[i] = _sol[i-1];
// shift the first component
_sol[second] = tmp;
}
_sol.invalidate();
}
/**
* fix two indexes regarding a key
* @param _key the key allowing to compute the two indexes for the shift
*/
void translate(unsigned int _key){
int step;
int val = _key;
int tmpSize = size * (size-1) / 2;
// moves from left to right
if (val <= tmpSize){
step = size - 1;
first = 0;
while ((val - step) > 0){
val = val - step;
step--;
first++;
}
second = first + val + 1;
}
// moves from right to left (equivalent moves are avoided)
else{ /* val > tmpSize */
val = val - tmpSize;
step = size - 2;
second = 0;
while ((val - step) > 0){
val = val - step;
step--;
second++;
}
first = second + val + 1;
}
}
/**
* fix two indexes regarding a key
* @param _key the key allowing to compute the two indexes for the shift
*/
void translate(unsigned int _key) {
int step;
int val = _key;
int tmpSize = size * (size-1) / 2;
// moves from left to right
if (val <= tmpSize) {
step = size - 1;
first = 0;
while ((val - step) > 0) {
val = val - step;
step--;
first++;
}
second = first + val + 1;
}
// moves from right to left (equivalent moves are avoided)
else { /* val > tmpSize */
val = val - tmpSize;
step = size - 2;
second = 0;
while ((val - step) > 0) {
val = val - step;
step--;
second++;
}
first = second + val + 1;
}
}
void print(){
std::cout << key << ": [" << first << ", " << second << "] -> " << (*this).fitness() << std::endl;
}
void print() {
std::cout << key << ": [" << first << ", " << second << "] -> " << (*this).fitness() << std::endl;
}
private:
unsigned int first;
unsigned int second;
unsigned int size;
unsigned int first;
unsigned int second;
unsigned int size;
};

View file

@ -41,49 +41,49 @@ class moSwapNeighbor: public moBackableNeighbor<EOT>
{
public:
/**
* Apply the swap
* @param _solution the solution to move
*/
virtual void move(EOT& _solution){
unsigned int tmp;
tmp=_solution[indices.first];
_solution[indices.first]=_solution[indices.second];
_solution[indices.second]=tmp;
_solution.invalidate();
}
/**
* Apply the swap
* @param _solution the solution to move
*/
virtual void move(EOT& _solution) {
unsigned int tmp;
tmp=_solution[indices.first];
_solution[indices.first]=_solution[indices.second];
_solution[indices.second]=tmp;
_solution.invalidate();
}
/**
* apply the swap to restore the solution (use by moFullEvalByModif)
* @param _solution the solution to move
*/
virtual void moveBack(EOT& _solution){
unsigned int tmp;
tmp=_solution[indices.first];
_solution[indices.first]=_solution[indices.second];
_solution[indices.second]=tmp;
_solution.invalidate();
}
/**
* apply the swap to restore the solution (use by moFullEvalByModif)
* @param _solution the solution to move
*/
virtual void moveBack(EOT& _solution) {
unsigned int tmp;
tmp=_solution[indices.first];
_solution[indices.first]=_solution[indices.second];
_solution[indices.second]=tmp;
_solution.invalidate();
}
/**
* Setter to fix the two indexes to swap
* @param _first first index
* @param _second second index
*/
void setIndices(unsigned int _first, unsigned int _second){
indices.first = _first;
indices.second = _second;
}
/**
* Setter to fix the two indexes to swap
* @param _first first index
* @param _second second index
*/
void setIndices(unsigned int _first, unsigned int _second) {
indices.first = _first;
indices.second = _second;
}
/**
* Print the Neighbor
*/
void print(){
std::cout << "[" << indices.first << ", " << indices.second << "] -> " << (*this).fitness() << std::endl;
}
/**
* Print the Neighbor
*/
void print() {
std::cout << "[" << indices.first << ", " << indices.second << "] -> " << (*this).fitness() << std::endl;
}
private:
std::pair<unsigned int, unsigned int> indices;
std::pair<unsigned int, unsigned int> indices;
};

View file

@ -45,8 +45,8 @@ public:
/**
* @return if there are available Neighbor
*/
virtual bool hasNeighbor(EOT& _solution){
return (_solution.size() > 1);
virtual bool hasNeighbor(EOT& _solution) {
return (_solution.size() > 1);
};
/**
@ -54,11 +54,11 @@ public:
* @param _solution the solution to explore
* @param _current the first neighbor
*/
virtual void init(EOT& _solution, Neighbor& _current){
indices.first=0;
indices.second=1;
size=_solution.size();
_current.setIndices(0,1);
virtual void init(EOT& _solution, Neighbor& _current) {
indices.first=0;
indices.second=1;
size=_solution.size();
_current.setIndices(0,1);
}
/**
@ -66,14 +66,14 @@ public:
* @param _solution the solution to explore
* @param _current the next neighbor
*/
virtual void next(EOT& _solution, Neighbor& _current){
if(indices.second==size-1){
indices.first++;
indices.second=indices.first+1;
}
else
indices.second++;
_current.setIndices(indices.first, indices.second);
virtual void next(EOT& _solution, Neighbor& _current) {
if (indices.second==size-1) {
indices.first++;
indices.second=indices.first+1;
}
else
indices.second++;
_current.setIndices(indices.first, indices.second);
}
/**
@ -81,8 +81,8 @@ public:
* @param _solution the solution to explore
* @return if there is again a neighbor not explored
*/
virtual bool cont(EOT& _solution){
return !((indices.first == (size-2)) && (indices.second == (size-1)));
virtual bool cont(EOT& _solution) {
return !((indices.first == (size-2)) && (indices.second == (size-1)));
}
/**
@ -90,7 +90,7 @@ public:
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moSwapNeighborhood";
return "moSwapNeighborhood";
}
private:

View file

@ -46,42 +46,42 @@
* To compute the autocorrelation function:
* Perform a random walk based on the neighborhood,
* The fitness values of solutions are collected during the random walk
* The autocorrelation can be computed from the serie of fitness values
*
* The autocorrelation can be computed from the serie of fitness values
*
*/
template <class Neighbor>
class moAutocorrelationSampling : public moSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood giving neighbor in random order
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbStep Number of steps of the random walk
*/
moAutocorrelationSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbStep) :
moSampling<Neighbor>(_init, * new moRandomWalk<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep), fitnessStat){}
using moSampling<Neighbor>::localSearch;
/**
* default destructor
*/
~moAutocorrelationSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood giving neighbor in random order
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbStep Number of steps of the random walk
*/
moAutocorrelationSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbStep) :
moSampling<Neighbor>(_init, * new moRandomWalk<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep), fitnessStat) {}
/**
* default destructor
*/
~moAutocorrelationSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
protected:
moFitnessStat<EOT> fitnessStat;
moFitnessStat<EOT> fitnessStat;
};

View file

@ -42,40 +42,40 @@
#include <sampling/moSampling.h>
/**
* To compute the density of states:
* To compute the density of states:
* Sample the fitness of random solution in the search space
* The fitness values of solutions are collected during the random search
*
*
*/
template <class Neighbor>
class moDensityOfStatesSampling : public moSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _fullEval Fitness function, full evaluation function
* @param _nbSol Number of solutions in the sample
*/
moDensityOfStatesSampling(eoInit<EOT> & _init,
eoEvalFunc<EOT>& _fullEval,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat){}
using moSampling<Neighbor>::localSearch;
/**
* default destructor
*/
~moDensityOfStatesSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _fullEval Fitness function, full evaluation function
* @param _nbSol Number of solutions in the sample
*/
moDensityOfStatesSampling(eoInit<EOT> & _init,
eoEvalFunc<EOT>& _fullEval,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat) {}
/**
* default destructor
*/
~moDensityOfStatesSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
protected:
moFitnessStat<EOT> fitnessStat;
moFitnessStat<EOT> fitnessStat;
};

View file

@ -45,7 +45,7 @@
#include <sampling/moSampling.h>
/**
* To compute the fitness distance correlation:
* To compute the fitness distance correlation:
* Sample the fitness and the distance from a particular solution of random solution in the search space
* The fitness values and distances of solutions are collected during the random search
* Then the correlation between the fitness and the distance can be computed
@ -55,40 +55,40 @@ template <class Neighbor>
class moFDCsampling : public moSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _fullEval a full evaluation function
* @param _dist the distance function between solution
* @param _refSol the reference solution to compute the distance (think of global optimum when possible)
* @param _nbSol Number of solutions of the sample
*/
moFDCsampling(eoInit<EOT> & _init,
eoEvalFunc<EOT>& _fullEval,
eoDistance<EOT>& _dist,
EOT& _refSol,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat),
distStat(_dist, _refSol)
{
add(distStat);
}
using moSampling<Neighbor>::localSearch;
/**
* default destructor
*/
~moFDCsampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _fullEval a full evaluation function
* @param _dist the distance function between solution
* @param _refSol the reference solution to compute the distance (think of global optimum when possible)
* @param _nbSol Number of solutions of the sample
*/
moFDCsampling(eoInit<EOT> & _init,
eoEvalFunc<EOT>& _fullEval,
eoDistance<EOT>& _dist,
EOT& _refSol,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat),
distStat(_dist, _refSol)
{
add(distStat);
}
/**
* default destructor
*/
~moFDCsampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
protected:
moFitnessStat<EOT> fitnessStat;
moDistanceStat<EOT> distStat;
moFitnessStat<EOT> fitnessStat;
moDistanceStat<EOT> distStat;
};

View file

@ -45,8 +45,8 @@
#include <sampling/moSampling.h>
/**
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
*
* This class do nothing. See others mo(...)FitnessCloudSampling classes
* with different fitness sampling methods
@ -55,44 +55,44 @@ template <class Neighbor>
class moFitnessCloudSampling : public moSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get a neighbor
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbSol Number of solutions in the sample
*/
moFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moDummyLS<Neighbor>(_fullEval), fitnessStat),
neighborhood(_neighborhood),
fullEval(_fullEval),
eval(_eval),
nbSol(_nbSol)
{}
using moSampling<Neighbor>::localSearch;
/**
* default destructor
*/
~moFitnessCloudSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get a neighbor
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbSol Number of solutions in the sample
*/
moFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moDummyLS<Neighbor>(_fullEval), fitnessStat),
neighborhood(_neighborhood),
fullEval(_fullEval),
eval(_eval),
nbSol(_nbSol)
{}
/**
* default destructor
*/
~moFitnessCloudSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
protected:
moNeighborhood<Neighbor> & neighborhood;
eoEvalFunc<EOT>& fullEval;
moEval<Neighbor>& eval;
unsigned int nbSol;
moFitnessStat<EOT> fitnessStat;
moNeighborhood<Neighbor> & neighborhood;
eoEvalFunc<EOT>& fullEval;
moEval<Neighbor>& eval;
unsigned int nbSol;
moFitnessStat<EOT> fitnessStat;
};

View file

@ -52,58 +52,58 @@
* Perform a simple Hill-climber based on the neighborhood (adaptive walk),
* The lengths of HC are collected and the final solution which are local optima
* The adaptive walk is repeated several times
*
*
*/
template <class Neighbor>
class moHillClimberSampling : public moSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood giving neighbor in random order
* @param _fullEval a full evaluation function
* @param _eval an incremental evaluation of neighbors
* @param _nbAdaptWalk Number of adaptive walks
*/
moHillClimberSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbAdaptWalk) :
moSampling<Neighbor>(initHC, * new moRandomSearch<Neighbor>(initHC, _fullEval, _nbAdaptWalk), copyStat),
copyStat(lengthStat),
checkpoint(trueCont),
hc(_neighborhood, _fullEval, _eval, checkpoint),
initHC(_init, hc)
{
// to count the number of step in the HC
checkpoint.add(lengthStat);
using moSampling<Neighbor>::localSearch;
// add the solution into statistics
add(solStat);
}
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood giving neighbor in random order
* @param _fullEval a full evaluation function
* @param _eval an incremental evaluation of neighbors
* @param _nbAdaptWalk Number of adaptive walks
*/
moHillClimberSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbAdaptWalk) :
moSampling<Neighbor>(initHC, * new moRandomSearch<Neighbor>(initHC, _fullEval, _nbAdaptWalk), copyStat),
copyStat(lengthStat),
checkpoint(trueCont),
hc(_neighborhood, _fullEval, _eval, checkpoint),
initHC(_init, hc)
{
// to count the number of step in the HC
checkpoint.add(lengthStat);
/**
* default destructor
*/
~moHillClimberSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
// add the solution into statistics
add(solStat);
}
/**
* default destructor
*/
~moHillClimberSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
protected:
moSolutionStat<EOT> solStat;
moMinusOneCounterStat<EOT> lengthStat;
moTrueContinuator<Neighbor> trueCont;
moStatFromStat<EOT, unsigned int> copyStat;
moCheckpoint<Neighbor> checkpoint;
moSimpleHC<Neighbor> hc;
moLocalSearchInit<Neighbor> initHC;
moSolutionStat<EOT> solStat;
moMinusOneCounterStat<EOT> lengthStat;
moTrueContinuator<Neighbor> trueCont;
moStatFromStat<EOT, unsigned int> copyStat;
moCheckpoint<Neighbor> checkpoint;
moSimpleHC<Neighbor> hc;
moLocalSearchInit<Neighbor> initHC;
};

View file

@ -44,8 +44,8 @@
#include <sampling/moFitnessCloudSampling.h>
/**
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
*
* Here solution are sampled with Metropolis-Hasting method
*
@ -53,59 +53,59 @@
* and the best fitness of k random neighbor
*
* The values are collected during the Metropolis-Hasting walk
*
*
*/
template <class Neighbor>
class moMHBestFitnessCloudSampling : public moFitnessCloudSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
using moSampling<Neighbor>::checkpoint;
using moSampling<Neighbor>::monitorVec;
using moSampling<Neighbor>::continuator;
using moFitnessCloudSampling<Neighbor>::fitnessStat;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbStep Number of step of the MH sampling
*/
moMHBestFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbStep) :
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbStep),
neighborBestStat(_neighborhood, _eval)
{
// delete the dummy local search
delete localSearch;
// Metropolis-Hasting sampling
localSearch = new moMetropolisHasting<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep);
using moSampling<Neighbor>::localSearch;
using moSampling<Neighbor>::checkpoint;
using moSampling<Neighbor>::monitorVec;
using moSampling<Neighbor>::continuator;
using moFitnessCloudSampling<Neighbor>::fitnessStat;
// delete the checkpoint with the wrong continuator
delete checkpoint;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbStep Number of step of the MH sampling
*/
moMHBestFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbStep) :
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbStep),
neighborBestStat(_neighborhood, _eval)
{
// delete the dummy local search
delete localSearch;
// set the continuator
continuator = localSearch->getContinuator();
// Metropolis-Hasting sampling
localSearch = new moMetropolisHasting<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep);
// re-construction of the checkpoint
checkpoint = new moCheckpoint<Neighbor>(*continuator);
checkpoint->add(fitnessStat);
checkpoint->add(*monitorVec[0]);
// delete the checkpoint with the wrong continuator
delete checkpoint;
// one random neighbor
add(neighborBestStat);
}
// set the continuator
continuator = localSearch->getContinuator();
// re-construction of the checkpoint
checkpoint = new moCheckpoint<Neighbor>(*continuator);
checkpoint->add(fitnessStat);
checkpoint->add(*monitorVec[0]);
// one random neighbor
add(neighborBestStat);
}
protected:
moNeighborBestStat< Neighbor > neighborBestStat;
moNeighborBestStat< Neighbor > neighborBestStat;
};

View file

@ -44,8 +44,8 @@
#include <sampling/moFitnessCloudSampling.h>
/**
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
*
* Here solution are sampled with Metropolis-Hasting method
*
@ -53,59 +53,59 @@
* and the fitness of one random neighbor
*
* The values are collected during the Metropolis-Hasting walk
*
*
*/
template <class Neighbor>
class moMHRndFitnessCloudSampling : public moFitnessCloudSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
using moSampling<Neighbor>::checkpoint;
using moSampling<Neighbor>::monitorVec;
using moSampling<Neighbor>::continuator;
using moFitnessCloudSampling<Neighbor>::fitnessStat;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbStep Number of step of the MH sampling
*/
moMHRndFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbStep) :
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbStep),
neighborFitnessStat(_neighborhood, _eval)
{
// delete the dummy local search
delete localSearch;
// Metropolis-Hasting sampling
localSearch = new moMetropolisHasting<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep);
using moSampling<Neighbor>::localSearch;
using moSampling<Neighbor>::checkpoint;
using moSampling<Neighbor>::monitorVec;
using moSampling<Neighbor>::continuator;
using moFitnessCloudSampling<Neighbor>::fitnessStat;
// delete the checkpoint with the wrong continuator
delete checkpoint;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbStep Number of step of the MH sampling
*/
moMHRndFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbStep) :
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbStep),
neighborFitnessStat(_neighborhood, _eval)
{
// delete the dummy local search
delete localSearch;
// set the continuator
continuator = localSearch->getContinuator();
// Metropolis-Hasting sampling
localSearch = new moMetropolisHasting<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep);
// re-construction of the checkpoint
checkpoint = new moCheckpoint<Neighbor>(*continuator);
checkpoint->add(fitnessStat);
checkpoint->add(*monitorVec[0]);
// delete the checkpoint with the wrong continuator
delete checkpoint;
// one random neighbor
add(neighborFitnessStat);
}
// set the continuator
continuator = localSearch->getContinuator();
// re-construction of the checkpoint
checkpoint = new moCheckpoint<Neighbor>(*continuator);
checkpoint->add(fitnessStat);
checkpoint->add(*monitorVec[0]);
// one random neighbor
add(neighborFitnessStat);
}
protected:
moNeighborFitnessStat< Neighbor > neighborFitnessStat;
moNeighborFitnessStat< Neighbor > neighborFitnessStat;
};

View file

@ -46,78 +46,78 @@
#include <sampling/moSampling.h>
/**
* To compute the neutral degree:
* To compute the neutral degree:
* Sample the fitness of random solution in the search space (1er information)
* and sample the neutral degree (2nd information), i.e. the number of neighbor solutions with the same fitness value
* The values are collected during the random search
*
*
*/
template <class Neighbor>
class moNeutralDegreeSampling : public moSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to compute the neutral degree
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbSol Number of solutions in the sample
*/
moNeutralDegreeSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat),
neighborhoodStat(_neighborhood, _eval),
ndStat(neighborhoodStat)
{
add(neighborhoodStat, false);
add(ndStat);
}
using moSampling<Neighbor>::localSearch;
/**
* Constructor with comparators
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to compute the neutral degree
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _neighborComparator a neighbor Comparator
* @param _solNeighborComparator a comparator between a solution and a neighbor
* @param _nbSol Number of solutions in the sample
*/
moNeutralDegreeSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
moNeighborComparator<Neighbor>& _neighborComparator,
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat),
neighborhoodStat(_neighborhood, _eval, _neighborComparator, _solNeighborComparator),
ndStat(neighborhoodStat)
{
add(neighborhoodStat, false);
add(ndStat);
}
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to compute the neutral degree
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbSol Number of solutions in the sample
*/
moNeutralDegreeSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat),
neighborhoodStat(_neighborhood, _eval),
ndStat(neighborhoodStat)
{
add(neighborhoodStat, false);
add(ndStat);
}
/**
* default destructor
*/
~moNeutralDegreeSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
/**
* Constructor with comparators
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to compute the neutral degree
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _neighborComparator a neighbor Comparator
* @param _solNeighborComparator a comparator between a solution and a neighbor
* @param _nbSol Number of solutions in the sample
*/
moNeutralDegreeSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
moNeighborComparator<Neighbor>& _neighborComparator,
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
unsigned int _nbSol) :
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat),
neighborhoodStat(_neighborhood, _eval, _neighborComparator, _solNeighborComparator),
ndStat(neighborhoodStat)
{
add(neighborhoodStat, false);
add(ndStat);
}
/**
* default destructor
*/
~moNeutralDegreeSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
protected:
moFitnessStat<EOT> fitnessStat;
moNeighborhoodStat< Neighbor > neighborhoodStat;
moNeutralDegreeNeighborStat< Neighbor > ndStat;
moFitnessStat<EOT> fitnessStat;
moNeighborhoodStat< Neighbor > neighborhoodStat;
moNeutralDegreeNeighborStat< Neighbor > ndStat;
};

View file

@ -58,8 +58,8 @@
* To explore the evolvability of solutions in a neutral networks:
* Perform a random neutral walk based on the neighborhood,
* The measures of evolvability of solutions are collected during the random neutral walk
* The distribution and autocorrelation can be computed from the serie of values
*
* The distribution and autocorrelation can be computed from the serie of values
*
* Informations collected:
* - the current solution of the walk
* - the distance from the starting solution
@ -76,71 +76,71 @@ template <class Neighbor>
class moNeutralWalkSampling : public moSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _initSol the first the solution of the walk
* @param _neighborhood neighborhood giving neighbor in random order
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _distance the distance to measure the distance from the initial solution
* @param _nbStep Number of steps of the random walk
*/
moNeutralWalkSampling(EOT & _initSol,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
eoDistance<EOT> & _distance,
unsigned int _nbStep) :
moSampling<Neighbor>(init, * new moRandomNeutralWalk<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep), solutionStat),
init(_initSol),
distStat(_distance, _initSol),
neighborhoodStat(_neighborhood, _eval),
minStat(neighborhoodStat),
averageStat(neighborhoodStat),
stdStat(neighborhoodStat),
maxStat(neighborhoodStat),
nbSupStat(neighborhoodStat),
nbInfStat(neighborhoodStat),
sizeStat(neighborhoodStat),
ndStat(neighborhoodStat)
{
add(neighborhoodStat, false);
add(distStat);
add(minStat);
add(averageStat);
add(stdStat);
add(maxStat);
add(sizeStat);
add(nbInfStat);
add(ndStat);
add(nbSupStat);
}
using moSampling<Neighbor>::localSearch;
/**
* default destructor
*/
~moNeutralWalkSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
/**
* Default Constructor
* @param _initSol the first the solution of the walk
* @param _neighborhood neighborhood giving neighbor in random order
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _distance the distance to measure the distance from the initial solution
* @param _nbStep Number of steps of the random walk
*/
moNeutralWalkSampling(EOT & _initSol,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
eoDistance<EOT> & _distance,
unsigned int _nbStep) :
moSampling<Neighbor>(init, * new moRandomNeutralWalk<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep), solutionStat),
init(_initSol),
distStat(_distance, _initSol),
neighborhoodStat(_neighborhood, _eval),
minStat(neighborhoodStat),
averageStat(neighborhoodStat),
stdStat(neighborhoodStat),
maxStat(neighborhoodStat),
nbSupStat(neighborhoodStat),
nbInfStat(neighborhoodStat),
sizeStat(neighborhoodStat),
ndStat(neighborhoodStat)
{
add(neighborhoodStat, false);
add(distStat);
add(minStat);
add(averageStat);
add(stdStat);
add(maxStat);
add(sizeStat);
add(nbInfStat);
add(ndStat);
add(nbSupStat);
}
/**
* default destructor
*/
~moNeutralWalkSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
protected:
moSolInit<EOT> init;
moSolutionStat<EOT> solutionStat;
moDistanceStat<EOT> distStat;
moNeighborhoodStat< Neighbor > neighborhoodStat;
moMinNeighborStat< Neighbor > minStat;
moAverageFitnessNeighborStat< Neighbor > averageStat;
moStdFitnessNeighborStat< Neighbor > stdStat;
moMaxNeighborStat< Neighbor > maxStat;
moNbSupNeighborStat< Neighbor > nbSupStat;
moNbInfNeighborStat< Neighbor > nbInfStat;
moSizeNeighborStat< Neighbor > sizeStat;
moNeutralDegreeNeighborStat< Neighbor > ndStat;
moSolInit<EOT> init;
moSolutionStat<EOT> solutionStat;
moDistanceStat<EOT> distStat;
moNeighborhoodStat< Neighbor > neighborhoodStat;
moMinNeighborStat< Neighbor > minStat;
moAverageFitnessNeighborStat< Neighbor > averageStat;
moStdFitnessNeighborStat< Neighbor > stdStat;
moMaxNeighborStat< Neighbor > maxStat;
moNbSupNeighborStat< Neighbor > nbSupStat;
moNbInfNeighborStat< Neighbor > nbInfStat;
moSizeNeighborStat< Neighbor > sizeStat;
moNeutralDegreeNeighborStat< Neighbor > ndStat;
};

View file

@ -44,66 +44,66 @@
#include <sampling/moFitnessCloudSampling.h>
/**
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
*
* Sample the fitness of random solution in the search space
* and the best fitness of k random neighbor
*
* The values are collected during the random search
*
*
*/
template <class Neighbor>
class moRndBestFitnessCloudSampling : public moFitnessCloudSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
using moSampling<Neighbor>::checkpoint;
using moSampling<Neighbor>::monitorVec;
using moSampling<Neighbor>::continuator;
using moFitnessCloudSampling<Neighbor>::fitnessStat;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbSol Number of solutions in the sample
*/
moRndBestFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbSol) :
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbSol),
neighborBestStat(_neighborhood, _eval)
{
// delete the dummy local search
delete localSearch;
// random sampling
localSearch = new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol);
using moSampling<Neighbor>::localSearch;
using moSampling<Neighbor>::checkpoint;
using moSampling<Neighbor>::monitorVec;
using moSampling<Neighbor>::continuator;
using moFitnessCloudSampling<Neighbor>::fitnessStat;
// delete the checkpoint with the wrong continuator
delete checkpoint;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbSol Number of solutions in the sample
*/
moRndBestFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbSol) :
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbSol),
neighborBestStat(_neighborhood, _eval)
{
// delete the dummy local search
delete localSearch;
// set the continuator
continuator = localSearch->getContinuator();
// random sampling
localSearch = new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol);
// re-construction of the checkpoint
checkpoint = new moCheckpoint<Neighbor>(*continuator);
checkpoint->add(fitnessStat);
checkpoint->add(*monitorVec[0]);
// delete the checkpoint with the wrong continuator
delete checkpoint;
// one random neighbor
add(neighborBestStat);
}
// set the continuator
continuator = localSearch->getContinuator();
// re-construction of the checkpoint
checkpoint = new moCheckpoint<Neighbor>(*continuator);
checkpoint->add(fitnessStat);
checkpoint->add(*monitorVec[0]);
// one random neighbor
add(neighborBestStat);
}
protected:
moNeighborBestStat< Neighbor > neighborBestStat;
moNeighborBestStat< Neighbor > neighborBestStat;
};

View file

@ -44,66 +44,66 @@
#include <sampling/moFitnessCloudSampling.h>
/**
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
* To compute an estimation of the fitness cloud,
* i.e. the scatter plot of solution fitness versus neighbor fitness:
*
* Sample the fitness of random solution in the search space
* and the fitness of one random neighbor
*
* The values are collected during the random search
*
*
*/
template <class Neighbor>
class moRndRndFitnessCloudSampling : public moFitnessCloudSampling<Neighbor>
{
public:
typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
using moSampling<Neighbor>::checkpoint;
using moSampling<Neighbor>::monitorVec;
using moSampling<Neighbor>::continuator;
using moFitnessCloudSampling<Neighbor>::fitnessStat;
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbSol Number of solutions in the sample
*/
moRndRndFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbSol) :
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbSol),
neighborFitnessStat(_neighborhood, _eval)
{
// delete the dummy local search
delete localSearch;
// random sampling
localSearch = new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol);
using moSampling<Neighbor>::localSearch;
using moSampling<Neighbor>::checkpoint;
using moSampling<Neighbor>::monitorVec;
using moSampling<Neighbor>::continuator;
using moFitnessCloudSampling<Neighbor>::fitnessStat;
// delete the checkpoint with the wrong continuator
delete checkpoint;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
* @param _fullEval Fitness function, full evaluation function
* @param _eval neighbor evaluation, incremental evaluation function
* @param _nbSol Number of solutions in the sample
*/
moRndRndFitnessCloudSampling(eoInit<EOT> & _init,
moNeighborhood<Neighbor> & _neighborhood,
eoEvalFunc<EOT>& _fullEval,
moEval<Neighbor>& _eval,
unsigned int _nbSol) :
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbSol),
neighborFitnessStat(_neighborhood, _eval)
{
// delete the dummy local search
delete localSearch;
// set the continuator
continuator = localSearch->getContinuator();
// random sampling
localSearch = new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol);
// re-construction of the checkpoint
checkpoint = new moCheckpoint<Neighbor>(*continuator);
checkpoint->add(fitnessStat);
checkpoint->add(*monitorVec[0]);
// delete the checkpoint with the wrong continuator
delete checkpoint;
// one random neighbor
add(neighborFitnessStat);
}
// set the continuator
continuator = localSearch->getContinuator();
// re-construction of the checkpoint
checkpoint = new moCheckpoint<Neighbor>(*continuator);
checkpoint->add(fitnessStat);
checkpoint->add(*monitorVec[0]);
// one random neighbor
add(neighborFitnessStat);
}
protected:
moNeighborFitnessStat< Neighbor > neighborFitnessStat;
moNeighborFitnessStat< Neighbor > neighborFitnessStat;
};

View file

@ -51,159 +51,159 @@
* To sample the search space:
* A local search is used to sample the search space
* Some statistics are computed at each step of the local search
*
*
* Can be used to study the fitness landscape
*/
template <class Neighbor>
class moSampling : public eoF<void>
{
public:
typedef typename Neighbor::EOT EOT ;
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _localSearch local search to sample the search space
* @param _stat statistic to compute during the search
* @param _monitoring the statistic is saved into the monitor if true
*/
template <class ValueType>
moSampling(eoInit<EOT> & _init, moLocalSearch<Neighbor> & _localSearch, moStat<EOT,ValueType> & _stat, bool _monitoring = true) : init(_init), localSearch(&_localSearch), continuator(_localSearch.getContinuator())
{
checkpoint = new moCheckpoint<Neighbor>(*continuator);
add(_stat, _monitoring);
}
typedef typename Neighbor::EOT EOT ;
/**
* default destructor
*/
~moSampling() {
// delete all monitors
for(unsigned i = 0; i < monitorVec.size(); i++)
delete monitorVec[i];
// delete the checkpoint
delete checkpoint ;
}
/**
* Add a statistic
* @param _stat another statistic to compute during the search
* @param _monitoring the statistic is saved into the monitor if true
*/
template< class ValueType >
void add(moStat<EOT, ValueType> & _stat, bool _monitoring = true) {
checkpoint->add(_stat);
if (_monitoring) {
moVectorMonitor<EOT> * monitor = new moVectorMonitor<EOT>(_stat);
monitorVec.push_back(monitor);
checkpoint->add(*monitor);
/**
* Default Constructor
* @param _init initialisation method of the solution
* @param _localSearch local search to sample the search space
* @param _stat statistic to compute during the search
* @param _monitoring the statistic is saved into the monitor if true
*/
template <class ValueType>
moSampling(eoInit<EOT> & _init, moLocalSearch<Neighbor> & _localSearch, moStat<EOT,ValueType> & _stat, bool _monitoring = true) : init(_init), localSearch(&_localSearch), continuator(_localSearch.getContinuator())
{
checkpoint = new moCheckpoint<Neighbor>(*continuator);
add(_stat, _monitoring);
}
}
/**
* To sample the search and get the statistics
* the statistics are stored in the moVectorMonitor vector
*/
void operator()(void) {
// clear all statistic vectors
for(unsigned i = 0; i < monitorVec.size(); i++)
monitorVec[i]->clear();
/**
* default destructor
*/
~moSampling() {
// delete all monitors
for (unsigned i = 0; i < monitorVec.size(); i++)
delete monitorVec[i];
// change the checkpoint to compute the statistics
localSearch->setContinuator(*checkpoint);
// the initial solution
EOT solution;
// initialisation of the solution
init(solution);
// compute the sampling
(*localSearch)(solution);
// set back to initial continuator
localSearch->setContinuator(*continuator);
}
/**
* to export the vectors of values into one file
* @param _filename file name
* @param _delim delimiter between statistics
*/
void fileExport(std::string _filename, std::string _delim = " ") {
// create file
std::ofstream os(_filename.c_str());
if (!os) {
std::string str = "moSampling: Could not open " + _filename;
throw std::runtime_error(str);
// delete the checkpoint
delete checkpoint ;
}
// all vector have the same size
unsigned vecSize = monitorVec[0]->size();
for(unsigned int i = 0; i < vecSize; i++) {
os << monitorVec[0]->getValue(i);
for(unsigned int j = 1; j < monitorVec.size(); j++) {
os << _delim.c_str() << monitorVec[j]->getValue(i);
}
os << std::endl ;
/**
* Add a statistic
* @param _stat another statistic to compute during the search
* @param _monitoring the statistic is saved into the monitor if true
*/
template< class ValueType >
void add(moStat<EOT, ValueType> & _stat, bool _monitoring = true) {
checkpoint->add(_stat);
if (_monitoring) {
moVectorMonitor<EOT> * monitor = new moVectorMonitor<EOT>(_stat);
monitorVec.push_back(monitor);
checkpoint->add(*monitor);
}
}
}
/**
* to export one vector of values into a file
* @param _col number of vector to print into file
* @param _filename file name
*/
void fileExport(unsigned int _col, std::string _filename) {
if (_col >= monitorVec.size()) {
std::string str = "moSampling: Could not export into file the vector. The index does not exists (too large)";
throw std::runtime_error(str);
/**
* To sample the search and get the statistics
* the statistics are stored in the moVectorMonitor vector
*/
void operator()(void) {
// clear all statistic vectors
for (unsigned i = 0; i < monitorVec.size(); i++)
monitorVec[i]->clear();
// change the checkpoint to compute the statistics
localSearch->setContinuator(*checkpoint);
// the initial solution
EOT solution;
// initialisation of the solution
init(solution);
// compute the sampling
(*localSearch)(solution);
// set back to initial continuator
localSearch->setContinuator(*continuator);
}
monitorVec[_col]->fileExport(_filename);
}
/**
* to get one vector of values
* @param _numStat number of stattistics to get (in order of creation)
* @return the vector of value (all values are converted in double)
*/
const std::vector<double> & getValues(unsigned int _numStat) {
return monitorVec[_numStat]->getValues();
}
/**
* to export the vectors of values into one file
* @param _filename file name
* @param _delim delimiter between statistics
*/
void fileExport(std::string _filename, std::string _delim = " ") {
// create file
std::ofstream os(_filename.c_str());
/**
* to get one vector of solutions values
* @param _numStat number of stattistics to get (in order of creation)
* @return the vector of value (all values are converted in double)
*/
const std::vector<EOT> & getSolutions(unsigned int _numStat) {
return monitorVec[_numStat]->getSolutions();
}
if (!os) {
std::string str = "moSampling: Could not open " + _filename;
throw std::runtime_error(str);
}
// all vector have the same size
unsigned vecSize = monitorVec[0]->size();
for (unsigned int i = 0; i < vecSize; i++) {
os << monitorVec[0]->getValue(i);
for (unsigned int j = 1; j < monitorVec.size(); j++) {
os << _delim.c_str() << monitorVec[j]->getValue(i);
}
os << std::endl ;
}
}
/**
* to export one vector of values into a file
* @param _col number of vector to print into file
* @param _filename file name
*/
void fileExport(unsigned int _col, std::string _filename) {
if (_col >= monitorVec.size()) {
std::string str = "moSampling: Could not export into file the vector. The index does not exists (too large)";
throw std::runtime_error(str);
}
monitorVec[_col]->fileExport(_filename);
}
/**
* to get one vector of values
* @param _numStat number of stattistics to get (in order of creation)
* @return the vector of value (all values are converted in double)
*/
const std::vector<double> & getValues(unsigned int _numStat) {
return monitorVec[_numStat]->getValues();
}
/**
* to get one vector of solutions values
* @param _numStat number of stattistics to get (in order of creation)
* @return the vector of value (all values are converted in double)
*/
const std::vector<EOT> & getSolutions(unsigned int _numStat) {
return monitorVec[_numStat]->getSolutions();
}
/**
* @return name of the class
*/
virtual std::string className(void) const {
return "moSampling";
}
/**
* @return name of the class
*/
virtual std::string className(void) const {
return "moSampling";
}
protected:
eoInit<EOT> & init;
moLocalSearch<Neighbor> * localSearch;
eoInit<EOT> & init;
moLocalSearch<Neighbor> * localSearch;
moContinuator<Neighbor> * continuator;
moCheckpoint<Neighbor> * checkpoint;
moContinuator<Neighbor> * continuator;
moCheckpoint<Neighbor> * checkpoint;
// std::vector<moStatBase<EOT>*> statVec;
std::vector< moVectorMonitor<EOT> *> monitorVec;
// std::vector<moStatBase<EOT>*> statVec;
std::vector< moVectorMonitor<EOT> *> monitorVec;
};

View file

@ -41,174 +41,174 @@
/**
* Tools to compute some basic statistics
*
*
* Remember it is better to use some statistic tool like R, etc.
* But it could be usefull to have here in paradisEO
*/
class moStatistics
class moStatistics
{
public:
/**
* Default Constructor
*/
moStatistics() { }
/**
* Default Constructor
*/
moStatistics() { }
/**
* To compute min, max , average and standard deviation of a vector of double
*
* @param data vector of double
* @param min to compute
* @param max to compute
* @param avg average to compute
* @param std standard deviation to compute
*/
void basic(const std::vector<double> & data,
double & min, double & max, double & avg, double & std) {
if (data.size() == 0) {
min = 0.0;
max = 0.0;
avg = 0.0;
std = 0.0;
} else {
unsigned int n = data.size();
/**
* To compute min, max , average and standard deviation of a vector of double
*
* @param data vector of double
* @param min to compute
* @param max to compute
* @param avg average to compute
* @param std standard deviation to compute
*/
void basic(const std::vector<double> & data,
double & min, double & max, double & avg, double & std) {
min = data[0];
max = data[0];
avg = 0.0;
std = 0.0;
if (data.size() == 0) {
min = 0.0;
max = 0.0;
avg = 0.0;
std = 0.0;
} else {
unsigned int n = data.size();
double d;
for(unsigned int i = 0; i < n; i++) {
d = data[i];
if (d < min)
min = d;
if (max < d)
max = d;
avg += d;
std += d * d;
}
min = data[0];
max = data[0];
avg = 0.0;
std = 0.0;
avg /= n;
double d;
for (unsigned int i = 0; i < n; i++) {
d = data[i];
if (d < min)
min = d;
if (max < d)
max = d;
avg += d;
std += d * d;
}
std = std / n - avg * avg ;
if (std > 0)
std = sqrt(std);
avg /= n;
std = std / n - avg * avg ;
if (std > 0)
std = sqrt(std);
}
}
}
/**
* To compute the distance between solutions
*
* @param data vector of solutions
* @param distance method to compute the distance
* @param matrix matrix of distances between solutions
*/
template <class EOT>
void distances(const std::vector<EOT> & data, eoDistance<EOT> & distance,
std::vector< std::vector<double> > & matrix) {
if (data.size() == 0) {
matrix.resize(0);
} else {
unsigned int n = data.size();
/**
* To compute the distance between solutions
*
* @param data vector of solutions
* @param distance method to compute the distance
* @param matrix matrix of distances between solutions
*/
template <class EOT>
void distances(const std::vector<EOT> & data, eoDistance<EOT> & distance,
std::vector< std::vector<double> > & matrix) {
if (data.size() == 0) {
matrix.resize(0);
} else {
unsigned int n = data.size();
matrix.resize(n);
for(unsigned i = 0; i < n; i++)
matrix[i].resize(n);
matrix.resize(n);
for (unsigned i = 0; i < n; i++)
matrix[i].resize(n);
unsigned j;
for(unsigned i = 0; i < n; i++) {
matrix[i][i] = 0.0;
for(j = 0; j < i; j++) {
matrix[i][j] = distance(data[i], data[j]);
matrix[j][i] = matrix[i][j];
}
}
unsigned j;
for (unsigned i = 0; i < n; i++) {
matrix[i][i] = 0.0;
for (j = 0; j < i; j++) {
matrix[i][j] = distance(data[i], data[j]);
matrix[j][i] = matrix[i][j];
}
}
}
}
}
/**
* To compute the autocorrelation and partial autocorrelation
*
* @param data vector of double
* @param nbS number of correlation coefficients
* @param rho autocorrelation coefficients
* @param phi partial autocorrelation coefficients
*/
void autocorrelation(const std::vector<double> & data, unsigned int nbS,
std::vector<double> & rho, std::vector<double> & phi) {
if (data.size() == 0) {
rho.resize(0);
phi.resize(0);
} else {
unsigned int n = data.size();
/**
* To compute the autocorrelation and partial autocorrelation
*
* @param data vector of double
* @param nbS number of correlation coefficients
* @param rho autocorrelation coefficients
* @param phi partial autocorrelation coefficients
*/
void autocorrelation(const std::vector<double> & data, unsigned int nbS,
std::vector<double> & rho, std::vector<double> & phi) {
if (data.size() == 0) {
rho.resize(0);
phi.resize(0);
} else {
unsigned int n = data.size();
double cov[nbS+1];
double m[nbS+1];
double sig[nbS+1];
double cov[nbS+1];
double m[nbS+1];
double sig[nbS+1];
rho.resize(nbS+1);
phi.resize(nbS+1);
rho[0] = 1.0;
phi[0] = 1.0; // ?
unsigned s, k;
rho.resize(nbS+1);
phi.resize(nbS+1);
rho[0] = 1.0;
phi[0] = 1.0; // ?
for(s = 0; s <= nbS; s++) {
cov[s] = 0;
m[s] = 0;
sig[s] = 0;
}
unsigned s, k;
double m0, s0;
unsigned j;
for (s = 0; s <= nbS; s++) {
cov[s] = 0;
m[s] = 0;
sig[s] = 0;
}
k = 0;
s = nbS;
while (s > 0) {
while (k + s < n) {
for(j = 0; j <= s; j++) {
m[j] += data[k+j];
sig[j] += data[k+j] * data[k+j];
cov[j] += data[k] * data[k+j];
}
k++;
}
m[s] /= n - s;
sig[s] = sig[s] / (n - s) - m[s] * m[s];
if (sig[s] <= 0)
sig[s] = 0;
else
sig[s] = sqrt(sig[s]);
m0 = m[0] / (n - s);
s0 = sqrt(sig[0] / (n - s) - m0 * m0);
cov[s] = cov[s] / (n - s) - (m[0] / (n - s)) * m[s];
rho[s] = cov[s] / (sig[s] * s0);
s--;
}
double m0, s0;
unsigned j;
double phi2[nbS+1][nbS+1];
double tmp1, tmp2;
k = 0;
s = nbS;
while (s > 0) {
while (k + s < n) {
for (j = 0; j <= s; j++) {
m[j] += data[k+j];
sig[j] += data[k+j] * data[k+j];
cov[j] += data[k] * data[k+j];
}
k++;
}
phi2[1][1] = rho[1];
for(k = 2; k <= nbS; k++) {
tmp1 = 0;
tmp2 = 0;
for(j = 1; j < k; j++) {
tmp1 += phi2[k-1][j] * rho[k-j];
tmp2 += phi2[k-1][j] * rho[j];
}
phi2[k][k] = (rho[k] - tmp1) / (1 - tmp2);
for(j = 1; j < k; j++)
phi2[k][j] = phi2[k-1][j] - phi2[k][k] * phi2[k-1][k-j];
}
for(j = 1; j <= nbS; j++)
phi[j] = phi2[j][j];
m[s] /= n - s;
sig[s] = sig[s] / (n - s) - m[s] * m[s];
if (sig[s] <= 0)
sig[s] = 0;
else
sig[s] = sqrt(sig[s]);
m0 = m[0] / (n - s);
s0 = sqrt(sig[0] / (n - s) - m0 * m0);
cov[s] = cov[s] / (n - s) - (m[0] / (n - s)) * m[s];
rho[s] = cov[s] / (sig[s] * s0);
s--;
}
double phi2[nbS+1][nbS+1];
double tmp1, tmp2;
phi2[1][1] = rho[1];
for (k = 2; k <= nbS; k++) {
tmp1 = 0;
tmp2 = 0;
for (j = 1; j < k; j++) {
tmp1 += phi2[k-1][j] * rho[k-j];
tmp2 += phi2[k-1][j] * rho[j];
}
phi2[k][k] = (rho[k] - tmp1) / (1 - tmp2);
for (j = 1; j < k; j++)
phi2[k][j] = phi2[k-1][j] - phi2[k][k] * phi2[k-1][k-j];
}
for (j = 1; j <= nbS; j++)
phi[j] = phi2[j][j];
}
}
}
};