new fast archive added
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1631 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
ca19a9bfc7
commit
eb763661c6
5 changed files with 544 additions and 27 deletions
83
trunk/paradiseo-moeo/src/archive/moeoArchiveIndex.h
Executable file
83
trunk/paradiseo-moeo/src/archive/moeoArchiveIndex.h
Executable file
|
|
@ -0,0 +1,83 @@
|
|||
#ifndef MOEOARCHIVEINDEX_H_
|
||||
#define MOEOARCHIVEINDEX_H_
|
||||
|
||||
#include <eoPop.h>
|
||||
#include <archive/moeoArchive.h>
|
||||
|
||||
/**
|
||||
* Inteface for Archive Indexes
|
||||
*/
|
||||
template < class MOEOT >
|
||||
class moeoArchiveIndex
|
||||
{
|
||||
|
||||
public:
|
||||
//type of MOEOT Objective vector
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
||||
/**type for a modification that will have to be applied to the archive
|
||||
* each item concern one ObjectiveVector, designated by itemObjective
|
||||
**/
|
||||
struct modif{
|
||||
public:
|
||||
//Objective vector of the concerned item
|
||||
ObjectiveVector itemObjective;
|
||||
//oldIdx is the index of the item in the vector before the modification (in the archive itself, not in the index)
|
||||
int oldIdx;
|
||||
//newIdx is the new index of the item in the vector after the modification (in the archive itself, not in the index)
|
||||
//-1 if deletion has to occur
|
||||
int newIdx;
|
||||
/**
|
||||
* ctor for a deletion
|
||||
* @param _obj the objectiveVector of the concerned entry
|
||||
* @param _oldIdx the current index of the concerned entry in the vector (before deletion)
|
||||
*/
|
||||
modif(ObjectiveVector& _obj, int _oldIdx):itemObjective(_obj),oldIdx(_oldIdx),newIdx(-1){}
|
||||
/**
|
||||
* ctor for a move
|
||||
* @param _obj the objectiveVector of the concerned entry
|
||||
* @param _oldIdx the current index of the concerned entry in the vector (before moving)
|
||||
* @param _newIdx the index of the concerned entry in the vector after moving
|
||||
**/
|
||||
modif(ObjectiveVector& _obj, int _oldIdx,int _newIdx):itemObjective(_obj),oldIdx(_oldIdx),newIdx(_newIdx){}
|
||||
};
|
||||
|
||||
/**
|
||||
* principal method for the index, add a moeot to the index
|
||||
* @param _moeot the MOEOT we try to insert
|
||||
* @param _insert should we really insert the moeot, or just check if we have to
|
||||
* @return a pair, the first is a boolean indicating if the insertion can occur, the second a vector of modification
|
||||
**/
|
||||
virtual std::pair<bool,std::vector<modif> > operator()(const MOEOT& _moeot, bool _insert=true)=0;
|
||||
|
||||
/*
|
||||
* method for adding a population of moeot to the the index
|
||||
* @param _pop the population of MOEOT we try to insert
|
||||
* @param _insert should we really insert the moeot, or just check if we have to
|
||||
* @return a pair, the first is how many moeot can be inserted, the second a vector of modification that would have to occur to insert
|
||||
*/
|
||||
// virtual std::pair<bool,std::vector<modif> > operator()(const eoPop<MOEOT>& _pop, bool _insert=true)=0;
|
||||
|
||||
/**
|
||||
* when updates will be necessary to keep indexes of archive and index synced, the archive will launch this method
|
||||
* @param _update the update to do, see modif documentation
|
||||
* @return false if no problem occured
|
||||
*/
|
||||
virtual bool update( modif& _update)=0;
|
||||
|
||||
/**
|
||||
* creates a modif that move the item ObjectiveVector placed at idx oldIdx in the archive to newIdx, or delete it if newIdx=-1
|
||||
* @param _obj the objectiveVector we want to move
|
||||
* @param _oldIdx the index of the item we want to move in the vector
|
||||
* @param _newIdx the new index for the item, -1 if we want it deleted
|
||||
**/
|
||||
static modif make_modif(ObjectiveVector &_obj,int _oldIdx,int _newIdx=-1){
|
||||
modif res(_obj,_oldIdx,_newIdx);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEOARCHIVEINDEX_H_*/
|
||||
111
trunk/paradiseo-moeo/src/archive/moeoIndexedArchive.h
Executable file
111
trunk/paradiseo-moeo/src/archive/moeoIndexedArchive.h
Executable file
|
|
@ -0,0 +1,111 @@
|
|||
#ifndef MOEOINDEXEDARCHIVE_H_
|
||||
#define MOEOINDEXEDARCHIVE_H_
|
||||
|
||||
#include <eoPop.h>
|
||||
#include <archive/moeoArchive.h>
|
||||
#include <archive/moeoArchiveIndex.h>
|
||||
|
||||
/**
|
||||
* Archive used for 2 dimension vectors which remove pareto dominated values
|
||||
* Use an moeoArchiveIndex
|
||||
*/
|
||||
template < class MOEOT >
|
||||
class moeoIndexedArchive : public moeoArchive < MOEOT >
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
|
||||
using eoPop < MOEOT > :: size;
|
||||
using eoPop < MOEOT > :: operator[];
|
||||
using eoPop < MOEOT > :: pop_back;
|
||||
|
||||
/**
|
||||
* The type of an objective vector for a solution
|
||||
*/
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
||||
/**
|
||||
* Default ctor.
|
||||
* The moeoObjectiveVectorComparator used to compare solutions is based on Pareto dominance
|
||||
*/
|
||||
moeoIndexedArchive(moeoArchiveIndex<MOEOT>& _index) : index(_index) {}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the archive with a given individual _moeo
|
||||
* @param _moeo the given individual
|
||||
*/
|
||||
bool operator()(const MOEOT & _moeo){
|
||||
bool added=false;
|
||||
std::pair<bool,std::vector<typename moeoArchiveIndex<MOEOT>::modif> > res=index(_moeo);
|
||||
if (!(res.first)){
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
for (unsigned int i=0;i<res.second.size();i++){
|
||||
apply_modif(res.second[i]);
|
||||
}
|
||||
push_back(_moeo);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the archive with a given population _pop
|
||||
* @param _pop the given population
|
||||
*/
|
||||
bool operator()(const eoPop < MOEOT > & _pop)
|
||||
{
|
||||
bool res=false;
|
||||
for (unsigned int i=0;i<_pop.size();i++){
|
||||
res=operator()(_pop[i])||res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* apply a modification
|
||||
* @param _modif the modification to apply
|
||||
**/
|
||||
void apply_modif(typename moeoArchiveIndex<MOEOT>::modif &_modif){
|
||||
if (_modif.newIdx==-1){
|
||||
int oldIdx=size()-1;
|
||||
(*this)[_modif.oldIdx]=(*this)[size()-1];
|
||||
ObjectiveVector obj=(*this)[_modif.oldIdx].objectiveVector();
|
||||
typename moeoArchiveIndex<MOEOT>::modif upd(obj,oldIdx,_modif.oldIdx);
|
||||
index.update(upd);
|
||||
pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
//not used yet...
|
||||
void apply_modif(std::vector<typename moeoArchiveIndex<MOEOT>::modif> &_modifs){
|
||||
unsigned int num_to_delete=0;
|
||||
for (unsigned int i=0;i<_modifs.size();i++){
|
||||
if (_modifs[i].newIdx==-1){
|
||||
num_to_delete++;
|
||||
int oldIdx=size()-1;
|
||||
(*this)[_modifs[i].oldIdx]=(*this)[size()-1];
|
||||
ObjectiveVector obj=(*this)[_modifs[i].oldIdx].objectiveVector();
|
||||
typename moeoArchiveIndex<MOEOT>::modif upd(obj,oldIdx,_modifs[i].oldIdx);
|
||||
index.update(upd);
|
||||
}
|
||||
}
|
||||
for (unsigned int i=0;i<num_to_delete;i++)
|
||||
pop_back();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
moeoArchiveIndex<MOEOT> &index;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEOINDEXEDARCHIVE_H_*/
|
||||
135
trunk/paradiseo-moeo/src/utils/moeoQuadTree.h → trunk/paradiseo-moeo/src/archive/moeoQuadTree.h
Normal file → Executable file
135
trunk/paradiseo-moeo/src/utils/moeoQuadTree.h → trunk/paradiseo-moeo/src/archive/moeoQuadTree.h
Normal file → Executable file
|
|
@ -40,10 +40,12 @@
|
|||
#define MOEOQUADTREE_H_
|
||||
|
||||
#include <comparator/moeoParetoObjectiveVectorComparator.h>
|
||||
|
||||
#include <archive/moeoArchiveIndex.h>
|
||||
template < class ObjectiveVector >
|
||||
class QuadTreeNode{
|
||||
public:
|
||||
|
||||
|
||||
QuadTreeNode(ObjectiveVector& _objVec):objVec(_objVec),subTree(){}
|
||||
|
||||
QuadTreeNode(const QuadTreeNode& _source):objVec(_source.objVec),subTree(_source.subTree){}
|
||||
|
|
@ -51,6 +53,8 @@ public:
|
|||
QuadTreeNode& operator=(const QuadTreeNode& _src){
|
||||
(*this).objVec=_src.objVec;
|
||||
(*this).subTree=subTree;
|
||||
(*this).inserted=_src.is_inserted();
|
||||
if(inserted) (*this).index=_src.get_index();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -72,25 +76,42 @@ public:
|
|||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
std::map<unsigned int, QuadTreeNode<ObjectiveVector>*>& getSubTree(){
|
||||
return (*this).subTree;
|
||||
}
|
||||
|
||||
void set_index(int idx){
|
||||
inserted=true;
|
||||
index=idx;
|
||||
}
|
||||
unsigned int get_index(){
|
||||
if (!inserted) std::cerr<<"moeoQuadTree getting index of a non-inserted node"<<std::endl;
|
||||
return index;
|
||||
}
|
||||
bool is_inserted(){
|
||||
return inserted;
|
||||
}
|
||||
|
||||
private:
|
||||
ObjectiveVector objVec;
|
||||
std::map<unsigned int, QuadTreeNode<ObjectiveVector>*> subTree;
|
||||
|
||||
//TODO Ajouter l'index du vecteur
|
||||
unsigned int index;
|
||||
bool inserted;
|
||||
};
|
||||
|
||||
|
||||
|
||||
template < class ObjectiveVector >
|
||||
class moeoQuadTree{
|
||||
template < class MOEOT >
|
||||
class moeoQuadTree : public moeoArchiveIndex<MOEOT> {
|
||||
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
typedef typename std::map<unsigned int, QuadTreeNode<ObjectiveVector>*>::iterator QuadTreeIterator;
|
||||
typedef typename moeoArchiveIndex<MOEOT>::modif modif;
|
||||
public:
|
||||
moeoQuadTree():root(NULL){
|
||||
moeoQuadTree():root(NULL),current_size(0){
|
||||
bound=pow(2,ObjectiveVector::nObjectives())-1;
|
||||
comparator=new moeoParetoObjectiveVectorComparator<ObjectiveVector>();
|
||||
}
|
||||
|
|
@ -99,24 +120,50 @@ public:
|
|||
delete(comparator);
|
||||
}
|
||||
|
||||
/**
|
||||
* insert a _moeot in the index if it can be inserted
|
||||
* @param @_moeot the individual ton insert
|
||||
* @param _insert not used, should be changed...
|
||||
*/
|
||||
std::pair<bool,std::vector<modif> > operator()(const MOEOT& _moeot, bool _insert=true){
|
||||
std::pair<bool,std::vector<modif> > res;
|
||||
insert(_moeot.objectiveVector(),res);
|
||||
if (res.first){
|
||||
current_size=current_size+1-res.second.size();
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* apply the modif
|
||||
* @param _update the modif to apply (move only)
|
||||
* @return false if no problem occured
|
||||
**/
|
||||
bool update( modif& _update){
|
||||
QuadTreeNode<ObjectiveVector>* node=find_node(_update.itemObjective,getRoot());
|
||||
if (node==NULL) return true;
|
||||
node->set_index(_update.newIdx);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @paramm _obj the Objective Vector to insert into the tree.
|
||||
* @return true if it is inserted
|
||||
*/
|
||||
bool insert(ObjectiveVector& _obj){
|
||||
bool res=false;
|
||||
void insert(ObjectiveVector _obj, std::pair<bool, std::vector<modif> > &res){
|
||||
//create a new node
|
||||
QuadTreeNode<ObjectiveVector>* tmp = new QuadTreeNode<ObjectiveVector>(_obj);
|
||||
//if the tree is empty, we have a new root!
|
||||
if(isEmpty()){
|
||||
root=tmp;
|
||||
res=true;
|
||||
tmp->set_index(0);
|
||||
res.first=true;
|
||||
}
|
||||
//else try to insert the new node in the tree
|
||||
else{
|
||||
res = insert_aux(tmp, root, NULL, 0);
|
||||
res.first = insert_aux(tmp, root, NULL, 0, res.second);
|
||||
if(res.first) tmp->set_index(size()-1);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -126,7 +173,7 @@ public:
|
|||
* @param _succ the index of _parent where the _tmproot is linked
|
||||
* @return true if the _newnode is inserted
|
||||
*/
|
||||
bool insert_aux(QuadTreeNode<ObjectiveVector>* _newnode, QuadTreeNode<ObjectiveVector>* _tmproot, QuadTreeNode<ObjectiveVector>* _parent, unsigned int _succ){
|
||||
bool insert_aux(QuadTreeNode<ObjectiveVector>* _newnode, QuadTreeNode<ObjectiveVector>* _tmproot, QuadTreeNode<ObjectiveVector>* _parent, unsigned int _succ, std::vector<modif> &modifs){
|
||||
bool res=false;
|
||||
bool dominated=false;
|
||||
|
||||
|
|
@ -137,7 +184,7 @@ public:
|
|||
}
|
||||
else if(succ==0){
|
||||
//_newnode dominates _tmproot
|
||||
replace(_newnode, _tmproot, _parent, _succ);
|
||||
replace(_newnode, _tmproot, _parent, _succ, modifs);
|
||||
res=true;
|
||||
}
|
||||
else{
|
||||
|
|
@ -163,7 +210,7 @@ public:
|
|||
while(it != _tmproot->getSubTree().end()){
|
||||
if((*it).second != NULL){
|
||||
if( (succ < (*it).first) && ((succ & (*it).first) == succ)){
|
||||
test2(_newnode, (*it).second, _tmproot, (*it).first);
|
||||
test2(_newnode, (*it).second, _tmproot, (*it).first, modifs);
|
||||
}
|
||||
}
|
||||
it++;
|
||||
|
|
@ -176,7 +223,7 @@ public:
|
|||
}
|
||||
else{
|
||||
//else if the child is not inserted, insert it in the subtree
|
||||
res=insert_aux(_newnode, _tmproot->getSubTree()[succ], _tmproot, succ);
|
||||
res=insert_aux(_newnode, _tmproot->getSubTree()[succ], _tmproot, succ , modifs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -208,13 +255,13 @@ public:
|
|||
* @param _parent the parent of _tmproot
|
||||
* @param _succ the index of _parent where the _tmproot is linked
|
||||
*/
|
||||
void replace(QuadTreeNode<ObjectiveVector>* _newnode, QuadTreeNode<ObjectiveVector>* _tmproot, QuadTreeNode<ObjectiveVector>* _parent, unsigned int _succ){
|
||||
void replace(QuadTreeNode<ObjectiveVector>* _newnode, QuadTreeNode<ObjectiveVector>* _tmproot, QuadTreeNode<ObjectiveVector>* _parent, unsigned int _succ, std::vector<modif> & res){
|
||||
if(!(_tmproot->getSubTree().empty())){
|
||||
//reconsider each son of the old root
|
||||
QuadTreeIterator it;
|
||||
for(it=(_tmproot->getSubTree()).begin(); it != (_tmproot->getSubTree()).end(); it++){
|
||||
if((*it).second!=NULL){
|
||||
reconsider(_newnode, (*it).second);
|
||||
reconsider(_newnode, (*it).second, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -226,6 +273,8 @@ public:
|
|||
_parent->getSubTree()[_succ]=_newnode;
|
||||
}
|
||||
//kill the old root
|
||||
modif new_modif(_tmproot->getVec(),_tmproot->get_index());
|
||||
res.push_back(new_modif);
|
||||
delete(_tmproot);
|
||||
}
|
||||
|
||||
|
|
@ -233,7 +282,7 @@ public:
|
|||
* @param _newroot the new root
|
||||
* @param _child a node to reconsider regarding tthe _newroot
|
||||
*/
|
||||
void reconsider(QuadTreeNode<ObjectiveVector>* _newroot, QuadTreeNode<ObjectiveVector>* _child){
|
||||
void reconsider(QuadTreeNode<ObjectiveVector>* _newroot, QuadTreeNode<ObjectiveVector>* _child, std::vector<modif> & res){
|
||||
unsigned int succ;
|
||||
//reconsider all child of _child
|
||||
if(!(_child->getSubTree().empty())){
|
||||
|
|
@ -242,14 +291,17 @@ public:
|
|||
if((*it).second != NULL){
|
||||
QuadTreeNode<ObjectiveVector>* tmp=(*it).second;
|
||||
_child->getSubTree()[(*it).first]=NULL;
|
||||
reconsider(_newroot, tmp);
|
||||
reconsider(_newroot, tmp, res );
|
||||
}
|
||||
}
|
||||
}
|
||||
succ=k_succ(_child->getVec(),_newroot->getVec());
|
||||
//if _child is dominated by the newroot, delete it
|
||||
if(succ==bound)
|
||||
if(succ==bound){
|
||||
modif new_modif(_child->getVec(),_child->get_index());
|
||||
res.push_back(new_modif);
|
||||
delete(_child);
|
||||
}
|
||||
//else reinsert it in the tree rooted at _newroot
|
||||
else if(_newroot->getSubTree()[succ] != NULL){
|
||||
reinsert(_newroot->getSubTree()[succ],_child);
|
||||
|
|
@ -295,7 +347,7 @@ public:
|
|||
* @param _parent its parent
|
||||
* @param _succ the index of _parent where the _node is linked
|
||||
*/
|
||||
void remove(QuadTreeNode<ObjectiveVector>* _node, QuadTreeNode<ObjectiveVector>* _parent, unsigned int _succ){
|
||||
void remove(QuadTreeNode<ObjectiveVector>* _node, QuadTreeNode<ObjectiveVector>* _parent, unsigned int _succ, std::vector<modif> & res){
|
||||
unsigned int k=1;
|
||||
QuadTreeNode<ObjectiveVector>* tmp=NULL;
|
||||
_parent->getSubTree()[_succ]=NULL;
|
||||
|
|
@ -313,6 +365,8 @@ public:
|
|||
}
|
||||
k++;
|
||||
}
|
||||
modif new_modif(_node->getVec(),_node->get_index());
|
||||
res.push_back(new_modif);
|
||||
delete(_node);
|
||||
}
|
||||
|
||||
|
|
@ -347,21 +401,21 @@ public:
|
|||
* @param _node1 first node
|
||||
* @param _node2 second node
|
||||
*/
|
||||
void test2(QuadTreeNode<ObjectiveVector>* _node1, QuadTreeNode<ObjectiveVector>* _node2, QuadTreeNode<ObjectiveVector>* _parent, unsigned int _succ){
|
||||
void test2(QuadTreeNode<ObjectiveVector>* _node1, QuadTreeNode<ObjectiveVector>* _node2, QuadTreeNode<ObjectiveVector>* _parent, unsigned int _succ, std::vector<modif> & res){
|
||||
|
||||
unsigned int succ;
|
||||
succ=k_succ(_node1->getVec(), _node2->getVec());
|
||||
if(succ==0){
|
||||
remove(_node2, _parent, _succ);
|
||||
remove(_node2, _parent, _succ, res);
|
||||
if(_parent->getSubTree()[_succ]!=NULL)
|
||||
test2(_node1, _parent->getSubTree()[_succ], _parent, _succ);
|
||||
test2(_node1, _parent->getSubTree()[_succ], _parent, _succ, res);
|
||||
}
|
||||
else{
|
||||
QuadTreeIterator it=_node2->getSubTree().begin();
|
||||
while(it != _node2->getSubTree().end()){
|
||||
if((*it).second!=NULL){
|
||||
if( (succ & (*it).first) == succ){
|
||||
test2(_node1, (*it).second, _node2, (*it).first);
|
||||
test2(_node1, (*it).second, _node2, (*it).first, res);
|
||||
}
|
||||
}
|
||||
it++;
|
||||
|
|
@ -423,9 +477,37 @@ public:
|
|||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* the number of individual currently indexed
|
||||
* @return the tree size
|
||||
*/
|
||||
unsigned int size(){
|
||||
return current_size;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* to find a node from his objectiveVector
|
||||
* @param _obj the objective to find
|
||||
* @param current the node in which we are looking (to be able to recurse)
|
||||
* @return the node with obj as objectiveVector, or null if it's not found
|
||||
*/
|
||||
QuadTreeNode<ObjectiveVector>* find_node(ObjectiveVector &_obj, QuadTreeNode<ObjectiveVector>* current){
|
||||
if (current->getVec()==_obj) return current;
|
||||
else{
|
||||
int succ=k_succ(current->getVec(),_obj);
|
||||
if(current->getSubTree()[succ]!=NULL)
|
||||
return find_node(_obj,current->getSubTree()[succ]);
|
||||
else{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//pointer on the root of the tree
|
||||
QuadTreeNode<ObjectiveVector>* root;
|
||||
|
||||
|
|
@ -435,6 +517,9 @@ private:
|
|||
//Pareto comparator
|
||||
moeoParetoObjectiveVectorComparator<ObjectiveVector>* comparator;
|
||||
|
||||
//current tree size
|
||||
int current_size;
|
||||
|
||||
};
|
||||
|
||||
|
||||
235
trunk/paradiseo-moeo/src/archive/moeoQuickUnboundedArchiveIndex.h
Executable file
235
trunk/paradiseo-moeo/src/archive/moeoQuickUnboundedArchiveIndex.h
Executable file
|
|
@ -0,0 +1,235 @@
|
|||
#ifndef MOEOQUICKUNBOUNDEDARCHIVEINDEX_H_
|
||||
#define MOEOQUICKUNBOUNDEDARCHIVEINDEX_H_
|
||||
|
||||
#include <eoPop.h>
|
||||
#include <archive/moeoArchive.h>
|
||||
#include <comparator/moeoObjectiveVectorComparator.h>
|
||||
#include <comparator/moeoParetoObjectiveVectorComparator.h>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
/**
|
||||
* Archive used for 2 dimension vectors which remove pareto dominated values
|
||||
* the index is ordered following the first objective
|
||||
*/
|
||||
template < class MOEOT >
|
||||
class moeoQuickUnboundedArchiveIndex : public moeoArchiveIndex < MOEOT >
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The type of an objective vector for a solution
|
||||
*/
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
typedef typename moeoArchiveIndex<MOEOT>::modif modif;
|
||||
// typedef typename moeoArchiveIndex < MOEOT> :: s_update s_update;
|
||||
|
||||
/**
|
||||
* Default ctor. Pareto !!!!
|
||||
* The moeoObjectiveVectorComparator used to compare solutions is based on Pareto dominance
|
||||
*/
|
||||
moeoQuickUnboundedArchiveIndex() : index() {}
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
* @param _comparator the moeoObjectiveVectorComparator used to compare solutions
|
||||
*/
|
||||
//moeoQuickUnboundedArchive(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator) : moeoArchive < MOEOT >(_comparator),index() {}
|
||||
|
||||
/**struct for an entry of the index
|
||||
* obj is the objective vector of the vector[indice]
|
||||
*/
|
||||
struct entree{
|
||||
entree(ObjectiveVector _obj, int _indice):obj(_obj),indice(_indice){}
|
||||
bool operator == (const entree a){
|
||||
return obj==a.obj;
|
||||
}
|
||||
ObjectiveVector obj;
|
||||
int indice;
|
||||
};
|
||||
/**
|
||||
* equivalent to "number one element should be on top of number two element" in the list by looking to the first obj
|
||||
*/
|
||||
struct CompareByFirst
|
||||
: std::binary_function< bool, entree, entree > {
|
||||
bool operator ()(
|
||||
const entree& elem1,
|
||||
const entree& elem2
|
||||
) const {
|
||||
if (ObjectiveVector::minimizing(0)){
|
||||
return elem1.obj[0] > elem2.obj[0];
|
||||
}
|
||||
else{
|
||||
return elem1.obj[0] < elem2.obj[0];
|
||||
}
|
||||
}
|
||||
}cbf;
|
||||
/**
|
||||
* equivalent to "number one element should be on top of number two element" in the list by looking to the 2nd obj
|
||||
*/
|
||||
struct CompareByLast
|
||||
: std::binary_function< bool, entree, entree > {
|
||||
bool operator ()(
|
||||
const entree& elem1,
|
||||
const entree& elem2
|
||||
) const {
|
||||
if (ObjectiveVector::minimizing(1)){
|
||||
return elem1.obj[1] < elem2.obj[1];
|
||||
}
|
||||
else{
|
||||
return elem1.obj[1] > elem2.obj[1];
|
||||
}
|
||||
}
|
||||
}cbl;
|
||||
|
||||
|
||||
struct CompareByLast2
|
||||
: std::binary_function< bool, MOEOT, MOEOT > {
|
||||
bool operator ()(
|
||||
const MOEOT& elem1,
|
||||
const MOEOT& elem2
|
||||
) const {
|
||||
if (ObjectiveVector::minimizing(1)){
|
||||
return elem1.objectiveVector()[1] < elem2.objectiveVector()[1];
|
||||
}
|
||||
else{
|
||||
return elem1.objectiveVector()[1] > elem2.objectiveVector()[1];
|
||||
}
|
||||
}
|
||||
}cbl2;
|
||||
/**
|
||||
* type for the index
|
||||
*/
|
||||
typedef typename std::set<entree,CompareByLast> MOEOTIndex;
|
||||
/**
|
||||
* iterator from the index
|
||||
*/
|
||||
typedef typename std::set<entree,CompareByLast>::iterator MOEOTIndexIte;
|
||||
/**
|
||||
* iterator for gcc stop being annoying
|
||||
*/
|
||||
typedef typename std::set<MOEOT>::iterator set_ite;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
updates the index following a modif
|
||||
@param _update the modification to apply
|
||||
@return false
|
||||
*/
|
||||
bool update(modif& _update){
|
||||
entree oldEnt(_update.itemObjective,_update.oldIdx);
|
||||
entree newEnt(_update.itemObjective,_update.newIdx);
|
||||
index.erase(oldEnt);
|
||||
index.insert(newEnt);
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
std::pair<bool,std::vector<modif> > operator()(const eoPop<MOEOT>& _pop, bool _insert=true){
|
||||
std::cout<<"OH, HI, je fais quelque chose"<<std::endl;
|
||||
std::pair < bool, std::vector<modif> > res;
|
||||
res.first=false;
|
||||
std::vector <modif> tmp;
|
||||
for (unsigned int i=0;i<_pop.size();i++){
|
||||
std::cout<<"once va être créé"<<std::endl;
|
||||
std::pair<bool,std::vector<modif> > once=operator()(_pop[i],_insert);
|
||||
if (once.first){
|
||||
std::cout<<"once vrai taille "<<once.second.size()<<std::endl;
|
||||
std::copy(once.second.begin(),once.second.end(),res.second.end());
|
||||
res.first=true;
|
||||
}
|
||||
|
||||
}
|
||||
return res;
|
||||
};
|
||||
*/
|
||||
|
||||
virtual std::pair<bool,std::vector<modif> > operator()(const MOEOT& _moeo, bool _insert=true){
|
||||
return insert(_moeo,_insert);
|
||||
}
|
||||
/**
|
||||
* inserts a _moeo in the index
|
||||
* @param _moeo the MOEOT to insert
|
||||
* @param _insert if _insert is false we only ask the index, and dont modify it
|
||||
* @return a pair composed by a boolean indicating if the moeot can be inserted, and a list of modif to do so
|
||||
*/
|
||||
virtual std::pair<bool,std::vector<modif> > insert(const MOEOT& _moeo, bool _insert=true){
|
||||
// std::cout<<"entree dans l'algo avec "<<_moeo.objectiveVector()<<std::endl;
|
||||
MOEOTIndexIte it,it2,it4;
|
||||
std::pair<bool,std::vector<modif> > res;
|
||||
std::vector<entree> to_er;
|
||||
res.first=false;
|
||||
if (index.empty()){
|
||||
std::cout<<"empty donc ok"<<std::endl;
|
||||
if (_insert)
|
||||
index.insert(entree(_moeo.objectiveVector(),index.size()));
|
||||
res.first=true;
|
||||
return res;
|
||||
}
|
||||
it=index.lower_bound(entree(_moeo.objectiveVector(),-1));
|
||||
if (it==index.end()) {
|
||||
it--;
|
||||
if (!comparator(_moeo.objectiveVector(),(*it).obj)){
|
||||
std::cout<<"fin et ok"<<std::endl;
|
||||
if (_insert)
|
||||
index.insert(entree(_moeo.objectiveVector(),index.size()));
|
||||
res.first=true;
|
||||
}else {
|
||||
std::cout<<"fin et ko"<<std::endl;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
if ((_moeo.objectiveVector()==(*it).obj) or (comparator(_moeo.objectiveVector(),(*it).obj))){
|
||||
std::cout<<"middle ko bas"<<std::endl;
|
||||
return res;
|
||||
}
|
||||
if (it!=index.begin()){
|
||||
it2=it;
|
||||
it2--;
|
||||
if (comparator(_moeo.objectiveVector(),(*it2).obj)){
|
||||
std::cout<<"middle ko haut"<<std::endl;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
it2=it;
|
||||
while (it2!=index.end() && comparator((*it2).obj,_moeo.objectiveVector())){
|
||||
it2++;
|
||||
}
|
||||
for (it4=it;it4!=it2;it4++){
|
||||
std::cout<<"ajout d'un truc à del"<<std::endl;
|
||||
ObjectiveVector cpy=(*it4).obj;
|
||||
int cpy_idx=(*it4).indice;
|
||||
modif new_modif(cpy,cpy_idx);
|
||||
res.second.push_back(new_modif);
|
||||
to_er.push_back(*it4);
|
||||
}
|
||||
if (_insert){
|
||||
for (unsigned int i=0;i<to_er.size();i++){
|
||||
index.erase(to_er[i]);
|
||||
}
|
||||
index.insert(entree(_moeo.objectiveVector(),index.size()));
|
||||
}
|
||||
res.first=true;
|
||||
std::cout<<"sortie avec insertion"<<std::endl;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
private:
|
||||
MOEOTIndex index;
|
||||
moeoParetoObjectiveVectorComparator<ObjectiveVector> comparator;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEOQUICKUNBOUNDEDARCHIVE_H_*/
|
||||
|
|
@ -61,14 +61,17 @@
|
|||
|
||||
|
||||
#include <archive/moeoArchive.h>
|
||||
#include <archive/moeoArchiveIndex.h>
|
||||
#include <archive/moeoBoundedArchive.h>
|
||||
#include <archive/moeoFixedSizeArchive.h>
|
||||
#include <archive/moeoIndexedArchive.h>
|
||||
#include <archive/moeoSPEA2Archive.h>
|
||||
#include <archive/moeoUnboundedArchive.h>
|
||||
#include <archive/moeoImprOnlyBoundedArchive.h>
|
||||
#include <archive/moeoFitDivBoundedArchive.h>
|
||||
//#include <archive/moeoEpsilonHyperboxArchive.h>
|
||||
#include <archive/moeoQuadTreeArchive.h>
|
||||
#include <archive/moeoQuadTree.h>
|
||||
#include <archive/moeoQuickUnboundedArchiveIndex.h>
|
||||
|
||||
|
||||
#include <comparator/moeoAggregativeComparator.h>
|
||||
|
|
@ -84,6 +87,7 @@
|
|||
#include <comparator/moeoPtrComparator.h>
|
||||
#include <comparator/moeoStrictObjectiveVectorComparator.h>
|
||||
#include <comparator/moeoWeakObjectiveVectorComparator.h>
|
||||
#include <comparator/moeoFitnessComparator.h>
|
||||
|
||||
#include <core/MOEO.h>
|
||||
#include <core/moeoBitVector.h>
|
||||
|
|
@ -174,7 +178,6 @@
|
|||
#include <utils/moeoConvertPopToObjectiveVectors.h>
|
||||
#include <utils/moeoDominanceMatrix.h>
|
||||
#include <utils/moeoObjVecStat.h>
|
||||
#include <utils/moeoQuadTree.h>
|
||||
#include <utils/moeoAnytimeWeightStrategy.h>
|
||||
#include <utils/moeoDummyRefPointStrategy.h>
|
||||
#include <utils/moeoDummyWeightStrategy.h>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue