From 39709d3d1255a0603c2509818bd29a87082ac56f Mon Sep 17 00:00:00 2001 From: canape Date: Fri, 16 Nov 2007 11:29:25 +0000 Subject: [PATCH] New style for MOEO git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@788 331e1502-861f-0410-8da2-ba01fb791d7f --- trunk/paradiseo-moeo/doc/index.h | 8 +- trunk/paradiseo-moeo/src/algo/moeoAlgo.h | 5 +- .../paradiseo-moeo/src/algo/moeoCombinedLS.h | 20 +- trunk/paradiseo-moeo/src/algo/moeoEA.h | 5 +- trunk/paradiseo-moeo/src/algo/moeoEasyEA.h | 119 ++-- trunk/paradiseo-moeo/src/algo/moeoHybridLS.h | 26 +- trunk/paradiseo-moeo/src/algo/moeoIBEA.h | 59 +- trunk/paradiseo-moeo/src/algo/moeoIBMOLS.h | 509 +++++++++--------- .../src/algo/moeoIteratedIBMOLS.h | 100 ++-- trunk/paradiseo-moeo/src/algo/moeoLS.h | 5 +- trunk/paradiseo-moeo/src/algo/moeoNSGA.h | 59 +- trunk/paradiseo-moeo/src/algo/moeoNSGAII.h | 67 +-- .../paradiseo-moeo/src/archive/moeoArchive.h | 92 ++-- .../comparator/moeoAggregativeComparator.h | 12 +- .../src/comparator/moeoComparator.h | 5 +- .../moeoDiversityThenFitnessComparator.h | 16 +- .../moeoFitnessThenDiversityComparator.h | 16 +- .../moeoGDominanceObjectiveVectorComparator.h | 52 +- .../moeoObjectiveObjectiveVectorComparator.h | 22 +- .../moeoObjectiveVectorComparator.h | 5 +- .../comparator/moeoOneObjectiveComparator.h | 16 +- .../moeoParetoObjectiveVectorComparator.h | 42 +- trunk/paradiseo-moeo/src/core/MOEO.h | 127 ++--- trunk/paradiseo-moeo/src/core/moeoBitVector.h | 38 +- trunk/paradiseo-moeo/src/core/moeoEvalFunc.h | 5 +- .../src/core/moeoObjectiveVector.h | 16 +- .../src/core/moeoObjectiveVectorTraits.cpp | 2 +- .../src/core/moeoObjectiveVectorTraits.h | 60 ++- .../src/core/moeoRealObjectiveVector.h | 58 +- .../paradiseo-moeo/src/core/moeoRealVector.h | 20 +- trunk/paradiseo-moeo/src/core/moeoVector.h | 60 +-- .../src/distance/moeoDistance.h | 8 +- .../src/distance/moeoDistanceMatrix.h | 34 +- .../src/distance/moeoEuclideanDistance.h | 24 +- .../src/distance/moeoManhattanDistance.h | 24 +- .../src/distance/moeoNormalizedDistance.h | 48 +- .../moeoCrowdingDiversityAssignment.h | 70 +-- .../src/diversity/moeoDiversityAssignment.h | 10 +- .../diversity/moeoDummyDiversityAssignment.h | 18 +- ...oFrontByFrontCrowdingDiversityAssignment.h | 100 ++-- ...eoFrontByFrontSharingDiversityAssignment.h | 44 +- .../moeoSharingDiversityAssignment.h | 58 +- .../src/do/make_checkpoint_moeo.h | 196 +++---- .../src/do/make_continue_moeo.h | 94 ++-- trunk/paradiseo-moeo/src/do/make_ea_moeo.h | 262 ++++----- trunk/paradiseo-moeo/src/do/make_ls_moeo.h | 115 ++-- .../moeoAchievementFitnessAssignment.h | 64 +-- ...oeoBinaryIndicatorBasedFitnessAssignment.h | 8 +- .../moeoCriterionBasedFitnessAssignment.h | 5 +- .../src/fitness/moeoDummyFitnessAssignment.h | 18 +- ...ExpBinaryIndicatorBasedFitnessAssignment.h | 112 ++-- ...FastNonDominatedSortingFitnessAssignment.h | 191 +++---- .../src/fitness/moeoFitnessAssignment.h | 10 +- .../moeoIndicatorBasedFitnessAssignment.h | 5 +- .../moeoParetoBasedFitnessAssignment.h | 7 +- ...encePointIndicatorBasedFitnessAssignment.h | 44 +- .../src/fitness/moeoScalarFitnessAssignment.h | 7 +- ...moeoUnaryIndicatorBasedFitnessAssignment.h | 5 +- .../metric/moeoAdditiveEpsilonBinaryMetric.h | 48 +- .../src/metric/moeoContributionMetric.h | 98 ++-- .../src/metric/moeoEntropyMetric.h | 184 ++++--- .../src/metric/moeoHypervolumeBinaryMetric.h | 88 +-- trunk/paradiseo-moeo/src/metric/moeoMetric.h | 23 +- ...NormalizedSolutionVsSolutionBinaryMetric.h | 30 +- .../src/move/moeoMoveIncrEval.h | 5 +- .../src/replacement/moeoElitistReplacement.h | 55 +- .../moeoEnvironmentalReplacement.h | 73 +-- .../replacement/moeoGenerationalReplacement.h | 10 +- .../src/replacement/moeoReplacement.h | 5 +- .../src/selection/moeoDetTournamentSelect.h | 34 +- .../src/selection/moeoRandomSelect.h | 13 +- .../src/selection/moeoRouletteSelect.h | 24 +- .../src/selection/moeoSelectFromPopAndArch.h | 28 +- .../src/selection/moeoSelectOne.h | 5 +- .../src/selection/moeoSelectors.h | 94 ++-- .../src/selection/moeoStochTournamentSelect.h | 44 +- .../moeoArchiveObjectiveVectorSavingUpdater.h | 47 +- .../src/utils/moeoArchiveUpdater.h | 15 +- .../src/utils/moeoBinaryMetricSavingUpdater.h | 50 +- .../utils/moeoConvertPopToObjectiveVectors.h | 18 +- trunk/paradiseo-moeo/test/t-moeo.cpp | 2 +- .../tutorial/Lesson1/FlowShopEA.cpp | 90 ++-- .../paradiseo-moeo/tutorial/Lesson2/Sch1.cpp | 95 ++-- .../tutorial/examples/flowshop/FlowShop.cpp | 6 +- .../tutorial/examples/flowshop/FlowShop.h | 8 +- .../flowshop/FlowShopBenchmarkParser.cpp | 99 ++-- .../flowshop/FlowShopBenchmarkParser.h | 10 +- .../examples/flowshop/FlowShopEval.cpp | 57 +- .../tutorial/examples/flowshop/FlowShopEval.h | 10 +- .../examples/flowshop/FlowShopInit.cpp | 32 +- .../tutorial/examples/flowshop/FlowShopInit.h | 10 +- .../flowshop/FlowShopObjectiveVector.h | 2 +- .../FlowShopObjectiveVectorTraits.cpp | 14 +- .../flowshop/FlowShopObjectiveVectorTraits.h | 8 +- .../flowshop/FlowShopOpCrossoverQuad.cpp | 93 ++-- .../flowshop/FlowShopOpCrossoverQuad.h | 10 +- .../flowshop/FlowShopOpMutationExchange.cpp | 51 +- .../flowshop/FlowShopOpMutationExchange.h | 8 +- .../flowshop/FlowShopOpMutationShift.cpp | 71 +-- .../flowshop/FlowShopOpMutationShift.h | 8 +- .../examples/flowshop/make_eval_FlowShop.h | 45 +- .../flowshop/make_genotype_FlowShop.h | 35 +- .../examples/flowshop/make_op_FlowShop.h | 116 ++-- 103 files changed, 2592 insertions(+), 2506 deletions(-) diff --git a/trunk/paradiseo-moeo/doc/index.h b/trunk/paradiseo-moeo/doc/index.h index af1e857ef..7d66328c1 100644 --- a/trunk/paradiseo-moeo/doc/index.h +++ b/trunk/paradiseo-moeo/doc/index.h @@ -3,11 +3,11 @@ @section Introduction ParadisEO-MOEO is a white-box object-oriented generic framework dedicated to the flexible design of evolutionary multi-objective algorithms. -This paradigm-free software embeds some features and techniques for Pareto-based resolution and +This paradigm-free software embeds some features and techniques for Pareto-based resolution and aims to provide a set of classes allowing to ease and speed up the development of computationally efficient programs. -It is based on a clear conceptual distinction between the solution methods and the multi-objective problems they are intended to solve. +It is based on a clear conceptual distinction between the solution methods and the multi-objective problems they are intended to solve. This separation confers a maximum design and code reuse. -ParadisEO-MOEO provides a broad range of archive-related features (such as elitism or performance metrics) +ParadisEO-MOEO provides a broad range of archive-related features (such as elitism or performance metrics) and the most common Pareto-based fitness assignment strategies (MOGA, NSGA, SPEA, IBEA and more). Furthermore, parallel and distributed models as well as hybridization mechanisms can be applied to an algorithm designed within ParadisEO-MOEO using the whole version of ParadisEO. @@ -29,7 +29,7 @@ href="../../README">README file in the top-directory of the source-tree. @section Design -For an introduction to the design of ParadisEO-MOEO, +For an introduction to the design of ParadisEO-MOEO, you can look at the ParadisEO website. diff --git a/trunk/paradiseo-moeo/src/algo/moeoAlgo.h b/trunk/paradiseo-moeo/src/algo/moeoAlgo.h index 15fcb4a5e..39b01f394 100644 --- a/trunk/paradiseo-moeo/src/algo/moeoAlgo.h +++ b/trunk/paradiseo-moeo/src/algo/moeoAlgo.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -41,6 +41,7 @@ /** * Abstract class for multi-objective algorithms. */ -class moeoAlgo {}; +class moeoAlgo + {}; #endif /*MOEOALGO_H_*/ diff --git a/trunk/paradiseo-moeo/src/algo/moeoCombinedLS.h b/trunk/paradiseo-moeo/src/algo/moeoCombinedLS.h index 8d14b335e..50b2fb258 100644 --- a/trunk/paradiseo-moeo/src/algo/moeoCombinedLS.h +++ b/trunk/paradiseo-moeo/src/algo/moeoCombinedLS.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -48,8 +48,8 @@ */ template < class MOEOT, class Type > class moeoCombinedLS : public moeoLS < MOEOT, Type > -{ -public: + { + public: /** * Ctor @@ -57,7 +57,7 @@ public: */ moeoCombinedLS(moeoLS < MOEOT, Type > & _first_mols) { - combinedLS.push_back (& _first_mols); + combinedLS.push_back (& _first_mols); } /** @@ -65,9 +65,9 @@ public: * @param _mols the multi-objective local search to add */ void add(moeoLS < MOEOT, Type > & _mols) - { + { combinedLS.push_back(& _mols); - } + } /** * Gives a new solution in order to explore the neigborhood. @@ -77,16 +77,16 @@ public: */ void operator () (Type _type, moeoArchive < MOEOT > & _arch) { - for (unsigned int i=0; i operator()(_type, _arch); + for (unsigned int i=0; i operator()(_type, _arch); } -private: + private: /** the vector that contains the combined LS */ std::vector< moeoLS < MOEOT, Type > * > combinedLS; -}; + }; #endif /*MOEOCOMBINEDLS_H_*/ diff --git a/trunk/paradiseo-moeo/src/algo/moeoEA.h b/trunk/paradiseo-moeo/src/algo/moeoEA.h index 37eaccbff..9e6ba3e48 100644 --- a/trunk/paradiseo-moeo/src/algo/moeoEA.h +++ b/trunk/paradiseo-moeo/src/algo/moeoEA.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,6 +45,7 @@ * Abstract class for multi-objective evolutionary algorithms. */ template < class MOEOT > -class moeoEA : public moeoAlgo, public eoAlgo < MOEOT > {}; +class moeoEA : public moeoAlgo, public eoAlgo < MOEOT > + {}; #endif /*MOEOEA_H_*/ diff --git a/trunk/paradiseo-moeo/src/algo/moeoEasyEA.h b/trunk/paradiseo-moeo/src/algo/moeoEasyEA.h index e9d77d19d..20cb0c8b8 100755 --- a/trunk/paradiseo-moeo/src/algo/moeoEasyEA.h +++ b/trunk/paradiseo-moeo/src/algo/moeoEasyEA.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -56,8 +56,8 @@ */ template < class MOEOT > class moeoEasyEA: public moeoEA < MOEOT > -{ -public: + { + public: /** * Ctor taking a breed and merge. @@ -71,9 +71,9 @@ public: */ moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoBreed < MOEOT > & _breed, moeoReplacement < MOEOT > & _replace, moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false) - : - continuator(_continuator), eval (_eval), loopEval(_eval), popEval(loopEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(dummyMerge, dummyReduce), replace(_replace), - fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection) + : + continuator(_continuator), eval (_eval), loopEval(_eval), popEval(loopEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(dummyMerge, dummyReduce), replace(_replace), + fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection) {} @@ -89,9 +89,9 @@ public: */ moeoEasyEA(eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoBreed < MOEOT > & _breed, moeoReplacement < MOEOT > & _replace, moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false) - : - continuator(_continuator), eval (dummyEval), loopEval(dummyEval), popEval(_popEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(dummyMerge, dummyReduce), replace(_replace), - fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection) + : + continuator(_continuator), eval (dummyEval), loopEval(dummyEval), popEval(_popEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(dummyMerge, dummyReduce), replace(_replace), + fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection) {} @@ -108,9 +108,9 @@ public: */ moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoBreed < MOEOT > & _breed, eoMerge < MOEOT > & _merge, eoReduce< MOEOT > & _reduce, moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false) - : - continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(_merge,_reduce), replace(mergeReduce), - fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection) + : + continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(_merge,_reduce), replace(mergeReduce), + fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection) {} @@ -127,9 +127,9 @@ public: */ moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoSelect < MOEOT > & _select, eoTransform < MOEOT > & _transform, moeoReplacement < MOEOT > & _replace, moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false) - : - continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(_select, _transform), breed(selectTransform), mergeReduce(dummyMerge, dummyReduce), replace(_replace), - fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection) + : + continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(_select, _transform), breed(selectTransform), mergeReduce(dummyMerge, dummyReduce), replace(_replace), + fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection) {} @@ -147,9 +147,9 @@ public: */ moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoSelect < MOEOT > & _select, eoTransform < MOEOT > & _transform, eoMerge < MOEOT > & _merge, eoReduce< MOEOT > & _reduce, moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false) - : - continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(_select, _transform), breed(selectTransform), mergeReduce(_merge,_reduce), replace(mergeReduce), - fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection) + : + continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(_select, _transform), breed(selectTransform), mergeReduce(_merge,_reduce), replace(mergeReduce), + fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection) {} @@ -159,45 +159,46 @@ public: */ virtual void operator()(eoPop < MOEOT > & _pop) { - eoPop < MOEOT > offspring, empty_pop; - popEval(empty_pop, _pop); // A first eval of pop. - bool firstTime = true; - do + eoPop < MOEOT > offspring, empty_pop; + popEval(empty_pop, _pop); // A first eval of pop. + bool firstTime = true; + do { - try + try { - unsigned int pSize = _pop.size(); - offspring.clear(); // new offspring - // fitness and diversity assignment (if you want to or if it is the first generation) - if (evalFitAndDivBeforeSelection || firstTime) + unsigned int pSize = _pop.size(); + offspring.clear(); // new offspring + // fitness and diversity assignment (if you want to or if it is the first generation) + if (evalFitAndDivBeforeSelection || firstTime) { - firstTime = false; - fitnessEval(_pop); - diversityEval(_pop); + firstTime = false; + fitnessEval(_pop); + diversityEval(_pop); } - breed(_pop, offspring); - popEval(_pop, offspring); // eval of parents + offspring if necessary - replace(_pop, offspring); // after replace, the new pop. is in _pop - if (pSize > _pop.size()) + breed(_pop, offspring); + popEval(_pop, offspring); // eval of parents + offspring if necessary + replace(_pop, offspring); // after replace, the new pop. is in _pop + if (pSize > _pop.size()) { - throw std::runtime_error("Population shrinking!"); + throw std::runtime_error("Population shrinking!"); } - else if (pSize < _pop.size()) + else if (pSize < _pop.size()) { - throw std::runtime_error("Population growing!"); + throw std::runtime_error("Population growing!"); } } - catch (std::exception& e) + catch (std::exception& e) { - std::string s = e.what(); - s.append( " in moeoEasyEA"); - throw std::runtime_error( s ); + std::string s = e.what(); + s.append( " in moeoEasyEA"); + throw std::runtime_error( s ); } - } while (continuator(_pop)); + } + while (continuator(_pop)); } -protected: + protected: /** the stopping criteria */ eoContinue < MOEOT > & continuator; @@ -222,22 +223,34 @@ protected: /** if this parameter is set to 'true', the fitness and the diversity of the whole population will be re-evaluated before the selection process */ bool evalFitAndDivBeforeSelection; /** a dummy eval */ - class eoDummyEval : public eoEvalFunc < MOEOT > - { public: /** the dummy functor */ - void operator()(MOEOT &) {}} dummyEval; + class eoDummyEval : public eoEvalFunc < MOEOT > + { + public: /** the dummy functor */ + void operator()(MOEOT &) + {} + } + dummyEval; /** a dummy select */ - class eoDummySelect : public eoSelect < MOEOT > - { public: /** the dummy functor */ - void operator()(const eoPop < MOEOT > &, eoPop < MOEOT > &) {} } dummySelect; + class eoDummySelect : public eoSelect < MOEOT > + { + public: /** the dummy functor */ + void operator()(const eoPop < MOEOT > &, eoPop < MOEOT > &) + {} + } + dummySelect; /** a dummy transform */ - class eoDummyTransform : public eoTransform < MOEOT > - { public: /** the dummy functor */ - void operator()(eoPop < MOEOT > &) {} } dummyTransform; + class eoDummyTransform : public eoTransform < MOEOT > + { + public: /** the dummy functor */ + void operator()(eoPop < MOEOT > &) + {} + } + dummyTransform; /** a dummy merge */ eoNoElitism < MOEOT > dummyMerge; /** a dummy reduce */ eoTruncate < MOEOT > dummyReduce; -}; + }; #endif /*MOEOEASYEA_H_*/ diff --git a/trunk/paradiseo-moeo/src/algo/moeoHybridLS.h b/trunk/paradiseo-moeo/src/algo/moeoHybridLS.h index 070e9128a..3f7af06b4 100644 --- a/trunk/paradiseo-moeo/src/algo/moeoHybridLS.h +++ b/trunk/paradiseo-moeo/src/algo/moeoHybridLS.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -51,8 +51,8 @@ */ template < class MOEOT > class moeoHybridLS : public eoUpdater -{ -public: + { + public: /** * Ctor @@ -62,7 +62,7 @@ public: * @param _arch the archive */ moeoHybridLS (eoContinue < MOEOT > & _term, eoSelect < MOEOT > & _select, moeoLS < MOEOT, MOEOT > & _mols, moeoArchive < MOEOT > & _arch) : - term(_term), select(_select), mols(_mols), arch(_arch) + term(_term), select(_select), mols(_mols), arch(_arch) {} @@ -71,21 +71,21 @@ public: */ void operator () () { - if (! term (arch)) + if (! term (arch)) { - // selection of solutions - eoPop < MOEOT > selectedSolutions; - select(arch, selectedSolutions); - // apply the local search to every selected solution - for (unsigned int i=0; i selectedSolutions; + select(arch, selectedSolutions); + // apply the local search to every selected solution + for (unsigned int i=0; i & term; @@ -96,6 +96,6 @@ private: /** archive */ moeoArchive < MOEOT > & arch; -}; + }; #endif /*MOEOHYBRIDLS_H_*/ diff --git a/trunk/paradiseo-moeo/src/algo/moeoIBEA.h b/trunk/paradiseo-moeo/src/algo/moeoIBEA.h index b3a196839..cbfe49298 100644 --- a/trunk/paradiseo-moeo/src/algo/moeoIBEA.h +++ b/trunk/paradiseo-moeo/src/algo/moeoIBEA.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -61,8 +61,8 @@ */ template < class MOEOT > class moeoIBEA : public moeoEA < MOEOT > -{ -public: + { + public: /** The type of objective vector */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -77,8 +77,8 @@ public: * @param _kappa scaling factor kappa */ moeoIBEA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) : - defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2), - fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed) + defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2), + fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed) {} @@ -91,8 +91,8 @@ public: * @param _kappa scaling factor kappa */ moeoIBEA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) : - defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2), - fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed) + defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2), + fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed) {} @@ -108,9 +108,9 @@ public: * @param _kappa scaling factor kappa */ moeoIBEA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) : - defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2), - fitnessAssignment(_metric, _kappa), replace (fitnessAssignment, dummyDiversityAssignment), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut), - genBreed (select, defaultSGAGenOp), breed (genBreed) + defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2), + fitnessAssignment(_metric, _kappa), replace (fitnessAssignment, dummyDiversityAssignment), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut), + genBreed (select, defaultSGAGenOp), breed (genBreed) {} @@ -123,8 +123,8 @@ public: * @param _kappa scaling factor kappa */ moeoIBEA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) : - continuator(_continuator), popEval(_eval), select(2), - fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed) + continuator(_continuator), popEval(_eval), select(2), + fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed) {} @@ -137,8 +137,8 @@ public: * @param _kappa scaling factor kappa */ moeoIBEA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) : - continuator(_continuator), popEval(_eval), select(2), - fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed) + continuator(_continuator), popEval(_eval), select(2), + fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed) {} @@ -148,24 +148,25 @@ public: */ virtual void operator () (eoPop < MOEOT > &_pop) { - eoPop < MOEOT > offspring, empty_pop; - popEval (empty_pop, _pop); // a first eval of _pop - // evaluate fitness and diversity - fitnessAssignment(_pop); - dummyDiversityAssignment(_pop); - do + eoPop < MOEOT > offspring, empty_pop; + popEval (empty_pop, _pop); // a first eval of _pop + // evaluate fitness and diversity + fitnessAssignment(_pop); + dummyDiversityAssignment(_pop); + do { - // generate offspring, worths are recalculated if necessary - breed (_pop, offspring); - // eval of offspring - popEval (_pop, offspring); - // after replace, the new pop is in _pop. Worths are recalculated if necessary - replace (_pop, offspring); - } while (continuator (_pop)); + // generate offspring, worths are recalculated if necessary + breed (_pop, offspring); + // eval of offspring + popEval (_pop, offspring); + // after replace, the new pop is in _pop. Worths are recalculated if necessary + replace (_pop, offspring); + } + while (continuator (_pop)); } -protected: + protected: /** a continuator based on the number of generations (used as default) */ eoGenContinue < MOEOT > defaultGenContinuator; @@ -188,6 +189,6 @@ protected: /** breeder */ eoBreed < MOEOT > & breed; -}; + }; #endif /*MOEOIBEA_H_*/ diff --git a/trunk/paradiseo-moeo/src/algo/moeoIBMOLS.h b/trunk/paradiseo-moeo/src/algo/moeoIBMOLS.h index 5606b9dfe..dca823463 100755 --- a/trunk/paradiseo-moeo/src/algo/moeoIBMOLS.h +++ b/trunk/paradiseo-moeo/src/algo/moeoIBMOLS.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -56,8 +56,8 @@ */ template < class MOEOT, class Move > class moeoIBMOLS : public moeoLS < MOEOT, eoPop < MOEOT > & > -{ -public: + { + public: /** The type of objective vector */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -73,19 +73,19 @@ public: * @param _continuator the stopping criteria */ moeoIBMOLS( - moMoveInit < Move > & _moveInit, - moNextMove < Move > & _nextMove, - eoEvalFunc < MOEOT > & _eval, - moeoMoveIncrEval < Move > & _moveIncrEval, - moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment, - eoContinue < MOEOT > & _continuator + moMoveInit < Move > & _moveInit, + moNextMove < Move > & _nextMove, + eoEvalFunc < MOEOT > & _eval, + moeoMoveIncrEval < Move > & _moveIncrEval, + moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment, + eoContinue < MOEOT > & _continuator ) : - moveInit(_moveInit), - nextMove(_nextMove), - eval(_eval), - moveIncrEval(_moveIncrEval), - fitnessAssignment (_fitnessAssignment), - continuator (_continuator) + moveInit(_moveInit), + nextMove(_nextMove), + eval(_eval), + moveIncrEval(_moveIncrEval), + fitnessAssignment (_fitnessAssignment), + continuator (_continuator) {} @@ -97,32 +97,33 @@ public: */ void operator() (eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _arch) { - // evaluation of the objective values - /* - for (unsigned int i=0; i<_pop.size(); i++) - { - eval(_pop[i]); - } - */ - // fitness assignment for the whole population - fitnessAssignment(_pop); - // creation of a local archive - moeoArchive < MOEOT > archive; - // creation of another local archive (for the stopping criteria) - moeoArchive < MOEOT > previousArchive; - // update the archive with the initial population - archive.update(_pop); - do + // evaluation of the objective values + /* + for (unsigned int i=0; i<_pop.size(); i++) + { + eval(_pop[i]); + } + */ + // fitness assignment for the whole population + fitnessAssignment(_pop); + // creation of a local archive + moeoArchive < MOEOT > archive; + // creation of another local archive (for the stopping criteria) + moeoArchive < MOEOT > previousArchive; + // update the archive with the initial population + archive.update(_pop); + do { - previousArchive.update(archive); - oneStep(_pop); - archive.update(_pop); - } while ( (! archive.equals(previousArchive)) && (continuator(_arch)) ); - _arch.update(archive); + previousArchive.update(archive); + oneStep(_pop); + archive.update(_pop); + } + while ( (! archive.equals(previousArchive)) && (continuator(_arch)) ); + _arch.update(archive); } -private: + private: /** the move initializer */ moMoveInit < Move > & moveInit; @@ -144,162 +145,162 @@ private: */ void oneStep (eoPop < MOEOT > & _pop) { - // the move - Move move; - // the objective vector and the fitness of the current solution - ObjectiveVector x_objVec; - double x_fitness; - // the index, the objective vector and the fitness of the worst solution in the population (-1 implies that the worst is the newly created one) - int worst_idx; - ObjectiveVector worst_objVec; - double worst_fitness; -//////////////////////////////////////////// - // the indexes and the objective vectors of the extreme non-dominated points - int ext_0_idx, ext_1_idx; - ObjectiveVector ext_0_objVec, ext_1_objVec; - unsigned int ind; + // the move + Move move; + // the objective vector and the fitness of the current solution + ObjectiveVector x_objVec; + double x_fitness; + // the index, the objective vector and the fitness of the worst solution in the population (-1 implies that the worst is the newly created one) + int worst_idx; + ObjectiveVector worst_objVec; + double worst_fitness; //////////////////////////////////////////// - // the index of the current solution to be explored - unsigned int i=0; - // initilization of the move for the first individual - moveInit(move, _pop[i]); - while (i<_pop.size() && continuator(_pop)) + // the indexes and the objective vectors of the extreme non-dominated points + int ext_0_idx, ext_1_idx; + ObjectiveVector ext_0_objVec, ext_1_objVec; + unsigned int ind; +//////////////////////////////////////////// + // the index of the current solution to be explored + unsigned int i=0; + // initilization of the move for the first individual + moveInit(move, _pop[i]); + while (i<_pop.size() && continuator(_pop)) { - // x = one neigbour of pop[i] - // evaluate x in the objective space - x_objVec = moveIncrEval(move, _pop[i]); - // update every fitness values to take x into account and compute the fitness of x - x_fitness = fitnessAssignment.updateByAdding(_pop, x_objVec); + // x = one neigbour of pop[i] + // evaluate x in the objective space + x_objVec = moveIncrEval(move, _pop[i]); + // update every fitness values to take x into account and compute the fitness of x + x_fitness = fitnessAssignment.updateByAdding(_pop, x_objVec); //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// - // extreme solutions (min only!) - ext_0_idx = -1; - ext_0_objVec = x_objVec; - ext_1_idx = -1; - ext_1_objVec = x_objVec; - for (unsigned int k=0; k<_pop.size(); k++) + // extreme solutions (min only!) + ext_0_idx = -1; + ext_0_objVec = x_objVec; + ext_1_idx = -1; + ext_1_objVec = x_objVec; + for (unsigned int k=0; k<_pop.size(); k++) { - // ext_0 - if (_pop[k].objectiveVector()[0] < ext_0_objVec[0]) + // ext_0 + if (_pop[k].objectiveVector()[0] < ext_0_objVec[0]) { - ext_0_idx = k; - ext_0_objVec = _pop[k].objectiveVector(); + ext_0_idx = k; + ext_0_objVec = _pop[k].objectiveVector(); } - else if ( (_pop[k].objectiveVector()[0] == ext_0_objVec[0]) && (_pop[k].objectiveVector()[1] < ext_0_objVec[1]) ) + else if ( (_pop[k].objectiveVector()[0] == ext_0_objVec[0]) && (_pop[k].objectiveVector()[1] < ext_0_objVec[1]) ) { - ext_0_idx = k; - ext_0_objVec = _pop[k].objectiveVector(); + ext_0_idx = k; + ext_0_objVec = _pop[k].objectiveVector(); } - // ext_1 - else if (_pop[k].objectiveVector()[1] < ext_1_objVec[1]) + // ext_1 + else if (_pop[k].objectiveVector()[1] < ext_1_objVec[1]) { - ext_1_idx = k; - ext_1_objVec = _pop[k].objectiveVector(); + ext_1_idx = k; + ext_1_objVec = _pop[k].objectiveVector(); } - else if ( (_pop[k].objectiveVector()[1] == ext_1_objVec[1]) && (_pop[k].objectiveVector()[0] < ext_1_objVec[0]) ) + else if ( (_pop[k].objectiveVector()[1] == ext_1_objVec[1]) && (_pop[k].objectiveVector()[0] < ext_1_objVec[0]) ) { - ext_1_idx = k; - ext_1_objVec = _pop[k].objectiveVector(); + ext_1_idx = k; + ext_1_objVec = _pop[k].objectiveVector(); } } - // worst init - if (ext_0_idx == -1) + // worst init + if (ext_0_idx == -1) { - ind = 0; - while (ind == ext_1_idx) + ind = 0; + while (ind == ext_1_idx) { - ind++; + ind++; } - worst_idx = ind; - worst_objVec = _pop[ind].objectiveVector(); - worst_fitness = _pop[ind].fitness(); + worst_idx = ind; + worst_objVec = _pop[ind].objectiveVector(); + worst_fitness = _pop[ind].fitness(); } - else if (ext_1_idx == -1) + else if (ext_1_idx == -1) { - ind = 0; - while (ind == ext_0_idx) + ind = 0; + while (ind == ext_0_idx) { - ind++; + ind++; } - worst_idx = ind; - worst_objVec = _pop[ind].objectiveVector(); - worst_fitness = _pop[ind].fitness(); + worst_idx = ind; + worst_objVec = _pop[ind].objectiveVector(); + worst_fitness = _pop[ind].fitness(); } - else + else { - worst_idx = -1; - worst_objVec = x_objVec; - worst_fitness = x_fitness; + worst_idx = -1; + worst_objVec = x_objVec; + worst_fitness = x_fitness; } //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// - // who is the worst ? - for (unsigned int j=0; j<_pop.size(); j++) + // who is the worst ? + for (unsigned int j=0; j<_pop.size(); j++) { - if ( (j!=ext_0_idx) && (j!=ext_1_idx) ) + if ( (j!=ext_0_idx) && (j!=ext_1_idx) ) { - if (_pop[j].fitness() < worst_fitness) + if (_pop[j].fitness() < worst_fitness) { - worst_idx = j; - worst_objVec = _pop[j].objectiveVector(); - worst_fitness = _pop[j].fitness(); + worst_idx = j; + worst_objVec = _pop[j].objectiveVector(); + worst_fitness = _pop[j].fitness(); } } } - // if the worst solution is the new one - if (worst_idx == -1) + // if the worst solution is the new one + if (worst_idx == -1) { - // if all its neighbours have been explored, - // let's explore the neighborhoud of the next individual - if (! nextMove(move, _pop[i])) + // if all its neighbours have been explored, + // let's explore the neighborhoud of the next individual + if (! nextMove(move, _pop[i])) { - i++; - if (i<_pop.size()) + i++; + if (i<_pop.size()) { - // initilization of the move for the next individual - moveInit(move, _pop[i]); + // initilization of the move for the next individual + moveInit(move, _pop[i]); } } } - // if the worst solution is located before _pop[i] - else if (worst_idx <= i) + // if the worst solution is located before _pop[i] + else if (worst_idx <= i) { - // the new solution takes place insteed of _pop[worst_idx] - _pop[worst_idx] = _pop[i]; - move(_pop[worst_idx]); - _pop[worst_idx].objectiveVector(x_objVec); - _pop[worst_idx].fitness(x_fitness); - // let's explore the neighborhoud of the next individual - i++; - if (i<_pop.size()) + // the new solution takes place insteed of _pop[worst_idx] + _pop[worst_idx] = _pop[i]; + move(_pop[worst_idx]); + _pop[worst_idx].objectiveVector(x_objVec); + _pop[worst_idx].fitness(x_fitness); + // let's explore the neighborhoud of the next individual + i++; + if (i<_pop.size()) { - // initilization of the move for the next individual - moveInit(move, _pop[i]); + // initilization of the move for the next individual + moveInit(move, _pop[i]); } } - // if the worst solution is located after _pop[i] - else if (worst_idx > i) + // if the worst solution is located after _pop[i] + else if (worst_idx > i) { - // the new solution takes place insteed of _pop[i+1] and _pop[worst_idx] is deleted - _pop[worst_idx] = _pop[i+1]; - _pop[i+1] = _pop[i]; - move(_pop[i+1]); - _pop[i+1].objectiveVector(x_objVec); - _pop[i+1].fitness(x_fitness); - // let's explore the neighborhoud of the individual _pop[i+2] - i += 2; - if (i<_pop.size()) + // the new solution takes place insteed of _pop[i+1] and _pop[worst_idx] is deleted + _pop[worst_idx] = _pop[i+1]; + _pop[i+1] = _pop[i]; + move(_pop[i+1]); + _pop[i+1].objectiveVector(x_objVec); + _pop[i+1].fitness(x_fitness); + // let's explore the neighborhoud of the individual _pop[i+2] + i += 2; + if (i<_pop.size()) { - // initilization of the move for the next individual - moveInit(move, _pop[i]); + // initilization of the move for the next individual + moveInit(move, _pop[i]); } } - // update fitness values - fitnessAssignment.updateByDeleting(_pop, worst_objVec); + // update fitness values + fitnessAssignment.updateByDeleting(_pop, worst_objVec); } } @@ -328,153 +329,153 @@ private: */ void new_oneStep (eoPop < MOEOT > & _pop) { - // the move - Move move; - // the objective vector and the fitness of the current solution - ObjectiveVector x_objVec; - double x_fitness; - // the index, the objective vector and the fitness of the worst solution in the population (-1 implies that the worst is the newly created one) - int worst_idx; - ObjectiveVector worst_objVec; - double worst_fitness; -//////////////////////////////////////////// - // the index of the extreme non-dominated points - int ext_0_idx, ext_1_idx; - unsigned int ind; + // the move + Move move; + // the objective vector and the fitness of the current solution + ObjectiveVector x_objVec; + double x_fitness; + // the index, the objective vector and the fitness of the worst solution in the population (-1 implies that the worst is the newly created one) + int worst_idx; + ObjectiveVector worst_objVec; + double worst_fitness; //////////////////////////////////////////// - // the index current of the current solution to be explored - unsigned int i=0; - // initilization of the move for the first individual - moveInit(move, _pop[i]); - while (i<_pop.size() && continuator(_pop)) + // the index of the extreme non-dominated points + int ext_0_idx, ext_1_idx; + unsigned int ind; +//////////////////////////////////////////// + // the index current of the current solution to be explored + unsigned int i=0; + // initilization of the move for the first individual + moveInit(move, _pop[i]); + while (i<_pop.size() && continuator(_pop)) { - // x = one neigbour of pop[i] - // evaluate x in the objective space - x_objVec = moveIncrEval(move, _pop[i]); - // update every fitness values to take x into account and compute the fitness of x - x_fitness = fitnessAssignment.updateByAdding(_pop, x_objVec); + // x = one neigbour of pop[i] + // evaluate x in the objective space + x_objVec = moveIncrEval(move, _pop[i]); + // update every fitness values to take x into account and compute the fitness of x + x_fitness = fitnessAssignment.updateByAdding(_pop, x_objVec); //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// - // extremes solutions - OneObjectiveComparator comp0(0); - ext_0_idx = std::min_element(_pop.begin(), _pop.end(), comp0) - _pop.begin(); - OneObjectiveComparator comp1(1); - ext_1_idx = std::min_element(_pop.begin(), _pop.end(), comp1) - _pop.begin(); - // new = extreme ? - if (x_objVec[0] < _pop[ext_0_idx].objectiveVector()[0]) + // extremes solutions + OneObjectiveComparator comp0(0); + ext_0_idx = std::min_element(_pop.begin(), _pop.end(), comp0) - _pop.begin(); + OneObjectiveComparator comp1(1); + ext_1_idx = std::min_element(_pop.begin(), _pop.end(), comp1) - _pop.begin(); + // new = extreme ? + if (x_objVec[0] < _pop[ext_0_idx].objectiveVector()[0]) { - ext_0_idx = -1; + ext_0_idx = -1; } - else if ( (x_objVec[0] == _pop[ext_0_idx].objectiveVector()[0]) && (x_objVec[1] < _pop[ext_0_idx].objectiveVector()[1]) ) + else if ( (x_objVec[0] == _pop[ext_0_idx].objectiveVector()[0]) && (x_objVec[1] < _pop[ext_0_idx].objectiveVector()[1]) ) { - ext_0_idx = -1; + ext_0_idx = -1; } - else if (x_objVec[1] < _pop[ext_1_idx].objectiveVector()[1]) + else if (x_objVec[1] < _pop[ext_1_idx].objectiveVector()[1]) { - ext_1_idx = -1; + ext_1_idx = -1; } - else if ( (x_objVec[1] == _pop[ext_1_idx].objectiveVector()[1]) && (x_objVec[0] < _pop[ext_1_idx].objectiveVector()[0]) ) + else if ( (x_objVec[1] == _pop[ext_1_idx].objectiveVector()[1]) && (x_objVec[0] < _pop[ext_1_idx].objectiveVector()[0]) ) { - ext_1_idx = -1; + ext_1_idx = -1; } - // worst init - if (ext_0_idx == -1) + // worst init + if (ext_0_idx == -1) { - ind = 0; - while (ind == ext_1_idx) + ind = 0; + while (ind == ext_1_idx) { - ind++; + ind++; } - worst_idx = ind; - worst_objVec = _pop[ind].objectiveVector(); - worst_fitness = _pop[ind].fitness(); + worst_idx = ind; + worst_objVec = _pop[ind].objectiveVector(); + worst_fitness = _pop[ind].fitness(); } - else if (ext_1_idx == -1) + else if (ext_1_idx == -1) { - ind = 0; - while (ind == ext_0_idx) + ind = 0; + while (ind == ext_0_idx) { - ind++; + ind++; } - worst_idx = ind; - worst_objVec = _pop[ind].objectiveVector(); - worst_fitness = _pop[ind].fitness(); + worst_idx = ind; + worst_objVec = _pop[ind].objectiveVector(); + worst_fitness = _pop[ind].fitness(); } - else + else { - worst_idx = -1; - worst_objVec = x_objVec; - worst_fitness = x_fitness; + worst_idx = -1; + worst_objVec = x_objVec; + worst_fitness = x_fitness; } //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// - // who is the worst ? - for (unsigned int j=0; j<_pop.size(); j++) + // who is the worst ? + for (unsigned int j=0; j<_pop.size(); j++) { - if ( (j!=ext_0_idx) && (j!=ext_1_idx) ) + if ( (j!=ext_0_idx) && (j!=ext_1_idx) ) { - if (_pop[j].fitness() < worst_fitness) + if (_pop[j].fitness() < worst_fitness) { - worst_idx = j; - worst_objVec = _pop[j].objectiveVector(); - worst_fitness = _pop[j].fitness(); + worst_idx = j; + worst_objVec = _pop[j].objectiveVector(); + worst_fitness = _pop[j].fitness(); } } } - // if the worst solution is the new one - if (worst_idx == -1) + // if the worst solution is the new one + if (worst_idx == -1) { - // if all its neighbours have been explored, - // let's explore the neighborhoud of the next individual - if (! nextMove(move, _pop[i])) + // if all its neighbours have been explored, + // let's explore the neighborhoud of the next individual + if (! nextMove(move, _pop[i])) { - i++; - if (i<_pop.size()) + i++; + if (i<_pop.size()) { - // initilization of the move for the next individual - moveInit(move, _pop[i]); + // initilization of the move for the next individual + moveInit(move, _pop[i]); } } } - // if the worst solution is located before _pop[i] - else if (worst_idx <= i) + // if the worst solution is located before _pop[i] + else if (worst_idx <= i) { - // the new solution takes place insteed of _pop[worst_idx] - _pop[worst_idx] = _pop[i]; - move(_pop[worst_idx]); - _pop[worst_idx].objectiveVector(x_objVec); - _pop[worst_idx].fitness(x_fitness); - // let's explore the neighborhoud of the next individual - i++; - if (i<_pop.size()) + // the new solution takes place insteed of _pop[worst_idx] + _pop[worst_idx] = _pop[i]; + move(_pop[worst_idx]); + _pop[worst_idx].objectiveVector(x_objVec); + _pop[worst_idx].fitness(x_fitness); + // let's explore the neighborhoud of the next individual + i++; + if (i<_pop.size()) { - // initilization of the move for the next individual - moveInit(move, _pop[i]); + // initilization of the move for the next individual + moveInit(move, _pop[i]); } } - // if the worst solution is located after _pop[i] - else if (worst_idx > i) + // if the worst solution is located after _pop[i] + else if (worst_idx > i) { - // the new solution takes place insteed of _pop[i+1] and _pop[worst_idx] is deleted - _pop[worst_idx] = _pop[i+1]; - _pop[i+1] = _pop[i]; - move(_pop[i+1]); - _pop[i+1].objectiveVector(x_objVec); - _pop[i+1].fitness(x_fitness); - // let's explore the neighborhoud of the individual _pop[i+2] - i += 2; - if (i<_pop.size()) + // the new solution takes place insteed of _pop[i+1] and _pop[worst_idx] is deleted + _pop[worst_idx] = _pop[i+1]; + _pop[i+1] = _pop[i]; + move(_pop[i+1]); + _pop[i+1].objectiveVector(x_objVec); + _pop[i+1].fitness(x_fitness); + // let's explore the neighborhoud of the individual _pop[i+2] + i += 2; + if (i<_pop.size()) { - // initilization of the move for the next individual - moveInit(move, _pop[i]); + // initilization of the move for the next individual + moveInit(move, _pop[i]); } } - // update fitness values - fitnessAssignment.updateByDeleting(_pop, worst_objVec); + // update fitness values + fitnessAssignment.updateByDeleting(_pop, worst_objVec); } } @@ -484,35 +485,35 @@ private: ////////////////////////////////////////////////////////////////////////////////////////// -class OneObjectiveComparator : public moeoComparator < MOEOT > - { - public: + class OneObjectiveComparator : public moeoComparator < MOEOT > + { + public: OneObjectiveComparator(unsigned int _obj) : obj(_obj) { - if (obj > MOEOT::ObjectiveVector::nObjectives()) + if (obj > MOEOT::ObjectiveVector::nObjectives()) { - throw std::runtime_error("Problem with the index of objective in OneObjectiveComparator"); + throw std::runtime_error("Problem with the index of objective in OneObjectiveComparator"); } } const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { - if (_moeo1.objectiveVector()[obj] < _moeo2.objectiveVector()[obj]) + if (_moeo1.objectiveVector()[obj] < _moeo2.objectiveVector()[obj]) { - return true; + return true; } - else + else { - return (_moeo1.objectiveVector()[obj] == _moeo2.objectiveVector()[obj]) && (_moeo1.objectiveVector()[(obj+1)%2] < _moeo2.objectiveVector()[(obj+1)%2]); + return (_moeo1.objectiveVector()[obj] == _moeo2.objectiveVector()[obj]) && (_moeo1.objectiveVector()[(obj+1)%2] < _moeo2.objectiveVector()[(obj+1)%2]); } } - private: + private: unsigned int obj; - }; + }; ////////////////////////////////////////////////////////////////////////////////////////// -}; + }; #endif /*MOEOIBMOLS_H_*/ diff --git a/trunk/paradiseo-moeo/src/algo/moeoIteratedIBMOLS.h b/trunk/paradiseo-moeo/src/algo/moeoIteratedIBMOLS.h index 3b91810f2..09436920c 100755 --- a/trunk/paradiseo-moeo/src/algo/moeoIteratedIBMOLS.h +++ b/trunk/paradiseo-moeo/src/algo/moeoIteratedIBMOLS.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -64,8 +64,8 @@ */ template < class MOEOT, class Move > class moeoIteratedIBMOLS : public moeoLS < MOEOT, eoPop < MOEOT > & > -{ -public: + { + public: /** The type of objective vector */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -84,22 +84,22 @@ public: * @param _nNoiseIterations the number of iterations to apply the random noise */ moeoIteratedIBMOLS( - moMoveInit < Move > & _moveInit, - moNextMove < Move > & _nextMove, - eoEvalFunc < MOEOT > & _eval, - moeoMoveIncrEval < Move > & _moveIncrEval, - moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment, - eoContinue < MOEOT > & _continuator, - eoMonOp < MOEOT > & _monOp, - eoMonOp < MOEOT > & _randomMonOp, - unsigned int _nNoiseIterations=1 + moMoveInit < Move > & _moveInit, + moNextMove < Move > & _nextMove, + eoEvalFunc < MOEOT > & _eval, + moeoMoveIncrEval < Move > & _moveIncrEval, + moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment, + eoContinue < MOEOT > & _continuator, + eoMonOp < MOEOT > & _monOp, + eoMonOp < MOEOT > & _randomMonOp, + unsigned int _nNoiseIterations=1 ) : - ibmols(_moveInit, _nextMove, _eval, _moveIncrEval, _fitnessAssignment, _continuator), - eval(_eval), - continuator(_continuator), - monOp(_monOp), - randomMonOp(_randomMonOp), - nNoiseIterations(_nNoiseIterations) + ibmols(_moveInit, _nextMove, _eval, _moveIncrEval, _fitnessAssignment, _continuator), + eval(_eval), + continuator(_continuator), + monOp(_monOp), + randomMonOp(_randomMonOp), + nNoiseIterations(_nNoiseIterations) {} @@ -110,19 +110,19 @@ public: */ void operator() (eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _arch) { - _arch.update(_pop); - ibmols(_pop, _arch); - while (continuator(_arch)) + _arch.update(_pop); + ibmols(_pop, _arch); + while (continuator(_arch)) { - // generate new solutions from the archive - generateNewSolutions(_pop, _arch); - // apply the local search (the global archive is updated in the sub-function) - ibmols(_pop, _arch); + // generate new solutions from the archive + generateNewSolutions(_pop, _arch); + // apply the local search (the global archive is updated in the sub-function) + ibmols(_pop, _arch); } } -private: + private: /** the local search to iterate */ moeoIBMOLS < MOEOT, Move > ibmols; @@ -145,38 +145,38 @@ private: */ void generateNewSolutions(eoPop < MOEOT > & _pop, const moeoArchive < MOEOT > & _arch) { - // shuffle vector for the random selection of individuals - vector shuffle; - shuffle.resize(std::max(_pop.size(), _arch.size())); - // init shuffle - for (unsigned int i=0; i shuffle; + shuffle.resize(std::max(_pop.size(), _arch.size())); + // init shuffle + for (unsigned int i=0; i gen; - std::random_shuffle(shuffle.begin(), shuffle.end(), gen); - // start the creation of new solutions - for (unsigned int i=0; i<_pop.size(); i++) + // randomize shuffle + UF_random_generator gen; + std::random_shuffle(shuffle.begin(), shuffle.end(), gen); + // start the creation of new solutions + for (unsigned int i=0; i<_pop.size(); i++) { - if (shuffle[i] < _arch.size()) // the given archive contains the individual i + if (shuffle[i] < _arch.size()) // the given archive contains the individual i { - // add it to the resulting pop - _pop[i] = _arch[shuffle[i]]; - // apply noise - for (unsigned int j=0; j * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -47,6 +47,7 @@ * Starting from a Type (i.e.: an individual, a pop, an archive...), it produces a set of new non-dominated solutions. */ template < class MOEOT, class Type > -class moeoLS: public moeoAlgo, public eoBF < Type, moeoArchive < MOEOT > &, void > {}; +class moeoLS: public moeoAlgo, public eoBF < Type, moeoArchive < MOEOT > &, void > + {}; #endif /*MOEOLS_H_*/ diff --git a/trunk/paradiseo-moeo/src/algo/moeoNSGA.h b/trunk/paradiseo-moeo/src/algo/moeoNSGA.h index 338a1a440..5c8d1fd28 100644 --- a/trunk/paradiseo-moeo/src/algo/moeoNSGA.h +++ b/trunk/paradiseo-moeo/src/algo/moeoNSGA.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -60,8 +60,8 @@ */ template < class MOEOT > class moeoNSGA: public moeoEA < MOEOT > -{ -public: + { + public: /** * Simple ctor with a eoGenOp. @@ -71,8 +71,8 @@ public: * @param _nicheSize niche size */ moeoNSGA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, double _nicheSize = 0.5) : - defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2), - diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed) + defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2), + diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed) {} @@ -84,8 +84,8 @@ public: * @param _nicheSize niche size */ moeoNSGA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op, double _nicheSize = 0.5) : - defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2), - diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed) + defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2), + diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed) {} @@ -100,9 +100,9 @@ public: * @param _nicheSize niche size */ moeoNSGA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut, double _nicheSize = 0.5) : - defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2), - diversityAssignment(_nicheSize), replace (fitnessAssignment, diversityAssignment), - defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut), genBreed (select, defaultSGAGenOp), breed (genBreed) + defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2), + diversityAssignment(_nicheSize), replace (fitnessAssignment, diversityAssignment), + defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut), genBreed (select, defaultSGAGenOp), breed (genBreed) {} @@ -114,8 +114,8 @@ public: * @param _nicheSize niche size */ moeoNSGA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, double _nicheSize = 0.5) : - continuator(_continuator), popEval(_eval), select(2), - diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed) + continuator(_continuator), popEval(_eval), select(2), + diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed) {} @@ -127,8 +127,8 @@ public: * @param _nicheSize niche size */ moeoNSGA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op, double _nicheSize = 0.5) : - continuator(_continuator), popEval(_eval), select(2), - diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed) + continuator(_continuator), popEval(_eval), select(2), + diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed) {} @@ -138,24 +138,25 @@ public: */ virtual void operator () (eoPop < MOEOT > &_pop) { - eoPop < MOEOT > offspring, empty_pop; - popEval (empty_pop, _pop); // a first eval of _pop - // evaluate fitness and diversity - fitnessAssignment(_pop); - diversityAssignment(_pop); - do + eoPop < MOEOT > offspring, empty_pop; + popEval (empty_pop, _pop); // a first eval of _pop + // evaluate fitness and diversity + fitnessAssignment(_pop); + diversityAssignment(_pop); + do { - // generate offspring, worths are recalculated if necessary - breed (_pop, offspring); - // eval of offspring - popEval (_pop, offspring); - // after replace, the new pop is in _pop. Worths are recalculated if necessary - replace (_pop, offspring); - } while (continuator (_pop)); + // generate offspring, worths are recalculated if necessary + breed (_pop, offspring); + // eval of offspring + popEval (_pop, offspring); + // after replace, the new pop is in _pop. Worths are recalculated if necessary + replace (_pop, offspring); + } + while (continuator (_pop)); } -protected: + protected: /** a continuator based on the number of generations (used as default) */ eoGenContinue < MOEOT > defaultGenContinuator; @@ -178,6 +179,6 @@ protected: /** breeder */ eoBreed < MOEOT > & breed; -}; + }; #endif /*MOEONSGAII_H_*/ diff --git a/trunk/paradiseo-moeo/src/algo/moeoNSGAII.h b/trunk/paradiseo-moeo/src/algo/moeoNSGAII.h index 4b8ea71f9..d31e723bc 100644 --- a/trunk/paradiseo-moeo/src/algo/moeoNSGAII.h +++ b/trunk/paradiseo-moeo/src/algo/moeoNSGAII.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -63,8 +63,8 @@ */ template < class MOEOT > class moeoNSGAII: public moeoEA < MOEOT > -{ -public: + { + public: /** * Simple ctor with a eoGenOp. @@ -73,9 +73,9 @@ public: * @param _op variation operator */ moeoNSGAII (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op) : - defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2), - replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0), - genBreed(select, _op), breed(genBreed) + defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2), + replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0), + genBreed(select, _op), breed(genBreed) {} @@ -86,9 +86,9 @@ public: * @param _op variation operator */ moeoNSGAII (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op) : - defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2), - replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0), - genBreed(select, _op), breed(genBreed) + defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2), + replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0), + genBreed(select, _op), breed(genBreed) {} @@ -102,9 +102,9 @@ public: * @param _pMut mutation probability */ moeoNSGAII (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut) : - defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2), - replace (fitnessAssignment, diversityAssignment), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut), - genBreed (select, defaultSGAGenOp), breed (genBreed) + defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2), + replace (fitnessAssignment, diversityAssignment), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut), + genBreed (select, defaultSGAGenOp), breed (genBreed) {} @@ -115,9 +115,9 @@ public: * @param _op variation operator */ moeoNSGAII (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op) : - defaultGenContinuator(0), continuator(_continuator), popEval(_eval), select(2), - replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 1.0, defaultMonOp, 1.0), - genBreed(select, _op), breed(genBreed) + defaultGenContinuator(0), continuator(_continuator), popEval(_eval), select(2), + replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 1.0, defaultMonOp, 1.0), + genBreed(select, _op), breed(genBreed) {} @@ -128,9 +128,9 @@ public: * @param _op variation operator */ moeoNSGAII (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op) : - continuator(_continuator), popEval(_eval), select(2), - replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0), - genBreed(select, _op), breed(genBreed) + continuator(_continuator), popEval(_eval), select(2), + replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0), + genBreed(select, _op), breed(genBreed) {} @@ -140,24 +140,25 @@ public: */ virtual void operator () (eoPop < MOEOT > &_pop) { - eoPop < MOEOT > offspring, empty_pop; - popEval (empty_pop, _pop); // a first eval of _pop - // evaluate fitness and diversity - fitnessAssignment(_pop); - diversityAssignment(_pop); - do + eoPop < MOEOT > offspring, empty_pop; + popEval (empty_pop, _pop); // a first eval of _pop + // evaluate fitness and diversity + fitnessAssignment(_pop); + diversityAssignment(_pop); + do { - // generate offspring, worths are recalculated if necessary - breed (_pop, offspring); - // eval of offspring - popEval (_pop, offspring); - // after replace, the new pop is in _pop. Worths are recalculated if necessary - replace (_pop, offspring); - } while (continuator (_pop)); + // generate offspring, worths are recalculated if necessary + breed (_pop, offspring); + // eval of offspring + popEval (_pop, offspring); + // after replace, the new pop is in _pop. Worths are recalculated if necessary + replace (_pop, offspring); + } + while (continuator (_pop)); } -protected: + protected: /** a continuator based on the number of generations (used as default) */ eoGenContinue < MOEOT > defaultGenContinuator; @@ -184,6 +185,6 @@ protected: /** breeder */ eoBreed < MOEOT > & breed; -}; + }; #endif /*MOEONSGAII_H_*/ diff --git a/trunk/paradiseo-moeo/src/archive/moeoArchive.h b/trunk/paradiseo-moeo/src/archive/moeoArchive.h index d58416a72..93cca5848 100644 --- a/trunk/paradiseo-moeo/src/archive/moeoArchive.h +++ b/trunk/paradiseo-moeo/src/archive/moeoArchive.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -47,8 +47,8 @@ */ template < class MOEOT > class moeoArchive : public eoPop < MOEOT > -{ -public: + { + public: using eoPop < MOEOT > :: size; using eoPop < MOEOT > :: operator[]; @@ -83,17 +83,17 @@ public: * @param _objectiveVector the objective vector to compare with the current archive */ bool dominates (const ObjectiveVector & _objectiveVector) const - { + { for (unsigned int i = 0; i & _pop) { - for (unsigned int i=0; i<_pop.size(); i++) + for (unsigned int i=0; i<_pop.size(); i++) { - update(_pop[i]); + update(_pop[i]); } } @@ -175,31 +175,31 @@ public: */ bool equals (const moeoArchive < MOEOT > & _arch) { - for (unsigned int i=0; i & comparator; /** A moeoObjectiveVectorComparator based on Pareto dominance (used as default) */ moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator; -}; + }; #endif /*MOEOARCHIVE_H_ */ diff --git a/trunk/paradiseo-moeo/src/comparator/moeoAggregativeComparator.h b/trunk/paradiseo-moeo/src/comparator/moeoAggregativeComparator.h index b45d5572b..d684c54eb 100644 --- a/trunk/paradiseo-moeo/src/comparator/moeoAggregativeComparator.h +++ b/trunk/paradiseo-moeo/src/comparator/moeoAggregativeComparator.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,8 +45,8 @@ */ template < class MOEOT > class moeoAggregativeComparator : public moeoComparator < MOEOT > -{ -public: + { + public: /** * Ctor. @@ -64,17 +64,17 @@ public: */ const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { - return ( weightFitness * _moeo1.fitness() + weightDiversity * _moeo1.diversity() ) < ( weightFitness * _moeo2.fitness() + weightDiversity * _moeo2.diversity() ); + return ( weightFitness * _moeo1.fitness() + weightDiversity * _moeo1.diversity() ) < ( weightFitness * _moeo2.fitness() + weightDiversity * _moeo2.diversity() ); } -private: + private: /** the weight for fitness */ double weightFitness; /** the weight for diversity */ double weightDiversity; -}; + }; #endif /*MOEOAGGREGATIVECOMPARATOR_H_*/ diff --git a/trunk/paradiseo-moeo/src/comparator/moeoComparator.h b/trunk/paradiseo-moeo/src/comparator/moeoComparator.h index 9d0c0fb49..e97845505 100644 --- a/trunk/paradiseo-moeo/src/comparator/moeoComparator.h +++ b/trunk/paradiseo-moeo/src/comparator/moeoComparator.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -44,6 +44,7 @@ * Functor allowing to compare two solutions. */ template < class MOEOT > -class moeoComparator : public eoBF < const MOEOT &, const MOEOT &, const bool > {}; +class moeoComparator : public eoBF < const MOEOT &, const MOEOT &, const bool > + {}; #endif /*MOEOCOMPARATOR_H_*/ diff --git a/trunk/paradiseo-moeo/src/comparator/moeoDiversityThenFitnessComparator.h b/trunk/paradiseo-moeo/src/comparator/moeoDiversityThenFitnessComparator.h index 599f3fcb8..db58f936f 100644 --- a/trunk/paradiseo-moeo/src/comparator/moeoDiversityThenFitnessComparator.h +++ b/trunk/paradiseo-moeo/src/comparator/moeoDiversityThenFitnessComparator.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,8 +45,8 @@ */ template < class MOEOT > class moeoDiversityThenFitnessComparator : public moeoComparator < MOEOT > -{ -public: + { + public: /** * Returns true if _moeo1 < _moeo2 according to their diversity values, then according to their fitness values @@ -55,16 +55,16 @@ public: */ const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { - if (_moeo1.diversity() == _moeo2.diversity()) + if (_moeo1.diversity() == _moeo2.diversity()) { - return _moeo1.fitness() < _moeo2.fitness(); + return _moeo1.fitness() < _moeo2.fitness(); } - else + else { - return _moeo1.diversity() < _moeo2.diversity(); + return _moeo1.diversity() < _moeo2.diversity(); } } -}; + }; #endif /*MOEODIVERSITYTHENFITNESSCOMPARATOR_H_*/ diff --git a/trunk/paradiseo-moeo/src/comparator/moeoFitnessThenDiversityComparator.h b/trunk/paradiseo-moeo/src/comparator/moeoFitnessThenDiversityComparator.h index f3872bd32..cf6c4004b 100644 --- a/trunk/paradiseo-moeo/src/comparator/moeoFitnessThenDiversityComparator.h +++ b/trunk/paradiseo-moeo/src/comparator/moeoFitnessThenDiversityComparator.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,8 +45,8 @@ */ template < class MOEOT > class moeoFitnessThenDiversityComparator : public moeoComparator < MOEOT > -{ -public: + { + public: /** * Returns true if _moeo1 < _moeo2 according to their fitness values, then according to their diversity values @@ -55,16 +55,16 @@ public: */ const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { - if (_moeo1.fitness() == _moeo2.fitness()) + if (_moeo1.fitness() == _moeo2.fitness()) { - return _moeo1.diversity() < _moeo2.diversity(); + return _moeo1.diversity() < _moeo2.diversity(); } - else + else { - return _moeo1.fitness() < _moeo2.fitness(); + return _moeo1.fitness() < _moeo2.fitness(); } } -}; + }; #endif /*MOEOFITNESSTHENDIVERSITYCOMPARATOR_H_*/ diff --git a/trunk/paradiseo-moeo/src/comparator/moeoGDominanceObjectiveVectorComparator.h b/trunk/paradiseo-moeo/src/comparator/moeoGDominanceObjectiveVectorComparator.h index 7acf9fdea..c51e26c02 100644 --- a/trunk/paradiseo-moeo/src/comparator/moeoGDominanceObjectiveVectorComparator.h +++ b/trunk/paradiseo-moeo/src/comparator/moeoGDominanceObjectiveVectorComparator.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -48,8 +48,8 @@ */ template < class ObjectiveVector > class moeoGDominanceObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector > -{ -public: + { + public: /** * Ctor. @@ -66,27 +66,27 @@ public: */ const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2) { - unsigned int flag1 = flag(_objectiveVector1); - unsigned int flag2 = flag(_objectiveVector2); - if (flag2==0) + unsigned int flag1 = flag(_objectiveVector1); + unsigned int flag2 = flag(_objectiveVector2); + if (flag2==0) { - // cannot dominate - return false; + // cannot dominate + return false; } - else if ( (flag2==1) && (flag1==0) ) + else if ( (flag2==1) && (flag1==0) ) { - // is dominated - return true; + // is dominated + return true; } - else // (flag1==1) && (flag2==1) + else // (flag1==1) && (flag2==1) { - // both are on the good region, so let's use the classical Pareto dominance - return paretoComparator(_objectiveVector1, _objectiveVector2); + // both are on the good region, so let's use the classical Pareto dominance + return paretoComparator(_objectiveVector1, _objectiveVector2); } } -private: + private: /** the reference point */ ObjectiveVector & ref; @@ -100,28 +100,28 @@ private: */ unsigned int flag(const ObjectiveVector & _objectiveVector) { - unsigned int result=1; - for (unsigned int i=0; i ref[i]) + if (_objectiveVector[i] > ref[i]) { - result=0; + result=0; } } - if (result==0) + if (result==0) { - result=1; - for (unsigned int i=0; i * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,8 +45,8 @@ */ template < class ObjectiveVector > class moeoObjectiveObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector > -{ -public: + { + public: /** * Returns true if _objectiveVector1 < _objectiveVector2 on the first objective, then on the second, and so on @@ -55,23 +55,23 @@ public: */ const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2) { - for (unsigned int i=0; i ObjectiveVector::Traits::tolerance() ) + if ( fabs(_objectiveVector1[i] - _objectiveVector2[i]) > ObjectiveVector::Traits::tolerance() ) { - if (_objectiveVector1[i] < _objectiveVector2[i]) + if (_objectiveVector1[i] < _objectiveVector2[i]) { - return true; + return true; } - else + else { - return false; + return false; } } } - return false; + return false; } -}; + }; #endif /*MOEOOBJECTIVEOBJECTIVEVECTORCOMPARATOR_H_*/ diff --git a/trunk/paradiseo-moeo/src/comparator/moeoObjectiveVectorComparator.h b/trunk/paradiseo-moeo/src/comparator/moeoObjectiveVectorComparator.h index a5e71daf7..a34112690 100644 --- a/trunk/paradiseo-moeo/src/comparator/moeoObjectiveVectorComparator.h +++ b/trunk/paradiseo-moeo/src/comparator/moeoObjectiveVectorComparator.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -46,6 +46,7 @@ * The template argument ObjectiveVector have to be a moeoObjectiveVector. */ template < class ObjectiveVector > -class moeoObjectiveVectorComparator : public eoBF < const ObjectiveVector &, const ObjectiveVector &, const bool > {}; +class moeoObjectiveVectorComparator : public eoBF < const ObjectiveVector &, const ObjectiveVector &, const bool > + {}; #endif /*MOEOOBJECTIVEVECTORCOMPARATOR_H_*/ diff --git a/trunk/paradiseo-moeo/src/comparator/moeoOneObjectiveComparator.h b/trunk/paradiseo-moeo/src/comparator/moeoOneObjectiveComparator.h index 201170d62..66c71a1de 100644 --- a/trunk/paradiseo-moeo/src/comparator/moeoOneObjectiveComparator.h +++ b/trunk/paradiseo-moeo/src/comparator/moeoOneObjectiveComparator.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,8 +45,8 @@ */ template < class MOEOT > class moeoOneObjectiveComparator : public moeoComparator < MOEOT > -{ -public: + { + public: /** * Ctor. @@ -54,9 +54,9 @@ public: */ moeoOneObjectiveComparator(unsigned int _obj) : obj(_obj) { - if (obj > MOEOT::ObjectiveVector::nObjectives()) + if (obj > MOEOT::ObjectiveVector::nObjectives()) { - throw std::runtime_error("Problem with the index of objective in moeoOneObjectiveComparator"); + throw std::runtime_error("Problem with the index of objective in moeoOneObjectiveComparator"); } } @@ -68,15 +68,15 @@ public: */ const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { - return _moeo1.objectiveVector()[obj] < _moeo2.objectiveVector()[obj]; + return _moeo1.objectiveVector()[obj] < _moeo2.objectiveVector()[obj]; } -private: + private: /** the index of objective */ unsigned int obj; -}; + }; #endif /*MOEOONEOBJECTIVECOMPARATOR_H_*/ diff --git a/trunk/paradiseo-moeo/src/comparator/moeoParetoObjectiveVectorComparator.h b/trunk/paradiseo-moeo/src/comparator/moeoParetoObjectiveVectorComparator.h index 46c543a08..fca1614f9 100644 --- a/trunk/paradiseo-moeo/src/comparator/moeoParetoObjectiveVectorComparator.h +++ b/trunk/paradiseo-moeo/src/comparator/moeoParetoObjectiveVectorComparator.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,8 +45,8 @@ */ template < class ObjectiveVector > class moeoParetoObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector > -{ -public: + { + public: /** * Returns true if _objectiveVector1 is dominated by _objectiveVector2 @@ -55,41 +55,41 @@ public: */ const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2) { - bool dom = false; - for (unsigned int i=0; i ObjectiveVector::Traits::tolerance() ) + // first, we have to check if the 2 objective values are not equal for the ith objective + if ( fabs(_objectiveVector1[i] - _objectiveVector2[i]) > ObjectiveVector::Traits::tolerance() ) { - // if the ith objective have to be minimized... - if (ObjectiveVector::minimizing(i)) + // if the ith objective have to be minimized... + if (ObjectiveVector::minimizing(i)) { - if (_objectiveVector1[i] > _objectiveVector2[i]) + if (_objectiveVector1[i] > _objectiveVector2[i]) { - dom = true; //_objectiveVector1[i] is not better than _objectiveVector2[i] + dom = true; //_objectiveVector1[i] is not better than _objectiveVector2[i] } - else + else { - return false; //_objectiveVector2 cannot dominate _objectiveVector1 + return false; //_objectiveVector2 cannot dominate _objectiveVector1 } } - // if the ith objective have to be maximized... - else if (ObjectiveVector::maximizing(i)) + // if the ith objective have to be maximized... + else if (ObjectiveVector::maximizing(i)) { - if (_objectiveVector1[i] < _objectiveVector2[i]) + if (_objectiveVector1[i] < _objectiveVector2[i]) { - dom = true; //_objectiveVector1[i] is not better than _objectiveVector2[i] + dom = true; //_objectiveVector1[i] is not better than _objectiveVector2[i] } - else + else { - return false; //_objectiveVector2 cannot dominate _objectiveVector1 + return false; //_objectiveVector2 cannot dominate _objectiveVector1 } } } } - return dom; + return dom; } -}; + }; #endif /*MOEOPARETOOBJECTIVEVECTORCOMPARATOR_H_*/ diff --git a/trunk/paradiseo-moeo/src/core/MOEO.h b/trunk/paradiseo-moeo/src/core/MOEO.h index d410c7c29..93cac8c0d 100644 --- a/trunk/paradiseo-moeo/src/core/MOEO.h +++ b/trunk/paradiseo-moeo/src/core/MOEO.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -57,8 +57,8 @@ */ template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity > class MOEO : public EO < MOEOObjectiveVector > -{ -public: + { + public: /** the objective vector type of a solution */ typedef MOEOObjectiveVector ObjectiveVector; @@ -75,32 +75,33 @@ public: */ MOEO() { - // default values for every parameters - objectiveVectorValue = ObjectiveVector(); - fitnessValue = Fitness(); - diversityValue = Diversity(); - // invalidate all - invalidate(); + // default values for every parameters + objectiveVectorValue = ObjectiveVector(); + fitnessValue = Fitness(); + diversityValue = Diversity(); + // invalidate all + invalidate(); } /** * Virtual dtor */ - virtual ~MOEO() {}; + virtual ~MOEO() + {}; /** * Returns the objective vector of the current solution */ ObjectiveVector objectiveVector() const - { + { if ( invalidObjectiveVector() ) - { + { throw std::runtime_error("invalid objective vector in MOEO"); - } + } return objectiveVectorValue; - } + } /** @@ -109,8 +110,8 @@ public: */ void objectiveVector(const ObjectiveVector & _objectiveVectorValue) { - objectiveVectorValue = _objectiveVectorValue; - invalidObjectiveVectorValue = false; + objectiveVectorValue = _objectiveVectorValue; + invalidObjectiveVectorValue = false; } @@ -119,7 +120,7 @@ public: */ void invalidateObjectiveVector() { - invalidObjectiveVectorValue = true; + invalidObjectiveVectorValue = true; } @@ -127,22 +128,22 @@ public: * Returns true if the objective vector is invalid, false otherwise */ bool invalidObjectiveVector() const - { + { return invalidObjectiveVectorValue; - } + } /** * Returns the fitness value of the current solution */ Fitness fitness() const - { + { if ( invalidFitness() ) - { + { throw std::runtime_error("invalid fitness in MOEO"); - } + } return fitnessValue; - } + } /** @@ -151,8 +152,8 @@ public: */ void fitness(const Fitness & _fitnessValue) { - fitnessValue = _fitnessValue; - invalidFitnessValue = false; + fitnessValue = _fitnessValue; + invalidFitnessValue = false; } @@ -161,7 +162,7 @@ public: */ void invalidateFitness() { - invalidFitnessValue = true; + invalidFitnessValue = true; } @@ -169,22 +170,22 @@ public: * Returns true if the fitness value is invalid, false otherwise */ bool invalidFitness() const - { + { return invalidFitnessValue; - } + } /** * Returns the diversity value of the current solution */ Diversity diversity() const - { + { if ( invalidDiversity() ) - { + { throw std::runtime_error("invalid diversity in MOEO"); - } + } return diversityValue; - } + } /** @@ -193,8 +194,8 @@ public: */ void diversity(const Diversity & _diversityValue) { - diversityValue = _diversityValue; - invalidDiversityValue = false; + diversityValue = _diversityValue; + invalidDiversityValue = false; } @@ -203,7 +204,7 @@ public: */ void invalidateDiversity() { - invalidDiversityValue = true; + invalidDiversityValue = true; } @@ -211,9 +212,9 @@ public: * Returns true if the diversity value is invalid, false otherwise */ bool invalidDiversity() const - { + { return invalidDiversityValue; - } + } /** @@ -221,9 +222,9 @@ public: */ void invalidate() { - invalidateObjectiveVector(); - invalidateFitness(); - invalidateDiversity(); + invalidateObjectiveVector(); + invalidateFitness(); + invalidateDiversity(); } @@ -231,9 +232,9 @@ public: * Returns true if the fitness value is invalid, false otherwise */ bool invalid() const - { + { return invalidObjectiveVector(); - } + } /** @@ -243,18 +244,18 @@ public: * @param _other the other MOEO object to compare with */ bool operator<(const MOEO & _other) const - { + { return objectiveVector() < _other.objectiveVector(); - } + } /** * Return the class id (the class name as a std::string) */ virtual std::string className() const - { + { return "MOEO"; - } + } /** @@ -262,16 +263,16 @@ public: * @param _os output stream */ virtual void printOn(std::ostream & _os) const - { + { if ( invalidObjectiveVector() ) - { + { _os << "INVALID\t"; - } + } else - { + { _os << objectiveVectorValue << '\t'; - } - } + } + } /** @@ -280,23 +281,23 @@ public: */ virtual void readFrom(std::istream & _is) { - std::string objectiveVector_str; - int pos = _is.tellg(); - _is >> objectiveVector_str; - if (objectiveVector_str == "INVALID") + std::string objectiveVector_str; + int pos = _is.tellg(); + _is >> objectiveVector_str; + if (objectiveVector_str == "INVALID") { - invalidateObjectiveVector(); + invalidateObjectiveVector(); } - else + else { - invalidObjectiveVectorValue = false; - _is.seekg(pos); // rewind - _is >> objectiveVectorValue; + invalidObjectiveVectorValue = false; + _is.seekg(pos); // rewind + _is >> objectiveVectorValue; } } -private: + private: /** the objective vector of this solution */ ObjectiveVector objectiveVectorValue; @@ -311,6 +312,6 @@ private: /** true if the diversity value is invalid */ bool invalidDiversityValue; -}; + }; #endif /*MOEO_H_*/ diff --git a/trunk/paradiseo-moeo/src/core/moeoBitVector.h b/trunk/paradiseo-moeo/src/core/moeoBitVector.h index 7fcfbb58a..355ea9d51 100644 --- a/trunk/paradiseo-moeo/src/core/moeoBitVector.h +++ b/trunk/paradiseo-moeo/src/core/moeoBitVector.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,8 +45,8 @@ */ template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity > class moeoBitVector : public moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > -{ -public: + { + public: using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: begin; using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: end; @@ -67,22 +67,22 @@ public: * Returns the class name as a std::string */ virtual std::string className() const - { - return "moeoBitVector"; - } - - + { + return "moeoBitVector"; + } + + /** * Writing object * @param _os output stream */ virtual void printOn(std::ostream & _os) const - { + { MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::printOn(_os); _os << ' '; _os << size() << ' '; std::copy(begin(), end(), std::ostream_iterator(_os)); - } + } /** @@ -91,18 +91,18 @@ public: */ virtual void readFrom(std::istream & _is) { - MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::readFrom(_is); - unsigned int s; - _is >> s; - std::string bits; - _is >> bits; - if (_is) + MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::readFrom(_is); + unsigned int s; + _is >> s; + std::string bits; + _is >> bits; + if (_is) { - resize(bits.size()); - std::transform(bits.begin(), bits.end(), begin(), std::bind2nd(std::equal_to(), '1')); + resize(bits.size()); + std::transform(bits.begin(), bits.end(), begin(), std::bind2nd(std::equal_to(), '1')); } } -}; + }; #endif /*MOEOBITVECTOR_H_*/ diff --git a/trunk/paradiseo-moeo/src/core/moeoEvalFunc.h b/trunk/paradiseo-moeo/src/core/moeoEvalFunc.h index e042e3f06..767fe8f9d 100644 --- a/trunk/paradiseo-moeo/src/core/moeoEvalFunc.h +++ b/trunk/paradiseo-moeo/src/core/moeoEvalFunc.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -44,6 +44,7 @@ * Functor that evaluates one MOEO by setting all its objective values. */ template < class MOEOT > -class moeoEvalFunc : public eoEvalFunc< MOEOT > {}; +class moeoEvalFunc : public eoEvalFunc< MOEOT > + {}; #endif /*MOEOEVALFUNC_H_*/ diff --git a/trunk/paradiseo-moeo/src/core/moeoObjectiveVector.h b/trunk/paradiseo-moeo/src/core/moeoObjectiveVector.h index a004f48bd..8629a4db9 100644 --- a/trunk/paradiseo-moeo/src/core/moeoObjectiveVector.h +++ b/trunk/paradiseo-moeo/src/core/moeoObjectiveVector.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -48,8 +48,8 @@ */ template < class ObjectiveVectorTraits, class ObjectiveVectorType > class moeoObjectiveVector : public std::vector < ObjectiveVectorType > -{ -public: + { + public: /** The traits of objective vectors */ typedef ObjectiveVectorTraits Traits; @@ -79,7 +79,7 @@ public: */ static void setup(unsigned int _nObjectives, std::vector < bool > & _bObjectives) { - ObjectiveVectorTraits::setup(_nObjectives, _bObjectives); + ObjectiveVectorTraits::setup(_nObjectives, _bObjectives); } @@ -88,7 +88,7 @@ public: */ static unsigned int nObjectives() { - return ObjectiveVectorTraits::nObjectives(); + return ObjectiveVectorTraits::nObjectives(); } @@ -98,7 +98,7 @@ public: */ static bool minimizing(unsigned int _i) { - return ObjectiveVectorTraits::minimizing(_i); + return ObjectiveVectorTraits::minimizing(_i); } @@ -108,9 +108,9 @@ public: */ static bool maximizing(unsigned int _i) { - return ObjectiveVectorTraits::maximizing(_i); + return ObjectiveVectorTraits::maximizing(_i); } -}; + }; #endif /*MOEOOBJECTIVEVECTOR_H_*/ diff --git a/trunk/paradiseo-moeo/src/core/moeoObjectiveVectorTraits.cpp b/trunk/paradiseo-moeo/src/core/moeoObjectiveVectorTraits.cpp index 8fc6d41c0..ffa042f24 100644 --- a/trunk/paradiseo-moeo/src/core/moeoObjectiveVectorTraits.cpp +++ b/trunk/paradiseo-moeo/src/core/moeoObjectiveVectorTraits.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 diff --git a/trunk/paradiseo-moeo/src/core/moeoObjectiveVectorTraits.h b/trunk/paradiseo-moeo/src/core/moeoObjectiveVectorTraits.h index ba901dfbd..63c4f9697 100644 --- a/trunk/paradiseo-moeo/src/core/moeoObjectiveVectorTraits.h +++ b/trunk/paradiseo-moeo/src/core/moeoObjectiveVectorTraits.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -46,8 +46,8 @@ * A traits class for moeoObjectiveVector to specify the number of objectives and which ones have to be minimized or maximized. */ class moeoObjectiveVectorTraits -{ -public: + { + public: /** * Parameters setting @@ -56,20 +56,21 @@ public: */ static void setup(unsigned int _nObjectives, std::vector < bool > & _bObjectives) { - // in case the number of objectives was already set to a different value - if ( nObj && (nObj != _nObjectives) ) { - std::cout << "WARNING\n"; - std::cout << "WARNING : the number of objectives are changing\n"; - std::cout << "WARNING : Make sure all existing objects are destroyed\n"; - std::cout << "WARNING\n"; + // in case the number of objectives was already set to a different value + if ( nObj && (nObj != _nObjectives) ) + { + std::cout << "WARNING\n"; + std::cout << "WARNING : the number of objectives are changing\n"; + std::cout << "WARNING : Make sure all existing objects are destroyed\n"; + std::cout << "WARNING\n"; } - // number of objectives - nObj = _nObjectives; - // min/max vector - bObj = _bObjectives; - // in case the number of objectives and the min/max vector size don't match - if (nObj != bObj.size()) - throw std::runtime_error("Number of objectives and min/max size don't match in moeoObjectiveVectorTraits::setup"); + // number of objectives + nObj = _nObjectives; + // min/max vector + bObj = _bObjectives; + // in case the number of objectives and the min/max vector size don't match + if (nObj != bObj.size()) + throw std::runtime_error("Number of objectives and min/max size don't match in moeoObjectiveVectorTraits::setup"); } @@ -78,10 +79,10 @@ public: */ static unsigned int nObjectives() { - // in case the number of objectives would not be assigned yet - if (! nObj) - throw std::runtime_error("Number of objectives not assigned in moeoObjectiveVectorTraits"); - return nObj; + // in case the number of objectives would not be assigned yet + if (! nObj) + throw std::runtime_error("Number of objectives not assigned in moeoObjectiveVectorTraits"); + return nObj; } @@ -91,10 +92,10 @@ public: */ static bool minimizing(unsigned int _i) { - // in case there would be a wrong index - if (_i >= bObj.size()) - throw std::runtime_error("Wrong index in moeoObjectiveVectorTraits"); - return bObj[_i]; + // in case there would be a wrong index + if (_i >= bObj.size()) + throw std::runtime_error("Wrong index in moeoObjectiveVectorTraits"); + return bObj[_i]; } @@ -102,8 +103,9 @@ public: * Returns true if the _ith objective have to be maximized * @param _i the index */ - static bool maximizing(unsigned int _i) { - return (! minimizing(_i)); + static bool maximizing(unsigned int _i) + { + return (! minimizing(_i)); } @@ -112,17 +114,17 @@ public: */ static double tolerance() { - return 1e-6; + return 1e-6; } -private: + private: /** The number of objectives */ static unsigned int nObj; /** The min/max vector */ static std::vector < bool > bObj; -}; + }; #endif /*MOEOOBJECTIVEVECTORTRAITS_H_*/ diff --git a/trunk/paradiseo-moeo/src/core/moeoRealObjectiveVector.h b/trunk/paradiseo-moeo/src/core/moeoRealObjectiveVector.h index 740a04061..71ce24b00 100644 --- a/trunk/paradiseo-moeo/src/core/moeoRealObjectiveVector.h +++ b/trunk/paradiseo-moeo/src/core/moeoRealObjectiveVector.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -50,8 +50,8 @@ */ template < class ObjectiveVectorTraits > class moeoRealObjectiveVector : public moeoObjectiveVector < ObjectiveVectorTraits, double > -{ -public: + { + public: using moeoObjectiveVector < ObjectiveVectorTraits, double >::size; using moeoObjectiveVector < ObjectiveVectorTraits, double >::operator[]; @@ -77,10 +77,10 @@ public: * @param _other the other moeoRealObjectiveVector object to compare with */ bool dominates(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const - { + { moeoParetoObjectiveVectorComparator < moeoRealObjectiveVector > comparator; return comparator(_other, *this); - } + } /** @@ -88,16 +88,16 @@ public: * @param _other the other moeoRealObjectiveVector object to compare with */ bool operator==(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const - { + { for (unsigned int i=0; i < size(); i++) - { + { if ( fabs(operator[](i) - _other[i]) > ObjectiveVectorTraits::tolerance() ) - { + { return false; - } - } + } + } return true; - } + } /** @@ -105,9 +105,9 @@ public: * @param _other the other moeoRealObjectiveVector object to compare with */ bool operator!=(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const - { + { return ! operator==(_other); - } + } /** @@ -116,10 +116,10 @@ public: * @param _other the other moeoRealObjectiveVector object to compare with */ bool operator<(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const - { + { moeoObjectiveObjectiveVectorComparator < moeoRealObjectiveVector < ObjectiveVectorTraits > > cmp; return cmp(*this, _other); - } + } /** @@ -128,9 +128,9 @@ public: * @param _other the other moeoRealObjectiveVector object to compare with */ bool operator>(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const - { + { return _other < *this; - } + } /** @@ -139,9 +139,9 @@ public: * @param _other the other moeoRealObjectiveVector object to compare with */ bool operator<=(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const - { + { return operator==(_other) || operator<(_other); - } + } /** @@ -150,11 +150,11 @@ public: * @param _other the other moeoRealObjectiveVector object to compare with */ bool operator>=(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const - { + { return operator==(_other) || operator>(_other); - } + } -}; + }; /** @@ -165,11 +165,11 @@ public: template < class ObjectiveVectorTraits > std::ostream & operator<<(std::ostream & _os, const moeoRealObjectiveVector < ObjectiveVectorTraits > & _objectiveVector) { - for (unsigned int i=0; i<_objectiveVector.size(); i++) + for (unsigned int i=0; i<_objectiveVector.size(); i++) { - _os << _objectiveVector[i] << '\t'; + _os << _objectiveVector[i] << '\t'; } - return _os; + return _os; } /** @@ -180,12 +180,12 @@ std::ostream & operator<<(std::ostream & _os, const moeoRealObjectiveVector < Ob template < class ObjectiveVectorTraits > std::istream & operator>>(std::istream & _is, moeoRealObjectiveVector < ObjectiveVectorTraits > & _objectiveVector) { - _objectiveVector = moeoRealObjectiveVector < ObjectiveVectorTraits > (); - for (unsigned int i=0; i<_objectiveVector.size(); i++) + _objectiveVector = moeoRealObjectiveVector < ObjectiveVectorTraits > (); + for (unsigned int i=0; i<_objectiveVector.size(); i++) { - _is >> _objectiveVector[i]; + _is >> _objectiveVector[i]; } - return _is; + return _is; } #endif /*MOEOREALOBJECTIVEVECTOR_H_*/ diff --git a/trunk/paradiseo-moeo/src/core/moeoRealVector.h b/trunk/paradiseo-moeo/src/core/moeoRealVector.h index 71bc36bed..6a5dd07bb 100644 --- a/trunk/paradiseo-moeo/src/core/moeoRealVector.h +++ b/trunk/paradiseo-moeo/src/core/moeoRealVector.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,8 +45,8 @@ */ template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity > class moeoRealVector : public moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, double > -{ -public: + { + public: /** * Ctor @@ -55,16 +55,16 @@ public: */ moeoRealVector(unsigned int _size = 0, double _value = 0.0) : moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, double >(_size, _value) {} - - + + /** * Returns the class name as a std::string */ virtual std::string className() const - { - return "moeoRealVector"; - } - -}; + { + return "moeoRealVector"; + } + + }; #endif /*MOEOREALVECTOR_H_*/ diff --git a/trunk/paradiseo-moeo/src/core/moeoVector.h b/trunk/paradiseo-moeo/src/core/moeoVector.h index 6eb8f58cb..407d8ba22 100644 --- a/trunk/paradiseo-moeo/src/core/moeoVector.h +++ b/trunk/paradiseo-moeo/src/core/moeoVector.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -48,8 +48,8 @@ */ template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity, class GeneType > class moeoVector : public MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >, public std::vector < GeneType > -{ -public: + { + public: using MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity > :: invalidate; using std::vector < GeneType > :: operator[]; @@ -70,30 +70,30 @@ public: * @param _value Initial value of all elements (default is default value of type GeneType) */ moeoVector(unsigned int _size = 0, GeneType _value = GeneType()) : - MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >(), std::vector(_size, _value) + MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >(), std::vector(_size, _value) {} - - + + /** * We can't have a Ctor from a std::vector as it would create ambiguity with the copy Ctor. * @param _v a vector of GeneType */ void value(const std::vector < GeneType > & _v) { - if (_v.size() != size()) // safety check + if (_v.size() != size()) // safety check { - if (size()) // NOT an initial empty std::vector + if (size()) // NOT an initial empty std::vector { - std::cout << "Warning: Changing size in moeoVector assignation"< & _moeo) const - { + { return MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::operator<(_moeo); - } + } /** @@ -112,12 +112,12 @@ public: * @param _os output stream */ virtual void printOn(std::ostream & _os) const - { + { MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::printOn(_os); _os << ' '; _os << size() << ' '; std::copy(begin(), end(), std::ostream_iterator(_os, " ")); - } + } /** @@ -126,20 +126,20 @@ public: */ virtual void readFrom(std::istream & _is) { - MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::readFrom(_is); - unsigned int sz; - _is >> sz; - resize(sz); - unsigned int i; - for (i = 0; i < sz; ++i) + MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::readFrom(_is); + unsigned int sz; + _is >> sz; + resize(sz); + unsigned int i; + for (i = 0; i < sz; ++i) { - AtomType atom; - _is >> atom; - operator[](i) = atom; + AtomType atom; + _is >> atom; + operator[](i) = atom; } } -}; + }; /** @@ -150,7 +150,7 @@ public: template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity, class GeneType > bool operator<(const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo1, const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo2) { - return _moeo1.operator<(_moeo2); + return _moeo1.operator<(_moeo2); } @@ -162,7 +162,7 @@ bool operator<(const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity, class GeneType > bool operator>(const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo1, const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo2) { - return _moeo1.operator>(_moeo2); + return _moeo1.operator>(_moeo2); } #endif /*MOEOVECTOR_H_*/ diff --git a/trunk/paradiseo-moeo/src/distance/moeoDistance.h b/trunk/paradiseo-moeo/src/distance/moeoDistance.h index be2c5049f..d5cf75c75 100644 --- a/trunk/paradiseo-moeo/src/distance/moeoDistance.h +++ b/trunk/paradiseo-moeo/src/distance/moeoDistance.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,8 +45,8 @@ */ template < class MOEOT , class Type > class moeoDistance : public eoBF < const MOEOT &, const MOEOT &, const Type > -{ -public: + { + public: /** * Nothing to do @@ -74,6 +74,6 @@ public: virtual void setup(eoRealInterval _realInterval, unsigned int _obj) {} -}; + }; #endif /*MOEODISTANCE_H_*/ diff --git a/trunk/paradiseo-moeo/src/distance/moeoDistanceMatrix.h b/trunk/paradiseo-moeo/src/distance/moeoDistanceMatrix.h index 0f95b3cbc..40514dc28 100644 --- a/trunk/paradiseo-moeo/src/distance/moeoDistanceMatrix.h +++ b/trunk/paradiseo-moeo/src/distance/moeoDistanceMatrix.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -47,8 +47,8 @@ */ template < class MOEOT , class Type > class moeoDistanceMatrix : public eoUF < const eoPop < MOEOT > &, void > , public std::vector< std::vector < Type > > -{ -public: + { + public: using std::vector< std::vector < Type > > :: size; using std::vector< std::vector < Type > > :: operator[]; @@ -61,10 +61,10 @@ public: */ moeoDistanceMatrix (unsigned int _size, moeoDistance < MOEOT , Type > & _distance) : distance(_distance) { - this->resize(_size); - for (unsigned int i=0; i<_size; i++) + this->resize(_size); + for (unsigned int i=0; i<_size; i++) { - this->operator[](i).resize(_size); + this->operator[](i).resize(_size); } } @@ -75,27 +75,27 @@ public: */ void operator()(const eoPop < MOEOT > & _pop) { - // 1 - setup the bounds (if necessary) - distance.setup(_pop); - // 2 - compute distances - this->operator[](0).operator[](0) = Type(); - for (unsigned int i=0; ioperator[](0).operator[](0) = Type(); + for (unsigned int i=0; ioperator[](i).operator[](i) = Type(); - for (unsigned int j=0; joperator[](i).operator[](i) = Type(); + for (unsigned int j=0; joperator[](i).operator[](j) = distance(_pop[i], _pop[j]); - this->operator[](j).operator[](i) = this->operator[](i).operator[](j); + this->operator[](i).operator[](j) = distance(_pop[i], _pop[j]); + this->operator[](j).operator[](i) = this->operator[](i).operator[](j); } } } -private: + private: /** the distance to use */ moeoDistance < MOEOT , Type > & distance; -}; + }; #endif /*MOEODISTANCEMATRIX_H_*/ diff --git a/trunk/paradiseo-moeo/src/distance/moeoEuclideanDistance.h b/trunk/paradiseo-moeo/src/distance/moeoEuclideanDistance.h index 8f771086b..7b29cce17 100644 --- a/trunk/paradiseo-moeo/src/distance/moeoEuclideanDistance.h +++ b/trunk/paradiseo-moeo/src/distance/moeoEuclideanDistance.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -47,8 +47,8 @@ */ template < class MOEOT > class moeoEuclideanDistance : public moeoNormalizedDistance < MOEOT > -{ -public: + { + public: /** the objective vector type of the solutions */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -61,23 +61,23 @@ public: */ const double operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { - double result = 0.0; - double tmp1, tmp2; - for (unsigned int i=0; i :: bounds; -}; + }; #endif /*MOEOEUCLIDEANDISTANCE_H_*/ diff --git a/trunk/paradiseo-moeo/src/distance/moeoManhattanDistance.h b/trunk/paradiseo-moeo/src/distance/moeoManhattanDistance.h index a168518b9..91eea6f3d 100644 --- a/trunk/paradiseo-moeo/src/distance/moeoManhattanDistance.h +++ b/trunk/paradiseo-moeo/src/distance/moeoManhattanDistance.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -47,8 +47,8 @@ */ template < class MOEOT > class moeoManhattanDistance : public moeoNormalizedDistance < MOEOT > -{ -public: + { + public: /** the objective vector type of the solutions */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -61,23 +61,23 @@ public: */ const double operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { - double result = 0.0; - double tmp1, tmp2; - for (unsigned int i=0; i :: bounds; -}; + }; #endif /*MOEOMANHATTANDISTANCE_H_*/ diff --git a/trunk/paradiseo-moeo/src/distance/moeoNormalizedDistance.h b/trunk/paradiseo-moeo/src/distance/moeoNormalizedDistance.h index 6405b78fa..8cf2f93a5 100644 --- a/trunk/paradiseo-moeo/src/distance/moeoNormalizedDistance.h +++ b/trunk/paradiseo-moeo/src/distance/moeoNormalizedDistance.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -47,8 +47,8 @@ */ template < class MOEOT , class Type = double > class moeoNormalizedDistance : public moeoDistance < MOEOT , Type > -{ -public: + { + public: /** the objective vector type of the solutions */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -59,11 +59,11 @@ public: */ moeoNormalizedDistance() { - bounds.resize(ObjectiveVector::Traits::nObjectives()); - // initialize bounds in case someone does not want to use them - for (unsigned int i=0; i & _pop) { - double min, max; - for (unsigned int i=0; i bounds; -}; + }; #endif /*MOEONORMALIZEDDISTANCE_H_*/ diff --git a/trunk/paradiseo-moeo/src/diversity/moeoCrowdingDiversityAssignment.h b/trunk/paradiseo-moeo/src/diversity/moeoCrowdingDiversityAssignment.h index da97dcb04..119436091 100644 --- a/trunk/paradiseo-moeo/src/diversity/moeoCrowdingDiversityAssignment.h +++ b/trunk/paradiseo-moeo/src/diversity/moeoCrowdingDiversityAssignment.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -48,8 +48,8 @@ */ template < class MOEOT > class moeoCrowdingDiversityAssignment : public moeoDiversityAssignment < MOEOT > -{ -public: + { + public: /** the objective vector type of the solutions */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -59,18 +59,18 @@ public: * Returns a big value (regarded as infinite) */ double inf() const - { + { return std::numeric_limits::max(); - } + } /** * Returns a very small value that can be used to avoid extreme cases (where the min bound == the max bound) */ double tiny() const - { + { return 1e-6; - } + } /** @@ -79,16 +79,16 @@ public: */ void operator()(eoPop < MOEOT > & _pop) { - if (_pop.size() <= 2) + if (_pop.size() <= 2) { - for (unsigned int i=0; i<_pop.size(); i++) + for (unsigned int i=0; i<_pop.size(); i++) { - _pop[i].diversity(inf()); + _pop[i].diversity(inf()); } } - else + else { - setDistances(_pop); + setDistances(_pop); } } @@ -102,11 +102,11 @@ public: */ void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) { - std::cout << "WARNING : updateByDeleting not implemented in moeoCrowdingDiversityAssignment" << std::endl; + std::cout << "WARNING : updateByDeleting not implemented in moeoCrowdingDiversityAssignment" << std::endl; } -protected: + protected: /** * Sets the distance values @@ -114,34 +114,34 @@ protected: */ virtual void setDistances (eoPop < MOEOT > & _pop) { - double min, max, distance; - unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives(); - // set diversity to 0 - for (unsigned int i=0; i<_pop.size(); i++) + double min, max, distance; + unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives(); + // set diversity to 0 + for (unsigned int i=0; i<_pop.size(); i++) { - _pop[i].diversity(0); + _pop[i].diversity(0); } - // for each objective - for (unsigned int obj=0; obj objComp(obj); - // sort - std::sort(_pop.begin(), _pop.end(), objComp); - // min & max - min = _pop[0].objectiveVector()[obj]; - max = _pop[_pop.size()-1].objectiveVector()[obj]; - // set the diversity value to infiny for min and max - _pop[0].diversity(inf()); - _pop[_pop.size()-1].diversity(inf()); - for (unsigned int i=1; i<_pop.size()-1; i++) + // comparator + moeoOneObjectiveComparator < MOEOT > objComp(obj); + // sort + std::sort(_pop.begin(), _pop.end(), objComp); + // min & max + min = _pop[0].objectiveVector()[obj]; + max = _pop[_pop.size()-1].objectiveVector()[obj]; + // set the diversity value to infiny for min and max + _pop[0].diversity(inf()); + _pop[_pop.size()-1].diversity(inf()); + for (unsigned int i=1; i<_pop.size()-1; i++) { - distance = (_pop[i+1].objectiveVector()[obj] - _pop[i-1].objectiveVector()[obj]) / (max-min); - _pop[i].diversity(_pop[i].diversity() + distance); + distance = (_pop[i+1].objectiveVector()[obj] - _pop[i-1].objectiveVector()[obj]) / (max-min); + _pop[i].diversity(_pop[i].diversity() + distance); } } } -}; + }; #endif /*MOEOCROWDINGDIVERSITYASSIGNMENT_H_*/ diff --git a/trunk/paradiseo-moeo/src/diversity/moeoDiversityAssignment.h b/trunk/paradiseo-moeo/src/diversity/moeoDiversityAssignment.h index 9b9480600..1f3e50560 100644 --- a/trunk/paradiseo-moeo/src/diversity/moeoDiversityAssignment.h +++ b/trunk/paradiseo-moeo/src/diversity/moeoDiversityAssignment.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -46,8 +46,8 @@ */ template < class MOEOT > class moeoDiversityAssignment : public eoUF < eoPop < MOEOT > &, void > -{ -public: + { + public: /** The type for objective vector */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -68,9 +68,9 @@ public: */ void updateByDeleting(eoPop < MOEOT > & _pop, MOEOT & _moeo) { - updateByDeleting(_pop, _moeo.objectiveVector()); + updateByDeleting(_pop, _moeo.objectiveVector()); } -}; + }; #endif /*MOEODIVERSITYASSIGNMENT_H_*/ diff --git a/trunk/paradiseo-moeo/src/diversity/moeoDummyDiversityAssignment.h b/trunk/paradiseo-moeo/src/diversity/moeoDummyDiversityAssignment.h index 2a9931e98..f36a75252 100644 --- a/trunk/paradiseo-moeo/src/diversity/moeoDummyDiversityAssignment.h +++ b/trunk/paradiseo-moeo/src/diversity/moeoDummyDiversityAssignment.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,8 +45,8 @@ */ template < class MOEOT > class moeoDummyDiversityAssignment : public moeoDiversityAssignment < MOEOT > -{ -public: + { + public: /** The type for objective vector */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -58,12 +58,12 @@ public: */ void operator () (eoPop < MOEOT > & _pop) { - for (unsigned int idx = 0; idx<_pop.size (); idx++) + for (unsigned int idx = 0; idx<_pop.size (); idx++) { - if (_pop[idx].invalidDiversity()) + if (_pop[idx].invalidDiversity()) { - // set the diversity to 0 - _pop[idx].diversity(0.0); + // set the diversity to 0 + _pop[idx].diversity(0.0); } } } @@ -76,9 +76,9 @@ public: */ void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) { - // nothing to do... ;-) + // nothing to do... ;-) } -}; + }; #endif /*MOEODUMMYDIVERSITYASSIGNMENT_H_*/ diff --git a/trunk/paradiseo-moeo/src/diversity/moeoFrontByFrontCrowdingDiversityAssignment.h b/trunk/paradiseo-moeo/src/diversity/moeoFrontByFrontCrowdingDiversityAssignment.h index 3569e2459..f089649d2 100644 --- a/trunk/paradiseo-moeo/src/diversity/moeoFrontByFrontCrowdingDiversityAssignment.h +++ b/trunk/paradiseo-moeo/src/diversity/moeoFrontByFrontCrowdingDiversityAssignment.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -48,8 +48,8 @@ */ template < class MOEOT > class moeoFrontByFrontCrowdingDiversityAssignment : public moeoCrowdingDiversityAssignment < MOEOT > -{ -public: + { + public: /** the objective vector type of the solutions */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -64,11 +64,11 @@ public: */ void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) { - std::cout << "WARNING : updateByDeleting not implemented in moeoFrontByFrontCrowdingDistanceDiversityAssignment" << std::endl; + std::cout << "WARNING : updateByDeleting not implemented in moeoFrontByFrontCrowdingDistanceDiversityAssignment" << std::endl; } -private: + private: using moeoCrowdingDiversityAssignment < MOEOT >::inf; using moeoCrowdingDiversityAssignment < MOEOT >::tiny; @@ -79,61 +79,61 @@ private: */ void setDistances (eoPop < MOEOT > & _pop) { - unsigned int a,b; - double min, max, distance; - unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives(); - // set diversity to 0 for every individual - for (unsigned int i=0; i<_pop.size(); i++) + unsigned int a,b; + double min, max, distance; + unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives(); + // set diversity to 0 for every individual + for (unsigned int i=0; i<_pop.size(); i++) { - _pop[i].diversity(0.0); + _pop[i].diversity(0.0); } - // sort the whole pop according to fitness values - moeoFitnessThenDiversityComparator < MOEOT > fitnessComparator; - std::sort(_pop.begin(), _pop.end(), fitnessComparator); - // compute the crowding distance values for every individual "front" by "front" (front : from a to b) - a = 0; // the front starts at a - while (a < _pop.size()) + // sort the whole pop according to fitness values + moeoFitnessThenDiversityComparator < MOEOT > fitnessComparator; + std::sort(_pop.begin(), _pop.end(), fitnessComparator); + // compute the crowding distance values for every individual "front" by "front" (front : from a to b) + a = 0; // the front starts at a + while (a < _pop.size()) { - b = lastIndex(_pop,a); // the front ends at b - // if there is less than 2 individuals in the front... - if ((b-a) < 2) + b = lastIndex(_pop,a); // the front ends at b + // if there is less than 2 individuals in the front... + if ((b-a) < 2) { - for (unsigned int i=a; i<=b; i++) + for (unsigned int i=a; i<=b; i++) { - _pop[i].diversity(inf()); + _pop[i].diversity(inf()); } } - // else... - else + // else... + else { - // for each objective - for (unsigned int obj=0; obj objComp(obj); - std::sort(_pop.begin()+a, _pop.begin()+b+1, objComp); - // min & max - min = _pop[b].objectiveVector()[obj]; - max = _pop[a].objectiveVector()[obj]; - // avoid extreme case - if (min == max) + // sort in the descending order using the values of the objective 'obj' + moeoOneObjectiveComparator < MOEOT > objComp(obj); + std::sort(_pop.begin()+a, _pop.begin()+b+1, objComp); + // min & max + min = _pop[b].objectiveVector()[obj]; + max = _pop[a].objectiveVector()[obj]; + // avoid extreme case + if (min == max) { - min -= tiny(); - max += tiny(); + min -= tiny(); + max += tiny(); } - // set the diversity value to infiny for min and max - _pop[a].diversity(inf()); - _pop[b].diversity(inf()); - // set the diversity values for the other individuals - for (unsigned int i=a+1; i & _pop, unsigned int _start) { - unsigned int i=_start; - while ( (i<_pop.size()-1) && (_pop[i].fitness()==_pop[i+1].fitness()) ) + unsigned int i=_start; + while ( (i<_pop.size()-1) && (_pop[i].fitness()==_pop[i+1].fitness()) ) { - i++; + i++; } - return i; + return i; } -}; + }; #endif /*MOEOFRONTBYFRONTCROWDINGDIVERSITYASSIGNMENT_H_*/ diff --git a/trunk/paradiseo-moeo/src/diversity/moeoFrontByFrontSharingDiversityAssignment.h b/trunk/paradiseo-moeo/src/diversity/moeoFrontByFrontSharingDiversityAssignment.h index 52d55c848..20291e19c 100644 --- a/trunk/paradiseo-moeo/src/diversity/moeoFrontByFrontSharingDiversityAssignment.h +++ b/trunk/paradiseo-moeo/src/diversity/moeoFrontByFrontSharingDiversityAssignment.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,8 +45,8 @@ */ template < class MOEOT > class moeoFrontByFrontSharingDiversityAssignment : public moeoSharingDiversityAssignment < MOEOT > -{ -public: + { + public: /** the objective vector type of the solutions */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -80,11 +80,11 @@ public: */ void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) { - std::cout << "WARNING : updateByDeleting not implemented in moeoSharingDiversityAssignment" << std::endl; + std::cout << "WARNING : updateByDeleting not implemented in moeoSharingDiversityAssignment" << std::endl; } -private: + private: using moeoSharingDiversityAssignment < MOEOT >::distance; using moeoSharingDiversityAssignment < MOEOT >::nicheSize; @@ -98,34 +98,34 @@ private: */ void setSimilarities(eoPop < MOEOT > & _pop) { - // compute distances between every individuals - moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance); - dMatrix(_pop); - // sets the distance to bigger than the niche size for every couple of solutions that do not belong to the same front - for (unsigned int i=0; i<_pop.size(); i++) + // compute distances between every individuals + moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance); + dMatrix(_pop); + // sets the distance to bigger than the niche size for every couple of solutions that do not belong to the same front + for (unsigned int i=0; i<_pop.size(); i++) { - for (unsigned int j=0; j * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -51,8 +51,8 @@ */ template < class MOEOT > class moeoSharingDiversityAssignment : public moeoDiversityAssignment < MOEOT > -{ -public: + { + public: /** the objective vector type of the solutions */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -83,14 +83,14 @@ public: */ void operator()(eoPop < MOEOT > & _pop) { - // 1 - set simuilarities - setSimilarities(_pop); - // 2 - a higher diversity is better, so the values need to be inverted - moeoDiversityThenFitnessComparator < MOEOT > divComparator; - double max = std::max_element(_pop.begin(), _pop.end(), divComparator)->diversity(); - for (unsigned int i=0 ; i<_pop.size() ; i++) + // 1 - set simuilarities + setSimilarities(_pop); + // 2 - a higher diversity is better, so the values need to be inverted + moeoDiversityThenFitnessComparator < MOEOT > divComparator; + double max = std::max_element(_pop.begin(), _pop.end(), divComparator)->diversity(); + for (unsigned int i=0 ; i<_pop.size() ; i++) { - _pop[i].diversity(max - _pop[i].diversity()); + _pop[i].diversity(max - _pop[i].diversity()); } } @@ -104,11 +104,11 @@ public: */ void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) { - std::cout << "WARNING : updateByDeleting not implemented in moeoSharingDiversityAssignment" << std::endl; + std::cout << "WARNING : updateByDeleting not implemented in moeoSharingDiversityAssignment" << std::endl; } -protected: + protected: /** the distance used to compute the neighborhood of solutions */ moeoDistance < MOEOT , double > & distance; @@ -126,19 +126,19 @@ protected: */ virtual void setSimilarities(eoPop < MOEOT > & _pop) { - // compute distances between every individuals - moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance); - dMatrix(_pop); - // compute similarities - double sum; - for (unsigned int i=0; i<_pop.size(); i++) + // compute distances between every individuals + moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance); + dMatrix(_pop); + // compute similarities + double sum; + for (unsigned int i=0; i<_pop.size(); i++) { - sum = 0.0; - for (unsigned int j=0; j<_pop.size(); j++) + sum = 0.0; + for (unsigned int j=0; j<_pop.size(); j++) { - sum += sh(dMatrix[i][j]); + sum += sh(dMatrix[i][j]); } - _pop[i].diversity(sum); + _pop[i].diversity(sum); } } @@ -149,19 +149,19 @@ protected: */ double sh(double _dist) { - double result; - if (_dist < nicheSize) + double result; + if (_dist < nicheSize) { - result = 1.0 - pow(_dist / nicheSize, alpha); + result = 1.0 - pow(_dist / nicheSize, alpha); } - else + else { - result = 0.0; + result = 0.0; } - return result; + return result; } -}; + }; #endif /*MOEOSHARINGDIVERSITYASSIGNMENT_H_*/ diff --git a/trunk/paradiseo-moeo/src/do/make_checkpoint_moeo.h b/trunk/paradiseo-moeo/src/do/make_checkpoint_moeo.h index 6b7cb2df0..e24d7a23b 100755 --- a/trunk/paradiseo-moeo/src/do/make_checkpoint_moeo.h +++ b/trunk/paradiseo-moeo/src/do/make_checkpoint_moeo.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -66,136 +66,136 @@ bool testDirRes(std::string _dirName, bool _erase); template < class MOEOT > eoCheckPoint < MOEOT > & do_make_checkpoint_moeo (eoParser & _parser, eoState & _state, eoEvalFuncCounter < MOEOT > & _eval, eoContinue < MOEOT > & _continue, eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _archive) { - eoCheckPoint < MOEOT > & checkpoint = _state.storeFunctor(new eoCheckPoint < MOEOT > (_continue)); - /* the objective vector type */ - typedef typename MOEOT::ObjectiveVector ObjectiveVector; - - /////////////////// - // Counters - ////////////////// - // is nb Eval to be used as counter? - //bool useEval = _parser.getORcreateParam(true, "useEval", "Use nb of eval. as counter (vs nb of gen.)", '\0', "Output").value(); - // Create anyway a generation-counter parameter - eoValueParam *generationCounter = new eoValueParam(0, "Gen."); - // Create an incrementor (sub-class of eoUpdater). - eoIncrementor & increment = _state.storeFunctor( new eoIncrementor(generationCounter->value()) ); - // Add it to the checkpoint - checkpoint.add(increment); - // dir for DISK output - std::string & dirName = _parser.getORcreateParam(std::string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output").value(); - // shoudl we empty it if exists - eoValueParam& eraseParam = _parser.getORcreateParam(true, "eraseDir", "erase files in dirName if any", '\0', "Output"); - bool dirOK = false; // not tested yet + eoCheckPoint < MOEOT > & checkpoint = _state.storeFunctor(new eoCheckPoint < MOEOT > (_continue)); + /* the objective vector type */ + typedef typename MOEOT::ObjectiveVector ObjectiveVector; - // Dump of the whole population - //----------------------------- - bool printPop = _parser.getORcreateParam(false, "printPop", "Print sorted pop. every gen.", '\0', "Output").value(); - eoSortedPopStat * popStat; - if ( printPop ) // we do want pop dump + /////////////////// + // Counters + ////////////////// + // is nb Eval to be used as counter? + //bool useEval = _parser.getORcreateParam(true, "useEval", "Use nb of eval. as counter (vs nb of gen.)", '\0', "Output").value(); + // Create anyway a generation-counter parameter + eoValueParam *generationCounter = new eoValueParam(0, "Gen."); + // Create an incrementor (sub-class of eoUpdater). + eoIncrementor & increment = _state.storeFunctor( new eoIncrementor(generationCounter->value()) ); + // Add it to the checkpoint + checkpoint.add(increment); + // dir for DISK output + std::string & dirName = _parser.getORcreateParam(std::string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output").value(); + // shoudl we empty it if exists + eoValueParam& eraseParam = _parser.getORcreateParam(true, "eraseDir", "erase files in dirName if any", '\0', "Output"); + bool dirOK = false; // not tested yet + + // Dump of the whole population + //----------------------------- + bool printPop = _parser.getORcreateParam(false, "printPop", "Print sorted pop. every gen.", '\0', "Output").value(); + eoSortedPopStat * popStat; + if ( printPop ) // we do want pop dump { - popStat = & _state.storeFunctor(new eoSortedPopStat); - checkpoint.add(*popStat); + popStat = & _state.storeFunctor(new eoSortedPopStat); + checkpoint.add(*popStat); } - ////////////////////////////////// - // State savers - ////////////////////////////// - // feed the state to state savers - // save state every N generation - eoValueParam& saveFrequencyParam = _parser.createParam((unsigned int)(0), "saveFrequency", "Save every F generation (0 = only final state, absent = never)", '\0', "Persistence" ); - if (_parser.isItThere(saveFrequencyParam)) + ////////////////////////////////// + // State savers + ////////////////////////////// + // feed the state to state savers + // save state every N generation + eoValueParam& saveFrequencyParam = _parser.createParam((unsigned int)(0), "saveFrequency", "Save every F generation (0 = only final state, absent = never)", '\0', "Persistence" ); + if (_parser.isItThere(saveFrequencyParam)) { - // first make sure dirName is OK - if (! dirOK ) - dirOK = testDirRes(dirName, eraseParam.value()); // TRUE - unsigned int freq = (saveFrequencyParam.value()>0 ? saveFrequencyParam.value() : UINT_MAX ); + // first make sure dirName is OK + if (! dirOK ) + dirOK = testDirRes(dirName, eraseParam.value()); // TRUE + unsigned int freq = (saveFrequencyParam.value()>0 ? saveFrequencyParam.value() : UINT_MAX ); #ifdef _MSVC - std::string stmp = dirName + "\generations"; + std::string stmp = dirName + "\generations"; #else - std::string stmp = dirName + "/generations"; + std::string stmp = dirName + "/generations"; #endif - eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp); - _state.storeFunctor(stateSaver1); - checkpoint.add(*stateSaver1); + eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp); + _state.storeFunctor(stateSaver1); + checkpoint.add(*stateSaver1); } - // save state every T seconds - eoValueParam& saveTimeIntervalParam = _parser.getORcreateParam((unsigned int)(0), "saveTimeInterval", "Save every T seconds (0 or absent = never)", '\0',"Persistence" ); - if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0) + // save state every T seconds + eoValueParam& saveTimeIntervalParam = _parser.getORcreateParam((unsigned int)(0), "saveTimeInterval", "Save every T seconds (0 or absent = never)", '\0',"Persistence" ); + if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0) { - // first make sure dirName is OK - if (! dirOK ) - dirOK = testDirRes(dirName, eraseParam.value()); // TRUE + // first make sure dirName is OK + if (! dirOK ) + dirOK = testDirRes(dirName, eraseParam.value()); // TRUE #ifdef _MSVC - std::string stmp = dirName + "\time"; + std::string stmp = dirName + "\time"; #else - std::string stmp = dirName + "/time"; + std::string stmp = dirName + "/time"; #endif - eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp); - _state.storeFunctor(stateSaver2); - checkpoint.add(*stateSaver2); + eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp); + _state.storeFunctor(stateSaver2); + checkpoint.add(*stateSaver2); } - /////////////////// - // Archive - ////////////////// - // update the archive every generation - bool updateArch = _parser.getORcreateParam(true, "updateArch", "Update the archive at each gen.", '\0', "Evolution Engine").value(); - if (updateArch) + /////////////////// + // Archive + ////////////////// + // update the archive every generation + bool updateArch = _parser.getORcreateParam(true, "updateArch", "Update the archive at each gen.", '\0', "Evolution Engine").value(); + if (updateArch) { - moeoArchiveUpdater < MOEOT > * updater = new moeoArchiveUpdater < MOEOT > (_archive, _pop); - _state.storeFunctor(updater); - checkpoint.add(*updater); + moeoArchiveUpdater < MOEOT > * updater = new moeoArchiveUpdater < MOEOT > (_archive, _pop); + _state.storeFunctor(updater); + checkpoint.add(*updater); } - // store the objective vectors contained in the archive every generation - bool storeArch = _parser.getORcreateParam(false, "storeArch", "Store the archive's objective vectors at each gen.", '\0', "Output").value(); - if (storeArch) + // store the objective vectors contained in the archive every generation + bool storeArch = _parser.getORcreateParam(false, "storeArch", "Store the archive's objective vectors at each gen.", '\0', "Output").value(); + if (storeArch) { - if (! dirOK ) - dirOK = testDirRes(dirName, eraseParam.value()); // TRUE + if (! dirOK ) + dirOK = testDirRes(dirName, eraseParam.value()); // TRUE #ifdef _MSVC - std::string stmp = dirName + "\arch"; + std::string stmp = dirName + "\arch"; #else - std::string stmp = dirName + "/arch"; + std::string stmp = dirName + "/arch"; #endif - moeoArchiveObjectiveVectorSavingUpdater < MOEOT > * save_updater = new moeoArchiveObjectiveVectorSavingUpdater < MOEOT > (_archive, stmp); - _state.storeFunctor(save_updater); - checkpoint.add(*save_updater); + moeoArchiveObjectiveVectorSavingUpdater < MOEOT > * save_updater = new moeoArchiveObjectiveVectorSavingUpdater < MOEOT > (_archive, stmp); + _state.storeFunctor(save_updater); + checkpoint.add(*save_updater); } - // store the contribution of the non-dominated solutions - bool cont = _parser.getORcreateParam(false, "contribution", "Store the contribution of the archive at each gen.", '\0', "Output").value(); - if (cont) + // store the contribution of the non-dominated solutions + bool cont = _parser.getORcreateParam(false, "contribution", "Store the contribution of the archive at each gen.", '\0', "Output").value(); + if (cont) { - if (! dirOK ) - dirOK = testDirRes(dirName, eraseParam.value()); // TRUE + if (! dirOK ) + dirOK = testDirRes(dirName, eraseParam.value()); // TRUE #ifdef _MSVC - std::string stmp = dirName + "\contribution"; + std::string stmp = dirName + "\contribution"; #else - std::string stmp = dirName + "/contribution"; + std::string stmp = dirName + "/contribution"; #endif - moeoContributionMetric < ObjectiveVector > * contribution = new moeoContributionMetric < ObjectiveVector >; - moeoBinaryMetricSavingUpdater < MOEOT > * contribution_updater = new moeoBinaryMetricSavingUpdater < MOEOT > (*contribution, _archive, stmp); - _state.storeFunctor(contribution_updater); - checkpoint.add(*contribution_updater); + moeoContributionMetric < ObjectiveVector > * contribution = new moeoContributionMetric < ObjectiveVector >; + moeoBinaryMetricSavingUpdater < MOEOT > * contribution_updater = new moeoBinaryMetricSavingUpdater < MOEOT > (*contribution, _archive, stmp); + _state.storeFunctor(contribution_updater); + checkpoint.add(*contribution_updater); } - // store the entropy of the non-dominated solutions - bool ent = _parser.getORcreateParam(false, "entropy", "Store the entropy of the archive at each gen.", '\0', "Output").value(); - if (ent) + // store the entropy of the non-dominated solutions + bool ent = _parser.getORcreateParam(false, "entropy", "Store the entropy of the archive at each gen.", '\0', "Output").value(); + if (ent) { - if (! dirOK ) - dirOK = testDirRes(dirName, eraseParam.value()); // TRUE + if (! dirOK ) + dirOK = testDirRes(dirName, eraseParam.value()); // TRUE #ifdef _MSVC - std::string stmp = dirName + "\entropy"; + std::string stmp = dirName + "\entropy"; #else - std::string stmp = dirName + "/entropy"; + std::string stmp = dirName + "/entropy"; #endif - moeoEntropyMetric < ObjectiveVector > * entropy = new moeoEntropyMetric < ObjectiveVector >; - moeoBinaryMetricSavingUpdater < MOEOT > * entropy_updater = new moeoBinaryMetricSavingUpdater < MOEOT > (*entropy, _archive, stmp); - _state.storeFunctor(entropy_updater); - checkpoint.add(*entropy_updater); + moeoEntropyMetric < ObjectiveVector > * entropy = new moeoEntropyMetric < ObjectiveVector >; + moeoBinaryMetricSavingUpdater < MOEOT > * entropy_updater = new moeoBinaryMetricSavingUpdater < MOEOT > (*entropy, _archive, stmp); + _state.storeFunctor(entropy_updater); + checkpoint.add(*entropy_updater); } - // and that's it for the (control and) output - return checkpoint; + // and that's it for the (control and) output + return checkpoint; } #endif /*MAKE_CHECKPOINT_MOEO_H_*/ diff --git a/trunk/paradiseo-moeo/src/do/make_continue_moeo.h b/trunk/paradiseo-moeo/src/do/make_continue_moeo.h index ec3019561..215ef6e17 100755 --- a/trunk/paradiseo-moeo/src/do/make_continue_moeo.h +++ b/trunk/paradiseo-moeo/src/do/make_continue_moeo.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -58,11 +58,11 @@ template eoCombinedContinue * make_combinedContinue(eoCombinedContinue *_combined, eoContinue *_cont) { - if (_combined) // already exists - _combined->add(*_cont); - else - _combined = new eoCombinedContinue(*_cont); - return _combined; + if (_combined) // already exists + _combined->add(*_cont); + else + _combined = new eoCombinedContinue(*_cont); + return _combined; } @@ -75,57 +75,57 @@ eoCombinedContinue * make_combinedContinue(eoCombinedContinue *_co template eoContinue & do_make_continue_moeo(eoParser& _parser, eoState& _state, eoEvalFuncCounter & _eval) { - // the combined continue - to be filled - eoCombinedContinue *continuator = NULL; - // First the eoGenContinue - need a default value so you can run blind - // but we also need to be able to avoid it <--> 0 - eoValueParam& maxGenParam = _parser.createParam((unsigned int)(100), "maxGen", "Maximum number of generations (0 = none)",'G',"Stopping criterion"); - if (maxGenParam.value()) // positive: -> define and store + // the combined continue - to be filled + eoCombinedContinue *continuator = NULL; + // First the eoGenContinue - need a default value so you can run blind + // but we also need to be able to avoid it <--> 0 + eoValueParam& maxGenParam = _parser.createParam((unsigned int)(100), "maxGen", "Maximum number of generations (0 = none)",'G',"Stopping criterion"); + if (maxGenParam.value()) // positive: -> define and store { - eoGenContinue *genCont = new eoGenContinue(maxGenParam.value()); - _state.storeFunctor(genCont); - // and "add" to combined - continuator = make_combinedContinue(continuator, genCont); + eoGenContinue *genCont = new eoGenContinue(maxGenParam.value()); + _state.storeFunctor(genCont); + // and "add" to combined + continuator = make_combinedContinue(continuator, genCont); } - // maxEval - eoValueParam& maxEvalParam = _parser.getORcreateParam((unsigned long)(0), "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion"); - if (maxEvalParam.value()) + // maxEval + eoValueParam& maxEvalParam = _parser.getORcreateParam((unsigned long)(0), "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion"); + if (maxEvalParam.value()) { - eoEvalContinue *evalCont = new eoEvalContinue(_eval, maxEvalParam.value()); - _state.storeFunctor(evalCont); - // and "add" to combined - continuator = make_combinedContinue(continuator, evalCont); + eoEvalContinue *evalCont = new eoEvalContinue(_eval, maxEvalParam.value()); + _state.storeFunctor(evalCont); + // and "add" to combined + continuator = make_combinedContinue(continuator, evalCont); } - // maxTime - eoValueParam& maxTimeParam = _parser.getORcreateParam((unsigned long)(0), "maxTime", "Maximum running time in seconds (0 = none)", 'T', "Stopping criterion"); - if (maxTimeParam.value()) // positive: -> define and store + // maxTime + eoValueParam& maxTimeParam = _parser.getORcreateParam((unsigned long)(0), "maxTime", "Maximum running time in seconds (0 = none)", 'T', "Stopping criterion"); + if (maxTimeParam.value()) // positive: -> define and store { - eoTimeContinue *timeCont = new eoTimeContinue(maxTimeParam.value()); - _state.storeFunctor(timeCont); - // and "add" to combined - continuator = make_combinedContinue(continuator, timeCont); + eoTimeContinue *timeCont = new eoTimeContinue(maxTimeParam.value()); + _state.storeFunctor(timeCont); + // and "add" to combined + continuator = make_combinedContinue(continuator, timeCont); } - // CtrlC + // CtrlC #ifndef _MSC_VER - // the CtrlC interception (Linux only I'm afraid) - eoCtrlCContinue *ctrlCCont; - eoValueParam& ctrlCParam = _parser.createParam(true, "CtrlC", "Terminate current generation upon Ctrl C",'C', "Stopping criterion"); - if (_parser.isItThere(ctrlCParam)) + // the CtrlC interception (Linux only I'm afraid) + eoCtrlCContinue *ctrlCCont; + eoValueParam& ctrlCParam = _parser.createParam(true, "CtrlC", "Terminate current generation upon Ctrl C",'C', "Stopping criterion"); + if (_parser.isItThere(ctrlCParam)) { - ctrlCCont = new eoCtrlCContinue; - // store - _state.storeFunctor(ctrlCCont); - // add to combinedContinue - continuator = make_combinedContinue(continuator, ctrlCCont); + ctrlCCont = new eoCtrlCContinue; + // store + _state.storeFunctor(ctrlCCont); + // add to combinedContinue + continuator = make_combinedContinue(continuator, ctrlCCont); } #endif - // now check that there is at least one! - if (!continuator) - throw std::runtime_error("You MUST provide a stopping criterion"); - // OK, it's there: store in the eoState - _state.storeFunctor(continuator); - // and return - return *continuator; + // now check that there is at least one! + if (!continuator) + throw std::runtime_error("You MUST provide a stopping criterion"); + // OK, it's there: store in the eoState + _state.storeFunctor(continuator); + // and return + return *continuator; } #endif /*MAKE_CONTINUE_MOEO_H_*/ diff --git a/trunk/paradiseo-moeo/src/do/make_ea_moeo.h b/trunk/paradiseo-moeo/src/do/make_ea_moeo.h index 4eb83111e..2192e5d30 100755 --- a/trunk/paradiseo-moeo/src/do/make_ea_moeo.h +++ b/trunk/paradiseo-moeo/src/do/make_ea_moeo.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -88,209 +88,209 @@ template < class MOEOT > moeoEA < MOEOT > & do_make_ea_moeo(eoParser & _parser, eoState & _state, eoEvalFunc < MOEOT > & _eval, eoContinue < MOEOT > & _continue, eoGenOp < MOEOT > & _op, moeoArchive < MOEOT > & _archive) { - /* the objective vector type */ - typedef typename MOEOT::ObjectiveVector ObjectiveVector; + /* the objective vector type */ + typedef typename MOEOT::ObjectiveVector ObjectiveVector; - /* the fitness assignment strategy */ - std::string & fitnessParam = _parser.createParam(std::string("FastNonDominatedSorting"), "fitness", - "Fitness assignment scheme: Dummy, FastNonDominatedSorting or IndicatorBased", 'F', - "Evolution Engine").value(); - std::string & indicatorParam = _parser.createParam(std::string("Epsilon"), "indicator", - "Binary indicator for IndicatorBased: Epsilon, Hypervolume", 'i', - "Evolution Engine").value(); - double rho = _parser.createParam(1.1, "rho", "reference point for the hypervolume indicator", 'r', + /* the fitness assignment strategy */ + std::string & fitnessParam = _parser.createParam(std::string("FastNonDominatedSorting"), "fitness", + "Fitness assignment scheme: Dummy, FastNonDominatedSorting or IndicatorBased", 'F', + "Evolution Engine").value(); + std::string & indicatorParam = _parser.createParam(std::string("Epsilon"), "indicator", + "Binary indicator for IndicatorBased: Epsilon, Hypervolume", 'i', + "Evolution Engine").value(); + double rho = _parser.createParam(1.1, "rho", "reference point for the hypervolume indicator", 'r', + "Evolution Engine").value(); + double kappa = _parser.createParam(0.05, "kappa", "Scaling factor kappa for IndicatorBased", 'k', "Evolution Engine").value(); - double kappa = _parser.createParam(0.05, "kappa", "Scaling factor kappa for IndicatorBased", 'k', - "Evolution Engine").value(); - moeoFitnessAssignment < MOEOT > * fitnessAssignment; - if (fitnessParam == std::string("Dummy")) + moeoFitnessAssignment < MOEOT > * fitnessAssignment; + if (fitnessParam == std::string("Dummy")) { - fitnessAssignment = new moeoDummyFitnessAssignment < MOEOT> (); + fitnessAssignment = new moeoDummyFitnessAssignment < MOEOT> (); } - else if (fitnessParam == std::string("FastNonDominatedSorting")) + else if (fitnessParam == std::string("FastNonDominatedSorting")) { - fitnessAssignment = new moeoFastNonDominatedSortingFitnessAssignment < MOEOT> (); + fitnessAssignment = new moeoFastNonDominatedSortingFitnessAssignment < MOEOT> (); } - else if (fitnessParam == std::string("IndicatorBased")) + else if (fitnessParam == std::string("IndicatorBased")) { - // metric - moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > *metric; - if (indicatorParam == std::string("Epsilon")) + // metric + moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > *metric; + if (indicatorParam == std::string("Epsilon")) { - metric = new moeoAdditiveEpsilonBinaryMetric < ObjectiveVector >; + metric = new moeoAdditiveEpsilonBinaryMetric < ObjectiveVector >; } - else if (indicatorParam == std::string("Hypervolume")) + else if (indicatorParam == std::string("Hypervolume")) { - metric = new moeoHypervolumeBinaryMetric < ObjectiveVector > (rho); + metric = new moeoHypervolumeBinaryMetric < ObjectiveVector > (rho); } - else + else { - std::string stmp = std::string("Invalid binary quality indicator: ") + indicatorParam; - throw std::runtime_error(stmp.c_str()); + std::string stmp = std::string("Invalid binary quality indicator: ") + indicatorParam; + throw std::runtime_error(stmp.c_str()); } - fitnessAssignment = new moeoExpBinaryIndicatorBasedFitnessAssignment < MOEOT > (*metric, kappa); + fitnessAssignment = new moeoExpBinaryIndicatorBasedFitnessAssignment < MOEOT > (*metric, kappa); } - else + else { - std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam; - throw std::runtime_error(stmp.c_str()); + std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam; + throw std::runtime_error(stmp.c_str()); } - _state.storeFunctor(fitnessAssignment); + _state.storeFunctor(fitnessAssignment); - /* the diversity assignment strategy */ - eoValueParam & diversityParam = _parser.createParam(eoParamParamType("Dummy"), "diversity", - "Diversity assignment scheme: Dummy, Sharing(nicheSize) or Crowding", 'D', "Evolution Engine"); - eoParamParamType & diversityParamValue = diversityParam.value(); - moeoDiversityAssignment < MOEOT > * diversityAssignment; - if (diversityParamValue.first == std::string("Dummy")) + /* the diversity assignment strategy */ + eoValueParam & diversityParam = _parser.createParam(eoParamParamType("Dummy"), "diversity", + "Diversity assignment scheme: Dummy, Sharing(nicheSize) or Crowding", 'D', "Evolution Engine"); + eoParamParamType & diversityParamValue = diversityParam.value(); + moeoDiversityAssignment < MOEOT > * diversityAssignment; + if (diversityParamValue.first == std::string("Dummy")) { - diversityAssignment = new moeoDummyDiversityAssignment < MOEOT> (); + diversityAssignment = new moeoDummyDiversityAssignment < MOEOT> (); } - else if (diversityParamValue.first == std::string("Sharing")) + else if (diversityParamValue.first == std::string("Sharing")) { - double nicheSize; - if (!diversityParamValue.second.size()) // no parameter added + double nicheSize; + if (!diversityParamValue.second.size()) // no parameter added { - std::cerr << "WARNING, no niche size given for Sharing, using 0.5" << std::endl; - nicheSize = 0.5; - diversityParamValue.second.push_back(std::string("0.5")); + std::cerr << "WARNING, no niche size given for Sharing, using 0.5" << std::endl; + nicheSize = 0.5; + diversityParamValue.second.push_back(std::string("0.5")); } - else + else { - nicheSize = atoi(diversityParamValue.second[0].c_str()); + nicheSize = atoi(diversityParamValue.second[0].c_str()); } - diversityAssignment = new moeoFrontByFrontSharingDiversityAssignment < MOEOT> (nicheSize); + diversityAssignment = new moeoFrontByFrontSharingDiversityAssignment < MOEOT> (nicheSize); } - else if (diversityParamValue.first == std::string("Crowding")) + else if (diversityParamValue.first == std::string("Crowding")) { - diversityAssignment = new moeoFrontByFrontCrowdingDiversityAssignment < MOEOT> (); + diversityAssignment = new moeoFrontByFrontCrowdingDiversityAssignment < MOEOT> (); } - else + else { - std::string stmp = std::string("Invalid diversity assignment strategy: ") + diversityParamValue.first; - throw std::runtime_error(stmp.c_str()); + std::string stmp = std::string("Invalid diversity assignment strategy: ") + diversityParamValue.first; + throw std::runtime_error(stmp.c_str()); } - _state.storeFunctor(diversityAssignment); + _state.storeFunctor(diversityAssignment); - /* the comparator strategy */ - std::string & comparatorParam = _parser.createParam(std::string("FitnessThenDiversity"), "comparator", - "Comparator scheme: FitnessThenDiversity, DiversityThenFitness or Aggregative", 'C', "Evolution Engine").value(); - moeoComparator < MOEOT > * comparator; - if (comparatorParam == std::string("FitnessThenDiversity")) + /* the comparator strategy */ + std::string & comparatorParam = _parser.createParam(std::string("FitnessThenDiversity"), "comparator", + "Comparator scheme: FitnessThenDiversity, DiversityThenFitness or Aggregative", 'C', "Evolution Engine").value(); + moeoComparator < MOEOT > * comparator; + if (comparatorParam == std::string("FitnessThenDiversity")) { - comparator = new moeoFitnessThenDiversityComparator < MOEOT> (); + comparator = new moeoFitnessThenDiversityComparator < MOEOT> (); } - else if (comparatorParam == std::string("DiversityThenFitness")) + else if (comparatorParam == std::string("DiversityThenFitness")) { - comparator = new moeoDiversityThenFitnessComparator < MOEOT> (); + comparator = new moeoDiversityThenFitnessComparator < MOEOT> (); } - else if (comparatorParam == std::string("Aggregative")) + else if (comparatorParam == std::string("Aggregative")) { - comparator = new moeoAggregativeComparator < MOEOT> (); + comparator = new moeoAggregativeComparator < MOEOT> (); } - else + else { - std::string stmp = std::string("Invalid comparator strategy: ") + comparatorParam; - throw std::runtime_error(stmp.c_str()); + std::string stmp = std::string("Invalid comparator strategy: ") + comparatorParam; + throw std::runtime_error(stmp.c_str()); } - _state.storeFunctor(comparator); + _state.storeFunctor(comparator); - /* the selection strategy */ - eoValueParam < eoParamParamType > & selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection", - "Selection scheme: DetTour(T), StochTour(t) or Random", 'S', "Evolution Engine"); - eoParamParamType & ppSelect = selectionParam.value(); - moeoSelectOne < MOEOT > * select; - if (ppSelect.first == std::string("DetTour")) + /* the selection strategy */ + eoValueParam < eoParamParamType > & selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection", + "Selection scheme: DetTour(T), StochTour(t) or Random", 'S', "Evolution Engine"); + eoParamParamType & ppSelect = selectionParam.value(); + moeoSelectOne < MOEOT > * select; + if (ppSelect.first == std::string("DetTour")) { - unsigned int tSize; - if (!ppSelect.second.size()) // no parameter added + unsigned int tSize; + if (!ppSelect.second.size()) // no parameter added { - std::cerr << "WARNING, no parameter passed to DetTour, using 2" << std::endl; - tSize = 2; - // put back 2 in parameter for consistency (and status file) - ppSelect.second.push_back(std::string("2")); + std::cerr << "WARNING, no parameter passed to DetTour, using 2" << std::endl; + tSize = 2; + // put back 2 in parameter for consistency (and status file) + ppSelect.second.push_back(std::string("2")); } - else // parameter passed by user as DetTour(T) + else // parameter passed by user as DetTour(T) { - tSize = atoi(ppSelect.second[0].c_str()); + tSize = atoi(ppSelect.second[0].c_str()); } - select = new moeoDetTournamentSelect < MOEOT > (*comparator, tSize); + select = new moeoDetTournamentSelect < MOEOT > (*comparator, tSize); } - else if (ppSelect.first == std::string("StochTour")) + else if (ppSelect.first == std::string("StochTour")) { - double tRate; - if (!ppSelect.second.size()) // no parameter added + double tRate; + if (!ppSelect.second.size()) // no parameter added { - std::cerr << "WARNING, no parameter passed to StochTour, using 1" << std::endl; - tRate = 1; - // put back 1 in parameter for consistency (and status file) - ppSelect.second.push_back(std::string("1")); + std::cerr << "WARNING, no parameter passed to StochTour, using 1" << std::endl; + tRate = 1; + // put back 1 in parameter for consistency (and status file) + ppSelect.second.push_back(std::string("1")); } - else // parameter passed by user as StochTour(T) + else // parameter passed by user as StochTour(T) { - tRate = atof(ppSelect.second[0].c_str()); + tRate = atof(ppSelect.second[0].c_str()); } - select = new moeoStochTournamentSelect < MOEOT > (*comparator, tRate); + select = new moeoStochTournamentSelect < MOEOT > (*comparator, tRate); } - /* - else if (ppSelect.first == string("Roulette")) + /* + else if (ppSelect.first == string("Roulette")) + { + // TO DO ! + // ... + } + */ + else if (ppSelect.first == std::string("Random")) { - // TO DO ! - // ... + select = new moeoRandomSelect (); } - */ - else if (ppSelect.first == std::string("Random")) + else { - select = new moeoRandomSelect (); + std::string stmp = std::string("Invalid selection strategy: ") + ppSelect.first; + throw std::runtime_error(stmp.c_str()); } - else - { - std::string stmp = std::string("Invalid selection strategy: ") + ppSelect.first; - throw std::runtime_error(stmp.c_str()); - } - _state.storeFunctor(select); + _state.storeFunctor(select); - /* the replacement strategy */ - std::string & replacementParam = _parser.createParam(std::string("Elitist"), "replacement", - "Replacement scheme: Elitist, Environmental or Generational", 'R', "Evolution Engine").value(); - moeoReplacement < MOEOT > * replace; - if (replacementParam == std::string("Elitist")) + /* the replacement strategy */ + std::string & replacementParam = _parser.createParam(std::string("Elitist"), "replacement", + "Replacement scheme: Elitist, Environmental or Generational", 'R', "Evolution Engine").value(); + moeoReplacement < MOEOT > * replace; + if (replacementParam == std::string("Elitist")) { - replace = new moeoElitistReplacement < MOEOT> (*fitnessAssignment, *diversityAssignment, *comparator); + replace = new moeoElitistReplacement < MOEOT> (*fitnessAssignment, *diversityAssignment, *comparator); } - else if (replacementParam == std::string("Environmental")) + else if (replacementParam == std::string("Environmental")) { - replace = new moeoEnvironmentalReplacement < MOEOT> (*fitnessAssignment, *diversityAssignment, *comparator); + replace = new moeoEnvironmentalReplacement < MOEOT> (*fitnessAssignment, *diversityAssignment, *comparator); } - else if (replacementParam == std::string("Generational")) + else if (replacementParam == std::string("Generational")) { - replace = new moeoGenerationalReplacement < MOEOT> (); + replace = new moeoGenerationalReplacement < MOEOT> (); } - else + else { - std::string stmp = std::string("Invalid replacement strategy: ") + replacementParam; - throw std::runtime_error(stmp.c_str()); + std::string stmp = std::string("Invalid replacement strategy: ") + replacementParam; + throw std::runtime_error(stmp.c_str()); } - _state.storeFunctor(replace); + _state.storeFunctor(replace); - /* the number of offspring */ - eoValueParam < eoHowMany > & offspringRateParam = _parser.createParam(eoHowMany(1.0), "nbOffspring", - "Number of offspring (percentage or absolute)", 'O', "Evolution Engine"); + /* the number of offspring */ + eoValueParam < eoHowMany > & offspringRateParam = _parser.createParam(eoHowMany(1.0), "nbOffspring", + "Number of offspring (percentage or absolute)", 'O', "Evolution Engine"); - // the general breeder - eoGeneralBreeder < MOEOT > * breed = new eoGeneralBreeder < MOEOT > (*select, _op, offspringRateParam.value()); - _state.storeFunctor(breed); - // the eoEasyEA - moeoEA < MOEOT > * algo = new moeoEasyEA < MOEOT > (_continue, _eval, *breed, *replace, *fitnessAssignment, *diversityAssignment); - _state.storeFunctor(algo); - return *algo; + // the general breeder + eoGeneralBreeder < MOEOT > * breed = new eoGeneralBreeder < MOEOT > (*select, _op, offspringRateParam.value()); + _state.storeFunctor(breed); + // the eoEasyEA + moeoEA < MOEOT > * algo = new moeoEasyEA < MOEOT > (_continue, _eval, *breed, *replace, *fitnessAssignment, *diversityAssignment); + _state.storeFunctor(algo); + return *algo; } diff --git a/trunk/paradiseo-moeo/src/do/make_ls_moeo.h b/trunk/paradiseo-moeo/src/do/make_ls_moeo.h index db9061bf7..4ac3e58f3 100755 --- a/trunk/paradiseo-moeo/src/do/make_ls_moeo.h +++ b/trunk/paradiseo-moeo/src/do/make_ls_moeo.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -67,80 +67,81 @@ */ template < class MOEOT, class Move > moeoLS < MOEOT, eoPop & > & do_make_ls_moeo ( - eoParser & _parser, - eoState & _state, - eoEvalFunc < MOEOT > & _eval, - moeoMoveIncrEval < Move > & _moveIncrEval, - eoContinue < MOEOT > & _continue, - eoMonOp < MOEOT > & _op, - eoMonOp < MOEOT > & _opInit, - moMoveInit < Move > & _moveInit, - moNextMove < Move > & _nextMove, - moeoArchive < MOEOT > & _archive + eoParser & _parser, + eoState & _state, + eoEvalFunc < MOEOT > & _eval, + moeoMoveIncrEval < Move > & _moveIncrEval, + eoContinue < MOEOT > & _continue, + eoMonOp < MOEOT > & _op, + eoMonOp < MOEOT > & _opInit, + moMoveInit < Move > & _moveInit, + moNextMove < Move > & _nextMove, + moeoArchive < MOEOT > & _archive ) { - /* the objective vector type */ - typedef typename MOEOT::ObjectiveVector ObjectiveVector; - /* the fitness assignment strategy */ - std::string & fitnessParam = _parser.getORcreateParam(std::string("IndicatorBased"), "fitness", - "Fitness assignment strategy parameter: IndicatorBased...", 'F', - "Evolution Engine").value(); - std::string & indicatorParam = _parser.getORcreateParam(std::string("Epsilon"), "indicator", - "Binary indicator to use with the IndicatorBased assignment: Epsilon, Hypervolume", 'i', - "Evolution Engine").value(); - double rho = _parser.getORcreateParam(1.1, "rho", "reference point for the hypervolume indicator", - 'r', "Evolution Engine").value(); - double kappa = _parser.getORcreateParam(0.05, "kappa", "Scaling factor kappa for IndicatorBased", - 'k', "Evolution Engine").value(); - moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > * fitnessAssignment; - if (fitnessParam == std::string("IndicatorBased")) + /* the objective vector type */ + typedef typename MOEOT::ObjectiveVector ObjectiveVector; + /* the fitness assignment strategy */ + std::string & fitnessParam = _parser.getORcreateParam(std::string("IndicatorBased"), "fitness", + "Fitness assignment strategy parameter: IndicatorBased...", 'F', + "Evolution Engine").value(); + std::string & indicatorParam = _parser.getORcreateParam(std::string("Epsilon"), "indicator", + "Binary indicator to use with the IndicatorBased assignment: Epsilon, Hypervolume", 'i', + "Evolution Engine").value(); + double rho = _parser.getORcreateParam(1.1, "rho", "reference point for the hypervolume indicator", + 'r', "Evolution Engine").value(); + double kappa = _parser.getORcreateParam(0.05, "kappa", "Scaling factor kappa for IndicatorBased", + 'k', "Evolution Engine").value(); + moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > * fitnessAssignment; + if (fitnessParam == std::string("IndicatorBased")) { - // metric - moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > *metric; - if (indicatorParam == std::string("Epsilon")) + // metric + moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > *metric; + if (indicatorParam == std::string("Epsilon")) { - metric = new moeoAdditiveEpsilonBinaryMetric < ObjectiveVector >; + metric = new moeoAdditiveEpsilonBinaryMetric < ObjectiveVector >; } - else if (indicatorParam == std::string("Hypervolume")) + else if (indicatorParam == std::string("Hypervolume")) { - metric = new moeoHypervolumeBinaryMetric < ObjectiveVector > (rho); + metric = new moeoHypervolumeBinaryMetric < ObjectiveVector > (rho); } - else + else { - std::string stmp = std::string("Invalid binary quality indicator: ") + indicatorParam; - throw std::runtime_error(stmp.c_str()); + std::string stmp = std::string("Invalid binary quality indicator: ") + indicatorParam; + throw std::runtime_error(stmp.c_str()); } - fitnessAssignment = new moeoExpBinaryIndicatorBasedFitnessAssignment < MOEOT> (*metric, kappa); + fitnessAssignment = new moeoExpBinaryIndicatorBasedFitnessAssignment < MOEOT> (*metric, kappa); } - else + else { - std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam; - throw std::runtime_error(stmp.c_str()); + std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam; + throw std::runtime_error(stmp.c_str()); } - _state.storeFunctor(fitnessAssignment); - // number of iterations - unsigned int n = _parser.getORcreateParam(1, "n", "Number of iterations for population Initialization", 'n', "Evolution Engine").value(); - // LS - std::string & lsParam = _parser.getORcreateParam(std::string("I-IBMOLS"), "ls", - "Local Search: IBMOLS, I-IBMOLS (Iterated-IBMOLS)...", 'L', - "Evolution Engine").value(); - moeoLS < MOEOT, eoPop & > * ls; - if (lsParam == std::string("IBMOLS")) + _state.storeFunctor(fitnessAssignment); + // number of iterations + unsigned int n = _parser.getORcreateParam(1, "n", "Number of iterations for population Initialization", 'n', "Evolution Engine").value(); + // LS + std::string & lsParam = _parser.getORcreateParam(std::string("I-IBMOLS"), "ls", + "Local Search: IBMOLS, I-IBMOLS (Iterated-IBMOLS)...", 'L', + "Evolution Engine").value(); + moeoLS < MOEOT, eoPop & > * ls; + if (lsParam == std::string("IBMOLS")) { - ls = new moeoIBMOLS < MOEOT, Move > (_moveInit, _nextMove, _eval, _moveIncrEval, *fitnessAssignment, _continue);; + ls = new moeoIBMOLS < MOEOT, Move > (_moveInit, _nextMove, _eval, _moveIncrEval, *fitnessAssignment, _continue); + ; } - else if (lsParam == std::string("I-IBMOLS")) + else if (lsParam == std::string("I-IBMOLS")) { - ls = new moeoIteratedIBMOLS < MOEOT, Move > (_moveInit, _nextMove, _eval, _moveIncrEval, *fitnessAssignment, _continue, _op, _opInit, n); + ls = new moeoIteratedIBMOLS < MOEOT, Move > (_moveInit, _nextMove, _eval, _moveIncrEval, *fitnessAssignment, _continue, _op, _opInit, n); } - else + else { - std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam; - throw std::runtime_error(stmp.c_str()); + std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam; + throw std::runtime_error(stmp.c_str()); } - _state.storeFunctor(ls); - // that's it ! - return *ls; + _state.storeFunctor(ls); + // that's it ! + return *ls; } #endif /*MAKE_LS_MOEO_H_*/ diff --git a/trunk/paradiseo-moeo/src/fitness/moeoAchievementFitnessAssignment.h b/trunk/paradiseo-moeo/src/fitness/moeoAchievementFitnessAssignment.h index e0ffaee06..b77355bb1 100644 --- a/trunk/paradiseo-moeo/src/fitness/moeoAchievementFitnessAssignment.h +++ b/trunk/paradiseo-moeo/src/fitness/moeoAchievementFitnessAssignment.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -47,8 +47,8 @@ */ template < class MOEOT > class moeoAchievementFitnessAssignment : public moeoScalarFitnessAssignment < MOEOT > -{ -public: + { + public: /** the objective vector type of the solutions */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -62,11 +62,11 @@ public: */ moeoAchievementFitnessAssignment(ObjectiveVector & _reference, std::vector < double > & _lambdas, double _spn=0.0001) : reference(_reference), lambdas(_lambdas), spn(_spn) { - // consistency check - if ((spn < 0.0) || (spn > 1.0)) + // consistency check + if ((spn < 0.0) || (spn > 1.0)) { - std::cout << "Warning, the arbitrary small positive number should be > 0 and <<1, adjusted to 0.0001\n"; - spn = 0.0001; + std::cout << "Warning, the arbitrary small positive number should be > 0 and <<1, adjusted to 0.0001\n"; + spn = 0.0001; } } @@ -78,17 +78,17 @@ public: */ moeoAchievementFitnessAssignment(ObjectiveVector & _reference, double _spn=0.0001) : reference(_reference), spn(_spn) { - // compute the default values for lambdas - lambdas = std::vector < double > (ObjectiveVector::nObjectives()); - for (unsigned int i=0 ; i (ObjectiveVector::nObjectives()); + for (unsigned int i=0 ; i 1.0)) + // consistency check + if ((spn < 0.0) || (spn > 1.0)) { - std::cout << "Warning, the arbitrary small positive number should be > 0 and <<1, adjusted to 0.0001\n"; - spn = 0.0001; + std::cout << "Warning, the arbitrary small positive number should be > 0 and <<1, adjusted to 0.0001\n"; + spn = 0.0001; } } @@ -99,9 +99,9 @@ public: */ virtual void operator()(eoPop < MOEOT > & _pop) { - for (unsigned int i=0; i<_pop.size() ; i++) + for (unsigned int i=0; i<_pop.size() ; i++) { - compute(_pop[i]); + compute(_pop[i]); } } @@ -113,7 +113,7 @@ public: */ void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) { - // nothing to do ;-) + // nothing to do ;-) } @@ -123,11 +123,11 @@ public: */ void setReference(const ObjectiveVector & _reference) { - reference = _reference; + reference = _reference; } -private: + private: /** the reference point */ ObjectiveVector reference; @@ -141,9 +141,9 @@ private: * Returns a big value (regarded as infinite) */ double inf() const - { + { return std::numeric_limits::max(); - } + } /** @@ -152,19 +152,19 @@ private: */ void compute(MOEOT & _moeo) { - unsigned int nobj = MOEOT::ObjectiveVector::nObjectives(); - double temp; - double min = inf(); - double sum = 0; - for (unsigned int obj=0; obj * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,8 +45,8 @@ */ template < class MOEOT > class moeoBinaryIndicatorBasedFitnessAssignment : public moeoIndicatorBasedFitnessAssignment < MOEOT > -{ -public: + { + public: /** The type for objective vector */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -60,6 +60,6 @@ public: */ virtual double updateByAdding(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) = 0; -}; + }; #endif /*MOEOINDICATORBASEDFITNESSASSIGNMENT_H_*/ diff --git a/trunk/paradiseo-moeo/src/fitness/moeoCriterionBasedFitnessAssignment.h b/trunk/paradiseo-moeo/src/fitness/moeoCriterionBasedFitnessAssignment.h index e4f249420..398e005bc 100644 --- a/trunk/paradiseo-moeo/src/fitness/moeoCriterionBasedFitnessAssignment.h +++ b/trunk/paradiseo-moeo/src/fitness/moeoCriterionBasedFitnessAssignment.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -44,6 +44,7 @@ * moeoCriterionBasedFitnessAssignment is a moeoFitnessAssignment for criterion-based strategies. */ template < class MOEOT > -class moeoCriterionBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT > {}; +class moeoCriterionBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT > + {}; #endif /*MOEOCRITERIONBASEDFITNESSASSIGNMENT_H_*/ diff --git a/trunk/paradiseo-moeo/src/fitness/moeoDummyFitnessAssignment.h b/trunk/paradiseo-moeo/src/fitness/moeoDummyFitnessAssignment.h index 5255ffb82..be80edb57 100644 --- a/trunk/paradiseo-moeo/src/fitness/moeoDummyFitnessAssignment.h +++ b/trunk/paradiseo-moeo/src/fitness/moeoDummyFitnessAssignment.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,8 +45,8 @@ */ template < class MOEOT > class moeoDummyFitnessAssignment : public moeoFitnessAssignment < MOEOT > -{ -public: + { + public: /** The type for objective vector */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -58,12 +58,12 @@ public: */ void operator () (eoPop < MOEOT > & _pop) { - for (unsigned int idx = 0; idx<_pop.size (); idx++) + for (unsigned int idx = 0; idx<_pop.size (); idx++) { - if (_pop[idx].invalidFitness()) + if (_pop[idx].invalidFitness()) { - // set the diversity to 0 - _pop[idx].fitness(0.0); + // set the diversity to 0 + _pop[idx].fitness(0.0); } } } @@ -76,9 +76,9 @@ public: */ void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) { - // nothing to do... ;-) + // nothing to do... ;-) } -}; + }; #endif /*MOEODUMMYFITNESSASSIGNMENT_H_*/ diff --git a/trunk/paradiseo-moeo/src/fitness/moeoExpBinaryIndicatorBasedFitnessAssignment.h b/trunk/paradiseo-moeo/src/fitness/moeoExpBinaryIndicatorBasedFitnessAssignment.h index be9f56ba5..a25382f41 100644 --- a/trunk/paradiseo-moeo/src/fitness/moeoExpBinaryIndicatorBasedFitnessAssignment.h +++ b/trunk/paradiseo-moeo/src/fitness/moeoExpBinaryIndicatorBasedFitnessAssignment.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -52,8 +52,8 @@ */ template < class MOEOT > class moeoExpBinaryIndicatorBasedFitnessAssignment : public moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > -{ -public: + { + public: /** The type of objective vector */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -74,12 +74,12 @@ public: */ void operator()(eoPop < MOEOT > & _pop) { - // 1 - setting of the bounds - setup(_pop); - // 2 - computing every indicator values - computeValues(_pop); - // 3 - setting fitnesses - setFitnesses(_pop); + // 1 - setting of the bounds + setup(_pop); + // 2 - computing every indicator values + computeValues(_pop); + // 3 - setting fitnesses + setFitnesses(_pop); } @@ -90,15 +90,15 @@ public: */ void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) { - std::vector < double > v; - v.resize(_pop.size()); - for (unsigned int i=0; i<_pop.size(); i++) + std::vector < double > v; + v.resize(_pop.size()); + for (unsigned int i=0; i<_pop.size(); i++) { - v[i] = metric(_objVec, _pop[i].objectiveVector()); + v[i] = metric(_objVec, _pop[i].objectiveVector()); } - for (unsigned int i=0; i<_pop.size(); i++) + for (unsigned int i=0; i<_pop.size(); i++) { - _pop[i].fitness( _pop[i].fitness() + exp(-v[i]/kappa) ); + _pop[i].fitness( _pop[i].fitness() + exp(-v[i]/kappa) ); } } @@ -111,34 +111,34 @@ public: */ double updateByAdding(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) { - std::vector < double > v; - // update every fitness values to take the new individual into account - v.resize(_pop.size()); - for (unsigned int i=0; i<_pop.size(); i++) + std::vector < double > v; + // update every fitness values to take the new individual into account + v.resize(_pop.size()); + for (unsigned int i=0; i<_pop.size(); i++) { - v[i] = metric(_objVec, _pop[i].objectiveVector()); + v[i] = metric(_objVec, _pop[i].objectiveVector()); } - for (unsigned int i=0; i<_pop.size(); i++) + for (unsigned int i=0; i<_pop.size(); i++) { - _pop[i].fitness( _pop[i].fitness() - exp(-v[i]/kappa) ); + _pop[i].fitness( _pop[i].fitness() - exp(-v[i]/kappa) ); } - // compute the fitness of the new individual - v.clear(); - v.resize(_pop.size()); - for (unsigned int i=0; i<_pop.size(); i++) + // compute the fitness of the new individual + v.clear(); + v.resize(_pop.size()); + for (unsigned int i=0; i<_pop.size(); i++) { - v[i] = metric(_pop[i].objectiveVector(), _objVec); + v[i] = metric(_pop[i].objectiveVector(), _objVec); } - double result = 0; - for (unsigned int i=0; i & metric; @@ -154,18 +154,18 @@ protected: */ void setup(const eoPop < MOEOT > & _pop) { - double min, max; - for (unsigned int i=0; i & _pop) { - values.clear(); - values.resize(_pop.size()); - for (unsigned int i=0; i<_pop.size(); i++) + values.clear(); + values.resize(_pop.size()); + for (unsigned int i=0; i<_pop.size(); i++) { - values[i].resize(_pop.size()); - for (unsigned int j=0; j<_pop.size(); j++) + values[i].resize(_pop.size()); + for (unsigned int j=0; j<_pop.size(); j++) { - if (i != j) + if (i != j) { - values[i][j] = metric(_pop[i].objectiveVector(), _pop[j].objectiveVector()); + values[i][j] = metric(_pop[i].objectiveVector(), _pop[j].objectiveVector()); } } } @@ -198,9 +198,9 @@ protected: */ void setFitnesses(eoPop < MOEOT > & _pop) { - for (unsigned int i=0; i<_pop.size(); i++) + for (unsigned int i=0; i<_pop.size(); i++) { - _pop[i].fitness(computeFitness(i)); + _pop[i].fitness(computeFitness(i)); } } @@ -211,17 +211,17 @@ protected: */ double computeFitness(const unsigned int _idx) { - double result = 0; - for (unsigned int i=0; i * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -55,8 +55,8 @@ */ template < class MOEOT > class moeoFastNonDominatedSortingFitnessAssignment : public moeoParetoBasedFitnessAssignment < MOEOT > -{ -public: + { + public: /** the objective vector type of the solutions */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -83,37 +83,37 @@ public: */ void operator()(eoPop < MOEOT > & _pop) { - // number of objectives for the problem under consideration - unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives(); - if (nObjectives == 1) + // number of objectives for the problem under consideration + unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives(); + if (nObjectives == 1) { - // one objective - oneObjective(_pop); + // one objective + oneObjective(_pop); } - else if (nObjectives == 2) + else if (nObjectives == 2) { - // two objectives (the two objectives function is still to implement) - mObjectives(_pop); + // two objectives (the two objectives function is still to implement) + mObjectives(_pop); } - else if (nObjectives > 2) + else if (nObjectives > 2) { - // more than two objectives - mObjectives(_pop); + // more than two objectives + mObjectives(_pop); } - else + else { - // problem with the number of objectives - throw std::runtime_error("Problem with the number of objectives in moeoNonDominatedSortingFitnessAssignment"); + // problem with the number of objectives + throw std::runtime_error("Problem with the number of objectives in moeoNonDominatedSortingFitnessAssignment"); } - // a higher fitness is better, so the values need to be inverted - double max = _pop[0].fitness(); - for (unsigned int i=1 ; i<_pop.size() ; i++) + // a higher fitness is better, so the values need to be inverted + double max = _pop[0].fitness(); + for (unsigned int i=1 ; i<_pop.size() ; i++) { - max = std::max(max, _pop[i].fitness()); + max = std::max(max, _pop[i].fitness()); } - for (unsigned int i=0 ; i<_pop.size() ; i++) + for (unsigned int i=0 ; i<_pop.size() ; i++) { - _pop[i].fitness(max - _pop[i].fitness()); + _pop[i].fitness(max - _pop[i].fitness()); } } @@ -125,40 +125,41 @@ public: */ void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) { - for (unsigned int i=0; i<_pop.size(); i++) + for (unsigned int i=0; i<_pop.size(); i++) { - // if _pop[i] is dominated by _objVec - if ( comparator(_pop[i].objectiveVector(), _objVec) ) + // if _pop[i] is dominated by _objVec + if ( comparator(_pop[i].objectiveVector(), _objVec) ) { - _pop[i].fitness(_pop[i].fitness()+1); + _pop[i].fitness(_pop[i].fitness()+1); } } } -private: + private: /** Functor to compare two objective vectors */ moeoObjectiveVectorComparator < ObjectiveVector > & comparator; /** Functor to compare two objective vectors according to Pareto dominance relation */ moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator; /** Functor allowing to compare two solutions according to their first objective value, then their second, and so on. */ - class ObjectiveComparator : public moeoComparator < MOEOT > - { - public: - /** - * Returns true if _moeo1 < _moeo2 on the first objective, then on the second, and so on - * @param _moeo1 the first solution - * @param _moeo2 the second solution - */ - const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) - { - return cmp(_moeo1.objectiveVector(), _moeo2.objectiveVector()); - } - private: - /** the corresponding comparator for objective vectors */ - moeoObjectiveObjectiveVectorComparator < ObjectiveVector > cmp; - } objComparator; + class ObjectiveComparator : public moeoComparator < MOEOT > + { + public: + /** + * Returns true if _moeo1 < _moeo2 on the first objective, then on the second, and so on + * @param _moeo1 the first solution + * @param _moeo2 the second solution + */ + const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) + { + return cmp(_moeo1.objectiveVector(), _moeo2.objectiveVector()); + } + private: + /** the corresponding comparator for objective vectors */ + moeoObjectiveObjectiveVectorComparator < ObjectiveVector > cmp; + } + objComparator; /** @@ -167,18 +168,18 @@ private: */ void oneObjective (eoPop < MOEOT > & _pop) { - // sorts the population in the ascending order - std::sort(_pop.begin(), _pop.end(), objComparator); - // assign fitness values - unsigned int rank = 1; - _pop[_pop.size()-1].fitness(rank); - for (unsigned int i=_pop.size()-2; i>=0; i--) + // sorts the population in the ascending order + std::sort(_pop.begin(), _pop.end(), objComparator); + // assign fitness values + unsigned int rank = 1; + _pop[_pop.size()-1].fitness(rank); + for (unsigned int i=_pop.size()-2; i>=0; i--) { - if (_pop[i].objectiveVector() != _pop[i+1].objectiveVector()) + if (_pop[i].objectiveVector() != _pop[i+1].objectiveVector()) { - rank++; + rank++; } - _pop[i].fitness(rank); + _pop[i].fitness(rank); } } @@ -189,7 +190,7 @@ private: */ void twoObjectives (eoPop < MOEOT > & _pop) { - //... TO DO ! + //... TO DO ! } @@ -199,66 +200,66 @@ private: */ void mObjectives (eoPop < MOEOT > & _pop) { - // S[i] = indexes of the individuals dominated by _pop[i] - std::vector < std::vector > S(_pop.size()); - // n[i] = number of individuals that dominate the individual _pop[i] - std::vector < unsigned int > n(_pop.size(), 0); - // fronts: F[i] = indexes of the individuals contained in the ith front - std::vector < std::vector > F(_pop.size()+2); - // used to store the number of the first front - F[1].reserve(_pop.size()); - for (unsigned int p=0; p<_pop.size(); p++) + // S[i] = indexes of the individuals dominated by _pop[i] + std::vector < std::vector > S(_pop.size()); + // n[i] = number of individuals that dominate the individual _pop[i] + std::vector < unsigned int > n(_pop.size(), 0); + // fronts: F[i] = indexes of the individuals contained in the ith front + std::vector < std::vector > F(_pop.size()+2); + // used to store the number of the first front + F[1].reserve(_pop.size()); + for (unsigned int p=0; p<_pop.size(); p++) { - for (unsigned int q=0; q<_pop.size(); q++) + for (unsigned int q=0; q<_pop.size(); q++) { - // if q is dominated by p - if ( comparator(_pop[q].objectiveVector(), _pop[p].objectiveVector()) ) + // if q is dominated by p + if ( comparator(_pop[q].objectiveVector(), _pop[p].objectiveVector()) ) { - // add q to the set of solutions dominated by p - S[p].push_back(q); + // add q to the set of solutions dominated by p + S[p].push_back(q); } - // if p is dominated by q - else if ( comparator(_pop[p].objectiveVector(), _pop[q].objectiveVector()) ) + // if p is dominated by q + else if ( comparator(_pop[p].objectiveVector(), _pop[q].objectiveVector()) ) { - // increment the domination counter of p - n[p]++; + // increment the domination counter of p + n[p]++; } } - // if no individual dominates p - if (n[p] == 0) + // if no individual dominates p + if (n[p] == 0) { - // p belongs to the first front - _pop[p].fitness(1); - F[1].push_back(p); + // p belongs to the first front + _pop[p].fitness(1); + F[1].push_back(p); } } - // front counter - unsigned int counter=1; - unsigned int p,q; - while (! F[counter].empty()) + // front counter + unsigned int counter=1; + unsigned int p,q; + while (! F[counter].empty()) { - // used to store the number of the next front - F[counter+1].reserve(_pop.size()); - for (unsigned int i=0; i * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -46,8 +46,8 @@ */ template < class MOEOT > class moeoFitnessAssignment : public eoUF < eoPop < MOEOT > &, void > -{ -public: + { + public: /** The type for objective vector */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -68,9 +68,9 @@ public: */ void updateByDeleting(eoPop < MOEOT > & _pop, MOEOT & _moeo) { - updateByDeleting(_pop, _moeo.objectiveVector()); + updateByDeleting(_pop, _moeo.objectiveVector()); } -}; + }; #endif /*MOEOFITNESSASSIGNMENT_H_*/ diff --git a/trunk/paradiseo-moeo/src/fitness/moeoIndicatorBasedFitnessAssignment.h b/trunk/paradiseo-moeo/src/fitness/moeoIndicatorBasedFitnessAssignment.h index 75ecfd980..23a761436 100644 --- a/trunk/paradiseo-moeo/src/fitness/moeoIndicatorBasedFitnessAssignment.h +++ b/trunk/paradiseo-moeo/src/fitness/moeoIndicatorBasedFitnessAssignment.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -44,6 +44,7 @@ * moeoIndicatorBasedFitnessAssignment is a moeoFitnessAssignment for Indicator-based strategies. */ template < class MOEOT > -class moeoIndicatorBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT > {}; +class moeoIndicatorBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT > + {}; #endif /*MOEOINDICATORBASEDFITNESSASSIGNMENT_H_*/ diff --git a/trunk/paradiseo-moeo/src/fitness/moeoParetoBasedFitnessAssignment.h b/trunk/paradiseo-moeo/src/fitness/moeoParetoBasedFitnessAssignment.h index 517c148bb..ab794e279 100644 --- a/trunk/paradiseo-moeo/src/fitness/moeoParetoBasedFitnessAssignment.h +++ b/trunk/paradiseo-moeo/src/fitness/moeoParetoBasedFitnessAssignment.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -44,6 +44,7 @@ * moeoParetoBasedFitnessAssignment is a moeoFitnessAssignment for Pareto-based strategies. */ template < class MOEOT > -class moeoParetoBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT > {}; - +class moeoParetoBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT > + {}; + #endif /*MOEOPARETOBASEDFITNESSASSIGNMENT_H_*/ diff --git a/trunk/paradiseo-moeo/src/fitness/moeoReferencePointIndicatorBasedFitnessAssignment.h b/trunk/paradiseo-moeo/src/fitness/moeoReferencePointIndicatorBasedFitnessAssignment.h index 028a4ffdc..6fb4470d2 100755 --- a/trunk/paradiseo-moeo/src/fitness/moeoReferencePointIndicatorBasedFitnessAssignment.h +++ b/trunk/paradiseo-moeo/src/fitness/moeoReferencePointIndicatorBasedFitnessAssignment.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -48,8 +48,8 @@ */ template < class MOEOT > class moeoReferencePointIndicatorBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT > -{ -public: + { + public: /** The type of objective vector */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -60,7 +60,7 @@ public: * @param _metric the quality indicator */ moeoReferencePointIndicatorBasedFitnessAssignment (ObjectiveVector & _refPoint, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric) : - refPoint(_refPoint), metric(_metric) + refPoint(_refPoint), metric(_metric) {} @@ -70,10 +70,10 @@ public: */ void operator()(eoPop < MOEOT > & _pop) { - // 1 - setting of the bounds - setup(_pop); - // 2 - setting fitnesses - setFitnesses(_pop); + // 1 - setting of the bounds + setup(_pop); + // 2 - setting fitnesses + setFitnesses(_pop); } @@ -84,11 +84,11 @@ public: */ void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) { - // nothing to do ;-) + // nothing to do ;-) } -protected: + protected: /** the reference point */ ObjectiveVector & refPoint; @@ -102,18 +102,18 @@ protected: */ void setup(const eoPop < MOEOT > & _pop) { - double min, max; - for (unsigned int i=0; i & _pop) { - for (unsigned int i=0; i<_pop.size(); i++) + for (unsigned int i=0; i<_pop.size(); i++) { - _pop[i].fitness(- metric(_pop[i].objectiveVector(), refPoint) ); + _pop[i].fitness(- metric(_pop[i].objectiveVector(), refPoint) ); } } -}; + }; #endif /*MOEOREFERENCEPOINTINDICATORBASEDFITNESSASSIGNMENT_H_*/ diff --git a/trunk/paradiseo-moeo/src/fitness/moeoScalarFitnessAssignment.h b/trunk/paradiseo-moeo/src/fitness/moeoScalarFitnessAssignment.h index e05ef3538..1cbbd56d9 100644 --- a/trunk/paradiseo-moeo/src/fitness/moeoScalarFitnessAssignment.h +++ b/trunk/paradiseo-moeo/src/fitness/moeoScalarFitnessAssignment.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -44,6 +44,7 @@ * moeoScalarFitnessAssignment is a moeoFitnessAssignment for scalar strategies. */ template < class MOEOT > -class moeoScalarFitnessAssignment : public moeoFitnessAssignment < MOEOT > {}; - +class moeoScalarFitnessAssignment : public moeoFitnessAssignment < MOEOT > + {}; + #endif /*MOEOSCALARFITNESSASSIGNMENT_H_*/ diff --git a/trunk/paradiseo-moeo/src/fitness/moeoUnaryIndicatorBasedFitnessAssignment.h b/trunk/paradiseo-moeo/src/fitness/moeoUnaryIndicatorBasedFitnessAssignment.h index 232453005..119ea37a8 100644 --- a/trunk/paradiseo-moeo/src/fitness/moeoUnaryIndicatorBasedFitnessAssignment.h +++ b/trunk/paradiseo-moeo/src/fitness/moeoUnaryIndicatorBasedFitnessAssignment.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -44,6 +44,7 @@ * moeoIndicatorBasedFitnessAssignment for unary indicators. */ template < class MOEOT > -class moeoUnaryIndicatorBasedFitnessAssignment : public moeoIndicatorBasedFitnessAssignment < MOEOT > {}; +class moeoUnaryIndicatorBasedFitnessAssignment : public moeoIndicatorBasedFitnessAssignment < MOEOT > + {}; #endif /*MOEOINDICATORBASEDFITNESSASSIGNMENT_H_*/ diff --git a/trunk/paradiseo-moeo/src/metric/moeoAdditiveEpsilonBinaryMetric.h b/trunk/paradiseo-moeo/src/metric/moeoAdditiveEpsilonBinaryMetric.h index 459873b6f..8dacc9d7c 100644 --- a/trunk/paradiseo-moeo/src/metric/moeoAdditiveEpsilonBinaryMetric.h +++ b/trunk/paradiseo-moeo/src/metric/moeoAdditiveEpsilonBinaryMetric.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -47,8 +47,8 @@ */ template < class ObjectiveVector > class moeoAdditiveEpsilonBinaryMetric : public moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > -{ -public: + { + public: /** * Returns the minimal distance by which the objective vector _o1 must be translated in all objectives @@ -59,21 +59,21 @@ public: */ double operator()(const ObjectiveVector & _o1, const ObjectiveVector & _o2) { - // computation of the epsilon value for the first objective - double result = epsilon(_o1, _o2, 0); - // computation of the epsilon value for the other objectives - double tmp; - for (unsigned int i=1; i :: bounds; @@ -88,22 +88,22 @@ private: */ double epsilon(const ObjectiveVector & _o1, const ObjectiveVector & _o2, const unsigned int _obj) { - double result; - // if the objective _obj have to be minimized - if (ObjectiveVector::Traits::minimizing(_obj)) + double result; + // if the objective _obj have to be minimized + if (ObjectiveVector::Traits::minimizing(_obj)) { - // _o1[_obj] - _o2[_obj] - result = ( (_o1[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ) - ( (_o2[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ); + // _o1[_obj] - _o2[_obj] + result = ( (_o1[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ) - ( (_o2[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ); } - // if the objective _obj have to be maximized - else + // if the objective _obj have to be maximized + else { - // _o2[_obj] - _o1[_obj] - result = ( (_o2[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ) - ( (_o1[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ); + // _o2[_obj] - _o1[_obj] + result = ( (_o2[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ) - ( (_o1[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ); } - return result; + return result; } -}; + }; #endif /*MOEOADDITIVEEPSILONBINARYMETRIC_H_*/ diff --git a/trunk/paradiseo-moeo/src/metric/moeoContributionMetric.h b/trunk/paradiseo-moeo/src/metric/moeoContributionMetric.h index 7bf954a51..f8df458da 100644 --- a/trunk/paradiseo-moeo/src/metric/moeoContributionMetric.h +++ b/trunk/paradiseo-moeo/src/metric/moeoContributionMetric.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -47,44 +47,47 @@ */ template < class ObjectiveVector > class moeoContributionMetric : public moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > -{ -public: + { + public: /** * Returns the contribution of the Pareto set '_set1' relatively to the Pareto set '_set2' * @param _set1 the first Pareto set * @param _set2 the second Pareto set */ - double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) { - unsigned int c = card_C(_set1, _set2); - unsigned int w1 = card_W(_set1, _set2); - unsigned int n1 = card_N(_set1, _set2); - unsigned int w2 = card_W(_set2, _set1); - unsigned int n2 = card_N(_set2, _set1); - return (double) (c / 2.0 + w1 + n1) / (c + w1 + n1 + w2 + n2); + double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) + { + unsigned int c = card_C(_set1, _set2); + unsigned int w1 = card_W(_set1, _set2); + unsigned int n1 = card_N(_set1, _set2); + unsigned int w2 = card_W(_set2, _set1); + unsigned int n2 = card_N(_set2, _set1); + return (double) (c / 2.0 + w1 + n1) / (c + w1 + n1 + w2 + n2); } -private: + private: /** Functor to compare two objective vectors according to Pareto dominance relation */ moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator; - - + + /** * Returns the number of solutions both in '_set1' and '_set2' * @param _set1 the first Pareto set * @param _set2 the second Pareto set */ - unsigned int card_C (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) { - unsigned int c=0; - for (unsigned int i=0; i<_set1.size(); i++) - for (unsigned int j=0; j<_set2.size(); j++) - if (_set1[i] == _set2[j]) { - c++; - break; - } - return c; + unsigned int card_C (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) + { + unsigned int c=0; + for (unsigned int i=0; i<_set1.size(); i++) + for (unsigned int j=0; j<_set2.size(); j++) + if (_set1[i] == _set2[j]) + { + c++; + break; + } + return c; } @@ -93,16 +96,17 @@ private: * @param _set1 the first Pareto set * @param _set2 the second Pareto set */ - unsigned int card_W (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) { - unsigned int w=0; - for (unsigned int i=0; i<_set1.size(); i++) - for (unsigned int j=0; j<_set2.size(); j++) - if (paretoComparator(_set2[j], _set1[i])) - { - w++; - break; - } - return w; + unsigned int card_W (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) + { + unsigned int w=0; + for (unsigned int i=0; i<_set1.size(); i++) + for (unsigned int j=0; j<_set2.size(); j++) + if (paretoComparator(_set2[j], _set1[i])) + { + w++; + break; + } + return w; } @@ -111,22 +115,24 @@ private: * @param _set1 the first Pareto set * @param _set2 the second Pareto set */ - unsigned int card_N (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) { - unsigned int n=0; - for (unsigned int i=0; i<_set1.size(); i++) { - bool domin_rel = false; - for (unsigned int j=0; j<_set2.size(); j++) - if ( (paretoComparator(_set2[j], _set1[i])) || (paretoComparator(_set1[i], _set2[j])) ) - { - domin_rel = true; - break; - } - if (! domin_rel) - n++; + unsigned int card_N (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) + { + unsigned int n=0; + for (unsigned int i=0; i<_set1.size(); i++) + { + bool domin_rel = false; + for (unsigned int j=0; j<_set2.size(); j++) + if ( (paretoComparator(_set2[j], _set1[i])) || (paretoComparator(_set1[i], _set2[j])) ) + { + domin_rel = true; + break; + } + if (! domin_rel) + n++; } - return n; + return n; } -}; + }; #endif /*MOEOCONTRIBUTIONMETRIC_H_*/ diff --git a/trunk/paradiseo-moeo/src/metric/moeoEntropyMetric.h b/trunk/paradiseo-moeo/src/metric/moeoEntropyMetric.h index 19e7239b3..012e99d9e 100644 --- a/trunk/paradiseo-moeo/src/metric/moeoEntropyMetric.h +++ b/trunk/paradiseo-moeo/src/metric/moeoEntropyMetric.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -48,52 +48,55 @@ */ template < class ObjectiveVector > class moeoEntropyMetric : public moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > -{ -public: + { + public: /** * Returns the entropy of the Pareto set '_set1' relatively to the Pareto set '_set2' * @param _set1 the first Pareto set * @param _set2 the second Pareto set */ - double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) { - // normalization - std::vector< ObjectiveVector > set1 = _set1; - std::vector< ObjectiveVector > set2= _set2; - removeDominated (set1); - removeDominated (set2); - prenormalize (set1); - normalize (set1); - normalize (set2); + double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) + { + // normalization + std::vector< ObjectiveVector > set1 = _set1; + std::vector< ObjectiveVector > set2= _set2; + removeDominated (set1); + removeDominated (set2); + prenormalize (set1); + normalize (set1); + normalize (set2); - // making of PO* - std::vector< ObjectiveVector > star; // rotf :-) - computeUnion (set1, set2, star); - removeDominated (star); + // making of PO* + std::vector< ObjectiveVector > star; // rotf :-) + computeUnion (set1, set2, star); + removeDominated (star); - // making of PO1 U PO* - std::vector< ObjectiveVector > union_set1_star; // rotf again ... - computeUnion (set1, star, union_set1_star); + // making of PO1 U PO* + std::vector< ObjectiveVector > union_set1_star; // rotf again ... + computeUnion (set1, star, union_set1_star); - unsigned int C = union_set1_star.size(); - float omega=0; - float entropy=0; + unsigned int C = union_set1_star.size(); + float omega=0; + float entropy=0; - for (unsigned int i=0 ; i 0) { - omega += 1.0 / N_i; - entropy += (float) n_i / (N_i * C) * log (((float) n_i / C) / log (2.0)); + for (unsigned int i=0 ; i 0) + { + omega += 1.0 / N_i; + entropy += (float) n_i / (N_i * C) * log (((float) n_i / C) / log (2.0)); } } - entropy /= - log (omega); - entropy *= log (2.0); - return entropy; + entropy /= - log (omega); + entropy *= log (2.0); + return entropy; } -private: + private: /** vector of min values */ std::vector vect_min_val; @@ -107,19 +110,22 @@ private: * Removes the dominated individuals contained in _f * @param _f a Pareto set */ - void removeDominated(std::vector < ObjectiveVector > & _f) { - for (unsigned int i=0 ; i<_f.size(); i++) { - bool dom = false; - for (unsigned int j=0; j<_f.size(); j++) - if (i != j && paretoComparator(_f[i],_f[j])) - { - dom = true; - break; - } - if (dom) { - _f[i] = _f.back(); - _f.pop_back(); - i--; + void removeDominated(std::vector < ObjectiveVector > & _f) + { + for (unsigned int i=0 ; i<_f.size(); i++) + { + bool dom = false; + for (unsigned int j=0; j<_f.size(); j++) + if (i != j && paretoComparator(_f[i],_f[j])) + { + dom = true; + break; + } + if (dom) + { + _f[i] = _f.back(); + _f.pop_back(); + i--; } } } @@ -129,20 +135,23 @@ private: * Prenormalization * @param _f a Pareto set */ - void prenormalize (const std::vector< ObjectiveVector > & _f) { - vect_min_val.clear(); - vect_max_val.clear(); + void prenormalize (const std::vector< ObjectiveVector > & _f) + { + vect_min_val.clear(); + vect_max_val.clear(); - for (unsigned int i=0 ; imax_val) - max_val = _f[j][i]; + for (unsigned int i=0 ; imax_val) + max_val = _f[j][i]; } - vect_min_val.push_back(min_val); - vect_max_val.push_back (max_val); + vect_min_val.push_back(min_val); + vect_max_val.push_back (max_val); } } @@ -151,10 +160,11 @@ private: * Normalization * @param _f a Pareto set */ - void normalize (std::vector< ObjectiveVector > & _f) { - for (unsigned int i=0 ; i & _f) + { + for (unsigned int i=0 ; i & _f1, const std::vector< ObjectiveVector > & _f2, std::vector< ObjectiveVector > & _f) { - _f = _f1 ; - for (unsigned int i=0; i<_f2.size(); i++) { - bool b = false; - for (unsigned int j=0; j<_f1.size(); j ++) - if (_f1[j] == _f2[i]) { - b = true; - break; - } - if (! b) - _f.push_back(_f2[i]); + void computeUnion(const std::vector< ObjectiveVector > & _f1, const std::vector< ObjectiveVector > & _f2, std::vector< ObjectiveVector > & _f) + { + _f = _f1 ; + for (unsigned int i=0; i<_f2.size(); i++) + { + bool b = false; + for (unsigned int j=0; j<_f1.size(); j ++) + if (_f1[j] == _f2[i]) + { + b = true; + break; + } + if (! b) + _f.push_back(_f2[i]); } } @@ -182,26 +195,29 @@ private: /** * How many in niche */ - unsigned int howManyInNicheOf (const std::vector< ObjectiveVector > & _f, const ObjectiveVector & _s, unsigned int _size) { - unsigned int n=0; - for (unsigned int i=0 ; i<_f.size(); i++) { - if (euclidianDistance(_f[i], _s) < (_s.size() / (double) _size)) - n++; + unsigned int howManyInNicheOf (const std::vector< ObjectiveVector > & _f, const ObjectiveVector & _s, unsigned int _size) + { + unsigned int n=0; + for (unsigned int i=0 ; i<_f.size(); i++) + { + if (euclidianDistance(_f[i], _s) < (_s.size() / (double) _size)) + n++; } - return n; + return n; } /** * Euclidian distance */ - double euclidianDistance (const ObjectiveVector & _set1, const ObjectiveVector & _to, unsigned int _deg = 2) { - double dist=0; - for (unsigned int i=0; i<_set1.size(); i++) - dist += pow(fabs(_set1[i] - _to[i]), (int)_deg); - return pow(dist, 1.0 / _deg); + double euclidianDistance (const ObjectiveVector & _set1, const ObjectiveVector & _to, unsigned int _deg = 2) + { + double dist=0; + for (unsigned int i=0; i<_set1.size(); i++) + dist += pow(fabs(_set1[i] - _to[i]), (int)_deg); + return pow(dist, 1.0 / _deg); } -}; + }; #endif /*MOEOENTROPYMETRIC_H_*/ diff --git a/trunk/paradiseo-moeo/src/metric/moeoHypervolumeBinaryMetric.h b/trunk/paradiseo-moeo/src/metric/moeoHypervolumeBinaryMetric.h index b8e3c44c6..d2e61cbf0 100644 --- a/trunk/paradiseo-moeo/src/metric/moeoHypervolumeBinaryMetric.h +++ b/trunk/paradiseo-moeo/src/metric/moeoHypervolumeBinaryMetric.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -52,8 +52,8 @@ */ template < class ObjectiveVector > class moeoHypervolumeBinaryMetric : public moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > -{ -public: + { + public: /** * Ctor @@ -61,20 +61,20 @@ public: */ moeoHypervolumeBinaryMetric(double _rho = 1.1) : rho(_rho) { - // not-a-maximization problem check - for (unsigned int i=0; i * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -44,49 +44,56 @@ /** * Base class for performance metrics (also known as quality indicators). */ -class moeoMetric : public eoFunctorBase {}; +class moeoMetric : public eoFunctorBase + {}; /** * Base class for unary metrics. */ template < class A, class R > -class moeoUnaryMetric : public eoUF < A, R >, public moeoMetric {}; +class moeoUnaryMetric : public eoUF < A, R >, public moeoMetric + {}; /** * Base class for binary metrics. */ template < class A1, class A2, class R > -class moeoBinaryMetric : public eoBF < A1, A2, R >, public moeoMetric {}; +class moeoBinaryMetric : public eoBF < A1, A2, R >, public moeoMetric + {}; /** * Base class for unary metrics dedicated to the performance evaluation of a single solution's objective vector. */ template < class ObjectiveVector, class R > -class moeoSolutionUnaryMetric : public moeoUnaryMetric < const ObjectiveVector &, R > {}; +class moeoSolutionUnaryMetric : public moeoUnaryMetric < const ObjectiveVector &, R > + {}; /** * Base class for unary metrics dedicated to the performance evaluation of a Pareto set (a vector of objective vectors) */ template < class ObjectiveVector, class R > -class moeoVectorUnaryMetric : public moeoUnaryMetric < const std::vector < ObjectiveVector > &, R > {}; +class moeoVectorUnaryMetric : public moeoUnaryMetric < const std::vector < ObjectiveVector > &, R > + {}; /** * Base class for binary metrics dedicated to the performance comparison between two solutions's objective vectors. */ template < class ObjectiveVector, class R > -class moeoSolutionVsSolutionBinaryMetric : public moeoBinaryMetric < const ObjectiveVector &, const ObjectiveVector &, R > {}; +class moeoSolutionVsSolutionBinaryMetric : public moeoBinaryMetric < const ObjectiveVector &, const ObjectiveVector &, R > + {}; /** * Base class for binary metrics dedicated to the performance comparison between two Pareto sets (two vectors of objective vectors) */ template < class ObjectiveVector, class R > -class moeoVectorVsVectorBinaryMetric : public moeoBinaryMetric < const std::vector < ObjectiveVector > &, const std::vector < ObjectiveVector > &, R > {}; +class moeoVectorVsVectorBinaryMetric : public moeoBinaryMetric < const std::vector < ObjectiveVector > &, const std::vector < ObjectiveVector > &, R > + {}; #endif /*MOEOMETRIC_H_*/ diff --git a/trunk/paradiseo-moeo/src/metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h b/trunk/paradiseo-moeo/src/metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h index 3ecea4c88..95a4e54ab 100644 --- a/trunk/paradiseo-moeo/src/metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h +++ b/trunk/paradiseo-moeo/src/metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -49,19 +49,19 @@ */ template < class ObjectiveVector, class R > class moeoNormalizedSolutionVsSolutionBinaryMetric : public moeoSolutionVsSolutionBinaryMetric < ObjectiveVector, R > -{ -public: + { + public: /** * Default ctr for any moeoNormalizedSolutionVsSolutionBinaryMetric object */ moeoNormalizedSolutionVsSolutionBinaryMetric() { - bounds.resize(ObjectiveVector::Traits::nObjectives()); - // initialize bounds in case someone does not want to use them - for (unsigned int i=0; i bounds; -}; + }; #endif /*MOEONORMALIZEDSOLUTIONVSSOLUTIONBINARYMETRIC_H_*/ diff --git a/trunk/paradiseo-moeo/src/move/moeoMoveIncrEval.h b/trunk/paradiseo-moeo/src/move/moeoMoveIncrEval.h index b4666bab0..d6ef1e38d 100644 --- a/trunk/paradiseo-moeo/src/move/moeoMoveIncrEval.h +++ b/trunk/paradiseo-moeo/src/move/moeoMoveIncrEval.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -41,6 +41,7 @@ #include template < class Move > -class moeoMoveIncrEval : public eoBF < const Move &, const typename Move::EOType &, typename Move::EOType::ObjectiveVector > {}; +class moeoMoveIncrEval : public eoBF < const Move &, const typename Move::EOType &, typename Move::EOType::ObjectiveVector > + {}; #endif diff --git a/trunk/paradiseo-moeo/src/replacement/moeoElitistReplacement.h b/trunk/paradiseo-moeo/src/replacement/moeoElitistReplacement.h index 5de97e8ca..75f896b2e 100644 --- a/trunk/paradiseo-moeo/src/replacement/moeoElitistReplacement.h +++ b/trunk/paradiseo-moeo/src/replacement/moeoElitistReplacement.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -49,8 +49,8 @@ * Elitist replacement strategy that consists in keeping the N best individuals. */ template < class MOEOT > class moeoElitistReplacement:public moeoReplacement < MOEOT > -{ -public: + { + public: /** * Full constructor. @@ -59,7 +59,7 @@ public: * @param _comparator the comparator (used to compare 2 individuals) */ moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoDiversityAssignment < MOEOT > & _diversityAssignment, moeoComparator < MOEOT > & _comparator) : - fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (_comparator) + fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (_comparator) {} @@ -69,7 +69,7 @@ public: * @param _diversityAssignment the diversity assignment strategy */ moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoDiversityAssignment < MOEOT > & _diversityAssignment) : - fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (defaultComparator) + fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (defaultComparator) {} @@ -79,7 +79,7 @@ public: * @param _comparator the comparator (used to compare 2 individuals) */ moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoComparator < MOEOT > & _comparator) : - fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (_comparator) + fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (_comparator) {} @@ -89,7 +89,7 @@ public: * @param _fitnessAssignment the fitness assignment strategy */ moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment) : - fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (defaultComparator) + fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (defaultComparator) {} @@ -100,23 +100,23 @@ public: */ void operator () (eoPop < MOEOT > &_parents, eoPop < MOEOT > &_offspring) { - unsigned int sz = _parents.size (); - // merges offspring and parents into a global population - _parents.reserve (_parents.size () + _offspring.size ()); - std::copy (_offspring.begin (), _offspring.end (), back_inserter (_parents)); - // evaluates the fitness and the diversity of this global population - fitnessAssignment (_parents); - diversityAssignment (_parents); - // sorts the whole population according to the comparator - std::sort(_parents.begin(), _parents.end(), comparator); - // finally, resize this global population - _parents.resize (sz); - // and clear the offspring population - _offspring.clear (); + unsigned int sz = _parents.size (); + // merges offspring and parents into a global population + _parents.reserve (_parents.size () + _offspring.size ()); + std::copy (_offspring.begin (), _offspring.end (), back_inserter (_parents)); + // evaluates the fitness and the diversity of this global population + fitnessAssignment (_parents); + diversityAssignment (_parents); + // sorts the whole population according to the comparator + std::sort(_parents.begin(), _parents.end(), comparator); + // finally, resize this global population + _parents.resize (sz); + // and clear the offspring population + _offspring.clear (); } -protected: + protected: /** the fitness assignment strategy */ moeoFitnessAssignment < MOEOT > & fitnessAssignment; @@ -128,8 +128,8 @@ protected: moeoFitnessThenDiversityComparator < MOEOT > defaultComparator; /** this object is used to compare solutions in order to sort the population */ class Cmp - { - public: + { + public: /** * Ctor. * @param _comp the comparator @@ -143,13 +143,14 @@ protected: */ bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { - return comp(_moeo2,_moeo1); + return comp(_moeo2,_moeo1); } - private: + private: /** the comparator */ moeoComparator < MOEOT > & comp; - } comparator; + } + comparator; -}; + }; #endif /*MOEOELITISTREPLACEMENT_H_ */ diff --git a/trunk/paradiseo-moeo/src/replacement/moeoEnvironmentalReplacement.h b/trunk/paradiseo-moeo/src/replacement/moeoEnvironmentalReplacement.h index 050ee85ba..4bba8e962 100755 --- a/trunk/paradiseo-moeo/src/replacement/moeoEnvironmentalReplacement.h +++ b/trunk/paradiseo-moeo/src/replacement/moeoEnvironmentalReplacement.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -49,8 +49,8 @@ * and by updating the fitness and diversity values after each deletion. */ template < class MOEOT > class moeoEnvironmentalReplacement:public moeoReplacement < MOEOT > -{ -public: + { + public: /** The type for objective vector */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -63,7 +63,7 @@ public: * @param _comparator the comparator (used to compare 2 individuals) */ moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoDiversityAssignment < MOEOT > & _diversityAssignment, moeoComparator < MOEOT > & _comparator) : - fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (_comparator) + fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (_comparator) {} @@ -73,7 +73,7 @@ public: * @param _diversityAssignment the diversity assignment strategy */ moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoDiversityAssignment < MOEOT > & _diversityAssignment) : - fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (defaultComparator) + fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (defaultComparator) {} @@ -83,7 +83,7 @@ public: * @param _comparator the comparator (used to compare 2 individuals) */ moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoComparator < MOEOT > & _comparator) : - fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (_comparator) + fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (_comparator) {} @@ -93,7 +93,7 @@ public: * @param _fitnessAssignment the fitness assignment strategy */ moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment) : - fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (defaultComparator) + fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (defaultComparator) {} @@ -104,35 +104,35 @@ public: */ void operator () (eoPop < MOEOT > &_parents, eoPop < MOEOT > &_offspring) { - unsigned int sz = _parents.size(); - // merges offspring and parents into a global population - _parents.reserve (_parents.size() + _offspring.size()); - std::copy (_offspring.begin(), _offspring.end(), back_inserter(_parents)); - // evaluates the fitness and the diversity of this global population - fitnessAssignment (_parents); - diversityAssignment (_parents); - // remove individuals 1 by 1 and update the fitness values - unsigned int worstIdx; - ObjectiveVector worstObjVec; - while (_parents.size() > sz) + unsigned int sz = _parents.size(); + // merges offspring and parents into a global population + _parents.reserve (_parents.size() + _offspring.size()); + std::copy (_offspring.begin(), _offspring.end(), back_inserter(_parents)); + // evaluates the fitness and the diversity of this global population + fitnessAssignment (_parents); + diversityAssignment (_parents); + // remove individuals 1 by 1 and update the fitness values + unsigned int worstIdx; + ObjectiveVector worstObjVec; + while (_parents.size() > sz) { - // the individual to delete - worstIdx = std::min_element(_parents.begin(), _parents.end(), comparator) - _parents.begin(); - worstObjVec = _parents[worstIdx].objectiveVector(); - // remove the woorst individual - _parents[worstIdx] = _parents.back(); - _parents.pop_back(); - // update of the fitness and diversity values - fitnessAssignment.updateByDeleting(_parents, worstObjVec); - diversityAssignment.updateByDeleting(_parents, worstObjVec); + // the individual to delete + worstIdx = std::min_element(_parents.begin(), _parents.end(), comparator) - _parents.begin(); + worstObjVec = _parents[worstIdx].objectiveVector(); + // remove the woorst individual + _parents[worstIdx] = _parents.back(); + _parents.pop_back(); + // update of the fitness and diversity values + fitnessAssignment.updateByDeleting(_parents, worstObjVec); + diversityAssignment.updateByDeleting(_parents, worstObjVec); } - // clear the offspring population - _offspring.clear (); + // clear the offspring population + _offspring.clear (); } -protected: + protected: /** the fitness assignment strategy */ moeoFitnessAssignment < MOEOT > & fitnessAssignment; @@ -144,8 +144,8 @@ protected: moeoFitnessThenDiversityComparator < MOEOT > defaultComparator; /** this object is used to compare solutions in order to sort the population */ class Cmp - { - public: + { + public: /** * Ctor. * @param _comp the comparator @@ -159,13 +159,14 @@ protected: */ bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2) { - return comp(_moeo1,_moeo2); + return comp(_moeo1,_moeo2); } - private: + private: /** the comparator */ moeoComparator < MOEOT > & comp; - } comparator; + } + comparator; -}; + }; #endif /*MOEOENVIRONMENTALREPLACEMENT_H_ */ diff --git a/trunk/paradiseo-moeo/src/replacement/moeoGenerationalReplacement.h b/trunk/paradiseo-moeo/src/replacement/moeoGenerationalReplacement.h index 4a745bbcf..bf78a7745 100644 --- a/trunk/paradiseo-moeo/src/replacement/moeoGenerationalReplacement.h +++ b/trunk/paradiseo-moeo/src/replacement/moeoGenerationalReplacement.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -46,8 +46,8 @@ */ template < class MOEOT > class moeoGenerationalReplacement : public moeoReplacement < MOEOT >, public eoGenerationalReplacement < MOEOT > -{ -public: + { + public: /** * Swaps _parents and _offspring @@ -56,9 +56,9 @@ public: */ void operator()(eoPop < MOEOT > & _parents, eoPop < MOEOT > & _offspring) { - eoGenerationalReplacement < MOEOT >::operator ()(_parents, _offspring); + eoGenerationalReplacement < MOEOT >::operator ()(_parents, _offspring); } -}; + }; #endif /*MOEOGENERATIONALREPLACEMENT_H_*/ diff --git a/trunk/paradiseo-moeo/src/replacement/moeoReplacement.h b/trunk/paradiseo-moeo/src/replacement/moeoReplacement.h index a883035fb..286575cc7 100644 --- a/trunk/paradiseo-moeo/src/replacement/moeoReplacement.h +++ b/trunk/paradiseo-moeo/src/replacement/moeoReplacement.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -44,6 +44,7 @@ * Replacement strategy for multi-objective optimization. */ template < class MOEOT > -class moeoReplacement : public eoReplacement < MOEOT > {}; +class moeoReplacement : public eoReplacement < MOEOT > + {}; #endif /*MOEOREPLACEMENT_H_*/ diff --git a/trunk/paradiseo-moeo/src/selection/moeoDetTournamentSelect.h b/trunk/paradiseo-moeo/src/selection/moeoDetTournamentSelect.h index efbbed553..24e0a451c 100644 --- a/trunk/paradiseo-moeo/src/selection/moeoDetTournamentSelect.h +++ b/trunk/paradiseo-moeo/src/selection/moeoDetTournamentSelect.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -47,8 +47,8 @@ * Selection strategy that selects ONE individual by deterministic tournament. */ template < class MOEOT > class moeoDetTournamentSelect:public moeoSelectOne < MOEOT > -{ -public: + { + public: /** * Full Ctor. @@ -57,12 +57,12 @@ public: */ moeoDetTournamentSelect (moeoComparator < MOEOT > & _comparator, unsigned int _tSize = 2) : comparator (_comparator), tSize (_tSize) { - // consistency check - if (tSize < 2) + // consistency check + if (tSize < 2) { - std:: - cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n"; - tSize = 2; + std:: + cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n"; + tSize = 2; } } @@ -73,12 +73,12 @@ public: */ moeoDetTournamentSelect (unsigned int _tSize = 2) : comparator (defaultComparator), tSize (_tSize) { - // consistency check - if (tSize < 2) + // consistency check + if (tSize < 2) { - std:: - cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n"; - tSize = 2; + std:: + cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n"; + tSize = 2; } } @@ -89,12 +89,12 @@ public: */ const MOEOT & operator() (const eoPop < MOEOT > &_pop) { - // use the selector - return mo_deterministic_tournament (_pop, tSize, comparator); + // use the selector + return mo_deterministic_tournament (_pop, tSize, comparator); } -protected: + protected: /** the comparator (used to compare 2 individuals) */ moeoComparator < MOEOT > & comparator; @@ -103,6 +103,6 @@ protected: /** the number of individuals in the tournament */ unsigned int tSize; -}; + }; #endif /*MOEODETTOURNAMENTSELECT_H_ */ diff --git a/trunk/paradiseo-moeo/src/selection/moeoRandomSelect.h b/trunk/paradiseo-moeo/src/selection/moeoRandomSelect.h index 28d99ae9e..c27f07c91 100644 --- a/trunk/paradiseo-moeo/src/selection/moeoRandomSelect.h +++ b/trunk/paradiseo-moeo/src/selection/moeoRandomSelect.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -46,13 +46,14 @@ * Selection strategy that selects only one element randomly from a whole population. */ template < class MOEOT > class moeoRandomSelect:public moeoSelectOne < MOEOT >, public eoRandomSelect -{ -public: + { + public: /** * Ctor. */ - moeoRandomSelect(){} + moeoRandomSelect() + {} /** @@ -60,9 +61,9 @@ public: */ const MOEOT & operator () (const eoPop < MOEOT > &_pop) { - return eoRandomSelect < MOEOT >::operator ()(_pop); + return eoRandomSelect < MOEOT >::operator ()(_pop); } -}; + }; #endif /*MOEORANDOMSELECT_H_ */ diff --git a/trunk/paradiseo-moeo/src/selection/moeoRouletteSelect.h b/trunk/paradiseo-moeo/src/selection/moeoRouletteSelect.h index 4a084a9a7..5bf89b6e2 100644 --- a/trunk/paradiseo-moeo/src/selection/moeoRouletteSelect.h +++ b/trunk/paradiseo-moeo/src/selection/moeoRouletteSelect.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -47,8 +47,8 @@ */ template < class MOEOT > class moeoRouletteSelect:public moeoSelectOne < MOEOT > -{ -public: + { + public: /** * Ctor. @@ -56,12 +56,12 @@ public: */ moeoRouletteSelect (unsigned int _tSize = 2) : tSize (_tSize) { - // consistency check - if (tSize < 2) + // consistency check + if (tSize < 2) { - std:: - cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n"; - tSize = 2; + std:: + cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n"; + tSize = 2; } } @@ -72,16 +72,16 @@ public: */ const MOEOT & operator () (const eoPop < MOEOT > & _pop) { - // use the selector - return mo_roulette_wheel(_pop,tSize); + // use the selector + return mo_roulette_wheel(_pop,tSize); } -protected: + protected: /** size */ double & tSize; -}; + }; #endif /*MOEOROULETTESELECT_H_ */ diff --git a/trunk/paradiseo-moeo/src/selection/moeoSelectFromPopAndArch.h b/trunk/paradiseo-moeo/src/selection/moeoSelectFromPopAndArch.h index 65db821d4..6b3c98700 100644 --- a/trunk/paradiseo-moeo/src/selection/moeoSelectFromPopAndArch.h +++ b/trunk/paradiseo-moeo/src/selection/moeoSelectFromPopAndArch.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -49,8 +49,8 @@ */ template < class MOEOT > class moeoSelectFromPopAndArch : public moeoSelectOne < MOEOT > -{ -public: + { + public: /** * Ctor @@ -60,7 +60,7 @@ public: * @param _ratioFromPop the ratio of selected individuals from the population */ moeoSelectFromPopAndArch (moeoSelectOne < MOEOT > & _popSelectOne, moeoSelectOne < MOEOT > _archSelectOne, moeoArchive < MOEOT > & _arch, double _ratioFromPop=0.5) - : popSelectOne(_popSelectOne), archSelectOne(_archSelectOne), arch(_arch), ratioFromPop(_ratioFromPop) + : popSelectOne(_popSelectOne), archSelectOne(_archSelectOne), arch(_arch), ratioFromPop(_ratioFromPop) {} @@ -71,7 +71,7 @@ public: * @param _ratioFromPop the ratio of selected individuals from the population */ moeoSelectFromPopAndArch (moeoSelectOne < MOEOT > & _popSelectOne, moeoArchive < MOEOT > & _arch, double _ratioFromPop=0.5) - : popSelectOne(_popSelectOne), archSelectOne(randomSelectOne), arch(_arch), ratioFromPop(_ratioFromPop) + : popSelectOne(_popSelectOne), archSelectOne(randomSelectOne), arch(_arch), ratioFromPop(_ratioFromPop) {} @@ -80,13 +80,13 @@ public: */ virtual const MOEOT & operator () (const eoPop < MOEOT > & pop) { - if (arch.size() > 0) - if (rng.flip(ratioFromPop)) - return popSelectOne(pop); - else - return archSelectOne(arch); + if (arch.size() > 0) + if (rng.flip(ratioFromPop)) + return popSelectOne(pop); else - return popSelectOne(pop); + return archSelectOne(arch); + else + return popSelectOne(pop); } @@ -95,11 +95,11 @@ public: */ virtual void setup (const eoPop < MOEOT > & _pop) { - popSelectOne.setup(_pop); + popSelectOne.setup(_pop); } -private: + private: /** The population's selection operator */ moeoSelectOne < MOEOT > & popSelectOne; @@ -112,6 +112,6 @@ private: /** A random selection operator (used as default for archSelectOne) */ moeoRandomSelect < MOEOT > randomSelectOne; -}; + }; #endif /*MOEOSELECTONEFROMPOPANDARCH_H_*/ diff --git a/trunk/paradiseo-moeo/src/selection/moeoSelectOne.h b/trunk/paradiseo-moeo/src/selection/moeoSelectOne.h index 273c3baf6..c05e44740 100644 --- a/trunk/paradiseo-moeo/src/selection/moeoSelectOne.h +++ b/trunk/paradiseo-moeo/src/selection/moeoSelectOne.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -44,6 +44,7 @@ * Selection strategy for multi-objective optimization that selects only one element from a whole population. */ template < class MOEOT > -class moeoSelectOne : public eoSelectOne < MOEOT > {}; +class moeoSelectOne : public eoSelectOne < MOEOT > + {}; #endif /*MOEOSELECTONE_H_*/ diff --git a/trunk/paradiseo-moeo/src/selection/moeoSelectors.h b/trunk/paradiseo-moeo/src/selection/moeoSelectors.h index 31ca0898c..1b61eafad 100644 --- a/trunk/paradiseo-moeo/src/selection/moeoSelectors.h +++ b/trunk/paradiseo-moeo/src/selection/moeoSelectors.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -44,71 +44,71 @@ template It mo_deterministic_tournament(It _begin, It _end, unsigned int _t_size,moeoComparator& _comparator ,eoRng& _gen = rng) { - It best = _begin + _gen.random(_end - _begin); + It best = _begin + _gen.random(_end - _begin); - for (unsigned int i = 0; i < _t_size - 1; ++i) + for (unsigned int i = 0; i < _t_size - 1; ++i) { - It competitor = _begin + _gen.random(_end - _begin); - // compare the two individuals by using the comparator - if (_comparator(*best, *competitor)) - // best "better" than competitor - best=competitor; + It competitor = _begin + _gen.random(_end - _begin); + // compare the two individuals by using the comparator + if (_comparator(*best, *competitor)) + // best "better" than competitor + best=competitor; } - return best; + return best; } template const MOEOT& mo_deterministic_tournament(const eoPop& _pop, unsigned int _t_size,moeoComparator& _comparator, eoRng& _gen = rng) { - return *mo_deterministic_tournament(_pop.begin(), _pop.end(),_t_size,_comparator, _gen); + return *mo_deterministic_tournament(_pop.begin(), _pop.end(),_t_size,_comparator, _gen); } template MOEOT& mo_deterministic_tournament(eoPop& _pop, unsigned int _t_size,moeoComparator& _comparator,eoRng& _gen = rng) { - return *mo_deterministic_tournament(_pop.begin(), _pop.end(), _t_size,_comparator, _gen); + return *mo_deterministic_tournament(_pop.begin(), _pop.end(), _t_size,_comparator, _gen); } template It mo_stochastic_tournament(It _begin, It _end, double _t_rate,moeoComparator& _comparator ,eoRng& _gen = rng) { - It i1 = _begin + _gen.random(_end - _begin); - It i2 = _begin + _gen.random(_end - _begin); + It i1 = _begin + _gen.random(_end - _begin); + It i2 = _begin + _gen.random(_end - _begin); - bool return_better = _gen.flip(_t_rate); + bool return_better = _gen.flip(_t_rate); - if (_comparator(*i1, *i2)) + if (_comparator(*i1, *i2)) { - if (return_better) return i2; - // else + if (return_better) return i2; + // else - return i1; + return i1; } - else + else { - if (return_better) return i1; - // else + if (return_better) return i1; + // else } - // else + // else - return i2; + return i2; } template const MOEOT& mo_stochastic_tournament(const eoPop& _pop, double _t_rate,moeoComparator& _comparator, eoRng& _gen = rng) { - return *mo_stochastic_tournament(_pop.begin(), _pop.end(), _t_rate,_comparator, _gen); + return *mo_stochastic_tournament(_pop.begin(), _pop.end(), _t_rate,_comparator, _gen); } template MOEOT& mo_stochastic_tournament(eoPop& _pop, double _t_rate, eoRng& _gen = rng) { - return *mo_stochastic_tournament(_pop.begin(), _pop.end(), _t_rate, _gen); + return *mo_stochastic_tournament(_pop.begin(), _pop.end(), _t_rate, _gen); } @@ -116,58 +116,58 @@ template It mo_roulette_wheel(It _begin, It _end, double total, eoRng& _gen = rng) { - float roulette = _gen.uniform(total); + float roulette = _gen.uniform(total); - if (roulette == 0.0) // covers the case where total==0.0 - return _begin + _gen.random(_end - _begin); // uniform choice + if (roulette == 0.0) // covers the case where total==0.0 + return _begin + _gen.random(_end - _begin); // uniform choice - It i = _begin; + It i = _begin; - while (roulette > 0.0) + while (roulette > 0.0) { - roulette -= static_cast(*(i++)); + roulette -= static_cast(*(i++)); } - return --i; + return --i; } template const MOEOT& mo_roulette_wheel(const eoPop& _pop, double total, eoRng& _gen = rng) { - float roulette = _gen.uniform(total); + float roulette = _gen.uniform(total); - if (roulette == 0.0) // covers the case where total==0.0 - return _pop[_gen.random(_pop.size())]; // uniform choice + if (roulette == 0.0) // covers the case where total==0.0 + return _pop[_gen.random(_pop.size())]; // uniform choice - typename eoPop::const_iterator i = _pop.begin(); + typename eoPop::const_iterator i = _pop.begin(); - while (roulette > 0.0) + while (roulette > 0.0) { - roulette -= static_cast((i++)->fitness()); + roulette -= static_cast((i++)->fitness()); } - return *--i; + return *--i; } template MOEOT& mo_roulette_wheel(eoPop& _pop, double total, eoRng& _gen = rng) { - float roulette = _gen.uniform(total); + float roulette = _gen.uniform(total); - if (roulette == 0.0) // covers the case where total==0.0 - return _pop[_gen.random(_pop.size())]; // uniform choice + if (roulette == 0.0) // covers the case where total==0.0 + return _pop[_gen.random(_pop.size())]; // uniform choice - typename eoPop::iterator i = _pop.begin(); + typename eoPop::iterator i = _pop.begin(); - while (roulette > 0.0) + while (roulette > 0.0) { - // fitness only - roulette -= static_cast((i++)->fitness()); + // fitness only + roulette -= static_cast((i++)->fitness()); } - return *--i; + return *--i; } diff --git a/trunk/paradiseo-moeo/src/selection/moeoStochTournamentSelect.h b/trunk/paradiseo-moeo/src/selection/moeoStochTournamentSelect.h index 934cce190..c718db309 100644 --- a/trunk/paradiseo-moeo/src/selection/moeoStochTournamentSelect.h +++ b/trunk/paradiseo-moeo/src/selection/moeoStochTournamentSelect.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -47,8 +47,8 @@ * Selection strategy that selects ONE individual by stochastic tournament. */ template < class MOEOT > class moeoStochTournamentSelect:public moeoSelectOne -{ -public: + { + public: /** * Full Ctor @@ -57,19 +57,19 @@ public: */ moeoStochTournamentSelect (moeoComparator < MOEOT > & _comparator, double _tRate = 1.0) : comparator (_comparator), tRate (_tRate) { - // consistency checks - if (tRate < 0.5) + // consistency checks + if (tRate < 0.5) { - std::cerr << "Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n"; - tRate = 0.55; + std::cerr << "Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n"; + tRate = 0.55; } - if (tRate > 1) + if (tRate > 1) { - std::cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n"; - tRate = 1; + std::cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n"; + tRate = 1; } } - + /** * Ctor without comparator. A moeoFitnessThenDiversityComparator is used as default. @@ -77,16 +77,16 @@ public: */ moeoStochTournamentSelect (double _tRate = 1.0) : comparator (defaultComparator), tRate (_tRate) { - // consistency checks - if (tRate < 0.5) + // consistency checks + if (tRate < 0.5) { - std::cerr << "Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n"; - tRate = 0.55; + std::cerr << "Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n"; + tRate = 0.55; } - if (tRate > 1) + if (tRate > 1) { - std::cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n"; - tRate = 1; + std::cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n"; + tRate = 1; } } @@ -97,12 +97,12 @@ public: */ const MOEOT & operator() (const eoPop < MOEOT > &_pop) { - // use the selector - return mo_stochastic_tournament(_pop,tRate,comparator); + // use the selector + return mo_stochastic_tournament(_pop,tRate,comparator); } -protected: + protected: /** the comparator (used to compare 2 individuals) */ moeoComparator < MOEOT > & comparator; @@ -111,6 +111,6 @@ protected: /** the tournament rate */ double tRate; -}; + }; #endif /*MOEOSTOCHTOURNAMENTSELECT_H_ */ diff --git a/trunk/paradiseo-moeo/src/utils/moeoArchiveObjectiveVectorSavingUpdater.h b/trunk/paradiseo-moeo/src/utils/moeoArchiveObjectiveVectorSavingUpdater.h index bb4149512..819533fe1 100644 --- a/trunk/paradiseo-moeo/src/utils/moeoArchiveObjectiveVectorSavingUpdater.h +++ b/trunk/paradiseo-moeo/src/utils/moeoArchiveObjectiveVectorSavingUpdater.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -51,8 +51,8 @@ */ template < class MOEOT > class moeoArchiveObjectiveVectorSavingUpdater : public eoUpdater -{ -public: + { + public: /** * Ctor @@ -62,46 +62,47 @@ public: * @param _id own ID */ moeoArchiveObjectiveVectorSavingUpdater (moeoArchive & _arch, const std::string & _filename, bool _count = false, int _id = -1) : - arch(_arch), filename(_filename), count(_count), counter(0), id(_id) + arch(_arch), filename(_filename), count(_count), counter(0), id(_id) {} /** * Saves the fitness of the archive's members into the file */ - void operator()() { - char buff[MAX_BUFFER_SIZE]; - if (count) + void operator()() + { + char buff[MAX_BUFFER_SIZE]; + if (count) { - if (id == -1) + if (id == -1) { - sprintf (buff, "%s.%u", filename.c_str(), counter ++); + sprintf (buff, "%s.%u", filename.c_str(), counter ++); } - else + else { - sprintf (buff, "%s.%u.%u", filename.c_str(), id, counter ++); + sprintf (buff, "%s.%u.%u", filename.c_str(), id, counter ++); } } - else + else { - if (id == -1) + if (id == -1) { - sprintf (buff, "%s", filename.c_str()); + sprintf (buff, "%s", filename.c_str()); } - else + else { - sprintf (buff, "%s.%u", filename.c_str(), id); + sprintf (buff, "%s.%u", filename.c_str(), id); } - counter ++; + counter ++; } - std::ofstream f(buff); - for (unsigned int i = 0; i < arch.size (); i++) - f << arch[i].objectiveVector() << std::endl; - f.close (); + std::ofstream f(buff); + for (unsigned int i = 0; i < arch.size (); i++) + f << arch[i].objectiveVector() << std::endl; + f.close (); } -private: + private: /** local archive */ moeoArchive & arch; @@ -114,6 +115,6 @@ private: /** own ID */ int id; -}; + }; #endif /*MOEOARCHIVEOBJECTIVEVECTORSAVINGUPDATER_H_*/ diff --git a/trunk/paradiseo-moeo/src/utils/moeoArchiveUpdater.h b/trunk/paradiseo-moeo/src/utils/moeoArchiveUpdater.h index 896a6a3a9..aa1d377c7 100644 --- a/trunk/paradiseo-moeo/src/utils/moeoArchiveUpdater.h +++ b/trunk/paradiseo-moeo/src/utils/moeoArchiveUpdater.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -47,8 +47,8 @@ */ template < class MOEOT > class moeoArchiveUpdater : public eoUpdater -{ -public: + { + public: /** * Ctor @@ -62,18 +62,19 @@ public: /** * Updates the archive with newly found non-dominated solutions contained in the main population */ - void operator()() { - arch.update(pop); + void operator()() + { + arch.update(pop); } -private: + private: /** the archive of non-dominated solutions */ moeoArchive < MOEOT > & arch; /** the main population */ const eoPop < MOEOT > & pop; -}; + }; #endif /*MOEOARCHIVEUPDATER_H_*/ diff --git a/trunk/paradiseo-moeo/src/utils/moeoBinaryMetricSavingUpdater.h b/trunk/paradiseo-moeo/src/utils/moeoBinaryMetricSavingUpdater.h index 63317f04b..6f0ed6172 100644 --- a/trunk/paradiseo-moeo/src/utils/moeoBinaryMetricSavingUpdater.h +++ b/trunk/paradiseo-moeo/src/utils/moeoBinaryMetricSavingUpdater.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -51,8 +51,8 @@ */ template < class MOEOT > class moeoBinaryMetricSavingUpdater : public eoUpdater -{ -public: + { + public: /** The objective vector type of a solution */ typedef typename MOEOT::ObjectiveVector ObjectiveVector; @@ -65,37 +65,41 @@ public: * @param _filename the target filename */ moeoBinaryMetricSavingUpdater (moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > & _metric, const eoPop < MOEOT > & _pop, std::string _filename) : - metric(_metric), pop(_pop), filename(_filename), counter(1) + metric(_metric), pop(_pop), filename(_filename), counter(1) {} /** * Saves the metric's value for the current generation */ - void operator()() { - if (pop.size()) { - if (firstGen) { - firstGen = false; + void operator()() + { + if (pop.size()) + { + if (firstGen) + { + firstGen = false; } - else { - // creation of the two Pareto sets - std::vector < ObjectiveVector > from; - std::vector < ObjectiveVector > to; - for (unsigned int i=0; i from; + std::vector < ObjectiveVector > to; + for (unsigned int i=0; i & metric; @@ -110,6 +114,6 @@ private: /** counter */ unsigned int counter; -}; + }; #endif /*MOEOBINARYMETRICSAVINGUPDATER_H_*/ diff --git a/trunk/paradiseo-moeo/src/utils/moeoConvertPopToObjectiveVectors.h b/trunk/paradiseo-moeo/src/utils/moeoConvertPopToObjectiveVectors.h index cf57e642c..62c5af29f 100644 --- a/trunk/paradiseo-moeo/src/utils/moeoConvertPopToObjectiveVectors.h +++ b/trunk/paradiseo-moeo/src/utils/moeoConvertPopToObjectiveVectors.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -46,8 +46,8 @@ */ template < class MOEOT, class ObjectiveVector = typename MOEOT::ObjectiveVector > class moeoConvertPopToObjectiveVectors : public eoUF < const eoPop < MOEOT >, const std::vector < ObjectiveVector > > -{ -public: + { + public: /** * Returns a vector of the objective vectors from the population _pop @@ -55,15 +55,15 @@ public: */ const std::vector < ObjectiveVector > operator()(const eoPop < MOEOT > _pop) { - std::vector < ObjectiveVector > result; - result.resize(_pop.size()); - for (unsigned int i=0; i<_pop.size(); i++) + std::vector < ObjectiveVector > result; + result.resize(_pop.size()); + for (unsigned int i=0; i<_pop.size(); i++) { - result.push_back(_pop[i].objectiveVector()); + result.push_back(_pop[i].objectiveVector()); } - return result; + return result; } -}; + }; #endif /*MOEOPOPTOOBJECTIVEVECTORS_H_*/ diff --git a/trunk/paradiseo-moeo/test/t-moeo.cpp b/trunk/paradiseo-moeo/test/t-moeo.cpp index 72ac60c69..bc996f156 100644 --- a/trunk/paradiseo-moeo/test/t-moeo.cpp +++ b/trunk/paradiseo-moeo/test/t-moeo.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 diff --git a/trunk/paradiseo-moeo/tutorial/Lesson1/FlowShopEA.cpp b/trunk/paradiseo-moeo/tutorial/Lesson1/FlowShopEA.cpp index 37c5cf69e..87aa59ad5 100644 --- a/trunk/paradiseo-moeo/tutorial/Lesson1/FlowShopEA.cpp +++ b/trunk/paradiseo-moeo/tutorial/Lesson1/FlowShopEA.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -65,68 +65,68 @@ using namespace std; int main(int argc, char* argv[]) { - try + try { - - eoParser parser(argc, argv); // for user-parameter reading - eoState state; // to keep all things allocated + + eoParser parser(argc, argv); // for user-parameter reading + eoState state; // to keep all things allocated - /*** the representation-dependent things ***/ + /*** the representation-dependent things ***/ - // The fitness evaluation - eoEvalFuncCounter& eval = do_make_eval(parser, state); - // the genotype (through a genotype initializer) - eoInit& init = do_make_genotype(parser, state); - // the variation operators - eoGenOp& op = do_make_op(parser, state); + // The fitness evaluation + eoEvalFuncCounter& eval = do_make_eval(parser, state); + // the genotype (through a genotype initializer) + eoInit& init = do_make_genotype(parser, state); + // the variation operators + eoGenOp& op = do_make_op(parser, state); - /*** the representation-independent things ***/ + /*** the representation-independent things ***/ - // initialization of the population - eoPop& pop = do_make_pop(parser, state, init); - // definition of the archive - moeoArchive arch; - // stopping criteria - eoContinue& term = do_make_continue_moeo(parser, state, eval); - // output - eoCheckPoint& checkpoint = do_make_checkpoint_moeo(parser, state, eval, term, pop, arch); - // algorithm - eoAlgo& algo = do_make_ea_moeo(parser, state, eval, checkpoint, op, arch); + // initialization of the population + eoPop& pop = do_make_pop(parser, state, init); + // definition of the archive + moeoArchive arch; + // stopping criteria + eoContinue& term = do_make_continue_moeo(parser, state, eval); + // output + eoCheckPoint& checkpoint = do_make_checkpoint_moeo(parser, state, eval, term, pop, arch); + // algorithm + eoAlgo& algo = do_make_ea_moeo(parser, state, eval, checkpoint, op, arch); - /*** Go ! ***/ + /*** Go ! ***/ - // help ? - make_help(parser); + // help ? + make_help(parser); - // first evalution - apply(eval, pop); + // first evalution + apply(eval, pop); - // printing of the initial population - cout << "Initial Population\n"; - pop.sortedPrintOn(cout); - cout << endl; + // printing of the initial population + cout << "Initial Population\n"; + pop.sortedPrintOn(cout); + cout << endl; - // run the algo - do_run(algo, pop); + // run the algo + do_run(algo, pop); - // printing of the final population - cout << "Final Population\n"; - pop.sortedPrintOn(cout); - cout << endl; + // printing of the final population + cout << "Final Population\n"; + pop.sortedPrintOn(cout); + cout << endl; - // printing of the final archive - cout << "Final Archive\n"; - arch.sortedPrintOn(cout); - cout << endl; + // printing of the final archive + cout << "Final Archive\n"; + arch.sortedPrintOn(cout); + cout << endl; } - catch (exception& e) + catch (exception& e) { - cout << e.what() << endl; + cout << e.what() << endl; } - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-moeo/tutorial/Lesson2/Sch1.cpp b/trunk/paradiseo-moeo/tutorial/Lesson2/Sch1.cpp index 5e66bad4b..450d6350f 100644 --- a/trunk/paradiseo-moeo/tutorial/Lesson2/Sch1.cpp +++ b/trunk/paradiseo-moeo/tutorial/Lesson2/Sch1.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -44,21 +44,21 @@ using namespace std; // the moeoObjectiveVectorTraits : minimizing 2 objectives class Sch1ObjectiveVectorTraits : public moeoObjectiveVectorTraits -{ -public: + { + public: static bool minimizing (int i) { - return true; + return true; } static bool maximizing (int i) { - return false; + return false; } static unsigned int nObjectives () { - return 2; + return 2; } -}; + }; // objective vector of real values @@ -67,66 +67,67 @@ typedef moeoRealObjectiveVector < Sch1ObjectiveVectorTraits > Sch1ObjectiveVecto // multi-objective evolving object for the Sch1 problem class Sch1 : public moeoRealVector < Sch1ObjectiveVector, double, double > -{ -public: - Sch1() : moeoRealVector < Sch1ObjectiveVector, double, double > (1) {} -}; + { + public: + Sch1() : moeoRealVector < Sch1ObjectiveVector, double, double > (1) + {} + }; // evaluation of objective functions class Sch1Eval : public moeoEvalFunc < Sch1 > -{ -public: + { + public: void operator () (Sch1 & _sch1) { - if (_sch1.invalidObjectiveVector()) + if (_sch1.invalidObjectiveVector()) { - Sch1ObjectiveVector objVec; - double x = _sch1[0]; - objVec[0] = x * x; - objVec[1] = (x - 2.0) * (x - 2.0); - _sch1.objectiveVector(objVec); + Sch1ObjectiveVector objVec; + double x = _sch1[0]; + objVec[0] = x * x; + objVec[1] = (x - 2.0) * (x - 2.0); + _sch1.objectiveVector(objVec); } } -}; + }; // main int main (int argc, char *argv[]) { - // parameters - unsigned int POP_SIZE = 20; - unsigned int MAX_GEN = 100; - double M_EPSILON = 0.01; - double P_CROSS = 0.25; - double P_MUT = 0.35; + // parameters + unsigned int POP_SIZE = 20; + unsigned int MAX_GEN = 100; + double M_EPSILON = 0.01; + double P_CROSS = 0.25; + double P_MUT = 0.35; - // objective functions evaluation - Sch1Eval eval; + // objective functions evaluation + Sch1Eval eval; - // crossover and mutation - eoQuadCloneOp < Sch1 > xover; - eoUniformMutation < Sch1 > mutation (M_EPSILON); + // crossover and mutation + eoQuadCloneOp < Sch1 > xover; + eoUniformMutation < Sch1 > mutation (M_EPSILON); - // generate initial population - eoRealVectorBounds bounds (1, 0.0, 2.0); // [0, 2] - eoRealInitBounded < Sch1 > init (bounds); - eoPop < Sch1 > pop (POP_SIZE, init); + // generate initial population + eoRealVectorBounds bounds (1, 0.0, 2.0); // [0, 2] + eoRealInitBounded < Sch1 > init (bounds); + eoPop < Sch1 > pop (POP_SIZE, init); - // build NSGA-II - moeoNSGAII < Sch1 > nsgaII (MAX_GEN, eval, xover, P_CROSS, mutation, P_MUT); + // build NSGA-II + moeoNSGAII < Sch1 > nsgaII (MAX_GEN, eval, xover, P_CROSS, mutation, P_MUT); - // run the algo - nsgaII (pop); + // run the algo + nsgaII (pop); - // extract first front of the final population using an moeoArchive (this is the output of nsgaII) - moeoArchive < Sch1 > arch; - arch.update (pop); + // extract first front of the final population using an moeoArchive (this is the output of nsgaII) + moeoArchive < Sch1 > arch; + arch.update (pop); - // printing of the final archive - cout << "Final Archive" << endl; - arch.sortedPrintOn (cout); - cout << endl; + // printing of the final archive + cout << "Final Archive" << endl; + arch.sortedPrintOn (cout); + cout << endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShop.cpp b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShop.cpp index 0586ab4ee..0bf5dfe89 100644 --- a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShop.cpp +++ b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShop.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -38,6 +38,6 @@ #include std::string FlowShop::className() const -{ + { return "FlowShop"; -} + } diff --git a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShop.h b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShop.h index 59cecc066..993f901d8 100644 --- a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShop.h +++ b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShop.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,14 +45,14 @@ * Structure of the genotype for the flow-shop scheduling problem: a vector of unsigned int int. */ class FlowShop: public moeoVector < FlowShopObjectiveVector , double , double , unsigned int > -{ -public: + { + public: /** * class name */ std::string className() const; -}; + }; #endif /*FLOWSHOP_H_*/ diff --git a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopBenchmarkParser.cpp b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopBenchmarkParser.cpp index bd9238f96..5a8b412b5 100644 --- a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopBenchmarkParser.cpp +++ b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopBenchmarkParser.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -40,87 +40,92 @@ FlowShopBenchmarkParser::FlowShopBenchmarkParser(const std::string _benchmarkFileName) { - init(_benchmarkFileName); + init(_benchmarkFileName); } const unsigned int FlowShopBenchmarkParser::getM() { - return M; + return M; } const unsigned int FlowShopBenchmarkParser::getN() { - return N; + return N; } const std::vector< std::vector > FlowShopBenchmarkParser::getP() { - return p; + return p; } const std::vector FlowShopBenchmarkParser::getD() { - return d; + return d; } void FlowShopBenchmarkParser::printOn(std::ostream & _os) const -{ + { _os << "M=" << M << " N=" << N << std::endl; _os << "*** processing times" << std::endl; - for (unsigned int i=0; i > (M,N); - d = std::vector (N); - // for each job... - for (unsigned int j=0 ; j j) - getline(inputFile, buffer, '\n'); - // due-date of the job j - getline(inputFile, buffer, '\n'); - d[j] = atoi(buffer.data()); - // processing times of the job j on each machine - getline(inputFile, buffer, '\n'); - start = buffer.find_first_not_of(" "); - for (unsigned int i=0 ; i > (M,N); + d = std::vector (N); + // for each job... + for (unsigned int j=0 ; j j) + getline(inputFile, buffer, '\n'); + // due-date of the job j + getline(inputFile, buffer, '\n'); + d[j] = atoi(buffer.data()); + // processing times of the job j on each machine + getline(inputFile, buffer, '\n'); + start = buffer.find_first_not_of(" "); + for (unsigned int i=0 ; i * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -46,8 +46,8 @@ * Class to handle parameters of a flow-shop instance from a benchmark file */ class FlowShopBenchmarkParser -{ -public: + { + public: /** * Ctor @@ -86,7 +86,7 @@ public: void printOn(std::ostream & _os) const; -private: + private: /** number of machines */ unsigned int M; @@ -104,6 +104,6 @@ private: */ void init(const std::string _benchmarkFileName); -}; + }; #endif /*FLOWSHOPBENCHMARKPARSER_H_*/ diff --git a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopEval.cpp b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopEval.cpp index 532ffe939..08465a6f8 100644 --- a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopEval.cpp +++ b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopEval.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -39,51 +39,52 @@ FlowShopEval::FlowShopEval(unsigned int _M, unsigned int _N, const std::vector< std::vector > & _p, const std::vector & _d) : - M(_M), N (_N), p(_p), d(_d) + M(_M), N (_N), p(_p), d(_d) {} void FlowShopEval::operator()(FlowShop & _flowshop) { - FlowShopObjectiveVector objVector; - objVector[0] = makespan(_flowshop); - objVector[1] = tardiness(_flowshop); - _flowshop.objectiveVector(objVector); + FlowShopObjectiveVector objVector; + objVector[0] = makespan(_flowshop); + objVector[1] = tardiness(_flowshop); + _flowshop.objectiveVector(objVector); } double FlowShopEval::makespan(const FlowShop & _flowshop) { - // completion times computation for each job on each machine - // C[i][j] = completion of the jth job of the scheduling on the ith machine - std::vector< std::vector > C = completionTime(_flowshop); - return C[M-1][_flowshop[N-1]]; + // completion times computation for each job on each machine + // C[i][j] = completion of the jth job of the scheduling on the ith machine + std::vector< std::vector > C = completionTime(_flowshop); + return C[M-1][_flowshop[N-1]]; } double FlowShopEval::tardiness(const FlowShop & _flowshop) { - // completion times computation for each job on each machine - // C[i][j] = completion of the jth job of the scheduling on the ith machine - std::vector< std::vector > C = completionTime(_flowshop); - // tardiness computation - unsigned int long sum = 0; - for (unsigned int j=0 ; j > C = completionTime(_flowshop); + // tardiness computation + unsigned int long sum = 0; + for (unsigned int j=0 ; j > FlowShopEval::completionTime(const FlowShop & _flowshop) { - std::vector< std::vector > C(M,N); - C[0][_flowshop[0]] = p[0][_flowshop[0]]; +std::vector< std::vector > FlowShopEval::completionTime(const FlowShop & _flowshop) +{ + std::vector< std::vector > C(M,N); + C[0][_flowshop[0]] = p[0][_flowshop[0]]; + for (unsigned int j=1; j * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -46,8 +46,8 @@ * Evaluation of the objective vector a (multi-objective) FlowShop object */ class FlowShopEval : public moeoEvalFunc -{ -public: + { + public: /** * Ctor @@ -66,7 +66,7 @@ public: void operator()(FlowShop & _flowshop); -private: + private: /** number of machines */ unsigned int M; @@ -99,6 +99,6 @@ private: */ std::vector< std::vector > completionTime (const FlowShop & _flowshop); -}; + }; #endif /*FLOWSHOPEVAL_H_*/ diff --git a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopInit.cpp b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopInit.cpp index 22d41cd54..dde677384 100644 --- a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopInit.cpp +++ b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopInit.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -44,21 +44,21 @@ FlowShopInit::FlowShopInit(unsigned int _N) : N(_N) void FlowShopInit::operator()(FlowShop & _flowshop) { - // scheduling vector - std::vector scheduling(N); - // initialisation of possible values - std::vector possibles(N); - for (unsigned int i=0 ; i scheduling(N); + // initialisation of possible values + std::vector possibles(N); + for (unsigned int i=0 ; i * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,8 +45,8 @@ * Initialization of a random genotype built by the default constructor of the FlowShop class */ class FlowShopInit : public eoInit -{ -public: + { + public: /** * Ctor @@ -62,11 +62,11 @@ public: void operator()(FlowShop & _flowshop); -private: + private: /** the number of jobs (size of a scheduling vector) */ unsigned int N; -}; + }; #endif /*FLOWSHOPINIT_H_*/ diff --git a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopObjectiveVector.h b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopObjectiveVector.h index 0a9d255aa..65814085f 100644 --- a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopObjectiveVector.h +++ b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopObjectiveVector.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 diff --git a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopObjectiveVectorTraits.cpp b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopObjectiveVectorTraits.cpp index 1e3292fdf..08487e873 100644 --- a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopObjectiveVectorTraits.cpp +++ b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopObjectiveVectorTraits.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -40,18 +40,18 @@ bool FlowShopObjectiveVectorTraits::minimizing (int _i) { - // minimizing both - return true; + // minimizing both + return true; } bool FlowShopObjectiveVectorTraits::maximizing (int _i) { - // minimizing both - return false; + // minimizing both + return false; } unsigned int FlowShopObjectiveVectorTraits::nObjectives () { - // 2 objectives - return 2; + // 2 objectives + return 2; } diff --git a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopObjectiveVectorTraits.h b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopObjectiveVectorTraits.h index 86c0aae4d..b95d6f2ea 100644 --- a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopObjectiveVectorTraits.h +++ b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopObjectiveVectorTraits.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -44,8 +44,8 @@ * Definition of the objective vector traits for multi-objective flow-shop problems */ class FlowShopObjectiveVectorTraits : public moeoObjectiveVectorTraits -{ -public: + { + public: /** * Returns true if the _ith objective have to be minimzed @@ -66,6 +66,6 @@ public: */ static unsigned int nObjectives (); -}; + }; #endif /*FLOWSHOPOBJECTIVEVECTORTRAITS_H_*/ diff --git a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpCrossoverQuad.cpp b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpCrossoverQuad.cpp index 9c979d6e9..5b64c7e41 100644 --- a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpCrossoverQuad.cpp +++ b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpCrossoverQuad.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -39,71 +39,72 @@ std::string FlowShopOpCrossoverQuad::className() const -{ + { return "FlowShopOpCrossoverQuad"; -} + } bool FlowShopOpCrossoverQuad::operator()(FlowShop & _flowshop1, FlowShop & _flowshop2) { - bool oneAtLeastIsModified; - // computation of the 2 random points - unsigned int point1, point2; - do + bool oneAtLeastIsModified; + // computation of the 2 random points + unsigned int point1, point2; + do { - point1 = rng.random(std::min(_flowshop1.size(), _flowshop2.size())); - point2 = rng.random(std::min(_flowshop1.size(), _flowshop2.size())); - } while (fabs((double) point1-point2) <= 2); - // computation of the offspring - FlowShop offspring1 = generateOffspring(_flowshop1, _flowshop2, point1, point2); - FlowShop offspring2 = generateOffspring(_flowshop2, _flowshop1, point1, point2); - // does at least one genotype has been modified ? - if ((_flowshop1 != offspring1) || (_flowshop2 != offspring2)) - { - // update - _flowshop1.value(offspring1); - _flowshop2.value(offspring2); - // at least one genotype has been modified - oneAtLeastIsModified = true; + point1 = rng.random(std::min(_flowshop1.size(), _flowshop2.size())); + point2 = rng.random(std::min(_flowshop1.size(), _flowshop2.size())); } - else + while (fabs((double) point1-point2) <= 2); + // computation of the offspring + FlowShop offspring1 = generateOffspring(_flowshop1, _flowshop2, point1, point2); + FlowShop offspring2 = generateOffspring(_flowshop2, _flowshop1, point1, point2); + // does at least one genotype has been modified ? + if ((_flowshop1 != offspring1) || (_flowshop2 != offspring2)) { - // no genotype has been modified - oneAtLeastIsModified = false; + // update + _flowshop1.value(offspring1); + _flowshop2.value(offspring2); + // at least one genotype has been modified + oneAtLeastIsModified = true; } - // return 'true' if at least one genotype has been modified - return oneAtLeastIsModified; + else + { + // no genotype has been modified + oneAtLeastIsModified = false; + } + // return 'true' if at least one genotype has been modified + return oneAtLeastIsModified; } FlowShop FlowShopOpCrossoverQuad::generateOffspring(const FlowShop & _parent1, const FlowShop & _parent2, unsigned int _point1, unsigned int _point2) { - FlowShop result = _parent1; - std::vector taken_values(result.size(), false); - if (_point1 > _point2) - std::swap(_point1, _point2); - /* first parent */ - for (unsigned int i=0 ; i<=_point1 ; i++) + FlowShop result = _parent1; + std::vector taken_values(result.size(), false); + if (_point1 > _point2) + std::swap(_point1, _point2); + /* first parent */ + for (unsigned int i=0 ; i<=_point1 ; i++) { - // result[i] == _parent1[i] - taken_values[_parent1[i]] = true; + // result[i] == _parent1[i] + taken_values[_parent1[i]] = true; } - for (unsigned int i=_point2 ; i * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,8 +45,8 @@ * Quadratic crossover operator for flow-shop (modify the both genotypes) */ class FlowShopOpCrossoverQuad : public eoQuadOp < FlowShop > -{ -public: + { + public: /** * the class name (used to display statistics) @@ -62,7 +62,7 @@ public: bool operator()(FlowShop & _flowshop1, FlowShop & _flowshop2); -private: + private: /** * generation of an offspring by a 2 points crossover @@ -73,6 +73,6 @@ private: */ FlowShop generateOffspring(const FlowShop & _parent1, const FlowShop & _parent2, unsigned int _point1, unsigned int _point2); -}; + }; #endif /*FLOWSHOPOPCROSSOVERQUAD_H_*/ diff --git a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpMutationExchange.cpp b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpMutationExchange.cpp index 580057438..a37ae2587 100644 --- a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpMutationExchange.cpp +++ b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpMutationExchange.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -39,37 +39,38 @@ std::string FlowShopOpMutationExchange::className() const -{ + { return "FlowShopOpMutationExchange"; -} + } bool FlowShopOpMutationExchange::operator()(FlowShop & _flowshop) { - bool isModified; - FlowShop result = _flowshop; - // computation of the 2 random points - unsigned int point1, point2; - do + bool isModified; + FlowShop result = _flowshop; + // computation of the 2 random points + unsigned int point1, point2; + do { - point1 = rng.random(result.size()); - point2 = rng.random(result.size()); - } while (point1 == point2); - // swap - std::swap (result[point1], result[point2]); - // update (if necessary) - if (result != _flowshop) - { - // update - _flowshop.value(result); - // the genotype has been modified - isModified = true; + point1 = rng.random(result.size()); + point2 = rng.random(result.size()); } - else + while (point1 == point2); + // swap + std::swap (result[point1], result[point2]); + // update (if necessary) + if (result != _flowshop) { - // the genotype has not been modified - isModified = false; + // update + _flowshop.value(result); + // the genotype has been modified + isModified = true; } - // return 'true' if the genotype has been modified - return isModified; + else + { + // the genotype has not been modified + isModified = false; + } + // return 'true' if the genotype has been modified + return isModified; } diff --git a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpMutationExchange.h b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpMutationExchange.h index b9f3cc961..c54b8f063 100644 --- a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpMutationExchange.h +++ b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpMutationExchange.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,8 +45,8 @@ * Exchange mutation operator for the flow-shop */ class FlowShopOpMutationExchange : public eoMonOp -{ -public: + { + public: /** * the class name (used to display statistics) @@ -60,6 +60,6 @@ public: */ bool operator()(FlowShop & _flowshop); -}; + }; #endif /*FLOWSHOPOPMUTATIONEXCHANGE_H_*/ diff --git a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpMutationShift.cpp b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpMutationShift.cpp index 8921bc1e3..389842bdd 100644 --- a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpMutationShift.cpp +++ b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpMutationShift.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -39,47 +39,48 @@ std::string FlowShopOpMutationShift::className() const -{ + { return "FlowShopOpMutationShift"; -} + } bool FlowShopOpMutationShift::operator()(FlowShop & _flowshop) { - bool isModified; - int direction; - unsigned int tmp; - FlowShop result = _flowshop; - // computation of the 2 random points - unsigned int point1, point2; - do + bool isModified; + int direction; + unsigned int tmp; + FlowShop result = _flowshop; + // computation of the 2 random points + unsigned int point1, point2; + do { - point1 = rng.random(result.size()); - point2 = rng.random(result.size()); - } while (point1 == point2); - // direction - if (point1 < point2) - direction = 1; - else - direction = -1; - // mutation - tmp = result[point1]; - for (unsigned int i=point1 ; i!=point2 ; i+=direction) - result[i] = result[i+direction]; - result[point2] = tmp; - // update (if necessary) - if (result != _flowshop) - { - // update - _flowshop.value(result); - // the genotype has been modified - isModified = true; + point1 = rng.random(result.size()); + point2 = rng.random(result.size()); } - else + while (point1 == point2); + // direction + if (point1 < point2) + direction = 1; + else + direction = -1; + // mutation + tmp = result[point1]; + for (unsigned int i=point1 ; i!=point2 ; i+=direction) + result[i] = result[i+direction]; + result[point2] = tmp; + // update (if necessary) + if (result != _flowshop) { - // the genotype has not been modified - isModified = false; + // update + _flowshop.value(result); + // the genotype has been modified + isModified = true; } - // return 'true' if the genotype has been modified - return isModified; + else + { + // the genotype has not been modified + isModified = false; + } + // return 'true' if the genotype has been modified + return isModified; } diff --git a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpMutationShift.h b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpMutationShift.h index 144ba147a..8e9fb851d 100644 --- a/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpMutationShift.h +++ b/trunk/paradiseo-moeo/tutorial/examples/flowshop/FlowShopOpMutationShift.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,8 +45,8 @@ * Shift mutation operator for flow-shop */ class FlowShopOpMutationShift : public eoMonOp < FlowShop > -{ -public: + { + public: /** * the class name (used to display statistics) @@ -60,6 +60,6 @@ public: */ bool operator()(FlowShop & _flowshop); -}; + }; #endif /*FLOWSHOPOPMUTATIONSHIFT_H_*/ diff --git a/trunk/paradiseo-moeo/tutorial/examples/flowshop/make_eval_FlowShop.h b/trunk/paradiseo-moeo/tutorial/examples/flowshop/make_eval_FlowShop.h index 6448c9e58..680615af7 100644 --- a/trunk/paradiseo-moeo/tutorial/examples/flowshop/make_eval_FlowShop.h +++ b/trunk/paradiseo-moeo/tutorial/examples/flowshop/make_eval_FlowShop.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -53,28 +53,29 @@ */ eoEvalFuncCounter & do_make_eval(eoParser& _parser, eoState& _state) { - // benchmark file name - std::string benchmarkFileName = _parser.getORcreateParam(std::string(), "BenchmarkFile", "Benchmark file name (benchmarks are available at www.lifl.fr/~liefooga/benchmarks)", 'B',"Representation", true).value(); - if (benchmarkFileName == "") { - std::string stmp = "*** Missing name of the benchmark file\n"; - stmp += " Type '-B=the_benchmark_file_name' or '--BenchmarkFile=the_benchmark_file_name'\n"; - stmp += " Benchmarks files are available at www.lifl.fr/~liefooga/benchmarks"; - throw std::runtime_error(stmp.c_str()); + // benchmark file name + std::string benchmarkFileName = _parser.getORcreateParam(std::string(), "BenchmarkFile", "Benchmark file name (benchmarks are available at www.lifl.fr/~liefooga/benchmarks)", 'B',"Representation", true).value(); + if (benchmarkFileName == "") + { + std::string stmp = "*** Missing name of the benchmark file\n"; + stmp += " Type '-B=the_benchmark_file_name' or '--BenchmarkFile=the_benchmark_file_name'\n"; + stmp += " Benchmarks files are available at www.lifl.fr/~liefooga/benchmarks"; + throw std::runtime_error(stmp.c_str()); } - // reading of the parameters contained in the benchmark file - FlowShopBenchmarkParser fParser(benchmarkFileName); - unsigned int M = fParser.getM(); - unsigned int N = fParser.getN(); - std::vector< std::vector > p = fParser.getP(); - std::vector d = fParser.getD(); - // build of the initializer (a pointer, stored in the eoState) - FlowShopEval* plainEval = new FlowShopEval(M, N, p, d); - // turn that object into an evaluation counter - eoEvalFuncCounter* eval = new eoEvalFuncCounter (* plainEval); - // store in state - _state.storeFunctor(eval); - // and return a reference - return *eval; + // reading of the parameters contained in the benchmark file + FlowShopBenchmarkParser fParser(benchmarkFileName); + unsigned int M = fParser.getM(); + unsigned int N = fParser.getN(); + std::vector< std::vector > p = fParser.getP(); + std::vector d = fParser.getD(); + // build of the initializer (a pointer, stored in the eoState) + FlowShopEval* plainEval = new FlowShopEval(M, N, p, d); + // turn that object into an evaluation counter + eoEvalFuncCounter* eval = new eoEvalFuncCounter (* plainEval); + // store in state + _state.storeFunctor(eval); + // and return a reference + return *eval; } #endif /*MAKE_EVAL_FLOWSHOP_H_*/ diff --git a/trunk/paradiseo-moeo/tutorial/examples/flowshop/make_genotype_FlowShop.h b/trunk/paradiseo-moeo/tutorial/examples/flowshop/make_genotype_FlowShop.h index 26ad4ccf7..5487a0f17 100644 --- a/trunk/paradiseo-moeo/tutorial/examples/flowshop/make_genotype_FlowShop.h +++ b/trunk/paradiseo-moeo/tutorial/examples/flowshop/make_genotype_FlowShop.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -51,23 +51,24 @@ */ eoInit & do_make_genotype(eoParser& _parser, eoState& _state) { - // benchmark file name - std::string benchmarkFileName = _parser.getORcreateParam(std::string(), "BenchmarkFile", "Benchmark file name (benchmarks are available at www.lifl.fr/~liefooga/benchmarks/)", 'B',"Representation", true).value(); - if (benchmarkFileName == "") { - std::string stmp = "*** Missing name of the benchmark file\n"; - stmp += " Type '-B=the_benchmark_file_name' or '--BenchmarkFile=the_benchmark_file_name'\n"; - stmp += " Benchmarks files are available at www.lifl.fr/~liefooga/benchmarks"; - throw std::runtime_error(stmp.c_str()); + // benchmark file name + std::string benchmarkFileName = _parser.getORcreateParam(std::string(), "BenchmarkFile", "Benchmark file name (benchmarks are available at www.lifl.fr/~liefooga/benchmarks/)", 'B',"Representation", true).value(); + if (benchmarkFileName == "") + { + std::string stmp = "*** Missing name of the benchmark file\n"; + stmp += " Type '-B=the_benchmark_file_name' or '--BenchmarkFile=the_benchmark_file_name'\n"; + stmp += " Benchmarks files are available at www.lifl.fr/~liefooga/benchmarks"; + throw std::runtime_error(stmp.c_str()); } - // reading of number of jobs to schedule contained in the benchmark file - FlowShopBenchmarkParser fParser(benchmarkFileName); - unsigned int N = fParser.getN(); - // build of the initializer (a pointer, stored in the eoState) - eoInit* init = new FlowShopInit(N); - // store in state - _state.storeFunctor(init); - // and return a reference - return *init; + // reading of number of jobs to schedule contained in the benchmark file + FlowShopBenchmarkParser fParser(benchmarkFileName); + unsigned int N = fParser.getN(); + // build of the initializer (a pointer, stored in the eoState) + eoInit* init = new FlowShopInit(N); + // store in state + _state.storeFunctor(init); + // and return a reference + return *init; } #endif /*MAKE_GENOTYPE_FLOWSHOP_H_*/ diff --git a/trunk/paradiseo-moeo/tutorial/examples/flowshop/make_op_FlowShop.h b/trunk/paradiseo-moeo/tutorial/examples/flowshop/make_op_FlowShop.h index cf6f7d4a3..4316f7f65 100644 --- a/trunk/paradiseo-moeo/tutorial/examples/flowshop/make_op_FlowShop.h +++ b/trunk/paradiseo-moeo/tutorial/examples/flowshop/make_op_FlowShop.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -57,76 +57,76 @@ eoGenOp & do_make_op(eoParameterLoader& _parser, eoState& _state) { - ///////////////////////////// - // Variation operators - //////////////////////////// + ///////////////////////////// + // Variation operators + //////////////////////////// - // the crossover - //////////////// + // the crossover + //////////////// - // a first crossover - eoQuadOp *cross = new FlowShopOpCrossoverQuad; - // store in the state - _state.storeFunctor(cross); + // a first crossover + eoQuadOp *cross = new FlowShopOpCrossoverQuad; + // store in the state + _state.storeFunctor(cross); - // relative rate in the combination - double cross1Rate = _parser.createParam(1.0, "crossRate", "Relative rate for the only crossover", 0, "Variation Operators").value(); - // creation of the combined operator with this one - eoPropCombinedQuadOp *propXover = new eoPropCombinedQuadOp(*cross, cross1Rate); - // store in the state - _state.storeFunctor(propXover); + // relative rate in the combination + double cross1Rate = _parser.createParam(1.0, "crossRate", "Relative rate for the only crossover", 0, "Variation Operators").value(); + // creation of the combined operator with this one + eoPropCombinedQuadOp *propXover = new eoPropCombinedQuadOp(*cross, cross1Rate); + // store in the state + _state.storeFunctor(propXover); - // the mutation - /////////////// + // the mutation + /////////////// - // a first mutation : the shift mutation - eoMonOp *mut = new FlowShopOpMutationShift; - _state.storeFunctor(mut); - // its relative rate in the combination - double mut1Rate = _parser.createParam(0.5, "shiftMutRate", "Relative rate for shift mutation", 0, "Variation Operators").value(); - // creation of the combined operator with this one - eoPropCombinedMonOp *propMutation = new eoPropCombinedMonOp(*mut, mut1Rate); - _state.storeFunctor(propMutation); + // a first mutation : the shift mutation + eoMonOp *mut = new FlowShopOpMutationShift; + _state.storeFunctor(mut); + // its relative rate in the combination + double mut1Rate = _parser.createParam(0.5, "shiftMutRate", "Relative rate for shift mutation", 0, "Variation Operators").value(); + // creation of the combined operator with this one + eoPropCombinedMonOp *propMutation = new eoPropCombinedMonOp(*mut, mut1Rate); + _state.storeFunctor(propMutation); - // a second mutation : the exchange mutation - mut = new FlowShopOpMutationExchange; - _state.storeFunctor(mut); - // its relative rate in the combination - double mut2Rate = _parser.createParam(0.5, "exchangeMutRate", "Relative rate for exchange mutation", 0, "Variation Operators").value(); - // addition of this one to the combined operator - propMutation -> add(*mut, mut2Rate); + // a second mutation : the exchange mutation + mut = new FlowShopOpMutationExchange; + _state.storeFunctor(mut); + // its relative rate in the combination + double mut2Rate = _parser.createParam(0.5, "exchangeMutRate", "Relative rate for exchange mutation", 0, "Variation Operators").value(); + // addition of this one to the combined operator + propMutation -> add(*mut, mut2Rate); - // end of crossover and mutation definitions - //////////////////////////////////////////// + // end of crossover and mutation definitions + //////////////////////////////////////////// - // First read the individual level parameters - eoValueParam& pCrossParam = _parser.createParam(0.25, "pCross", "Probability of Crossover", 'c', "Variation Operators" ); - // minimum check - if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) ) - throw std::runtime_error("Invalid pCross"); + // First read the individual level parameters + eoValueParam& pCrossParam = _parser.createParam(0.25, "pCross", "Probability of Crossover", 'c', "Variation Operators" ); + // minimum check + if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) ) + throw std::runtime_error("Invalid pCross"); - eoValueParam& pMutParam = _parser.createParam(0.35, "pMut", "Probability of Mutation", 'm', "Variation Operators" ); - // minimum check - if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) ) - throw std::runtime_error("Invalid pMut"); + eoValueParam& pMutParam = _parser.createParam(0.35, "pMut", "Probability of Mutation", 'm', "Variation Operators" ); + // minimum check + if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) ) + throw std::runtime_error("Invalid pMut"); - // the crossover - with probability pCross - eoProportionalOp * propOp = new eoProportionalOp ; - _state.storeFunctor(propOp); - eoQuadOp *ptQuad = new eoQuadCloneOp; - _state.storeFunctor(ptQuad); - propOp -> add(*propXover, pCrossParam.value()); // crossover, with proba pcross - propOp -> add(*ptQuad, 1-pCrossParam.value()); // nothing, with proba 1-pcross + // the crossover - with probability pCross + eoProportionalOp * propOp = new eoProportionalOp ; + _state.storeFunctor(propOp); + eoQuadOp *ptQuad = new eoQuadCloneOp; + _state.storeFunctor(ptQuad); + propOp -> add(*propXover, pCrossParam.value()); // crossover, with proba pcross + propOp -> add(*ptQuad, 1-pCrossParam.value()); // nothing, with proba 1-pcross - // now the sequential - eoSequentialOp *op = new eoSequentialOp; - _state.storeFunctor(op); - op -> add(*propOp, 1.0); // always do combined crossover - op -> add(*propMutation, pMutParam.value()); // then mutation, with proba pmut + // now the sequential + eoSequentialOp *op = new eoSequentialOp; + _state.storeFunctor(op); + op -> add(*propOp, 1.0); // always do combined crossover + op -> add(*propMutation, pMutParam.value()); // then mutation, with proba pmut - // return a reference - return *op; + // return a reference + return *op; } #endif /*MAKE_OP_FLOWSHOP_H_*/