Nettoyage et documentation des classes de bases

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1653 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-01-19 10:42:01 +00:00
commit 31c6fe9888
9 changed files with 224 additions and 177 deletions

View file

@ -1,34 +1,43 @@
#ifndef _moNeighborComparator_h #ifndef _moComparator_h
#define _moNeighborComparator_h #define _moComparator_h
#include <neighborhood/moNeighbor.h> #include <EO.h>
#include <eoFunctor.h>
template< class Neigh > // moComparator => comparer deux solutions
class moNeighborComparator : public eoBF<const Neigh & , const Neigh & , bool> // idée :
// - eoComparator
// - moComparator qui hérite de eoComparator ?
// - moeoComparator qui hérite de eoComparator
// idée J :
// - eoComparator<TYPE> : eoBF <const TYPE & , const TYPE & , bool>
// - eoSolComparator : eoComparator<EOT> ?
// - moNeighborCompartor : : eoComparator<Neighbor>
//
// une instantiation possible !!
template< class EOT >
class moComparator : public eoBF<const EOT & , const EOT & , bool>
{ {
public: public:
/* /*
* true if the neighbor1 is better than neighbor2 * Compare two solutions
*/ * @param _sol1 the first solution
virtual bool operator()(const Neigh & neighbor1, const Neigh & neighbor2) { * @param _sol2 the second solution
return (neighbor1.fitness() > neighbor2.fitness()); * @return true if the _sol1 is better than _sol2
*/
virtual bool operator()(const EOT& _sol1, const EOT& _sol2) {
return (_sol1.fitness() > _sol2.fitness());
} }
/** Return the class id. /*
* @return the class name as a std::string * Return the class id.
*/ * @return the class name as a std::string
virtual std::string className() const { return "moNeighborComparator"; } */
virtual std::string className() const {
return "moComparator";
}
}; };
#endif #endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -1,47 +1,34 @@
#ifndef _moNeighborComparator_h #ifndef _moNeighborComparator_h
#define _moNeighborComparator_h #define _moNeighborComparator_h
#include <EO.h>
#include <eoFunctor.h>
#include <neighborhood/moNeighbor.h> #include <neighborhood/moNeighbor.h>
template< class Neighbor >
class moNeighborComparator : public eoBF<const Neighbor & , const Neighbor & , bool>
// moComparator => comparer deux solutions
// idée :
// - eoComparator
// - moComparator qui hérite de eoComparator ?
// - moeoComparator qui hérite de eoComparator
// idée J :
// - eoComparator<TYPE> : eoBF <const TYPE & , const TYPE & , bool>
// - eoSolComparator : eoComparator<EOT> ?
// - moNeighborCompartor : : eoComparator<Neighbor>
//
// une instantiation possible !!
template< class EOT >
class moComparator : public eoBF<const EOT & , const EOT & , bool>
{ {
public: public:
/* /*
* true if the _sol1 is better than _sol2 * Compare two neighbors
*/ * @param _neighbor1 the first neighbor
virtual bool operator()(const EOT & _sol1, const EOT & _sol2) { * @param _neighbor2 the second neighbor
return (_sol1.fitness() > _sol2.fitness()); * @return true if the neighbor1 is better than neighbor2
*/
virtual bool operator()(const Neighbor& _neighbor1, const Neighbor& _neighbor2) {
return (neighbor1.fitness() > neighbor2.fitness());
} }
/** Return the class id. /*
* @return the class name as a std::string * Return the class id.
*/ * @return the class name as a std::string
virtual std::string className() const { return "moComparator"; } */
virtual std::string className() const {
return "moNeighborComparator";
}
}; };
#endif #endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -1,9 +1,11 @@
#ifndef _moContinuator_h #ifndef _moContinuator_h
#define _moContinuator_h #define _moContinuator_h
#include <eoFunctor.h>
/* /*
to make specific continuator from a solution * To make specific continuator from a solution
*/ */
template< class NH > template< class NH >
class moContinuator : public eoUF<typename NH::EOT &, bool> class moContinuator : public eoUF<typename NH::EOT &, bool>
{ {
@ -11,19 +13,11 @@ public:
typedef NH Neighborhood ; typedef NH Neighborhood ;
typedef typename Neighborhood::EOT EOT ; typedef typename Neighborhood::EOT EOT ;
// empty constructor /*
moContinuator() { } ; * Init Continuator parameters
* @param _solution the related solution
virtual void init(EOT & solution) = 0 ; */
virtual void init(EOT& _solution) = 0 ;
}; };
#endif #endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -1,40 +1,74 @@
#ifndef _neighborhoodExplorer_h #ifndef _neighborhoodExplorer_h
#define _neighborhoodExplorer_h #define _neighborhoodExplorer_h
//EO inclusion
#include <eoFunctor.h>
#include <neighborhood/moNeighborhood.h> #include <neighborhood/moNeighborhood.h>
/* /*
explore the neighborhood * Explore the neighborhood
*/ */
template< class NH > template< class NH >
class moNeighborhoodExplorer : public eoUF<typename NH::EOT & , void> class moNeighborhoodExplorer : public eoUF<typename NH::EOT&, void>
{ {
public: public:
typedef NH Neighborhood ; typedef NH Neighborhood ;
typedef typename Neighborhood::EOT EOT ; typedef typename Neighborhood::EOT EOT ;
typedef typename Neighborhood::Neighbor Neighbor ; typedef typename Neighborhood::Neighbor Neighbor ;
// empty constructor /*
moNeighborhoodExplorer() { } ; * Constructor with a Neighborhood and evaluation function
* @param _neighborhood the neighborhood
* @param _eval the evaluation function
*/
moNeighborhoodExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval):neighborhood(_neighborhood), eval(_eval) {}
// empty constructor /*
moNeighborhoodExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval):neighborhood(_neighborhood), eval(_eval) { } ; * Init Search parameters
* @param _solution the solution to explore
*/
virtual void initParam (EOT& _solution) = 0 ;
virtual void initParam (EOT & solution) = 0 ; /*
* Update Search parameters
* @param _solution the solution to explore
*/
virtual void updateParam (EOT& _solution) = 0 ;
virtual void updateParam (EOT & solution) = 0 ; /*
* Test if the exploration continue or not
* @param _solution the solution to explore
* @return true if the exploration continue, else return false
*/
virtual bool isContinue(EOT& _solution) = 0 ;
virtual bool isContinue(EOT & solution) = 0 ; /*
* Move a solution
* @param _solution the solution to explore
*/
virtual void move(EOT& _solution) = 0 ;
virtual void move(EOT & solution) = 0 ; /*
* Test if a solution is accepted
* @param _solution the solution to explore
* @return true if the solution is accepted, else return false
*/
virtual bool accept(EOT& _solution) = 0 ;
virtual bool accept(EOT & solution) = 0 ; /*
* Terminate the search
* @param _solution the solution to explore
*/
virtual void terminate(EOT& _solution) = 0 ;
virtual void terminate(EOT & solution) = 0 ; /*
* Return the class id.
/** Return the class id. * @return the class name as a std::string
* @return the class name as a std::string */
*/ virtual std::string className() const {
virtual std::string className() const { return "moNeighborhoodExplorer"; } return "moNeighborhoodExplorer";
}
protected: protected:
Neighborhood & neighborhood; Neighborhood & neighborhood;
@ -42,14 +76,4 @@ protected:
}; };
#endif #endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -2,17 +2,17 @@
#define _BackableNeighbor_h #define _BackableNeighbor_h
/* /*
neighbor with a move back function to use in a moFullEvalByModif * Neighbor with a move back function to use in a moFullEvalByModif
*/ */
template< class EOT , class Fitness > template< class EOT , class Fitness >
class moBackableNeighbor : moNeighbor<EOT, Fitness> class moBackableNeighbor : moNeighbor<EOT, Fitness>
{ {
public: public:
/* /*
* the move back function * the move back function
* @param _solution the solution to moveBack * @param _solution the solution to moveBack
*/ */
virtual moveBack(EOT & _solution) = 0; virtual moveBack(EOT & _solution) = 0;
}; };

View file

@ -30,12 +30,3 @@ public:
}; };
#endif #endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -1,76 +1,96 @@
#ifndef _moNeighbor_h #ifndef _moNeighbor_h
#define _moNeighbor_h #define _moNeighbor_h
#include <eo> //EO inclusion
#include <EO.h>
#include <eoObject.h>
#include <eoPersistent.h>
#include <comparator/moNeighborComparator.h> #include <comparator/moNeighborComparator.h>
/* /*
contener of the neighbor informations * Container of the neighbor informations
*/ */
template< class EOT , class Fitness > template< class EOT , class Fitness >
class moNeighbor : public eoObject, public eoPersistent class moNeighbor : public eoObject, public eoPersistent
{ {
public: public:
typedef EOT EOType ;
// empty constructor /*
moNeighbor() { } ; * Default Constructor
*/
moNeighbor(){}
// copy constructeur /*
moNeighbor(const moNeighbor<EOType, Fitness> & _n) { * Copy Constructor
repFitness = _n.fitness(); * @param _neighbor to copy
} */
moNeighbor(const moNeighbor<EOType, Fitness>& _neighbor) {
// assignment operator repFitness = _neighbor.fitness();
virtual moNeighbor<EOType, Fitness> & operator=(const moNeighbor<EOType, Fitness> & _n) {
repFitness = _n.fitness();
return *this ;
} }
/* /*
* move the solution * Assignment operator
*/ * @param the _neighbor to assign
virtual void move(EOT & solution) = 0 ; * @return a neighbor equal to the other
*/
virtual moNeighbor<EOT, Fitness>& operator=(const moNeighbor<EOT, Fitness>& _neighbor) {
repFitness = _neighbor.fitness();
return (*this);
}
/*
* Move a solution
* @param _solution the related solution
*/
virtual void move(EOT & _solution) = 0 ;
/// Return fitness value. /*
* Get the fitness of the neighbor
* @return fitness of the neighbor
*/
const Fitness& fitness() const { const Fitness& fitness() const {
return repFitness; return repFitness;
} }
/// Get fitness as reference, useful when fitness is set in a multi-stage way, e.g., MOFitness gets performance information, is subsequently ranked
/*
* Get fitness as reference, useful when fitness is set in a multi-stage way, e.g., MOFitness gets performance information, is subsequently ranked
* @return fitness as reference of the neighbor
*/
Fitness& fitnessReference() { Fitness& fitnessReference() {
return repFitness; return repFitness;
} }
/** Set fitness. At the same time, validates it. /*
* @param _fitness New fitness value. * Set fitness. At the same time, validates it.
*/ * @param _fitness new fitness value.
void fitness(const Fitness& _fitness) */
{ void fitness(const Fitness& _fitness){
repFitness = _fitness; repFitness = _fitness;
} }
/** Return the class id. /*
* @return the class name as a std::string * Return the class id.
*/ * @return the class name as a std::string
*/
virtual std::string className() const { return "moNeighbor"; } virtual std::string className() const { return "moNeighbor"; }
/** /*
* Read object.\ \ * Read object.
* Calls base class, just in case that one had something to do. * Calls base class, just in case that one had something to do.
* The read and print methods should be compatible and have the same format. * The read and print methods should be compatible and have the same format.
* In principle, format is "plain": they just print a number * In principle, format is "plain": they just print a number
* @param _is a std::istream. * @param _is a std::istream.
*/ */
virtual void readFrom(std::istream& _is) { virtual void readFrom(std::istream& _is) {
_is >> repFitness; _is >> repFitness;
} }
/** /*
* Write object. Called printOn since it prints the object _on_ a stream. * Write object. Called printOn since it prints the object _on_ a stream.
* @param _os A std::ostream. * @param _os A std::ostream.
*/ */
virtual void printOn(std::ostream& _os) const { virtual void printOn(std::ostream& _os) const {
_os << repFitness << ' ' ; _os << repFitness << ' ' ;
} }

View file

@ -1,35 +1,57 @@
#ifndef _moNeighborhood_h #ifndef _moNeighborhood_h
#define _moNeighborhood_h #define _moNeighborhood_h
template< class Neigh > #include <eoObject.h>
/*
* A Neighborhood
*/
template< class Neighbor >
class moNeighborhood : public eoObject class moNeighborhood : public eoObject
{ {
public: public:
typedef Neigh Neighbor; /*
* Define type of a solution corresponding to Neighbor
*/
typedef typename Neighbor::EOType EOT; typedef typename Neighbor::EOType EOT;
moNeighborhood() { } /*
* Default Constructor
virtual bool hasNeighbor(EOT & solution) = 0 ; */
moNeighborhood(){}
/* /*
initialisation of the neighborhood * Test if a solution has (again) a Neighbor
*/ * @param _solution the related solution
virtual void init(EOT & solution, Neighbor & current) = 0 ; * @return if _solution has a Neighbor
*/
virtual bool hasNeighbor(EOT & _solution) = 0 ;
/* /*
Give the next neighbor * Initialization of the neighborhood
*/ * @param _solution the solution to explore
virtual void next(EOT & solution, Neighbor & current) = 0 ; * @param _current the first neighbor
*/
virtual void init(EOT & _solution, Neighbor & _current) = 0 ;
/* /*
if false, there is no neighbor left to explore * Give the next neighbor
*/ * @param _solution the solution to explore
virtual bool cont(EOT & solution) = 0 ; * @param _current the next neighbor
*/
virtual void next(EOT & _solution, Neighbor & _current) = 0 ;
/** Return the class id. /*
* @return the class name as a std::string * Test if there is again a neighbor
*/ * @param _solution the solution to explore
* @return if there is again a neighbor not explored
*/
virtual bool cont(EOT & _solution) = 0 ;
/* Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const { return "moNeighborhood"; } virtual std::string className() const { return "moNeighborhood"; }
}; };

View file

@ -40,7 +40,7 @@ using namespace std;
// explore the neighborhood of a bit string in order // explore the neighborhood of a bit string in order
#include <neighborhood/moBitNeighborhood.h> #include <neighborhood/moBitNeighborhood.h>
#include <neighborhood/moFullEvalBitNeighbor.h> #include <eval/moFullEvalBitNeighbor.h>
#include <oneMaxBitNeighbor.h> #include <oneMaxBitNeighbor.h>