From 3d8057ac4dfeff00d99208803472222050234578 Mon Sep 17 00:00:00 2001 From: jhumeau Date: Mon, 17 May 2010 14:56:42 +0000 Subject: [PATCH] Passage du code dans un pretty printer git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1813 331e1502-861f-0410-8da2-ba01fb791d7f --- .../src/acceptCrit/moAcceptanceCriterion.h | 2 +- .../src/acceptCrit/moAlwaysAcceptCrit.h | 22 +- .../src/acceptCrit/moBetterAcceptCrit.h | 26 +- trunk/paradiseo-mo/src/algo/moDummyLS.h | 44 +-- trunk/paradiseo-mo/src/algo/moFirstImprHC.h | 96 +++--- trunk/paradiseo-mo/src/algo/moILS.h | 56 ++-- trunk/paradiseo-mo/src/algo/moLocalSearch.h | 26 +- .../src/algo/moMetropolisHasting.h | 102 +++--- trunk/paradiseo-mo/src/algo/moNeutralHC.h | 100 +++--- trunk/paradiseo-mo/src/algo/moRandomBestHC.h | 96 +++--- .../src/algo/moRandomNeutralWalk.h | 96 +++--- trunk/paradiseo-mo/src/algo/moRandomSearch.h | 72 ++--- trunk/paradiseo-mo/src/algo/moRandomWalk.h | 64 ++-- trunk/paradiseo-mo/src/algo/moSA.h | 40 +-- trunk/paradiseo-mo/src/algo/moSimpleHC.h | 96 +++--- trunk/paradiseo-mo/src/algo/moTS.h | 90 +++--- .../src/comparator/moComparator.h | 10 +- .../src/continuator/moBestSoFarStat.h | 66 ++-- .../src/continuator/moCombinedContinuator.h | 84 ++--- .../src/continuator/moCounterStat.h | 62 ++-- .../src/continuator/moDistanceStat.h | 6 +- .../src/continuator/moFitContinuator.h | 34 +- .../src/continuator/moFitnessStat.h | 66 ++-- .../src/continuator/moFullEvalContinuator.h | 66 ++-- .../src/continuator/moIterContinuator.h | 26 +- .../src/continuator/moMinusOneCounterStat.h | 76 ++--- .../src/continuator/moNeighborBestStat.h | 66 ++-- .../continuator/moNeighborEvalContinuator.h | 72 ++--- .../src/continuator/moNeighborFitnessStat.h | 110 +++---- .../src/continuator/moNeighborhoodStat.h | 4 +- .../paradiseo-mo/src/continuator/moStatBase.h | 2 +- .../src/continuator/moStatFromStat.h | 66 ++-- .../src/continuator/moTimeContinuator.h | 10 +- .../src/continuator/moVectorMonitor.h | 290 +++++++++--------- .../src/coolingSchedule/moCoolingSchedule.h | 22 +- .../moDynSpanCoolingSchedule.h | 130 ++++---- .../coolingSchedule/moSimpleCoolingSchedule.h | 96 +++--- trunk/paradiseo-mo/src/eval/moDummyEval.h | 12 +- trunk/paradiseo-mo/src/eval/moEvalCounter.h | 36 +-- .../src/explorer/moDummyExplorer.h | 20 +- .../paradiseo-mo/src/explorer/moILSexplorer.h | 106 +++---- .../src/explorer/moNeutralHCexplorer.h | 6 +- .../src/explorer/moRandomBestHCexplorer.h | 8 +- .../explorer/moRandomNeutralWalkExplorer.h | 2 +- .../src/explorer/moRandomSearchExplorer.h | 182 +++++------ .../paradiseo-mo/src/explorer/moSAexplorer.h | 34 +- .../paradiseo-mo/src/explorer/moVNSexplorer.h | 164 +++++----- .../src/memory/moCountMoveMemory.h | 40 +-- .../src/memory/moDiversification.h | 2 +- trunk/paradiseo-mo/src/memory/moDummyMemory.h | 4 +- .../src/memory/moIntensification.h | 2 +- .../src/memory/moMonOpDiversification.h | 38 +-- .../src/memory/moNeighborVectorTabuList.h | 8 +- .../src/memory/moSolVectorTabuList.h | 8 +- .../moBackwardVariableNeighborhood.h | 8 +- .../src/neighborhood/moDummyNeighbor.h | 4 +- .../src/neighborhood/moDummyNeighborhood.h | 14 +- .../moForwardVariableNeighborhood.h | 8 +- .../src/neighborhood/moIndexNeighbor.h | 4 +- .../src/neighborhood/moNeighbor.h | 4 +- .../src/neighborhood/moRndNeighborhood.h | 6 +- .../neighborhood/moRndVariableNeighborhood.h | 20 +- .../src/neighborhood/moVariableNeighborhood.h | 18 +- .../src/perturb/moLocalSearchInit.h | 40 +-- .../paradiseo-mo/src/perturb/moMonOpPerturb.h | 40 +-- .../src/perturb/moNeighborhoodPerturb.h | 72 ++--- .../src/perturb/moRestartPerturb.h | 48 +-- trunk/paradiseo-mo/src/perturb/moSolInit.h | 28 +- .../src/problems/eval/moMaxSATincrEval.h | 140 ++++----- .../src/problems/eval/moOneMaxIncrEval.h | 8 +- .../src/problems/eval/moRoyalRoadIncrEval.h | 72 ++--- .../src/problems/eval/oneMaxFullEval.h | 8 +- .../problems/permutation/moShiftNeighbor.h | 128 ++++---- .../src/problems/permutation/moSwapNeighbor.h | 76 ++--- .../problems/permutation/moSwapNeighborhood.h | 36 +-- .../src/sampling/moAutocorrelationSampling.h | 54 ++-- .../src/sampling/moDensityOfStatesSampling.h | 46 +-- .../paradiseo-mo/src/sampling/moFDCsampling.h | 62 ++-- .../src/sampling/moFitnessCloudSampling.h | 72 ++--- .../src/sampling/moHillClimberSampling.h | 84 ++--- .../sampling/moMHBestFitnessCloudSampling.h | 86 +++--- .../sampling/moMHRndFitnessCloudSampling.h | 86 +++--- .../src/sampling/moNeutralDegreeSampling.h | 118 +++---- .../src/sampling/moNeutralWalkSampling.h | 126 ++++---- .../sampling/moRndBestFitnessCloudSampling.h | 86 +++--- .../sampling/moRndRndFitnessCloudSampling.h | 86 +++--- trunk/paradiseo-mo/src/sampling/moSampling.h | 264 ++++++++-------- .../paradiseo-mo/src/sampling/moStatistics.h | 288 ++++++++--------- 88 files changed, 2655 insertions(+), 2649 deletions(-) diff --git a/trunk/paradiseo-mo/src/acceptCrit/moAcceptanceCriterion.h b/trunk/paradiseo-mo/src/acceptCrit/moAcceptanceCriterion.h index 15d7ae7f5..266b30f45 100644 --- a/trunk/paradiseo-mo/src/acceptCrit/moAcceptanceCriterion.h +++ b/trunk/paradiseo-mo/src/acceptCrit/moAcceptanceCriterion.h @@ -37,7 +37,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr * Abstract class for Acceptance criteria */ template< class Neighbor > -class moAcceptanceCriterion : public eoBF, virtual public moMemory{ +class moAcceptanceCriterion : public eoBF, virtual public moMemory { }; diff --git a/trunk/paradiseo-mo/src/acceptCrit/moAlwaysAcceptCrit.h b/trunk/paradiseo-mo/src/acceptCrit/moAlwaysAcceptCrit.h index ce22dd186..777ef0b18 100644 --- a/trunk/paradiseo-mo/src/acceptCrit/moAlwaysAcceptCrit.h +++ b/trunk/paradiseo-mo/src/acceptCrit/moAlwaysAcceptCrit.h @@ -37,20 +37,20 @@ Contact: paradiseo-help@lists.gforge.inria.fr * Acceptance Criterion for extreme diversification : always accept new solution */ template< class Neighbor > -class moAlwaysAcceptCrit : public moAcceptanceCriterion, public moDummyMemory{ +class moAlwaysAcceptCrit : public moAcceptanceCriterion, public moDummyMemory { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; - /** - * Always accept the new solution - * @param _sol1 the previous solution - * @param _sol2 the new solution after local search - * @return always true - */ - bool operator()(EOT& _sol1, EOT& _sol2){ - return true; - } + /** + * Always accept the new solution + * @param _sol1 the previous solution + * @param _sol2 the new solution after local search + * @return always true + */ + bool operator()(EOT& _sol1, EOT& _sol2) { + return true; + } }; diff --git a/trunk/paradiseo-mo/src/acceptCrit/moBetterAcceptCrit.h b/trunk/paradiseo-mo/src/acceptCrit/moBetterAcceptCrit.h index 6248c03e8..a9a79d511 100644 --- a/trunk/paradiseo-mo/src/acceptCrit/moBetterAcceptCrit.h +++ b/trunk/paradiseo-mo/src/acceptCrit/moBetterAcceptCrit.h @@ -38,25 +38,25 @@ Contact: paradiseo-help@lists.gforge.inria.fr * Acceptance Criterion for extreme intensification : accept if the new solution is better than previous one */ template< class Neighbor > -class moBetterAcceptCrit : public moAcceptanceCriterion, public moDummyMemory{ +class moBetterAcceptCrit : public moAcceptanceCriterion, public moDummyMemory { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; - moBetterAcceptCrit(moSolComparator& _comparator):comparator(_comparator){} + moBetterAcceptCrit(moSolComparator& _comparator):comparator(_comparator) {} - /** - * Accept if the new solution is better than previous one - * @param _sol1 the previous solution - * @param _sol2 the new solution after local search - * @return true if the new solution is better than previous one - */ - bool operator()(EOT& _sol1, EOT& _sol2){ - return comparator(_sol1, _sol2); - } + /** + * Accept if the new solution is better than previous one + * @param _sol1 the previous solution + * @param _sol2 the new solution after local search + * @return true if the new solution is better than previous one + */ + bool operator()(EOT& _sol1, EOT& _sol2) { + return comparator(_sol1, _sol2); + } private: - moSolComparator& comparator; + moSolComparator& comparator; }; diff --git a/trunk/paradiseo-mo/src/algo/moDummyLS.h b/trunk/paradiseo-mo/src/algo/moDummyLS.h index 4d45f79f2..259b8eada 100644 --- a/trunk/paradiseo-mo/src/algo/moDummyLS.h +++ b/trunk/paradiseo-mo/src/algo/moDummyLS.h @@ -36,36 +36,36 @@ Contact: paradiseo-help@lists.gforge.inria.fr /** * Dummy Local Search: - * + * * To do nothing, only the full evaluation of the solution if necessary ;-) */ template class moDummyLS: public moLocalSearch { public: - typedef typename Neighbor::EOT EOT; - typedef moNeighborhood Neighborhood ; + typedef typename Neighbor::EOT EOT; + typedef moNeighborhood Neighborhood ; + + /** + * Simple constructor + * @param _fullEval the full evaluation function + */ + moDummyLS(eoEvalFunc& _fullEval): + moLocalSearch(explorer, trueCont, _fullEval) + {} + + /** + * @return name of the class + */ + virtual std::string className(void) const { + return "moDummyLS"; + } - /** - * Simple constructor - * @param _fullEval the full evaluation function - */ - moDummyLS(eoEvalFunc& _fullEval): - moLocalSearch(explorer, trueCont, _fullEval) - {} - - /** - * @return name of the class - */ - virtual std::string className(void) const { - return "moDummyLS"; - } - private: - // always true continuator - moTrueContinuator trueCont; - // the explorer of the simple HC - moDummyExplorer explorer; + // always true continuator + moTrueContinuator trueCont; + // the explorer of the simple HC + moDummyExplorer explorer; }; #endif diff --git a/trunk/paradiseo-mo/src/algo/moFirstImprHC.h b/trunk/paradiseo-mo/src/algo/moFirstImprHC.h index d41a82ebb..28f141bfd 100644 --- a/trunk/paradiseo-mo/src/algo/moFirstImprHC.h +++ b/trunk/paradiseo-mo/src/algo/moFirstImprHC.h @@ -39,7 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr /** * First improvement HC: * Hill-Climber local search - * + * * At each iteration, * one of the random solution in the neighborhood is selected * if the selected neighbor have higher fitness than the current solution @@ -50,55 +50,55 @@ template class moFirstImprHC: public moLocalSearch { public: - typedef typename Neighbor::EOT EOT; - typedef moNeighborhood Neighborhood ; + typedef typename Neighbor::EOT EOT; + typedef moNeighborhood Neighborhood ; + + /** + * Basic constructor for a hill-climber + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + */ + moFirstImprHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval): + moLocalSearch(explorer, trueCont, _fullEval), + explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp) + {} + + /** + * Simple constructor for a hill-climber + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _cont an external continuator + */ + moFirstImprHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, moContinuator& _cont): + moLocalSearch(explorer, _cont, _fullEval), + explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp) + {} + + /** + * General constructor for a hill-climber + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _cont an external continuator + * @param _compN a neighbor vs neighbor comparator + * @param _compSN a solution vs neighbor comparator + */ + moFirstImprHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, moContinuator& _cont, moNeighborComparator& _compN, moSolNeighborComparator& _compSN): + moLocalSearch(explorer, _cont, _fullEval), + explorer(_neighborhood, _eval, _compN, _compSN) + {} - /** - * Basic constructor for a hill-climber - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - */ - moFirstImprHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval): - moLocalSearch(explorer, trueCont, _fullEval), - explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp) - {} - - /** - * Simple constructor for a hill-climber - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _cont an external continuator - */ - moFirstImprHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, moContinuator& _cont): - moLocalSearch(explorer, _cont, _fullEval), - explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp) - {} - - /** - * General constructor for a hill-climber - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _cont an external continuator - * @param _compN a neighbor vs neighbor comparator - * @param _compSN a solution vs neighbor comparator - */ - moFirstImprHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, moContinuator& _cont, moNeighborComparator& _compN, moSolNeighborComparator& _compSN): - moLocalSearch(explorer, _cont, _fullEval), - explorer(_neighborhood, _eval, _compN, _compSN) - {} - private: - // always true continuator - moTrueContinuator trueCont; - // compare the fitness values of neighbors: true is strictly greater - moNeighborComparator defaultNeighborComp; - // compare the fitness values of the solution and the neighbor: true if strictly greater - moSolNeighborComparator defaultSolNeighborComp; - // the explorer of the first improvement HC - moFirstImprHCexplorer explorer; + // always true continuator + moTrueContinuator trueCont; + // compare the fitness values of neighbors: true is strictly greater + moNeighborComparator defaultNeighborComp; + // compare the fitness values of the solution and the neighbor: true if strictly greater + moSolNeighborComparator defaultSolNeighborComp; + // the explorer of the first improvement HC + moFirstImprHCexplorer explorer; }; #endif diff --git a/trunk/paradiseo-mo/src/algo/moILS.h b/trunk/paradiseo-mo/src/algo/moILS.h index 9da7e4123..5c7c48f5c 100644 --- a/trunk/paradiseo-mo/src/algo/moILS.h +++ b/trunk/paradiseo-mo/src/algo/moILS.h @@ -49,7 +49,7 @@ class moILS: public moLocalSearch > { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; typedef moNeighborhood Neighborhood ; /** @@ -59,12 +59,12 @@ public: * @param _op the operator used to perturb solution * @param _nbIteration the time limit for search */ - moILS(moLocalSearch& _ls, eoEvalFunc& _fullEval, eoMonOp& _op, unsigned int _nbIteration): - moLocalSearch >(explorer, iterCont, _fullEval), - iterCont(_nbIteration), - defaultPerturb(_op, _fullEval), - explorer(_ls, defaultPerturb, defaultAccept) - {} + moILS(moLocalSearch& _ls, eoEvalFunc& _fullEval, eoMonOp& _op, unsigned int _nbIteration): + moLocalSearch >(explorer, iterCont, _fullEval), + iterCont(_nbIteration), + defaultPerturb(_op, _fullEval), + explorer(_ls, defaultPerturb, defaultAccept) + {} /** * Simple constructor for Iterated Local Search @@ -73,12 +73,12 @@ public: * @param _op the operator used to perturb solution * @param _cont a continuator */ - moILS(moLocalSearch& _ls, eoEvalFunc& _fullEval, eoMonOp& _op, moContinuator >& _cont): - moLocalSearch >(explorer, _cont, _fullEval), - iterCont(0), - defaultPerturb(_op, _fullEval), - explorer(_ls, defaultPerturb, defaultAccept) - {} + moILS(moLocalSearch& _ls, eoEvalFunc& _fullEval, eoMonOp& _op, moContinuator >& _cont): + moLocalSearch >(explorer, _cont, _fullEval), + iterCont(0), + defaultPerturb(_op, _fullEval), + explorer(_ls, defaultPerturb, defaultAccept) + {} /** * General constructor for Iterated Local Search @@ -88,23 +88,25 @@ public: * @param _perturb a perturbation operator * @param _accept a acceptance criteria */ - moILS(moLocalSearch& _ls, eoEvalFunc& _fullEval, moContinuator >& _cont, moMonOpPerturb& _perturb, moAcceptanceCriterion& _accept): - moLocalSearch >(explorer, _cont, _fullEval), - iterCont(0), - defaultPerturb(dummyOp, _fullEval), - explorer(_ls, _perturb, _accept) - {} + moILS(moLocalSearch& _ls, eoEvalFunc& _fullEval, moContinuator >& _cont, moMonOpPerturb& _perturb, moAcceptanceCriterion& _accept): + moLocalSearch >(explorer, _cont, _fullEval), + iterCont(0), + defaultPerturb(dummyOp, _fullEval), + explorer(_ls, _perturb, _accept) + {} private: - class dummmyMonOp: public eoMonOp{ - public: - bool operator()(EOT&){return false;} - }dummyOp; - moIterContinuator > iterCont; - moMonOpPerturb defaultPerturb; - moAlwaysAcceptCrit defaultAccept; - moILSexplorer explorer; + class dummmyMonOp: public eoMonOp { + public: + bool operator()(EOT&) { + return false; + } + }dummyOp; + moIterContinuator > iterCont; + moMonOpPerturb defaultPerturb; + moAlwaysAcceptCrit defaultAccept; + moILSexplorer explorer; }; diff --git a/trunk/paradiseo-mo/src/algo/moLocalSearch.h b/trunk/paradiseo-mo/src/algo/moLocalSearch.h index 16c7199d2..518da7609 100644 --- a/trunk/paradiseo-mo/src/algo/moLocalSearch.h +++ b/trunk/paradiseo-mo/src/algo/moLocalSearch.h @@ -48,9 +48,9 @@ template class moLocalSearch: public eoMonOp { public: - typedef moNeighborhood Neighborhood; - typedef moNeighborhoodExplorer NeighborhoodExplorer; - typedef typename Neighbor::EOT EOT ; + typedef moNeighborhood Neighborhood; + typedef moNeighborhoodExplorer NeighborhoodExplorer; + typedef typename Neighbor::EOT EOT ; /** * Constructor of a moLocalSearch @@ -101,23 +101,23 @@ public: return true; }; - /** + /** * Set an external continuator * @param _cont the external continuator */ - void setContinuator(moContinuator & _cont) { - cont = &_cont ; - } + void setContinuator(moContinuator & _cont) { + cont = &_cont ; + } - /** + /** * external continuator object - * + * * @overload - * @return the external continuator + * @return the external continuator */ - moContinuator* getContinuator() const { - return cont ; - } + moContinuator* getContinuator() const { + return cont ; + } protected: // make the exploration of the neighborhood according to a local search heuristic diff --git a/trunk/paradiseo-mo/src/algo/moMetropolisHasting.h b/trunk/paradiseo-mo/src/algo/moMetropolisHasting.h index 94278627f..99426c24b 100644 --- a/trunk/paradiseo-mo/src/algo/moMetropolisHasting.h +++ b/trunk/paradiseo-mo/src/algo/moMetropolisHasting.h @@ -40,7 +40,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr * Metropolis-Hasting local search * Only the symetric case is considered when Q(x,y) = Q(y,x) * Fitness must be > 0 - * + * * At each iteration, * one of the random solution in the neighborhood is selected * if the selected neighbor have higher or equal fitness than the current solution @@ -53,58 +53,58 @@ template class moMetropolisHasting: public moLocalSearch { public: - typedef typename Neighbor::EOT EOT; - typedef moNeighborhood Neighborhood ; + typedef typename Neighbor::EOT EOT; + typedef moNeighborhood Neighborhood ; + + /** + * Basic constructor of the Metropolis-Hasting + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _nbStep maximum step to do + */ + moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep): + moLocalSearch(explorer, trueCont, _fullEval), + explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep) + {} + + /** + * Simple constructor of the Metropolis-Hasting + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _nbStep maximum step to do + * @param _cont an external continuator + */ + moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep, moContinuator& _cont): + moLocalSearch(explorer, _cont, _fullEval), + explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep) + {} + + /** + * General constructor of the Metropolis-Hasting + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _nbStep maximum step to do + * @param _cont an external continuator + * @param _compN a neighbor vs neighbor comparator + * @param _compSN a solution vs neighbor comparator + */ + moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep, moContinuator& _cont, moNeighborComparator& _compN, moSolNeighborComparator& _compSN): + moLocalSearch(explorer, _cont, _fullEval), + explorer(_neighborhood, _eval, _compN, _compSN, _nbStep) + {} - /** - * Basic constructor of the Metropolis-Hasting - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _nbStep maximum step to do - */ - moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep): - moLocalSearch(explorer, trueCont, _fullEval), - explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep) - {} - - /** - * Simple constructor of the Metropolis-Hasting - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _nbStep maximum step to do - * @param _cont an external continuator - */ - moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep, moContinuator& _cont): - moLocalSearch(explorer, _cont, _fullEval), - explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep) - {} - - /** - * General constructor of the Metropolis-Hasting - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _nbStep maximum step to do - * @param _cont an external continuator - * @param _compN a neighbor vs neighbor comparator - * @param _compSN a solution vs neighbor comparator - */ - moMetropolisHasting(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep, moContinuator& _cont, moNeighborComparator& _compN, moSolNeighborComparator& _compSN): - moLocalSearch(explorer, _cont, _fullEval), - explorer(_neighborhood, _eval, _compN, _compSN, _nbStep) - {} - private: - // always true continuator - moTrueContinuator trueCont; - // compare the fitness values of neighbors: true is strictly greater - moNeighborComparator defaultNeighborComp; - // compare the fitness values of the solution and the neighbor: true if strictly greater - moSolNeighborComparator defaultSolNeighborComp; - // the explorer of the HC with neutral move (equals fitness move) - moMetropolisHastingExplorer explorer; + // always true continuator + moTrueContinuator trueCont; + // compare the fitness values of neighbors: true is strictly greater + moNeighborComparator defaultNeighborComp; + // compare the fitness values of the solution and the neighbor: true if strictly greater + moSolNeighborComparator defaultSolNeighborComp; + // the explorer of the HC with neutral move (equals fitness move) + moMetropolisHastingExplorer explorer; }; #endif diff --git a/trunk/paradiseo-mo/src/algo/moNeutralHC.h b/trunk/paradiseo-mo/src/algo/moNeutralHC.h index 24673e5aa..881980a66 100644 --- a/trunk/paradiseo-mo/src/algo/moNeutralHC.h +++ b/trunk/paradiseo-mo/src/algo/moNeutralHC.h @@ -49,58 +49,58 @@ template class moNeutralHC: public moLocalSearch { public: - typedef typename Neighbor::EOT EOT; - typedef moNeighborhood Neighborhood ; + typedef typename Neighbor::EOT EOT; + typedef moNeighborhood Neighborhood ; + + /** + * Basic constructor for a hill-climber + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _nbStep maximum step to do + */ + moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep): + moLocalSearch(explorer, trueCont, _fullEval), + explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep) + {} + + /** + * Simple constructor for a hill-climber + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _nbStep maximum step to do + * @param _cont an external continuator + */ + moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep, moContinuator& _cont): + moLocalSearch(explorer, _cont, _fullEval), + explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep) + {} + + /** + * General constructor for a hill-climber + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _nbStep maximum step to do + * @param _cont an external continuator + * @param _compN a neighbor vs neighbor comparator + * @param _compSN a solution vs neighbor comparator + */ + moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep, moContinuator& _cont, moNeighborComparator& _compN, moSolNeighborComparator& _compSN): + moLocalSearch(explorer, _cont, _fullEval), + explorer(_neighborhood, _eval, _compN, _compSN, _nbStep) + {} - /** - * Basic constructor for a hill-climber - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _nbStep maximum step to do - */ - moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep): - moLocalSearch(explorer, trueCont, _fullEval), - explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep) - {} - - /** - * Simple constructor for a hill-climber - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _nbStep maximum step to do - * @param _cont an external continuator - */ - moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep, moContinuator& _cont): - moLocalSearch(explorer, _cont, _fullEval), - explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _nbStep) - {} - - /** - * General constructor for a hill-climber - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _nbStep maximum step to do - * @param _cont an external continuator - * @param _compN a neighbor vs neighbor comparator - * @param _compSN a solution vs neighbor comparator - */ - moNeutralHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned int _nbStep, moContinuator& _cont, moNeighborComparator& _compN, moSolNeighborComparator& _compSN): - moLocalSearch(explorer, _cont, _fullEval), - explorer(_neighborhood, _eval, _compN, _compSN, _nbStep) - {} - private: - // always true continuator - moTrueContinuator trueCont; - // compare the fitness values of neighbors: true is strictly greater - moNeighborComparator defaultNeighborComp; - // compare the fitness values of the solution and the neighbor: true if strictly greater - moSolNeighborComparator defaultSolNeighborComp; - // the explorer of the HC with neutral move (equals fitness move) - moNeutralHCexplorer explorer; + // always true continuator + moTrueContinuator trueCont; + // compare the fitness values of neighbors: true is strictly greater + moNeighborComparator defaultNeighborComp; + // compare the fitness values of the solution and the neighbor: true if strictly greater + moSolNeighborComparator defaultSolNeighborComp; + // the explorer of the HC with neutral move (equals fitness move) + moNeutralHCexplorer explorer; }; #endif diff --git a/trunk/paradiseo-mo/src/algo/moRandomBestHC.h b/trunk/paradiseo-mo/src/algo/moRandomBestHC.h index 3ed82c985..0e3f8bbbf 100644 --- a/trunk/paradiseo-mo/src/algo/moRandomBestHC.h +++ b/trunk/paradiseo-mo/src/algo/moRandomBestHC.h @@ -39,7 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr /** * Random Best HC: * Hill-Climber local search - * + * * At each iteration, * one of the random best solution in the neighborhood is selected * if the selected neighbor have higher fitness than the current solution @@ -50,55 +50,55 @@ template class moRandomBestHC: public moLocalSearch { public: - typedef typename Neighbor::EOT EOT; - typedef moNeighborhood Neighborhood ; + typedef typename Neighbor::EOT EOT; + typedef moNeighborhood Neighborhood ; + + /** + * Basic constructor for a hill-climber + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + */ + moRandomBestHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval): + moLocalSearch(explorer, trueCont, _fullEval), + explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp) + {} + + /** + * Simple constructor for a hill-climber + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _cont an external continuator + */ + moRandomBestHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, moContinuator& _cont): + moLocalSearch(explorer, _cont, _fullEval), + explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp) + {} + + /** + * General constructor for a hill-climber + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _cont an external continuator + * @param _compN a neighbor vs neighbor comparator + * @param _compSN a solution vs neighbor comparator + */ + moRandomBestHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, moContinuator& _cont, moNeighborComparator& _compN, moSolNeighborComparator& _compSN): + moLocalSearch(explorer, _cont, _fullEval), + explorer(_neighborhood, _eval, _compN, _compSN) + {} - /** - * Basic constructor for a hill-climber - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - */ - moRandomBestHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval): - moLocalSearch(explorer, trueCont, _fullEval), - explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp) - {} - - /** - * Simple constructor for a hill-climber - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _cont an external continuator - */ - moRandomBestHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, moContinuator& _cont): - moLocalSearch(explorer, _cont, _fullEval), - explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp) - {} - - /** - * General constructor for a hill-climber - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _cont an external continuator - * @param _compN a neighbor vs neighbor comparator - * @param _compSN a solution vs neighbor comparator - */ - moRandomBestHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, moContinuator& _cont, moNeighborComparator& _compN, moSolNeighborComparator& _compSN): - moLocalSearch(explorer, _cont, _fullEval), - explorer(_neighborhood, _eval, _compN, _compSN) - {} - private: - // always true continuator - moTrueContinuator trueCont; - // compare the fitness values of neighbors: true is strictly greater - moNeighborComparator defaultNeighborComp; - // compare the fitness values of the solution and the neighbor: true if strictly greater - moSolNeighborComparator defaultSolNeighborComp; - // the explorer of the HC with random choice of the best solution - moRandomBestHCexplorer explorer; + // always true continuator + moTrueContinuator trueCont; + // compare the fitness values of neighbors: true is strictly greater + moNeighborComparator defaultNeighborComp; + // compare the fitness values of the solution and the neighbor: true if strictly greater + moSolNeighborComparator defaultSolNeighborComp; + // the explorer of the HC with random choice of the best solution + moRandomBestHCexplorer explorer; }; #endif diff --git a/trunk/paradiseo-mo/src/algo/moRandomNeutralWalk.h b/trunk/paradiseo-mo/src/algo/moRandomNeutralWalk.h index bb3eae6eb..2071f93a8 100644 --- a/trunk/paradiseo-mo/src/algo/moRandomNeutralWalk.h +++ b/trunk/paradiseo-mo/src/algo/moRandomNeutralWalk.h @@ -39,7 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr /** * Random Neutral Walk: * Random Neutral walk local search - * + * * At each iteration, * one random neighbor with the same fitness is selected and replace the current solution * the algorithm stops when the number of steps is reached @@ -48,55 +48,55 @@ template class moRandomNeutralWalk: public moLocalSearch { public: - typedef typename Neighbor::EOT EOT; - typedef moNeighborhood Neighborhood ; + typedef typename Neighbor::EOT EOT; + typedef moNeighborhood Neighborhood ; + + /** + * Basic constructor for a random walk + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _nbStepMax number of step of the walk + */ + moRandomNeutralWalk(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned _nbStepMax): + moLocalSearch(explorer, trueCont, _fullEval), + explorer(_neighborhood, _eval, defaultSolNeighborComp, _nbStepMax) + {} + + /** + * Simple constructor for a random walk + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _nbStepMax number of step of the walk + * @param _cont an external continuator + */ + moRandomNeutralWalk(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned _nbStepMax, moContinuator& _cont): + moLocalSearch(explorer, _cont, _fullEval), + explorer(_neighborhood, _eval, defaultSolNeighborComp, _nbStepMax) + {} + + /** + * General constructor for a random walk + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _nbStepMax number of step of the walk + * @param _cont an external continuator + * @param _comp a solution vs neighbor comparator + */ + moRandomNeutralWalk(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned _nbStepMax, moContinuator& _cont, moSolNeighborComparator& _comp): + moLocalSearch(explorer, _cont, _fullEval), + explorer(_neighborhood, _eval, _comp, _nbStepMax) + {} - /** - * Basic constructor for a random walk - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _nbStepMax number of step of the walk - */ - moRandomNeutralWalk(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned _nbStepMax): - moLocalSearch(explorer, trueCont, _fullEval), - explorer(_neighborhood, _eval, defaultSolNeighborComp, _nbStepMax) - {} - - /** - * Simple constructor for a random walk - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _nbStepMax number of step of the walk - * @param _cont an external continuator - */ - moRandomNeutralWalk(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned _nbStepMax, moContinuator& _cont): - moLocalSearch(explorer, _cont, _fullEval), - explorer(_neighborhood, _eval, defaultSolNeighborComp, _nbStepMax) - {} - - /** - * General constructor for a random walk - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _nbStepMax number of step of the walk - * @param _cont an external continuator - * @param _comp a solution vs neighbor comparator - */ - moRandomNeutralWalk(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned _nbStepMax, moContinuator& _cont, moSolNeighborComparator& _comp): - moLocalSearch(explorer, _cont, _fullEval), - explorer(_neighborhood, _eval, _comp, _nbStepMax) - {} - private: - // always true continuator - moTrueContinuator trueCont; - // the explorer of the random walk - moRandomNeutralWalkExplorer explorer; - // compare the fitness values of the solution and the neighbor: true if strictly greater - moSolNeighborComparator defaultSolNeighborComp; + // always true continuator + moTrueContinuator trueCont; + // the explorer of the random walk + moRandomNeutralWalkExplorer explorer; + // compare the fitness values of the solution and the neighbor: true if strictly greater + moSolNeighborComparator defaultSolNeighborComp; }; #endif diff --git a/trunk/paradiseo-mo/src/algo/moRandomSearch.h b/trunk/paradiseo-mo/src/algo/moRandomSearch.h index 849797751..c0a468d6a 100644 --- a/trunk/paradiseo-mo/src/algo/moRandomSearch.h +++ b/trunk/paradiseo-mo/src/algo/moRandomSearch.h @@ -39,7 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr /** * Random Search: * Pure random search local search - * + * * At each iteration, * one random solution is selected and replace the current solution * the algorithm stops when the number of solution is reached @@ -48,43 +48,43 @@ template class moRandomSearch: public moLocalSearch { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; + + /** + * Simple constructor for a random search + * @param _init the solution initializer, to explore at random the search space + * @param _fullEval the full evaluation function + * @param _nbSolMax number of solutions + */ + moRandomSearch(eoInit & _init, eoEvalFunc& _fullEval, unsigned _nbSolMax): + moLocalSearch(explorer, trueCont, _fullEval), + explorer(_init, _fullEval, _nbSolMax>0?_nbSolMax - 1:0) + {} + + /** + * General constructor for a random search + * @param _init the solution initializer, to explore at random the search space + * @param _fullEval the full evaluation function + * @param _nbSolMax number of solutions + * @param _cont external continuator + */ + moRandomSearch(eoInit & _init, eoEvalFunc& _fullEval, unsigned _nbSolMax, moContinuator& _cont): + moLocalSearch(explorer, _cont, _fullEval), + explorer(_init, _fullEval, _nbSolMax>0?_nbSolMax - 1:0) + {} + + /** + * @return name of the class + */ + virtual std::string className(void) const { + return "moRandomSearch"; + } - /** - * Simple constructor for a random search - * @param _init the solution initializer, to explore at random the search space - * @param _fullEval the full evaluation function - * @param _nbSolMax number of solutions - */ - moRandomSearch(eoInit & _init, eoEvalFunc& _fullEval, unsigned _nbSolMax): - moLocalSearch(explorer, trueCont, _fullEval), - explorer(_init, _fullEval, _nbSolMax>0?_nbSolMax - 1:0) - {} - - /** - * General constructor for a random search - * @param _init the solution initializer, to explore at random the search space - * @param _fullEval the full evaluation function - * @param _nbSolMax number of solutions - * @param _cont external continuator - */ - moRandomSearch(eoInit & _init, eoEvalFunc& _fullEval, unsigned _nbSolMax, moContinuator& _cont): - moLocalSearch(explorer, _cont, _fullEval), - explorer(_init, _fullEval, _nbSolMax>0?_nbSolMax - 1:0) - {} - - /** - * @return name of the class - */ - virtual std::string className(void) const { - return "moRandomSearch"; - } - private: - // always true continuator - moTrueContinuator trueCont; - // the explorer of the random walk - moRandomSearchExplorer explorer; + // always true continuator + moTrueContinuator trueCont; + // the explorer of the random walk + moRandomSearchExplorer explorer; }; #endif diff --git a/trunk/paradiseo-mo/src/algo/moRandomWalk.h b/trunk/paradiseo-mo/src/algo/moRandomWalk.h index ade72ac02..cbf7dcb2b 100644 --- a/trunk/paradiseo-mo/src/algo/moRandomWalk.h +++ b/trunk/paradiseo-mo/src/algo/moRandomWalk.h @@ -39,7 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr /** * Random Walk: * Random walk local search - * + * * At each iteration, * one random neighbor is selected and replace the current solution * the algorithm stops when the number of steps is reached @@ -48,39 +48,39 @@ template class moRandomWalk: public moLocalSearch { public: - typedef typename Neighbor::EOT EOT; - typedef moNeighborhood Neighborhood ; + typedef typename Neighbor::EOT EOT; + typedef moNeighborhood Neighborhood ; + + /** + * Simple constructor for a random walk + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _nbStepMax number of step of the walk + */ + moRandomWalk(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned _nbStepMax): + moLocalSearch(explorer, trueCont, _fullEval), + explorer(_neighborhood, _eval, _nbStepMax) + {} + + /** + * General constructor for a random walk + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _nbStepMax number of step of the walk + * @param _cont an external continuator + */ + moRandomWalk(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned _nbStepMax, moContinuator& _cont): + moLocalSearch(explorer, _cont, _fullEval), + explorer(_neighborhood, _eval, _nbStepMax) + {} - /** - * Simple constructor for a random walk - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _nbStepMax number of step of the walk - */ - moRandomWalk(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned _nbStepMax): - moLocalSearch(explorer, trueCont, _fullEval), - explorer(_neighborhood, _eval, _nbStepMax) - {} - - /** - * General constructor for a random walk - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _nbStepMax number of step of the walk - * @param _cont an external continuator - */ - moRandomWalk(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned _nbStepMax, moContinuator& _cont): - moLocalSearch(explorer, _cont, _fullEval), - explorer(_neighborhood, _eval, _nbStepMax) - {} - private: - // always true continuator - moTrueContinuator trueCont; - // the explorer of the random walk - moRandomWalkExplorer explorer; + // always true continuator + moTrueContinuator trueCont; + // the explorer of the random walk + moRandomWalkExplorer explorer; }; #endif diff --git a/trunk/paradiseo-mo/src/algo/moSA.h b/trunk/paradiseo-mo/src/algo/moSA.h index 9193361a4..893bf41c6 100644 --- a/trunk/paradiseo-mo/src/algo/moSA.h +++ b/trunk/paradiseo-mo/src/algo/moSA.h @@ -46,7 +46,7 @@ class moSA: public moLocalSearch { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; typedef moNeighborhood Neighborhood ; @@ -60,11 +60,11 @@ public: * @param _span number of iteration with equal temperature for cooling schedule (default = 100) * @param _finalT final temperature, threshold of the stopping criteria for cooling schedule (default = 0.01) */ - moSA(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, double _initT=10, double _alpha=0.9, unsigned _span=100, double _finalT=0.01): - moLocalSearch(explorer, trueCont, _fullEval), - defaultCool(_initT, _alpha, _span, _finalT), - explorer(_neighborhood, _eval, defaultSolNeighborComp, defaultCool) - {} + moSA(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, double _initT=10, double _alpha=0.9, unsigned _span=100, double _finalT=0.01): + moLocalSearch(explorer, trueCont, _fullEval), + defaultCool(_initT, _alpha, _span, _finalT), + explorer(_neighborhood, _eval, defaultSolNeighborComp, defaultCool) + {} /** * Simple constructor for a simulated annealing @@ -73,11 +73,11 @@ public: * @param _eval neighbor's evaluation function * @param _cool a cooling schedule */ - moSA(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, moCoolingSchedule& _cool): - moLocalSearch(explorer, trueCont, _fullEval), - defaultCool(0, 0, 0, 0), - explorer(_neighborhood, _eval, defaultSolNeighborComp, _cool) - {} + moSA(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, moCoolingSchedule& _cool): + moLocalSearch(explorer, trueCont, _fullEval), + defaultCool(0, 0, 0, 0), + explorer(_neighborhood, _eval, defaultSolNeighborComp, _cool) + {} /** * General constructor for a simulated annealing @@ -88,19 +88,19 @@ public: * @param _comp a solution vs neighbor comparator * @param _cont an external continuator */ - moSA(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, moCoolingSchedule& _cool, moSolNeighborComparator& _comp, moContinuator& _cont): - moLocalSearch(explorer, _cont, _fullEval), - defaultCool(0, 0, 0, 0), - explorer(_neighborhood, _eval, _comp, _cool) - {} + moSA(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, moCoolingSchedule& _cool, moSolNeighborComparator& _comp, moContinuator& _cont): + moLocalSearch(explorer, _cont, _fullEval), + defaultCool(0, 0, 0, 0), + explorer(_neighborhood, _eval, _comp, _cool) + {} private: - moTrueContinuator trueCont; - moSimpleCoolingSchedule defaultCool; - moSolNeighborComparator defaultSolNeighborComp; - moSAexplorer explorer; + moTrueContinuator trueCont; + moSimpleCoolingSchedule defaultCool; + moSolNeighborComparator defaultSolNeighborComp; + moSAexplorer explorer; }; #endif diff --git a/trunk/paradiseo-mo/src/algo/moSimpleHC.h b/trunk/paradiseo-mo/src/algo/moSimpleHC.h index 6eee394b1..a8c9c6093 100644 --- a/trunk/paradiseo-mo/src/algo/moSimpleHC.h +++ b/trunk/paradiseo-mo/src/algo/moSimpleHC.h @@ -39,7 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr /** * Simple HC: * Hill-Climber local search - * + * * At each iteration, * the first best solution in the neighborhood is selected * if the selected neighbor have higher fitness than the current solution @@ -50,55 +50,55 @@ template class moSimpleHC: public moLocalSearch { public: - typedef typename Neighbor::EOT EOT; - typedef moNeighborhood Neighborhood ; + typedef typename Neighbor::EOT EOT; + typedef moNeighborhood Neighborhood ; + + /** + * Simple constructor for a hill-climber + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + */ + moSimpleHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval): + moLocalSearch(explorer, trueCont, _fullEval), + explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp) + {} + + /** + * Simple constructor for a hill-climber + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _cont an external continuator + */ + moSimpleHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, moContinuator& _cont): + moLocalSearch(explorer, _cont, _fullEval), + explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp) + {} + + /** + * Simple constructor for a hill-climber + * @param _neighborhood the neighborhood + * @param _fullEval the full evaluation function + * @param _eval neighbor's evaluation function + * @param _cont an external continuator + * @param _compN a neighbor vs neighbor comparator + * @param _compSN a solution vs neighbor comparator + */ + moSimpleHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, moContinuator& _cont, moNeighborComparator& _compN, moSolNeighborComparator& _compSN): + moLocalSearch(explorer, _cont, _fullEval), + explorer(_neighborhood, _eval, _compN, _compSN) + {} - /** - * Simple constructor for a hill-climber - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - */ - moSimpleHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval): - moLocalSearch(explorer, trueCont, _fullEval), - explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp) - {} - - /** - * Simple constructor for a hill-climber - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _cont an external continuator - */ - moSimpleHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, moContinuator& _cont): - moLocalSearch(explorer, _cont, _fullEval), - explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp) - {} - - /** - * Simple constructor for a hill-climber - * @param _neighborhood the neighborhood - * @param _fullEval the full evaluation function - * @param _eval neighbor's evaluation function - * @param _cont an external continuator - * @param _compN a neighbor vs neighbor comparator - * @param _compSN a solution vs neighbor comparator - */ - moSimpleHC(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, moContinuator& _cont, moNeighborComparator& _compN, moSolNeighborComparator& _compSN): - moLocalSearch(explorer, _cont, _fullEval), - explorer(_neighborhood, _eval, _compN, _compSN) - {} - private: - // always true continuator - moTrueContinuator trueCont; - // compare the fitness values of neighbors: true is strictly greater - moNeighborComparator defaultNeighborComp; - // compare the fitness values of the solution and the neighbor: true if strictly greater - moSolNeighborComparator defaultSolNeighborComp; - // the explorer of the simple HC - moSimpleHCexplorer explorer; + // always true continuator + moTrueContinuator trueCont; + // compare the fitness values of neighbors: true is strictly greater + moNeighborComparator defaultNeighborComp; + // compare the fitness values of the solution and the neighbor: true if strictly greater + moSolNeighborComparator defaultSolNeighborComp; + // the explorer of the simple HC + moSimpleHCexplorer explorer; }; #endif diff --git a/trunk/paradiseo-mo/src/algo/moTS.h b/trunk/paradiseo-mo/src/algo/moTS.h index 389ae6b6f..fa64a0812 100644 --- a/trunk/paradiseo-mo/src/algo/moTS.h +++ b/trunk/paradiseo-mo/src/algo/moTS.h @@ -51,7 +51,7 @@ class moTS: public moLocalSearch { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; typedef moNeighborhood Neighborhood ; /** @@ -62,17 +62,17 @@ public: * @param _time the time limit for stopping criteria * @param _tabuListSize the size of the tabu list */ - moTS(Neighborhood& _neighborhood, - eoEvalFunc& _fullEval, - moEval& _eval, - unsigned int _time, - unsigned int _tabuListSize - ): - moLocalSearch(explorer, timeCont, _fullEval), - timeCont(_time), - tabuList(_tabuListSize,0), - explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, tabuList, dummyIntensification, dummyDiversification, defaultAspiration) - {} + moTS(Neighborhood& _neighborhood, + eoEvalFunc& _fullEval, + moEval& _eval, + unsigned int _time, + unsigned int _tabuListSize + ): + moLocalSearch(explorer, timeCont, _fullEval), + timeCont(_time), + tabuList(_tabuListSize,0), + explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, tabuList, dummyIntensification, dummyDiversification, defaultAspiration) + {} /** * Simple constructor for a tabu search @@ -82,16 +82,16 @@ public: * @param _time the time limit for stopping criteria * @param _tabuList the tabu list */ - moTS(Neighborhood& _neighborhood, - eoEvalFunc& _fullEval, - moEval& _eval, - unsigned int _time, - moTabuList& _tabuList): - moLocalSearch(explorer, timeCont, _fullEval), - timeCont(_time), - tabuList(0,0), - explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _tabuList, dummyIntensification, dummyDiversification, defaultAspiration) - {} + moTS(Neighborhood& _neighborhood, + eoEvalFunc& _fullEval, + moEval& _eval, + unsigned int _time, + moTabuList& _tabuList): + moLocalSearch(explorer, timeCont, _fullEval), + timeCont(_time), + tabuList(0,0), + explorer(_neighborhood, _eval, defaultNeighborComp, defaultSolNeighborComp, _tabuList, dummyIntensification, dummyDiversification, defaultAspiration) + {} /** * General constructor for a tabu search @@ -106,31 +106,31 @@ public: * @param _diversification the diversification strategy * @param _aspiration the aspiration Criteria */ - moTS(Neighborhood& _neighborhood, - eoEvalFunc& _fullEval, - moEval& _eval, - moNeighborComparator& _neighborComp, - moSolNeighborComparator& _solNeighborComp, - moContinuator& _cont, - moTabuList& _tabuList, - moIntensification& _intensification, - moDiversification& _diversification, - moAspiration& _aspiration): - moLocalSearch(explorer, _cont, _fullEval), - timeCont(0), - tabuList(0,0), - explorer(_neighborhood, _eval, _neighborComp, _solNeighborComp, _tabuList, _intensification, _diversification, _aspiration) - {} + moTS(Neighborhood& _neighborhood, + eoEvalFunc& _fullEval, + moEval& _eval, + moNeighborComparator& _neighborComp, + moSolNeighborComparator& _solNeighborComp, + moContinuator& _cont, + moTabuList& _tabuList, + moIntensification& _intensification, + moDiversification& _diversification, + moAspiration& _aspiration): + moLocalSearch(explorer, _cont, _fullEval), + timeCont(0), + tabuList(0,0), + explorer(_neighborhood, _eval, _neighborComp, _solNeighborComp, _tabuList, _intensification, _diversification, _aspiration) + {} private: - moTimeContinuator timeCont; - moNeighborComparator defaultNeighborComp; - moSolNeighborComparator defaultSolNeighborComp; - moNeighborVectorTabuList tabuList; - moDummyIntensification dummyIntensification; - moDummyDiversification dummyDiversification; - moBestImprAspiration defaultAspiration; - moTSexplorer explorer; + moTimeContinuator timeCont; + moNeighborComparator defaultNeighborComp; + moSolNeighborComparator defaultSolNeighborComp; + moNeighborVectorTabuList tabuList; + moDummyIntensification dummyIntensification; + moDummyDiversification dummyDiversification; + moBestImprAspiration defaultAspiration; + moTSexplorer explorer; }; #endif diff --git a/trunk/paradiseo-mo/src/comparator/moComparator.h b/trunk/paradiseo-mo/src/comparator/moComparator.h index 09cd9aeba..153e39422 100644 --- a/trunk/paradiseo-mo/src/comparator/moComparator.h +++ b/trunk/paradiseo-mo/src/comparator/moComparator.h @@ -47,11 +47,11 @@ class moComparator : public eoBF { public: - /** - * @param _ref1 a reference on a variable of type T1 - * @param _ref2 a reference on a variable of type T2 - * @return true if _ref1 and _ref2 are equals - */ + /** + * @param _ref1 a reference on a variable of type T1 + * @param _ref2 a reference on a variable of type T2 + * @return true if _ref1 and _ref2 are equals + */ virtual bool equals(const T1& _ref1, const T2& _ref2) = 0; }; diff --git a/trunk/paradiseo-mo/src/continuator/moBestSoFarStat.h b/trunk/paradiseo-mo/src/continuator/moBestSoFarStat.h index 06d835ed1..b5eaab882 100644 --- a/trunk/paradiseo-mo/src/continuator/moBestSoFarStat.h +++ b/trunk/paradiseo-mo/src/continuator/moBestSoFarStat.h @@ -38,44 +38,44 @@ #include /** - * The statistic which save the best solution found during the search + * The statistic which save the best solution found during the search */ template class moBestSoFarStat : public moStat { public : - using moStat< EOT , EOT& >::value; - - /** - * Default Constructor - */ - moBestSoFarStat(): moStat(EOT(), "best") { - } - - /** - * Initialization of the best solution on the first one - * @param _sol the first solution - */ - virtual void init(EOT & _sol) { - value() = _sol; - } - - /** - * Update the best solution - * @param _sol the current solution - */ - virtual void operator()(EOT & _sol) { - if (value().fitness() < _sol.fitness()) - value() = _sol; - } - - /** - * @return name of the class - */ - virtual std::string className(void) const { - return "moBestSoFarStat"; - } - + using moStat< EOT , EOT& >::value; + + /** + * Default Constructor + */ + moBestSoFarStat(): moStat(EOT(), "best") { + } + + /** + * Initialization of the best solution on the first one + * @param _sol the first solution + */ + virtual void init(EOT & _sol) { + value() = _sol; + } + + /** + * Update the best solution + * @param _sol the current solution + */ + virtual void operator()(EOT & _sol) { + if (value().fitness() < _sol.fitness()) + value() = _sol; + } + + /** + * @return name of the class + */ + virtual std::string className(void) const { + return "moBestSoFarStat"; + } + }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moCombinedContinuator.h b/trunk/paradiseo-mo/src/continuator/moCombinedContinuator.h index 7001a0e66..5d85d4179 100644 --- a/trunk/paradiseo-mo/src/continuator/moCombinedContinuator.h +++ b/trunk/paradiseo-mo/src/continuator/moCombinedContinuator.h @@ -42,52 +42,52 @@ template< class Neighbor > class moCombinedContinuator : public moContinuator { public: - typedef typename Neighbor::EOT EOT ; + typedef typename Neighbor::EOT EOT ; - /** - * Default constructor (moCheckpoint must have at least one continuator) - * @param _cont a continuator - */ - moCombinedContinuator(moContinuator& _cont) { - continuators.push_back(&_cont); - } + /** + * Default constructor (moCheckpoint must have at least one continuator) + * @param _cont a continuator + */ + moCombinedContinuator(moContinuator& _cont) { + continuators.push_back(&_cont); + } - /** - * add a continuator to the combined continuator - * @param _cont a continuator - */ - void add(moContinuator& _cont) { - continuators.push_back(&_cont); - } - - /** - * init all continuators - * @param _solution a solution - */ - virtual void init(EOT & _solution) { - for(unsigned int i = 0; i < continuators.size(); ++i) - continuators[i]->init(_solution); - } + /** + * add a continuator to the combined continuator + * @param _cont a continuator + */ + void add(moContinuator& _cont) { + continuators.push_back(&_cont); + } - /** - *@param _solution a solution - *@return true all the continuators are true - */ - virtual bool operator()(EOT & _solution) { - bool bContinue = true; + /** + * init all continuators + * @param _solution a solution + */ + virtual void init(EOT & _solution) { + for (unsigned int i = 0; i < continuators.size(); ++i) + continuators[i]->init(_solution); + } + + /** + *@param _solution a solution + *@return true all the continuators are true + */ + virtual bool operator()(EOT & _solution) { + bool bContinue = true; + + // some data may be update in each continuator. + // So, all continuators are tested + for (unsigned int i = 0; i < continuators.size(); ++i) + if ( !(*continuators[i])(_solution) ) + bContinue = false; + + return bContinue; + } - // some data may be update in each continuator. - // So, all continuators are tested - for(unsigned int i = 0; i < continuators.size(); ++i) - if ( !(*continuators[i])(_solution) ) - bContinue = false; - - return bContinue; - } - private: - /** continuators vector */ - std::vector< moContinuator* > continuators; - + /** continuators vector */ + std::vector< moContinuator* > continuators; + }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moCounterStat.h b/trunk/paradiseo-mo/src/continuator/moCounterStat.h index b3302aa36..7db90f916 100644 --- a/trunk/paradiseo-mo/src/continuator/moCounterStat.h +++ b/trunk/paradiseo-mo/src/continuator/moCounterStat.h @@ -44,37 +44,37 @@ template class moCounterStat : public moStat { public : - using moStat< EOT, unsigned int>::value; - - /** - * Default Constructor - */ - moCounterStat(): moStat(0, "counter") { - } - - /** - * Give the number of iteration - * @param _sol a solution - */ - virtual void init(EOT & _sol) { - value() = 0; - } - - /** - * Give the number of iteration - * @param _sol a solution - */ - virtual void operator()(EOT & _sol) { - value() = value() + 1; - } - - /** - * @return name of the class - */ - virtual std::string className(void) const { - return "moCounterStat"; - } - + using moStat< EOT, unsigned int>::value; + + /** + * Default Constructor + */ + moCounterStat(): moStat(0, "counter") { + } + + /** + * Give the number of iteration + * @param _sol a solution + */ + virtual void init(EOT & _sol) { + value() = 0; + } + + /** + * Give the number of iteration + * @param _sol a solution + */ + virtual void operator()(EOT & _sol) { + value() = value() + 1; + } + + /** + * @return name of the class + */ + virtual std::string className(void) const { + return "moCounterStat"; + } + }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moDistanceStat.h b/trunk/paradiseo-mo/src/continuator/moDistanceStat.h index 0b11498ab..ffb877f0e 100644 --- a/trunk/paradiseo-mo/src/continuator/moDistanceStat.h +++ b/trunk/paradiseo-mo/src/continuator/moDistanceStat.h @@ -60,9 +60,9 @@ public : * Compute distance between the first solution and the reference solution * @param _sol the first solution */ - virtual void init(EOT & _sol) { - value() = dist(_sol, refSolution); - } + virtual void init(EOT & _sol) { + value() = dist(_sol, refSolution); + } /** * Compute distance between a solution and the reference solution diff --git a/trunk/paradiseo-mo/src/continuator/moFitContinuator.h b/trunk/paradiseo-mo/src/continuator/moFitContinuator.h index 05787bcf8..03ac6b686 100644 --- a/trunk/paradiseo-mo/src/continuator/moFitContinuator.h +++ b/trunk/paradiseo-mo/src/continuator/moFitContinuator.h @@ -40,24 +40,24 @@ template< class Neighbor > class moFitContinuator : public moContinuator { public: - typedef typename Neighbor::EOT EOT ; - typedef typename EOT::Fitness Fitness ; + typedef typename Neighbor::EOT EOT ; + typedef typename EOT::Fitness Fitness ; + + /** + * @param _maxFit maximum fitness to reach + */ + moFitContinuator(Fitness _maxFit): maxFit(_maxFit) {} + + /** + *@param _solution a solution + *@return true if counter < maxFit + */ + virtual bool operator()(EOT & _solution) { + return (_solution.fitness() < maxFit); + } - /** - * @param _maxFit maximum fitness to reach - */ - moFitContinuator(Fitness _maxFit): maxFit(_maxFit){} - - /** - *@param _solution a solution - *@return true if counter < maxFit - */ - virtual bool operator()(EOT & _solution) { - return (_solution.fitness() < maxFit); - } - private: - Fitness maxFit; - + Fitness maxFit; + }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moFitnessStat.h b/trunk/paradiseo-mo/src/continuator/moFitnessStat.h index 3aa0ec8f1..9deb77eec 100644 --- a/trunk/paradiseo-mo/src/continuator/moFitnessStat.h +++ b/trunk/paradiseo-mo/src/continuator/moFitnessStat.h @@ -44,40 +44,40 @@ template class moFitnessStat : public moStat { public : - typedef typename EOT::Fitness Fitness; - using moStat< EOT, Fitness >::value; + typedef typename EOT::Fitness Fitness; + using moStat< EOT, Fitness >::value; - /** - * Default Constructor - * @param _description a description of the stat - */ - moFitnessStat(std::string _description = "fitness"): - moStat(Fitness(), _description) {} - - /** - * store the initial fitness value - * @param _sol the initial solution - */ - virtual void init(EOT & _sol) - { - value() = _sol.fitness(); - } - - /** - * store fitness value - * @param _sol the corresponding solution - */ - virtual void operator()(EOT & _sol) - { - value() = _sol.fitness(); - } - - /** - * @return the name of the class - */ - virtual std::string className(void) const { - return "moFitnessStat"; - } + /** + * Default Constructor + * @param _description a description of the stat + */ + moFitnessStat(std::string _description = "fitness"): + moStat(Fitness(), _description) {} + + /** + * store the initial fitness value + * @param _sol the initial solution + */ + virtual void init(EOT & _sol) + { + value() = _sol.fitness(); + } + + /** + * store fitness value + * @param _sol the corresponding solution + */ + virtual void operator()(EOT & _sol) + { + value() = _sol.fitness(); + } + + /** + * @return the name of the class + */ + virtual std::string className(void) const { + return "moFitnessStat"; + } }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moFullEvalContinuator.h b/trunk/paradiseo-mo/src/continuator/moFullEvalContinuator.h index bf063833d..bf78f9294 100644 --- a/trunk/paradiseo-mo/src/continuator/moFullEvalContinuator.h +++ b/trunk/paradiseo-mo/src/continuator/moFullEvalContinuator.h @@ -37,53 +37,53 @@ Contact: paradiseo-help@lists.gforge.inria.fr /** * Continue until a maximum fixed number of full evaluation is reached * - * Becareful 1: The number of full evaluations considered is within the local search (not before it) + * Becareful 1: The number of full evaluations considered is within the local search (not before it) * Becareful 2: Can not be used if the evaluation function is used in parallel */ template< class Neighbor > class moFullEvalContinuator : public moContinuator { public: - typedef typename Neighbor::EOT EOT ; + typedef typename Neighbor::EOT EOT ; + + /** + * Default constructor + * @param _eval evaluation function to count + * @param _maxFullEval number maximum of iterations + */ + moFullEvalContinuator(eoEvalFuncCounter & _eval, unsigned int _maxFullEval): eval(_eval), maxFullEval(_maxFullEval) { + nbEval_start = eval.value(); + } + + /** + * Test if continue + * @param _solution a solution + * @return true if number of evaluations < maxFullEval + */ + virtual bool operator()(EOT & _solution) { + return (eval.value() - nbEval_start < maxFullEval); + } + + /** + * Reset the number of evaluations + * @param _solution a solution + */ + virtual void init(EOT & _solution) { + nbEval_start = eval.value(); + } - /** - * Default constructor - * @param _eval evaluation function to count - * @param _maxFullEval number maximum of iterations - */ - moFullEvalContinuator(eoEvalFuncCounter & _eval, unsigned int _maxFullEval): eval(_eval), maxFullEval(_maxFullEval) { - nbEval_start = eval.value(); - } - - /** - * Test if continue - * @param _solution a solution - * @return true if number of evaluations < maxFullEval - */ - virtual bool operator()(EOT & _solution) { - return (eval.value() - nbEval_start < maxFullEval); - } - - /** - * Reset the number of evaluations - * @param _solution a solution - */ - virtual void init(EOT & _solution) { - nbEval_start = eval.value(); - } - /** * the current number of evaluation from the begining * @return the number of evaluation */ unsigned int value() { - return eval.value() - nbEval_start ; + return eval.value() - nbEval_start ; } private: - eoEvalFuncCounter & eval; - unsigned int nbEval_start ; - unsigned int maxFullEval ; - + eoEvalFuncCounter & eval; + unsigned int nbEval_start ; + unsigned int maxFullEval ; + }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moIterContinuator.h b/trunk/paradiseo-mo/src/continuator/moIterContinuator.h index 1d222c843..1df9da7bf 100644 --- a/trunk/paradiseo-mo/src/continuator/moIterContinuator.h +++ b/trunk/paradiseo-mo/src/continuator/moIterContinuator.h @@ -42,23 +42,23 @@ class moIterContinuator : public moContinuator public: typedef typename Neighbor::EOT EOT ; - /** - * @param _maxIter number maximum of iterations - * @param _verbose true/false : verbose mode on/off - */ - moIterContinuator(unsigned int _maxIter, bool _verbose=true): maxIter(_maxIter), verbose(_verbose){} + /** + * @param _maxIter number maximum of iterations + * @param _verbose true/false : verbose mode on/off + */ + moIterContinuator(unsigned int _maxIter, bool _verbose=true): maxIter(_maxIter), verbose(_verbose) {} /** *@param _solution a solution *@return true if counter < maxIter */ virtual bool operator()(EOT & _solution) { - bool res; - cpt++; - res = (cpt < maxIter); - if(!res && verbose) - std::cout << "STOP in moIterContinuator: Reached maximum number of iterations [" << cpt << "/" << maxIter << "]" << std::endl; - return res; + bool res; + cpt++; + res = (cpt < maxIter); + if (!res && verbose) + std::cout << "STOP in moIterContinuator: Reached maximum number of iterations [" << cpt << "/" << maxIter << "]" << std::endl; + return res; } /** @@ -66,7 +66,7 @@ public: * @param _solution a solution */ virtual void init(EOT & _solution) { - cpt = 0; + cpt = 0; } /** @@ -74,7 +74,7 @@ public: * @return the number of iteration */ unsigned int value() { - return cpt ; + return cpt ; } private: diff --git a/trunk/paradiseo-mo/src/continuator/moMinusOneCounterStat.h b/trunk/paradiseo-mo/src/continuator/moMinusOneCounterStat.h index 02f7a5451..0e32f3b9e 100644 --- a/trunk/paradiseo-mo/src/continuator/moMinusOneCounterStat.h +++ b/trunk/paradiseo-mo/src/continuator/moMinusOneCounterStat.h @@ -45,46 +45,46 @@ template class moMinusOneCounterStat : public moStat { public : - using moStat< EOT, unsigned int>::value; - - /** - * Default Constructor - */ - moMinusOneCounterStat(): moStat(0, "counter") { - counter = 0; - } - - /** - * Give the number of iteration - * @param _sol a solution - */ - virtual void init(EOT & _sol) { - counter = 0; - value() = 0; - } - - /** - * Give the number of iteration - * @param _sol a solution - */ - virtual void operator()(EOT & _sol) { - counter++; - if (counter > 0) - value() = counter - 1; - else - value() = 0; - } - - /** - * @return name of the class - */ - virtual std::string className(void) const { - return "moMinusOneCounterStat"; - } + using moStat< EOT, unsigned int>::value; + + /** + * Default Constructor + */ + moMinusOneCounterStat(): moStat(0, "counter") { + counter = 0; + } + + /** + * Give the number of iteration + * @param _sol a solution + */ + virtual void init(EOT & _sol) { + counter = 0; + value() = 0; + } + + /** + * Give the number of iteration + * @param _sol a solution + */ + virtual void operator()(EOT & _sol) { + counter++; + if (counter > 0) + value() = counter - 1; + else + value() = 0; + } + + /** + * @return name of the class + */ + virtual std::string className(void) const { + return "moMinusOneCounterStat"; + } private: - unsigned int counter; - + unsigned int counter; + }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moNeighborBestStat.h b/trunk/paradiseo-mo/src/continuator/moNeighborBestStat.h index 0b4a4ab96..d96ddaadb 100644 --- a/trunk/paradiseo-mo/src/continuator/moNeighborBestStat.h +++ b/trunk/paradiseo-mo/src/continuator/moNeighborBestStat.h @@ -63,12 +63,12 @@ public : * @param _solNeighborComparator a comparator between a solution and a neighbor * @param _k number of neighbors visited */ - moNeighborBestStat(Neighborhood& _neighborhood, moEval& _eval, moNeighborComparator& _neighborComparator, moSolNeighborComparator& _solNeighborComparator, unsigned int _k = 0): - moStat(true, "neighborhood"), - neighborhood(_neighborhood), eval(_eval), - neighborComparator(_neighborComparator), - solNeighborComparator(_solNeighborComparator), - kmax(_k) + moNeighborBestStat(Neighborhood& _neighborhood, moEval& _eval, moNeighborComparator& _neighborComparator, moSolNeighborComparator& _solNeighborComparator, unsigned int _k = 0): + moStat(true, "neighborhood"), + neighborhood(_neighborhood), eval(_eval), + neighborComparator(_neighborComparator), + solNeighborComparator(_solNeighborComparator), + kmax(_k) {} /** @@ -79,12 +79,12 @@ public : * @param _eval an evaluation function * @param _k number of neighbors visited (default all) */ - moNeighborBestStat(Neighborhood& _neighborhood, moEval& _eval, unsigned _k = 0): - moStat(Fitness(), "best"), - neighborhood(_neighborhood), eval(_eval), - neighborComparator(defaultNeighborComp), - solNeighborComparator(defaultSolNeighborComp), - kmax(_k) + moNeighborBestStat(Neighborhood& _neighborhood, moEval& _eval, unsigned _k = 0): + moStat(Fitness(), "best"), + neighborhood(_neighborhood), eval(_eval), + neighborComparator(defaultNeighborComp), + solNeighborComparator(defaultSolNeighborComp), + kmax(_k) {} /** @@ -92,7 +92,7 @@ public : * @param _solution the first solution */ virtual void init(EOT & _solution) { - operator()(_solution); + operator()(_solution); } /** @@ -113,8 +113,8 @@ public : //initialize the best neighbor best = current; - // number of visited neighbors - unsigned int k = 1; + // number of visited neighbors + unsigned int k = 1; //test all others neighbors while ( ( (kmax == 0) || (k < kmax) ) && neighborhood.cont(_solution)) { @@ -127,14 +127,14 @@ public : if (neighborComparator(best, current)) best = current; - k++; + k++; } value() = best.fitness(); } else { //if _solution hasn't neighbor, - value() = Fitness(); + value() = Fitness(); } } @@ -146,22 +146,22 @@ public : } private: - // to explore the neighborhood - Neighborhood& neighborhood ; - moEval& eval; - - // comparator betwenn solution and neighbor or between neighbors - moNeighborComparator& neighborComparator; - moSolNeighborComparator& solNeighborComparator; - - // default comparators - // compare the fitness values of neighbors: true is strictly greater - moNeighborComparator defaultNeighborComp; - // compare the fitness values of the solution and the neighbor: true if strictly greater - moSolNeighborComparator defaultSolNeighborComp; - - // number of neighbor to explore - unsigned int kmax; + // to explore the neighborhood + Neighborhood& neighborhood ; + moEval& eval; + + // comparator betwenn solution and neighbor or between neighbors + moNeighborComparator& neighborComparator; + moSolNeighborComparator& solNeighborComparator; + + // default comparators + // compare the fitness values of neighbors: true is strictly greater + moNeighborComparator defaultNeighborComp; + // compare the fitness values of the solution and the neighbor: true if strictly greater + moSolNeighborComparator defaultSolNeighborComp; + + // number of neighbor to explore + unsigned int kmax; }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moNeighborEvalContinuator.h b/trunk/paradiseo-mo/src/continuator/moNeighborEvalContinuator.h index 561d895ac..6b42086f2 100644 --- a/trunk/paradiseo-mo/src/continuator/moNeighborEvalContinuator.h +++ b/trunk/paradiseo-mo/src/continuator/moNeighborEvalContinuator.h @@ -37,7 +37,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr /** * Continue until a maximum fixed number of neighbor evaluation is reached * - * Becareful 1: The number of full evaluations considered is within the local search (not before it) + * Becareful 1: The number of full evaluations considered is within the local search (not before it) * Becareful 2: Can not be used if the evaluation function is used in parallel */ template< class Neighbor > @@ -46,42 +46,42 @@ class moNeighborEvalContinuator : public moContinuator public: typedef typename Neighbor::EOT EOT ; - /** - * Default constructor - * @param _eval neighbor evaluation function to count - * @param _maxNeighborEval number maximum of iterations - */ - moNeighborEvalContinuator(moEvalCounter & _eval, unsigned int _maxNeighborEval): eval(_eval), maxNeighborEval(_maxNeighborEval){} + /** + * Default constructor + * @param _eval neighbor evaluation function to count + * @param _maxNeighborEval number maximum of iterations + */ + moNeighborEvalContinuator(moEvalCounter & _eval, unsigned int _maxNeighborEval): eval(_eval), maxNeighborEval(_maxNeighborEval) {} + + /** + * Test if continue + * @param _solution a solution + * @return true if number of evaluations < maxNeighborEval + */ + virtual bool operator()(EOT & _solution) { + return (eval.value() - nbEval_start < maxNeighborEval); + } + + /** + * Reset the number of evaluations + * @param _solution a solution + */ + virtual void init(EOT & _solution) { + nbEval_start = eval.value(); + } + + /** + * the current number of evaluation from the begining + * @return the number of evaluation + */ + unsigned int value() { + return eval.value() - nbEval_start ; + } - /** - * Test if continue - * @param _solution a solution - * @return true if number of evaluations < maxNeighborEval - */ - virtual bool operator()(EOT & _solution) { - return (eval.value() - nbEval_start < maxNeighborEval); - } - - /** - * Reset the number of evaluations - * @param _solution a solution - */ - virtual void init(EOT & _solution) { - nbEval_start = eval.value(); - } - - /** - * the current number of evaluation from the begining - * @return the number of evaluation - */ - unsigned int value() { - return eval.value() - nbEval_start ; - } - private: - moEvalCounter & eval; - unsigned int maxNeighborEval; - unsigned int nbEval_start ; - + moEvalCounter & eval; + unsigned int maxNeighborEval; + unsigned int nbEval_start ; + }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moNeighborFitnessStat.h b/trunk/paradiseo-mo/src/continuator/moNeighborFitnessStat.h index 9d515299d..239f60326 100644 --- a/trunk/paradiseo-mo/src/continuator/moNeighborFitnessStat.h +++ b/trunk/paradiseo-mo/src/continuator/moNeighborFitnessStat.h @@ -46,67 +46,67 @@ template< class Neighbor > class moNeighborFitnessStat : public moStat { public : - typedef typename Neighbor::EOT EOT ; - typedef moNeighborhood Neighborhood ; - typedef typename EOT::Fitness Fitness ; + typedef typename Neighbor::EOT EOT ; + typedef moNeighborhood Neighborhood ; + typedef typename EOT::Fitness Fitness ; - using moStat< EOT, Fitness >::value; + using moStat< EOT, Fitness >::value; - /** - * Default Constructor - * @param _neighborhood a neighborhood - * @param _eval an evaluation function - */ - moNeighborFitnessStat(Neighborhood& _neighborhood, moEval& _eval): - moStat(Fitness(), "neighborhood"), - neighborhood(_neighborhood), eval(_eval) - { - if (!neighborhood.isRandom()) { - std::cout << "moNeighborFitnessStat::Warning -> the neighborhood used is not random, the neighbor will not be random" << std::endl; - } - } - - /** - * Compute the fitness of one random neighbor - * @param _solution the first solution - */ - virtual void init(EOT & _solution) { - operator()(_solution); - } - - /** - * Compute the fitness of one random neighbor - * @param _solution the corresponding solution - */ - virtual void operator()(EOT & _solution) { - if (neighborhood.hasNeighbor(_solution)) { - Neighbor current ; - - //init the first neighbor which is suppoed to be random - neighborhood.init(_solution, current); - - //eval the _solution moved with the neighbor and stock the result in the neighbor - eval(_solution, current); - - // the fitness value is collected - value() = current.fitness(); - } else { - //if _solution hasn't neighbor, - value() = Fitness(); + /** + * Default Constructor + * @param _neighborhood a neighborhood + * @param _eval an evaluation function + */ + moNeighborFitnessStat(Neighborhood& _neighborhood, moEval& _eval): + moStat(Fitness(), "neighborhood"), + neighborhood(_neighborhood), eval(_eval) + { + if (!neighborhood.isRandom()) { + std::cout << "moNeighborFitnessStat::Warning -> the neighborhood used is not random, the neighbor will not be random" << std::endl; + } } - } - /** - * @return the class name - */ - virtual std::string className(void) const { - return "moNeighborFitnessStat"; - } + /** + * Compute the fitness of one random neighbor + * @param _solution the first solution + */ + virtual void init(EOT & _solution) { + operator()(_solution); + } + + /** + * Compute the fitness of one random neighbor + * @param _solution the corresponding solution + */ + virtual void operator()(EOT & _solution) { + if (neighborhood.hasNeighbor(_solution)) { + Neighbor current ; + + //init the first neighbor which is suppoed to be random + neighborhood.init(_solution, current); + + //eval the _solution moved with the neighbor and stock the result in the neighbor + eval(_solution, current); + + // the fitness value is collected + value() = current.fitness(); + } else { + //if _solution hasn't neighbor, + value() = Fitness(); + } + } + + /** + * @return the class name + */ + virtual std::string className(void) const { + return "moNeighborFitnessStat"; + } private: - // to explore the neighborhood - Neighborhood& neighborhood ; - moEval& eval; + // to explore the neighborhood + Neighborhood& neighborhood ; + moEval& eval; }; diff --git a/trunk/paradiseo-mo/src/continuator/moNeighborhoodStat.h b/trunk/paradiseo-mo/src/continuator/moNeighborhoodStat.h index 3806b8551..25ea7661e 100644 --- a/trunk/paradiseo-mo/src/continuator/moNeighborhoodStat.h +++ b/trunk/paradiseo-mo/src/continuator/moNeighborhoodStat.h @@ -89,7 +89,7 @@ public : * @param _solution the first solution */ virtual void init(EOT & _solution) { - operator()(_solution); + operator()(_solution); } /** @@ -246,7 +246,7 @@ private: // default comparators // compare the fitness values of neighbors: true is strictly greater moNeighborComparator 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 defaultSolNeighborComp; // the stastics of the fitness diff --git a/trunk/paradiseo-mo/src/continuator/moStatBase.h b/trunk/paradiseo-mo/src/continuator/moStatBase.h index eff9ddaed..f0553ee1f 100644 --- a/trunk/paradiseo-mo/src/continuator/moStatBase.h +++ b/trunk/paradiseo-mo/src/continuator/moStatBase.h @@ -54,7 +54,7 @@ public: /** * first call of a statistical operator */ - virtual void init(EOT &){} + virtual void init(EOT &) {} }; diff --git a/trunk/paradiseo-mo/src/continuator/moStatFromStat.h b/trunk/paradiseo-mo/src/continuator/moStatFromStat.h index a8c934e0b..02eb0c70f 100644 --- a/trunk/paradiseo-mo/src/continuator/moStatFromStat.h +++ b/trunk/paradiseo-mo/src/continuator/moStatFromStat.h @@ -44,40 +44,40 @@ template class moStatFromStat : public moStat { public : - using moStat< EOT , T >::value; - - /** - * Default Constructor - * @param _stat a stat - */ - moStatFromStat(moStat & _stat): moStat(0, _stat.description()), stat(_stat) { - } - - /** - * The value of this stat is a copy of the value of the initial stat - * @param _sol a solution - */ - virtual void init(EOT & _sol) { - value() = stat.value(); - } - - /** - * The value of this stat is a copy of the value of the initial stat - * @param _sol a solution - */ - virtual void operator()(EOT & _sol) { - value() = stat.value(); - } - - /** - * @return name of the class - */ - virtual std::string className(void) const { - return "moStatFromStat"; - } - + using moStat< EOT , T >::value; + + /** + * Default Constructor + * @param _stat a stat + */ + moStatFromStat(moStat & _stat): moStat(0, _stat.description()), stat(_stat) { + } + + /** + * The value of this stat is a copy of the value of the initial stat + * @param _sol a solution + */ + virtual void init(EOT & _sol) { + value() = stat.value(); + } + + /** + * The value of this stat is a copy of the value of the initial stat + * @param _sol a solution + */ + virtual void operator()(EOT & _sol) { + value() = stat.value(); + } + + /** + * @return name of the class + */ + virtual std::string className(void) const { + return "moStatFromStat"; + } + private: - moStat & stat; + moStat & stat; }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moTimeContinuator.h b/trunk/paradiseo-mo/src/continuator/moTimeContinuator.h index 94d13721d..7c137cee6 100644 --- a/trunk/paradiseo-mo/src/continuator/moTimeContinuator.h +++ b/trunk/paradiseo-mo/src/continuator/moTimeContinuator.h @@ -40,14 +40,14 @@ class moTimeContinuator: public moContinuator { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; /** * Ctor. * @param _max maximum running time$ * @param _verbose verbose mode true/false -> on/off */ - moTimeContinuator(time_t _max, bool _verbose=true): max(_max), verbose(_verbose){ + moTimeContinuator(time_t _max, bool _verbose=true): max(_max), verbose(_verbose) { start = time(NULL); } @@ -58,11 +58,11 @@ public: */ virtual bool operator() (EOT& _sol) { - bool res; + bool res; time_t elapsed = (time_t) difftime(time(NULL), start); res = (elapsed < max); - if(!res && verbose) - std::cout << "STOP in moTimeContinuator: Reached maximum time [" << elapsed << "/" << max << "]" << std::endl; + if (!res && verbose) + std::cout << "STOP in moTimeContinuator: Reached maximum time [" << elapsed << "/" << max << "]" << std::endl; return res; } diff --git a/trunk/paradiseo-mo/src/continuator/moVectorMonitor.h b/trunk/paradiseo-mo/src/continuator/moVectorMonitor.h index 5fc74db9a..dc6a24eaa 100644 --- a/trunk/paradiseo-mo/src/continuator/moVectorMonitor.h +++ b/trunk/paradiseo-mo/src/continuator/moVectorMonitor.h @@ -42,165 +42,165 @@ /** * To save the values of the same type (double, unsigned int, or EOT) in a vector * It is similar to eoFileMonitor - * + * */ template class moVectorMonitor : public eoMonitor { public: - - /** - * Default Constructor - * @param _param the parameter of type double to save in the vector - */ - moVectorMonitor(eoValueParam & _param) : doubleParam(&_param), intParam(NULL), eotParam(NULL) - { } - /** - * Default Constructor - * @param _param the parameter of type unsigned int to save in the vector - */ - moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(&_param), eotParam(NULL) - { } + /** + * Default Constructor + * @param _param the parameter of type double to save in the vector + */ + moVectorMonitor(eoValueParam & _param) : doubleParam(&_param), intParam(NULL), eotParam(NULL) + { } - /** - * Default Constructor - * @param _param the parameter of type EOT to save in the vector - */ - moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), eotParam(&_param) - { } + /** + * Default Constructor + * @param _param the parameter of type unsigned int to save in the vector + */ + moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(&_param), eotParam(NULL) + { } - /** - * Default Constructor - * @param _param the parameter of type eoScalarFitness to save in the vector - */ - template - moVectorMonitor(eoValueParam > & _param) : doubleParam( & (eoValueParam&)_param), intParam(NULL), eotParam(NULL) - { } + /** + * Default Constructor + * @param _param the parameter of type EOT to save in the vector + */ + moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), eotParam(&_param) + { } - /** - * Default Constructor - * @param _param unvalid Parameter - */ - template - moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), eotParam(NULL) - { - std::cerr << "Sorry the type can not be in a vector of moVectorMonitor" << std::endl; - } + /** + * Default Constructor + * @param _param the parameter of type eoScalarFitness to save in the vector + */ + template + moVectorMonitor(eoValueParam > & _param) : doubleParam( & (eoValueParam&)_param), intParam(NULL), eotParam(NULL) + { } - /** - * To test if the value are basic type (double or unsigned int), or EOT type - * - * @return true if the type is a EOT type - */ - bool solutionType() { - return eotParam != NULL; - } - - /** - * To "print" the value of the parameter in the vector - * - * @return this monitor (sorry I don't why, but it is like this in EO) - */ - eoMonitor& operator()(void) { - if (doubleParam != NULL) - valueVec.push_back(doubleParam->value()); - else - if (intParam != NULL) - valueVec.push_back((double) intParam->value()); - else - eotVec.push_back(eotParam->value()); - - return *this ; - } - - /** - * To have all the values - * - * @return the vector of values - */ - const std::vector& getValues() const { - return valueVec; - } - - /** - * To have all the solutions - * - * @return the vector of solutions - */ - const std::vector& getSolutions() const { - return eotVec; - } - - /** - * to get the value out. - * @return the string of the value - */ - std::string getValue(unsigned int i) const { - std::ostringstream os; - - if (eotParam == NULL) - os << (valueVec[i]) ; - else - os << (eotVec[i]) ; - - return os.str(); - } - - /** - * clear the vector - */ - void clear() { - valueVec.clear(); - eotVec.clear(); - } - - /** - * number of value - * @return size of the vector - */ - unsigned int size() { - if (eotParam == NULL) - return valueVec.size(); - else - return eotVec.size(); - } - - /** - * to export the vector of values into one file - * @param _filename file name - */ - void fileExport(std::string _filename) { - // create file - std::ofstream os(_filename.c_str()); - - if (!os) { - std::string str = "moVectorMonitor: Could not open " + _filename; - throw std::runtime_error(str); + /** + * Default Constructor + * @param _param unvalid Parameter + */ + template + moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), eotParam(NULL) + { + std::cerr << "Sorry the type can not be in a vector of moVectorMonitor" << std::endl; + } + + /** + * To test if the value are basic type (double or unsigned int), or EOT type + * + * @return true if the type is a EOT type + */ + bool solutionType() { + return eotParam != NULL; + } + + /** + * To "print" the value of the parameter in the vector + * + * @return this monitor (sorry I don't why, but it is like this in EO) + */ + eoMonitor& operator()(void) { + if (doubleParam != NULL) + valueVec.push_back(doubleParam->value()); + else + if (intParam != NULL) + valueVec.push_back((double) intParam->value()); + else + eotVec.push_back(eotParam->value()); + + return *this ; + } + + /** + * To have all the values + * + * @return the vector of values + */ + const std::vector& getValues() const { + return valueVec; + } + + /** + * To have all the solutions + * + * @return the vector of solutions + */ + const std::vector& getSolutions() const { + return eotVec; + } + + /** + * to get the value out. + * @return the string of the value + */ + std::string getValue(unsigned int i) const { + std::ostringstream os; + + if (eotParam == NULL) + os << (valueVec[i]) ; + else + os << (eotVec[i]) ; + + return os.str(); + } + + /** + * clear the vector + */ + void clear() { + valueVec.clear(); + eotVec.clear(); + } + + /** + * number of value + * @return size of the vector + */ + unsigned int size() { + if (eotParam == NULL) + return valueVec.size(); + else + return eotVec.size(); + } + + /** + * to export the vector of values into one file + * @param _filename file name + */ + void fileExport(std::string _filename) { + // create file + std::ofstream os(_filename.c_str()); + + if (!os) { + std::string str = "moVectorMonitor: Could not open " + _filename; + throw std::runtime_error(str); + } + + for (unsigned int i = 0; i < size(); i++) { + os << getValue(i); + + os << std::endl ; + } + + } + + /** + * @return name of the class + */ + virtual std::string className(void) const { + return "moVectorMonitor"; } - - for(unsigned int i = 0; i < size(); i++) { - os << getValue(i); - - os << std::endl ; - } - - } - /** - * @return name of the class - */ - virtual std::string className(void) const { - return "moVectorMonitor"; - } - protected: - eoValueParam * doubleParam ; - eoValueParam * intParam ; - eoValueParam * eotParam ; + eoValueParam * doubleParam ; + eoValueParam * intParam ; + eoValueParam * eotParam ; - std::vector valueVec; - std::vector eotVec; + std::vector valueVec; + std::vector eotVec; }; diff --git a/trunk/paradiseo-mo/src/coolingSchedule/moCoolingSchedule.h b/trunk/paradiseo-mo/src/coolingSchedule/moCoolingSchedule.h index b75e68a6e..149304f93 100644 --- a/trunk/paradiseo-mo/src/coolingSchedule/moCoolingSchedule.h +++ b/trunk/paradiseo-mo/src/coolingSchedule/moCoolingSchedule.h @@ -39,23 +39,23 @@ /** * Cooling Schedule of the temperature in the simulated algorithm - * + * */ template< class EOT > class moCoolingSchedule : public eoUF { public: - /** - * Initial temperature - * @param _solution initial solution - */ - virtual double init(EOT & _solution) = 0; + /** + * Initial temperature + * @param _solution initial solution + */ + virtual double init(EOT & _solution) = 0; - /** - * update the temperature - * @param _temp current temperature to update - */ - virtual void update(double& _temp) = 0; + /** + * update the temperature + * @param _temp current temperature to update + */ + virtual void update(double& _temp) = 0; }; diff --git a/trunk/paradiseo-mo/src/coolingSchedule/moDynSpanCoolingSchedule.h b/trunk/paradiseo-mo/src/coolingSchedule/moDynSpanCoolingSchedule.h index c28905f33..4bca3d36d 100644 --- a/trunk/paradiseo-mo/src/coolingSchedule/moDynSpanCoolingSchedule.h +++ b/trunk/paradiseo-mo/src/coolingSchedule/moDynSpanCoolingSchedule.h @@ -39,86 +39,86 @@ /** * Cooling Schedule of the temperature in the simulated algorithm - * + * */ template< class EOT > class moDynSpanCoolingSchedule : public moCoolingSchedule { public: - /** - * default constructor - * @param _initT initial temperature - * @param _alpha factor of decreasing - * @param _spanMove maximum number of move with equal temperature - * @param _spanNoMove maximum number of no improvement with equal temperature - * @param _nbSpan maximum number of span with no improvmement before stopping the search - */ - moDynSpanCoolingSchedule(double _initT, double _alpha, unsigned int _spanMove, unsigned int _spanNoMove, unsigned int _nbSpan) : initT(_initT), alpha(_alpha), spanMove(_spanMove), spanNoMove(_spanNoMove), nbSpan(_nbSpan) { - } - - /** - * Initial temperature - * @param _solution initial solution - */ - virtual double init(EOT & _solution) { - // number of successive moves since the last temperature change - nbMove = 0; - - // number of no improvement since the last temperature change - nbNoMove = 0; - - // number of span with no improvement - nbSpan = 0; - - return initT; - } - - /** - * update the temperature by a factor - * @param _temp current temperature to update - */ - virtual void update(double& _temp) { - if (nbMove >= spanMove || nbNoMove >= spanNoMove) { - _temp *= alpha; - - nbMove = 0; - nbNoMove = 0; - } else { - nbMove++; - nbNoMove++; + /** + * default constructor + * @param _initT initial temperature + * @param _alpha factor of decreasing + * @param _spanMove maximum number of move with equal temperature + * @param _spanNoMove maximum number of no improvement with equal temperature + * @param _nbSpan maximum number of span with no improvmement before stopping the search + */ + moDynSpanCoolingSchedule(double _initT, double _alpha, unsigned int _spanMove, unsigned int _spanNoMove, unsigned int _nbSpan) : initT(_initT), alpha(_alpha), spanMove(_spanMove), spanNoMove(_spanNoMove), nbSpan(_nbSpan) { } - } - /** - * compare the temperature to the threshold - * @param _temp current temperature - * @return true if the current temperature is over the threshold (final temperature) - */ - virtual bool operator()(double _temp) { - return _temp > finalT; - } + /** + * Initial temperature + * @param _solution initial solution + */ + virtual double init(EOT & _solution) { + // number of successive moves since the last temperature change + nbMove = 0; + + // number of no improvement since the last temperature change + nbNoMove = 0; + + // number of span with no improvement + nbSpan = 0; + + return initT; + } + + /** + * update the temperature by a factor + * @param _temp current temperature to update + */ + virtual void update(double& _temp) { + if (nbMove >= spanMove || nbNoMove >= spanNoMove) { + _temp *= alpha; + + nbMove = 0; + nbNoMove = 0; + } else { + nbMove++; + nbNoMove++; + } + } + + /** + * compare the temperature to the threshold + * @param _temp current temperature + * @return true if the current temperature is over the threshold (final temperature) + */ + virtual bool operator()(double _temp) { + return _temp > finalT; + } private: - // initial temperature - double initT; + // initial temperature + double initT; - // coefficient of decrease - double alpha; + // coefficient of decrease + double alpha; - // - unsigned int spanMove; + // + unsigned int spanMove; - // - unsigned int spanNoMove; + // + unsigned int spanNoMove; - // maximum number of iterations at the same temperature - unsigned int nbSpan; + // maximum number of iterations at the same temperature + unsigned int nbSpan; - // threshold temperature - double finalT; + // threshold temperature + double finalT; - // number of steps with the same temperature - unsigned int step; + // number of steps with the same temperature + unsigned int step; }; diff --git a/trunk/paradiseo-mo/src/coolingSchedule/moSimpleCoolingSchedule.h b/trunk/paradiseo-mo/src/coolingSchedule/moSimpleCoolingSchedule.h index 3c04c1084..4bab840d9 100644 --- a/trunk/paradiseo-mo/src/coolingSchedule/moSimpleCoolingSchedule.h +++ b/trunk/paradiseo-mo/src/coolingSchedule/moSimpleCoolingSchedule.h @@ -39,65 +39,65 @@ /** * Classical cooling Schedule of the temperature in the simulated algorithm with initial and final temperature and a factor of decrease - * + * */ template< class EOT > class moSimpleCoolingSchedule : public moCoolingSchedule { public: - /** - * default constructor - * @param _initT initial temperature - * @param _alpha factor of decreasing - * @param _span number of iteration with equal temperature - * @param _finalT final temperature, threshold of the stopping criteria - */ - moSimpleCoolingSchedule(double _initT, double _alpha, unsigned _span, double _finalT) : initT(_initT), alpha(_alpha), span(_span), finalT(_finalT) {} + /** + * default constructor + * @param _initT initial temperature + * @param _alpha factor of decreasing + * @param _span number of iteration with equal temperature + * @param _finalT final temperature, threshold of the stopping criteria + */ + moSimpleCoolingSchedule(double _initT, double _alpha, unsigned _span, double _finalT) : initT(_initT), alpha(_alpha), span(_span), finalT(_finalT) {} - /** - * Initial temperature - * @param _solution initial solution - * @return the initial temperature - */ - virtual double init(EOT & _solution) { - // number of iteration with the same temperature - step = 0; + /** + * Initial temperature + * @param _solution initial solution + * @return the initial temperature + */ + virtual double init(EOT & _solution) { + // number of iteration with the same temperature + step = 0; - return initT; - } + return initT; + } - /** - * update the temperature by a factor - * @param _temp current temperature to update - */ - virtual void update(double& _temp) { - if (step >= span) { - _temp *= alpha; - step = 0; - } else - step++; - } + /** + * update the temperature by a factor + * @param _temp current temperature to update + */ + virtual void update(double& _temp) { + if (step >= span) { + _temp *= alpha; + step = 0; + } else + step++; + } - /** - * compare the temperature to the threshold - * @param _temp current temperature - * @return true if the current temperature is over the threshold (final temperature) - */ - virtual bool operator()(double _temp) { - return _temp > finalT; - } + /** + * compare the temperature to the threshold + * @param _temp current temperature + * @return true if the current temperature is over the threshold (final temperature) + */ + virtual bool operator()(double _temp) { + return _temp > finalT; + } private: - // initial temperature - double initT; - // coefficient of decrease - double alpha; - // maximum number of iterations at the same temperature - unsigned int span; - // threshold temperature - double finalT; - // number of steps with the same temperature - unsigned int step; + // initial temperature + double initT; + // coefficient of decrease + double alpha; + // maximum number of iterations at the same temperature + unsigned int span; + // threshold temperature + double finalT; + // number of steps with the same temperature + unsigned int step; }; diff --git a/trunk/paradiseo-mo/src/eval/moDummyEval.h b/trunk/paradiseo-mo/src/eval/moDummyEval.h index 67861990c..cb2a946b2 100644 --- a/trunk/paradiseo-mo/src/eval/moDummyEval.h +++ b/trunk/paradiseo-mo/src/eval/moDummyEval.h @@ -36,17 +36,17 @@ Contact: paradiseo-help@lists.gforge.inria.fr * Dummy Evaluation function */ template -class moDummyEval : public moEval{ +class moDummyEval : public moEval { public: typedef typename Neighbor::EOT EOT; typedef typename EOT::Fitness Fitness; /** - * NOTHING TO DO - * @param _sol a solution (unused) - * @param _n a neighbor (unused) - */ - void operator()(EOT& _sol, Neighbor& _n){} + * NOTHING TO DO + * @param _sol a solution (unused) + * @param _n a neighbor (unused) + */ + void operator()(EOT& _sol, Neighbor& _n) {} }; diff --git a/trunk/paradiseo-mo/src/eval/moEvalCounter.h b/trunk/paradiseo-mo/src/eval/moEvalCounter.h index 902c96749..e795f4384 100644 --- a/trunk/paradiseo-mo/src/eval/moEvalCounter.h +++ b/trunk/paradiseo-mo/src/eval/moEvalCounter.h @@ -33,7 +33,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include -/** +/** Counts the number of neighbor evaluations actually performed, thus checks first if it has to evaluate.. etc. */ @@ -41,25 +41,25 @@ template class moEvalCounter : public moEval, public eoValueParam { public: - typedef typename Neighbor::EOT EOT; - typedef typename EOT::Fitness Fitness; - - moEvalCounter(moEval& _eval, std::string _name = "Neighbor Eval. ") - : eoValueParam(0, _name), eval(_eval) {} - - /** - * Increase the number of neighbor evaluations and perform the evaluation - * - * @param _solution a solution - * @param _neighbor a neighbor - */ - void operator()(EOT& _solution, Neighbor& _neighbor) { - value()++; - eval(_solution, _neighbor); - } + typedef typename Neighbor::EOT EOT; + typedef typename EOT::Fitness Fitness; + + moEvalCounter(moEval& _eval, std::string _name = "Neighbor Eval. ") + : eoValueParam(0, _name), eval(_eval) {} + + /** + * Increase the number of neighbor evaluations and perform the evaluation + * + * @param _solution a solution + * @param _neighbor a neighbor + */ + void operator()(EOT& _solution, Neighbor& _neighbor) { + value()++; + eval(_solution, _neighbor); + } private: - moEval & eval; + moEval & eval; }; diff --git a/trunk/paradiseo-mo/src/explorer/moDummyExplorer.h b/trunk/paradiseo-mo/src/explorer/moDummyExplorer.h index c9a1e655d..623dfc8e6 100644 --- a/trunk/paradiseo-mo/src/explorer/moDummyExplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moDummyExplorer.h @@ -48,51 +48,55 @@ public: typedef typename Neighbor::EOT EOT; typedef typename EOT::Fitness Fitness ; - moDummyExplorer(): moNeighborhoodExplorer() { } + moDummyExplorer(): moNeighborhoodExplorer() { } /** * NOTHING TO DO * @param _solution a solution (unused) */ - void initParam (EOT& _solution) { } ; + void initParam (EOT& _solution) { } ; /** * NOTHING TO DO * @param _solution a solution (unused) */ - void updateParam (EOT& _solution) { } ; + void updateParam (EOT& _solution) { } ; /** * NOTHING TO DO * @param _solution a solution (unused) * @return always false */ - bool isContinue(EOT& _solution) { return false; } ; + bool isContinue(EOT& _solution) { + return false; + } ; /** * NOTHING TO DO * @param _solution a solution (unused) */ - void move(EOT& _solution) { } ; + void move(EOT& _solution) { } ; /** * NOTHING TO DO * @param _solution a solution (unused) * @return always false */ - virtual bool accept(EOT& _solution) { return false; } ; + virtual bool accept(EOT& _solution) { + return false; + } ; /** * NOTHING TO DO * @param _solution a solution (unused) */ - virtual void terminate(EOT& _solution) { } ; + virtual void terminate(EOT& _solution) { } ; /** * NOTHING TO DO * @param _solution a solution (unused) */ - void operator()(EOT & _solution) { } + void operator()(EOT & _solution) { } /** * Return the class id. diff --git a/trunk/paradiseo-mo/src/explorer/moILSexplorer.h b/trunk/paradiseo-mo/src/explorer/moILSexplorer.h index 520905a1f..3a787656d 100644 --- a/trunk/paradiseo-mo/src/explorer/moILSexplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moILSexplorer.h @@ -53,73 +53,73 @@ class moILSexplorer : public moNeighborhoodExplorer< moDummyNeighbor Neighborhood ; typedef typename Neighbor::EOT EOT; - typedef moDummyNeighbor dummyNeighbor; - typedef moDummyNeighborhood dummyNeighborhood; + typedef moDummyNeighbor dummyNeighbor; + typedef moDummyNeighborhood dummyNeighborhood; - /** - * Constructor - * @param _ls a local search - * @param _perturb a perturbation operator - * @param _acceptCrit a acceptance criteria - */ - moILSexplorer(moLocalSearch& _ls, moPerturbation& _perturb, moAcceptanceCriterion& _acceptCrit) : moNeighborhoodExplorer(), ls(_ls), perturb(_perturb), acceptCrit(_acceptCrit){ - firstIteration=true; + /** + * Constructor + * @param _ls a local search + * @param _perturb a perturbation operator + * @param _acceptCrit a acceptance criteria + */ + moILSexplorer(moLocalSearch& _ls, moPerturbation& _perturb, moAcceptanceCriterion& _acceptCrit) : moNeighborhoodExplorer(), ls(_ls), perturb(_perturb), acceptCrit(_acceptCrit) { + firstIteration=true; } - /** - * Destructor - */ - ~moILSexplorer(){ + /** + * Destructor + */ + ~moILSexplorer() { } - /** - * Init perturbation and acceptance criteria - * @param _solution the current solution - */ - virtual void initParam(EOT & _solution){ - firstIteration=true; - perturb.init(_solution); - acceptCrit.init(_solution); + /** + * Init perturbation and acceptance criteria + * @param _solution the current solution + */ + virtual void initParam(EOT & _solution) { + firstIteration=true; + perturb.init(_solution); + acceptCrit.init(_solution); }; - /** - * Update perturbation and acceptance criteria - * @param _solution the current solution - */ - virtual void updateParam(EOT & _solution){ - if((*this).moveApplied()){ - perturb.add(_solution,emptyNeighbor); - acceptCrit.add(_solution,emptyNeighbor); - } - perturb.update(_solution, emptyNeighbor); - acceptCrit.update(_solution, emptyNeighbor); + /** + * Update perturbation and acceptance criteria + * @param _solution the current solution + */ + virtual void updateParam(EOT & _solution) { + if ((*this).moveApplied()) { + perturb.add(_solution,emptyNeighbor); + acceptCrit.add(_solution,emptyNeighbor); + } + perturb.update(_solution, emptyNeighbor); + acceptCrit.update(_solution, emptyNeighbor); }; - /** - * terminate: NOTHING TO DO + /** + * terminate: NOTHING TO DO * @param _solution a solution (unused) - */ - virtual void terminate(EOT & _solution){}; + */ + virtual void terminate(EOT & _solution) {}; /** * Perturb and apply local search on a solution * @param _solution the solution */ - virtual void operator()(EOT & _solution){ - //copy the solution to perform new local search - current=_solution; + virtual void operator()(EOT & _solution) { + //copy the solution to perform new local search + current=_solution; - //perturb solution exept at the first iteration - if(!firstIteration){ - perturb(current); + //perturb solution exept at the first iteration + if (!firstIteration) { + perturb(current); - } - else - firstIteration=false; + } + else + firstIteration=false; - //apply the local search on the copy - ls(current); + //apply the local search on the copy + ls(current); }; @@ -129,7 +129,7 @@ public: * @return always true */ virtual bool isContinue(EOT & _solution) { - return true; + return true; }; /** @@ -137,7 +137,7 @@ public: * @param _solution the solution */ virtual void move(EOT & _solution) { - _solution=current; + _solution=current; }; /** @@ -146,7 +146,7 @@ public: * @return true if acceptance criteria is verified */ virtual bool accept(EOT & _solution) { - return acceptCrit(_solution, current); + return acceptCrit(_solution, current); }; /** @@ -154,12 +154,12 @@ public: * @return the class name as a std::string */ virtual std::string className() const { - return "moILSexplorer"; + return "moILSexplorer"; } private: //Usefull to use the momory of tabuSearch - Neighbor emptyNeighbor; + Neighbor emptyNeighbor; EOT current; moLocalSearch& ls; moPerturbation & perturb; diff --git a/trunk/paradiseo-mo/src/explorer/moNeutralHCexplorer.h b/trunk/paradiseo-mo/src/explorer/moNeutralHCexplorer.h index 6ecd91b88..3f2020e28 100644 --- a/trunk/paradiseo-mo/src/explorer/moNeutralHCexplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moNeutralHCexplorer.h @@ -70,7 +70,7 @@ public: moNeighborComparator& _neighborComparator, moSolNeighborComparator& _solNeighborComparator, unsigned _nbStep) : - moRandomBestHCexplorer(_neighborhood, _eval, _neighborComparator, _solNeighborComparator),nbStep(_nbStep) { + moRandomBestHCexplorer(_neighborhood, _eval, _neighborComparator, _solNeighborComparator),nbStep(_nbStep) { //Some cycle is possible with equals fitness solutions if the neighborhood is not random } @@ -85,7 +85,7 @@ public: * @param _solution the current solution */ virtual void initParam(EOT & _solution) { - moRandomBestHCexplorer::initParam(_solution); + moRandomBestHCexplorer::initParam(_solution); step = 0; }; @@ -95,7 +95,7 @@ public: * @param _solution the current solution */ virtual void updateParam(EOT & _solution) { - moRandomBestHCexplorer::updateParam(_solution); + moRandomBestHCexplorer::updateParam(_solution); step++; }; diff --git a/trunk/paradiseo-mo/src/explorer/moRandomBestHCexplorer.h b/trunk/paradiseo-mo/src/explorer/moRandomBestHCexplorer.h index 6dd6299ea..d6ef191ec 100644 --- a/trunk/paradiseo-mo/src/explorer/moRandomBestHCexplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moRandomBestHCexplorer.h @@ -43,7 +43,7 @@ #include /** - * Explorer for Hill-Climbing + * Explorer for Hill-Climbing * which choose randomly one of the best solution in the neighborhood at each iteration */ template< class Neighbor > @@ -64,9 +64,9 @@ public: * @param _solNeighborComparator solution vs neighbor comparator */ moRandomBestHCexplorer(Neighborhood& _neighborhood, - moEval& _eval, - moNeighborComparator& _neighborComparator, - moSolNeighborComparator& _solNeighborComparator) : + moEval& _eval, + moNeighborComparator& _neighborComparator, + moSolNeighborComparator& _solNeighborComparator) : moNeighborhoodExplorer(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) { diff --git a/trunk/paradiseo-mo/src/explorer/moRandomNeutralWalkExplorer.h b/trunk/paradiseo-mo/src/explorer/moRandomNeutralWalkExplorer.h index 410c5b1f8..f92940621 100644 --- a/trunk/paradiseo-mo/src/explorer/moRandomNeutralWalkExplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moRandomNeutralWalkExplorer.h @@ -63,7 +63,7 @@ public: * @param _nbStep maximum number of step to do */ moRandomNeutralWalkExplorer(Neighborhood& _neighborhood, - moEval& _eval, + moEval& _eval, moSolNeighborComparator& _solNeighborComparator, unsigned _nbStep): moNeighborhoodExplorer(_neighborhood, _eval), diff --git a/trunk/paradiseo-mo/src/explorer/moRandomSearchExplorer.h b/trunk/paradiseo-mo/src/explorer/moRandomSearchExplorer.h index 8520803e4..06276b658 100644 --- a/trunk/paradiseo-mo/src/explorer/moRandomSearchExplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moRandomSearchExplorer.h @@ -48,101 +48,101 @@ template< class Neighbor > class moRandomSearchExplorer : public moNeighborhoodExplorer { public: - typedef typename Neighbor::EOT EOT ; - typedef moNeighborhood Neighborhood ; - - using moNeighborhoodExplorer::neighborhood; - using moNeighborhoodExplorer::eval; - - /** - * Constructor - * @param _init the solution initializer, to explore at random the search space - * @param _fulleval the evaluation function - * @param _nbStep maximum number of step to do - */ - moRandomSearchExplorer(eoInit& _init, eoEvalFunc& _fulleval, unsigned _nbStep) : moNeighborhoodExplorer(), init(_init), fulleval(_fulleval), nbStep(_nbStep) { - // number of step done - step = 0; - } + typedef typename Neighbor::EOT EOT ; + typedef moNeighborhood Neighborhood ; + + using moNeighborhoodExplorer::neighborhood; + using moNeighborhoodExplorer::eval; + + /** + * Constructor + * @param _init the solution initializer, to explore at random the search space + * @param _fulleval the evaluation function + * @param _nbStep maximum number of step to do + */ + moRandomSearchExplorer(eoInit& _init, eoEvalFunc& _fulleval, unsigned _nbStep) : moNeighborhoodExplorer(), init(_init), fulleval(_fulleval), nbStep(_nbStep) { + // number of step done + step = 0; + } + + /** + * Destructor + */ + ~moRandomSearchExplorer() {} + + /** + * initialization of the number of step to be done + * @param _solution a solution (unused) + */ + virtual void initParam(EOT & _solution) { + step = 0; + }; + + /** + * increase the number of step + * @param _solution a solution (unused) + */ + virtual void updateParam(EOT & _solution) { + step++; + }; + + /** + * terminate: NOTHING TO DO + * @param _solution a solution (unused) + */ + virtual void terminate(EOT & _solution) {}; + + /** + * Explore the neighborhood with only one random solution + * we supposed that the first neighbor is uniformly selected in the neighborhood + * @param _solution + */ + virtual void operator()(EOT & _solution) { + //init the first neighbor + init(_solution); + + //eval the _solution moved with the neighbor and stock the result in the neighbor + fulleval(_solution); + }; + + /** + * continue if it is remainds some steps to do + * @param _solution the solution + * @return true there is some steps to do + */ + virtual bool isContinue(EOT & _solution) { + return (step < nbStep) ; + }; + + /** + * move the solution with the best neighbor + * @param _solution the solution to move + */ + virtual void move(EOT & _solution) { + // the solution is already move. So nothing to do ! + }; + + /** + * accept test : always accept + * @param _solution the solution + * @return true if the best neighbor ameliorate the fitness + */ + virtual bool accept(EOT & _solution) { + return true; + }; - /** - * Destructor - */ - ~moRandomSearchExplorer() {} - - /** - * initialization of the number of step to be done - * @param _solution a solution (unused) - */ - virtual void initParam(EOT & _solution) { - step = 0; - }; - - /** - * increase the number of step - * @param _solution a solution (unused) - */ - virtual void updateParam(EOT & _solution) { - step++; - }; - - /** - * terminate: NOTHING TO DO - * @param _solution a solution (unused) - */ - virtual void terminate(EOT & _solution) {}; - - /** - * Explore the neighborhood with only one random solution - * we supposed that the first neighbor is uniformly selected in the neighborhood - * @param _solution - */ - virtual void operator()(EOT & _solution) { - //init the first neighbor - init(_solution); - - //eval the _solution moved with the neighbor and stock the result in the neighbor - fulleval(_solution); - }; - - /** - * continue if it is remainds some steps to do - * @param _solution the solution - * @return true there is some steps to do - */ - virtual bool isContinue(EOT & _solution) { - return (step < nbStep) ; - }; - - /** - * move the solution with the best neighbor - * @param _solution the solution to move - */ - virtual void move(EOT & _solution) { - // the solution is already move. So nothing to do ! - }; - - /** - * accept test : always accept - * @param _solution the solution - * @return true if the best neighbor ameliorate the fitness - */ - virtual bool accept(EOT & _solution) { - return true; - }; - private: - // initialization method to explore at random the search space - eoInit & init; + // initialization method to explore at random the search space + eoInit & init; - // the full eval function - eoEvalFunc & fulleval; + // the full eval function + eoEvalFunc & fulleval; - // current number of step - unsigned int step; - - // maximum number of steps to do - unsigned int nbStep; + // current number of step + unsigned int step; + + // maximum number of steps to do + unsigned int nbStep; }; diff --git a/trunk/paradiseo-mo/src/explorer/moSAexplorer.h b/trunk/paradiseo-mo/src/explorer/moSAexplorer.h index 479be2355..56ca6834f 100644 --- a/trunk/paradiseo-mo/src/explorer/moSAexplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moSAexplorer.h @@ -48,7 +48,7 @@ * Explorer for the Simulated Annealing * Only the symetric case is considered when Q(x,y) = Q(y,x) * Fitness must be > 0 - * + * */ template< class Neighbor > class moSAexplorer : public moNeighborhoodExplorer @@ -67,7 +67,7 @@ public: * @param _solNeighborComparator a solution vs neighbor comparator * @param _coolingSchedule the cooling schedule */ - moSAexplorer(Neighborhood& _neighborhood, moEval& _eval, moSolNeighborComparator& _solNeighborComparator, moCoolingSchedule& _coolingSchedule) : moNeighborhoodExplorer(_neighborhood, _eval), solNeighborComparator(_solNeighborComparator), coolingSchedule(_coolingSchedule) { + moSAexplorer(Neighborhood& _neighborhood, moEval& _eval, moSolNeighborComparator& _solNeighborComparator, moCoolingSchedule& _coolingSchedule) : moNeighborhoodExplorer(_neighborhood, _eval), solNeighborComparator(_solNeighborComparator), coolingSchedule(_coolingSchedule) { isAccept = false; if (!neighborhood.isRandom()) { @@ -83,11 +83,11 @@ public: /** * initialization of the initial temperature - * @param _solution the solution + * @param _solution the solution */ virtual void initParam(EOT & _solution) { - temperature = coolingSchedule.init(_solution); - isAccept = true; + temperature = coolingSchedule.init(_solution); + isAccept = true; }; /** @@ -95,7 +95,7 @@ public: * @param _solution the solution (unused here) */ virtual void updateParam(EOT & _solution) { - coolingSchedule.update(temperature); + coolingSchedule.update(temperature); }; /** @@ -129,7 +129,7 @@ public: * @return true if the criteria from the cooling schedule is true */ virtual bool isContinue(EOT & _solution) { - return coolingSchedule(temperature); + return coolingSchedule(temperature); }; /** @@ -152,16 +152,16 @@ public: double alpha=0.0; double fit1, fit2; if (neighborhood.hasNeighbor(_solution)) { - if (solNeighborComparator(_solution, current)) // accept if the current neighbor is better than the solution + if (solNeighborComparator(_solution, current)) // accept if the current neighbor is better than the solution isAccept = true; else { - fit1=(double)current.fitness(); - fit2=(double)_solution.fitness(); - if (fit1 < fit2) // this is a maximization - alpha = exp((fit1 - fit2) / temperature ); - else // this is a minimization - alpha = exp((fit2 - fit1) / temperature ); - isAccept = (rng.uniform() < alpha) ; + fit1=(double)current.fitness(); + fit2=(double)_solution.fitness(); + if (fit1 < fit2) // this is a maximization + alpha = exp((fit1 - fit2) / temperature ); + else // this is a minimization + alpha = exp((fit2 - fit1) / temperature ); + isAccept = (rng.uniform() < alpha) ; } } return isAccept; @@ -171,8 +171,8 @@ public: * Getter * @return the temperature */ - double getTemperature(){ - return temperature; + double getTemperature() { + return temperature; } private: diff --git a/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h b/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h index 5efe89fde..1887d1fe0 100644 --- a/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moVNSexplorer.h @@ -41,92 +41,92 @@ template< class EOT > class moVNSexplorer : public moNeighborhoodExplorer< moNeighborhood< moNeighbor > > { public: - typedef typename EOT::Fitness Fitness ; - typedef moNeighbor Neighbor ; - typedef moNeighborhood Neighborhood ; + typedef typename EOT::Fitness Fitness ; + typedef moNeighbor Neighbor ; + typedef moNeighborhood Neighborhood ; - using moNeighborhoodExplorer::neighborhood; - using moNeighborhoodExplorer::eval; + using moNeighborhoodExplorer::neighborhood; + using moNeighborhoodExplorer::eval; - /** - * Constructor - * @param _neighborhood the neighborhood - * @param _eval the evaluation function - * @param _neighborComparator a neighbor comparator - * @param _solNeighborComparator solution vs neighbor comparator - */ - moVNSexplorer(Neighborhood& _neighborhood, moEval& _eval, moNeighborComparator& _neighborComparator, moSolNeighborComparator& _solNeighborComparator) : moNeighborhoodExplorer(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) { - } + /** + * Constructor + * @param _neighborhood the neighborhood + * @param _eval the evaluation function + * @param _neighborComparator a neighbor comparator + * @param _solNeighborComparator solution vs neighbor comparator + */ + moVNSexplorer(Neighborhood& _neighborhood, moEval& _eval, moNeighborComparator& _neighborComparator, moSolNeighborComparator& _solNeighborComparator) : moNeighborhoodExplorer(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) { + } + + /** + * Destructor + */ + ~moVNSexplorer() { + } + + /** + * initParam: NOTHING TO DO + */ + virtual void initParam(EOT & solution) {}; + + /** + * updateParam: NOTHING TO DO + */ + virtual void updateParam(EOT & solution) {}; + + /** + * terminate: NOTHING TO DO + */ + virtual void terminate(EOT & solution) {}; + + /** + * Explore the neighborhood of a solution + * @param _solution + */ + virtual void operator()(EOT & _solution) { + }; + + /** + * continue if a move is accepted + * @param _solution the solution + * @return true if an ameliorated neighbor was be found + */ + virtual bool isContinue(EOT & _solution) { + return isAccept ; + }; + + /** + * move the solution with the best neighbor + * @param _solution the solution to move + */ + virtual void move(EOT & _solution) { + //move the solution + (*best).move(_solution); + //update its fitness + _solution.fitness((*best).fitness()); + }; + + /** + * accept test if an amelirated neighbor was be found + * @param _solution the solution + * @return true if the best neighbor ameliorate the fitness + */ + virtual bool accept(EOT & _solution) { + }; + + /** + * Return the class id. + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moVNSexplorer"; + } - /** - * Destructor - */ - ~moVNSexplorer() { - } - - /** - * initParam: NOTHING TO DO - */ - virtual void initParam(EOT & solution) {}; - - /** - * updateParam: NOTHING TO DO - */ - virtual void updateParam(EOT & solution) {}; - - /** - * terminate: NOTHING TO DO - */ - virtual void terminate(EOT & solution) {}; - - /** - * Explore the neighborhood of a solution - * @param _solution - */ - virtual void operator()(EOT & _solution) { - }; - - /** - * continue if a move is accepted - * @param _solution the solution - * @return true if an ameliorated neighbor was be found - */ - virtual bool isContinue(EOT & _solution) { - return isAccept ; - }; - - /** - * move the solution with the best neighbor - * @param _solution the solution to move - */ - virtual void move(EOT & _solution) { - //move the solution - (*best).move(_solution); - //update its fitness - _solution.fitness((*best).fitness()); - }; - - /** - * accept test if an amelirated neighbor was be found - * @param _solution the solution - * @return true if the best neighbor ameliorate the fitness - */ - virtual bool accept(EOT & _solution) { - }; - - /** - * Return the class id. - * @return the class name as a std::string - */ - virtual std::string className() const { - return "moVNSexplorer"; - } - private: - // comparator betwenn solution and neighbor or between neighbors - moNeighborComparator& neighborComparator; - moSolNeighborComparator& solNeighborComparator; - + // comparator betwenn solution and neighbor or between neighbors + moNeighborComparator& neighborComparator; + moSolNeighborComparator& solNeighborComparator; + }; diff --git a/trunk/paradiseo-mo/src/memory/moCountMoveMemory.h b/trunk/paradiseo-mo/src/memory/moCountMoveMemory.h index a5417e1ed..cfca0eee8 100644 --- a/trunk/paradiseo-mo/src/memory/moCountMoveMemory.h +++ b/trunk/paradiseo-mo/src/memory/moCountMoveMemory.h @@ -36,19 +36,19 @@ Contact: paradiseo-help@lists.gforge.inria.fr * Count the number of move, noMove and the number of successive stagnation since the last Move */ template< class Neighbor > -class moCountMoveMemory : virtual public moMemory{ +class moCountMoveMemory : virtual public moMemory { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; /** * Init all the counters * @param _sol unused solution */ void init(EOT & _sol) { - nbMove=0; - nbNoMove=0; - counter=0; + nbMove=0; + nbNoMove=0; + counter=0; } /** @@ -56,8 +56,8 @@ public: * @param _neighbor unused neighbor */ void add(EOT & _sol, Neighbor & _neighbor) { - nbMove++; - counter=0; + nbMove++; + counter=0; } /** @@ -65,48 +65,48 @@ public: * @param _neighbor unused neighbor */ void update(EOT & _sol, Neighbor & _neighbor) { - nbNoMove++; - counter++; + nbNoMove++; + counter++; } /** * ClearMemory : Reinit all the counters */ void clearMemory() { - nbMove=0; - nbNoMove=0; - counter=0; + nbMove=0; + nbNoMove=0; + counter=0; } /** * Getter of the number of move * @return the counter */ - unsigned int getNbMove(){ - return nbMove; + unsigned int getNbMove() { + return nbMove; } /** * Getter of the number of no move * @return the counter */ - unsigned int getNbNoMove(){ - return nbNoMove; + unsigned int getNbNoMove() { + return nbNoMove; } /** * Getter of the number of successive stagnation since the last Move * @return the counter */ - unsigned int getCounter(){ - return counter; + unsigned int getCounter() { + return counter; } /** * Init counter */ - void initCounter(){ - counter=0; + void initCounter() { + counter=0; } private: diff --git a/trunk/paradiseo-mo/src/memory/moDiversification.h b/trunk/paradiseo-mo/src/memory/moDiversification.h index af0292f82..5df67a3fe 100644 --- a/trunk/paradiseo-mo/src/memory/moDiversification.h +++ b/trunk/paradiseo-mo/src/memory/moDiversification.h @@ -37,6 +37,6 @@ Contact: paradiseo-help@lists.gforge.inria.fr * Abstract class for diversification strategy */ template< class Neighbor > -class moDiversification : virtual public moMemory, public eoUF{}; +class moDiversification : virtual public moMemory, public eoUF {}; #endif diff --git a/trunk/paradiseo-mo/src/memory/moDummyMemory.h b/trunk/paradiseo-mo/src/memory/moDummyMemory.h index 40b6c8918..c927a30f0 100644 --- a/trunk/paradiseo-mo/src/memory/moDummyMemory.h +++ b/trunk/paradiseo-mo/src/memory/moDummyMemory.h @@ -36,10 +36,10 @@ Contact: paradiseo-help@lists.gforge.inria.fr * Dummy memory to make an empty memory */ template< class Neighbor > -class moDummyMemory : virtual public moMemory{ +class moDummyMemory : virtual public moMemory { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; /** * Init : NOTHIING TO DO diff --git a/trunk/paradiseo-mo/src/memory/moIntensification.h b/trunk/paradiseo-mo/src/memory/moIntensification.h index f5257e284..44d6c1bc3 100644 --- a/trunk/paradiseo-mo/src/memory/moIntensification.h +++ b/trunk/paradiseo-mo/src/memory/moIntensification.h @@ -37,6 +37,6 @@ Contact: paradiseo-help@lists.gforge.inria.fr * Abstract class for intensification strategy */ template< class Neighbor > -class moIntensification : virtual public moMemory, public eoUF{}; +class moIntensification : virtual public moMemory, public eoUF {}; #endif diff --git a/trunk/paradiseo-mo/src/memory/moMonOpDiversification.h b/trunk/paradiseo-mo/src/memory/moMonOpDiversification.h index d4ff55537..317dbd5e8 100644 --- a/trunk/paradiseo-mo/src/memory/moMonOpDiversification.h +++ b/trunk/paradiseo-mo/src/memory/moMonOpDiversification.h @@ -45,28 +45,28 @@ class moMonOpDiversification : public moDiversification, public moDumm public: typedef typename Neighbor::EOT EOT; - /** - * Default Constructor - * @param _monOp an eoMonOp (diversification operator) - * @param _fullEval a full evaluation function - */ - moMonOpDiversification(eoMonOp& _monOp, eoEvalFunc& _fullEval):monOp(_monOp), fullEval(_fullEval){} + /** + * Default Constructor + * @param _monOp an eoMonOp (diversification operator) + * @param _fullEval a full evaluation function + */ + moMonOpDiversification(eoMonOp& _monOp, eoEvalFunc& _fullEval):monOp(_monOp), fullEval(_fullEval) {} - /** - * Apply monOp on the solution - * @param _solution to diversify - * @return value of monOp - */ - bool operator()(EOT& _solution){ - bool res = monOp(_solution); - fullEval(_solution); - return res; - } + /** + * Apply monOp on the solution + * @param _solution to diversify + * @return value of monOp + */ + bool operator()(EOT& _solution) { + bool res = monOp(_solution); + fullEval(_solution); + return res; + } private: - /** monOp */ - eoMonOp& monOp; - eoEvalFunc& fullEval; + /** monOp */ + eoMonOp& monOp; + eoEvalFunc& fullEval; }; #endif diff --git a/trunk/paradiseo-mo/src/memory/moNeighborVectorTabuList.h b/trunk/paradiseo-mo/src/memory/moNeighborVectorTabuList.h index 5da01ee17..3d0bfbf7c 100644 --- a/trunk/paradiseo-mo/src/memory/moNeighborVectorTabuList.h +++ b/trunk/paradiseo-mo/src/memory/moNeighborVectorTabuList.h @@ -88,10 +88,10 @@ public: * @param _neighbor the current neighbor (unused) */ virtual void update(EOT & _sol, Neighbor & _neighbor) { - if(howlong > 0) - for (unsigned int i=0; i 0) - tabuList[i].second--; + if (howlong > 0) + for (unsigned int i=0; i 0) + tabuList[i].second--; } /** diff --git a/trunk/paradiseo-mo/src/memory/moSolVectorTabuList.h b/trunk/paradiseo-mo/src/memory/moSolVectorTabuList.h index 080d35c5e..e6b034f82 100644 --- a/trunk/paradiseo-mo/src/memory/moSolVectorTabuList.h +++ b/trunk/paradiseo-mo/src/memory/moSolVectorTabuList.h @@ -88,10 +88,10 @@ public: * @param _neighbor the current neighbor (unused) */ virtual void update(EOT & _sol, Neighbor & _neighbor) { - if(howlong > 0) - for (unsigned int i=0; i 0) - tabuList[i].second--; + if (howlong > 0) + for (unsigned int i=0; i 0) + tabuList[i].second--; } /** diff --git a/trunk/paradiseo-mo/src/neighborhood/moBackwardVariableNeighborhood.h b/trunk/paradiseo-mo/src/neighborhood/moBackwardVariableNeighborhood.h index 5c8102467..397246ea4 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moBackwardVariableNeighborhood.h +++ b/trunk/paradiseo-mo/src/neighborhood/moBackwardVariableNeighborhood.h @@ -39,7 +39,7 @@ template< class EOT > class moBackwardVariableNeighborhood : public moVariableNeighborhood { public: - typedef moNeighbor Neighbor; + typedef moNeighbor Neighbor; using moVariableNeighborhood::currentNH; using moVariableNeighborhood::neighborhoodVector; @@ -63,21 +63,21 @@ public: * @return true if there is some neighborhood to explore */ virtual bool contNeighborhood() { - return (currentNH > 0); + return (currentNH > 0); } /** * put the current neighborhood on the last one */ virtual void initNeighborhood() { - currentNH = neighborhoodVector.size() - 1; + currentNH = neighborhoodVector.size() - 1; } /** * put the current neighborhood on the next one */ virtual void nextNeighborhood() { - currentNH--; + currentNH--; } }; diff --git a/trunk/paradiseo-mo/src/neighborhood/moDummyNeighbor.h b/trunk/paradiseo-mo/src/neighborhood/moDummyNeighbor.h index 8e20113d0..628cf285a 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moDummyNeighbor.h +++ b/trunk/paradiseo-mo/src/neighborhood/moDummyNeighbor.h @@ -36,13 +36,13 @@ Contact: paradiseo-help@lists.gforge.inria.fr * Dummy Neighborhood */ template< class EOT > -class moDummyNeighbor : public moNeighbor< EOT >{ +class moDummyNeighbor : public moNeighbor< EOT > { public: /** * NOTHING TO DO * @param _solution the related solution */ - virtual void move(EOT& _solution){} + virtual void move(EOT& _solution) {} }; #endif diff --git a/trunk/paradiseo-mo/src/neighborhood/moDummyNeighborhood.h b/trunk/paradiseo-mo/src/neighborhood/moDummyNeighborhood.h index 824f8e7ea..b06cfa17c 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moDummyNeighborhood.h +++ b/trunk/paradiseo-mo/src/neighborhood/moDummyNeighborhood.h @@ -37,7 +37,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr * Dummy Neighborhood */ template< class Neighbor > -class moDummyNeighborhood : public moNeighborhood{ +class moDummyNeighborhood : public moNeighborhood { public: typedef typename Neighbor::EOT EOT; @@ -46,8 +46,8 @@ public: * @param _solution a solution (unused) * @return always false */ - virtual bool hasNeighbor(EOT & _solution){ - return false; + virtual bool hasNeighbor(EOT & _solution) { + return false; } /** @@ -55,22 +55,22 @@ public: * @param _solution a solution (unused) * @param _current a neighbor (unused) */ - virtual void init(EOT & _solution, Neighbor & _current){} + virtual void init(EOT & _solution, Neighbor & _current) {} /** * NOTHING TO DO * @param _solution a solution (unused) * @param _current a neighbor (unused) */ - virtual void next(EOT & _solution, Neighbor & _current){} + virtual void next(EOT & _solution, Neighbor & _current) {} /** * NOTHING TO DO * @param _solution a solution (unused) * @return always false */ - virtual bool cont(EOT & _solution){ - return false; + virtual bool cont(EOT & _solution) { + return false; } }; diff --git a/trunk/paradiseo-mo/src/neighborhood/moForwardVariableNeighborhood.h b/trunk/paradiseo-mo/src/neighborhood/moForwardVariableNeighborhood.h index d9e5f7e50..449999208 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moForwardVariableNeighborhood.h +++ b/trunk/paradiseo-mo/src/neighborhood/moForwardVariableNeighborhood.h @@ -40,7 +40,7 @@ class moForwardVariableNeighborhood : public moVariableNeighborhood { public: - typedef moNeighbor Neighbor; + typedef moNeighbor Neighbor; using moVariableNeighborhood::currentNH; using moVariableNeighborhood::neighborhoodVector; @@ -64,21 +64,21 @@ public: * @return true if there is some neighborhood to explore */ virtual bool contNeighborhood() { - return (currentNH < neighborhoodVector.size() - 1); + return (currentNH < neighborhoodVector.size() - 1); } /** * put the current neighborhood on the first one */ virtual void initNeighborhood() { - currentNH = 0; + currentNH = 0; } /** * put the current neighborhood on the next one */ virtual void nextNeighborhood() { - currentNH++; + currentNH++; } }; diff --git a/trunk/paradiseo-mo/src/neighborhood/moIndexNeighbor.h b/trunk/paradiseo-mo/src/neighborhood/moIndexNeighbor.h index 7957f2112..0603c00c1 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moIndexNeighbor.h +++ b/trunk/paradiseo-mo/src/neighborhood/moIndexNeighbor.h @@ -98,8 +98,8 @@ public: * @param _neighbor a neighbor * @return if _neighbor and this one are equals */ - virtual bool equals(moIndexNeighbor& _neighbor){ - return (key==_neighbor.index()); + virtual bool equals(moIndexNeighbor& _neighbor) { + return (key==_neighbor.index()); } protected: diff --git a/trunk/paradiseo-mo/src/neighborhood/moNeighbor.h b/trunk/paradiseo-mo/src/neighborhood/moNeighbor.h index f2d95ee8a..c097a7e5f 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moNeighbor.h +++ b/trunk/paradiseo-mo/src/neighborhood/moNeighbor.h @@ -107,8 +107,8 @@ public: * @param _neighbor a neighbor * @return if _neighbor and this one are equals */ - virtual bool equals(moNeighbor& _neighbor){ - return false; + virtual bool equals(moNeighbor& _neighbor) { + return false; } /** diff --git a/trunk/paradiseo-mo/src/neighborhood/moRndNeighborhood.h b/trunk/paradiseo-mo/src/neighborhood/moRndNeighborhood.h index 52ad20d4c..9c7ec2d22 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moRndNeighborhood.h +++ b/trunk/paradiseo-mo/src/neighborhood/moRndNeighborhood.h @@ -40,9 +40,9 @@ class moRndNeighborhood : virtual public moNeighborhood { public: - /** - * @return true - */ + /** + * @return true + */ bool isRandom() { return true; } diff --git a/trunk/paradiseo-mo/src/neighborhood/moRndVariableNeighborhood.h b/trunk/paradiseo-mo/src/neighborhood/moRndVariableNeighborhood.h index e0c32050e..8b7421a1e 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moRndVariableNeighborhood.h +++ b/trunk/paradiseo-mo/src/neighborhood/moRndVariableNeighborhood.h @@ -40,7 +40,7 @@ template< class EOT, class Fitness > class moRndVariableNeighborhood : public moVariableNeighborhood { public: - typedef moNeighbor Neighbor; + typedef moNeighbor Neighbor; using moVariableNeighborhood::currentNH; using moVariableNeighborhood::neighborhoodVector; @@ -50,7 +50,7 @@ public: * @param _firstNH first neighborhood in the vector */ moRndVariableNeighborhood(moNeighborhood& _firstNH) : moVariableNeighborhood(_firstNH) { - indexVector.push_back(0); + indexVector.push_back(0); } /** @@ -58,8 +58,8 @@ public: * @param _nh the neighborhood to add at the end of the vector of neighborhood */ virtual void add(moNeighborhood& _nh) { - neighborhoodVector.push_back(_nh); - indexVector.push_back(indexVector.size()); + neighborhoodVector.push_back(_nh); + indexVector.push_back(indexVector.size()); } @@ -76,24 +76,24 @@ public: * @return true if there is some neighborhood to explore */ virtual bool contNeighborhood() { - return (index < neighborhoodVector.size() - 1); + return (index < neighborhoodVector.size() - 1); } /** * put the current neighborhood on the first one */ virtual void initNeighborhood() { - std::random_shuffle(indexVector.begin(), indexVector.end()); - index = 0; - currentNH = indexVector[index]; + std::random_shuffle(indexVector.begin(), indexVector.end()); + index = 0; + currentNH = indexVector[index]; } /** * put the current neighborhood on the next one */ virtual void nextNeighborhood() { - index++; - currentNH = indexVector[index]; + index++; + currentNH = indexVector[index]; } private: diff --git a/trunk/paradiseo-mo/src/neighborhood/moVariableNeighborhood.h b/trunk/paradiseo-mo/src/neighborhood/moVariableNeighborhood.h index bf4ef2692..ac07af8b0 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moVariableNeighborhood.h +++ b/trunk/paradiseo-mo/src/neighborhood/moVariableNeighborhood.h @@ -43,15 +43,15 @@ class moVariableNeighborhood : public moNeighborhood > { public: - typedef moNeighbor Neighbor; + typedef moNeighbor Neighbor; /** * Construction of at least one neighborhood * @param _firstNH first neighborhood in the vector */ moVariableNeighborhood(moNeighborhood& _firstNH) { - neighborhoodVector.push_back(&_firstNH); - // the current neighborhood - currentNH = 0; + neighborhoodVector.push_back(&_firstNH); + // the current neighborhood + currentNH = 0; } /** @@ -67,7 +67,7 @@ public: * @return if _solution has a Neighbor in the current neighborhood */ virtual bool hasNeighbor(EOT & _solution) { - return neighborhoodVector[currentNH]->hasNeighbor(_solution); + return neighborhoodVector[currentNH]->hasNeighbor(_solution); } /** @@ -76,7 +76,7 @@ public: * @param _current the first neighbor in the current neighborhood */ virtual void init(EOT & _solution, Neighbor & _current) { - neighborhoodVector[currentNH]->init(_solution, _current); + neighborhoodVector[currentNH]->init(_solution, _current); } /** @@ -85,7 +85,7 @@ public: * @param _current the next neighbor in the current neighborhood */ virtual void next(EOT & _solution, Neighbor & _current) { - neighborhoodVector[currentNH]->next(_solution, _current); + neighborhoodVector[currentNH]->next(_solution, _current); } /** @@ -94,7 +94,7 @@ public: * @return if there is still a neighbor not explored in the current neighborhood */ virtual bool cont(EOT & _solution) { - return neighborhoodVector[currentNH]->cont(_solution); + return neighborhoodVector[currentNH]->cont(_solution); } /** @@ -110,7 +110,7 @@ public: * @param _nh the neighborhood to add at the end of the vector of neighborhood */ virtual void add(moNeighborhood& _nh) { - neighborhoodVector.push_back(&_nh); + neighborhoodVector.push_back(&_nh); } /** diff --git a/trunk/paradiseo-mo/src/perturb/moLocalSearchInit.h b/trunk/paradiseo-mo/src/perturb/moLocalSearchInit.h index 333237e08..615b47e4a 100644 --- a/trunk/paradiseo-mo/src/perturb/moLocalSearchInit.h +++ b/trunk/paradiseo-mo/src/perturb/moLocalSearchInit.h @@ -39,28 +39,28 @@ Contact: paradiseo-help@lists.gforge.inria.fr template< class Neighbor > class moLocalSearchInit : public eoInit { public: - typedef typename Neighbor::EOT EOT; - - /** - * Default Constructor - * @param _init initialization of the solution before the local search - * @param _ls the local search to apply to the solution - */ - moLocalSearchInit(eoInit& _init, moLocalSearch& _ls) : init(_init), ls(_ls) { - } - - /** - * Apply the local search on the solution - * @param _solution to perturb - */ - void operator()(EOT& _solution){ - init(_solution); - ls(_solution); - } + typedef typename Neighbor::EOT EOT; + + /** + * Default Constructor + * @param _init initialization of the solution before the local search + * @param _ls the local search to apply to the solution + */ + moLocalSearchInit(eoInit& _init, moLocalSearch& _ls) : init(_init), ls(_ls) { + } + + /** + * Apply the local search on the solution + * @param _solution to perturb + */ + void operator()(EOT& _solution) { + init(_solution); + ls(_solution); + } private: - eoInit& init; - moLocalSearch & ls; + eoInit& init; + moLocalSearch & ls; }; #endif diff --git a/trunk/paradiseo-mo/src/perturb/moMonOpPerturb.h b/trunk/paradiseo-mo/src/perturb/moMonOpPerturb.h index 8afdd7735..bce407d71 100644 --- a/trunk/paradiseo-mo/src/perturb/moMonOpPerturb.h +++ b/trunk/paradiseo-mo/src/perturb/moMonOpPerturb.h @@ -42,30 +42,30 @@ template< class Neighbor > class moMonOpPerturb : public moPerturbation, public moDummyMemory { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; - /** - * Default Constructor - * @param _monOp an eoMonOp (pertubation operator) - * @param _fullEval a full evaluation function - */ - moMonOpPerturb(eoMonOp& _monOp, eoEvalFunc& _fullEval):monOp(_monOp), fullEval(_fullEval){} + /** + * Default Constructor + * @param _monOp an eoMonOp (pertubation operator) + * @param _fullEval a full evaluation function + */ + moMonOpPerturb(eoMonOp& _monOp, eoEvalFunc& _fullEval):monOp(_monOp), fullEval(_fullEval) {} - /** - * Apply monOp on the solution - * @param _solution to perturb - * @return value of monOp - */ - bool operator()(EOT& _solution){ - bool res = monOp(_solution); - fullEval(_solution); - return res; - } + /** + * Apply monOp on the solution + * @param _solution to perturb + * @return value of monOp + */ + bool operator()(EOT& _solution) { + bool res = monOp(_solution); + fullEval(_solution); + return res; + } private: - /** monOp */ - eoMonOp& monOp; - eoEvalFunc& fullEval; + /** monOp */ + eoMonOp& monOp; + eoEvalFunc& fullEval; }; #endif diff --git a/trunk/paradiseo-mo/src/perturb/moNeighborhoodPerturb.h b/trunk/paradiseo-mo/src/perturb/moNeighborhoodPerturb.h index 88b946a2f..334b60994 100644 --- a/trunk/paradiseo-mo/src/perturb/moNeighborhoodPerturb.h +++ b/trunk/paradiseo-mo/src/perturb/moNeighborhoodPerturb.h @@ -38,40 +38,40 @@ Contact: paradiseo-help@lists.gforge.inria.fr * Neighborhood Perturbation: explore the neighborhood to perturb the solution (the neighborhood could be different as the one used in the Local Search) */ template< class Neighbor, class OtherNeighbor > -class moNeighborhoodPerturb : public moPerturbation{ +class moNeighborhoodPerturb : public moPerturbation { public: - typedef typename Neighbor::EOT EOT; - typedef moNeighborhood OtherNH; + typedef typename Neighbor::EOT EOT; + typedef moNeighborhood OtherNH; - /** - * Default Constructor - * @param _otherNeighborhood a neighborhood - * @param _eval an Evaluation Function - */ - moNeighborhoodPerturb(OtherNH& _otherNeighborhood, moEval& _eval): otherNeighborhood(_otherNeighborhood), eval(_eval){} + /** + * Default Constructor + * @param _otherNeighborhood a neighborhood + * @param _eval an Evaluation Function + */ + moNeighborhoodPerturb(OtherNH& _otherNeighborhood, moEval& _eval): otherNeighborhood(_otherNeighborhood), eval(_eval) {} - /** - * Apply move on the solution - * @param _solution the current solution - * @return true - */ - virtual bool operator()(EOT& _solution){ - if(otherNeighborhood.hasNeighbor(_solution)){ - eval(_solution, current); - current.move(_solution); - _solution.fitness(current.fitness()); - } - return true; - } + /** + * Apply move on the solution + * @param _solution the current solution + * @return true + */ + virtual bool operator()(EOT& _solution) { + if (otherNeighborhood.hasNeighbor(_solution)) { + eval(_solution, current); + current.move(_solution); + _solution.fitness(current.fitness()); + } + return true; + } /** * Init the neighborhood * @param _sol the current solution */ - virtual void init(EOT & _sol){ - if(otherNeighborhood.hasNeighbor(_sol)) - otherNeighborhood.init(_sol, current); + virtual void init(EOT & _sol) { + if (otherNeighborhood.hasNeighbor(_sol)) + otherNeighborhood.init(_sol, current); } /** @@ -79,8 +79,8 @@ public: * @param _sol the current solution * @param _neighbor unused neighbor (always empty) */ - virtual void add(EOT & _sol, Neighbor & _neighbor){ - (*this).init(_sol); + virtual void add(EOT & _sol, Neighbor & _neighbor) { + (*this).init(_sol); } /** @@ -88,22 +88,22 @@ public: * @param _sol the current solution * @param _neighbor unused neighbor (always empty) */ - virtual void update(EOT & _sol, Neighbor & _neighbor){ - if(otherNeighborhood.cont(_sol)) - otherNeighborhood.next(_sol, current); - else - (*this).init(_sol); + virtual void update(EOT & _sol, Neighbor & _neighbor) { + if (otherNeighborhood.cont(_sol)) + otherNeighborhood.next(_sol, current); + else + (*this).init(_sol); } /** * NOTHING TO DO */ - virtual void clearMemory(){} + virtual void clearMemory() {} private: - OtherNH& otherNeighborhood; - moEval& eval; - OtherNeighbor current; + OtherNH& otherNeighborhood; + moEval& eval; + OtherNeighbor current; }; #endif diff --git a/trunk/paradiseo-mo/src/perturb/moRestartPerturb.h b/trunk/paradiseo-mo/src/perturb/moRestartPerturb.h index 5ab71e1f1..d2705b31d 100644 --- a/trunk/paradiseo-mo/src/perturb/moRestartPerturb.h +++ b/trunk/paradiseo-mo/src/perturb/moRestartPerturb.h @@ -43,34 +43,34 @@ template< class Neighbor > class moRestartPerturb : public moPerturbation, public moCountMoveMemory { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; - /** - * Default Constructor - * @param _initializer an initializer of solution - * @param _fullEval a full evaluation function - * @param _threshold maximum number of iteration with no improvement - */ - moRestartPerturb(eoInit& _initializer, eoEvalFunc& _fullEval, unsigned int _threshold):initializer(_initializer), fullEval(_fullEval), threshold(_threshold) {} + /** + * Default Constructor + * @param _initializer an initializer of solution + * @param _fullEval a full evaluation function + * @param _threshold maximum number of iteration with no improvement + */ + moRestartPerturb(eoInit& _initializer, eoEvalFunc& _fullEval, unsigned int _threshold):initializer(_initializer), fullEval(_fullEval), threshold(_threshold) {} - /** - * Apply restart when necessary - * @param _solution to restart - * @return true - */ - bool operator()(EOT& _solution){ - if((*this).getCounter()>= threshold){ - initializer(_solution); - fullEval(_solution); - (*this).initCounter(); - } - return true; - } + /** + * Apply restart when necessary + * @param _solution to restart + * @return true + */ + bool operator()(EOT& _solution) { + if ((*this).getCounter()>= threshold) { + initializer(_solution); + fullEval(_solution); + (*this).initCounter(); + } + return true; + } private: - eoInit& initializer; - eoEvalFunc& fullEval; - unsigned int threshold; + eoInit& initializer; + eoEvalFunc& fullEval; + unsigned int threshold; }; diff --git a/trunk/paradiseo-mo/src/perturb/moSolInit.h b/trunk/paradiseo-mo/src/perturb/moSolInit.h index 8348adcb0..abfc693f9 100644 --- a/trunk/paradiseo-mo/src/perturb/moSolInit.h +++ b/trunk/paradiseo-mo/src/perturb/moSolInit.h @@ -39,22 +39,22 @@ template< class EOT > class moSolInit : public eoInit { public: - /** - * Default Constructor - * @param _extSol external solution of the intiialization - */ - moSolInit(EOT & _extSol) : extSol(_extSol) {} - - /** - * Initialization on the externatl solution - * @param _solution to initialize - */ - void operator()(EOT& _solution){ - _solution = extSol; - } + /** + * Default Constructor + * @param _extSol external solution of the intiialization + */ + moSolInit(EOT & _extSol) : extSol(_extSol) {} + + /** + * Initialization on the externatl solution + * @param _solution to initialize + */ + void operator()(EOT& _solution) { + _solution = extSol; + } private: - EOT& extSol; + EOT& extSol; }; #endif diff --git a/trunk/paradiseo-mo/src/problems/eval/moMaxSATincrEval.h b/trunk/paradiseo-mo/src/problems/eval/moMaxSATincrEval.h index 2d4cbf9ca..b5595c4c1 100644 --- a/trunk/paradiseo-mo/src/problems/eval/moMaxSATincrEval.h +++ b/trunk/paradiseo-mo/src/problems/eval/moMaxSATincrEval.h @@ -39,83 +39,83 @@ Contact: paradiseo-help@lists.gforge.inria.fr template class moMaxSATincrEval : public moEval { public : - typedef typename Neighbor::EOT EOT; - - moMaxSATincrEval(MaxSATeval & _fulleval) : fulleval(_fulleval) { - nbClauses = _fulleval.nbClauses; - nbVar = _fulleval.nbVar; + typedef typename Neighbor::EOT EOT; - clauses = _fulleval.clauses; - variables = _fulleval.variables; - } + moMaxSATincrEval(MaxSATeval & _fulleval) : fulleval(_fulleval) { + nbClauses = _fulleval.nbClauses; + nbVar = _fulleval.nbVar; - /* - * incremental evaluation of the neighbor for the max SAT problem - * @param _solution the solution (of type bit string) to move - * @param _neighbor the neighbor (of type moBitNeigbor) to consider - */ - virtual void operator()(EOT & _solution, Neighbor & _neighbor) { - // the difference of fitness - int delta = 0; - - // the flipped bit - unsigned int bit = _neighbor.index(); - - // clauses which can be modified by the flipped bit - const vector & modifiedClauses = variables[bit + 1] ; // remember that the variables start at index 1 and not 0 - unsigned int size = modifiedClauses.size(); - - int nc; - bool litt; - - for(unsigned int k = 0; k < size; k++) { - // number of the clause - nc = modifiedClauses[k]; - - // negative means that the not(variable) is in the clause - if (nc < 0) { - nc = - nc; - litt = !_solution[bit]; - } else - litt = _solution[bit]; - - if (litt) { - // the litteral was true and becomes false - _solution[bit] = !_solution[bit]; - - if (!fulleval.clauseEval(nc, _solution)) - // the clause was true and becomes false - delta--; - - _solution[bit] = !_solution[bit]; - } else { - // the litteral was false and becomes true - if (!fulleval.clauseEval(nc, _solution)) - // the clause was false and becomes true - delta++; - } + clauses = _fulleval.clauses; + variables = _fulleval.variables; + } + + /* + * incremental evaluation of the neighbor for the max SAT problem + * @param _solution the solution (of type bit string) to move + * @param _neighbor the neighbor (of type moBitNeigbor) to consider + */ + virtual void operator()(EOT & _solution, Neighbor & _neighbor) { + // the difference of fitness + int delta = 0; + + // the flipped bit + unsigned int bit = _neighbor.index(); + + // clauses which can be modified by the flipped bit + const vector & modifiedClauses = variables[bit + 1] ; // remember that the variables start at index 1 and not 0 + unsigned int size = modifiedClauses.size(); + + int nc; + bool litt; + + for (unsigned int k = 0; k < size; k++) { + // number of the clause + nc = modifiedClauses[k]; + + // negative means that the not(variable) is in the clause + if (nc < 0) { + nc = - nc; + litt = !_solution[bit]; + } else + litt = _solution[bit]; + + if (litt) { + // the litteral was true and becomes false + _solution[bit] = !_solution[bit]; + + if (!fulleval.clauseEval(nc, _solution)) + // the clause was true and becomes false + delta--; + + _solution[bit] = !_solution[bit]; + } else { + // the litteral was false and becomes true + if (!fulleval.clauseEval(nc, _solution)) + // the clause was false and becomes true + delta++; + } + } + + _neighbor.fitness(_solution.fitness() + delta); } - - _neighbor.fitness(_solution.fitness() + delta); - } protected: - // number of variables - unsigned int nbVar; - // number of clauses - unsigned int nbClauses; + // number of variables + unsigned int nbVar; + // number of clauses + unsigned int nbClauses; - // list of clauses: - // each clause has the number of the variable (from 1 to nbVar) - // when the value, litteral = not(variable) - vector * clauses; + // list of clauses: + // each clause has the number of the variable (from 1 to nbVar) + // when the value, litteral = not(variable) + vector * clauses; - // list of variables: - // for each variable, the list of clauses - vector * variables; - - //full eval of the max SAT - MaxSATeval & fulleval; + // list of variables: + // for each variable, the list of clauses + vector * variables; + + //full eval of the max SAT + MaxSATeval & fulleval; }; #endif diff --git a/trunk/paradiseo-mo/src/problems/eval/moOneMaxIncrEval.h b/trunk/paradiseo-mo/src/problems/eval/moOneMaxIncrEval.h index ede6fa91e..c97b096e2 100644 --- a/trunk/paradiseo-mo/src/problems/eval/moOneMaxIncrEval.h +++ b/trunk/paradiseo-mo/src/problems/eval/moOneMaxIncrEval.h @@ -47,10 +47,10 @@ public: * @param _neighbor the neighbor to consider (of type moBitNeigbor) */ virtual void operator()(EOT & _solution, Neighbor & _neighbor) { - if (_solution[_neighbor.index()] == 0) - _neighbor.fitness(_solution.fitness() + 1); - else - _neighbor.fitness(_solution.fitness() - 1); + if (_solution[_neighbor.index()] == 0) + _neighbor.fitness(_solution.fitness() + 1); + else + _neighbor.fitness(_solution.fitness() - 1); } }; diff --git a/trunk/paradiseo-mo/src/problems/eval/moRoyalRoadIncrEval.h b/trunk/paradiseo-mo/src/problems/eval/moRoyalRoadIncrEval.h index 0beb7eb07..9a3432b09 100644 --- a/trunk/paradiseo-mo/src/problems/eval/moRoyalRoadIncrEval.h +++ b/trunk/paradiseo-mo/src/problems/eval/moRoyalRoadIncrEval.h @@ -40,48 +40,48 @@ template< class Neighbor > class moRoyalRoadIncrEval : public moEval { public: - typedef typename Neighbor::EOT EOT; + typedef typename Neighbor::EOT EOT; - /** - * Default constructor - * @param _rr full evaluation of the Royal Road (to have the same block size) - */ - moRoyalRoadIncrEval(RoyalRoadEval & _rr) : k(_rr.blockSize()) {} + /** + * Default constructor + * @param _rr full evaluation of the Royal Road (to have the same block size) + */ + moRoyalRoadIncrEval(RoyalRoadEval & _rr) : k(_rr.blockSize()) {} - /* - * incremental evaluation of the neighbor for the Royal Road problem - * @param _solution the solution to move (bit string) - * @param _neighbor the neighbor to consider (of type moBitNeigbor) - */ - virtual void operator()(EOT & _solution, Neighbor & _neighbor) { - // which block can be changed? - unsigned int n = _neighbor.index() / k; - - // complete block? - unsigned int offset = n * k; - - unsigned int j = 0; - while (_solution[offset + j] && j < k) j++; - - if (j == k) // the block is complete, so the fitness decreases from one - _neighbor.fitness(_solution.fitness() - 1); - else { - if ((_solution[_neighbor.index()] == 0) && (offset + j == _neighbor.index())) { // can the block be filled? - j++; // next bit - while (_solution[offset + j] && j < k) j++; + /* + * incremental evaluation of the neighbor for the Royal Road problem + * @param _solution the solution to move (bit string) + * @param _neighbor the neighbor to consider (of type moBitNeigbor) + */ + virtual void operator()(EOT & _solution, Neighbor & _neighbor) { + // which block can be changed? + unsigned int n = _neighbor.index() / k; - if (j == k) // the block can be filled, so the fitness increases from one - _neighbor.fitness(_solution.fitness() + 1); - else - _neighbor.fitness(_solution.fitness()); - } else - _neighbor.fitness(_solution.fitness()); + // complete block? + unsigned int offset = n * k; + + unsigned int j = 0; + while (_solution[offset + j] && j < k) j++; + + if (j == k) // the block is complete, so the fitness decreases from one + _neighbor.fitness(_solution.fitness() - 1); + else { + if ((_solution[_neighbor.index()] == 0) && (offset + j == _neighbor.index())) { // can the block be filled? + j++; // next bit + while (_solution[offset + j] && j < k) j++; + + if (j == k) // the block can be filled, so the fitness increases from one + _neighbor.fitness(_solution.fitness() + 1); + else + _neighbor.fitness(_solution.fitness()); + } else + _neighbor.fitness(_solution.fitness()); + } } - } protected: - // size of the blocks - unsigned int k; + // size of the blocks + unsigned int k; }; #endif diff --git a/trunk/paradiseo-mo/src/problems/eval/oneMaxFullEval.h b/trunk/paradiseo-mo/src/problems/eval/oneMaxFullEval.h index f778c3414..37fec1433 100644 --- a/trunk/paradiseo-mo/src/problems/eval/oneMaxFullEval.h +++ b/trunk/paradiseo-mo/src/problems/eval/oneMaxFullEval.h @@ -40,10 +40,10 @@ class oneMaxFullEval : public eoEvalFunc { public: - /** - * Count the number of 1 in a bitString - * @param _sol the solution to evaluate - */ + /** + * Count the number of 1 in a bitString + * @param _sol the solution to evaluate + */ void operator() (EOT& _sol) { unsigned int sum = 0; for (unsigned int i = 0; i < _sol.size(); i++) diff --git a/trunk/paradiseo-mo/src/problems/permutation/moShiftNeighbor.h b/trunk/paradiseo-mo/src/problems/permutation/moShiftNeighbor.h index c67b55d0f..791918cf9 100644 --- a/trunk/paradiseo-mo/src/problems/permutation/moShiftNeighbor.h +++ b/trunk/paradiseo-mo/src/problems/permutation/moShiftNeighbor.h @@ -40,75 +40,75 @@ class moShiftNeighbor: public moIndexNeighbor { public: - using moIndexNeighbor::key; + using moIndexNeighbor::key; - /** - * Apply move on a solution regarding a key - * @param _sol the solution to move - */ - virtual void move(EOT & _sol){ - unsigned int tmp ; - size=_sol.size(); - translate(key+1); - // keep the first component to change - tmp = _sol[first]; - // shift - if (first < second){ - for (unsigned int i=first; i second*/ - for (unsigned int i=first; i>second; i--) - _sol[i] = _sol[i-1]; - // shift the first component - _sol[second] = tmp; - } - _sol.invalidate(); - } + /** + * Apply move on a solution regarding a key + * @param _sol the solution to move + */ + virtual void move(EOT & _sol) { + unsigned int tmp ; + size=_sol.size(); + translate(key+1); + // keep the first component to change + tmp = _sol[first]; + // shift + if (first < second) { + for (unsigned int i=first; i second*/ + for (unsigned int i=first; i>second; i--) + _sol[i] = _sol[i-1]; + // shift the first component + _sol[second] = tmp; + } + _sol.invalidate(); + } - /** - * fix two indexes regarding a key - * @param _key the key allowing to compute the two indexes for the shift - */ - void translate(unsigned int _key){ - int step; - int val = _key; - int tmpSize = size * (size-1) / 2; - // moves from left to right - if (val <= tmpSize){ - step = size - 1; - first = 0; - while ((val - step) > 0){ - val = val - step; - step--; - first++; - } - second = first + val + 1; - } - // moves from right to left (equivalent moves are avoided) - else{ /* val > tmpSize */ - val = val - tmpSize; - step = size - 2; - second = 0; - while ((val - step) > 0){ - val = val - step; - step--; - second++; - } - first = second + val + 1; - } - } + /** + * fix two indexes regarding a key + * @param _key the key allowing to compute the two indexes for the shift + */ + void translate(unsigned int _key) { + int step; + int val = _key; + int tmpSize = size * (size-1) / 2; + // moves from left to right + if (val <= tmpSize) { + step = size - 1; + first = 0; + while ((val - step) > 0) { + val = val - step; + step--; + first++; + } + second = first + val + 1; + } + // moves from right to left (equivalent moves are avoided) + else { /* val > tmpSize */ + val = val - tmpSize; + step = size - 2; + second = 0; + while ((val - step) > 0) { + val = val - step; + step--; + second++; + } + first = second + val + 1; + } + } - void print(){ - std::cout << key << ": [" << first << ", " << second << "] -> " << (*this).fitness() << std::endl; - } + void print() { + std::cout << key << ": [" << first << ", " << second << "] -> " << (*this).fitness() << std::endl; + } private: - unsigned int first; - unsigned int second; - unsigned int size; + unsigned int first; + unsigned int second; + unsigned int size; }; diff --git a/trunk/paradiseo-mo/src/problems/permutation/moSwapNeighbor.h b/trunk/paradiseo-mo/src/problems/permutation/moSwapNeighbor.h index 7416294d1..37ef990c9 100644 --- a/trunk/paradiseo-mo/src/problems/permutation/moSwapNeighbor.h +++ b/trunk/paradiseo-mo/src/problems/permutation/moSwapNeighbor.h @@ -41,49 +41,49 @@ class moSwapNeighbor: public moBackableNeighbor { public: - /** - * Apply the swap - * @param _solution the solution to move - */ - virtual void move(EOT& _solution){ - unsigned int tmp; - tmp=_solution[indices.first]; - _solution[indices.first]=_solution[indices.second]; - _solution[indices.second]=tmp; - _solution.invalidate(); - } + /** + * Apply the swap + * @param _solution the solution to move + */ + virtual void move(EOT& _solution) { + unsigned int tmp; + tmp=_solution[indices.first]; + _solution[indices.first]=_solution[indices.second]; + _solution[indices.second]=tmp; + _solution.invalidate(); + } - /** - * apply the swap to restore the solution (use by moFullEvalByModif) - * @param _solution the solution to move - */ - virtual void moveBack(EOT& _solution){ - unsigned int tmp; - tmp=_solution[indices.first]; - _solution[indices.first]=_solution[indices.second]; - _solution[indices.second]=tmp; - _solution.invalidate(); - } + /** + * apply the swap to restore the solution (use by moFullEvalByModif) + * @param _solution the solution to move + */ + virtual void moveBack(EOT& _solution) { + unsigned int tmp; + tmp=_solution[indices.first]; + _solution[indices.first]=_solution[indices.second]; + _solution[indices.second]=tmp; + _solution.invalidate(); + } - /** - * Setter to fix the two indexes to swap - * @param _first first index - * @param _second second index - */ - void setIndices(unsigned int _first, unsigned int _second){ - indices.first = _first; - indices.second = _second; - } + /** + * Setter to fix the two indexes to swap + * @param _first first index + * @param _second second index + */ + void setIndices(unsigned int _first, unsigned int _second) { + indices.first = _first; + indices.second = _second; + } - /** - * Print the Neighbor - */ - void print(){ - std::cout << "[" << indices.first << ", " << indices.second << "] -> " << (*this).fitness() << std::endl; - } + /** + * Print the Neighbor + */ + void print() { + std::cout << "[" << indices.first << ", " << indices.second << "] -> " << (*this).fitness() << std::endl; + } private: - std::pair indices; + std::pair indices; }; diff --git a/trunk/paradiseo-mo/src/problems/permutation/moSwapNeighborhood.h b/trunk/paradiseo-mo/src/problems/permutation/moSwapNeighborhood.h index 79410c50b..b7ea59984 100644 --- a/trunk/paradiseo-mo/src/problems/permutation/moSwapNeighborhood.h +++ b/trunk/paradiseo-mo/src/problems/permutation/moSwapNeighborhood.h @@ -45,8 +45,8 @@ public: /** * @return if there are available Neighbor */ - virtual bool hasNeighbor(EOT& _solution){ - return (_solution.size() > 1); + virtual bool hasNeighbor(EOT& _solution) { + return (_solution.size() > 1); }; /** @@ -54,11 +54,11 @@ public: * @param _solution the solution to explore * @param _current the first neighbor */ - virtual void init(EOT& _solution, Neighbor& _current){ - indices.first=0; - indices.second=1; - size=_solution.size(); - _current.setIndices(0,1); + virtual void init(EOT& _solution, Neighbor& _current) { + indices.first=0; + indices.second=1; + size=_solution.size(); + _current.setIndices(0,1); } /** @@ -66,14 +66,14 @@ public: * @param _solution the solution to explore * @param _current the next neighbor */ - virtual void next(EOT& _solution, Neighbor& _current){ - if(indices.second==size-1){ - indices.first++; - indices.second=indices.first+1; - } - else - indices.second++; - _current.setIndices(indices.first, indices.second); + virtual void next(EOT& _solution, Neighbor& _current) { + if (indices.second==size-1) { + indices.first++; + indices.second=indices.first+1; + } + else + indices.second++; + _current.setIndices(indices.first, indices.second); } /** @@ -81,8 +81,8 @@ public: * @param _solution the solution to explore * @return if there is again a neighbor not explored */ - virtual bool cont(EOT& _solution){ - return !((indices.first == (size-2)) && (indices.second == (size-1))); + virtual bool cont(EOT& _solution) { + return !((indices.first == (size-2)) && (indices.second == (size-1))); } /** @@ -90,7 +90,7 @@ public: * @return the class name as a std::string */ virtual std::string className() const { - return "moSwapNeighborhood"; + return "moSwapNeighborhood"; } private: diff --git a/trunk/paradiseo-mo/src/sampling/moAutocorrelationSampling.h b/trunk/paradiseo-mo/src/sampling/moAutocorrelationSampling.h index 636ac7508..ab2b4315f 100644 --- a/trunk/paradiseo-mo/src/sampling/moAutocorrelationSampling.h +++ b/trunk/paradiseo-mo/src/sampling/moAutocorrelationSampling.h @@ -46,42 +46,42 @@ * To compute the autocorrelation function: * Perform a random walk based on the neighborhood, * The fitness values of solutions are collected during the random walk - * The autocorrelation can be computed from the serie of fitness values - * + * The autocorrelation can be computed from the serie of fitness values + * */ template class moAutocorrelationSampling : public moSampling { public: - typedef typename Neighbor::EOT EOT ; - - using moSampling::localSearch; + typedef typename Neighbor::EOT EOT ; - /** - * Default Constructor - * @param _init initialisation method of the solution - * @param _neighborhood neighborhood giving neighbor in random order - * @param _fullEval Fitness function, full evaluation function - * @param _eval neighbor evaluation, incremental evaluation function - * @param _nbStep Number of steps of the random walk - */ - moAutocorrelationSampling(eoInit & _init, - moNeighborhood & _neighborhood, - eoEvalFunc& _fullEval, - moEval& _eval, - unsigned int _nbStep) : - moSampling(_init, * new moRandomWalk(_neighborhood, _fullEval, _eval, _nbStep), fitnessStat){} + using moSampling::localSearch; - /** - * default destructor - */ - ~moAutocorrelationSampling() { - // delete the pointer on the local search which has been constructed in the constructor - delete localSearch; - } + /** + * Default Constructor + * @param _init initialisation method of the solution + * @param _neighborhood neighborhood giving neighbor in random order + * @param _fullEval Fitness function, full evaluation function + * @param _eval neighbor evaluation, incremental evaluation function + * @param _nbStep Number of steps of the random walk + */ + moAutocorrelationSampling(eoInit & _init, + moNeighborhood & _neighborhood, + eoEvalFunc& _fullEval, + moEval& _eval, + unsigned int _nbStep) : + moSampling(_init, * new moRandomWalk(_neighborhood, _fullEval, _eval, _nbStep), fitnessStat) {} + + /** + * default destructor + */ + ~moAutocorrelationSampling() { + // delete the pointer on the local search which has been constructed in the constructor + delete localSearch; + } protected: - moFitnessStat fitnessStat; + moFitnessStat fitnessStat; }; diff --git a/trunk/paradiseo-mo/src/sampling/moDensityOfStatesSampling.h b/trunk/paradiseo-mo/src/sampling/moDensityOfStatesSampling.h index b0696ae6c..ec13fd8b9 100644 --- a/trunk/paradiseo-mo/src/sampling/moDensityOfStatesSampling.h +++ b/trunk/paradiseo-mo/src/sampling/moDensityOfStatesSampling.h @@ -42,40 +42,40 @@ #include /** - * To compute the density of states: + * To compute the density of states: * Sample the fitness of random solution in the search space * The fitness values of solutions are collected during the random search - * + * */ template class moDensityOfStatesSampling : public moSampling { public: - typedef typename Neighbor::EOT EOT ; - - using moSampling::localSearch; + typedef typename Neighbor::EOT EOT ; - /** - * Default Constructor - * @param _init initialisation method of the solution - * @param _fullEval Fitness function, full evaluation function - * @param _nbSol Number of solutions in the sample - */ - moDensityOfStatesSampling(eoInit & _init, - eoEvalFunc& _fullEval, - unsigned int _nbSol) : - moSampling(_init, * new moRandomSearch(_init, _fullEval, _nbSol), fitnessStat){} + using moSampling::localSearch; - /** - * default destructor - */ - ~moDensityOfStatesSampling() { - // delete the pointer on the local search which has been constructed in the constructor - delete localSearch; - } + /** + * Default Constructor + * @param _init initialisation method of the solution + * @param _fullEval Fitness function, full evaluation function + * @param _nbSol Number of solutions in the sample + */ + moDensityOfStatesSampling(eoInit & _init, + eoEvalFunc& _fullEval, + unsigned int _nbSol) : + moSampling(_init, * new moRandomSearch(_init, _fullEval, _nbSol), fitnessStat) {} + + /** + * default destructor + */ + ~moDensityOfStatesSampling() { + // delete the pointer on the local search which has been constructed in the constructor + delete localSearch; + } protected: - moFitnessStat fitnessStat; + moFitnessStat fitnessStat; }; diff --git a/trunk/paradiseo-mo/src/sampling/moFDCsampling.h b/trunk/paradiseo-mo/src/sampling/moFDCsampling.h index 57e9492a0..899c184b2 100644 --- a/trunk/paradiseo-mo/src/sampling/moFDCsampling.h +++ b/trunk/paradiseo-mo/src/sampling/moFDCsampling.h @@ -45,7 +45,7 @@ #include /** - * To compute the fitness distance correlation: + * To compute the fitness distance correlation: * Sample the fitness and the distance from a particular solution of random solution in the search space * The fitness values and distances of solutions are collected during the random search * Then the correlation between the fitness and the distance can be computed @@ -55,40 +55,40 @@ template class moFDCsampling : public moSampling { public: - typedef typename Neighbor::EOT EOT ; - - using moSampling::localSearch; + typedef typename Neighbor::EOT EOT ; - /** - * Default Constructor - * @param _init initialisation method of the solution - * @param _fullEval a full evaluation function - * @param _dist the distance function between solution - * @param _refSol the reference solution to compute the distance (think of global optimum when possible) - * @param _nbSol Number of solutions of the sample - */ - moFDCsampling(eoInit & _init, - eoEvalFunc& _fullEval, - eoDistance& _dist, - EOT& _refSol, - unsigned int _nbSol) : - moSampling(_init, * new moRandomSearch(_init, _fullEval, _nbSol), fitnessStat), - distStat(_dist, _refSol) - { - add(distStat); - } + using moSampling::localSearch; - /** - * default destructor - */ - ~moFDCsampling() { - // delete the pointer on the local search which has been constructed in the constructor - delete localSearch; - } + /** + * Default Constructor + * @param _init initialisation method of the solution + * @param _fullEval a full evaluation function + * @param _dist the distance function between solution + * @param _refSol the reference solution to compute the distance (think of global optimum when possible) + * @param _nbSol Number of solutions of the sample + */ + moFDCsampling(eoInit & _init, + eoEvalFunc& _fullEval, + eoDistance& _dist, + EOT& _refSol, + unsigned int _nbSol) : + moSampling(_init, * new moRandomSearch(_init, _fullEval, _nbSol), fitnessStat), + distStat(_dist, _refSol) + { + add(distStat); + } + + /** + * default destructor + */ + ~moFDCsampling() { + // delete the pointer on the local search which has been constructed in the constructor + delete localSearch; + } protected: - moFitnessStat fitnessStat; - moDistanceStat distStat; + moFitnessStat fitnessStat; + moDistanceStat distStat; }; diff --git a/trunk/paradiseo-mo/src/sampling/moFitnessCloudSampling.h b/trunk/paradiseo-mo/src/sampling/moFitnessCloudSampling.h index bd222ee25..4e5051acf 100644 --- a/trunk/paradiseo-mo/src/sampling/moFitnessCloudSampling.h +++ b/trunk/paradiseo-mo/src/sampling/moFitnessCloudSampling.h @@ -45,8 +45,8 @@ #include /** - * To compute an estimation of the fitness cloud, - * i.e. the scatter plot of solution fitness versus neighbor fitness: + * To compute an estimation of the fitness cloud, + * i.e. the scatter plot of solution fitness versus neighbor fitness: * * This class do nothing. See others mo(...)FitnessCloudSampling classes * with different fitness sampling methods @@ -55,44 +55,44 @@ template class moFitnessCloudSampling : public moSampling { public: - typedef typename Neighbor::EOT EOT ; - - using moSampling::localSearch; + typedef typename Neighbor::EOT EOT ; - /** - * Default Constructor - * @param _init initialisation method of the solution - * @param _neighborhood neighborhood to get a neighbor - * @param _fullEval Fitness function, full evaluation function - * @param _eval neighbor evaluation, incremental evaluation function - * @param _nbSol Number of solutions in the sample - */ - moFitnessCloudSampling(eoInit & _init, - moNeighborhood & _neighborhood, - eoEvalFunc& _fullEval, - moEval& _eval, - unsigned int _nbSol) : - moSampling(_init, * new moDummyLS(_fullEval), fitnessStat), - neighborhood(_neighborhood), - fullEval(_fullEval), - eval(_eval), - nbSol(_nbSol) - {} + using moSampling::localSearch; - /** - * default destructor - */ - ~moFitnessCloudSampling() { - // delete the pointer on the local search which has been constructed in the constructor - delete localSearch; - } + /** + * Default Constructor + * @param _init initialisation method of the solution + * @param _neighborhood neighborhood to get a neighbor + * @param _fullEval Fitness function, full evaluation function + * @param _eval neighbor evaluation, incremental evaluation function + * @param _nbSol Number of solutions in the sample + */ + moFitnessCloudSampling(eoInit & _init, + moNeighborhood & _neighborhood, + eoEvalFunc& _fullEval, + moEval& _eval, + unsigned int _nbSol) : + moSampling(_init, * new moDummyLS(_fullEval), fitnessStat), + neighborhood(_neighborhood), + fullEval(_fullEval), + eval(_eval), + nbSol(_nbSol) + {} + + /** + * default destructor + */ + ~moFitnessCloudSampling() { + // delete the pointer on the local search which has been constructed in the constructor + delete localSearch; + } protected: - moNeighborhood & neighborhood; - eoEvalFunc& fullEval; - moEval& eval; - unsigned int nbSol; - moFitnessStat fitnessStat; + moNeighborhood & neighborhood; + eoEvalFunc& fullEval; + moEval& eval; + unsigned int nbSol; + moFitnessStat fitnessStat; }; diff --git a/trunk/paradiseo-mo/src/sampling/moHillClimberSampling.h b/trunk/paradiseo-mo/src/sampling/moHillClimberSampling.h index 1b83f2017..2aa229345 100644 --- a/trunk/paradiseo-mo/src/sampling/moHillClimberSampling.h +++ b/trunk/paradiseo-mo/src/sampling/moHillClimberSampling.h @@ -52,58 +52,58 @@ * Perform a simple Hill-climber based on the neighborhood (adaptive walk), * The lengths of HC are collected and the final solution which are local optima * The adaptive walk is repeated several times - * + * */ template class moHillClimberSampling : public moSampling { public: - typedef typename Neighbor::EOT EOT ; - - using moSampling::localSearch; + typedef typename Neighbor::EOT EOT ; - /** - * Default Constructor - * @param _init initialisation method of the solution - * @param _neighborhood neighborhood giving neighbor in random order - * @param _fullEval a full evaluation function - * @param _eval an incremental evaluation of neighbors - * @param _nbAdaptWalk Number of adaptive walks - */ - moHillClimberSampling(eoInit & _init, - moNeighborhood & _neighborhood, - eoEvalFunc& _fullEval, - moEval& _eval, - unsigned int _nbAdaptWalk) : - moSampling(initHC, * new moRandomSearch(initHC, _fullEval, _nbAdaptWalk), copyStat), - copyStat(lengthStat), - checkpoint(trueCont), - hc(_neighborhood, _fullEval, _eval, checkpoint), - initHC(_init, hc) - { - // to count the number of step in the HC - checkpoint.add(lengthStat); + using moSampling::localSearch; - // add the solution into statistics - add(solStat); - } + /** + * Default Constructor + * @param _init initialisation method of the solution + * @param _neighborhood neighborhood giving neighbor in random order + * @param _fullEval a full evaluation function + * @param _eval an incremental evaluation of neighbors + * @param _nbAdaptWalk Number of adaptive walks + */ + moHillClimberSampling(eoInit & _init, + moNeighborhood & _neighborhood, + eoEvalFunc& _fullEval, + moEval& _eval, + unsigned int _nbAdaptWalk) : + moSampling(initHC, * new moRandomSearch(initHC, _fullEval, _nbAdaptWalk), copyStat), + copyStat(lengthStat), + checkpoint(trueCont), + hc(_neighborhood, _fullEval, _eval, checkpoint), + initHC(_init, hc) + { + // to count the number of step in the HC + checkpoint.add(lengthStat); - /** - * default destructor - */ - ~moHillClimberSampling() { - // delete the pointer on the local search which has been constructed in the constructor - delete localSearch; - } + // add the solution into statistics + add(solStat); + } + + /** + * default destructor + */ + ~moHillClimberSampling() { + // delete the pointer on the local search which has been constructed in the constructor + delete localSearch; + } protected: - moSolutionStat solStat; - moMinusOneCounterStat lengthStat; - moTrueContinuator trueCont; - moStatFromStat copyStat; - moCheckpoint checkpoint; - moSimpleHC hc; - moLocalSearchInit initHC; + moSolutionStat solStat; + moMinusOneCounterStat lengthStat; + moTrueContinuator trueCont; + moStatFromStat copyStat; + moCheckpoint checkpoint; + moSimpleHC hc; + moLocalSearchInit initHC; }; diff --git a/trunk/paradiseo-mo/src/sampling/moMHBestFitnessCloudSampling.h b/trunk/paradiseo-mo/src/sampling/moMHBestFitnessCloudSampling.h index 2a2c0f21e..7a1d07e8f 100644 --- a/trunk/paradiseo-mo/src/sampling/moMHBestFitnessCloudSampling.h +++ b/trunk/paradiseo-mo/src/sampling/moMHBestFitnessCloudSampling.h @@ -44,8 +44,8 @@ #include /** - * To compute an estimation of the fitness cloud, - * i.e. the scatter plot of solution fitness versus neighbor fitness: + * To compute an estimation of the fitness cloud, + * i.e. the scatter plot of solution fitness versus neighbor fitness: * * Here solution are sampled with Metropolis-Hasting method * @@ -53,59 +53,59 @@ * and the best fitness of k random neighbor * * The values are collected during the Metropolis-Hasting walk - * + * */ template class moMHBestFitnessCloudSampling : public moFitnessCloudSampling { public: - typedef typename Neighbor::EOT EOT ; - - using moSampling::localSearch; - using moSampling::checkpoint; - using moSampling::monitorVec; - using moSampling::continuator; - using moFitnessCloudSampling::fitnessStat; + typedef typename Neighbor::EOT EOT ; - /** - * Default Constructor - * @param _init initialisation method of the solution - * @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood) - * @param _fullEval Fitness function, full evaluation function - * @param _eval neighbor evaluation, incremental evaluation function - * @param _nbStep Number of step of the MH sampling - */ - moMHBestFitnessCloudSampling(eoInit & _init, - moNeighborhood & _neighborhood, - eoEvalFunc& _fullEval, - moEval& _eval, - unsigned int _nbStep) : - moFitnessCloudSampling(_init, _neighborhood, _fullEval, _eval, _nbStep), - neighborBestStat(_neighborhood, _eval) - { - // delete the dummy local search - delete localSearch; - - // Metropolis-Hasting sampling - localSearch = new moMetropolisHasting(_neighborhood, _fullEval, _eval, _nbStep); + using moSampling::localSearch; + using moSampling::checkpoint; + using moSampling::monitorVec; + using moSampling::continuator; + using moFitnessCloudSampling::fitnessStat; - // delete the checkpoint with the wrong continuator - delete checkpoint; + /** + * Default Constructor + * @param _init initialisation method of the solution + * @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood) + * @param _fullEval Fitness function, full evaluation function + * @param _eval neighbor evaluation, incremental evaluation function + * @param _nbStep Number of step of the MH sampling + */ + moMHBestFitnessCloudSampling(eoInit & _init, + moNeighborhood & _neighborhood, + eoEvalFunc& _fullEval, + moEval& _eval, + unsigned int _nbStep) : + moFitnessCloudSampling(_init, _neighborhood, _fullEval, _eval, _nbStep), + neighborBestStat(_neighborhood, _eval) + { + // delete the dummy local search + delete localSearch; - // set the continuator - continuator = localSearch->getContinuator(); + // Metropolis-Hasting sampling + localSearch = new moMetropolisHasting(_neighborhood, _fullEval, _eval, _nbStep); - // re-construction of the checkpoint - checkpoint = new moCheckpoint(*continuator); - checkpoint->add(fitnessStat); - checkpoint->add(*monitorVec[0]); + // delete the checkpoint with the wrong continuator + delete checkpoint; - // one random neighbor - add(neighborBestStat); - } + // set the continuator + continuator = localSearch->getContinuator(); + + // re-construction of the checkpoint + checkpoint = new moCheckpoint(*continuator); + checkpoint->add(fitnessStat); + checkpoint->add(*monitorVec[0]); + + // one random neighbor + add(neighborBestStat); + } protected: - moNeighborBestStat< Neighbor > neighborBestStat; + moNeighborBestStat< Neighbor > neighborBestStat; }; diff --git a/trunk/paradiseo-mo/src/sampling/moMHRndFitnessCloudSampling.h b/trunk/paradiseo-mo/src/sampling/moMHRndFitnessCloudSampling.h index a06a39c05..5e9efc10f 100644 --- a/trunk/paradiseo-mo/src/sampling/moMHRndFitnessCloudSampling.h +++ b/trunk/paradiseo-mo/src/sampling/moMHRndFitnessCloudSampling.h @@ -44,8 +44,8 @@ #include /** - * To compute an estimation of the fitness cloud, - * i.e. the scatter plot of solution fitness versus neighbor fitness: + * To compute an estimation of the fitness cloud, + * i.e. the scatter plot of solution fitness versus neighbor fitness: * * Here solution are sampled with Metropolis-Hasting method * @@ -53,59 +53,59 @@ * and the fitness of one random neighbor * * The values are collected during the Metropolis-Hasting walk - * + * */ template class moMHRndFitnessCloudSampling : public moFitnessCloudSampling { public: - typedef typename Neighbor::EOT EOT ; - - using moSampling::localSearch; - using moSampling::checkpoint; - using moSampling::monitorVec; - using moSampling::continuator; - using moFitnessCloudSampling::fitnessStat; + typedef typename Neighbor::EOT EOT ; - /** - * Default Constructor - * @param _init initialisation method of the solution - * @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood) - * @param _fullEval Fitness function, full evaluation function - * @param _eval neighbor evaluation, incremental evaluation function - * @param _nbStep Number of step of the MH sampling - */ - moMHRndFitnessCloudSampling(eoInit & _init, - moNeighborhood & _neighborhood, - eoEvalFunc& _fullEval, - moEval& _eval, - unsigned int _nbStep) : - moFitnessCloudSampling(_init, _neighborhood, _fullEval, _eval, _nbStep), - neighborFitnessStat(_neighborhood, _eval) - { - // delete the dummy local search - delete localSearch; - - // Metropolis-Hasting sampling - localSearch = new moMetropolisHasting(_neighborhood, _fullEval, _eval, _nbStep); + using moSampling::localSearch; + using moSampling::checkpoint; + using moSampling::monitorVec; + using moSampling::continuator; + using moFitnessCloudSampling::fitnessStat; - // delete the checkpoint with the wrong continuator - delete checkpoint; + /** + * Default Constructor + * @param _init initialisation method of the solution + * @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood) + * @param _fullEval Fitness function, full evaluation function + * @param _eval neighbor evaluation, incremental evaluation function + * @param _nbStep Number of step of the MH sampling + */ + moMHRndFitnessCloudSampling(eoInit & _init, + moNeighborhood & _neighborhood, + eoEvalFunc& _fullEval, + moEval& _eval, + unsigned int _nbStep) : + moFitnessCloudSampling(_init, _neighborhood, _fullEval, _eval, _nbStep), + neighborFitnessStat(_neighborhood, _eval) + { + // delete the dummy local search + delete localSearch; - // set the continuator - continuator = localSearch->getContinuator(); + // Metropolis-Hasting sampling + localSearch = new moMetropolisHasting(_neighborhood, _fullEval, _eval, _nbStep); - // re-construction of the checkpoint - checkpoint = new moCheckpoint(*continuator); - checkpoint->add(fitnessStat); - checkpoint->add(*monitorVec[0]); + // delete the checkpoint with the wrong continuator + delete checkpoint; - // one random neighbor - add(neighborFitnessStat); - } + // set the continuator + continuator = localSearch->getContinuator(); + + // re-construction of the checkpoint + checkpoint = new moCheckpoint(*continuator); + checkpoint->add(fitnessStat); + checkpoint->add(*monitorVec[0]); + + // one random neighbor + add(neighborFitnessStat); + } protected: - moNeighborFitnessStat< Neighbor > neighborFitnessStat; + moNeighborFitnessStat< Neighbor > neighborFitnessStat; }; diff --git a/trunk/paradiseo-mo/src/sampling/moNeutralDegreeSampling.h b/trunk/paradiseo-mo/src/sampling/moNeutralDegreeSampling.h index b4a3173df..8ff55419c 100644 --- a/trunk/paradiseo-mo/src/sampling/moNeutralDegreeSampling.h +++ b/trunk/paradiseo-mo/src/sampling/moNeutralDegreeSampling.h @@ -46,78 +46,78 @@ #include /** - * To compute the neutral degree: + * To compute the neutral degree: * Sample the fitness of random solution in the search space (1er information) * and sample the neutral degree (2nd information), i.e. the number of neighbor solutions with the same fitness value * The values are collected during the random search - * + * */ template class moNeutralDegreeSampling : public moSampling { public: - typedef typename Neighbor::EOT EOT ; - - using moSampling::localSearch; + typedef typename Neighbor::EOT EOT ; - /** - * Default Constructor - * @param _init initialisation method of the solution - * @param _neighborhood neighborhood to compute the neutral degree - * @param _fullEval Fitness function, full evaluation function - * @param _eval neighbor evaluation, incremental evaluation function - * @param _nbSol Number of solutions in the sample - */ - moNeutralDegreeSampling(eoInit & _init, - moNeighborhood & _neighborhood, - eoEvalFunc& _fullEval, - moEval& _eval, - unsigned int _nbSol) : - moSampling(_init, * new moRandomSearch(_init, _fullEval, _nbSol), fitnessStat), - neighborhoodStat(_neighborhood, _eval), - ndStat(neighborhoodStat) - { - add(neighborhoodStat, false); - add(ndStat); - } + using moSampling::localSearch; - /** - * Constructor with comparators - * @param _init initialisation method of the solution - * @param _neighborhood neighborhood to compute the neutral degree - * @param _fullEval Fitness function, full evaluation function - * @param _eval neighbor evaluation, incremental evaluation function - * @param _neighborComparator a neighbor Comparator - * @param _solNeighborComparator a comparator between a solution and a neighbor - * @param _nbSol Number of solutions in the sample - */ - moNeutralDegreeSampling(eoInit & _init, - moNeighborhood & _neighborhood, - eoEvalFunc& _fullEval, - moEval& _eval, - moNeighborComparator& _neighborComparator, - moSolNeighborComparator& _solNeighborComparator, - unsigned int _nbSol) : - moSampling(_init, * new moRandomSearch(_init, _fullEval, _nbSol), fitnessStat), - neighborhoodStat(_neighborhood, _eval, _neighborComparator, _solNeighborComparator), - ndStat(neighborhoodStat) - { - add(neighborhoodStat, false); - add(ndStat); - } + /** + * Default Constructor + * @param _init initialisation method of the solution + * @param _neighborhood neighborhood to compute the neutral degree + * @param _fullEval Fitness function, full evaluation function + * @param _eval neighbor evaluation, incremental evaluation function + * @param _nbSol Number of solutions in the sample + */ + moNeutralDegreeSampling(eoInit & _init, + moNeighborhood & _neighborhood, + eoEvalFunc& _fullEval, + moEval& _eval, + unsigned int _nbSol) : + moSampling(_init, * new moRandomSearch(_init, _fullEval, _nbSol), fitnessStat), + neighborhoodStat(_neighborhood, _eval), + ndStat(neighborhoodStat) + { + add(neighborhoodStat, false); + add(ndStat); + } - /** - * default destructor - */ - ~moNeutralDegreeSampling() { - // delete the pointer on the local search which has been constructed in the constructor - delete localSearch; - } + /** + * Constructor with comparators + * @param _init initialisation method of the solution + * @param _neighborhood neighborhood to compute the neutral degree + * @param _fullEval Fitness function, full evaluation function + * @param _eval neighbor evaluation, incremental evaluation function + * @param _neighborComparator a neighbor Comparator + * @param _solNeighborComparator a comparator between a solution and a neighbor + * @param _nbSol Number of solutions in the sample + */ + moNeutralDegreeSampling(eoInit & _init, + moNeighborhood & _neighborhood, + eoEvalFunc& _fullEval, + moEval& _eval, + moNeighborComparator& _neighborComparator, + moSolNeighborComparator& _solNeighborComparator, + unsigned int _nbSol) : + moSampling(_init, * new moRandomSearch(_init, _fullEval, _nbSol), fitnessStat), + neighborhoodStat(_neighborhood, _eval, _neighborComparator, _solNeighborComparator), + ndStat(neighborhoodStat) + { + add(neighborhoodStat, false); + add(ndStat); + } + + /** + * default destructor + */ + ~moNeutralDegreeSampling() { + // delete the pointer on the local search which has been constructed in the constructor + delete localSearch; + } protected: - moFitnessStat fitnessStat; - moNeighborhoodStat< Neighbor > neighborhoodStat; - moNeutralDegreeNeighborStat< Neighbor > ndStat; + moFitnessStat fitnessStat; + moNeighborhoodStat< Neighbor > neighborhoodStat; + moNeutralDegreeNeighborStat< Neighbor > ndStat; }; diff --git a/trunk/paradiseo-mo/src/sampling/moNeutralWalkSampling.h b/trunk/paradiseo-mo/src/sampling/moNeutralWalkSampling.h index 03547593a..5ffdf647b 100644 --- a/trunk/paradiseo-mo/src/sampling/moNeutralWalkSampling.h +++ b/trunk/paradiseo-mo/src/sampling/moNeutralWalkSampling.h @@ -58,8 +58,8 @@ * To explore the evolvability of solutions in a neutral networks: * Perform a random neutral walk based on the neighborhood, * The measures of evolvability of solutions are collected during the random neutral walk - * The distribution and autocorrelation can be computed from the serie of values - * + * The distribution and autocorrelation can be computed from the serie of values + * * Informations collected: * - the current solution of the walk * - the distance from the starting solution @@ -76,71 +76,71 @@ template class moNeutralWalkSampling : public moSampling { public: - typedef typename Neighbor::EOT EOT ; - - using moSampling::localSearch; + typedef typename Neighbor::EOT EOT ; - /** - * Default Constructor - * @param _initSol the first the solution of the walk - * @param _neighborhood neighborhood giving neighbor in random order - * @param _fullEval Fitness function, full evaluation function - * @param _eval neighbor evaluation, incremental evaluation function - * @param _distance the distance to measure the distance from the initial solution - * @param _nbStep Number of steps of the random walk - */ - moNeutralWalkSampling(EOT & _initSol, - moNeighborhood & _neighborhood, - eoEvalFunc& _fullEval, - moEval& _eval, - eoDistance & _distance, - unsigned int _nbStep) : - moSampling(init, * new moRandomNeutralWalk(_neighborhood, _fullEval, _eval, _nbStep), solutionStat), - init(_initSol), - distStat(_distance, _initSol), - neighborhoodStat(_neighborhood, _eval), - minStat(neighborhoodStat), - averageStat(neighborhoodStat), - stdStat(neighborhoodStat), - maxStat(neighborhoodStat), - nbSupStat(neighborhoodStat), - nbInfStat(neighborhoodStat), - sizeStat(neighborhoodStat), - ndStat(neighborhoodStat) - { - add(neighborhoodStat, false); - add(distStat); - add(minStat); - add(averageStat); - add(stdStat); - add(maxStat); - add(sizeStat); - add(nbInfStat); - add(ndStat); - add(nbSupStat); - } + using moSampling::localSearch; - /** - * default destructor - */ - ~moNeutralWalkSampling() { - // delete the pointer on the local search which has been constructed in the constructor - delete localSearch; - } + /** + * Default Constructor + * @param _initSol the first the solution of the walk + * @param _neighborhood neighborhood giving neighbor in random order + * @param _fullEval Fitness function, full evaluation function + * @param _eval neighbor evaluation, incremental evaluation function + * @param _distance the distance to measure the distance from the initial solution + * @param _nbStep Number of steps of the random walk + */ + moNeutralWalkSampling(EOT & _initSol, + moNeighborhood & _neighborhood, + eoEvalFunc& _fullEval, + moEval& _eval, + eoDistance & _distance, + unsigned int _nbStep) : + moSampling(init, * new moRandomNeutralWalk(_neighborhood, _fullEval, _eval, _nbStep), solutionStat), + init(_initSol), + distStat(_distance, _initSol), + neighborhoodStat(_neighborhood, _eval), + minStat(neighborhoodStat), + averageStat(neighborhoodStat), + stdStat(neighborhoodStat), + maxStat(neighborhoodStat), + nbSupStat(neighborhoodStat), + nbInfStat(neighborhoodStat), + sizeStat(neighborhoodStat), + ndStat(neighborhoodStat) + { + add(neighborhoodStat, false); + add(distStat); + add(minStat); + add(averageStat); + add(stdStat); + add(maxStat); + add(sizeStat); + add(nbInfStat); + add(ndStat); + add(nbSupStat); + } + + /** + * default destructor + */ + ~moNeutralWalkSampling() { + // delete the pointer on the local search which has been constructed in the constructor + delete localSearch; + } protected: - moSolInit init; - moSolutionStat solutionStat; - moDistanceStat distStat; - moNeighborhoodStat< Neighbor > neighborhoodStat; - moMinNeighborStat< Neighbor > minStat; - moAverageFitnessNeighborStat< Neighbor > averageStat; - moStdFitnessNeighborStat< Neighbor > stdStat; - moMaxNeighborStat< Neighbor > maxStat; - moNbSupNeighborStat< Neighbor > nbSupStat; - moNbInfNeighborStat< Neighbor > nbInfStat; - moSizeNeighborStat< Neighbor > sizeStat; - moNeutralDegreeNeighborStat< Neighbor > ndStat; + moSolInit init; + moSolutionStat solutionStat; + moDistanceStat distStat; + moNeighborhoodStat< Neighbor > neighborhoodStat; + moMinNeighborStat< Neighbor > minStat; + moAverageFitnessNeighborStat< Neighbor > averageStat; + moStdFitnessNeighborStat< Neighbor > stdStat; + moMaxNeighborStat< Neighbor > maxStat; + moNbSupNeighborStat< Neighbor > nbSupStat; + moNbInfNeighborStat< Neighbor > nbInfStat; + moSizeNeighborStat< Neighbor > sizeStat; + moNeutralDegreeNeighborStat< Neighbor > ndStat; }; diff --git a/trunk/paradiseo-mo/src/sampling/moRndBestFitnessCloudSampling.h b/trunk/paradiseo-mo/src/sampling/moRndBestFitnessCloudSampling.h index 1ac80f37a..d2adcfec3 100644 --- a/trunk/paradiseo-mo/src/sampling/moRndBestFitnessCloudSampling.h +++ b/trunk/paradiseo-mo/src/sampling/moRndBestFitnessCloudSampling.h @@ -44,66 +44,66 @@ #include /** - * To compute an estimation of the fitness cloud, - * i.e. the scatter plot of solution fitness versus neighbor fitness: + * To compute an estimation of the fitness cloud, + * i.e. the scatter plot of solution fitness versus neighbor fitness: * * Sample the fitness of random solution in the search space * and the best fitness of k random neighbor * * The values are collected during the random search - * + * */ template class moRndBestFitnessCloudSampling : public moFitnessCloudSampling { public: - typedef typename Neighbor::EOT EOT ; - - using moSampling::localSearch; - using moSampling::checkpoint; - using moSampling::monitorVec; - using moSampling::continuator; - using moFitnessCloudSampling::fitnessStat; + typedef typename Neighbor::EOT EOT ; - /** - * Default Constructor - * @param _init initialisation method of the solution - * @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood) - * @param _fullEval Fitness function, full evaluation function - * @param _eval neighbor evaluation, incremental evaluation function - * @param _nbSol Number of solutions in the sample - */ - moRndBestFitnessCloudSampling(eoInit & _init, - moNeighborhood & _neighborhood, - eoEvalFunc& _fullEval, - moEval& _eval, - unsigned int _nbSol) : - moFitnessCloudSampling(_init, _neighborhood, _fullEval, _eval, _nbSol), - neighborBestStat(_neighborhood, _eval) - { - // delete the dummy local search - delete localSearch; - - // random sampling - localSearch = new moRandomSearch(_init, _fullEval, _nbSol); + using moSampling::localSearch; + using moSampling::checkpoint; + using moSampling::monitorVec; + using moSampling::continuator; + using moFitnessCloudSampling::fitnessStat; - // delete the checkpoint with the wrong continuator - delete checkpoint; + /** + * Default Constructor + * @param _init initialisation method of the solution + * @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood) + * @param _fullEval Fitness function, full evaluation function + * @param _eval neighbor evaluation, incremental evaluation function + * @param _nbSol Number of solutions in the sample + */ + moRndBestFitnessCloudSampling(eoInit & _init, + moNeighborhood & _neighborhood, + eoEvalFunc& _fullEval, + moEval& _eval, + unsigned int _nbSol) : + moFitnessCloudSampling(_init, _neighborhood, _fullEval, _eval, _nbSol), + neighborBestStat(_neighborhood, _eval) + { + // delete the dummy local search + delete localSearch; - // set the continuator - continuator = localSearch->getContinuator(); + // random sampling + localSearch = new moRandomSearch(_init, _fullEval, _nbSol); - // re-construction of the checkpoint - checkpoint = new moCheckpoint(*continuator); - checkpoint->add(fitnessStat); - checkpoint->add(*monitorVec[0]); + // delete the checkpoint with the wrong continuator + delete checkpoint; - // one random neighbor - add(neighborBestStat); - } + // set the continuator + continuator = localSearch->getContinuator(); + + // re-construction of the checkpoint + checkpoint = new moCheckpoint(*continuator); + checkpoint->add(fitnessStat); + checkpoint->add(*monitorVec[0]); + + // one random neighbor + add(neighborBestStat); + } protected: - moNeighborBestStat< Neighbor > neighborBestStat; + moNeighborBestStat< Neighbor > neighborBestStat; }; diff --git a/trunk/paradiseo-mo/src/sampling/moRndRndFitnessCloudSampling.h b/trunk/paradiseo-mo/src/sampling/moRndRndFitnessCloudSampling.h index e13173d08..47a28eb99 100644 --- a/trunk/paradiseo-mo/src/sampling/moRndRndFitnessCloudSampling.h +++ b/trunk/paradiseo-mo/src/sampling/moRndRndFitnessCloudSampling.h @@ -44,66 +44,66 @@ #include /** - * To compute an estimation of the fitness cloud, - * i.e. the scatter plot of solution fitness versus neighbor fitness: + * To compute an estimation of the fitness cloud, + * i.e. the scatter plot of solution fitness versus neighbor fitness: * * Sample the fitness of random solution in the search space * and the fitness of one random neighbor * * The values are collected during the random search - * + * */ template class moRndRndFitnessCloudSampling : public moFitnessCloudSampling { public: - typedef typename Neighbor::EOT EOT ; - - using moSampling::localSearch; - using moSampling::checkpoint; - using moSampling::monitorVec; - using moSampling::continuator; - using moFitnessCloudSampling::fitnessStat; + typedef typename Neighbor::EOT EOT ; - /** - * Default Constructor - * @param _init initialisation method of the solution - * @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood) - * @param _fullEval Fitness function, full evaluation function - * @param _eval neighbor evaluation, incremental evaluation function - * @param _nbSol Number of solutions in the sample - */ - moRndRndFitnessCloudSampling(eoInit & _init, - moNeighborhood & _neighborhood, - eoEvalFunc& _fullEval, - moEval& _eval, - unsigned int _nbSol) : - moFitnessCloudSampling(_init, _neighborhood, _fullEval, _eval, _nbSol), - neighborFitnessStat(_neighborhood, _eval) - { - // delete the dummy local search - delete localSearch; - - // random sampling - localSearch = new moRandomSearch(_init, _fullEval, _nbSol); + using moSampling::localSearch; + using moSampling::checkpoint; + using moSampling::monitorVec; + using moSampling::continuator; + using moFitnessCloudSampling::fitnessStat; - // delete the checkpoint with the wrong continuator - delete checkpoint; + /** + * Default Constructor + * @param _init initialisation method of the solution + * @param _neighborhood neighborhood to get one random neighbor (supposed to be random neighborhood) + * @param _fullEval Fitness function, full evaluation function + * @param _eval neighbor evaluation, incremental evaluation function + * @param _nbSol Number of solutions in the sample + */ + moRndRndFitnessCloudSampling(eoInit & _init, + moNeighborhood & _neighborhood, + eoEvalFunc& _fullEval, + moEval& _eval, + unsigned int _nbSol) : + moFitnessCloudSampling(_init, _neighborhood, _fullEval, _eval, _nbSol), + neighborFitnessStat(_neighborhood, _eval) + { + // delete the dummy local search + delete localSearch; - // set the continuator - continuator = localSearch->getContinuator(); + // random sampling + localSearch = new moRandomSearch(_init, _fullEval, _nbSol); - // re-construction of the checkpoint - checkpoint = new moCheckpoint(*continuator); - checkpoint->add(fitnessStat); - checkpoint->add(*monitorVec[0]); + // delete the checkpoint with the wrong continuator + delete checkpoint; - // one random neighbor - add(neighborFitnessStat); - } + // set the continuator + continuator = localSearch->getContinuator(); + + // re-construction of the checkpoint + checkpoint = new moCheckpoint(*continuator); + checkpoint->add(fitnessStat); + checkpoint->add(*monitorVec[0]); + + // one random neighbor + add(neighborFitnessStat); + } protected: - moNeighborFitnessStat< Neighbor > neighborFitnessStat; + moNeighborFitnessStat< Neighbor > neighborFitnessStat; }; diff --git a/trunk/paradiseo-mo/src/sampling/moSampling.h b/trunk/paradiseo-mo/src/sampling/moSampling.h index d4179577c..84a8a1cb2 100644 --- a/trunk/paradiseo-mo/src/sampling/moSampling.h +++ b/trunk/paradiseo-mo/src/sampling/moSampling.h @@ -51,159 +51,159 @@ * To sample the search space: * A local search is used to sample the search space * Some statistics are computed at each step of the local search - * + * * Can be used to study the fitness landscape */ template class moSampling : public eoF { public: - typedef typename Neighbor::EOT EOT ; - - /** - * Default Constructor - * @param _init initialisation method of the solution - * @param _localSearch local search to sample the search space - * @param _stat statistic to compute during the search - * @param _monitoring the statistic is saved into the monitor if true - */ - template - moSampling(eoInit & _init, moLocalSearch & _localSearch, moStat & _stat, bool _monitoring = true) : init(_init), localSearch(&_localSearch), continuator(_localSearch.getContinuator()) - { - checkpoint = new moCheckpoint(*continuator); - add(_stat, _monitoring); - } + typedef typename Neighbor::EOT EOT ; - /** - * default destructor - */ - ~moSampling() { - // delete all monitors - for(unsigned i = 0; i < monitorVec.size(); i++) - delete monitorVec[i]; - - // delete the checkpoint - delete checkpoint ; - } - - /** - * Add a statistic - * @param _stat another statistic to compute during the search - * @param _monitoring the statistic is saved into the monitor if true - */ - template< class ValueType > - void add(moStat & _stat, bool _monitoring = true) { - checkpoint->add(_stat); - - if (_monitoring) { - moVectorMonitor * monitor = new moVectorMonitor(_stat); - monitorVec.push_back(monitor); - checkpoint->add(*monitor); + /** + * Default Constructor + * @param _init initialisation method of the solution + * @param _localSearch local search to sample the search space + * @param _stat statistic to compute during the search + * @param _monitoring the statistic is saved into the monitor if true + */ + template + moSampling(eoInit & _init, moLocalSearch & _localSearch, moStat & _stat, bool _monitoring = true) : init(_init), localSearch(&_localSearch), continuator(_localSearch.getContinuator()) + { + checkpoint = new moCheckpoint(*continuator); + add(_stat, _monitoring); } - } - /** - * To sample the search and get the statistics - * the statistics are stored in the moVectorMonitor vector - */ - void operator()(void) { - // clear all statistic vectors - for(unsigned i = 0; i < monitorVec.size(); i++) - monitorVec[i]->clear(); + /** + * default destructor + */ + ~moSampling() { + // delete all monitors + for (unsigned i = 0; i < monitorVec.size(); i++) + delete monitorVec[i]; - // change the checkpoint to compute the statistics - localSearch->setContinuator(*checkpoint); - - // the initial solution - EOT solution; - - // initialisation of the solution - init(solution); - - // compute the sampling - (*localSearch)(solution); - - // set back to initial continuator - localSearch->setContinuator(*continuator); - } - - /** - * to export the vectors of values into one file - * @param _filename file name - * @param _delim delimiter between statistics - */ - void fileExport(std::string _filename, std::string _delim = " ") { - // create file - std::ofstream os(_filename.c_str()); - - if (!os) { - std::string str = "moSampling: Could not open " + _filename; - throw std::runtime_error(str); + // delete the checkpoint + delete checkpoint ; } - - // all vector have the same size - unsigned vecSize = monitorVec[0]->size(); - for(unsigned int i = 0; i < vecSize; i++) { - os << monitorVec[0]->getValue(i); - - for(unsigned int j = 1; j < monitorVec.size(); j++) { - os << _delim.c_str() << monitorVec[j]->getValue(i); - } - - os << std::endl ; + /** + * Add a statistic + * @param _stat another statistic to compute during the search + * @param _monitoring the statistic is saved into the monitor if true + */ + template< class ValueType > + void add(moStat & _stat, bool _monitoring = true) { + checkpoint->add(_stat); + + if (_monitoring) { + moVectorMonitor * monitor = new moVectorMonitor(_stat); + monitorVec.push_back(monitor); + checkpoint->add(*monitor); + } } - - } - /** - * to export one vector of values into a file - * @param _col number of vector to print into file - * @param _filename file name - */ - void fileExport(unsigned int _col, std::string _filename) { - if (_col >= monitorVec.size()) { - std::string str = "moSampling: Could not export into file the vector. The index does not exists (too large)"; - throw std::runtime_error(str); + /** + * To sample the search and get the statistics + * the statistics are stored in the moVectorMonitor vector + */ + void operator()(void) { + // clear all statistic vectors + for (unsigned i = 0; i < monitorVec.size(); i++) + monitorVec[i]->clear(); + + // change the checkpoint to compute the statistics + localSearch->setContinuator(*checkpoint); + + // the initial solution + EOT solution; + + // initialisation of the solution + init(solution); + + // compute the sampling + (*localSearch)(solution); + + // set back to initial continuator + localSearch->setContinuator(*continuator); } - - monitorVec[_col]->fileExport(_filename); - } - /** - * to get one vector of values - * @param _numStat number of stattistics to get (in order of creation) - * @return the vector of value (all values are converted in double) - */ - const std::vector & getValues(unsigned int _numStat) { - return monitorVec[_numStat]->getValues(); - } + /** + * to export the vectors of values into one file + * @param _filename file name + * @param _delim delimiter between statistics + */ + void fileExport(std::string _filename, std::string _delim = " ") { + // create file + std::ofstream os(_filename.c_str()); - /** - * to get one vector of solutions values - * @param _numStat number of stattistics to get (in order of creation) - * @return the vector of value (all values are converted in double) - */ - const std::vector & getSolutions(unsigned int _numStat) { - return monitorVec[_numStat]->getSolutions(); - } + if (!os) { + std::string str = "moSampling: Could not open " + _filename; + throw std::runtime_error(str); + } + + // all vector have the same size + unsigned vecSize = monitorVec[0]->size(); + + for (unsigned int i = 0; i < vecSize; i++) { + os << monitorVec[0]->getValue(i); + + for (unsigned int j = 1; j < monitorVec.size(); j++) { + os << _delim.c_str() << monitorVec[j]->getValue(i); + } + + os << std::endl ; + } + + } + + /** + * to export one vector of values into a file + * @param _col number of vector to print into file + * @param _filename file name + */ + void fileExport(unsigned int _col, std::string _filename) { + if (_col >= monitorVec.size()) { + std::string str = "moSampling: Could not export into file the vector. The index does not exists (too large)"; + throw std::runtime_error(str); + } + + monitorVec[_col]->fileExport(_filename); + } + + /** + * to get one vector of values + * @param _numStat number of stattistics to get (in order of creation) + * @return the vector of value (all values are converted in double) + */ + const std::vector & 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 & getSolutions(unsigned int _numStat) { + return monitorVec[_numStat]->getSolutions(); + } + + /** + * @return name of the class + */ + virtual std::string className(void) const { + return "moSampling"; + } - /** - * @return name of the class - */ - virtual std::string className(void) const { - return "moSampling"; - } - protected: - eoInit & init; - moLocalSearch * localSearch; + eoInit & init; + moLocalSearch * localSearch; - moContinuator * continuator; - moCheckpoint * checkpoint; + moContinuator * continuator; + moCheckpoint * checkpoint; - // std::vector*> statVec; - std::vector< moVectorMonitor *> monitorVec; + // std::vector*> statVec; + std::vector< moVectorMonitor *> monitorVec; }; diff --git a/trunk/paradiseo-mo/src/sampling/moStatistics.h b/trunk/paradiseo-mo/src/sampling/moStatistics.h index 2dd461067..7dd5731ea 100644 --- a/trunk/paradiseo-mo/src/sampling/moStatistics.h +++ b/trunk/paradiseo-mo/src/sampling/moStatistics.h @@ -41,174 +41,174 @@ /** * Tools to compute some basic statistics - * + * * Remember it is better to use some statistic tool like R, etc. * But it could be usefull to have here in paradisEO */ -class moStatistics +class moStatistics { public: - /** - * Default Constructor - */ - moStatistics() { } + /** + * Default Constructor + */ + moStatistics() { } - /** - * To compute min, max , average and standard deviation of a vector of double - * - * @param data vector of double - * @param min to compute - * @param max to compute - * @param avg average to compute - * @param std standard deviation to compute - */ - void basic(const std::vector & data, - double & min, double & max, double & avg, double & std) { - - if (data.size() == 0) { - min = 0.0; - max = 0.0; - avg = 0.0; - std = 0.0; - } else { - unsigned int n = data.size(); + /** + * To compute min, max , average and standard deviation of a vector of double + * + * @param data vector of double + * @param min to compute + * @param max to compute + * @param avg average to compute + * @param std standard deviation to compute + */ + void basic(const std::vector & data, + double & min, double & max, double & avg, double & std) { - min = data[0]; - max = data[0]; - avg = 0.0; - std = 0.0; + if (data.size() == 0) { + min = 0.0; + max = 0.0; + avg = 0.0; + std = 0.0; + } else { + unsigned int n = data.size(); - double d; - for(unsigned int i = 0; i < n; i++) { - d = data[i]; - if (d < min) - min = d; - if (max < d) - max = d; - avg += d; - std += d * d; - } + min = data[0]; + max = data[0]; + avg = 0.0; + std = 0.0; - avg /= n; + double d; + for (unsigned int i = 0; i < n; i++) { + d = data[i]; + if (d < min) + min = d; + if (max < d) + max = d; + avg += d; + std += d * d; + } - std = std / n - avg * avg ; - if (std > 0) - std = sqrt(std); + avg /= n; + + std = std / n - avg * avg ; + if (std > 0) + std = sqrt(std); + } } - } - /** - * To compute the distance between solutions - * - * @param data vector of solutions - * @param distance method to compute the distance - * @param matrix matrix of distances between solutions - */ - template - void distances(const std::vector & data, eoDistance & distance, - std::vector< std::vector > & matrix) { - if (data.size() == 0) { - matrix.resize(0); - } else { - unsigned int n = data.size(); + /** + * To compute the distance between solutions + * + * @param data vector of solutions + * @param distance method to compute the distance + * @param matrix matrix of distances between solutions + */ + template + void distances(const std::vector & data, eoDistance & distance, + std::vector< std::vector > & matrix) { + if (data.size() == 0) { + matrix.resize(0); + } else { + unsigned int n = data.size(); - matrix.resize(n); - for(unsigned i = 0; i < n; i++) - matrix[i].resize(n); + matrix.resize(n); + for (unsigned i = 0; i < n; i++) + matrix[i].resize(n); - unsigned j; - for(unsigned i = 0; i < n; i++) { - matrix[i][i] = 0.0; - for(j = 0; j < i; j++) { - matrix[i][j] = distance(data[i], data[j]); - matrix[j][i] = matrix[i][j]; - } - } + unsigned j; + for (unsigned i = 0; i < n; i++) { + matrix[i][i] = 0.0; + for (j = 0; j < i; j++) { + matrix[i][j] = distance(data[i], data[j]); + matrix[j][i] = matrix[i][j]; + } + } + } } - } - /** - * To compute the autocorrelation and partial autocorrelation - * - * @param data vector of double - * @param nbS number of correlation coefficients - * @param rho autocorrelation coefficients - * @param phi partial autocorrelation coefficients - */ - void autocorrelation(const std::vector & data, unsigned int nbS, - std::vector & rho, std::vector & phi) { - if (data.size() == 0) { - rho.resize(0); - phi.resize(0); - } else { - unsigned int n = data.size(); + /** + * To compute the autocorrelation and partial autocorrelation + * + * @param data vector of double + * @param nbS number of correlation coefficients + * @param rho autocorrelation coefficients + * @param phi partial autocorrelation coefficients + */ + void autocorrelation(const std::vector & data, unsigned int nbS, + std::vector & rho, std::vector & phi) { + if (data.size() == 0) { + rho.resize(0); + phi.resize(0); + } else { + unsigned int n = data.size(); - double cov[nbS+1]; - double m[nbS+1]; - double sig[nbS+1]; + double cov[nbS+1]; + double m[nbS+1]; + double sig[nbS+1]; - rho.resize(nbS+1); - phi.resize(nbS+1); - rho[0] = 1.0; - phi[0] = 1.0; // ? - - unsigned s, k; + rho.resize(nbS+1); + phi.resize(nbS+1); + rho[0] = 1.0; + phi[0] = 1.0; // ? - for(s = 0; s <= nbS; s++) { - cov[s] = 0; - m[s] = 0; - sig[s] = 0; - } + unsigned s, k; - double m0, s0; - unsigned j; + for (s = 0; s <= nbS; s++) { + cov[s] = 0; + m[s] = 0; + sig[s] = 0; + } - k = 0; - s = nbS; - while (s > 0) { - while (k + s < n) { - for(j = 0; j <= s; j++) { - m[j] += data[k+j]; - sig[j] += data[k+j] * data[k+j]; - cov[j] += data[k] * data[k+j]; - } - k++; - } - - m[s] /= n - s; - sig[s] = sig[s] / (n - s) - m[s] * m[s]; - if (sig[s] <= 0) - sig[s] = 0; - else - sig[s] = sqrt(sig[s]); - m0 = m[0] / (n - s); - s0 = sqrt(sig[0] / (n - s) - m0 * m0); - cov[s] = cov[s] / (n - s) - (m[0] / (n - s)) * m[s]; - rho[s] = cov[s] / (sig[s] * s0); - s--; - } + double m0, s0; + unsigned j; - double phi2[nbS+1][nbS+1]; - double tmp1, tmp2; + k = 0; + s = nbS; + while (s > 0) { + while (k + s < n) { + for (j = 0; j <= s; j++) { + m[j] += data[k+j]; + sig[j] += data[k+j] * data[k+j]; + cov[j] += data[k] * data[k+j]; + } + k++; + } - phi2[1][1] = rho[1]; - for(k = 2; k <= nbS; k++) { - tmp1 = 0; - tmp2 = 0; - for(j = 1; j < k; j++) { - tmp1 += phi2[k-1][j] * rho[k-j]; - tmp2 += phi2[k-1][j] * rho[j]; - } - phi2[k][k] = (rho[k] - tmp1) / (1 - tmp2); - for(j = 1; j < k; j++) - phi2[k][j] = phi2[k-1][j] - phi2[k][k] * phi2[k-1][k-j]; - } - - for(j = 1; j <= nbS; j++) - phi[j] = phi2[j][j]; - + m[s] /= n - s; + sig[s] = sig[s] / (n - s) - m[s] * m[s]; + if (sig[s] <= 0) + sig[s] = 0; + else + sig[s] = sqrt(sig[s]); + m0 = m[0] / (n - s); + s0 = sqrt(sig[0] / (n - s) - m0 * m0); + cov[s] = cov[s] / (n - s) - (m[0] / (n - s)) * m[s]; + rho[s] = cov[s] / (sig[s] * s0); + s--; + } + + double phi2[nbS+1][nbS+1]; + double tmp1, tmp2; + + phi2[1][1] = rho[1]; + for (k = 2; k <= nbS; k++) { + tmp1 = 0; + tmp2 = 0; + for (j = 1; j < k; j++) { + tmp1 += phi2[k-1][j] * rho[k-j]; + tmp2 += phi2[k-1][j] * rho[j]; + } + phi2[k][k] = (rho[k] - tmp1) / (1 - tmp2); + for (j = 1; j < k; j++) + phi2[k][j] = phi2[k-1][j] - phi2[k][k] * phi2[k-1][k-j]; + } + + for (j = 1; j <= nbS; j++) + phi[j] = phi2[j][j]; + + } } - } };