diff --git a/contribution/branches/MOLS/src2/moeoDMLSGenUpdater.h b/contribution/branches/MOLS/src2/moeoDMLSGenUpdater.h index 420e35cfe..c8e2074ef 100644 --- a/contribution/branches/MOLS/src2/moeoDMLSGenUpdater.h +++ b/contribution/branches/MOLS/src2/moeoDMLSGenUpdater.h @@ -16,14 +16,17 @@ class moeoDMLSGenUpdater : public eoUpdater public : /** Ctor with a dmls. * @param _dmls the dmls use for the hybridization (!!! Special care is needed when choosing the continuator of the dmls !!!) + * @param _dmlsArchive an archive (used to instantiate the dmls) * @param _globalArchive the same archive used in the other algorithm * @param _continuator is a Generational Continuator which allow to run dmls on the global archive each X generation(s) + * @param _verbose verbose mode */ moeoDMLSGenUpdater(moeoUnifiedDominanceBasedLS & _dmls, + moeoArchive < MOEOT > & _dmlsArchive, moeoArchive < MOEOT > & _globalArchive, eoGenContinue < MOEOT > & _continuator, bool _verbose = true): - defaultContinuator(0), dmls(_dmls), globalArchive(_globalArchive), continuator(_continuator), verbose(_verbose){} + defaultContinuator(0), dmlsArchive(_dmlsArchive), dmls(_dmls), globalArchive(_globalArchive), continuator(_continuator), verbose(_verbose){} /** Ctor with a dmls. * @param _eval a evaluation function (used to instantiate the dmls) @@ -32,6 +35,7 @@ class moeoDMLSGenUpdater : public eoUpdater * @param _globalArchive the same archive used in the other algorithm * @param _continuator is a Generational Continuator which allow to run dmls on the global archive each X generation(s) * @param _step (default=1) is the number of Generation of dmls (used to instantiate the defaultContinuator for the dmls) + * @param _verbose verbose mode */ moeoDMLSGenUpdater(eoEvalFunc < MOEOT > & _eval, moeoPopNeighborhoodExplorer < Move > & _explorer, @@ -40,7 +44,7 @@ class moeoDMLSGenUpdater : public eoUpdater eoGenContinue < MOEOT > & _continuator, unsigned int _step=1, bool _verbose = true): - defaultContinuator(_step), dmls(defaultContinuator, _eval, defaultArchive, _explorer, _select), globalArchive(_globalArchive), continuator(_continuator), verbose(_verbose){} + defaultContinuator(_step), dmlsArchive(defaultArchive), dmls(defaultContinuator, _eval, defaultArchive, _explorer, _select), globalArchive(_globalArchive), continuator(_continuator), verbose(_verbose){} /** Ctor with a dmls. * @param _eval a evaluation function (used to instantiate the dmls) @@ -50,6 +54,7 @@ class moeoDMLSGenUpdater : public eoUpdater * @param _globalArchive the same archive used in the other algorithm * @param _continuator is a Generational Continuator which allow to run dmls on the global archive each X generation(s) * @param _step (default=1) is the number of Generation of dmls (used to instantiate the defaultContinuator for the dmls) + * @param _verbose verbose mode */ moeoDMLSGenUpdater(eoEvalFunc < MOEOT > & _eval, moeoArchive < MOEOT > & _dmlsArchive, @@ -59,17 +64,18 @@ class moeoDMLSGenUpdater : public eoUpdater eoGenContinue < MOEOT > & _continuator, unsigned int _step=1, bool _verbose = true): - defaultContinuator(_step), dmls(defaultContinuator, _eval, _dmlsArchive, _explorer, _select), globalArchive(_globalArchive), continuator(_continuator), verbose(_verbose){} + defaultContinuator(_step), dmlsArchive(_dmlsArchive), dmls(defaultContinuator, _eval, _dmlsArchive, _explorer, _select), globalArchive(_globalArchive), continuator(_continuator), verbose(_verbose){} /** functor which allow to run the dmls*/ virtual void operator()() { if(!continuator(globalArchive)){ if(verbose) - std::cout << std::endl << "dmls started" << std::endl; + std::cout << std::endl << "moeoDMLSGenUpdater: dmls start" << std::endl; dmls(globalArchive); + globalArchive(dmlsArchive); if(verbose) - std::cout << "dmls stop" << std::endl; + std::cout << "moeoDMLSGenUpdater: dmls stop" << std::endl; defaultContinuator.totalGenerations(defaultContinuator.totalGenerations()); if(verbose) std::cout << "the other algorithm restart for " << continuator.totalGenerations() << " generation(s)" << std::endl << std::endl; @@ -85,6 +91,8 @@ class moeoDMLSGenUpdater : public eoUpdater private: /** defaultContinuator used for the dmls */ eoGenContinue < MOEOT > defaultContinuator; + /** dmls archive */ + moeoArchive < MOEOT > & dmlsArchive; /** default archive used for the dmls */ moeoUnboundedArchive < MOEOT > defaultArchive; /** the dmls */ diff --git a/contribution/branches/MOLS/src2/moeoDMLSMonOp.h b/contribution/branches/MOLS/src2/moeoDMLSMonOp.h new file mode 100644 index 000000000..f9d9f01bd --- /dev/null +++ b/contribution/branches/MOLS/src2/moeoDMLSMonOp.h @@ -0,0 +1,91 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +/** eoMonOp allowing hybridization with a dmls at mutation */ +template < class Move > +class moeoDMLSMonOp : public eoMonOp < typename Move::EOType > +{ + + typedef typename Move::EOType MOEOT; + + public : + /** Ctor with a dmls. + * @param _dmls the dmls use for the hybridization (!!! Special care is needed when choosing the continuator of the dmls !!!) + * @param _dmlsArchive an archive (used to instantiate the dmls) + * @param _verbose verbose mode + */ + moeoDMLSMonOp(moeoUnifiedDominanceBasedLS & _dmls, + moeoArchive < MOEOT > & _dmlsArchive, + bool _verbose = true): + defaultContinuator(0), dmlsArchive(_dmlsArchive), dmls(_dmls), verbose(_verbose) {} + + /** Ctor with a dmls. + * @param _eval a evaluation function (used to instantiate the dmls) + * @param _eplorer a neighborhood explorer (used to instantiate the dmls) + * @param _select a selector of unvisited individuals of a population (used to instantiate the dmls) + * @param _step (default=1) is the number of Generation of dmls (used to instantiate the defaultContinuator for the dmls) + * @param _verbose verbose mode + */ + moeoDMLSMonOp(eoEvalFunc < MOEOT > & _eval, + moeoPopNeighborhoodExplorer < Move > & _explorer, + moeoUnvisitedSelect < MOEOT > & _select, + unsigned int _step=1, + bool _verbose = true): + defaultContinuator(_step), dmlsArchive(defaultArchive), dmls(defaultContinuator, _eval, defaultArchive, _explorer, _select), verbose(_verbose){} + + /** Ctor with a dmls. + * @param _eval a evaluation function (used to instantiate the dmls) + * @param _dmlsArchive an archive (used to instantiate the dmls) + * @param _eplorer a neighborhood explorer (used to instantiate the dmls) + * @param _select a selector of unvisited individuals of a population (used to instantiate the dmls) + * @param _step (default=1) is the number of Generation of dmls (used to instantiate the defaultContinuator for the dmls) + * @param _verbose verbose mode + */ + moeoDMLSMonOp(eoEvalFunc < MOEOT > & _eval, + moeoArchive < MOEOT > & _dmlsArchive, + moeoPopNeighborhoodExplorer < Move > & _explorer, + moeoUnvisitedSelect < MOEOT > & _select, + unsigned int _step=1, + bool _verbose = true): + defaultContinuator(_step), dmlsArchive(_dmlsArchive), dmls(defaultContinuator, _eval, _dmlsArchive, _explorer, _select), verbose(_verbose){} + + /** functor which allow to run the dmls on a MOEOT and return one of the resulting archive*/ + bool operator()( MOEOT & _moeo) + { + if(verbose) + std::cout << std::endl << "moeoDMLSMonOp: dmls start" << std::endl; + unsigned int tmp; + eoPop < MOEOT> pop; + pop.push_back(_moeo); + dmls(pop); + tmp = rng.random(dmlsArchive.size()); + _moeo = dmlsArchive[tmp]; + defaultContinuator.totalGenerations(defaultContinuator.totalGenerations()); + if(verbose) + std::cout << "moeoDMLSMonOp: dmls stop" << std::endl << std::endl; + return false; + } + + /** + * @return the class name + */ + virtual std::string className(void) const { return "moeoDMLSMonOp"; } + +private: + /** defaultContinuator used for the dmls */ + eoGenContinue < MOEOT > defaultContinuator; + /** dmls archive */ + moeoArchive < MOEOT > & dmlsArchive; + /** default archive used for the dmls */ + moeoUnboundedArchive < MOEOT > defaultArchive; + /** the dmls */ + moeoUnifiedDominanceBasedLS dmls; + /** verbose mode */ + bool verbose; +};