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:
parent
cc31901008
commit
3d8057ac4d
88 changed files with 2726 additions and 2720 deletions
|
|
@ -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> {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,29 +43,29 @@ 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
|
* Simple constructor
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
*/
|
*/
|
||||||
moDummyLS(eoEvalFunc<EOT>& _fullEval):
|
moDummyLS(eoEvalFunc<EOT>& _fullEval):
|
||||||
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval)
|
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return name of the class
|
* @return name of the class
|
||||||
*/
|
*/
|
||||||
virtual std::string className(void) const {
|
virtual std::string className(void) const {
|
||||||
return "moDummyLS";
|
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
|
||||||
|
|
|
||||||
|
|
@ -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
|
* Basic constructor for a hill-climber
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
*/
|
*/
|
||||||
moFirstImprHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval):
|
moFirstImprHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval):
|
||||||
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
|
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple constructor for a hill-climber
|
* Simple constructor for a hill-climber
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
* @param _cont an external continuator
|
* @param _cont an external continuator
|
||||||
*/
|
*/
|
||||||
moFirstImprHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont):
|
moFirstImprHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont):
|
||||||
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
|
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General constructor for a hill-climber
|
* General constructor for a hill-climber
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
* @param _cont an external continuator
|
* @param _cont an external continuator
|
||||||
* @param _compN a neighbor vs neighbor comparator
|
* @param _compN a neighbor vs neighbor comparator
|
||||||
* @param _compSN a solution 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):
|
moFirstImprHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont, moNeighborComparator<Neighbor>& _compN, moSolNeighborComparator<Neighbor>& _compSN):
|
||||||
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, _compN, _compSN)
|
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
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -105,9 +105,9 @@ public:
|
||||||
* 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
|
||||||
|
|
@ -115,9 +115,9 @@ public:
|
||||||
* @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
|
||||||
|
|
|
||||||
|
|
@ -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
|
* Basic constructor of the Metropolis-Hasting
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
* @param _nbStep maximum step to do
|
* @param _nbStep maximum step to do
|
||||||
*/
|
*/
|
||||||
moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep):
|
moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep):
|
||||||
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep)
|
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple constructor of the Metropolis-Hasting
|
* Simple constructor of the Metropolis-Hasting
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
* @param _nbStep maximum step to do
|
* @param _nbStep maximum step to do
|
||||||
* @param _cont an external continuator
|
* @param _cont an external continuator
|
||||||
*/
|
*/
|
||||||
moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep, moContinuator<Neighbor>& _cont):
|
moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep, moContinuator<Neighbor>& _cont):
|
||||||
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep)
|
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General constructor of the Metropolis-Hasting
|
* General constructor of the Metropolis-Hasting
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
* @param _nbStep maximum step to do
|
* @param _nbStep maximum step to do
|
||||||
* @param _cont an external continuator
|
* @param _cont an external continuator
|
||||||
* @param _compN a neighbor vs neighbor comparator
|
* @param _compN a neighbor vs neighbor comparator
|
||||||
* @param _compSN a solution 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):
|
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),
|
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, _compN, _compSN, _nbStep)
|
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
|
||||||
|
|
|
||||||
|
|
@ -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
|
* Basic constructor for a hill-climber
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
* @param _nbStep maximum step to do
|
* @param _nbStep maximum step to do
|
||||||
*/
|
*/
|
||||||
moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep):
|
moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep):
|
||||||
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep)
|
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple constructor for a hill-climber
|
* Simple constructor for a hill-climber
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
* @param _nbStep maximum step to do
|
* @param _nbStep maximum step to do
|
||||||
* @param _cont an external continuator
|
* @param _cont an external continuator
|
||||||
*/
|
*/
|
||||||
moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep, moContinuator<Neighbor>& _cont):
|
moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned int _nbStep, moContinuator<Neighbor>& _cont):
|
||||||
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep)
|
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General constructor for a hill-climber
|
* General constructor for a hill-climber
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
* @param _nbStep maximum step to do
|
* @param _nbStep maximum step to do
|
||||||
* @param _cont an external continuator
|
* @param _cont an external continuator
|
||||||
* @param _compN a neighbor vs neighbor comparator
|
* @param _compN a neighbor vs neighbor comparator
|
||||||
* @param _compSN a solution 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):
|
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),
|
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, _compN, _compSN, _nbStep)
|
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
|
||||||
|
|
|
||||||
|
|
@ -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
|
* Basic constructor for a hill-climber
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
*/
|
*/
|
||||||
moRandomBestHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval):
|
moRandomBestHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval):
|
||||||
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
|
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple constructor for a hill-climber
|
* Simple constructor for a hill-climber
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
* @param _cont an external continuator
|
* @param _cont an external continuator
|
||||||
*/
|
*/
|
||||||
moRandomBestHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont):
|
moRandomBestHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont):
|
||||||
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
|
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General constructor for a hill-climber
|
* General constructor for a hill-climber
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
* @param _cont an external continuator
|
* @param _cont an external continuator
|
||||||
* @param _compN a neighbor vs neighbor comparator
|
* @param _compN a neighbor vs neighbor comparator
|
||||||
* @param _compSN a solution 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):
|
moRandomBestHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont, moNeighborComparator<Neighbor>& _compN, moSolNeighborComparator<Neighbor>& _compSN):
|
||||||
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, _compN, _compSN)
|
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
|
||||||
|
|
|
||||||
|
|
@ -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
|
* Basic constructor for a random walk
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
* @param _nbStepMax number of step of the walk
|
* @param _nbStepMax number of step of the walk
|
||||||
*/
|
*/
|
||||||
moRandomNeutralWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax):
|
moRandomNeutralWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax):
|
||||||
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, defaultSolNeighborComp, _nbStepMax)
|
explorer(_neighborhood, _eval, defaultSolNeighborComp, _nbStepMax)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple constructor for a random walk
|
* Simple constructor for a random walk
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
* @param _nbStepMax number of step of the walk
|
* @param _nbStepMax number of step of the walk
|
||||||
* @param _cont an external continuator
|
* @param _cont an external continuator
|
||||||
*/
|
*/
|
||||||
moRandomNeutralWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax, moContinuator<Neighbor>& _cont):
|
moRandomNeutralWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax, moContinuator<Neighbor>& _cont):
|
||||||
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, defaultSolNeighborComp, _nbStepMax)
|
explorer(_neighborhood, _eval, defaultSolNeighborComp, _nbStepMax)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General constructor for a random walk
|
* General constructor for a random walk
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
* @param _nbStepMax number of step of the walk
|
* @param _nbStepMax number of step of the walk
|
||||||
* @param _cont an external continuator
|
* @param _cont an external continuator
|
||||||
* @param _comp a solution vs neighbor comparator
|
* @param _comp a solution vs neighbor comparator
|
||||||
*/
|
*/
|
||||||
moRandomNeutralWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax, moContinuator<Neighbor>& _cont, moSolNeighborComparator<Neighbor>& _comp):
|
moRandomNeutralWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax, moContinuator<Neighbor>& _cont, moSolNeighborComparator<Neighbor>& _comp):
|
||||||
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, _comp, _nbStepMax)
|
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
|
||||||
|
|
|
||||||
|
|
@ -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
|
* Simple constructor for a random search
|
||||||
* @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 full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _nbSolMax number of solutions
|
* @param _nbSolMax number of solutions
|
||||||
*/
|
*/
|
||||||
moRandomSearch(eoInit<EOT> & _init, eoEvalFunc<EOT>& _fullEval, unsigned _nbSolMax):
|
moRandomSearch(eoInit<EOT> & _init, eoEvalFunc<EOT>& _fullEval, unsigned _nbSolMax):
|
||||||
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
||||||
explorer(_init, _fullEval, _nbSolMax>0?_nbSolMax - 1:0)
|
explorer(_init, _fullEval, _nbSolMax>0?_nbSolMax - 1:0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General constructor for a random search
|
* General constructor for a random search
|
||||||
* @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 full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _nbSolMax number of solutions
|
* @param _nbSolMax number of solutions
|
||||||
* @param _cont external continuator
|
* @param _cont external continuator
|
||||||
*/
|
*/
|
||||||
moRandomSearch(eoInit<EOT> & _init, eoEvalFunc<EOT>& _fullEval, unsigned _nbSolMax, moContinuator<Neighbor>& _cont):
|
moRandomSearch(eoInit<EOT> & _init, eoEvalFunc<EOT>& _fullEval, unsigned _nbSolMax, moContinuator<Neighbor>& _cont):
|
||||||
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
||||||
explorer(_init, _fullEval, _nbSolMax>0?_nbSolMax - 1:0)
|
explorer(_init, _fullEval, _nbSolMax>0?_nbSolMax - 1:0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return name of the class
|
* @return name of the class
|
||||||
*/
|
*/
|
||||||
virtual std::string className(void) const {
|
virtual std::string className(void) const {
|
||||||
return "moRandomSearch";
|
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
|
||||||
|
|
|
||||||
|
|
@ -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
|
* Simple constructor for a random walk
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
* @param _nbStepMax number of step of the walk
|
* @param _nbStepMax number of step of the walk
|
||||||
*/
|
*/
|
||||||
moRandomWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax):
|
moRandomWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax):
|
||||||
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, _nbStepMax)
|
explorer(_neighborhood, _eval, _nbStepMax)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General constructor for a random walk
|
* General constructor for a random walk
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
* @param _nbStepMax number of step of the walk
|
* @param _nbStepMax number of step of the walk
|
||||||
* @param _cont an external continuator
|
* @param _cont an external continuator
|
||||||
*/
|
*/
|
||||||
moRandomWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax, moContinuator<Neighbor>& _cont):
|
moRandomWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax, moContinuator<Neighbor>& _cont):
|
||||||
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, _nbStepMax)
|
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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
* Simple constructor for a hill-climber
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
*/
|
*/
|
||||||
moSimpleHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval):
|
moSimpleHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval):
|
||||||
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
|
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple constructor for a hill-climber
|
* Simple constructor for a hill-climber
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
* @param _cont an external continuator
|
* @param _cont an external continuator
|
||||||
*/
|
*/
|
||||||
moSimpleHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont):
|
moSimpleHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont):
|
||||||
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
|
explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple constructor for a hill-climber
|
* Simple constructor for a hill-climber
|
||||||
* @param _neighborhood the neighborhood
|
* @param _neighborhood the neighborhood
|
||||||
* @param _fullEval the full evaluation function
|
* @param _fullEval the full evaluation function
|
||||||
* @param _eval neighbor's evaluation function
|
* @param _eval neighbor's evaluation function
|
||||||
* @param _cont an external continuator
|
* @param _cont an external continuator
|
||||||
* @param _compN a neighbor vs neighbor comparator
|
* @param _compN a neighbor vs neighbor comparator
|
||||||
* @param _compSN a solution 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):
|
moSimpleHC(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, moContinuator<Neighbor>& _cont, moNeighborComparator<Neighbor>& _compN, moSolNeighborComparator<Neighbor>& _compSN):
|
||||||
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, _cont, _fullEval),
|
||||||
explorer(_neighborhood, _eval, _compN, _compSN)
|
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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -44,37 +44,37 @@ 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";
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
* init all continuators
|
||||||
* @param _solution a solution
|
* @param _solution a solution
|
||||||
*/
|
*/
|
||||||
virtual void init(EOT & _solution) {
|
virtual void init(EOT & _solution) {
|
||||||
for(unsigned int i = 0; i < continuators.size(); ++i)
|
for (unsigned int i = 0; i < continuators.size(); ++i)
|
||||||
continuators[i]->init(_solution);
|
continuators[i]->init(_solution);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*@param _solution a solution
|
*@param _solution a solution
|
||||||
*@return true all the continuators are true
|
*@return true all the continuators are true
|
||||||
*/
|
*/
|
||||||
virtual bool operator()(EOT & _solution) {
|
virtual bool operator()(EOT & _solution) {
|
||||||
bool bContinue = true;
|
bool bContinue = true;
|
||||||
|
|
||||||
// some data may be update in each continuator.
|
// some data may be update in each continuator.
|
||||||
// So, all continuators are tested
|
// So, all continuators are tested
|
||||||
for(unsigned int i = 0; i < continuators.size(); ++i)
|
for (unsigned int i = 0; i < continuators.size(); ++i)
|
||||||
if ( !(*continuators[i])(_solution) )
|
if ( !(*continuators[i])(_solution) )
|
||||||
bContinue = false;
|
bContinue = false;
|
||||||
|
|
||||||
return bContinue;
|
return bContinue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** continuators vector */
|
/** continuators vector */
|
||||||
std::vector< moContinuator<Neighbor>* > continuators;
|
std::vector< moContinuator<Neighbor>* > continuators;
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -44,36 +44,36 @@ 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";
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
* @param _maxFit maximum fitness to reach
|
||||||
*/
|
*/
|
||||||
moFitContinuator(Fitness _maxFit): maxFit(_maxFit){}
|
moFitContinuator(Fitness _maxFit): maxFit(_maxFit) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*@param _solution a solution
|
*@param _solution a solution
|
||||||
*@return true if counter < maxFit
|
*@return true if counter < maxFit
|
||||||
*/
|
*/
|
||||||
virtual bool operator()(EOT & _solution) {
|
virtual bool operator()(EOT & _solution) {
|
||||||
return (_solution.fitness() < maxFit);
|
return (_solution.fitness() < maxFit);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Fitness maxFit;
|
Fitness maxFit;
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -44,46 +44,46 @@ 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
|
* Default constructor
|
||||||
* @param _eval evaluation function to count
|
* @param _eval evaluation function to count
|
||||||
* @param _maxFullEval number maximum of iterations
|
* @param _maxFullEval number maximum of iterations
|
||||||
*/
|
*/
|
||||||
moFullEvalContinuator(eoEvalFuncCounter<EOT> & _eval, unsigned int _maxFullEval): eval(_eval), maxFullEval(_maxFullEval) {
|
moFullEvalContinuator(eoEvalFuncCounter<EOT> & _eval, unsigned int _maxFullEval): eval(_eval), maxFullEval(_maxFullEval) {
|
||||||
nbEval_start = eval.value();
|
nbEval_start = eval.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if continue
|
* Test if continue
|
||||||
* @param _solution a solution
|
* @param _solution a solution
|
||||||
* @return true if number of evaluations < maxFullEval
|
* @return true if number of evaluations < maxFullEval
|
||||||
*/
|
*/
|
||||||
virtual bool operator()(EOT & _solution) {
|
virtual bool operator()(EOT & _solution) {
|
||||||
return (eval.value() - nbEval_start < maxFullEval);
|
return (eval.value() - nbEval_start < maxFullEval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset the number of evaluations
|
* Reset the number of evaluations
|
||||||
* @param _solution a solution
|
* @param _solution a solution
|
||||||
*/
|
*/
|
||||||
virtual void init(EOT & _solution) {
|
virtual void init(EOT & _solution) {
|
||||||
nbEval_start = eval.value();
|
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
|
||||||
|
|
|
||||||
|
|
@ -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:
|
||||||
|
|
|
||||||
|
|
@ -45,45 +45,45 @@ 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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
* Test if continue
|
||||||
* @param _solution a solution
|
* @param _solution a solution
|
||||||
* @return true if number of evaluations < maxNeighborEval
|
* @return true if number of evaluations < maxNeighborEval
|
||||||
*/
|
*/
|
||||||
virtual bool operator()(EOT & _solution) {
|
virtual bool operator()(EOT & _solution) {
|
||||||
return (eval.value() - nbEval_start < maxNeighborEval);
|
return (eval.value() - nbEval_start < maxNeighborEval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset the number of evaluations
|
* Reset the number of evaluations
|
||||||
* @param _solution a solution
|
* @param _solution a solution
|
||||||
*/
|
*/
|
||||||
virtual void init(EOT & _solution) {
|
virtual void init(EOT & _solution) {
|
||||||
nbEval_start = eval.value();
|
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:
|
||||||
moEvalCounter<Neighbor> & eval;
|
moEvalCounter<Neighbor> & eval;
|
||||||
unsigned int maxNeighborEval;
|
unsigned int maxNeighborEval;
|
||||||
unsigned int nbEval_start ;
|
unsigned int nbEval_start ;
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -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
|
* Compute the fitness of one random neighbor
|
||||||
* @param _solution the first solution
|
* @param _solution the first solution
|
||||||
*/
|
*/
|
||||||
virtual void init(EOT & _solution) {
|
virtual void init(EOT & _solution) {
|
||||||
operator()(_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 corresponding solution
|
||||||
virtual std::string className(void) const {
|
*/
|
||||||
return "moNeighborFitnessStat";
|
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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -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 &) {}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,158 +49,158 @@ class moVectorMonitor : public eoMonitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
* @param _param the parameter of type double to save in the vector
|
* @param _param the parameter of type double to save in the vector
|
||||||
*/
|
*/
|
||||||
moVectorMonitor(eoValueParam<double> & _param) : doubleParam(&_param), intParam(NULL), eotParam(NULL)
|
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 unsigned int to save in the vector
|
||||||
*/
|
*/
|
||||||
moVectorMonitor(eoValueParam<unsigned int> & _param) : doubleParam(NULL), intParam(&_param), eotParam(NULL)
|
moVectorMonitor(eoValueParam<unsigned int> & _param) : doubleParam(NULL), intParam(&_param), eotParam(NULL)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
* @param _param the parameter of type EOT to save in the vector
|
* @param _param the parameter of type EOT to save in the vector
|
||||||
*/
|
*/
|
||||||
moVectorMonitor(eoValueParam<EOT> & _param) : doubleParam(NULL), intParam(NULL), eotParam(&_param)
|
moVectorMonitor(eoValueParam<EOT> & _param) : doubleParam(NULL), intParam(NULL), eotParam(&_param)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
* @param _param the parameter of type eoScalarFitness to save in the vector
|
* @param _param the parameter of type eoScalarFitness to save in the vector
|
||||||
*/
|
*/
|
||||||
template <class ScalarType, class Compare>
|
template <class ScalarType, class Compare>
|
||||||
moVectorMonitor(eoValueParam<eoScalarFitness<ScalarType, Compare> > & _param) : doubleParam( & (eoValueParam<double>&)_param), intParam(NULL), eotParam(NULL)
|
moVectorMonitor(eoValueParam<eoScalarFitness<ScalarType, Compare> > & _param) : doubleParam( & (eoValueParam<double>&)_param), intParam(NULL), eotParam(NULL)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
* @param _param unvalid Parameter
|
* @param _param unvalid Parameter
|
||||||
*/
|
*/
|
||||||
template <class T>
|
template <class T>
|
||||||
moVectorMonitor(eoValueParam<T> & _param) : doubleParam(NULL), intParam(NULL), eotParam(NULL)
|
moVectorMonitor(eoValueParam<T> & _param) : doubleParam(NULL), intParam(NULL), eotParam(NULL)
|
||||||
{
|
{
|
||||||
std::cerr << "Sorry the type can not be in a vector of moVectorMonitor" << std::endl;
|
std::cerr << "Sorry the type can not be in a vector of moVectorMonitor" << std::endl;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* To test if the value are basic type (double or unsigned int), or EOT type
|
|
||||||
*
|
|
||||||
* @return true if the type is a EOT type
|
|
||||||
*/
|
|
||||||
bool solutionType() {
|
|
||||||
return eotParam != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* To "print" the value of the parameter in the vector
|
|
||||||
*
|
|
||||||
* @return this monitor (sorry I don't why, but it is like this in EO)
|
|
||||||
*/
|
|
||||||
eoMonitor& operator()(void) {
|
|
||||||
if (doubleParam != NULL)
|
|
||||||
valueVec.push_back(doubleParam->value());
|
|
||||||
else
|
|
||||||
if (intParam != NULL)
|
|
||||||
valueVec.push_back((double) intParam->value());
|
|
||||||
else
|
|
||||||
eotVec.push_back(eotParam->value());
|
|
||||||
|
|
||||||
return *this ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* To have all the values
|
|
||||||
*
|
|
||||||
* @return the vector of values
|
|
||||||
*/
|
|
||||||
const std::vector<double>& getValues() const {
|
|
||||||
return valueVec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* To have all the solutions
|
|
||||||
*
|
|
||||||
* @return the vector of solutions
|
|
||||||
*/
|
|
||||||
const std::vector<EOT>& getSolutions() const {
|
|
||||||
return eotVec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* to get the value out.
|
|
||||||
* @return the string of the value
|
|
||||||
*/
|
|
||||||
std::string getValue(unsigned int i) const {
|
|
||||||
std::ostringstream os;
|
|
||||||
|
|
||||||
if (eotParam == NULL)
|
|
||||||
os << (valueVec[i]) ;
|
|
||||||
else
|
|
||||||
os << (eotVec[i]) ;
|
|
||||||
|
|
||||||
return os.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clear the vector
|
|
||||||
*/
|
|
||||||
void clear() {
|
|
||||||
valueVec.clear();
|
|
||||||
eotVec.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* number of value
|
|
||||||
* @return size of the vector
|
|
||||||
*/
|
|
||||||
unsigned int size() {
|
|
||||||
if (eotParam == NULL)
|
|
||||||
return valueVec.size();
|
|
||||||
else
|
|
||||||
return eotVec.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* to export the vector of values into one file
|
|
||||||
* @param _filename file name
|
|
||||||
*/
|
|
||||||
void fileExport(std::string _filename) {
|
|
||||||
// create file
|
|
||||||
std::ofstream os(_filename.c_str());
|
|
||||||
|
|
||||||
if (!os) {
|
|
||||||
std::string str = "moVectorMonitor: Could not open " + _filename;
|
|
||||||
throw std::runtime_error(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(unsigned int i = 0; i < size(); i++) {
|
/**
|
||||||
os << getValue(i);
|
* To test if the value are basic type (double or unsigned int), or EOT type
|
||||||
|
*
|
||||||
os << std::endl ;
|
* @return true if the type is a EOT type
|
||||||
|
*/
|
||||||
|
bool solutionType() {
|
||||||
|
return eotParam != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* To "print" the value of the parameter in the vector
|
||||||
|
*
|
||||||
|
* @return this monitor (sorry I don't why, but it is like this in EO)
|
||||||
|
*/
|
||||||
|
eoMonitor& operator()(void) {
|
||||||
|
if (doubleParam != NULL)
|
||||||
|
valueVec.push_back(doubleParam->value());
|
||||||
|
else
|
||||||
|
if (intParam != NULL)
|
||||||
|
valueVec.push_back((double) intParam->value());
|
||||||
|
else
|
||||||
|
eotVec.push_back(eotParam->value());
|
||||||
|
|
||||||
/**
|
return *this ;
|
||||||
* @return name of the class
|
}
|
||||||
*/
|
|
||||||
virtual std::string className(void) const {
|
/**
|
||||||
return "moVectorMonitor";
|
* To have all the values
|
||||||
}
|
*
|
||||||
|
* @return the vector of values
|
||||||
|
*/
|
||||||
|
const std::vector<double>& getValues() const {
|
||||||
|
return valueVec;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To have all the solutions
|
||||||
|
*
|
||||||
|
* @return the vector of solutions
|
||||||
|
*/
|
||||||
|
const std::vector<EOT>& getSolutions() const {
|
||||||
|
return eotVec;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* to get the value out.
|
||||||
|
* @return the string of the value
|
||||||
|
*/
|
||||||
|
std::string getValue(unsigned int i) const {
|
||||||
|
std::ostringstream os;
|
||||||
|
|
||||||
|
if (eotParam == NULL)
|
||||||
|
os << (valueVec[i]) ;
|
||||||
|
else
|
||||||
|
os << (eotVec[i]) ;
|
||||||
|
|
||||||
|
return os.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clear the vector
|
||||||
|
*/
|
||||||
|
void clear() {
|
||||||
|
valueVec.clear();
|
||||||
|
eotVec.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* number of value
|
||||||
|
* @return size of the vector
|
||||||
|
*/
|
||||||
|
unsigned int size() {
|
||||||
|
if (eotParam == NULL)
|
||||||
|
return valueVec.size();
|
||||||
|
else
|
||||||
|
return eotVec.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* to export the vector of values into one file
|
||||||
|
* @param _filename file name
|
||||||
|
*/
|
||||||
|
void fileExport(std::string _filename) {
|
||||||
|
// create file
|
||||||
|
std::ofstream os(_filename.c_str());
|
||||||
|
|
||||||
|
if (!os) {
|
||||||
|
std::string str = "moVectorMonitor: Could not open " + _filename;
|
||||||
|
throw std::runtime_error(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < size(); i++) {
|
||||||
|
os << getValue(i);
|
||||||
|
|
||||||
|
os << std::endl ;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return name of the class
|
||||||
|
*/
|
||||||
|
virtual std::string className(void) const {
|
||||||
|
return "moVectorMonitor";
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,17 +45,17 @@ 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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,80 +45,80 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,59 +45,59 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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) {}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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++;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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),
|
||||||
|
|
|
||||||
|
|
@ -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
|
* Destructor
|
||||||
*/
|
*/
|
||||||
~moRandomSearchExplorer() {}
|
~moRandomSearchExplorer() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initialization of the number of step to be done
|
* initialization of the number of step to be done
|
||||||
* @param _solution a solution (unused)
|
* @param _solution a solution (unused)
|
||||||
*/
|
*/
|
||||||
virtual void initParam(EOT & _solution) {
|
virtual void initParam(EOT & _solution) {
|
||||||
step = 0;
|
step = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* increase the number of step
|
* increase the number of step
|
||||||
* @param _solution a solution (unused)
|
* @param _solution a solution (unused)
|
||||||
*/
|
*/
|
||||||
virtual void updateParam(EOT & _solution) {
|
virtual void updateParam(EOT & _solution) {
|
||||||
step++;
|
step++;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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) {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Explore the neighborhood with only one random solution
|
* Explore the neighborhood with only one random solution
|
||||||
* we supposed that the first neighbor is uniformly selected in the neighborhood
|
* we supposed that the first neighbor is uniformly selected in the neighborhood
|
||||||
* @param _solution
|
* @param _solution
|
||||||
*/
|
*/
|
||||||
virtual void operator()(EOT & _solution) {
|
virtual void operator()(EOT & _solution) {
|
||||||
//init the first neighbor
|
//init the first neighbor
|
||||||
init(_solution);
|
init(_solution);
|
||||||
|
|
||||||
//eval the _solution moved with the neighbor and stock the result in the neighbor
|
//eval the _solution moved with the neighbor and stock the result in the neighbor
|
||||||
fulleval(_solution);
|
fulleval(_solution);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* continue if it is remainds some steps to do
|
* continue if it is remainds some steps to do
|
||||||
* @param _solution the solution
|
* @param _solution the solution
|
||||||
* @return true there is some steps to do
|
* @return true there is some steps to do
|
||||||
*/
|
*/
|
||||||
virtual bool isContinue(EOT & _solution) {
|
virtual bool isContinue(EOT & _solution) {
|
||||||
return (step < nbStep) ;
|
return (step < nbStep) ;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* move the solution with the best neighbor
|
* move the solution with the best neighbor
|
||||||
* @param _solution the solution to move
|
* @param _solution the solution to move
|
||||||
*/
|
*/
|
||||||
virtual void move(EOT & _solution) {
|
virtual void move(EOT & _solution) {
|
||||||
// the solution is already move. So nothing to do !
|
// the solution is already move. So nothing to do !
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* accept test : always accept
|
* accept test : always accept
|
||||||
* @param _solution the solution
|
* @param _solution the solution
|
||||||
* @return true if the best neighbor ameliorate the fitness
|
* @return true if the best neighbor ameliorate the fitness
|
||||||
*/
|
*/
|
||||||
virtual bool accept(EOT & _solution) {
|
virtual bool accept(EOT & _solution) {
|
||||||
return true;
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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()) {
|
||||||
|
|
@ -86,8 +86,8 @@ public:
|
||||||
* @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:
|
||||||
|
|
|
||||||
|
|
@ -41,91 +41,91 @@ 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
|
* Destructor
|
||||||
*/
|
*/
|
||||||
~moVNSexplorer() {
|
~moVNSexplorer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initParam: NOTHING TO DO
|
* initParam: NOTHING TO DO
|
||||||
*/
|
*/
|
||||||
virtual void initParam(EOT & solution) {};
|
virtual void initParam(EOT & solution) {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* updateParam: NOTHING TO DO
|
* updateParam: NOTHING TO DO
|
||||||
*/
|
*/
|
||||||
virtual void updateParam(EOT & solution) {};
|
virtual void updateParam(EOT & solution) {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* terminate: NOTHING TO DO
|
* terminate: NOTHING TO DO
|
||||||
*/
|
*/
|
||||||
virtual void terminate(EOT & solution) {};
|
virtual void terminate(EOT & solution) {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Explore the neighborhood of a solution
|
* Explore the neighborhood of a solution
|
||||||
* @param _solution
|
* @param _solution
|
||||||
*/
|
*/
|
||||||
virtual void operator()(EOT & _solution) {
|
virtual void operator()(EOT & _solution) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* continue if a move is accepted
|
* continue if a move is accepted
|
||||||
* @param _solution the solution
|
* @param _solution the solution
|
||||||
* @return true if an ameliorated neighbor was be found
|
* @return true if an ameliorated neighbor was be found
|
||||||
*/
|
*/
|
||||||
virtual bool isContinue(EOT & _solution) {
|
virtual bool isContinue(EOT & _solution) {
|
||||||
return isAccept ;
|
return isAccept ;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* move the solution with the best neighbor
|
* move the solution with the best neighbor
|
||||||
* @param _solution the solution to move
|
* @param _solution the solution to move
|
||||||
*/
|
*/
|
||||||
virtual void move(EOT & _solution) {
|
virtual void move(EOT & _solution) {
|
||||||
//move the solution
|
//move the solution
|
||||||
(*best).move(_solution);
|
(*best).move(_solution);
|
||||||
//update its fitness
|
//update its fitness
|
||||||
_solution.fitness((*best).fitness());
|
_solution.fitness((*best).fitness());
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* accept test if an amelirated neighbor was be found
|
* accept test if an amelirated neighbor was be found
|
||||||
* @param _solution the solution
|
* @param _solution the solution
|
||||||
* @return true if the best neighbor ameliorate the fitness
|
* @return true if the best neighbor ameliorate the fitness
|
||||||
*/
|
*/
|
||||||
virtual bool accept(EOT & _solution) {
|
virtual bool accept(EOT & _solution) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the class id.
|
* Return the class id.
|
||||||
* @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 "moVNSexplorer";
|
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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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:
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -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--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -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--;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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++;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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:
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,9 @@ class moRndNeighborhood : virtual public moNeighborhood<Neighbor> {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true
|
* @return true
|
||||||
*/
|
*/
|
||||||
bool isRandom() {
|
bool isRandom() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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:
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
moMaxSATincrEval(MaxSATeval<EOT> & _fulleval) : fulleval(_fulleval) {
|
||||||
nbClauses = _fulleval.nbClauses;
|
nbClauses = _fulleval.nbClauses;
|
||||||
nbVar = _fulleval.nbVar;
|
nbVar = _fulleval.nbVar;
|
||||||
|
|
||||||
clauses = _fulleval.clauses;
|
clauses = _fulleval.clauses;
|
||||||
variables = _fulleval.variables;
|
variables = _fulleval.variables;
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* incremental evaluation of the neighbor for the max SAT problem
|
|
||||||
* @param _solution the solution (of type bit string) to move
|
|
||||||
* @param _neighbor the neighbor (of type moBitNeigbor) to consider
|
|
||||||
*/
|
|
||||||
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
|
|
||||||
// the difference of fitness
|
|
||||||
int delta = 0;
|
|
||||||
|
|
||||||
// the flipped bit
|
|
||||||
unsigned int bit = _neighbor.index();
|
|
||||||
|
|
||||||
// clauses which can be modified by the flipped bit
|
|
||||||
const vector<int> & modifiedClauses = variables[bit + 1] ; // remember that the variables start at index 1 and not 0
|
|
||||||
unsigned int size = modifiedClauses.size();
|
|
||||||
|
|
||||||
int nc;
|
|
||||||
bool litt;
|
|
||||||
|
|
||||||
for(unsigned int k = 0; k < size; k++) {
|
|
||||||
// number of the clause
|
|
||||||
nc = modifiedClauses[k];
|
|
||||||
|
|
||||||
// negative means that the not(variable) is in the clause
|
|
||||||
if (nc < 0) {
|
|
||||||
nc = - nc;
|
|
||||||
litt = !_solution[bit];
|
|
||||||
} else
|
|
||||||
litt = _solution[bit];
|
|
||||||
|
|
||||||
if (litt) {
|
|
||||||
// the litteral was true and becomes false
|
|
||||||
_solution[bit] = !_solution[bit];
|
|
||||||
|
|
||||||
if (!fulleval.clauseEval(nc, _solution))
|
|
||||||
// the clause was true and becomes false
|
|
||||||
delta--;
|
|
||||||
|
|
||||||
_solution[bit] = !_solution[bit];
|
|
||||||
} else {
|
|
||||||
// the litteral was false and becomes true
|
|
||||||
if (!fulleval.clauseEval(nc, _solution))
|
|
||||||
// the clause was false and becomes true
|
|
||||||
delta++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_neighbor.fitness(_solution.fitness() + delta);
|
/*
|
||||||
}
|
* incremental evaluation of the neighbor for the max SAT problem
|
||||||
|
* @param _solution the solution (of type bit string) to move
|
||||||
|
* @param _neighbor the neighbor (of type moBitNeigbor) to consider
|
||||||
|
*/
|
||||||
|
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
|
||||||
|
// the difference of fitness
|
||||||
|
int delta = 0;
|
||||||
|
|
||||||
|
// the flipped bit
|
||||||
|
unsigned int bit = _neighbor.index();
|
||||||
|
|
||||||
|
// clauses which can be modified by the flipped bit
|
||||||
|
const vector<int> & modifiedClauses = variables[bit + 1] ; // remember that the variables start at index 1 and not 0
|
||||||
|
unsigned int size = modifiedClauses.size();
|
||||||
|
|
||||||
|
int nc;
|
||||||
|
bool litt;
|
||||||
|
|
||||||
|
for (unsigned int k = 0; k < size; k++) {
|
||||||
|
// number of the clause
|
||||||
|
nc = modifiedClauses[k];
|
||||||
|
|
||||||
|
// negative means that the not(variable) is in the clause
|
||||||
|
if (nc < 0) {
|
||||||
|
nc = - nc;
|
||||||
|
litt = !_solution[bit];
|
||||||
|
} else
|
||||||
|
litt = _solution[bit];
|
||||||
|
|
||||||
|
if (litt) {
|
||||||
|
// the litteral was true and becomes false
|
||||||
|
_solution[bit] = !_solution[bit];
|
||||||
|
|
||||||
|
if (!fulleval.clauseEval(nc, _solution))
|
||||||
|
// the clause was true and becomes false
|
||||||
|
delta--;
|
||||||
|
|
||||||
|
_solution[bit] = !_solution[bit];
|
||||||
|
} else {
|
||||||
|
// the litteral was false and becomes true
|
||||||
|
if (!fulleval.clauseEval(nc, _solution))
|
||||||
|
// the clause was false and becomes true
|
||||||
|
delta++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_neighbor.fitness(_solution.fitness() + delta);
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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?
|
// complete block?
|
||||||
unsigned int offset = n * k;
|
unsigned int offset = n * k;
|
||||||
|
|
||||||
unsigned int j = 0;
|
unsigned int j = 0;
|
||||||
while (_solution[offset + j] && j < k) j++;
|
while (_solution[offset + j] && j < k) j++;
|
||||||
|
|
||||||
if (j == k) // the block is complete, so the fitness decreases from one
|
if (j == k) // the block is complete, so the fitness decreases from one
|
||||||
_neighbor.fitness(_solution.fitness() - 1);
|
_neighbor.fitness(_solution.fitness() - 1);
|
||||||
else {
|
else {
|
||||||
if ((_solution[_neighbor.index()] == 0) && (offset + j == _neighbor.index())) { // can the block be filled?
|
if ((_solution[_neighbor.index()] == 0) && (offset + j == _neighbor.index())) { // can the block be filled?
|
||||||
j++; // next bit
|
j++; // next bit
|
||||||
while (_solution[offset + j] && j < k) j++;
|
while (_solution[offset + j] && j < k) j++;
|
||||||
|
|
||||||
if (j == k) // the block can be filled, so the fitness increases from one
|
if (j == k) // the block can be filled, so the fitness increases from one
|
||||||
_neighbor.fitness(_solution.fitness() + 1);
|
_neighbor.fitness(_solution.fitness() + 1);
|
||||||
else
|
else
|
||||||
_neighbor.fitness(_solution.fitness());
|
_neighbor.fitness(_solution.fitness());
|
||||||
} else
|
} else
|
||||||
_neighbor.fitness(_solution.fitness());
|
_neighbor.fitness(_solution.fitness());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// size of the blocks
|
// size of the blocks
|
||||||
unsigned int k;
|
unsigned int k;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -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++)
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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:
|
||||||
|
|
|
||||||
|
|
@ -53,35 +53,35 @@ 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
|
* Default Constructor
|
||||||
* @param _init initialisation method of the solution
|
* @param _init initialisation method of the solution
|
||||||
* @param _neighborhood neighborhood giving neighbor in random order
|
* @param _neighborhood neighborhood giving neighbor in random order
|
||||||
* @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 _nbStep Number of steps of the random walk
|
* @param _nbStep Number of steps of the random walk
|
||||||
*/
|
*/
|
||||||
moAutocorrelationSampling(eoInit<EOT> & _init,
|
moAutocorrelationSampling(eoInit<EOT> & _init,
|
||||||
moNeighborhood<Neighbor> & _neighborhood,
|
moNeighborhood<Neighbor> & _neighborhood,
|
||||||
eoEvalFunc<EOT>& _fullEval,
|
eoEvalFunc<EOT>& _fullEval,
|
||||||
moEval<Neighbor>& _eval,
|
moEval<Neighbor>& _eval,
|
||||||
unsigned int _nbStep) :
|
unsigned int _nbStep) :
|
||||||
moSampling<Neighbor>(_init, * new moRandomWalk<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep), fitnessStat){}
|
moSampling<Neighbor>(_init, * new moRandomWalk<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep), fitnessStat) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default destructor
|
* default destructor
|
||||||
*/
|
*/
|
||||||
~moAutocorrelationSampling() {
|
~moAutocorrelationSampling() {
|
||||||
// delete the pointer on the local search which has been constructed in the constructor
|
// delete the pointer on the local search which has been constructed in the constructor
|
||||||
delete localSearch;
|
delete localSearch;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
moFitnessStat<EOT> fitnessStat;
|
moFitnessStat<EOT> fitnessStat;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,31 +51,31 @@ 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
|
* Default Constructor
|
||||||
* @param _init initialisation method of the solution
|
* @param _init initialisation method of the solution
|
||||||
* @param _fullEval Fitness function, full evaluation function
|
* @param _fullEval Fitness function, full evaluation function
|
||||||
* @param _nbSol Number of solutions in the sample
|
* @param _nbSol Number of solutions in the sample
|
||||||
*/
|
*/
|
||||||
moDensityOfStatesSampling(eoInit<EOT> & _init,
|
moDensityOfStatesSampling(eoInit<EOT> & _init,
|
||||||
eoEvalFunc<EOT>& _fullEval,
|
eoEvalFunc<EOT>& _fullEval,
|
||||||
unsigned int _nbSol) :
|
unsigned int _nbSol) :
|
||||||
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat){}
|
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default destructor
|
* default destructor
|
||||||
*/
|
*/
|
||||||
~moDensityOfStatesSampling() {
|
~moDensityOfStatesSampling() {
|
||||||
// delete the pointer on the local search which has been constructed in the constructor
|
// delete the pointer on the local search which has been constructed in the constructor
|
||||||
delete localSearch;
|
delete localSearch;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
moFitnessStat<EOT> fitnessStat;
|
moFitnessStat<EOT> fitnessStat;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
* Default Constructor
|
||||||
* @param _init initialisation method of the solution
|
* @param _init initialisation method of the solution
|
||||||
* @param _fullEval a full evaluation function
|
* @param _fullEval a full evaluation function
|
||||||
* @param _dist the distance function between solution
|
* @param _dist the distance function between solution
|
||||||
* @param _refSol the reference solution to compute the distance (think of global optimum when possible)
|
* @param _refSol the reference solution to compute the distance (think of global optimum when possible)
|
||||||
* @param _nbSol Number of solutions of the sample
|
* @param _nbSol Number of solutions of the sample
|
||||||
*/
|
*/
|
||||||
moFDCsampling(eoInit<EOT> & _init,
|
moFDCsampling(eoInit<EOT> & _init,
|
||||||
eoEvalFunc<EOT>& _fullEval,
|
eoEvalFunc<EOT>& _fullEval,
|
||||||
eoDistance<EOT>& _dist,
|
eoDistance<EOT>& _dist,
|
||||||
EOT& _refSol,
|
EOT& _refSol,
|
||||||
unsigned int _nbSol) :
|
unsigned int _nbSol) :
|
||||||
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat),
|
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat),
|
||||||
distStat(_dist, _refSol)
|
distStat(_dist, _refSol)
|
||||||
{
|
{
|
||||||
add(distStat);
|
add(distStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default destructor
|
* default destructor
|
||||||
*/
|
*/
|
||||||
~moFDCsampling() {
|
~moFDCsampling() {
|
||||||
// delete the pointer on the local search which has been constructed in the constructor
|
// delete the pointer on the local search which has been constructed in the constructor
|
||||||
delete localSearch;
|
delete localSearch;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
moFitnessStat<EOT> fitnessStat;
|
moFitnessStat<EOT> fitnessStat;
|
||||||
moDistanceStat<EOT> distStat;
|
moDistanceStat<EOT> distStat;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
* Default Constructor
|
||||||
* @param _init initialisation method of the solution
|
* @param _init initialisation method of the solution
|
||||||
* @param _neighborhood neighborhood to get a neighbor
|
* @param _neighborhood neighborhood to get a neighbor
|
||||||
* @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 _nbSol Number of solutions in the sample
|
* @param _nbSol Number of solutions in the sample
|
||||||
*/
|
*/
|
||||||
moFitnessCloudSampling(eoInit<EOT> & _init,
|
moFitnessCloudSampling(eoInit<EOT> & _init,
|
||||||
moNeighborhood<Neighbor> & _neighborhood,
|
moNeighborhood<Neighbor> & _neighborhood,
|
||||||
eoEvalFunc<EOT>& _fullEval,
|
eoEvalFunc<EOT>& _fullEval,
|
||||||
moEval<Neighbor>& _eval,
|
moEval<Neighbor>& _eval,
|
||||||
unsigned int _nbSol) :
|
unsigned int _nbSol) :
|
||||||
moSampling<Neighbor>(_init, * new moDummyLS<Neighbor>(_fullEval), fitnessStat),
|
moSampling<Neighbor>(_init, * new moDummyLS<Neighbor>(_fullEval), fitnessStat),
|
||||||
neighborhood(_neighborhood),
|
neighborhood(_neighborhood),
|
||||||
fullEval(_fullEval),
|
fullEval(_fullEval),
|
||||||
eval(_eval),
|
eval(_eval),
|
||||||
nbSol(_nbSol)
|
nbSol(_nbSol)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default destructor
|
* default destructor
|
||||||
*/
|
*/
|
||||||
~moFitnessCloudSampling() {
|
~moFitnessCloudSampling() {
|
||||||
// delete the pointer on the local search which has been constructed in the constructor
|
// delete the pointer on the local search which has been constructed in the constructor
|
||||||
delete localSearch;
|
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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,52 +58,52 @@ 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
|
* Default Constructor
|
||||||
* @param _init initialisation method of the solution
|
* @param _init initialisation method of the solution
|
||||||
* @param _neighborhood neighborhood giving neighbor in random order
|
* @param _neighborhood neighborhood giving neighbor in random order
|
||||||
* @param _fullEval a full evaluation function
|
* @param _fullEval a full evaluation function
|
||||||
* @param _eval an incremental evaluation of neighbors
|
* @param _eval an incremental evaluation of neighbors
|
||||||
* @param _nbAdaptWalk Number of adaptive walks
|
* @param _nbAdaptWalk Number of adaptive walks
|
||||||
*/
|
*/
|
||||||
moHillClimberSampling(eoInit<EOT> & _init,
|
moHillClimberSampling(eoInit<EOT> & _init,
|
||||||
moNeighborhood<Neighbor> & _neighborhood,
|
moNeighborhood<Neighbor> & _neighborhood,
|
||||||
eoEvalFunc<EOT>& _fullEval,
|
eoEvalFunc<EOT>& _fullEval,
|
||||||
moEval<Neighbor>& _eval,
|
moEval<Neighbor>& _eval,
|
||||||
unsigned int _nbAdaptWalk) :
|
unsigned int _nbAdaptWalk) :
|
||||||
moSampling<Neighbor>(initHC, * new moRandomSearch<Neighbor>(initHC, _fullEval, _nbAdaptWalk), copyStat),
|
moSampling<Neighbor>(initHC, * new moRandomSearch<Neighbor>(initHC, _fullEval, _nbAdaptWalk), copyStat),
|
||||||
copyStat(lengthStat),
|
copyStat(lengthStat),
|
||||||
checkpoint(trueCont),
|
checkpoint(trueCont),
|
||||||
hc(_neighborhood, _fullEval, _eval, checkpoint),
|
hc(_neighborhood, _fullEval, _eval, checkpoint),
|
||||||
initHC(_init, hc)
|
initHC(_init, hc)
|
||||||
{
|
{
|
||||||
// to count the number of step in the HC
|
// to count the number of step in the HC
|
||||||
checkpoint.add(lengthStat);
|
checkpoint.add(lengthStat);
|
||||||
|
|
||||||
// add the solution into statistics
|
// add the solution into statistics
|
||||||
add(solStat);
|
add(solStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default destructor
|
* default destructor
|
||||||
*/
|
*/
|
||||||
~moHillClimberSampling() {
|
~moHillClimberSampling() {
|
||||||
// delete the pointer on the local search which has been constructed in the constructor
|
// delete the pointer on the local search which has been constructed in the constructor
|
||||||
delete localSearch;
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,53 +59,53 @@ 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>::localSearch;
|
||||||
using moSampling<Neighbor>::checkpoint;
|
using moSampling<Neighbor>::checkpoint;
|
||||||
using moSampling<Neighbor>::monitorVec;
|
using moSampling<Neighbor>::monitorVec;
|
||||||
using moSampling<Neighbor>::continuator;
|
using moSampling<Neighbor>::continuator;
|
||||||
using moFitnessCloudSampling<Neighbor>::fitnessStat;
|
using moFitnessCloudSampling<Neighbor>::fitnessStat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
* @param _init initialisation method of the solution
|
* @param _init initialisation method of the solution
|
||||||
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
|
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
|
||||||
* @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 _nbStep Number of step of the MH sampling
|
* @param _nbStep Number of step of the MH sampling
|
||||||
*/
|
*/
|
||||||
moMHBestFitnessCloudSampling(eoInit<EOT> & _init,
|
moMHBestFitnessCloudSampling(eoInit<EOT> & _init,
|
||||||
moNeighborhood<Neighbor> & _neighborhood,
|
moNeighborhood<Neighbor> & _neighborhood,
|
||||||
eoEvalFunc<EOT>& _fullEval,
|
eoEvalFunc<EOT>& _fullEval,
|
||||||
moEval<Neighbor>& _eval,
|
moEval<Neighbor>& _eval,
|
||||||
unsigned int _nbStep) :
|
unsigned int _nbStep) :
|
||||||
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbStep),
|
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbStep),
|
||||||
neighborBestStat(_neighborhood, _eval)
|
neighborBestStat(_neighborhood, _eval)
|
||||||
{
|
{
|
||||||
// delete the dummy local search
|
// delete the dummy local search
|
||||||
delete localSearch;
|
delete localSearch;
|
||||||
|
|
||||||
// Metropolis-Hasting sampling
|
// Metropolis-Hasting sampling
|
||||||
localSearch = new moMetropolisHasting<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep);
|
localSearch = new moMetropolisHasting<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep);
|
||||||
|
|
||||||
// delete the checkpoint with the wrong continuator
|
// delete the checkpoint with the wrong continuator
|
||||||
delete checkpoint;
|
delete checkpoint;
|
||||||
|
|
||||||
// set the continuator
|
// set the continuator
|
||||||
continuator = localSearch->getContinuator();
|
continuator = localSearch->getContinuator();
|
||||||
|
|
||||||
// re-construction of the checkpoint
|
// re-construction of the checkpoint
|
||||||
checkpoint = new moCheckpoint<Neighbor>(*continuator);
|
checkpoint = new moCheckpoint<Neighbor>(*continuator);
|
||||||
checkpoint->add(fitnessStat);
|
checkpoint->add(fitnessStat);
|
||||||
checkpoint->add(*monitorVec[0]);
|
checkpoint->add(*monitorVec[0]);
|
||||||
|
|
||||||
// one random neighbor
|
// one random neighbor
|
||||||
add(neighborBestStat);
|
add(neighborBestStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
moNeighborBestStat< Neighbor > neighborBestStat;
|
moNeighborBestStat< Neighbor > neighborBestStat;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,53 +59,53 @@ 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>::localSearch;
|
||||||
using moSampling<Neighbor>::checkpoint;
|
using moSampling<Neighbor>::checkpoint;
|
||||||
using moSampling<Neighbor>::monitorVec;
|
using moSampling<Neighbor>::monitorVec;
|
||||||
using moSampling<Neighbor>::continuator;
|
using moSampling<Neighbor>::continuator;
|
||||||
using moFitnessCloudSampling<Neighbor>::fitnessStat;
|
using moFitnessCloudSampling<Neighbor>::fitnessStat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
* @param _init initialisation method of the solution
|
* @param _init initialisation method of the solution
|
||||||
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
|
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
|
||||||
* @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 _nbStep Number of step of the MH sampling
|
* @param _nbStep Number of step of the MH sampling
|
||||||
*/
|
*/
|
||||||
moMHRndFitnessCloudSampling(eoInit<EOT> & _init,
|
moMHRndFitnessCloudSampling(eoInit<EOT> & _init,
|
||||||
moNeighborhood<Neighbor> & _neighborhood,
|
moNeighborhood<Neighbor> & _neighborhood,
|
||||||
eoEvalFunc<EOT>& _fullEval,
|
eoEvalFunc<EOT>& _fullEval,
|
||||||
moEval<Neighbor>& _eval,
|
moEval<Neighbor>& _eval,
|
||||||
unsigned int _nbStep) :
|
unsigned int _nbStep) :
|
||||||
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbStep),
|
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbStep),
|
||||||
neighborFitnessStat(_neighborhood, _eval)
|
neighborFitnessStat(_neighborhood, _eval)
|
||||||
{
|
{
|
||||||
// delete the dummy local search
|
// delete the dummy local search
|
||||||
delete localSearch;
|
delete localSearch;
|
||||||
|
|
||||||
// Metropolis-Hasting sampling
|
// Metropolis-Hasting sampling
|
||||||
localSearch = new moMetropolisHasting<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep);
|
localSearch = new moMetropolisHasting<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep);
|
||||||
|
|
||||||
// delete the checkpoint with the wrong continuator
|
// delete the checkpoint with the wrong continuator
|
||||||
delete checkpoint;
|
delete checkpoint;
|
||||||
|
|
||||||
// set the continuator
|
// set the continuator
|
||||||
continuator = localSearch->getContinuator();
|
continuator = localSearch->getContinuator();
|
||||||
|
|
||||||
// re-construction of the checkpoint
|
// re-construction of the checkpoint
|
||||||
checkpoint = new moCheckpoint<Neighbor>(*continuator);
|
checkpoint = new moCheckpoint<Neighbor>(*continuator);
|
||||||
checkpoint->add(fitnessStat);
|
checkpoint->add(fitnessStat);
|
||||||
checkpoint->add(*monitorVec[0]);
|
checkpoint->add(*monitorVec[0]);
|
||||||
|
|
||||||
// one random neighbor
|
// one random neighbor
|
||||||
add(neighborFitnessStat);
|
add(neighborFitnessStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
moNeighborFitnessStat< Neighbor > neighborFitnessStat;
|
moNeighborFitnessStat< Neighbor > neighborFitnessStat;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,68 +56,68 @@ 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
|
* 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 _nbSol Number of solutions in the sample
|
* @param _nbSol Number of solutions in the sample
|
||||||
*/
|
*/
|
||||||
moNeutralDegreeSampling(eoInit<EOT> & _init,
|
moNeutralDegreeSampling(eoInit<EOT> & _init,
|
||||||
moNeighborhood<Neighbor> & _neighborhood,
|
moNeighborhood<Neighbor> & _neighborhood,
|
||||||
eoEvalFunc<EOT>& _fullEval,
|
eoEvalFunc<EOT>& _fullEval,
|
||||||
moEval<Neighbor>& _eval,
|
moEval<Neighbor>& _eval,
|
||||||
unsigned int _nbSol) :
|
unsigned int _nbSol) :
|
||||||
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat),
|
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat),
|
||||||
neighborhoodStat(_neighborhood, _eval),
|
neighborhoodStat(_neighborhood, _eval),
|
||||||
ndStat(neighborhoodStat)
|
ndStat(neighborhoodStat)
|
||||||
{
|
{
|
||||||
add(neighborhoodStat, false);
|
add(neighborhoodStat, false);
|
||||||
add(ndStat);
|
add(ndStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor with comparators
|
* Constructor with comparators
|
||||||
* @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 _neighborComparator a neighbor Comparator
|
||||||
* @param _solNeighborComparator a comparator between a solution and a neighbor
|
* @param _solNeighborComparator a comparator between a solution and a neighbor
|
||||||
* @param _nbSol Number of solutions in the sample
|
* @param _nbSol Number of solutions in the sample
|
||||||
*/
|
*/
|
||||||
moNeutralDegreeSampling(eoInit<EOT> & _init,
|
moNeutralDegreeSampling(eoInit<EOT> & _init,
|
||||||
moNeighborhood<Neighbor> & _neighborhood,
|
moNeighborhood<Neighbor> & _neighborhood,
|
||||||
eoEvalFunc<EOT>& _fullEval,
|
eoEvalFunc<EOT>& _fullEval,
|
||||||
moEval<Neighbor>& _eval,
|
moEval<Neighbor>& _eval,
|
||||||
moNeighborComparator<Neighbor>& _neighborComparator,
|
moNeighborComparator<Neighbor>& _neighborComparator,
|
||||||
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
|
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
|
||||||
unsigned int _nbSol) :
|
unsigned int _nbSol) :
|
||||||
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat),
|
moSampling<Neighbor>(_init, * new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol), fitnessStat),
|
||||||
neighborhoodStat(_neighborhood, _eval, _neighborComparator, _solNeighborComparator),
|
neighborhoodStat(_neighborhood, _eval, _neighborComparator, _solNeighborComparator),
|
||||||
ndStat(neighborhoodStat)
|
ndStat(neighborhoodStat)
|
||||||
{
|
{
|
||||||
add(neighborhoodStat, false);
|
add(neighborhoodStat, false);
|
||||||
add(ndStat);
|
add(ndStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default destructor
|
* default destructor
|
||||||
*/
|
*/
|
||||||
~moNeutralDegreeSampling() {
|
~moNeutralDegreeSampling() {
|
||||||
// delete the pointer on the local search which has been constructed in the constructor
|
// delete the pointer on the local search which has been constructed in the constructor
|
||||||
delete localSearch;
|
delete localSearch;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
moFitnessStat<EOT> fitnessStat;
|
moFitnessStat<EOT> fitnessStat;
|
||||||
moNeighborhoodStat< Neighbor > neighborhoodStat;
|
moNeighborhoodStat< Neighbor > neighborhoodStat;
|
||||||
moNeutralDegreeNeighborStat< Neighbor > ndStat;
|
moNeutralDegreeNeighborStat< Neighbor > ndStat;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
* Default Constructor
|
||||||
* @param _initSol the first the solution of the walk
|
* @param _initSol the first the solution of the walk
|
||||||
* @param _neighborhood neighborhood giving neighbor in random order
|
* @param _neighborhood neighborhood giving neighbor in random order
|
||||||
* @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 _distance the distance to measure the distance from the initial solution
|
* @param _distance the distance to measure the distance from the initial solution
|
||||||
* @param _nbStep Number of steps of the random walk
|
* @param _nbStep Number of steps of the random walk
|
||||||
*/
|
*/
|
||||||
moNeutralWalkSampling(EOT & _initSol,
|
moNeutralWalkSampling(EOT & _initSol,
|
||||||
moNeighborhood<Neighbor> & _neighborhood,
|
moNeighborhood<Neighbor> & _neighborhood,
|
||||||
eoEvalFunc<EOT>& _fullEval,
|
eoEvalFunc<EOT>& _fullEval,
|
||||||
moEval<Neighbor>& _eval,
|
moEval<Neighbor>& _eval,
|
||||||
eoDistance<EOT> & _distance,
|
eoDistance<EOT> & _distance,
|
||||||
unsigned int _nbStep) :
|
unsigned int _nbStep) :
|
||||||
moSampling<Neighbor>(init, * new moRandomNeutralWalk<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep), solutionStat),
|
moSampling<Neighbor>(init, * new moRandomNeutralWalk<Neighbor>(_neighborhood, _fullEval, _eval, _nbStep), solutionStat),
|
||||||
init(_initSol),
|
init(_initSol),
|
||||||
distStat(_distance, _initSol),
|
distStat(_distance, _initSol),
|
||||||
neighborhoodStat(_neighborhood, _eval),
|
neighborhoodStat(_neighborhood, _eval),
|
||||||
minStat(neighborhoodStat),
|
minStat(neighborhoodStat),
|
||||||
averageStat(neighborhoodStat),
|
averageStat(neighborhoodStat),
|
||||||
stdStat(neighborhoodStat),
|
stdStat(neighborhoodStat),
|
||||||
maxStat(neighborhoodStat),
|
maxStat(neighborhoodStat),
|
||||||
nbSupStat(neighborhoodStat),
|
nbSupStat(neighborhoodStat),
|
||||||
nbInfStat(neighborhoodStat),
|
nbInfStat(neighborhoodStat),
|
||||||
sizeStat(neighborhoodStat),
|
sizeStat(neighborhoodStat),
|
||||||
ndStat(neighborhoodStat)
|
ndStat(neighborhoodStat)
|
||||||
{
|
{
|
||||||
add(neighborhoodStat, false);
|
add(neighborhoodStat, false);
|
||||||
add(distStat);
|
add(distStat);
|
||||||
add(minStat);
|
add(minStat);
|
||||||
add(averageStat);
|
add(averageStat);
|
||||||
add(stdStat);
|
add(stdStat);
|
||||||
add(maxStat);
|
add(maxStat);
|
||||||
add(sizeStat);
|
add(sizeStat);
|
||||||
add(nbInfStat);
|
add(nbInfStat);
|
||||||
add(ndStat);
|
add(ndStat);
|
||||||
add(nbSupStat);
|
add(nbSupStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default destructor
|
* default destructor
|
||||||
*/
|
*/
|
||||||
~moNeutralWalkSampling() {
|
~moNeutralWalkSampling() {
|
||||||
// delete the pointer on the local search which has been constructed in the constructor
|
// delete the pointer on the local search which has been constructed in the constructor
|
||||||
delete localSearch;
|
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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,53 +57,53 @@ 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>::localSearch;
|
||||||
using moSampling<Neighbor>::checkpoint;
|
using moSampling<Neighbor>::checkpoint;
|
||||||
using moSampling<Neighbor>::monitorVec;
|
using moSampling<Neighbor>::monitorVec;
|
||||||
using moSampling<Neighbor>::continuator;
|
using moSampling<Neighbor>::continuator;
|
||||||
using moFitnessCloudSampling<Neighbor>::fitnessStat;
|
using moFitnessCloudSampling<Neighbor>::fitnessStat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
* @param _init initialisation method of the solution
|
* @param _init initialisation method of the solution
|
||||||
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
|
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
|
||||||
* @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 _nbSol Number of solutions in the sample
|
* @param _nbSol Number of solutions in the sample
|
||||||
*/
|
*/
|
||||||
moRndBestFitnessCloudSampling(eoInit<EOT> & _init,
|
moRndBestFitnessCloudSampling(eoInit<EOT> & _init,
|
||||||
moNeighborhood<Neighbor> & _neighborhood,
|
moNeighborhood<Neighbor> & _neighborhood,
|
||||||
eoEvalFunc<EOT>& _fullEval,
|
eoEvalFunc<EOT>& _fullEval,
|
||||||
moEval<Neighbor>& _eval,
|
moEval<Neighbor>& _eval,
|
||||||
unsigned int _nbSol) :
|
unsigned int _nbSol) :
|
||||||
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbSol),
|
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbSol),
|
||||||
neighborBestStat(_neighborhood, _eval)
|
neighborBestStat(_neighborhood, _eval)
|
||||||
{
|
{
|
||||||
// delete the dummy local search
|
// delete the dummy local search
|
||||||
delete localSearch;
|
delete localSearch;
|
||||||
|
|
||||||
// random sampling
|
// random sampling
|
||||||
localSearch = new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol);
|
localSearch = new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol);
|
||||||
|
|
||||||
// delete the checkpoint with the wrong continuator
|
// delete the checkpoint with the wrong continuator
|
||||||
delete checkpoint;
|
delete checkpoint;
|
||||||
|
|
||||||
// set the continuator
|
// set the continuator
|
||||||
continuator = localSearch->getContinuator();
|
continuator = localSearch->getContinuator();
|
||||||
|
|
||||||
// re-construction of the checkpoint
|
// re-construction of the checkpoint
|
||||||
checkpoint = new moCheckpoint<Neighbor>(*continuator);
|
checkpoint = new moCheckpoint<Neighbor>(*continuator);
|
||||||
checkpoint->add(fitnessStat);
|
checkpoint->add(fitnessStat);
|
||||||
checkpoint->add(*monitorVec[0]);
|
checkpoint->add(*monitorVec[0]);
|
||||||
|
|
||||||
// one random neighbor
|
// one random neighbor
|
||||||
add(neighborBestStat);
|
add(neighborBestStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
moNeighborBestStat< Neighbor > neighborBestStat;
|
moNeighborBestStat< Neighbor > neighborBestStat;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,53 +57,53 @@ 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>::localSearch;
|
||||||
using moSampling<Neighbor>::checkpoint;
|
using moSampling<Neighbor>::checkpoint;
|
||||||
using moSampling<Neighbor>::monitorVec;
|
using moSampling<Neighbor>::monitorVec;
|
||||||
using moSampling<Neighbor>::continuator;
|
using moSampling<Neighbor>::continuator;
|
||||||
using moFitnessCloudSampling<Neighbor>::fitnessStat;
|
using moFitnessCloudSampling<Neighbor>::fitnessStat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
* @param _init initialisation method of the solution
|
* @param _init initialisation method of the solution
|
||||||
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
|
* @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood)
|
||||||
* @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 _nbSol Number of solutions in the sample
|
* @param _nbSol Number of solutions in the sample
|
||||||
*/
|
*/
|
||||||
moRndRndFitnessCloudSampling(eoInit<EOT> & _init,
|
moRndRndFitnessCloudSampling(eoInit<EOT> & _init,
|
||||||
moNeighborhood<Neighbor> & _neighborhood,
|
moNeighborhood<Neighbor> & _neighborhood,
|
||||||
eoEvalFunc<EOT>& _fullEval,
|
eoEvalFunc<EOT>& _fullEval,
|
||||||
moEval<Neighbor>& _eval,
|
moEval<Neighbor>& _eval,
|
||||||
unsigned int _nbSol) :
|
unsigned int _nbSol) :
|
||||||
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbSol),
|
moFitnessCloudSampling<Neighbor>(_init, _neighborhood, _fullEval, _eval, _nbSol),
|
||||||
neighborFitnessStat(_neighborhood, _eval)
|
neighborFitnessStat(_neighborhood, _eval)
|
||||||
{
|
{
|
||||||
// delete the dummy local search
|
// delete the dummy local search
|
||||||
delete localSearch;
|
delete localSearch;
|
||||||
|
|
||||||
// random sampling
|
// random sampling
|
||||||
localSearch = new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol);
|
localSearch = new moRandomSearch<Neighbor>(_init, _fullEval, _nbSol);
|
||||||
|
|
||||||
// delete the checkpoint with the wrong continuator
|
// delete the checkpoint with the wrong continuator
|
||||||
delete checkpoint;
|
delete checkpoint;
|
||||||
|
|
||||||
// set the continuator
|
// set the continuator
|
||||||
continuator = localSearch->getContinuator();
|
continuator = localSearch->getContinuator();
|
||||||
|
|
||||||
// re-construction of the checkpoint
|
// re-construction of the checkpoint
|
||||||
checkpoint = new moCheckpoint<Neighbor>(*continuator);
|
checkpoint = new moCheckpoint<Neighbor>(*continuator);
|
||||||
checkpoint->add(fitnessStat);
|
checkpoint->add(fitnessStat);
|
||||||
checkpoint->add(*monitorVec[0]);
|
checkpoint->add(*monitorVec[0]);
|
||||||
|
|
||||||
// one random neighbor
|
// one random neighbor
|
||||||
add(neighborFitnessStat);
|
add(neighborFitnessStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
moNeighborFitnessStat< Neighbor > neighborFitnessStat;
|
moNeighborFitnessStat< Neighbor > neighborFitnessStat;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,152 +58,152 @@ 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
|
* Default Constructor
|
||||||
* @param _init initialisation method of the solution
|
* @param _init initialisation method of the solution
|
||||||
* @param _localSearch local search to sample the search space
|
* @param _localSearch local search to sample the search space
|
||||||
* @param _stat statistic to compute during the search
|
* @param _stat statistic to compute during the search
|
||||||
* @param _monitoring the statistic is saved into the monitor if true
|
* @param _monitoring the statistic is saved into the monitor if true
|
||||||
*/
|
*/
|
||||||
template <class ValueType>
|
template <class ValueType>
|
||||||
moSampling(eoInit<EOT> & _init, moLocalSearch<Neighbor> & _localSearch, moStat<EOT,ValueType> & _stat, bool _monitoring = true) : init(_init), localSearch(&_localSearch), continuator(_localSearch.getContinuator())
|
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);
|
checkpoint = new moCheckpoint<Neighbor>(*continuator);
|
||||||
add(_stat, _monitoring);
|
add(_stat, _monitoring);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* default destructor
|
|
||||||
*/
|
|
||||||
~moSampling() {
|
|
||||||
// delete all monitors
|
|
||||||
for(unsigned i = 0; i < monitorVec.size(); i++)
|
|
||||||
delete monitorVec[i];
|
|
||||||
|
|
||||||
// delete the checkpoint
|
|
||||||
delete checkpoint ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a statistic
|
|
||||||
* @param _stat another statistic to compute during the search
|
|
||||||
* @param _monitoring the statistic is saved into the monitor if true
|
|
||||||
*/
|
|
||||||
template< class ValueType >
|
|
||||||
void add(moStat<EOT, ValueType> & _stat, bool _monitoring = true) {
|
|
||||||
checkpoint->add(_stat);
|
|
||||||
|
|
||||||
if (_monitoring) {
|
|
||||||
moVectorMonitor<EOT> * monitor = new moVectorMonitor<EOT>(_stat);
|
|
||||||
monitorVec.push_back(monitor);
|
|
||||||
checkpoint->add(*monitor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* To sample the search and get the statistics
|
|
||||||
* the statistics are stored in the moVectorMonitor vector
|
|
||||||
*/
|
|
||||||
void operator()(void) {
|
|
||||||
// clear all statistic vectors
|
|
||||||
for(unsigned i = 0; i < monitorVec.size(); i++)
|
|
||||||
monitorVec[i]->clear();
|
|
||||||
|
|
||||||
// change the checkpoint to compute the statistics
|
|
||||||
localSearch->setContinuator(*checkpoint);
|
|
||||||
|
|
||||||
// the initial solution
|
|
||||||
EOT solution;
|
|
||||||
|
|
||||||
// initialisation of the solution
|
|
||||||
init(solution);
|
|
||||||
|
|
||||||
// compute the sampling
|
|
||||||
(*localSearch)(solution);
|
|
||||||
|
|
||||||
// set back to initial continuator
|
|
||||||
localSearch->setContinuator(*continuator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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();
|
* default destructor
|
||||||
|
*/
|
||||||
|
~moSampling() {
|
||||||
|
// delete all monitors
|
||||||
|
for (unsigned i = 0; i < monitorVec.size(); i++)
|
||||||
|
delete monitorVec[i];
|
||||||
|
|
||||||
for(unsigned int i = 0; i < vecSize; i++) {
|
// delete the checkpoint
|
||||||
os << monitorVec[0]->getValue(i);
|
delete checkpoint ;
|
||||||
|
|
||||||
for(unsigned int j = 1; j < monitorVec.size(); j++) {
|
|
||||||
os << _delim.c_str() << monitorVec[j]->getValue(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
os << std::endl ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* Add a statistic
|
||||||
|
* @param _stat another statistic to compute during the search
|
||||||
|
* @param _monitoring the statistic is saved into the monitor if true
|
||||||
|
*/
|
||||||
|
template< class ValueType >
|
||||||
|
void add(moStat<EOT, ValueType> & _stat, bool _monitoring = true) {
|
||||||
|
checkpoint->add(_stat);
|
||||||
|
|
||||||
/**
|
if (_monitoring) {
|
||||||
* to export one vector of values into a file
|
moVectorMonitor<EOT> * monitor = new moVectorMonitor<EOT>(_stat);
|
||||||
* @param _col number of vector to print into file
|
monitorVec.push_back(monitor);
|
||||||
* @param _filename file name
|
checkpoint->add(*monitor);
|
||||||
*/
|
}
|
||||||
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 sample the search and get the statistics
|
||||||
|
* the statistics are stored in the moVectorMonitor vector
|
||||||
|
*/
|
||||||
|
void operator()(void) {
|
||||||
|
// clear all statistic vectors
|
||||||
|
for (unsigned i = 0; i < monitorVec.size(); i++)
|
||||||
|
monitorVec[i]->clear();
|
||||||
|
|
||||||
/**
|
// change the checkpoint to compute the statistics
|
||||||
* to get one vector of values
|
localSearch->setContinuator(*checkpoint);
|
||||||
* @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();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// the initial solution
|
||||||
* to get one vector of solutions values
|
EOT solution;
|
||||||
* @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();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// initialisation of the solution
|
||||||
* @return name of the class
|
init(solution);
|
||||||
*/
|
|
||||||
virtual std::string className(void) const {
|
// compute the sampling
|
||||||
return "moSampling";
|
(*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);
|
||||||
|
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,167 +48,167 @@
|
||||||
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) {
|
if (data.size() == 0) {
|
||||||
min = 0.0;
|
min = 0.0;
|
||||||
max = 0.0;
|
max = 0.0;
|
||||||
avg = 0.0;
|
avg = 0.0;
|
||||||
std = 0.0;
|
std = 0.0;
|
||||||
} else {
|
} else {
|
||||||
unsigned int n = data.size();
|
unsigned int n = data.size();
|
||||||
|
|
||||||
min = data[0];
|
min = data[0];
|
||||||
max = data[0];
|
max = data[0];
|
||||||
avg = 0.0;
|
avg = 0.0;
|
||||||
std = 0.0;
|
std = 0.0;
|
||||||
|
|
||||||
double d;
|
double d;
|
||||||
for(unsigned int i = 0; i < n; i++) {
|
for (unsigned int i = 0; i < n; i++) {
|
||||||
d = data[i];
|
d = data[i];
|
||||||
if (d < min)
|
if (d < min)
|
||||||
min = d;
|
min = d;
|
||||||
if (max < d)
|
if (max < d)
|
||||||
max = d;
|
max = d;
|
||||||
avg += d;
|
avg += d;
|
||||||
std += d * d;
|
std += d * d;
|
||||||
}
|
}
|
||||||
|
|
||||||
avg /= n;
|
avg /= n;
|
||||||
|
|
||||||
std = std / n - avg * avg ;
|
std = std / n - avg * avg ;
|
||||||
if (std > 0)
|
if (std > 0)
|
||||||
std = sqrt(std);
|
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;
|
unsigned s, k;
|
||||||
|
|
||||||
for(s = 0; s <= nbS; s++) {
|
for (s = 0; s <= nbS; s++) {
|
||||||
cov[s] = 0;
|
cov[s] = 0;
|
||||||
m[s] = 0;
|
m[s] = 0;
|
||||||
sig[s] = 0;
|
sig[s] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
double m0, s0;
|
double m0, s0;
|
||||||
unsigned j;
|
unsigned j;
|
||||||
|
|
||||||
k = 0;
|
k = 0;
|
||||||
s = nbS;
|
s = nbS;
|
||||||
while (s > 0) {
|
while (s > 0) {
|
||||||
while (k + s < n) {
|
while (k + s < n) {
|
||||||
for(j = 0; j <= s; j++) {
|
for (j = 0; j <= s; j++) {
|
||||||
m[j] += data[k+j];
|
m[j] += data[k+j];
|
||||||
sig[j] += data[k+j] * data[k+j];
|
sig[j] += data[k+j] * data[k+j];
|
||||||
cov[j] += data[k] * data[k+j];
|
cov[j] += data[k] * data[k+j];
|
||||||
}
|
}
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
|
|
||||||
m[s] /= n - s;
|
m[s] /= n - s;
|
||||||
sig[s] = sig[s] / (n - s) - m[s] * m[s];
|
sig[s] = sig[s] / (n - s) - m[s] * m[s];
|
||||||
if (sig[s] <= 0)
|
if (sig[s] <= 0)
|
||||||
sig[s] = 0;
|
sig[s] = 0;
|
||||||
else
|
else
|
||||||
sig[s] = sqrt(sig[s]);
|
sig[s] = sqrt(sig[s]);
|
||||||
m0 = m[0] / (n - s);
|
m0 = m[0] / (n - s);
|
||||||
s0 = sqrt(sig[0] / (n - s) - m0 * m0);
|
s0 = sqrt(sig[0] / (n - s) - m0 * m0);
|
||||||
cov[s] = cov[s] / (n - s) - (m[0] / (n - s)) * m[s];
|
cov[s] = cov[s] / (n - s) - (m[0] / (n - s)) * m[s];
|
||||||
rho[s] = cov[s] / (sig[s] * s0);
|
rho[s] = cov[s] / (sig[s] * s0);
|
||||||
s--;
|
s--;
|
||||||
}
|
}
|
||||||
|
|
||||||
double phi2[nbS+1][nbS+1];
|
double phi2[nbS+1][nbS+1];
|
||||||
double tmp1, tmp2;
|
double tmp1, tmp2;
|
||||||
|
|
||||||
phi2[1][1] = rho[1];
|
phi2[1][1] = rho[1];
|
||||||
for(k = 2; k <= nbS; k++) {
|
for (k = 2; k <= nbS; k++) {
|
||||||
tmp1 = 0;
|
tmp1 = 0;
|
||||||
tmp2 = 0;
|
tmp2 = 0;
|
||||||
for(j = 1; j < k; j++) {
|
for (j = 1; j < k; j++) {
|
||||||
tmp1 += phi2[k-1][j] * rho[k-j];
|
tmp1 += phi2[k-1][j] * rho[k-j];
|
||||||
tmp2 += phi2[k-1][j] * rho[j];
|
tmp2 += phi2[k-1][j] * rho[j];
|
||||||
}
|
}
|
||||||
phi2[k][k] = (rho[k] - tmp1) / (1 - tmp2);
|
phi2[k][k] = (rho[k] - tmp1) / (1 - tmp2);
|
||||||
for(j = 1; j < k; j++)
|
for (j = 1; j < k; j++)
|
||||||
phi2[k][j] = phi2[k-1][j] - phi2[k][k] * phi2[k-1][k-j];
|
phi2[k][j] = phi2[k-1][j] - phi2[k][k] * phi2[k-1][k-j];
|
||||||
}
|
}
|
||||||
|
|
||||||
for(j = 1; j <= nbS; j++)
|
for (j = 1; j <= nbS; j++)
|
||||||
phi[j] = phi2[j][j];
|
phi[j] = phi2[j][j];
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue