diff --git a/trunk/paradiseo-moeo/src/algo/moeoIBMOLS.h b/trunk/paradiseo-moeo/src/algo/moeoIBMOLS.h index e34a459fc..1213592c9 100755 --- a/trunk/paradiseo-moeo/src/algo/moeoIBMOLS.h +++ b/trunk/paradiseo-moeo/src/algo/moeoIBMOLS.h @@ -13,6 +13,7 @@ #ifndef MOEOIBMOLS_H_ #define MOEOIBMOLS_H_ +#include #include #include #include @@ -21,7 +22,7 @@ #include #include #include -#include +#include #include /** @@ -51,7 +52,7 @@ public: moNextMove < Move > & _nextMove, eoEvalFunc < MOEOT > & _eval, moeoMoveIncrEval < Move > & _moveIncrEval, - moeoIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment, + moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment, eoContinue < MOEOT > & _continuator ) : moveInit(_moveInit), @@ -86,13 +87,16 @@ public: moeoArchive < MOEOT > previousArchive; // update the archive with the initial population archive.update(_pop); + unsigned int count = 0; do { previousArchive.update(archive); oneStep(_pop); + count++; archive.update(_pop); } while ( (! archive.equals(previousArchive)) && (continuator(_arch)) ); _arch.update(archive); + cout << "\t" << count << " steps" << endl; } @@ -107,7 +111,7 @@ private: /** the incremental evaluation */ moeoMoveIncrEval < Move > & moveIncrEval; /** the fitness assignment strategy */ - moeoIndicatorBasedFitnessAssignment < MOEOT > & fitnessAssignment; + moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > & fitnessAssignment; /** the stopping criteria */ eoContinue < MOEOT > & continuator; @@ -116,12 +120,8 @@ private: * Apply one step of the local search to the population _pop * @param _pop the population */ - void oneStep (eoPop < MOEOT > & _pop) + void old_oneStep (eoPop < MOEOT > & _pop) { -//////////////////////////////////////////// - int ext_0_idx, ext_1_idx; - ObjectiveVector ext_0_objVec, ext_1_objVec; -/////////////////////////////////////////// // the move Move move; // the objective vector and the fitness of the current solution @@ -131,7 +131,13 @@ private: int worst_idx; ObjectiveVector worst_objVec; double worst_fitness; - // the index current of the current solution to be explored +//////////////////////////////////////////// + // 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]); @@ -146,7 +152,7 @@ private: //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// -// qui sont les extremes ? (=> min only !!!) + // extreme solutions (min only!) ext_0_idx = -1; ext_0_objVec = x_objVec; ext_1_idx = -1; @@ -176,10 +182,10 @@ private: ext_1_objVec = _pop[k].objectiveVector(); } } -// worst init + // worst init if (ext_0_idx == -1) { - unsigned int ind = 0; + ind = 0; while (ind == ext_1_idx) { ind++; @@ -190,7 +196,7 @@ private: } else if (ext_1_idx == -1) { - unsigned int ind = 0; + ind = 0; while (ind == ext_0_idx) { ind++; @@ -275,6 +281,216 @@ private: } } + + + + + + + + + + + + +// INUTILE !!!! + + + + + + + /** + * Apply one step of the local search to the population _pop + * @param _pop the population + */ + 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 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); + +//////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////// + // 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; + } + else if ( (x_objVec[0] == _pop[ext_0_idx].objectiveVector()[0]) && (x_objVec[1] < _pop[ext_0_idx].objectiveVector()[1]) ) + { + ext_0_idx = -1; + } + else if (x_objVec[1] < _pop[ext_1_idx].objectiveVector()[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]) ) + { + ext_1_idx = -1; + } + // worst init + if (ext_0_idx == -1) + { + ind = 0; + while (ind == ext_1_idx) + { + ind++; + } + worst_idx = ind; + worst_objVec = _pop[ind].objectiveVector(); + worst_fitness = _pop[ind].fitness(); + } + else if (ext_1_idx == -1) + { + ind = 0; + while (ind == ext_0_idx) + { + ind++; + } + worst_idx = ind; + worst_objVec = _pop[ind].objectiveVector(); + worst_fitness = _pop[ind].fitness(); + } + else + { + worst_idx = -1; + worst_objVec = x_objVec; + worst_fitness = x_fitness; + } +//////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////// + + // who is the worst ? + for (unsigned int j=0; j<_pop.size(); j++) + { + if ( (j!=ext_0_idx) && (j!=ext_1_idx) ) + { + if (_pop[j].fitness() < worst_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 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()) + { + // 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) + { + // 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]); + } + } + // 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()) + { + // initilization of the move for the next individual + moveInit(move, _pop[i]); + } + } + // update fitness values + fitnessAssignment.updateByDeleting(_pop, worst_objVec); + } + } + + + + + + +////////////////////////////////////////////////////////////////////////////////////////// +class OneObjectiveComparator : public moeoComparator < MOEOT > + { + public: + OneObjectiveComparator(unsigned int _obj) : obj(_obj) + { + if (obj > MOEOT::ObjectiveVector::nObjectives()) + { + 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]) + { + return true; + } + else + { + return (_moeo1.objectiveVector()[obj] == _moeo2.objectiveVector()[obj]) && (_moeo1.objectiveVector()[(obj+1)%2] < _moeo2.objectiveVector()[(obj+1)%2]); + } + } + 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 6ad71f0a5..8a42b25f2 100755 --- a/trunk/paradiseo-moeo/src/algo/moeoIteratedIBMOLS.h +++ b/trunk/paradiseo-moeo/src/algo/moeoIteratedIBMOLS.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include @@ -63,7 +63,7 @@ public: moNextMove < Move > & _nextMove, eoEvalFunc < MOEOT > & _eval, moeoMoveIncrEval < Move > & _moveIncrEval, - moeoIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment, + moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment, eoContinue < MOEOT > & _continuator, eoMonOp < MOEOT > & _monOp, eoMonOp < MOEOT > & _randomMonOp, @@ -134,19 +134,17 @@ private: // 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]]; - // then, apply the operator nIterationsNoise times + // apply noise for (unsigned int j=0; j #include #include -#include +#include +#include #include #include @@ -66,7 +67,7 @@ moeoLS < MOEOT, eoPop & > & do_make_ls_moeo ( 'r', "Evolution Engine").value(); double kappa = _parser.getORcreateParam(0.05, "kappa", "Scaling factor kappa for IndicatorBased", 'k', "Evolution Engine").value(); - moeoIndicatorBasedFitnessAssignment < MOEOT > * fitnessAssignment; + moeoBinaryIndicatorBasedFitnessAssignment < MOEOT > * fitnessAssignment; if (fitnessParam == std::string("IndicatorBased")) { // metric @@ -84,7 +85,7 @@ moeoLS < MOEOT, eoPop & > & do_make_ls_moeo ( std::string stmp = std::string("Invalid binary quality indicator: ") + indicatorParam; throw std::runtime_error(stmp.c_str()); } - fitnessAssignment = new moeoIndicatorBasedFitnessAssignment < MOEOT> (*metric, kappa); + fitnessAssignment = new moeoExpBinaryIndicatorBasedFitnessAssignment < MOEOT> (*metric, kappa); } else {