git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1617 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
3512f82858
commit
9d21c75869
10 changed files with 1413 additions and 1 deletions
278
trunk/paradiseo-moeo/src/utils/moeoObjectiveVectorNormalizer.h
Normal file
278
trunk/paradiseo-moeo/src/utils/moeoObjectiveVectorNormalizer.h
Normal file
|
|
@ -0,0 +1,278 @@
|
|||
/*
|
||||
* <moeoObjectiveVectorNormalizer.h>
|
||||
* 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 <eoPop.h>
|
||||
#include <utils/eoRealBounds.h>
|
||||
/**
|
||||
class to normalize each dimension of objectiveVectors
|
||||
*/
|
||||
template <class MOEOT>
|
||||
class moeoObjectiveVectorNormalizer
|
||||
{
|
||||
public:
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
typedef typename MOEOT::ObjectiveVector::Type Type;
|
||||
typedef typename std::vector<std::vector<Type> > 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<MOEOT> &_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<Bounds> &_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<MOEOT> &_pop, Type &max_param=100){
|
||||
Scale res;
|
||||
if (_pop.empty()) {
|
||||
std::cout<<"makeScale in moeoObjectiveVEctorNormalizer.h: pop is empty"<<std::endl;
|
||||
return res;
|
||||
}
|
||||
unsigned int dim=_pop[0].objectiveVector().nObjectives();
|
||||
std::vector<Type> amps;
|
||||
std::vector<Type> mins;
|
||||
unsigned int num_amp_max=0;
|
||||
//recherche des min et du max, par dimension
|
||||
for (unsigned int i=0;i<dim;i++){
|
||||
Type min=_pop[0].objectiveVector()[i];
|
||||
Type max=_pop[0].objectiveVector()[i];
|
||||
unsigned int pop_size=_pop.size();
|
||||
for (unsigned int j=0;j<pop_size;j++){
|
||||
if (_pop[j].objectiveVector()[i]< min) min=_pop[j].objectiveVector()[i];
|
||||
if (_pop[j].objectiveVector()[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<dim;i++){
|
||||
std::vector<Type> coefs;
|
||||
if(!max_param){
|
||||
// std::cout<<"ampmax="<<amp_max;
|
||||
if(amps[i]==0) std::cout<<"scale erronée"<<std::endl;
|
||||
coefs.push_back(amps[i]==0?1:amp_max/amps[i]);
|
||||
}
|
||||
else{
|
||||
// std::cout<<"maxparam="<<max_param;
|
||||
if(amps[i]==0) std::cout<<"scale erronée"<<std::endl;
|
||||
coefs.push_back(amps[i]==0?1:max_param/amps[i]);
|
||||
}
|
||||
|
||||
coefs.push_back(mins[i]);
|
||||
// std::cout<<"a="<<coefs[0]<<" b="<<coefs[1]<<std::endl;
|
||||
res.push_back(coefs);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
create a scale from bounds
|
||||
@param boundaries the boundaries
|
||||
@param max the maximum for returned values
|
||||
@return a scale
|
||||
*/
|
||||
static Scale make_scale_from_bounds(std::vector<Bounds> &_boundaries,Type max=100){
|
||||
Scale res;
|
||||
for (unsigned i=0;i<_boundaries.size();i++){
|
||||
std::vector<Type> coeff;
|
||||
coeff.push_back(max/(_boundaries[i].maximum()-_boundaries[i].minimum()));
|
||||
coeff.push_back(_boundaries[i].minimum());
|
||||
res.push_back(coeff);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
create a scale from bounds
|
||||
@param bounds the bounds (the same for each dimension)
|
||||
@param max the maximum for returned values
|
||||
@return a scale
|
||||
*/
|
||||
static Scale make_scale_from_bounds(Bounds &bounds,int dim,Type max=100){
|
||||
Scale res;
|
||||
for (unsigned i=0;i<dim;i++){
|
||||
std::vector<Type> coeff;
|
||||
coeff.push_back(max/(bounds.maximum()-bounds.minimum()));
|
||||
coeff.push_back(bounds.minimum());
|
||||
res.push_back(coeff);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
create a scale from a point with minimums in each dimension, and a point with ther max in each dimension
|
||||
@param best the point with all mins
|
||||
@param worst the point with all maxs
|
||||
@param max the maximum for returned values
|
||||
@return a scale
|
||||
*/
|
||||
static Scale make_scale_from_minmax(const ObjectiveVector &best, const ObjectiveVector &worst,Type max=100){
|
||||
Scale res;
|
||||
for (unsigned i=0;i<worst.nObjectives();i++){
|
||||
std::vector<Type> coeff;
|
||||
coeff.push_back(max/(worst[i]-best[i]));
|
||||
coeff.push_back(best[i]);
|
||||
res.push_back(coeff);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
/**
|
||||
* main fonction, normalize a vector. All objective returned vectors will be between 0 and max previously
|
||||
* supplied, be carefull about a possible rounding error.
|
||||
* @param _vec the vector
|
||||
* @return the normalized vector
|
||||
*/
|
||||
virtual ObjectiveVector operator()(const ObjectiveVector &_vec){
|
||||
unsigned int dim=_vec.nObjectives();
|
||||
ObjectiveVector res;
|
||||
for (unsigned int i=0;i<dim;i++){
|
||||
res[i]=(_vec[i]-scale[i][1])*scale[i][0];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
normalize a population
|
||||
@param pop the population to normalize
|
||||
@return a vector of normalized Objective vectors
|
||||
*/
|
||||
std::vector<ObjectiveVector> operator()(const eoPop<MOEOT> &pop){
|
||||
std::vector<ObjectiveVector> res;
|
||||
for (unsigned int i=0;i<pop.size();i++){
|
||||
res.push_back(operator()(pop[i].objectiveVector()));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
fast(to use, not in complexity) function to normalize a population
|
||||
@param pop the population to normalize
|
||||
@return a vector of normalized Objective vectors < max
|
||||
*/
|
||||
static std::vector<ObjectiveVector> normalize(const eoPop<MOEOT> &pop, Type &max){
|
||||
moeoObjectiveVectorNormalizer normalizer(pop,true, max);
|
||||
return normalizer(pop);
|
||||
}
|
||||
|
||||
/**
|
||||
Change the scale according to a new pop. Should be called everytime pop is updated
|
||||
@param pop population to analyse
|
||||
@param max_param the worst vector is is set to max_param
|
||||
*/
|
||||
void update_by_pop(eoPop<MOEOT> pop){
|
||||
scale=make_scale_from_pop(pop,max);
|
||||
}
|
||||
|
||||
/** change the scale with the worst point and the best point
|
||||
@param max the worst point
|
||||
@param min the best point
|
||||
*/
|
||||
void update_by_min_max(const ObjectiveVector &_min,const ObjectiveVector &_max){
|
||||
scale=make_scale_from_minmax(_min,_max,max);
|
||||
}
|
||||
|
||||
/**
|
||||
updates the scale
|
||||
@param _scale the new scale
|
||||
*/
|
||||
void update_scale(Scale _scale){
|
||||
scale=_scale;
|
||||
}
|
||||
|
||||
/**
|
||||
change the maximum returned by the normalizer (if the scale is adapted)
|
||||
@param _max the maximum returned
|
||||
*/
|
||||
void change_max(Type _max){
|
||||
for (unsigned int i=0;i<scale.size();i++){
|
||||
if (max) scale[i][0]=scale[i][0]*_max/max;
|
||||
|
||||
|
||||
}
|
||||
max=_max;
|
||||
}
|
||||
protected:
|
||||
moeoObjectiveVectorNormalizer()
|
||||
{
|
||||
}
|
||||
private:
|
||||
Scale scale;
|
||||
Type max;
|
||||
|
||||
|
||||
};
|
||||
#endif
|
||||
308
trunk/paradiseo-moeo/src/utils/moeoQuadTree.h
Normal file
308
trunk/paradiseo-moeo/src/utils/moeoQuadTree.h
Normal file
|
|
@ -0,0 +1,308 @@
|
|||
/*
|
||||
* <moeoQuadTree.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
*
|
||||
* Arnaud Liefooghe
|
||||
* Jérémie 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
|
||||
*
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEOQUADTREE_H_
|
||||
#define MOEOQUADTREE_H_
|
||||
|
||||
template < class ObjectiveVector >
|
||||
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<ObjectiveVector>* _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<unsigned int, QuadTreeNode<ObjectiveVector>*>& getSubTree(){
|
||||
return (*this).subTree;
|
||||
}
|
||||
|
||||
private:
|
||||
ObjectiveVector& objVec;
|
||||
std::map<unsigned int, QuadTreeNode<ObjectiveVector>*> 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<ObjectiveVector>* tmp = new QuadTreeNode<ObjectiveVector>(_obj);
|
||||
QuadTreeNode<ObjectiveVector>* 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<unsigned int, QuadTreeNode<ObjectiveVector>*>::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<unsigned int, QuadTreeNode<ObjectiveVector>*>::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<ObjectiveVector>* tmp = new QuadTreeNode<ObjectiveVector>(_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<ObjectiveVector>* newroot = new QuadTreeNode<ObjectiveVector>(_newroot);
|
||||
//reconsider each son of the old root
|
||||
if(!(root->getSubTree().empty())){
|
||||
typename std::map<unsigned int, QuadTreeNode<ObjectiveVector>*>::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<ObjectiveVector>* _newroot, QuadTreeNode<ObjectiveVector>* _child){
|
||||
unsigned int succ;
|
||||
std::cout << "reconsider: " << _child->getVec() << std::endl;
|
||||
if(!(_child->getSubTree().empty())){
|
||||
std::cout << "enter reconsider" << std::endl;
|
||||
typename std::map<unsigned int, QuadTreeNode<ObjectiveVector>*>::iterator it;
|
||||
for(it=(_child->getSubTree()).begin(); it != (_child->getSubTree()).end(); it++){
|
||||
std::cout << "reconsider: " << (*it).second->getVec() << std::endl;
|
||||
QuadTreeNode<ObjectiveVector>* 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<ObjectiveVector>* _node1, QuadTreeNode<ObjectiveVector>* _node2){
|
||||
unsigned int succ;
|
||||
if(!(_node1->getSubTree().empty())){
|
||||
typename std::map<unsigned int, QuadTreeNode<ObjectiveVector>*>::iterator it;
|
||||
for(it=(_node1->getSubTree()).begin(); it != (_node1->getSubTree()).end(); it++){
|
||||
std::cout << "reinsert: " << (*it).second->getVec() << std::endl;
|
||||
QuadTreeNode<ObjectiveVector>* 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<ObjectiveVector>* _node, QuadTreeNode<ObjectiveVector>* _parent, unsigned int _succ){
|
||||
unsigned int k=1;
|
||||
QuadTreeNode<ObjectiveVector>* 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<ObjectiveVector>* _node1, QuadTreeNode<ObjectiveVector>* _node2){
|
||||
bool res = false;
|
||||
unsigned int succ;
|
||||
succ=k_succ(_node1->getVec(), _node2->getVec());
|
||||
if(succ==bound){
|
||||
res=true;
|
||||
}
|
||||
else{
|
||||
typename std::map<unsigned int, QuadTreeNode<ObjectiveVector>*>::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<ObjectiveVector>* _node1, QuadTreeNode<ObjectiveVector>* _node2, QuadTreeNode<ObjectiveVector>* _parent, unsigned int _succ){
|
||||
unsigned int succ;
|
||||
succ=k_succ(_node1->getVec(), _node2->getVec());
|
||||
if(succ==0)
|
||||
remove(_node2, _parent, _succ);
|
||||
typename std::map<unsigned int, QuadTreeNode<ObjectiveVector>*>::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<unsigned int, QuadTreeNode<ObjectiveVector>*>::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<ObjectiveVector>* root;
|
||||
unsigned int bound;
|
||||
std::list< QuadTreeNode<ObjectiveVector> > nodes;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /*MOEOQUADTREE_H_*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue