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
#define _moNeighborComparator_h
#ifndef _moComparator_h
#define _moComparator_h
#include <neighborhood/moNeighbor.h>
#include <EO.h>
#include <eoFunctor.h>
template< class Neigh >
class moNeighborComparator : public eoBF<const Neigh & , const Neigh & , 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:
/*
* true if the neighbor1 is better than neighbor2
*/
virtual bool operator()(const Neigh & neighbor1, const Neigh & neighbor2) {
return (neighbor1.fitness() > neighbor2.fitness());
* Compare two solutions
* @param _sol1 the first solution
* @param _sol2 the second solution
* @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
*/
virtual std::string className() const { return "moNeighborComparator"; }
/*
* Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moComparator";
}
};
#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
#define _moNeighborComparator_h
#include <EO.h>
#include <eoFunctor.h>
#include <neighborhood/moNeighbor.h>
// 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>
template< class Neighbor >
class moNeighborComparator : public eoBF<const Neighbor & , const Neighbor & , bool>
{
public:
/*
* true if the _sol1 is better than _sol2
*/
virtual bool operator()(const EOT & _sol1, const EOT & _sol2) {
return (_sol1.fitness() > _sol2.fitness());
* Compare two neighbors
* @param _neighbor1 the first neighbor
* @param _neighbor2 the second neighbor
* @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
*/
virtual std::string className() const { return "moComparator"; }
/*
* Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moNeighborComparator";
}
};
#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
#define _moContinuator_h
#include <eoFunctor.h>
/*
to make specific continuator from a solution
*/
* To make specific continuator from a solution
*/
template< class NH >
class moContinuator : public eoUF<typename NH::EOT &, bool>
{
@ -11,19 +13,11 @@ public:
typedef NH Neighborhood ;
typedef typename Neighborhood::EOT EOT ;
// empty constructor
moContinuator() { } ;
virtual void init(EOT & solution) = 0 ;
/*
* Init Continuator parameters
* @param _solution the related solution
*/
virtual void init(EOT& _solution) = 0 ;
};
#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
#define _neighborhoodExplorer_h
//EO inclusion
#include <eoFunctor.h>
#include <neighborhood/moNeighborhood.h>
/*
explore the neighborhood
*/
* Explore the neighborhood
*/
template< class NH >
class moNeighborhoodExplorer : public eoUF<typename NH::EOT & , void>
class moNeighborhoodExplorer : public eoUF<typename NH::EOT&, void>
{
public:
typedef NH Neighborhood ;
typedef typename Neighborhood::EOT EOT ;
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 name as a std::string
*/
virtual std::string className() const { return "moNeighborhoodExplorer"; }
/*
* Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moNeighborhoodExplorer";
}
protected:
Neighborhood & neighborhood;
@ -42,14 +76,4 @@ protected:
};
#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
/*
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 >
class moBackableNeighbor : moNeighbor<EOT, Fitness>
{
public:
/*
* the move back function
* @param _solution the solution to moveBack
*/
/*
* the move back function
* @param _solution the solution to moveBack
*/
virtual moveBack(EOT & _solution) = 0;
};

View file

@ -30,12 +30,3 @@ public:
};
#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
#define _moNeighbor_h
#include <eo>
//EO inclusion
#include <EO.h>
#include <eoObject.h>
#include <eoPersistent.h>
#include <comparator/moNeighborComparator.h>
/*
contener of the neighbor informations
*/
* Container of the neighbor informations
*/
template< class EOT , class Fitness >
class moNeighbor : public eoObject, public eoPersistent
{
public:
typedef EOT EOType ;
// empty constructor
moNeighbor() { } ;
/*
* Default Constructor
*/
moNeighbor(){}
// copy constructeur
moNeighbor(const moNeighbor<EOType, Fitness> & _n) {
repFitness = _n.fitness();
}
// assignment operator
virtual moNeighbor<EOType, Fitness> & operator=(const moNeighbor<EOType, Fitness> & _n) {
repFitness = _n.fitness();
return *this ;
/*
* Copy Constructor
* @param _neighbor to copy
*/
moNeighbor(const moNeighbor<EOType, Fitness>& _neighbor) {
repFitness = _neighbor.fitness();
}
/*
* move the solution
*/
virtual void move(EOT & solution) = 0 ;
* Assignment operator
* @param the _neighbor to assign
* @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 {
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() {
return repFitness;
}
/** Set fitness. At the same time, validates it.
* @param _fitness New fitness value.
*/
void fitness(const Fitness& _fitness)
{
/*
* Set fitness. At the same time, validates it.
* @param _fitness new fitness value.
*/
void fitness(const Fitness& _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"; }
/**
* Read object.\ \
* 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.
* In principle, format is "plain": they just print a number
* @param _is a std::istream.
*/
/*
* Read object.
* 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.
* In principle, format is "plain": they just print a number
* @param _is a std::istream.
*/
virtual void readFrom(std::istream& _is) {
_is >> repFitness;
_is >> repFitness;
}
/**
* Write object. Called printOn since it prints the object _on_ a stream.
* @param _os A std::ostream.
*/
/*
* Write object. Called printOn since it prints the object _on_ a stream.
* @param _os A std::ostream.
*/
virtual void printOn(std::ostream& _os) const {
_os << repFitness << ' ' ;
}

View file

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

View file

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