From 9d21c75869cf4578c8369fc18b5c4ccf5119dd30 Mon Sep 17 00:00:00 2001 From: jhumeau Date: Fri, 13 Nov 2009 16:45:16 +0000 Subject: [PATCH] git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1617 331e1502-861f-0410-8da2-ba01fb791d7f --- .../src/archive/moeoEpsilonHyperboxArchive.h | 419 ++++++++++++++++++ .../src/archive/moeoQuadTreeArchive.h | 109 +++++ .../src/distance/moeoEuclideanDistance.h | 18 + trunk/paradiseo-moeo/src/moeo | 4 + .../src/utils/moeoObjectiveVectorNormalizer.h | 278 ++++++++++++ trunk/paradiseo-moeo/src/utils/moeoQuadTree.h | 308 +++++++++++++ trunk/paradiseo-moeo/test/CMakeLists.txt | 2 + .../test/t-moeoEpsilonHyperboxArchive.cpp | 158 +++++++ .../test/t-moeoQuadTreeArchive.cpp | 116 +++++ .../test/t-moeoUnboundedArchive.cpp | 2 +- 10 files changed, 1413 insertions(+), 1 deletion(-) create mode 100644 trunk/paradiseo-moeo/src/archive/moeoEpsilonHyperboxArchive.h create mode 100644 trunk/paradiseo-moeo/src/archive/moeoQuadTreeArchive.h create mode 100644 trunk/paradiseo-moeo/src/utils/moeoObjectiveVectorNormalizer.h create mode 100644 trunk/paradiseo-moeo/src/utils/moeoQuadTree.h create mode 100644 trunk/paradiseo-moeo/test/t-moeoEpsilonHyperboxArchive.cpp create mode 100644 trunk/paradiseo-moeo/test/t-moeoQuadTreeArchive.cpp diff --git a/trunk/paradiseo-moeo/src/archive/moeoEpsilonHyperboxArchive.h b/trunk/paradiseo-moeo/src/archive/moeoEpsilonHyperboxArchive.h new file mode 100644 index 000000000..8890a88e8 --- /dev/null +++ b/trunk/paradiseo-moeo/src/archive/moeoEpsilonHyperboxArchive.h @@ -0,0 +1,419 @@ +/* +* +* Copyright (C) DOLPHIN Project-Team, INRIA Lille-Nord Europe, 2006-2008 +* (C) OPAC Team, LIFL, 2002-2008 +* +* Arnaud Liefooghe +* Jeremie Humeau +* +* This software is governed by the CeCILL license under French law and +* abiding by the rules of distribution of free software. You can use, +* modify and/ or redistribute the software under the terms of the CeCILL +* license as circulated by CEA, CNRS and INRIA at the following URL +* "http://www.cecill.info". +* +* As a counterpart to the access to the source code and rights to copy, +* modify and redistribute granted by the license, users are provided only +* with a limited warranty and the software's author, the holder of the +* economic rights, and the successive licensors have only limited liability. +* +* In this respect, the user's attention is drawn to the risks associated +* with loading, using, modifying and/or developing or reproducing the +* software by the user in light of its specific status of free software, +* that may mean that it is complicated to manipulate, and that also +* therefore means that it is reserved for developers and experienced +* professionals having in-depth computer knowledge. Users are therefore +* encouraged to load and test the software's suitability as regards their +* requirements in conditions enabling the security of their systems and/or +* data to be ensured and, more generally, to use and operate it in the +* same conditions as regards security. +* The fact that you are presently reading this means that you have had +* knowledge of the CeCILL license and that you accept its terms. +* +* ParadisEO WebSite : http://paradiseo.gforge.inria.fr +* Contact: paradiseo-help@lists.gforge.inria.fr +* +*/ +//----------------------------------------------------------------------------- +// moeoEpsilonHyperboxArchive.h +//----------------------------------------------------------------------------- + +#ifndef MOEOEPSILONBOXARCHIVE_H_ +#define MOEOEPSILONBOXARCHIVE_H_ + +#include +#include +#include +#include +#include +#include + +/** + * This class represents an epsilon hyperbox archive. + */ +template < class MOEOT > +class moeoEpsilonHyperboxArchive : public moeoArchive < MOEOT > +{ +public: + + using moeoArchive < MOEOT > :: size; + using moeoArchive < MOEOT > :: resize; + using moeoArchive < MOEOT > :: operator[]; + using moeoArchive < MOEOT > :: back; + using moeoArchive < MOEOT > :: pop_back; + using moeoArchive < MOEOT > :: push_back; + using moeoArchive < MOEOT > :: begin; + using moeoArchive < MOEOT > :: end; + using moeoArchive < MOEOT > :: replace; + + + /** + * The type of an objective vector for a solution + */ + typedef typename MOEOT::ObjectiveVector ObjectiveVector; + + + /** + * Ctor where you can choose your own moeoObjectiveVectorComparator + * @param _comparator the functor used to compare objective vectors + * @param _epsilon the vector contains epsilon values for each objective + * @param _replace boolean which determine if a solution with the same objectiveVector than another one, can replace it or not + */ + moeoEpsilonHyperboxArchive(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator, std::vector _epsilon, bool _replace=true) : moeoArchive < MOEOT >(_comparator, _replace), epsilon(_epsilon), bounds(0.0, 1.0), normalizer(bounds, 1.0) + {} + + /** + * Default Ctor + * @param _epsilon the vector contains epsilon values for each objective + * @param _replace boolean which determine if a solution with the same objectiveVector than another one, can replace it or not + */ + moeoEpsilonHyperboxArchive(std::vector _epsilon, bool _replace=true) : moeoArchive < MOEOT >(paretoComparator, _replace), epsilon(_epsilon), bounds(0.0, 1.0), normalizer(bounds, 1.0) + {} + + /** + * Updates the archive with a given individual _moeo + * @param _moeo the given individual + * @return true if _moeo is non-dominated (and not if it is added to the archive) + */ + bool operator()(const MOEOT & _moeo) + { + bool res=false; + unsigned int i=0; + bool nonstop = true; + bool same = true; + int change = 0; + MOEOT removed; + + //if the archive is empty, we accept automaticaly _moeo + if(size()==0){ + push_back(_moeo); + ideal = _moeo.objectiveVector(); + nadir = _moeo.objectiveVector(); + res = true; + } + else{ + //change bounds if necessary + change = changeBounds(_moeo); + + //if change < 0, we have detected that _moeo is bad + //else there are 4 cases: + if(change >= 0){ + //calculate the hyperbox corner of _moeo + ObjectiveVector corner, tmp; + corner=hyperbox(_moeo); + + //test if _moeo hyperbox corner dominates a hyperbox corner of an element of the archive + while(nonstop && (i dist; + double d1 = dist(_moeo.objectiveVector(), corner); + double d2 = dist(operator[](i).objectiveVector(), corner); + if(d1 <= d2){ + if(i==size()-1) + pop_back(); + else{ + operator[](i)=back(); + pop_back(); + i--; + } +// removed=operator[](i); +// operator[](i) = _moeo; +// changeBoundsByDeleting(removed); + res=true; + } + else{ + nonstop=false; +// changeBoundsByDeleting(_moeo); + res=true; + } + } + + }//END CASE 3 + } + i++; + } + //CASE 4: _moeo have is place in a empty hyperbox + if(nonstop){ + std::cout << "ENTER CASE 4" << std::endl; + push_back(_moeo); + res=true; + recalculateBounds(); + }//END CASE 4 + } + else{ + std::cout << "ENTER CASE 5" << std::endl; + } + } + + return res; + } + + /** + * Updates the archive with a given population _pop + * @param _pop the given population + * @return if an archive's element is non-dominated (and not if it is added to the archive) + */ + bool operator()(const eoPop < MOEOT > & _pop) + { + bool res, tmp = false; + for(unsigned int i=0; i<_pop.size(); i++){ + tmp = (*this)(_pop[i]); + res = res || tmp; + } + return res; + } + + + /** + * get the nadir point + * @return ObjectiveVector corresponding to the nadir point + */ + ObjectiveVector getNadir(){ + return nadir; + } + + /** + * get the idealpoint + * @return ObjectiveVector corresponding to the ideal point + */ + ObjectiveVector getIdeal(){ + return ideal; + } + + void filtre(){ + eoPop pop; + for(int i=0; i changed, 0 -> not changed, -1 -> _moeo is bad) + */ + int changeBounds(const MOEOT & _moeo){ +// std::cout << "changebounds objVec: "<< _moeo.objectiveVector() << std::endl; + int res = 0; + //check if an objective is better than the corresponding of the current ideal point + for(unsigned int i=0; i ideal[i]){ + ideal[i]=_moeo.objectiveVector()[i]; + res = 1; + } + } + } + //check if an objective is worst than the corresponding of the current nadir point + for(unsigned int i=0; i nadir[i]){ + if(res == 1) + nadir[i]=_moeo.objectiveVector()[i]; + else + res = -1; // no objective is better than the ideal and some are worst than nadir -> _moeo is bad + } + } + else{ + if(_moeo.objectiveVector()[i] < nadir[i]){ + if(res == 1) + nadir[i]=_moeo.objectiveVector()[i]; + else + res = -1; // no objective is better than the ideal and some are worst than nadir -> _moeo is bad + } + } + } + //If bounds are changed, change the scale of normalizer + if(res == 1){ + ObjectiveVector mini; + ObjectiveVector maxi; + for(unsigned int i=0; i 1){ + for(unsigned int i=0; i< ObjectiveVector::nObjectives(); i++){ + for(unsigned int j=1; j nadir[i]) + nadir[i] = tmp[i]; + } + else{ + if(tmp[i] > ideal[i]) + ideal[i] = tmp[i]; + else if(tmp[i] < nadir[i]) + nadir[i] = tmp[i]; + } + } + } + } + ObjectiveVector mini; + ObjectiveVector maxi; + for(unsigned int i=0; i paretoComparator; + + /** epsilon values */ + std::vector epsilon; + + /** ideal point of the archive */ + ObjectiveVector ideal; + /** nadir point of the archive */ + ObjectiveVector nadir; + + /** bounds use by default to initialize the normalizer */ + eoRealInterval bounds; + + /** the objective vector normalizer */ + moeoObjectiveVectorNormalizer normalizer; + +}; + +#endif /*MOEOEPSILONBOXARCHIVE_H_*/ diff --git a/trunk/paradiseo-moeo/src/archive/moeoQuadTreeArchive.h b/trunk/paradiseo-moeo/src/archive/moeoQuadTreeArchive.h new file mode 100644 index 000000000..e7317db9e --- /dev/null +++ b/trunk/paradiseo-moeo/src/archive/moeoQuadTreeArchive.h @@ -0,0 +1,109 @@ +/* +* +* Copyright (C) DOLPHIN Project-Team, INRIA Lille-Nord Europe, 2006-2008 +* (C) OPAC Team, LIFL, 2002-2008 +* +* Arnaud Liefooghe +* Jeremie Humeau +* +* This software is governed by the CeCILL license under French law and +* abiding by the rules of distribution of free software. You can use, +* modify and/ or redistribute the software under the terms of the CeCILL +* license as circulated by CEA, CNRS and INRIA at the following URL +* "http://www.cecill.info". +* +* As a counterpart to the access to the source code and rights to copy, +* modify and redistribute granted by the license, users are provided only +* with a limited warranty and the software's author, the holder of the +* economic rights, and the successive licensors have only limited liability. +* +* In this respect, the user's attention is drawn to the risks associated +* with loading, using, modifying and/or developing or reproducing the +* software by the user in light of its specific status of free software, +* that may mean that it is complicated to manipulate, and that also +* therefore means that it is reserved for developers and experienced +* professionals having in-depth computer knowledge. Users are therefore +* encouraged to load and test the software's suitability as regards their +* requirements in conditions enabling the security of their systems and/or +* data to be ensured and, more generally, to use and operate it in the +* same conditions as regards security. +* The fact that you are presently reading this means that you have had +* knowledge of the CeCILL license and that you accept its terms. +* +* ParadisEO WebSite : http://paradiseo.gforge.inria.fr +* Contact: paradiseo-help@lists.gforge.inria.fr +* +*/ +//----------------------------------------------------------------------------- +// moeoEpsilonHyperboxArchive.h +//----------------------------------------------------------------------------- + +#ifndef MOEOQUADTREEARCHIVE_H_ +#define MOEOQUADTREEARCHIVE_H_ + +#include + + +/** + * This class represents an epsilon hyperbox archive. + */ +template < class MOEOT > +class moeoQuadTreeArchive : public moeoArchive < MOEOT > +{ +public: + + using moeoArchive < MOEOT > :: size; + using moeoArchive < MOEOT > :: resize; + using moeoArchive < MOEOT > :: operator[]; + using moeoArchive < MOEOT > :: back; + using moeoArchive < MOEOT > :: pop_back; + using moeoArchive < MOEOT > :: push_back; + using moeoArchive < MOEOT > :: begin; + using moeoArchive < MOEOT > :: end; + using moeoArchive < MOEOT > :: replace; + + + /** + * The type of an objective vector for a solution + */ + typedef typename MOEOT::ObjectiveVector ObjectiveVector; + + + /** + * Ctor where you can choose your own moeoObjectiveVectorComparator + * @param _comparator the functor used to compare objective vectors + * @param _epsilon the vector contains epsilon values for each objective + * @param _replace boolean which determine if a solution with the same objectiveVector than another one, can replace it or not + */ + moeoQuadTreeArchive() : moeoArchive < MOEOT >(){} + + /** + * Updates the archive with a given individual _moeo + * @param _moeo the given individual + * @return if the _moeo is added to the archive + */ + bool operator()(const MOEOT & _moeo){ + return false; + } + + + /** + * Updates the archive with a given population _pop + * @param _pop the given population + * @return if at least one _pop[i] is added to the archive + */ + bool operator()(const eoPop < MOEOT > & _pop){ + bool res, tmp = false; + for(unsigned int i=0; i<_pop.size(); i++){ + tmp = (*this)(_pop[i]); + res = res || tmp; + } + return res; + } + + + + +}; + +#endif /*MOEOQUADTREEARCHIVE_H_*/ diff --git a/trunk/paradiseo-moeo/src/distance/moeoEuclideanDistance.h b/trunk/paradiseo-moeo/src/distance/moeoEuclideanDistance.h index 7b29cce17..2c949a464 100644 --- a/trunk/paradiseo-moeo/src/distance/moeoEuclideanDistance.h +++ b/trunk/paradiseo-moeo/src/distance/moeoEuclideanDistance.h @@ -72,6 +72,24 @@ class moeoEuclideanDistance : public moeoNormalizedDistance < MOEOT > return sqrt(result); } + /** + * Returns the euclidian distance between _obj1 and _obj2 + * @param _obj1 the first objective vector + * @param _obj2 the second objective vector + */ + const double operator()(const ObjectiveVector & _obj1, const ObjectiveVector & _obj2) + { + double result = 0.0; + double tmp1, tmp2; + for (unsigned int i=0; i #include #include +#include +#include #include @@ -151,6 +153,8 @@ #include #include #include +#include + #endif /*MOEO_*/ diff --git a/trunk/paradiseo-moeo/src/utils/moeoObjectiveVectorNormalizer.h b/trunk/paradiseo-moeo/src/utils/moeoObjectiveVectorNormalizer.h new file mode 100644 index 000000000..b56611e5a --- /dev/null +++ b/trunk/paradiseo-moeo/src/utils/moeoObjectiveVectorNormalizer.h @@ -0,0 +1,278 @@ +/* +* +* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2009 +* +* Legillon François +* +* +* This software is governed by the CeCILL license under French law and +* abiding by the rules of distribution of free software. You can use, +* modify and/ or redistribute the software under the terms of the CeCILL +* license as circulated by CEA, CNRS and INRIA at the following URL +* "http://www.cecill.info". +* +* As a counterpart to the access to the source code and rights to copy, +* modify and redistribute granted by the license, users are provided only +* with a limited warranty and the software's author, the holder of the +* economic rights, and the successive licensors have only limited liability. +* +* In this respect, the user's attention is drawn to the risks associated +* with loading, using, modifying and/or developing or reproducing the +* software by the user in light of its specific status of free software, +* that may mean that it is complicated to manipulate, and that also +* therefore means that it is reserved for developers and experienced +* professionals having in-depth computer knowledge. Users are therefore +* encouraged to load and test the software's suitability as regards their +* requirements in conditions enabling the security of their systems and/or +* data to be ensured and, more generally, to use and operate it in the +* same conditions as regards security. +* The fact that you are presently reading this means that you have had +* knowledge of the CeCILL license and that you accept its terms. +* +* ParadisEO WebSite : http://paradiseo.gforge.inria.fr +* Contact: paradiseo-help@lists.gforge.inria.fr +* +*/ +//----------------------------------------------------------------------------- + +#ifndef MOEOOBJVECNORM_H_ +#define MOEOOBJVECNORM_H_ +#include +#include +/** + class to normalize each dimension of objectiveVectors + */ +template +class moeoObjectiveVectorNormalizer +{ + public: + typedef typename MOEOT::ObjectiveVector ObjectiveVector; + typedef typename MOEOT::ObjectiveVector::Type Type; + typedef typename std::vector > Scale; + typedef eoRealInterval Bounds; + + + + /** + constructor with a supplied scale, usefull if you tweak your scale + @param scale the scale for noramlzation + */ + moeoObjectiveVectorNormalizer(Scale &_scale,Type max_param=100):scale(_scale),max(max_param) + {} + /** + constructor to create a normalizer from a given population + @param _pop the population to analyse to create the scale + @param max_param the returned values will be between 0 and max + */ + moeoObjectiveVectorNormalizer(eoPop &_pop, Type max_param=100):scale(make_scale_from_pop(_pop,max_param)),max(max_param) + {} + /** + constructor to create a normalizer with given boundaries + @param boundaries the supplied vectors should have their values between thos boundaries + **/ + moeoObjectiveVectorNormalizer(std::vector &_boundaries, Type max_param=100):scale(make_scale_from_bounds(_boundaries,max_param)), max(max_param) + {} + /** + constructor to create a normalizer from bounds + @param bounds the supplied vectors should have their value in those bounds + **/ + moeoObjectiveVectorNormalizer(Bounds &_bounds, Type max_param=100 ):scale(make_scale_from_bounds(_bounds,ObjectiveVector::nObjectives(),max_param)), max(max_param) + {} + /** + constructor to create a normalizer from a worst vector and a best vector + @param _worst the worst possible vector + @param _best the best possible vector + @param max_param the maximum value for returned objectives + */ + moeoObjectiveVectorNormalizer(const ObjectiveVector &_best,const ObjectiveVector &_worst, Type max_param=100 ):scale(make_scale_from_minmax(_best,_worst,max_param)), max(max_param) + {} + + + /** + * Creates a scale which can be used in conjonction with a normalizer + * @param _pop the population to analyse + * @param max_param worst vector is set to it + * @return a scale to use with the normalizer + */ + static Scale make_scale_from_pop(eoPop &_pop, Type &max_param=100){ + Scale res; + if (_pop.empty()) { + std::cout<<"makeScale in moeoObjectiveVEctorNormalizer.h: pop is empty"< amps; + std::vector mins; + unsigned int num_amp_max=0; + //recherche des min et du max, par dimension + for (unsigned int i=0;i max) max=_pop[j].objectiveVector()[i]; + } + amps.push_back(max-min); + mins.push_back(min); + if (max-min>amps[num_amp_max]) + num_amp_max=i; + } + Type amp_max=amps[num_amp_max]; + for (unsigned int i=0;i coefs; + if(!max_param){ +// std::cout<<"ampmax="< +class QuadTreeNode{ +public: + QuadTreeNode(ObjectiveVector& _objVec):objVec(_objVec),subTree(){} + + QuadTreeNode(const QuadTreeNode& _source):objVec(_source.objVec),subTree(_source.subTree){} + + QuadTreeNode& operator=(const QuadTreeNode& _src){ + (*this).objVec=_src.objVec; + (*this).subTree=subTree; + return *this; + } + + ObjectiveVector& getVec(){ + return objVec; + } + + bool setChild(unsigned int _kSuccesor, QuadTreeNode* _child){ + bool res = false; + if((*this).subTree[_kSuccesor] != NULL) + res=true; + else{ + (*this).subTree[_kSuccesor]= _child; + std::cout <<"setChild: " << getVec() << std::endl; + } + return res; + } + + std::map*>& getSubTree(){ + return (*this).subTree; + } + +private: + ObjectiveVector& objVec; + std::map*> subTree; +}; + + + +template < class ObjectiveVector > +class moeoQuadTree{ +public: + moeoQuadTree():root(NULL){ + bound=pow(2,ObjectiveVector::nObjectives())-1; + } + + bool insert(ObjectiveVector& _obj){ + bool res=false; + bool stop=false; + QuadTreeNode* tmp = new QuadTreeNode(_obj); + QuadTreeNode* realroot = root; + //the tree is empty -> create a node and fix it at the root + if(isEmpty()){ + root=tmp; + res=true; + std::cout << "insert case empty: " << root->getVec() << std::endl; + } + else{ + while(!stop){ + //calulate the k-Successor de _obj wtih respect to the root + unsigned int succ=k_succ(_obj, root->getVec()); + if(succ != bound){ + if(succ == 0){ + replace(_obj); + res=true; + } + else{ + //dominance test1 + typename std::map*>::iterator it=root->getSubTree().begin(); + while(!stop && (it != root->getSubTree().end())){ + if( ((*it).first < succ) && (((succ ^ bound) & ((*it).first ^ bound))== succ) ){ + stop = test1(tmp, (*it).second); + } + it++; + } + if(!stop){ + //dominance test2 + typename std::map*>::iterator it=root->getSubTree().begin(); + while(it != root->getSubTree().end()){ + if( (succ < (*it).first) && ((succ & (*it).first) == succ)){ + test2(tmp, (*it).second, root, (*it).first); + } + it++; + } + //insertion + QuadTreeNode* tmp = new QuadTreeNode(_obj); + std::cout << "insert case new son: " << root->getVec() << std::endl; + if(root->setChild(succ, tmp)){ + root=root->getSubTree()[succ]; + } + else{ + res=true; + stop=true; + } + } + } + } + } + } + root=realroot; + return res; + } + + /* + * return the k-successor of _objVec1 with respect to _objVec2 + * @param _objVec1 + * @param _objVec2 + */ + unsigned int k_succ(const ObjectiveVector& _objVec1, const ObjectiveVector& _objVec2){ + unsigned int res=0; + for(int i=0; i < ObjectiveVector::nObjectives(); i++){ + if( (ObjectiveVector::minimizing(i) && ((_objVec1[i] - _objVec2[i]) >= (-1.0 * 1e-6 ))) || + (ObjectiveVector::maximizing(i) && ((_objVec1[i] - _objVec2[i]) <= 1e-6 ))){ + res+=pow(2,ObjectiveVector::nObjectives()-i-1); + } + } + return res; + } + + /* + * replace the old root by the new one + * @param _newroot + */ + void replace(ObjectiveVector _newroot){ + //create the new root + QuadTreeNode* newroot = new QuadTreeNode(_newroot); + //reconsider each son of the old root + if(!(root->getSubTree().empty())){ + typename std::map*>::iterator it; + for(it=(root->getSubTree()).begin(); it != (root->getSubTree()).end(); it++){ + std::cout << "replace: " << (*it).second->getVec() << std::endl; + reconsider(newroot, (*it).second); + } + } + //replace the old root by the new one + delete(root); + root = newroot; + } + + void reconsider(QuadTreeNode* _newroot, QuadTreeNode* _child){ + unsigned int succ; + std::cout << "reconsider: " << _child->getVec() << std::endl; + if(!(_child->getSubTree().empty())){ + std::cout << "enter reconsider" << std::endl; + typename std::map*>::iterator it; + for(it=(_child->getSubTree()).begin(); it != (_child->getSubTree()).end(); it++){ + std::cout << "reconsider: " << (*it).second->getVec() << std::endl; + QuadTreeNode* tmp=(*it).second; + _child->getSubTree().erase(it); + reconsider(_newroot, tmp); + } + } + else{ + std::cout << "reconsider: no more child" << std::endl; + } + succ=k_succ(_child->getVec(),_newroot->getVec()); + if(succ==bound) + delete(_child); + else if(_newroot->getSubTree()[succ] != NULL){ + reinsert(_newroot->getSubTree()[succ],_child); + } + else{ + _newroot->setChild(succ, _child); + } + } + + void reinsert(QuadTreeNode* _node1, QuadTreeNode* _node2){ + unsigned int succ; + if(!(_node1->getSubTree().empty())){ + typename std::map*>::iterator it; + for(it=(_node1->getSubTree()).begin(); it != (_node1->getSubTree()).end(); it++){ + std::cout << "reinsert: " << (*it).second->getVec() << std::endl; + QuadTreeNode* tmp=(*it).second; + _node1->getSubTree().erase(it); + reinsert(_node1, tmp); + } + } + succ=k_succ(_node2->getVec(),_node1->getVec()); + if(_node1->getSubTree()[succ] != NULL){ + reinsert(_node1->getSubTree()[succ],_node2); + } + else{ + _node1->setChild(succ, _node2); + } + } + + void remove(QuadTreeNode* _node, QuadTreeNode* _parent, unsigned int _succ){ + unsigned int k=1; + QuadTreeNode* tmp=NULL; + _parent->getSubTree()[_succ]=NULL; + while((k < (bound -1)) && _node->getSubTree()[k]==NULL){ + k++; + } + if(_node->getSubTree()[k]!=NULL){ + tmp =_node->getSubTree()[k]; + _parent->setChild(_succ, tmp); + } + k++; + while(k < (bound -1)){ + if(_node->getSubTree()[k]!=NULL){ + reinsert(tmp ,_node->getSubTree()[k]); + } + k++; + } + delete(_node); + } + + bool test1(QuadTreeNode* _node1, QuadTreeNode* _node2){ + bool res = false; + unsigned int succ; + succ=k_succ(_node1->getVec(), _node2->getVec()); + if(succ==bound){ + res=true; + } + else{ + typename std::map*>::iterator it=_node2->getSubTree().begin(); + while(!res && (it != _node2->getSubTree().end())){ + if( ((succ ^ bound) & ((*it).first ^ bound)) == succ){ + res = res || test1(_node1, (*it).second); + } + it++; + } + } + return res; + } + + void test2(QuadTreeNode* _node1, QuadTreeNode* _node2, QuadTreeNode* _parent, unsigned int _succ){ + unsigned int succ; + succ=k_succ(_node1->getVec(), _node2->getVec()); + if(succ==0) + remove(_node2, _parent, _succ); + typename std::map*>::iterator it=_node2->getSubTree().begin(); + while(it != _node2->getSubTree().end()){ + if( (succ & (*it).first) == succ){ + test2(_node1, (*it).second, _node2, (*it).first); + } + it++; + } + } + + + + void printTree(){ +// typename std::map*>::iterator it; +// std::cout << "root: " << root->getVec() << "&" << std::endl << "childs:" << std::endl; +// for(it=(root->getSubTree()).begin(); it != (root->getSubTree()).end(); ++it) +// std::cout << (*it).second->getVec() << std::endl; + } + + bool isEmpty(){ + return root==NULL; + } + +private: + + + QuadTreeNode* root; + unsigned int bound; + std::list< QuadTreeNode > nodes; + + + +}; + + + +#endif /*MOEOQUADTREE_H_*/ diff --git a/trunk/paradiseo-moeo/test/CMakeLists.txt b/trunk/paradiseo-moeo/test/CMakeLists.txt index a33702083..d1c87b527 100644 --- a/trunk/paradiseo-moeo/test/CMakeLists.txt +++ b/trunk/paradiseo-moeo/test/CMakeLists.txt @@ -69,6 +69,8 @@ SET (TEST_LIST t-moeoFitDivBoundedArchive t-moeoDetArchiveSelect t-moeoASEEA + t-moeoEpsilonHyperboxArchive + t-moeoQuadTreeArchive ) FOREACH (test ${TEST_LIST}) diff --git a/trunk/paradiseo-moeo/test/t-moeoEpsilonHyperboxArchive.cpp b/trunk/paradiseo-moeo/test/t-moeoEpsilonHyperboxArchive.cpp new file mode 100644 index 000000000..0b90fbfa3 --- /dev/null +++ b/trunk/paradiseo-moeo/test/t-moeoEpsilonHyperboxArchive.cpp @@ -0,0 +1,158 @@ +/* +* +* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 +* (C) OPAC Team, LIFL, 2002-2007 +* +* Arnaud Liefooghe +* +* This software is governed by the CeCILL license under French law and +* abiding by the rules of distribution of free software. You can use, +* modify and/ or redistribute the software under the terms of the CeCILL +* license as circulated by CEA, CNRS and INRIA at the following URL +* "http://www.cecill.info". +* +* As a counterpart to the access to the source code and rights to copy, +* modify and redistribute granted by the license, users are provided only +* with a limited warranty and the software's author, the holder of the +* economic rights, and the successive licensors have only limited liability. +* +* In this respect, the user's attention is drawn to the risks associated +* with loading, using, modifying and/or developing or reproducing the +* software by the user in light of its specific status of free software, +* that may mean that it is complicated to manipulate, and that also +* therefore means that it is reserved for developers and experienced +* professionals having in-depth computer knowledge. Users are therefore +* encouraged to load and test the software's suitability as regards their +* requirements in conditions enabling the security of their systems and/or +* data to be ensured and, more generally, to use and operate it in the +* same conditions as regards security. +* The fact that you are presently reading this means that you have had +* knowledge of the CeCILL license and that you accept its terms. +* +* ParadisEO WebSite : http://paradiseo.gforge.inria.fr +* Contact: paradiseo-help@lists.gforge.inria.fr +* +*/ +//----------------------------------------------------------------------------- +// t-moeoEpsilonHyperboxArchive.cpp +//----------------------------------------------------------------------------- + +#include +#include + +//----------------------------------------------------------------------------- + +class ObjectiveVectorTraits : public moeoObjectiveVectorTraits +{ +public: + static bool minimizing (int i) + { + return true; + } + static bool maximizing (int i) + { + return false; + } + static unsigned int nObjectives () + { + return 2; + } +}; + +typedef moeoRealObjectiveVector < ObjectiveVectorTraits > ObjectiveVector; + +typedef MOEO < ObjectiveVector, double, double > Solution; + +//----------------------------------------------------------------------------- + +int main() +{ + std::cout << "[moeoEpsilonHyperboxArchive]\t=>\t"; + + std::cout << std::endl; + + // objective vectors + ObjectiveVector obj; + + // population + eoPop < Solution > pop; + pop.resize(100); + + unsigned int o1=50; + unsigned int o2=50; + unsigned int o3=50; + unsigned int o4=50; + + double tmp; + + for(int i=0; i< pop.size()/2; i++){ +// tmp=rng.uniform()*100; + obj[0]=o1; + obj[1]=o2; +// obj[0]=tmp; +// obj[1]=100-tmp; + pop[2*i].objectiveVector(obj); + obj[0]=o3; + obj[1]=o4; +// tmp=rng.uniform()*100; +// obj[0]=tmp; +// obj[1]=100-tmp; + pop[2*i + 1].objectiveVector(obj); + o1++; + o2--; + o3--; + o4++; + } +// pop.resize(4); +// obj[0]=0; +// obj[1]=100; +// pop[0].objectiveVector(obj); +// obj[0]=100; +// obj[1]=0; +// pop[1].objectiveVector(obj); +// obj[0]=50; +// obj[1]=50; +// pop[2].objectiveVector(obj); +// obj[0]=49; +// obj[1]=50.5; +// pop[3].objectiveVector(obj); + + std::vector < double > epsilon; + epsilon.push_back(0.05); + epsilon.push_back(0.05); + + // archive + moeoEpsilonHyperboxArchive< Solution > arch(epsilon); + + ObjectiveVector nadir = arch.getNadir(); + ObjectiveVector ideal = arch.getIdeal(); + std::cout << "nadir: " << nadir << std::endl; + std::cout << "ideal: " << ideal << std::endl; + + for(int i=0; i +* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 +* (C) OPAC Team, LIFL, 2002-2007 +* +* Arnaud Liefooghe +* +* This software is governed by the CeCILL license under French law and +* abiding by the rules of distribution of free software. You can use, +* modify and/ or redistribute the software under the terms of the CeCILL +* license as circulated by CEA, CNRS and INRIA at the following URL +* "http://www.cecill.info". +* +* As a counterpart to the access to the source code and rights to copy, +* modify and redistribute granted by the license, users are provided only +* with a limited warranty and the software's author, the holder of the +* economic rights, and the successive licensors have only limited liability. +* +* In this respect, the user's attention is drawn to the risks associated +* with loading, using, modifying and/or developing or reproducing the +* software by the user in light of its specific status of free software, +* that may mean that it is complicated to manipulate, and that also +* therefore means that it is reserved for developers and experienced +* professionals having in-depth computer knowledge. Users are therefore +* encouraged to load and test the software's suitability as regards their +* requirements in conditions enabling the security of their systems and/or +* data to be ensured and, more generally, to use and operate it in the +* same conditions as regards security. +* The fact that you are presently reading this means that you have had +* knowledge of the CeCILL license and that you accept its terms. +* +* ParadisEO WebSite : http://paradiseo.gforge.inria.fr +* Contact: paradiseo-help@lists.gforge.inria.fr +* +*/ +//----------------------------------------------------------------------------- +// t-moeoEpsilonHyperboxArchive.cpp +//----------------------------------------------------------------------------- + +#include +#include +#include + +//----------------------------------------------------------------------------- + +class ObjectiveVectorTraits : public moeoObjectiveVectorTraits +{ +public: + static bool minimizing (int i) + { + return true; + } + static bool maximizing (int i) + { + return false; + } + static unsigned int nObjectives () + { + return 3; + } +}; + +typedef moeoRealObjectiveVector < ObjectiveVectorTraits > ObjectiveVector; + +typedef MOEO < ObjectiveVector, double, double > Solution; + + + + + +//----------------------------------------------------------------------------- + +int main() +{ + std::cout << "[moeoQuadTreeArchive]\t=>\t"; + moeoQuadTree tree; + + bool empty= tree.isEmpty(); + std::cout <<"empty? " << empty << std::endl; + ObjectiveVector obj1; + obj1[0]=2.0; + obj1[1]=2.0; + obj1[2]=2.0; + ObjectiveVector obj2; + obj2[0]=2.0; + obj2[1]=1.0; + obj2[2]=1.0; + ObjectiveVector obj3; + obj3[0]=1.0; + obj3[1]=1.0; + obj3[2]=1.0; + QuadTreeNode hop(obj1); + QuadTreeNode hop2(obj2); + QuadTreeNode hop3(obj3); +// empty = hop.getSubTree().empty(); +// std::cout <<"empty? " << empty << std::endl; +// std::vector< QuadTreeNode > nodes; +// nodes.push_back(hop); +// nodes.push_back(hop2); +// nodes.push_back(hop3); +// std::cout << nodes[1].getVec() << std::endl; + +// std::cout << "size: " << nodes.size() << std::endl; + tree.insert(obj1); + tree.insert(obj2); + tree.insert(obj2); + tree.printTree(); + + + + + std::cout << "OK" << std::endl; + return EXIT_SUCCESS; +} + +//----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-moeo/test/t-moeoUnboundedArchive.cpp b/trunk/paradiseo-moeo/test/t-moeoUnboundedArchive.cpp index 13fcf2307..5c4d8f180 100644 --- a/trunk/paradiseo-moeo/test/t-moeoUnboundedArchive.cpp +++ b/trunk/paradiseo-moeo/test/t-moeoUnboundedArchive.cpp @@ -67,7 +67,7 @@ typedef MOEO < ObjectiveVector, double, double > Solution; int main() { - std::cout << "[moeoArchive]\t=>\t"; + std::cout << "[moeoUnboundedArchive]\t=>\t"; // objective vectors ObjectiveVector obj0, obj1, obj2, obj3, obj4, obj5;