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
419
trunk/paradiseo-moeo/src/archive/moeoEpsilonHyperboxArchive.h
Normal file
419
trunk/paradiseo-moeo/src/archive/moeoEpsilonHyperboxArchive.h
Normal file
|
|
@ -0,0 +1,419 @@
|
|||
/*
|
||||
* <moeoEpsilonHyperboxArchive.h>
|
||||
* 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 <eoPop.h>
|
||||
#include <comparator/moeoComparator.h>
|
||||
#include <comparator/moeoObjectiveVectorComparator.h>
|
||||
#include <distance/moeoEuclideanDistance.h>
|
||||
#include <utils/moeoObjectiveVectorNormalizer.h>
|
||||
#include <utils/eoRealBounds.h>
|
||||
|
||||
/**
|
||||
* 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<double> _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<double> _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<size())){
|
||||
same = true;
|
||||
//calculate the hyperbox corner of the ieme element of the archive
|
||||
tmp=hyperbox(operator[](i));
|
||||
|
||||
//CASE 1: _moeo epsilon-domine the ieme element of the archive
|
||||
if(comparator(tmp, corner)){
|
||||
std::cout << "ENTER CASE 1" << std::endl;
|
||||
//test if bounds changed
|
||||
//removed=operator[](i);
|
||||
//delete the ieme element of the archive
|
||||
if(i==size()-1)
|
||||
pop_back();
|
||||
else{
|
||||
operator[](i)=back();
|
||||
pop_back();
|
||||
i--;
|
||||
}
|
||||
//changeBoundsByDeleting(removed);
|
||||
res = true;
|
||||
}//END CASE 1
|
||||
//CASE 2: the ieme element of the archive epsilon-domine _moeo
|
||||
else if(comparator(corner, tmp)){
|
||||
std::cout << "ENTER CASE 2" << std::endl;
|
||||
if(change == 1)
|
||||
changeBoundsByDeleting(_moeo);
|
||||
//we can stop
|
||||
nonstop = false;
|
||||
}//END CASE 2
|
||||
// _moeo is no-epsilon-dominated by archive[i] and arhcive[i] is no-epsilon-dominated by _moeo
|
||||
else{
|
||||
//test if the hyperbox corner are the same
|
||||
for(unsigned int j=0; j<corner.size(); j++)
|
||||
same = same && (corner[j] == tmp[j]);
|
||||
//CASE 3: _moeo is in the same hyperbox of archive[i]
|
||||
if(same){
|
||||
std::cout << "ENTER CASE 3" << std::endl;
|
||||
// _moeo dominates archive[i]
|
||||
if(comparator(operator[](i).objectiveVector(), _moeo.objectiveVector())){
|
||||
if(i==size()-1)
|
||||
pop_back();
|
||||
else{
|
||||
operator[](i)=back();
|
||||
pop_back();
|
||||
i--;
|
||||
}
|
||||
// removed=operator[](i);
|
||||
// operator[](i) = _moeo;
|
||||
// changeBoundsByDeleting(removed);
|
||||
res=true;
|
||||
}
|
||||
// _moeo is dominated by archive[i]
|
||||
else if(comparator(_moeo.objectiveVector(), operator[](i).objectiveVector())){
|
||||
changeBoundsByDeleting(_moeo);
|
||||
nonstop=false;
|
||||
}
|
||||
else{
|
||||
//keep the one who have the shortest euclidian distance between the corner
|
||||
moeoEuclideanDistance < MOEOT > 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<MOEOT> pop;
|
||||
for(int i=0; i<size(); i++)
|
||||
pop.push_back(operator[](i));
|
||||
for(int i=0; i<pop.size(); i++)
|
||||
(*this)(pop[i]);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* calculate the hyperbox corner of _moeo
|
||||
* @param _moeo the given individual
|
||||
* @return the ObjectiveVector contains the hyperbox corner values
|
||||
*/
|
||||
ObjectiveVector hyperbox(const MOEOT & _moeo){
|
||||
//normalize _moeo's objectiveVector
|
||||
ObjectiveVector res;
|
||||
res = normalizer(_moeo.objectiveVector());
|
||||
|
||||
// std::cout << "ObjectiveVector non normalise:"<< _moeo.objectiveVector() << std::endl;
|
||||
// std::cout << "ObjectiveVector normalise:"<< res << std::endl;
|
||||
|
||||
//calculate the hyperbox corner
|
||||
for(unsigned int i=0; i<ObjectiveVector::nObjectives(); i++){
|
||||
if(ObjectiveVector::minimizing(i))
|
||||
res[i] = floor(res[i]*1.0/epsilon[i]);
|
||||
else
|
||||
res[i] = ceil(res[i]*1.0/epsilon[i]);
|
||||
}
|
||||
// std::cout << "ObjectiveVector epsilone:" << res << std::endl;
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* changes ideal and nadir point if _moeo is out of bounds and is not bad
|
||||
* @param _moeo the given individual
|
||||
* @return if bounds changed or not (1 -> 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<ObjectiveVector::nObjectives(); i++){
|
||||
if(ObjectiveVector::minimizing(i)){
|
||||
if(_moeo.objectiveVector()[i] < ideal[i]){
|
||||
ideal[i]=_moeo.objectiveVector()[i];
|
||||
res = 1;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(_moeo.objectiveVector()[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<ObjectiveVector::nObjectives(); i++){
|
||||
if(ObjectiveVector::minimizing(i)){
|
||||
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
|
||||
}
|
||||
}
|
||||
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<ObjectiveVector::nObjectives(); i++){
|
||||
mini[i]=std::min(ideal[i], nadir[i]);
|
||||
maxi[i]=std::max(ideal[i], nadir[i]);
|
||||
}
|
||||
normalizer.update_by_min_max(mini, maxi);
|
||||
}
|
||||
// std::cout << "change nadir: " << nadir << std::endl;
|
||||
// std::cout << "change ideal: " << ideal << std::endl;
|
||||
// std::cout << "res: " << res << std::endl;
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* when a element is deleting, change the bounds if neccesary.
|
||||
* @param _moeo the deleted individual
|
||||
*/
|
||||
void changeBoundsByDeleting(const MOEOT & _moeo){
|
||||
for(unsigned int i=0; i< ObjectiveVector::nObjectives(); i++){
|
||||
if((_moeo.objectiveVector()[i]==nadir[i]) || (_moeo.objectiveVector()[i]==ideal[i]) )
|
||||
return recalculateBounds();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* recalculate ideal and nadir point and change scale of normalizer
|
||||
*/
|
||||
void recalculateBounds(){
|
||||
ObjectiveVector tmp;
|
||||
ideal=operator[](0).objectiveVector();
|
||||
nadir=operator[](0).objectiveVector();
|
||||
if (size() > 1){
|
||||
for(unsigned int i=0; i< ObjectiveVector::nObjectives(); i++){
|
||||
for(unsigned int j=1; j<size(); j++){
|
||||
tmp=operator[](j).objectiveVector();
|
||||
if(ObjectiveVector::minimizing(i)){
|
||||
if(tmp[i] < ideal[i])
|
||||
ideal[i] = tmp[i];
|
||||
else if(tmp[i] > 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<ObjectiveVector::nObjectives(); i++){
|
||||
mini[i]=std::min(ideal[i], nadir[i]);
|
||||
maxi[i]=std::max(ideal[i], nadir[i]);
|
||||
}
|
||||
normalizer.update_by_min_max(mini, maxi);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** A moeoObjectiveVectorComparator based on Pareto dominance (used as default) */
|
||||
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
|
||||
|
||||
/** epsilon values */
|
||||
std::vector <double> 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 <MOEOT> normalizer;
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEOEPSILONBOXARCHIVE_H_*/
|
||||
109
trunk/paradiseo-moeo/src/archive/moeoQuadTreeArchive.h
Normal file
109
trunk/paradiseo-moeo/src/archive/moeoQuadTreeArchive.h
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* <moeoQuadTreeArchive.h>
|
||||
* 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 <eoPop.h>
|
||||
|
||||
|
||||
/**
|
||||
* 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_*/
|
||||
|
|
@ -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<ObjectiveVector::nObjectives(); i++)
|
||||
{
|
||||
tmp1 = (_obj1[i] - bounds[i].minimum()) / bounds[i].range();
|
||||
tmp2 = (_obj2[i] - bounds[i].minimum()) / bounds[i].range();
|
||||
result += (tmp1-tmp2) * (tmp1-tmp2);
|
||||
}
|
||||
return sqrt(result);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,8 @@
|
|||
#include <archive/moeoUnboundedArchive.h>
|
||||
#include <archive/moeoImprOnlyBoundedArchive.h>
|
||||
#include <archive/moeoFitDivBoundedArchive.h>
|
||||
#include <archive/moeoEpsilonHyperboxArchive.h>
|
||||
#include <archive/moeoQuadTreeArchive.h>
|
||||
|
||||
|
||||
#include <comparator/moeoAggregativeComparator.h>
|
||||
|
|
@ -151,6 +153,8 @@
|
|||
#include <utils/moeoConvertPopToObjectiveVectors.h>
|
||||
#include <utils/moeoDominanceMatrix.h>
|
||||
#include <utils/moeoObjVecStat.h>
|
||||
#include <utils/moeoQuadTree.h>
|
||||
|
||||
|
||||
|
||||
#endif /*MOEO_*/
|
||||
|
|
|
|||
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_*/
|
||||
|
|
@ -69,6 +69,8 @@ SET (TEST_LIST
|
|||
t-moeoFitDivBoundedArchive
|
||||
t-moeoDetArchiveSelect
|
||||
t-moeoASEEA
|
||||
t-moeoEpsilonHyperboxArchive
|
||||
t-moeoQuadTreeArchive
|
||||
)
|
||||
|
||||
FOREACH (test ${TEST_LIST})
|
||||
|
|
|
|||
158
trunk/paradiseo-moeo/test/t-moeoEpsilonHyperboxArchive.cpp
Normal file
158
trunk/paradiseo-moeo/test/t-moeoEpsilonHyperboxArchive.cpp
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* <t-moeoEpsilonHyperboxArchive.cpp>
|
||||
* 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 <eo>
|
||||
#include <moeo>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
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<pop.size() ; i++)
|
||||
std::cout << pop[i].objectiveVector() << std::endl;
|
||||
|
||||
for(int i=0; i<pop.size() ; i++){
|
||||
arch(pop[i]);
|
||||
// nadir = arch.getNadir();
|
||||
// ideal = arch.getIdeal();
|
||||
// std::cout << "nadir: " << nadir << std::endl;
|
||||
// std::cout << "ideal: " << ideal << std::endl;
|
||||
// std::cout << "archive size: " << arch.size() << std::endl;
|
||||
}
|
||||
|
||||
arch.filtre();
|
||||
|
||||
std::cout << "archive size: " << arch.size() << std::endl;
|
||||
for (unsigned int i=0; i< arch.size(); i++)
|
||||
std::cout << arch[i].objectiveVector() << std::endl;
|
||||
|
||||
std::cout << "nadir: " << nadir << std::endl;
|
||||
std::cout << "ideal: " << ideal << std::endl;
|
||||
//arch(pop);
|
||||
|
||||
std::cout << "OK" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
116
trunk/paradiseo-moeo/test/t-moeoQuadTreeArchive.cpp
Normal file
116
trunk/paradiseo-moeo/test/t-moeoQuadTreeArchive.cpp
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* <t-moeoquadTreeArchive.cpp>
|
||||
* 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 <eo>
|
||||
#include <moeo>
|
||||
#include <cmath>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
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<ObjectiveVector> 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<ObjectiveVector> hop(obj1);
|
||||
QuadTreeNode<ObjectiveVector> hop2(obj2);
|
||||
QuadTreeNode<ObjectiveVector> hop3(obj3);
|
||||
// empty = hop.getSubTree().empty();
|
||||
// std::cout <<"empty? " << empty << std::endl;
|
||||
// std::vector< QuadTreeNode<ObjectiveVector> > 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue