From db66347fb1726cc45d3ed936b5d6c903835a1409 Mon Sep 17 00:00:00 2001 From: jhumeau Date: Thu, 19 Feb 2009 15:32:42 +0000 Subject: [PATCH] git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1450 331e1502-861f-0410-8da2-ba01fb791d7f --- .../MOLS/src/moeoAllSolAllNeighborsExpl.h | 42 ++++--- .../MOLS/src/moeoAllSolOneNeighborExpl.h | 10 +- .../MOLS/src/moeoOneSolAllNeighborsExpl.h | 42 ++++--- .../MOLS/src/moeoOneSolOneNeighborExpl.h | 116 +++++++++++++----- .../MOLS/src/moeoUnifiedDominanceBasedLS.h | 31 ++--- .../test/t-moeoUnifiedDominanceBasedLS.cpp | 3 +- 6 files changed, 150 insertions(+), 94 deletions(-) diff --git a/contribution/branches/MOLS/src/moeoAllSolAllNeighborsExpl.h b/contribution/branches/MOLS/src/moeoAllSolAllNeighborsExpl.h index 6a7861f3e..1087db55a 100755 --- a/contribution/branches/MOLS/src/moeoAllSolAllNeighborsExpl.h +++ b/contribution/branches/MOLS/src/moeoAllSolAllNeighborsExpl.h @@ -59,26 +59,30 @@ public: moeoAllSolAllNeighborsExpl( moMoveInit < Move > & _moveInit, moNextMove < Move > & _nextMove, - eoEvalFunc < MOEOT > & _eval - ): moveInit(_moveInit), nextMove(_nextMove), eval(_eval){} + moMoveIncrEval < Move, ObjectiveVector > & _incrEval) + : moveInit(_moveInit), nextMove(_nextMove), incrEval(_incrEval){} - void operator()(eoPop < MOEOT > & _src, eoPop < MOEOT > & _dest){ + void operator()(eoPop < MOEOT > & _src, eoPop < MOEOT > & _dest) + { Move move; - MOEOT * sol; ObjectiveVector objVec; - - for(unsigned int i=0; i<_src.size(); i++){ - if (_src[i].flag() == 0){ + for(unsigned int i=0; i<_src.size(); i++) + { + if (_src[i].flag() == 0) + { moveInit(move, _src[i]); - do{ - _dest.push_back(_src[i]); - sol = & _dest.back(); - //objVec = moveIncrEval(move, *sol); - move(*sol); - sol->invalidate(); - eval(*sol); - //sol->objectiveVector(objVec); - //if (comparator(sol, _src[i])) + do + { + objVec = moveIncrEval(move, _src[i]); + if (! comparator (objVec, _src[i].objectiveVector())) + { + if (objVec != _src[i].objectiveVector()) + { + _dest.push_back(_src[i]); + move(_dest.back()); + _dest.back().objectiveVector(objVec); + } + } } while(nextMove(move, _src[i])); _src[i].flag(1); @@ -92,8 +96,10 @@ private: /** the neighborhood explorer */ moNextMove < Move > & nextMove; /** the incremental evaluation */ - eoEvalFunc < MOEOT > & eval; - + moMoveIncrEval < Move, ObjectiveVector > & incrEval; + /** comparator */ + moeoParetoObjectiveVectorComparator comparator; + }; #endif /*_MOEOALLSOLALLNEIGHBORSEXPL_H_*/ diff --git a/contribution/branches/MOLS/src/moeoAllSolOneNeighborExpl.h b/contribution/branches/MOLS/src/moeoAllSolOneNeighborExpl.h index bead42575..ff43e9b2e 100644 --- a/contribution/branches/MOLS/src/moeoAllSolOneNeighborExpl.h +++ b/contribution/branches/MOLS/src/moeoAllSolOneNeighborExpl.h @@ -60,8 +60,8 @@ public: moeoAllSolOneNeighborExpl( moMoveInit < Move > & _moveInit, moNextMove < Move > & _nextMove, - eoEvalFunc < MOEOT > & _eval - ): moveInit(_moveInit), nextMove(_nextMove), eval(_eval){} + moMoveIncrEval < Move, ObjectiveVector > & _incrEval) + : moveInit(_moveInit), nextMove(_nextMove), incrEval(_incrEval){} void operator()(eoPop < MOEOT > & _src, eoPop < MOEOT > & _dest){ //Move move; @@ -160,7 +160,11 @@ private: moNextMove < Move > & nextMove; /** the incremental evaluation */ eoEvalFunc < MOEOT > & eval; - + /** the incremental evaluation */ + moMoveIncrEval < Move, ObjectiveVector > & incrEval; + /** comparator */ + moeoParetoObjectiveVectorComparator comparator; + }; #endif /*_MOEOALLSOLONENEIGHBOREXPL_H_*/ diff --git a/contribution/branches/MOLS/src/moeoOneSolAllNeighborsExpl.h b/contribution/branches/MOLS/src/moeoOneSolAllNeighborsExpl.h index c56c83a76..a16ea251a 100644 --- a/contribution/branches/MOLS/src/moeoOneSolAllNeighborsExpl.h +++ b/contribution/branches/MOLS/src/moeoOneSolAllNeighborsExpl.h @@ -57,32 +57,34 @@ class moeoOneSolAllNeighborsExpl : public moeoPopNeighborhoodExplorer < Move > public: moeoOneSolAllNeighborsExpl( - moMoveInit < Move > & _moveInit, - moNextMove < Move > & _nextMove, - eoEvalFunc < MOEOT > & _eval - ): moveInit(_moveInit), nextMove(_nextMove), eval(_eval){} + moMoveInit < Move > & _moveInit, + moNextMove < Move > & _nextMove, + moMoveIncrEval < Move, ObjectiveVector > & _incrEval) + : moveInit(_moveInit), nextMove(_nextMove), incrEval(_incrEval){} - void operator()(eoPop < MOEOT > & _src, eoPop < MOEOT > & _dest){ + void operator()(eoPop < MOEOT > & _src, eoPop < MOEOT > & _dest) + { Move move; - MOEOT * sol; ObjectiveVector objVec; - unsigned int i = 0; while(_src[i].flag() != 0) i++; moveInit(move, _src[i]); - do{ - _dest.push_back(_src[i]); - sol = & _dest.back(); - //objVec = moveIncrEval(move, *sol); - move(*sol); - sol->invalidate(); - eval(*sol); - //sol->objectiveVector(objVec); - //if (comparator(sol, _src[i])) + do + { + objVec = moveIncrEval(move, _src[i]); + if (! comparator (objVec, _src[i].objectiveVector())) + { + if (objVec != _src[i].objectiveVector()) + { + _dest.push_back(_src[i]); + move(_dest.back()); + _dest.back().objectiveVector(objVec); + } + } } while(nextMove(move, _src[i])); - _src[i].flag(1); + _src[i].flag(1); } private: @@ -91,8 +93,10 @@ private: /** the neighborhood explorer */ moNextMove < Move > & nextMove; /** the incremental evaluation */ - eoEvalFunc < MOEOT > & eval; - + moMoveIncrEval < Move, ObjectiveVector > & incrEval; + /** comparator */ + moeoParetoObjectiveVectorComparator comparator; + }; #endif /*_MOEOONESOLALLNEIGHBORSEXPL_H_*/ diff --git a/contribution/branches/MOLS/src/moeoOneSolOneNeighborExpl.h b/contribution/branches/MOLS/src/moeoOneSolOneNeighborExpl.h index 797409698..d695df48a 100644 --- a/contribution/branches/MOLS/src/moeoOneSolOneNeighborExpl.h +++ b/contribution/branches/MOLS/src/moeoOneSolOneNeighborExpl.h @@ -59,47 +59,60 @@ public: moeoOneSolOneNeighborExpl( moMoveInit < Move > & _moveInit, moNextMove < Move > & _nextMove, - eoEvalFunc < MOEOT > & _eval - ):start(false), moveInit(_moveInit), nextMove(_nextMove), eval(_eval){} + moMoveIncrEval < Move, ObjectiveVector > & _incrEval) + : moveInit(_moveInit), nextMove(_nextMove), incrEval(_incrEval){} - void operator()(eoPop < MOEOT > & _src, eoPop < MOEOT > & _dest){ - //Move move; - MOEOT * sol; + void operator()(eoPop < MOEOT > & _src, eoPop < MOEOT > & _dest) + { ObjectiveVector objVec; - unsigned int i = 0; - while(_src[i].flag() != 0) - i++; - if(!start){ + // setting _src[i] + if(!start) + { + while(_src[i].flag() != 0) + i++; moveInit(move, _src[i]); - _dest.push_back(_src[i]); - sol = & _dest.back(); - move(*sol); - sol->invalidate(); - eval(*sol); - if(nextMove(move, _src[i])) - start=true; - else{ - start=false; - _src[i].flag(1); + _src[i].flag()=-1; + } + else + { + while( (i < _src.size()) && (_src[i].flag() != -1) ) + i++; + if(_src[i].flag() != -1) + { + i=0; + while(_src[i].flag() != 0) + i++; + moveInit(move, _src[i]); + _src[i].flag()=-1; } } - else{ - _dest.push_back(_src[i]); - sol = & _dest.back(); - //objVec = moveIncrEval(move, *sol); - move(*sol); - sol->invalidate(); - eval(*sol); - //sol->objectiveVector(objVec); - //if (comparator(sol, _src[i])) - if(!nextMove(move, _src[i])){ - start=false; - _src[i].flag(1); - } - } + // ttt + objVec = moveIncrEval(move, _src[i]); + if (! comparator (objVec, _src[i].objectiveVector())) + { + if (objVec != _src[i].objectiveVector()) + { + _dest.push_back(_src[i]); + move(_dest.back()); + _dest.back().objectiveVector(objVec); + } + } + // preparing the next iteration + if(nextMove(move, _src[i])) + { + start=true; + } + else + { + start=false; + _src[i].flag(1); + } } + + + private: Move move; bool start; @@ -108,7 +121,42 @@ private: /** the neighborhood explorer */ moNextMove < Move > & nextMove; /** the incremental evaluation */ - eoEvalFunc < MOEOT > & eval; + moMoveIncrEval < Move, ObjectiveVector > & incrEval; + /** comparator */ + moeoParetoObjectiveVectorComparator comparator; + + + +// if(!start){ +// moveInit(move, _src[i]); +// _dest.push_back(_src[i]); +// sol = & _dest.back(); +// move(*sol); +// sol->invalidate(); +// eval(*sol); +// if(nextMove(move, _src[i])) +// start=true; +// else{ +// start=false; +// _src[i].flag(1); +// } +// } +// else{ +// _dest.push_back(_src[i]); +// sol = & _dest.back(); +// //objVec = moveIncrEval(move, *sol); +// move(*sol); +// sol->invalidate(); +// eval(*sol); +// //sol->objectiveVector(objVec); +// //if (comparator(sol, _src[i])) +// if(!nextMove(move, _src[i])){ +// start=false; +// _src[i].flag(1); +// } +// } +// } + }; diff --git a/contribution/branches/MOLS/src/moeoUnifiedDominanceBasedLS.h b/contribution/branches/MOLS/src/moeoUnifiedDominanceBasedLS.h index 0cda53518..e2a0ab2fd 100644 --- a/contribution/branches/MOLS/src/moeoUnifiedDominanceBasedLS.h +++ b/contribution/branches/MOLS/src/moeoUnifiedDominanceBasedLS.h @@ -57,18 +57,11 @@ public: moeoUnifiedDominanceBasedLS( eoContinue < MOEOT > & _continuator, - //moeoContinue < MOEOT > & _naturalContinuator, eoEvalFunc < MOEOT > & _full_evaluation, - eoPopEvalFunc < MOEOT > & _popEval, +// eoPopEvalFunc < MOEOT > & _popEval, moeoArchive < MOEOT > & _archive, moeoPopNeighborhoodExplorer < Move > & _explorer - ):continuator(_continuator), naturalContinuator(defaultContinuator), full_evaluation(_full_evaluation), popEval(_popEval), archive(_archive), explorer(_explorer) - {} - - moeoUnifiedDominanceBasedLS( - eoContinue < MOEOT > & _continuator, - moeoPopNeighborhoodExplorer < Move > & _explorer - ):continuator(_continuator), naturalContinuator(defaultContinuator), full_evaluation(dummyEval),loopEval(dummyEval), popEval(loopEval), archive(defaultArchive), explorer(_explorer) + ):continuator(_continuator), full_evaluation(_full_evaluation), popEval(full_evaluation), archive(_archive), explorer(_explorer) {} /** @@ -117,25 +110,25 @@ protected: std::cout << res << std::endl; return res; } - }; + } naturalContinuator; - moeoContinue < MOEOT > defaultContinuator; +// moeoContinue < MOEOT > defaultContinuator; - moeoContinue < MOEOT > & naturalContinuator; +// moeoContinue < MOEOT > & naturalContinuator; /** a dummy eval */ - class eoDummyEval : public eoEvalFunc < MOEOT > - { - public: - void operator()(MOEOT &) {} - } - dummyEval; +// class eoDummyEval : public eoEvalFunc < MOEOT > +// { +// public: +// void operator()(MOEOT &) {} +// } +// dummyEval; eoEvalFunc < MOEOT > & full_evaluation; eoPopLoopEval < MOEOT > loopEval; eoPopEvalFunc < MOEOT > & popEval; - moeoUnboundedArchive < MOEOT > defaultArchive; +// moeoUnboundedArchive < MOEOT > defaultArchive; moeoArchive < MOEOT > & archive; moeoPopNeighborhoodExplorer < Move > & explorer; diff --git a/contribution/branches/MOLS/test/t-moeoUnifiedDominanceBasedLS.cpp b/contribution/branches/MOLS/test/t-moeoUnifiedDominanceBasedLS.cpp index f7db3aecf..fdb0998d7 100644 --- a/contribution/branches/MOLS/test/t-moeoUnifiedDominanceBasedLS.cpp +++ b/contribution/branches/MOLS/test/t-moeoUnifiedDominanceBasedLS.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -36,7 +37,7 @@ int main(int argc, char* argv[]) eoPop& pop = do_make_pop(parser, state, init); eoTimeContinue < FlowShop > continuator(10000000); - moeoOneSolOneNeighborExpl < ExchangeMove > explorer(moveInit,moveNext, eval); + moeoAllSolOneNeighborExpl < ExchangeMove > explorer(moveInit,moveNext, eval); // moeoUnifiedDominanceBasedLS < ExchangeMove > algo(continuator, explorer);