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 * Abstract class for Acceptance criteria
*/ */
template< class Neighbor > 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 * Acceptance Criterion for extreme diversification : always accept new solution
*/ */
template< class Neighbor > template< class Neighbor >
class moAlwaysAcceptCrit : public moAcceptanceCriterion<Neighbor>, public moDummyMemory<Neighbor>{ class moAlwaysAcceptCrit : public moAcceptanceCriterion<Neighbor>, public moDummyMemory<Neighbor> {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
/** /**
* Always accept the new solution * Always accept the new solution
* @param _sol1 the previous solution * @param _sol1 the previous solution
* @param _sol2 the new solution after local search * @param _sol2 the new solution after local search
* @return always true * @return always true
*/ */
bool operator()(EOT& _sol1, EOT& _sol2){ bool operator()(EOT& _sol1, EOT& _sol2) {
return true; 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 * Acceptance Criterion for extreme intensification : accept if the new solution is better than previous one
*/ */
template< class Neighbor > template< class Neighbor >
class moBetterAcceptCrit : public moAcceptanceCriterion<Neighbor>, public moDummyMemory<Neighbor>{ class moBetterAcceptCrit : public moAcceptanceCriterion<Neighbor>, public moDummyMemory<Neighbor> {
public: 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 * Accept if the new solution is better than previous one
* @param _sol1 the previous solution * @param _sol1 the previous solution
* @param _sol2 the new solution after local search * @param _sol2 the new solution after local search
* @return true if the new solution is better than previous one * @return true if the new solution is better than previous one
*/ */
bool operator()(EOT& _sol1, EOT& _sol2){ bool operator()(EOT& _sol1, EOT& _sol2) {
return comparator(_sol1, _sol2); return comparator(_sol1, _sol2);
} }
private: private:
moSolComparator<EOT>& comparator; moSolComparator<EOT>& comparator;
}; };

View file

@ -36,36 +36,36 @@ Contact: paradiseo-help@lists.gforge.inria.fr
/** /**
* Dummy Local Search: * Dummy Local Search:
* *
* To do nothing, only the full evaluation of the solution if necessary ;-) * To do nothing, only the full evaluation of the solution if necessary ;-)
*/ */
template<class Neighbor> template<class Neighbor>
class moDummyLS: public moLocalSearch<Neighbor> class moDummyLS: public moLocalSearch<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ; 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: private:
// always true continuator // always true continuator
moTrueContinuator<Neighbor> trueCont; moTrueContinuator<Neighbor> trueCont;
// the explorer of the simple HC // the explorer of the simple HC
moDummyExplorer<Neighbor> explorer; moDummyExplorer<Neighbor> explorer;
}; };
#endif #endif

View file

@ -39,7 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
/** /**
* First improvement HC: * First improvement HC:
* Hill-Climber local search * Hill-Climber local search
* *
* At each iteration, * At each iteration,
* one of the random solution in the neighborhood is selected * one of the random solution in the neighborhood is selected
* if the selected neighbor have higher fitness than the current solution * if the selected neighbor have higher fitness than the current solution
@ -50,55 +50,55 @@ template<class Neighbor>
class moFirstImprHC: public moLocalSearch<Neighbor> class moFirstImprHC: public moLocalSearch<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ; 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: private:
// always true continuator // always true continuator
moTrueContinuator<Neighbor> trueCont; moTrueContinuator<Neighbor> trueCont;
// compare the fitness values of neighbors: true is strictly greater // compare the fitness values of neighbors: true is strictly greater
moNeighborComparator<Neighbor> defaultNeighborComp; 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; moSolNeighborComparator<Neighbor> defaultSolNeighborComp;
// the explorer of the first improvement HC // the explorer of the first improvement HC
moFirstImprHCexplorer<Neighbor> explorer; moFirstImprHCexplorer<Neighbor> explorer;
}; };
#endif #endif

View file

@ -49,7 +49,7 @@ class moILS: public moLocalSearch<moDummyNeighbor<typename Neighbor::EOT> >
{ {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ; typedef moNeighborhood<Neighbor> Neighborhood ;
/** /**
@ -59,12 +59,12 @@ public:
* @param _op the operator used to perturb solution * @param _op the operator used to perturb solution
* @param _nbIteration the time limit for search * @param _nbIteration the time limit for search
*/ */
moILS(moLocalSearch<Neighbor>& _ls, eoEvalFunc<EOT>& _fullEval, eoMonOp<EOT>& _op, unsigned int _nbIteration): moILS(moLocalSearch<Neighbor>& _ls, eoEvalFunc<EOT>& _fullEval, eoMonOp<EOT>& _op, unsigned int _nbIteration):
moLocalSearch<moDummyNeighbor<EOT> >(explorer, iterCont, _fullEval), moLocalSearch<moDummyNeighbor<EOT> >(explorer, iterCont, _fullEval),
iterCont(_nbIteration), iterCont(_nbIteration),
defaultPerturb(_op, _fullEval), defaultPerturb(_op, _fullEval),
explorer(_ls, defaultPerturb, defaultAccept) explorer(_ls, defaultPerturb, defaultAccept)
{} {}
/** /**
* Simple constructor for Iterated Local Search * Simple constructor for Iterated Local Search
@ -73,12 +73,12 @@ public:
* @param _op the operator used to perturb solution * @param _op the operator used to perturb solution
* @param _cont a continuator * @param _cont a continuator
*/ */
moILS(moLocalSearch<Neighbor>& _ls, eoEvalFunc<EOT>& _fullEval, eoMonOp<EOT>& _op, moContinuator<moDummyNeighbor<EOT> >& _cont): moILS(moLocalSearch<Neighbor>& _ls, eoEvalFunc<EOT>& _fullEval, eoMonOp<EOT>& _op, moContinuator<moDummyNeighbor<EOT> >& _cont):
moLocalSearch<moDummyNeighbor<EOT> >(explorer, _cont, _fullEval), moLocalSearch<moDummyNeighbor<EOT> >(explorer, _cont, _fullEval),
iterCont(0), iterCont(0),
defaultPerturb(_op, _fullEval), defaultPerturb(_op, _fullEval),
explorer(_ls, defaultPerturb, defaultAccept) explorer(_ls, defaultPerturb, defaultAccept)
{} {}
/** /**
* General constructor for Iterated Local Search * General constructor for Iterated Local Search
@ -88,23 +88,25 @@ public:
* @param _perturb a perturbation operator * @param _perturb a perturbation operator
* @param _accept a acceptance criteria * @param _accept a acceptance criteria
*/ */
moILS(moLocalSearch<Neighbor>& _ls, eoEvalFunc<EOT>& _fullEval, moContinuator<moDummyNeighbor<EOT> >& _cont, moMonOpPerturb<Neighbor>& _perturb, moAcceptanceCriterion<Neighbor>& _accept): moILS(moLocalSearch<Neighbor>& _ls, eoEvalFunc<EOT>& _fullEval, moContinuator<moDummyNeighbor<EOT> >& _cont, moMonOpPerturb<Neighbor>& _perturb, moAcceptanceCriterion<Neighbor>& _accept):
moLocalSearch<moDummyNeighbor<EOT> >(explorer, _cont, _fullEval), moLocalSearch<moDummyNeighbor<EOT> >(explorer, _cont, _fullEval),
iterCont(0), iterCont(0),
defaultPerturb(dummyOp, _fullEval), defaultPerturb(dummyOp, _fullEval),
explorer(_ls, _perturb, _accept) explorer(_ls, _perturb, _accept)
{} {}
private: private:
class dummmyMonOp: public eoMonOp<EOT>{ class dummmyMonOp: public eoMonOp<EOT> {
public: public:
bool operator()(EOT&){return false;} bool operator()(EOT&) {
}dummyOp; return false;
moIterContinuator<moDummyNeighbor<EOT> > iterCont; }
moMonOpPerturb<Neighbor> defaultPerturb; }dummyOp;
moAlwaysAcceptCrit<Neighbor> defaultAccept; moIterContinuator<moDummyNeighbor<EOT> > iterCont;
moILSexplorer<Neighbor> explorer; 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> class moLocalSearch: public eoMonOp<typename Neighbor::EOT>
{ {
public: public:
typedef moNeighborhood<Neighbor> Neighborhood; typedef moNeighborhood<Neighbor> Neighborhood;
typedef moNeighborhoodExplorer<Neighbor> NeighborhoodExplorer; typedef moNeighborhoodExplorer<Neighbor> NeighborhoodExplorer;
typedef typename Neighbor::EOT EOT ; typedef typename Neighbor::EOT EOT ;
/** /**
* Constructor of a moLocalSearch * Constructor of a moLocalSearch
@ -101,23 +101,23 @@ public:
return true; return true;
}; };
/** /**
* Set an external continuator * Set an external continuator
* @param _cont the external continuator * @param _cont the external continuator
*/ */
void setContinuator(moContinuator<Neighbor> & _cont) { void setContinuator(moContinuator<Neighbor> & _cont) {
cont = &_cont ; cont = &_cont ;
} }
/** /**
* external continuator object * external continuator object
* *
* @overload * @overload
* @return the external continuator * @return the external continuator
*/ */
moContinuator<Neighbor>* getContinuator() const { moContinuator<Neighbor>* getContinuator() const {
return cont ; return cont ;
} }
protected: protected:
// make the exploration of the neighborhood according to a local search heuristic // 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 * Metropolis-Hasting local search
* Only the symetric case is considered when Q(x,y) = Q(y,x) * Only the symetric case is considered when Q(x,y) = Q(y,x)
* Fitness must be > 0 * Fitness must be > 0
* *
* At each iteration, * At each iteration,
* one of the random solution in the neighborhood is selected * one of the random solution in the neighborhood is selected
* if the selected neighbor have higher or equal fitness than the current solution * 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> class moMetropolisHasting: public moLocalSearch<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ; 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: private:
// always true continuator // always true continuator
moTrueContinuator<Neighbor> trueCont; moTrueContinuator<Neighbor> trueCont;
// compare the fitness values of neighbors: true is strictly greater // compare the fitness values of neighbors: true is strictly greater
moNeighborComparator<Neighbor> defaultNeighborComp; 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; moSolNeighborComparator<Neighbor> defaultSolNeighborComp;
// the explorer of the HC with neutral move (equals fitness move) // the explorer of the HC with neutral move (equals fitness move)
moMetropolisHastingExplorer<Neighbor> explorer; moMetropolisHastingExplorer<Neighbor> explorer;
}; };
#endif #endif

View file

@ -49,58 +49,58 @@ template<class Neighbor>
class moNeutralHC: public moLocalSearch<Neighbor> class moNeutralHC: public moLocalSearch<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ; 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: private:
// always true continuator // always true continuator
moTrueContinuator<Neighbor> trueCont; moTrueContinuator<Neighbor> trueCont;
// compare the fitness values of neighbors: true is strictly greater // compare the fitness values of neighbors: true is strictly greater
moNeighborComparator<Neighbor> defaultNeighborComp; 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; moSolNeighborComparator<Neighbor> defaultSolNeighborComp;
// the explorer of the HC with neutral move (equals fitness move) // the explorer of the HC with neutral move (equals fitness move)
moNeutralHCexplorer<Neighbor> explorer; moNeutralHCexplorer<Neighbor> explorer;
}; };
#endif #endif

View file

@ -39,7 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
/** /**
* Random Best HC: * Random Best HC:
* Hill-Climber local search * Hill-Climber local search
* *
* At each iteration, * At each iteration,
* one of the random best solution in the neighborhood is selected * one of the random best solution in the neighborhood is selected
* if the selected neighbor have higher fitness than the current solution * if the selected neighbor have higher fitness than the current solution
@ -50,55 +50,55 @@ template<class Neighbor>
class moRandomBestHC: public moLocalSearch<Neighbor> class moRandomBestHC: public moLocalSearch<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ; 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: private:
// always true continuator // always true continuator
moTrueContinuator<Neighbor> trueCont; moTrueContinuator<Neighbor> trueCont;
// compare the fitness values of neighbors: true is strictly greater // compare the fitness values of neighbors: true is strictly greater
moNeighborComparator<Neighbor> defaultNeighborComp; 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; moSolNeighborComparator<Neighbor> defaultSolNeighborComp;
// the explorer of the HC with random choice of the best solution // the explorer of the HC with random choice of the best solution
moRandomBestHCexplorer<Neighbor> explorer; moRandomBestHCexplorer<Neighbor> explorer;
}; };
#endif #endif

View file

@ -39,7 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
/** /**
* Random Neutral Walk: * Random Neutral Walk:
* Random Neutral walk local search * Random Neutral walk local search
* *
* At each iteration, * At each iteration,
* one random neighbor with the same fitness is selected and replace the current solution * one random neighbor with the same fitness is selected and replace the current solution
* the algorithm stops when the number of steps is reached * the algorithm stops when the number of steps is reached
@ -48,55 +48,55 @@ template<class Neighbor>
class moRandomNeutralWalk: public moLocalSearch<Neighbor> class moRandomNeutralWalk: public moLocalSearch<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ; 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: private:
// always true continuator // always true continuator
moTrueContinuator<Neighbor> trueCont; moTrueContinuator<Neighbor> trueCont;
// the explorer of the random walk // the explorer of the random walk
moRandomNeutralWalkExplorer<Neighbor> explorer; moRandomNeutralWalkExplorer<Neighbor> explorer;
// 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; moSolNeighborComparator<Neighbor> defaultSolNeighborComp;
}; };
#endif #endif

View file

@ -39,7 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
/** /**
* Random Search: * Random Search:
* Pure random search local search * Pure random search local search
* *
* At each iteration, * At each iteration,
* one random solution is selected and replace the current solution * one random solution is selected and replace the current solution
* the algorithm stops when the number of solution is reached * the algorithm stops when the number of solution is reached
@ -48,43 +48,43 @@ template<class Neighbor>
class moRandomSearch: public moLocalSearch<Neighbor> class moRandomSearch: public moLocalSearch<Neighbor>
{ {
public: 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: private:
// always true continuator // always true continuator
moTrueContinuator<Neighbor> trueCont; moTrueContinuator<Neighbor> trueCont;
// the explorer of the random walk // the explorer of the random walk
moRandomSearchExplorer<Neighbor> explorer; moRandomSearchExplorer<Neighbor> explorer;
}; };
#endif #endif

View file

@ -39,7 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
/** /**
* Random Walk: * Random Walk:
* Random walk local search * Random walk local search
* *
* At each iteration, * At each iteration,
* one random neighbor is selected and replace the current solution * one random neighbor is selected and replace the current solution
* the algorithm stops when the number of steps is reached * the algorithm stops when the number of steps is reached
@ -48,39 +48,39 @@ template<class Neighbor>
class moRandomWalk: public moLocalSearch<Neighbor> class moRandomWalk: public moLocalSearch<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ; 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: private:
// always true continuator // always true continuator
moTrueContinuator<Neighbor> trueCont; moTrueContinuator<Neighbor> trueCont;
// the explorer of the random walk // the explorer of the random walk
moRandomWalkExplorer<Neighbor> explorer; moRandomWalkExplorer<Neighbor> explorer;
}; };
#endif #endif

View file

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

View file

@ -39,7 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
/** /**
* Simple HC: * Simple HC:
* Hill-Climber local search * Hill-Climber local search
* *
* At each iteration, * At each iteration,
* the first best solution in the neighborhood is selected * the first best solution in the neighborhood is selected
* if the selected neighbor have higher fitness than the current solution * if the selected neighbor have higher fitness than the current solution
@ -50,55 +50,55 @@ template<class Neighbor>
class moSimpleHC: public moLocalSearch<Neighbor> class moSimpleHC: public moLocalSearch<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<Neighbor> Neighborhood ; 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: private:
// always true continuator // always true continuator
moTrueContinuator<Neighbor> trueCont; moTrueContinuator<Neighbor> trueCont;
// compare the fitness values of neighbors: true is strictly greater // compare the fitness values of neighbors: true is strictly greater
moNeighborComparator<Neighbor> defaultNeighborComp; 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; moSolNeighborComparator<Neighbor> defaultSolNeighborComp;
// the explorer of the simple HC // the explorer of the simple HC
moSimpleHCexplorer<Neighbor> explorer; moSimpleHCexplorer<Neighbor> explorer;
}; };
#endif #endif

View file

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

View file

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

View file

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

View file

@ -42,52 +42,52 @@ template< class Neighbor >
class moCombinedContinuator : public moContinuator<Neighbor> class moCombinedContinuator : public moContinuator<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT ; typedef typename Neighbor::EOT EOT ;
/** /**
* Default constructor (moCheckpoint must have at least one continuator) * Default constructor (moCheckpoint must have at least one continuator)
* @param _cont a continuator * @param _cont a continuator
*/ */
moCombinedContinuator(moContinuator<Neighbor>& _cont) { moCombinedContinuator(moContinuator<Neighbor>& _cont) {
continuators.push_back(&_cont); continuators.push_back(&_cont);
} }
/** /**
* add a continuator to the combined continuator * add a continuator to the combined continuator
* @param _cont a continuator * @param _cont a continuator
*/ */
void add(moContinuator<Neighbor>& _cont) { void add(moContinuator<Neighbor>& _cont) {
continuators.push_back(&_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);
}
/** /**
*@param _solution a solution * init all continuators
*@return true all the continuators are true * @param _solution a solution
*/ */
virtual bool operator()(EOT & _solution) { virtual void init(EOT & _solution) {
bool bContinue = true; 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: private:
/** continuators vector */ /** continuators vector */
std::vector< moContinuator<Neighbor>* > continuators; std::vector< moContinuator<Neighbor>* > continuators;
}; };
#endif #endif

View file

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

View file

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

View file

@ -40,24 +40,24 @@ template< class Neighbor >
class moFitContinuator : public moContinuator<Neighbor> class moFitContinuator : public moContinuator<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT ; typedef typename Neighbor::EOT EOT ;
typedef typename EOT::Fitness Fitness ; 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: private:
Fitness maxFit; Fitness maxFit;
}; };
#endif #endif

View file

@ -44,40 +44,40 @@ template <class EOT>
class moFitnessStat : public moStat<EOT, typename EOT::Fitness> class moFitnessStat : public moStat<EOT, typename EOT::Fitness>
{ {
public : public :
typedef typename EOT::Fitness Fitness; typedef typename EOT::Fitness Fitness;
using moStat< EOT, Fitness >::value; using moStat< EOT, Fitness >::value;
/** /**
* Default Constructor * Default Constructor
* @param _description a description of the stat * @param _description a description of the stat
*/ */
moFitnessStat(std::string _description = "fitness"): moFitnessStat(std::string _description = "fitness"):
moStat<EOT, Fitness>(Fitness(), _description) {} moStat<EOT, Fitness>(Fitness(), _description) {}
/** /**
* store the initial fitness value * store the initial fitness value
* @param _sol the initial solution * @param _sol the initial solution
*/ */
virtual void init(EOT & _sol) virtual void init(EOT & _sol)
{ {
value() = _sol.fitness(); value() = _sol.fitness();
} }
/** /**
* store fitness value * store fitness value
* @param _sol the corresponding solution * @param _sol the corresponding solution
*/ */
virtual void operator()(EOT & _sol) virtual void operator()(EOT & _sol)
{ {
value() = _sol.fitness(); value() = _sol.fitness();
} }
/** /**
* @return the name of the class * @return the name of the class
*/ */
virtual std::string className(void) const { virtual std::string className(void) const {
return "moFitnessStat"; return "moFitnessStat";
} }
}; };
#endif #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 * 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 * Becareful 2: Can not be used if the evaluation function is used in parallel
*/ */
template< class Neighbor > template< class Neighbor >
class moFullEvalContinuator : public moContinuator<Neighbor> class moFullEvalContinuator : public moContinuator<Neighbor>
{ {
public: 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 * the current number of evaluation from the begining
* @return the number of evaluation * @return the number of evaluation
*/ */
unsigned int value() { unsigned int value() {
return eval.value() - nbEval_start ; return eval.value() - nbEval_start ;
} }
private: private:
eoEvalFuncCounter<EOT> & eval; eoEvalFuncCounter<EOT> & eval;
unsigned int nbEval_start ; unsigned int nbEval_start ;
unsigned int maxFullEval ; unsigned int maxFullEval ;
}; };
#endif #endif

View file

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

View file

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

View file

@ -63,12 +63,12 @@ public :
* @param _solNeighborComparator a comparator between a solution and a neighbor * @param _solNeighborComparator a comparator between a solution and a neighbor
* @param _k number of neighbors visited * @param _k number of neighbors visited
*/ */
moNeighborBestStat(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator, unsigned int _k = 0): moNeighborBestStat(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator, unsigned int _k = 0):
moStat<EOT, Fitness>(true, "neighborhood"), moStat<EOT, Fitness>(true, "neighborhood"),
neighborhood(_neighborhood), eval(_eval), neighborhood(_neighborhood), eval(_eval),
neighborComparator(_neighborComparator), neighborComparator(_neighborComparator),
solNeighborComparator(_solNeighborComparator), solNeighborComparator(_solNeighborComparator),
kmax(_k) kmax(_k)
{} {}
/** /**
@ -79,12 +79,12 @@ public :
* @param _eval an evaluation function * @param _eval an evaluation function
* @param _k number of neighbors visited (default all) * @param _k number of neighbors visited (default all)
*/ */
moNeighborBestStat(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, unsigned _k = 0): moNeighborBestStat(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, unsigned _k = 0):
moStat<EOT, Fitness>(Fitness(), "best"), moStat<EOT, Fitness>(Fitness(), "best"),
neighborhood(_neighborhood), eval(_eval), neighborhood(_neighborhood), eval(_eval),
neighborComparator(defaultNeighborComp), neighborComparator(defaultNeighborComp),
solNeighborComparator(defaultSolNeighborComp), solNeighborComparator(defaultSolNeighborComp),
kmax(_k) kmax(_k)
{} {}
/** /**
@ -92,7 +92,7 @@ public :
* @param _solution the first solution * @param _solution the first solution
*/ */
virtual void init(EOT & _solution) { virtual void init(EOT & _solution) {
operator()(_solution); operator()(_solution);
} }
/** /**
@ -113,8 +113,8 @@ public :
//initialize the best neighbor //initialize the best neighbor
best = current; best = current;
// number of visited neighbors // number of visited neighbors
unsigned int k = 1; unsigned int k = 1;
//test all others neighbors //test all others neighbors
while ( ( (kmax == 0) || (k < kmax) ) && neighborhood.cont(_solution)) { while ( ( (kmax == 0) || (k < kmax) ) && neighborhood.cont(_solution)) {
@ -127,14 +127,14 @@ public :
if (neighborComparator(best, current)) if (neighborComparator(best, current))
best = current; best = current;
k++; k++;
} }
value() = best.fitness(); value() = best.fitness();
} }
else { else {
//if _solution hasn't neighbor, //if _solution hasn't neighbor,
value() = Fitness(); value() = Fitness();
} }
} }
@ -146,22 +146,22 @@ public :
} }
private: private:
// to explore the neighborhood // to explore the neighborhood
Neighborhood& neighborhood ; Neighborhood& neighborhood ;
moEval<Neighbor>& eval; moEval<Neighbor>& eval;
// comparator betwenn solution and neighbor or between neighbors // comparator betwenn solution and neighbor or between neighbors
moNeighborComparator<Neighbor>& neighborComparator; moNeighborComparator<Neighbor>& neighborComparator;
moSolNeighborComparator<Neighbor>& solNeighborComparator; moSolNeighborComparator<Neighbor>& solNeighborComparator;
// default comparators // default comparators
// compare the fitness values of neighbors: true is strictly greater // compare the fitness values of neighbors: true is strictly greater
moNeighborComparator<Neighbor> defaultNeighborComp; 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; moSolNeighborComparator<Neighbor> defaultSolNeighborComp;
// number of neighbor to explore // number of neighbor to explore
unsigned int kmax; unsigned int kmax;
}; };
#endif #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 * 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 * Becareful 2: Can not be used if the evaluation function is used in parallel
*/ */
template< class Neighbor > template< class Neighbor >
@ -46,42 +46,42 @@ class moNeighborEvalContinuator : public moContinuator<Neighbor>
public: public:
typedef typename Neighbor::EOT EOT ; typedef typename Neighbor::EOT EOT ;
/** /**
* Default constructor * Default constructor
* @param _eval neighbor evaluation function to count * @param _eval neighbor evaluation function to count
* @param _maxNeighborEval number maximum of iterations * @param _maxNeighborEval number maximum of iterations
*/ */
moNeighborEvalContinuator(moEvalCounter<Neighbor> & _eval, unsigned int _maxNeighborEval): eval(_eval), maxNeighborEval(_maxNeighborEval){} 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: private:
moEvalCounter<Neighbor> & eval; moEvalCounter<Neighbor> & eval;
unsigned int maxNeighborEval; unsigned int maxNeighborEval;
unsigned int nbEval_start ; unsigned int nbEval_start ;
}; };
#endif #endif

View file

@ -46,67 +46,67 @@ template< class Neighbor >
class moNeighborFitnessStat : public moStat<typename Neighbor::EOT, typename Neighbor::EOT::Fitness> class moNeighborFitnessStat : public moStat<typename Neighbor::EOT, typename Neighbor::EOT::Fitness>
{ {
public : public :
typedef typename Neighbor::EOT EOT ; typedef typename Neighbor::EOT EOT ;
typedef moNeighborhood<Neighbor> Neighborhood ; typedef moNeighborhood<Neighbor> Neighborhood ;
typedef typename EOT::Fitness Fitness ; typedef typename EOT::Fitness Fitness ;
using moStat< EOT, Fitness >::value; using moStat< EOT, Fitness >::value;
/** /**
* Default Constructor * Default Constructor
* @param _neighborhood a neighborhood * @param _neighborhood a neighborhood
* @param _eval an evaluation function * @param _eval an evaluation function
*/ */
moNeighborFitnessStat(Neighborhood& _neighborhood, moEval<Neighbor>& _eval): moNeighborFitnessStat(Neighborhood& _neighborhood, moEval<Neighbor>& _eval):
moStat<EOT, Fitness>(Fitness(), "neighborhood"), moStat<EOT, Fitness>(Fitness(), "neighborhood"),
neighborhood(_neighborhood), eval(_eval) neighborhood(_neighborhood), eval(_eval)
{ {
if (!neighborhood.isRandom()) { if (!neighborhood.isRandom()) {
std::cout << "moNeighborFitnessStat::Warning -> the neighborhood used is not random, the neighbor will not be random" << std::endl; 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();
} }
}
/** /**
* @return the class name * Compute the fitness of one random neighbor
*/ * @param _solution the first solution
virtual std::string className(void) const { */
return "moNeighborFitnessStat"; 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: private:
// to explore the neighborhood // to explore the neighborhood
Neighborhood& neighborhood ; Neighborhood& neighborhood ;
moEval<Neighbor>& eval; moEval<Neighbor>& eval;
}; };

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -48,101 +48,101 @@ template< class Neighbor >
class moRandomSearchExplorer : public moNeighborhoodExplorer<Neighbor> class moRandomSearchExplorer : public moNeighborhoodExplorer<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT ; typedef typename Neighbor::EOT EOT ;
typedef moNeighborhood<Neighbor> Neighborhood ; typedef moNeighborhood<Neighbor> Neighborhood ;
using moNeighborhoodExplorer<Neighbor>::neighborhood; using moNeighborhoodExplorer<Neighbor>::neighborhood;
using moNeighborhoodExplorer<Neighbor>::eval; using moNeighborhoodExplorer<Neighbor>::eval;
/** /**
* Constructor * Constructor
* @param _init the solution initializer, to explore at random the search space * @param _init the solution initializer, to explore at random the search space
* @param _fulleval the evaluation function * @param _fulleval the evaluation function
* @param _nbStep maximum number of step to do * @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) { moRandomSearchExplorer(eoInit<EOT>& _init, eoEvalFunc<EOT>& _fulleval, unsigned _nbStep) : moNeighborhoodExplorer<Neighbor>(), init(_init), fulleval(_fulleval), nbStep(_nbStep) {
// number of step done // number of step done
step = 0; 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: private:
// initialization method to explore at random the search space // initialization method to explore at random the search space
eoInit<EOT> & init; eoInit<EOT> & init;
// the full eval function // the full eval function
eoEvalFunc<EOT> & fulleval; eoEvalFunc<EOT> & fulleval;
// current number of step // current number of step
unsigned int step; unsigned int step;
// maximum number of steps to do // maximum number of steps to do
unsigned int nbStep; unsigned int nbStep;
}; };

View file

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

View file

@ -41,92 +41,92 @@ template< class EOT >
class moVNSexplorer : public moNeighborhoodExplorer< moNeighborhood< moNeighbor<EOT, typename EOT::Fitness> > > class moVNSexplorer : public moNeighborhoodExplorer< moNeighborhood< moNeighbor<EOT, typename EOT::Fitness> > >
{ {
public: public:
typedef typename EOT::Fitness Fitness ; typedef typename EOT::Fitness Fitness ;
typedef moNeighbor<EOT, Fitness> Neighbor ; typedef moNeighbor<EOT, Fitness> Neighbor ;
typedef moNeighborhood<Neighbor> Neighborhood ; typedef moNeighborhood<Neighbor> Neighborhood ;
using moNeighborhoodExplorer<Neighborhood>::neighborhood; using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::eval; using moNeighborhoodExplorer<Neighborhood>::eval;
/** /**
* Constructor * Constructor
* @param _neighborhood the neighborhood * @param _neighborhood the neighborhood
* @param _eval the evaluation function * @param _eval the evaluation function
* @param _neighborComparator a neighbor comparator * @param _neighborComparator a neighbor comparator
* @param _solNeighborComparator solution vs 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) { 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: private:
// comparator betwenn solution and neighbor or between neighbors // comparator betwenn solution and neighbor or between neighbors
moNeighborComparator<Neighbor>& neighborComparator; moNeighborComparator<Neighbor>& neighborComparator;
moSolNeighborComparator<Neighbor>& solNeighborComparator; 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 * Count the number of move, noMove and the number of successive stagnation since the last Move
*/ */
template< class Neighbor > template< class Neighbor >
class moCountMoveMemory : virtual public moMemory<Neighbor>{ class moCountMoveMemory : virtual public moMemory<Neighbor> {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
/** /**
* Init all the counters * Init all the counters
* @param _sol unused solution * @param _sol unused solution
*/ */
void init(EOT & _sol) { void init(EOT & _sol) {
nbMove=0; nbMove=0;
nbNoMove=0; nbNoMove=0;
counter=0; counter=0;
} }
/** /**
@ -56,8 +56,8 @@ public:
* @param _neighbor unused neighbor * @param _neighbor unused neighbor
*/ */
void add(EOT & _sol, Neighbor & _neighbor) { void add(EOT & _sol, Neighbor & _neighbor) {
nbMove++; nbMove++;
counter=0; counter=0;
} }
/** /**
@ -65,48 +65,48 @@ public:
* @param _neighbor unused neighbor * @param _neighbor unused neighbor
*/ */
void update(EOT & _sol, Neighbor & _neighbor) { void update(EOT & _sol, Neighbor & _neighbor) {
nbNoMove++; nbNoMove++;
counter++; counter++;
} }
/** /**
* ClearMemory : Reinit all the counters * ClearMemory : Reinit all the counters
*/ */
void clearMemory() { void clearMemory() {
nbMove=0; nbMove=0;
nbNoMove=0; nbNoMove=0;
counter=0; counter=0;
} }
/** /**
* Getter of the number of move * Getter of the number of move
* @return the counter * @return the counter
*/ */
unsigned int getNbMove(){ unsigned int getNbMove() {
return nbMove; return nbMove;
} }
/** /**
* Getter of the number of no move * Getter of the number of no move
* @return the counter * @return the counter
*/ */
unsigned int getNbNoMove(){ unsigned int getNbNoMove() {
return nbNoMove; return nbNoMove;
} }
/** /**
* Getter of the number of successive stagnation since the last Move * Getter of the number of successive stagnation since the last Move
* @return the counter * @return the counter
*/ */
unsigned int getCounter(){ unsigned int getCounter() {
return counter; return counter;
} }
/** /**
* Init counter * Init counter
*/ */
void initCounter(){ void initCounter() {
counter=0; counter=0;
} }
private: private:

View file

@ -37,6 +37,6 @@ Contact: paradiseo-help@lists.gforge.inria.fr
* Abstract class for diversification strategy * Abstract class for diversification strategy
*/ */
template< class Neighbor > 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 #endif

View file

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

View file

@ -37,6 +37,6 @@ Contact: paradiseo-help@lists.gforge.inria.fr
* Abstract class for intensification strategy * Abstract class for intensification strategy
*/ */
template< class Neighbor > 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 #endif

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -43,15 +43,15 @@ class moVariableNeighborhood : public moNeighborhood<moNeighbor<EOT> >
{ {
public: public:
typedef moNeighbor<EOT> Neighbor; typedef moNeighbor<EOT> Neighbor;
/** /**
* Construction of at least one neighborhood * Construction of at least one neighborhood
* @param _firstNH first neighborhood in the vector * @param _firstNH first neighborhood in the vector
*/ */
moVariableNeighborhood(moNeighborhood<Neighbor>& _firstNH) { moVariableNeighborhood(moNeighborhood<Neighbor>& _firstNH) {
neighborhoodVector.push_back(&_firstNH); neighborhoodVector.push_back(&_firstNH);
// the current neighborhood // the current neighborhood
currentNH = 0; currentNH = 0;
} }
/** /**
@ -67,7 +67,7 @@ public:
* @return if _solution has a Neighbor in the current neighborhood * @return if _solution has a Neighbor in the current neighborhood
*/ */
virtual bool hasNeighbor(EOT & _solution) { 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 * @param _current the first neighbor in the current neighborhood
*/ */
virtual void init(EOT & _solution, Neighbor & _current) { 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 * @param _current the next neighbor in the current neighborhood
*/ */
virtual void next(EOT & _solution, Neighbor & _current) { 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 * @return if there is still a neighbor not explored in the current neighborhood
*/ */
virtual bool cont(EOT & _solution) { 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 * @param _nh the neighborhood to add at the end of the vector of neighborhood
*/ */
virtual void add(moNeighborhood<Neighbor>& _nh) { 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 > template< class Neighbor >
class moLocalSearchInit : public eoInit<typename Neighbor::EOT> { class moLocalSearchInit : public eoInit<typename Neighbor::EOT> {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
/** /**
* Default Constructor * Default Constructor
* @param _init initialization of the solution before the local search * @param _init initialization of the solution before the local search
* @param _ls the local search to apply to the solution * @param _ls the local search to apply to the solution
*/ */
moLocalSearchInit(eoInit<EOT>& _init, moLocalSearch<Neighbor>& _ls) : init(_init), ls(_ls) { moLocalSearchInit(eoInit<EOT>& _init, moLocalSearch<Neighbor>& _ls) : init(_init), ls(_ls) {
} }
/** /**
* Apply the local search on the solution * Apply the local search on the solution
* @param _solution to perturb * @param _solution to perturb
*/ */
void operator()(EOT& _solution){ void operator()(EOT& _solution) {
init(_solution); init(_solution);
ls(_solution); ls(_solution);
} }
private: private:
eoInit<EOT>& init; eoInit<EOT>& init;
moLocalSearch<Neighbor> & ls; moLocalSearch<Neighbor> & ls;
}; };
#endif #endif

View file

@ -42,30 +42,30 @@ template< class Neighbor >
class moMonOpPerturb : public moPerturbation<Neighbor>, public moDummyMemory<Neighbor> { class moMonOpPerturb : public moPerturbation<Neighbor>, public moDummyMemory<Neighbor> {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
/** /**
* Default Constructor * Default Constructor
* @param _monOp an eoMonOp (pertubation operator) * @param _monOp an eoMonOp (pertubation operator)
* @param _fullEval a full evaluation function * @param _fullEval a full evaluation function
*/ */
moMonOpPerturb(eoMonOp<EOT>& _monOp, eoEvalFunc<EOT>& _fullEval):monOp(_monOp), fullEval(_fullEval){} moMonOpPerturb(eoMonOp<EOT>& _monOp, eoEvalFunc<EOT>& _fullEval):monOp(_monOp), fullEval(_fullEval) {}
/** /**
* Apply monOp on the solution * Apply monOp on the solution
* @param _solution to perturb * @param _solution to perturb
* @return value of monOp * @return value of monOp
*/ */
bool operator()(EOT& _solution){ bool operator()(EOT& _solution) {
bool res = monOp(_solution); bool res = monOp(_solution);
fullEval(_solution); fullEval(_solution);
return res; return res;
} }
private: private:
/** monOp */ /** monOp */
eoMonOp<EOT>& monOp; eoMonOp<EOT>& monOp;
eoEvalFunc<EOT>& fullEval; eoEvalFunc<EOT>& fullEval;
}; };
#endif #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) * 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 > template< class Neighbor, class OtherNeighbor >
class moNeighborhoodPerturb : public moPerturbation<Neighbor>{ class moNeighborhoodPerturb : public moPerturbation<Neighbor> {
public: public:
typedef typename Neighbor::EOT EOT; typedef typename Neighbor::EOT EOT;
typedef moNeighborhood<OtherNeighbor> OtherNH; typedef moNeighborhood<OtherNeighbor> OtherNH;
/** /**
* Default Constructor * Default Constructor
* @param _otherNeighborhood a neighborhood * @param _otherNeighborhood a neighborhood
* @param _eval an Evaluation Function * @param _eval an Evaluation Function
*/ */
moNeighborhoodPerturb(OtherNH& _otherNeighborhood, moEval<OtherNeighbor>& _eval): otherNeighborhood(_otherNeighborhood), eval(_eval){} moNeighborhoodPerturb(OtherNH& _otherNeighborhood, moEval<OtherNeighbor>& _eval): otherNeighborhood(_otherNeighborhood), eval(_eval) {}
/** /**
* Apply move on the solution * Apply move on the solution
* @param _solution the current solution * @param _solution the current solution
* @return true * @return true
*/ */
virtual bool operator()(EOT& _solution){ virtual bool operator()(EOT& _solution) {
if(otherNeighborhood.hasNeighbor(_solution)){ if (otherNeighborhood.hasNeighbor(_solution)) {
eval(_solution, current); eval(_solution, current);
current.move(_solution); current.move(_solution);
_solution.fitness(current.fitness()); _solution.fitness(current.fitness());
} }
return true; return true;
} }
/** /**
* Init the neighborhood * Init the neighborhood
* @param _sol the current solution * @param _sol the current solution
*/ */
virtual void init(EOT & _sol){ virtual void init(EOT & _sol) {
if(otherNeighborhood.hasNeighbor(_sol)) if (otherNeighborhood.hasNeighbor(_sol))
otherNeighborhood.init(_sol, current); otherNeighborhood.init(_sol, current);
} }
/** /**
@ -79,8 +79,8 @@ public:
* @param _sol the current solution * @param _sol the current solution
* @param _neighbor unused neighbor (always empty) * @param _neighbor unused neighbor (always empty)
*/ */
virtual void add(EOT & _sol, Neighbor & _neighbor){ virtual void add(EOT & _sol, Neighbor & _neighbor) {
(*this).init(_sol); (*this).init(_sol);
} }
/** /**
@ -88,22 +88,22 @@ public:
* @param _sol the current solution * @param _sol the current solution
* @param _neighbor unused neighbor (always empty) * @param _neighbor unused neighbor (always empty)
*/ */
virtual void update(EOT & _sol, Neighbor & _neighbor){ virtual void update(EOT & _sol, Neighbor & _neighbor) {
if(otherNeighborhood.cont(_sol)) if (otherNeighborhood.cont(_sol))
otherNeighborhood.next(_sol, current); otherNeighborhood.next(_sol, current);
else else
(*this).init(_sol); (*this).init(_sol);
} }
/** /**
* NOTHING TO DO * NOTHING TO DO
*/ */
virtual void clearMemory(){} virtual void clearMemory() {}
private: private:
OtherNH& otherNeighborhood; OtherNH& otherNeighborhood;
moEval<OtherNeighbor>& eval; moEval<OtherNeighbor>& eval;
OtherNeighbor current; OtherNeighbor current;
}; };
#endif #endif

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -41,49 +41,49 @@ class moSwapNeighbor: public moBackableNeighbor<EOT>
{ {
public: public:
/** /**
* Apply the swap * Apply the swap
* @param _solution the solution to move * @param _solution the solution to move
*/ */
virtual void move(EOT& _solution){ virtual void move(EOT& _solution) {
unsigned int tmp; unsigned int tmp;
tmp=_solution[indices.first]; tmp=_solution[indices.first];
_solution[indices.first]=_solution[indices.second]; _solution[indices.first]=_solution[indices.second];
_solution[indices.second]=tmp; _solution[indices.second]=tmp;
_solution.invalidate(); _solution.invalidate();
} }
/** /**
* apply the swap to restore the solution (use by moFullEvalByModif) * apply the swap to restore the solution (use by moFullEvalByModif)
* @param _solution the solution to move * @param _solution the solution to move
*/ */
virtual void moveBack(EOT& _solution){ virtual void moveBack(EOT& _solution) {
unsigned int tmp; unsigned int tmp;
tmp=_solution[indices.first]; tmp=_solution[indices.first];
_solution[indices.first]=_solution[indices.second]; _solution[indices.first]=_solution[indices.second];
_solution[indices.second]=tmp; _solution[indices.second]=tmp;
_solution.invalidate(); _solution.invalidate();
} }
/** /**
* Setter to fix the two indexes to swap * Setter to fix the two indexes to swap
* @param _first first index * @param _first first index
* @param _second second index * @param _second second index
*/ */
void setIndices(unsigned int _first, unsigned int _second){ void setIndices(unsigned int _first, unsigned int _second) {
indices.first = _first; indices.first = _first;
indices.second = _second; indices.second = _second;
} }
/** /**
* Print the Neighbor * Print the Neighbor
*/ */
void print(){ void print() {
std::cout << "[" << indices.first << ", " << indices.second << "] -> " << (*this).fitness() << std::endl; std::cout << "[" << indices.first << ", " << indices.second << "] -> " << (*this).fitness() << std::endl;
} }
private: 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 * @return if there are available Neighbor
*/ */
virtual bool hasNeighbor(EOT& _solution){ virtual bool hasNeighbor(EOT& _solution) {
return (_solution.size() > 1); return (_solution.size() > 1);
}; };
/** /**
@ -54,11 +54,11 @@ public:
* @param _solution the solution to explore * @param _solution the solution to explore
* @param _current the first neighbor * @param _current the first neighbor
*/ */
virtual void init(EOT& _solution, Neighbor& _current){ virtual void init(EOT& _solution, Neighbor& _current) {
indices.first=0; indices.first=0;
indices.second=1; indices.second=1;
size=_solution.size(); size=_solution.size();
_current.setIndices(0,1); _current.setIndices(0,1);
} }
/** /**
@ -66,14 +66,14 @@ public:
* @param _solution the solution to explore * @param _solution the solution to explore
* @param _current the next neighbor * @param _current the next neighbor
*/ */
virtual void next(EOT& _solution, Neighbor& _current){ virtual void next(EOT& _solution, Neighbor& _current) {
if(indices.second==size-1){ if (indices.second==size-1) {
indices.first++; indices.first++;
indices.second=indices.first+1; indices.second=indices.first+1;
} }
else else
indices.second++; indices.second++;
_current.setIndices(indices.first, indices.second); _current.setIndices(indices.first, indices.second);
} }
/** /**
@ -81,8 +81,8 @@ public:
* @param _solution the solution to explore * @param _solution the solution to explore
* @return if there is again a neighbor not explored * @return if there is again a neighbor not explored
*/ */
virtual bool cont(EOT& _solution){ virtual bool cont(EOT& _solution) {
return !((indices.first == (size-2)) && (indices.second == (size-1))); return !((indices.first == (size-2)) && (indices.second == (size-1)));
} }
/** /**
@ -90,7 +90,7 @@ public:
* @return the class name as a std::string * @return the class name as a std::string
*/ */
virtual std::string className() const { virtual std::string className() const {
return "moSwapNeighborhood"; return "moSwapNeighborhood";
} }
private: private:

View file

@ -46,42 +46,42 @@
* To compute the autocorrelation function: * To compute the autocorrelation function:
* Perform a random walk based on the neighborhood, * Perform a random walk based on the neighborhood,
* The fitness values of solutions are collected during the random walk * 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> template <class Neighbor>
class moAutocorrelationSampling : public moSampling<Neighbor> class moAutocorrelationSampling : public moSampling<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT ; typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
/** using moSampling<Neighbor>::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 * Default Constructor
*/ * @param _init initialisation method of the solution
~moAutocorrelationSampling() { * @param _neighborhood neighborhood giving neighbor in random order
// delete the pointer on the local search which has been constructed in the constructor * @param _fullEval Fitness function, full evaluation function
delete localSearch; * @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: protected:
moFitnessStat<EOT> fitnessStat; moFitnessStat<EOT> fitnessStat;
}; };

View file

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

View file

@ -45,7 +45,7 @@
#include <sampling/moSampling.h> #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 * 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 * 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 * Then the correlation between the fitness and the distance can be computed
@ -55,40 +55,40 @@ template <class Neighbor>
class moFDCsampling : public moSampling<Neighbor> class moFDCsampling : public moSampling<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT ; typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
/** using moSampling<Neighbor>::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 * Default Constructor
*/ * @param _init initialisation method of the solution
~moFDCsampling() { * @param _fullEval a full evaluation function
// delete the pointer on the local search which has been constructed in the constructor * @param _dist the distance function between solution
delete localSearch; * @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: protected:
moFitnessStat<EOT> fitnessStat; moFitnessStat<EOT> fitnessStat;
moDistanceStat<EOT> distStat; moDistanceStat<EOT> distStat;
}; };

View file

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

View file

@ -52,58 +52,58 @@
* Perform a simple Hill-climber based on the neighborhood (adaptive walk), * 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 lengths of HC are collected and the final solution which are local optima
* The adaptive walk is repeated several times * The adaptive walk is repeated several times
* *
*/ */
template <class Neighbor> template <class Neighbor>
class moHillClimberSampling : public moSampling<Neighbor> class moHillClimberSampling : public moSampling<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT ; typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
/** using moSampling<Neighbor>::localSearch;
* 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);
// 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);
/** // add the solution into statistics
* default destructor add(solStat);
*/ }
~moHillClimberSampling() {
// delete the pointer on the local search which has been constructed in the constructor /**
delete localSearch; * default destructor
} */
~moHillClimberSampling() {
// delete the pointer on the local search which has been constructed in the constructor
delete localSearch;
}
protected: protected:
moSolutionStat<EOT> solStat; moSolutionStat<EOT> solStat;
moMinusOneCounterStat<EOT> lengthStat; moMinusOneCounterStat<EOT> lengthStat;
moTrueContinuator<Neighbor> trueCont; moTrueContinuator<Neighbor> trueCont;
moStatFromStat<EOT, unsigned int> copyStat; moStatFromStat<EOT, unsigned int> copyStat;
moCheckpoint<Neighbor> checkpoint; moCheckpoint<Neighbor> checkpoint;
moSimpleHC<Neighbor> hc; moSimpleHC<Neighbor> hc;
moLocalSearchInit<Neighbor> initHC; moLocalSearchInit<Neighbor> initHC;
}; };

View file

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

View file

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

View file

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

View file

@ -58,8 +58,8 @@
* To explore the evolvability of solutions in a neutral networks: * To explore the evolvability of solutions in a neutral networks:
* Perform a random neutral walk based on the neighborhood, * Perform a random neutral walk based on the neighborhood,
* The measures of evolvability of solutions are collected during the random neutral walk * 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: * Informations collected:
* - the current solution of the walk * - the current solution of the walk
* - the distance from the starting solution * - the distance from the starting solution
@ -76,71 +76,71 @@ template <class Neighbor>
class moNeutralWalkSampling : public moSampling<Neighbor> class moNeutralWalkSampling : public moSampling<Neighbor>
{ {
public: public:
typedef typename Neighbor::EOT EOT ; typedef typename Neighbor::EOT EOT ;
using moSampling<Neighbor>::localSearch;
/** using moSampling<Neighbor>::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 * Default Constructor
*/ * @param _initSol the first the solution of the walk
~moNeutralWalkSampling() { * @param _neighborhood neighborhood giving neighbor in random order
// delete the pointer on the local search which has been constructed in the constructor * @param _fullEval Fitness function, full evaluation function
delete localSearch; * @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: protected:
moSolInit<EOT> init; moSolInit<EOT> init;
moSolutionStat<EOT> solutionStat; moSolutionStat<EOT> solutionStat;
moDistanceStat<EOT> distStat; moDistanceStat<EOT> distStat;
moNeighborhoodStat< Neighbor > neighborhoodStat; moNeighborhoodStat< Neighbor > neighborhoodStat;
moMinNeighborStat< Neighbor > minStat; moMinNeighborStat< Neighbor > minStat;
moAverageFitnessNeighborStat< Neighbor > averageStat; moAverageFitnessNeighborStat< Neighbor > averageStat;
moStdFitnessNeighborStat< Neighbor > stdStat; moStdFitnessNeighborStat< Neighbor > stdStat;
moMaxNeighborStat< Neighbor > maxStat; moMaxNeighborStat< Neighbor > maxStat;
moNbSupNeighborStat< Neighbor > nbSupStat; moNbSupNeighborStat< Neighbor > nbSupStat;
moNbInfNeighborStat< Neighbor > nbInfStat; moNbInfNeighborStat< Neighbor > nbInfStat;
moSizeNeighborStat< Neighbor > sizeStat; moSizeNeighborStat< Neighbor > sizeStat;
moNeutralDegreeNeighborStat< Neighbor > ndStat; moNeutralDegreeNeighborStat< Neighbor > ndStat;
}; };

View file

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

View file

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

View file

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

View file

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