merge ParadisEO-MOEO v-1.0

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@400 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
liefooga 2007-06-26 13:28:59 +00:00
commit 8b7d5260fb
724 changed files with 63305 additions and 2757 deletions

View file

@ -0,0 +1,55 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoAggregativeComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOAGGREGATIVECOMPARATOR_H_
#define MOEOAGGREGATIVECOMPARATOR_H_
#include <comparator/moeoComparator.h>
/**
* Functor allowing to compare two solutions according to their fitness and diversity values, each according to its aggregative value.
*/
template < class MOEOT >
class moeoAggregativeComparator : public moeoComparator < MOEOT >
{
public:
/**
* Ctor.
* @param _weightFitness the weight for fitness
* @param _weightDiversity the weight for diversity
*/
moeoAggregativeComparator(double _weightFitness = 1.0, double _weightDiversity = 1.0) : weightFitness(_weightFitness), weightDiversity(_weightDiversity)
{}
/**
* Returns true if _moeo1 < _moeo2 according to the aggregation of their fitness and diversity values
* @param _moeo1 the first solution
* @param _moeo2 the second solution
*/
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
return ( weightFitness * _moeo1.fitness() + weightDiversity * _moeo1.diversity() ) < ( weightFitness * _moeo2.fitness() + weightDiversity * _moeo2.diversity() );
}
private:
/** the weight for fitness */
double weightFitness;
/** the weight for diversity */
double weightDiversity;
};
#endif /*MOEOAGGREGATIVECOMPARATOR_H_*/

View file

@ -0,0 +1,24 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOCOMPARATOR_H_
#define MOEOCOMPARATOR_H_
#include <eoFunctor.h>
/**
* Functor allowing to compare two solutions.
*/
template < class MOEOT >
class moeoComparator : public eoBF < const MOEOT &, const MOEOT &, const bool > {};
#endif /*MOEOCOMPARATOR_H_*/

View file

@ -0,0 +1,45 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoDiversityThenFitnessComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEODIVERSITYTHENFITNESSCOMPARATOR_H_
#define MOEODIVERSITYTHENFITNESSCOMPARATOR_H_
#include <comparator/moeoComparator.h>
/**
* Functor allowing to compare two solutions according to their diversity values, then according to their fitness values.
*/
template < class MOEOT >
class moeoDiversityThenFitnessComparator : public moeoComparator < MOEOT >
{
public:
/**
* Returns true if _moeo1 < _moeo2 according to their diversity values, then according to their fitness values
* @param _moeo1 the first solution
* @param _moeo2 the second solution
*/
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
if (_moeo1.diversity() == _moeo2.diversity())
{
return _moeo1.fitness() < _moeo2.fitness();
}
else
{
return _moeo1.diversity() < _moeo2.diversity();
}
}
};
#endif /*MOEODIVERSITYTHENFITNESSCOMPARATOR_H_*/

View file

@ -0,0 +1,45 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoFitnessThenDiversityComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOFITNESSTHENDIVERSITYCOMPARATOR_H_
#define MOEOFITNESSTHENDIVERSITYCOMPARATOR_H_
#include <comparator/moeoComparator.h>
/**
* Functor allowing to compare two solutions according to their fitness values, then according to their diversity values.
*/
template < class MOEOT >
class moeoFitnessThenDiversityComparator : public moeoComparator < MOEOT >
{
public:
/**
* Returns true if _moeo1 < _moeo2 according to their fitness values, then according to their diversity values
* @param _moeo1 the first solution
* @param _moeo2 the second solution
*/
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
if (_moeo1.fitness() == _moeo2.fitness())
{
return _moeo1.diversity() < _moeo2.diversity();
}
else
{
return _moeo1.fitness() < _moeo2.fitness();
}
}
};
#endif /*MOEOFITNESSTHENDIVERSITYCOMPARATOR_H_*/

View file

@ -0,0 +1,102 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoGDominanceObjectiveVectorComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOGDOMINANCEOBJECTIVEVECTORCOMPARATOR_H_
#define MOEOGDOMINANCEOBJECTIVEVECTORCOMPARATOR_H_
#include <comparator/moeoObjectiveVectorComparator.h>
/**
* This functor class allows to compare 2 objective vectors according to g-dominance.
* The concept of g-dominance as been introduced in:
* J. Molina, L. V. Santana, A. G. Hernandez-Diaz, C. A. Coello Coello, R. Caballero,
* "g-dominance: Reference point based dominance" (2007)
*/
template < class ObjectiveVector >
class moeoGDominanceObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector >
{
public:
/**
* Ctor.
* @param _ref the reference point
*/
moeoGDominanceObjectiveVectorComparator(ObjectiveVector & _ref) : ref(_ref)
{}
/**
* Returns true if _objectiveVector1 is g-dominated by _objectiveVector2.
* @param _objectiveVector1 the first objective vector
* @param _objectiveVector2 the second objective vector
*/
const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2)
{
unsigned int flag1 = flag(_objectiveVector1);
unsigned int flag2 = flag(_objectiveVector2);
if (flag2==0)
{
// cannot dominate
return false;
}
else if ( (flag2==1) && (flag1==0) )
{
// is dominated
return true;
}
else // (flag1==1) && (flag2==1)
{
// both are on the good region, so let's use the classical Pareto dominance
return paretoComparator(_objectiveVector1, _objectiveVector2);
}
}
private:
/** the reference point */
ObjectiveVector & ref;
/** Pareto comparator */
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
/**
* Returns the flag of _objectiveVector according to the reference point
* @param _objectiveVector the first objective vector
*/
unsigned int flag(const ObjectiveVector & _objectiveVector)
{
unsigned int result=1;
for (unsigned int i=0; i<ref.nObjectives(); i++)
{
if (_objectiveVector[i] > ref[i])
{
result=0;
}
}
if (result==0)
{
result=1;
for (unsigned int i=0; i<ref.nObjectives(); i++)
{
if (_objectiveVector[i] < ref[i])
{
result=0;
}
}
}
return result;
}
};
#endif /*MOEOGDOMINANCEOBJECTIVEVECTORCOMPARATOR_H_*/

View file

@ -0,0 +1,52 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoObjectiveObjectiveVectorComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOOBJECTIVEOBJECTIVEVECTORCOMPARATOR_H_
#define MOEOOBJECTIVEOBJECTIVEVECTORCOMPARATOR_H_
#include <comparator/moeoObjectiveVectorComparator.h>
/**
* Functor allowing to compare two objective vectors according to their first objective value, then their second, and so on.
*/
template < class ObjectiveVector >
class moeoObjectiveObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector >
{
public:
/**
* Returns true if _objectiveVector1 < _objectiveVector2 on the first objective, then on the second, and so on
* @param _objectiveVector1 the first objective vector
* @param _objectiveVector2 the second objective vector
*/
const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2)
{
for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++)
{
if ( fabs(_objectiveVector1[i] - _objectiveVector2[i]) > ObjectiveVector::Traits::tolerance() )
{
if (_objectiveVector1[i] < _objectiveVector2[i])
{
return true;
}
else
{
return false;
}
}
}
return false;
}
};
#endif /*MOEOOBJECTIVEOBJECTIVEVECTORCOMPARATOR_H_*/

View file

@ -0,0 +1,26 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoObjectiveVectorComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOOBJECTIVEVECTORCOMPARATOR_H_
#define MOEOOBJECTIVEVECTORCOMPARATOR_H_
#include <math.h>
#include <eoFunctor.h>
/**
* Abstract class allowing to compare 2 objective vectors.
* The template argument ObjectiveVector have to be a moeoObjectiveVector.
*/
template < class ObjectiveVector >
class moeoObjectiveVectorComparator : public eoBF < const ObjectiveVector &, const ObjectiveVector &, const bool > {};
#endif /*MOEOOBJECTIVEVECTORCOMPARATOR_H_*/

View file

@ -0,0 +1,57 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoOneObjectiveComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOONEOBJECTIVECOMPARATOR_H_
#define MOEOONEOBJECTIVECOMPARATOR_H_
#include <comparator/moeoComparator.h>
/**
* Functor allowing to compare two solutions according to one objective.
*/
template < class MOEOT >
class moeoOneObjectiveComparator : public moeoComparator < MOEOT >
{
public:
/**
* Ctor.
* @param _obj the index of objective
*/
moeoOneObjectiveComparator(unsigned int _obj) : obj(_obj)
{
if (obj > MOEOT::ObjectiveVector::nObjectives())
{
throw std::runtime_error("Problem with the index of objective in moeoOneObjectiveComparator");
}
}
/**
* Returns true if _moeo1 < _moeo2 on the obj objective
* @param _moeo1 the first solution
* @param _moeo2 the second solution
*/
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
return _moeo1.objectiveVector()[obj] < _moeo2.objectiveVector()[obj];
}
private:
/** the index of objective */
unsigned int obj;
};
#endif /*MOEOONEOBJECTIVECOMPARATOR_H_*/

View file

@ -0,0 +1,70 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoParetoObjectiveVectorComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOPARETOOBJECTIVEVECTORCOMPARATOR_H_
#define MOEOPARETOOBJECTIVEVECTORCOMPARATOR_H_
#include <comparator/moeoObjectiveVectorComparator.h>
/**
* This functor class allows to compare 2 objective vectors according to Pareto dominance.
*/
template < class ObjectiveVector >
class moeoParetoObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector >
{
public:
/**
* Returns true if _objectiveVector1 is dominated by _objectiveVector2
* @param _objectiveVector1 the first objective vector
* @param _objectiveVector2 the second objective vector
*/
const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2)
{
bool dom = false;
for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++)
{
// first, we have to check if the 2 objective values are not equal for the ith objective
if ( fabs(_objectiveVector1[i] - _objectiveVector2[i]) > ObjectiveVector::Traits::tolerance() )
{
// if the ith objective have to be minimized...
if (ObjectiveVector::minimizing(i))
{
if (_objectiveVector1[i] > _objectiveVector2[i])
{
dom = true; //_objectiveVector1[i] is not better than _objectiveVector2[i]
}
else
{
return false; //_objectiveVector2 cannot dominate _objectiveVector1
}
}
// if the ith objective have to be maximized...
else if (ObjectiveVector::maximizing(i))
{
if (_objectiveVector1[i] > _objectiveVector2[i])
{
dom = true; //_objectiveVector1[i] is not better than _objectiveVector2[i]
}
else
{
return false; //_objectiveVector2 cannot dominate _objectiveVector1
}
}
}
}
return dom;
}
};
#endif /*MOEOPARETOOBJECTIVEVECTORCOMPARATOR_H_*/