From 9cf56808231414d00fd076af4e83bd3aa727f012 Mon Sep 17 00:00:00 2001 From: jhumeau Date: Wed, 20 Jan 2010 14:49:54 +0000 Subject: [PATCH] Encore de la doc git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1660 331e1502-861f-0410-8da2-ba01fb791d7f --- branches/newMo/src/algo/moLocalSearch.h | 58 +++---- .../newMo/src/continuator/moTrueContinuator.h | 29 ++-- branches/newMo/src/eval/moEval.h | 4 +- .../newMo/src/neighborhood/moBitNeighbor.h | 142 +++++++++--------- .../src/neighborhood/moBitNeighborhood.h | 58 ++++--- branches/newMo/src/neighborhood/moNeighbor.h | 36 ----- .../newMo/src/neighborhood/moNeighborhood.h | 2 +- 7 files changed, 153 insertions(+), 176 deletions(-) diff --git a/branches/newMo/src/algo/moLocalSearch.h b/branches/newMo/src/algo/moLocalSearch.h index 174e1c1e4..93ff2ed45 100644 --- a/branches/newMo/src/algo/moLocalSearch.h +++ b/branches/newMo/src/algo/moLocalSearch.h @@ -3,6 +3,7 @@ #include #include +#include /** * the main algorithm of the local search @@ -19,41 +20,47 @@ public: /** * Constructor of a moLocalSearch needs a NeighborhooExplorer and a Continuator */ - moLocalSearch(NeighborhoodExplorer& _searchExpl, Continuator & _continuator) : searchExplorer(_searchExpl), continuator(_continuator) { } ; + moLocalSearch(NeighborhoodExplorer& _searchExpl, Continuator & _continuator, eoEvalFunc& _fullEval) : searchExplorer(_searchExpl), continuator(_continuator), fullEval(_fullEval) { } ; /** * Run the local search on a solution * @param _solution the related solution */ virtual bool operator() (EOT & _solution) { + + if(_solution.invalid()) + fullEval(_solution); - // initialization of the external continuator (for example the time, or the number of generations) - continuator.init(_solution); + // initialization of the external continuator (for example the time, or the number of generations) + continuator.init(_solution); - // initialization of the parameter of the search (for example fill empty the tabu list) - searchExplorer.initParam(_solution); + // initialization of the parameter of the search (for example fill empty the tabu list) + searchExplorer.initParam(_solution); - unsigned num = 0; + //A virer par la suite + unsigned int num = 0; - do { - // explore the neighborhood of the solution - searchExplorer(_solution); + do{ + // explore the neighborhood of the solution + searchExplorer(_solution); - // if a solution in the neighborhood can be accepted - if (searchExplorer.accept(_solution)) - searchExplorer.move(_solution); + // if a solution in the neighborhood can be accepted + if (searchExplorer.accept(_solution)) + searchExplorer.move(_solution); - // update the parameter of the search (for ex. Temperature of the SA) - searchExplorer.updateParam(_solution); + // update the parameter of the search (for ex. Temperature of the SA) + searchExplorer.updateParam(_solution); - std::cout << num << " : " << _solution << std::endl ; - num++; - } while (continuator(_solution) && searchExplorer.isContinue(_solution)); + //A virer par la suite + std::cout << num << " : " << _solution << std::endl ; + num++; - searchExplorer.terminate(_solution); + }while (continuator(_solution) && searchExplorer.isContinue(_solution)); - //A CHANGER - return true; + searchExplorer.terminate(_solution); + + //A CHANGER + return true; }; @@ -63,15 +70,10 @@ private: // external continuator Continuator& continuator ; + + //full evaluation function + eoEvalFunc& fullEval; }; #endif - -// Local Variables: -// coding: iso-8859-1 -// mode: C++ -// c-file-offsets: ((c . 0)) -// c-file-style: "Stroustrup" -// fill-column: 80 -// End: diff --git a/branches/newMo/src/continuator/moTrueContinuator.h b/branches/newMo/src/continuator/moTrueContinuator.h index 97354daa7..fd296ea3f 100644 --- a/branches/newMo/src/continuator/moTrueContinuator.h +++ b/branches/newMo/src/continuator/moTrueContinuator.h @@ -4,30 +4,31 @@ #include /** - to make specific continuator from a solution -*/ + * Continuator always return True + */ template< class NH > class moTrueContinuator : public moContinuator { public: - typedef NH Neighborhood ; - typedef typename Neighborhood::EOT EOT ; + typedef typename NH::EOT EOT ; // empty constructor - moTrueContinuator() { i=0;} ; + moTrueContinuator() {} ; /** - always true - */ - virtual bool operator()(EOT & solution) { - i++; - return i<10; - }; - - virtual void init(EOT & solution) { + *@param _solution a solution + *@return always true + */ + virtual bool operator()(EOT & _solution) { + return true; } - int i; + /** + * NOTHING TO DO + * @param _solution a solution + */ + virtual void init(EOT & _solution) {} + }; #endif diff --git a/branches/newMo/src/eval/moEval.h b/branches/newMo/src/eval/moEval.h index 130821c31..ff8026609 100644 --- a/branches/newMo/src/eval/moEval.h +++ b/branches/newMo/src/eval/moEval.h @@ -7,10 +7,10 @@ * Abstract class for the evaluation */ template -class moEval : public eoBF +class moEval : public eoBF { public: - typedef typename Neighbor::EOType EOT; + typedef typename Neighbor::EOT EOT; typedef typename EOT::Fitness Fitness; }; diff --git a/branches/newMo/src/neighborhood/moBitNeighbor.h b/branches/newMo/src/neighborhood/moBitNeighbor.h index c8f8f20a9..996204b18 100644 --- a/branches/newMo/src/neighborhood/moBitNeighbor.h +++ b/branches/newMo/src/neighborhood/moBitNeighbor.h @@ -4,108 +4,104 @@ #include #include -/* - contener of the neighbor information -*/ +/** + * Neighbor related to a vector of Bit + */ template< class Fitness > class moBitNeighbor : public moBackableNeighbor, Fitness> { public: - typedef eoBit EOType ; + typedef eoBit EOT ; using moNeighbor, Fitness>::fitness; // describe the neighbor unsigned bit ; - // empty constructor needed + /** + * Default Constructor + */ moBitNeighbor() : moBackableNeighbor , Fitness>() { } ; - // copy constructor - moBitNeighbor(const moBitNeighbor & n) : moNeighbor , Fitness>(n) { - this->bit = n.bit ; + /** + * Copy Constructor + */ + moBitNeighbor(const moBitNeighbor& _n) : moNeighbor , Fitness>(_n) { + this->bit = _n.bit ; } ; - moBitNeighbor(unsigned b) : moNeighbor , Fitness>() , bit(b) { } ; + /** + * Constructor + * @param _b index + */ + moBitNeighbor(unsigned int _b) : moNeighbor , Fitness>() , bit(_b) { } ; - /* - * operator of assignment - */ - virtual moBitNeighbor & operator=(const moBitNeighbor & source) { - moNeighbor::operator=(source); - - this->bit = source.bit ; - - return *this ; + /** + * Assignment operator + */ + virtual moBitNeighbor & operator=(const moBitNeighbor & _source) { + moNeighbor::operator=(_source); + this->bit = _source.bit ; + return *this ; } - /* - move the solution - */ - virtual void move(EOType & solution) { - solution[bit] = !solution[bit]; + /** + * move the solution + * @param _solution the solution to move + */ + virtual void move(EOT & _solution) { + _solution[bit] = !_solution[bit]; } - virtual void moveBack(EOType & solution) { - solution[bit] = !solution[bit]; + /** + * move back the solution (useful for the evaluation by modif) + * @param _solution the solution to move back + */ + virtual void moveBack(EOT & _solution) { + _solution[bit] = !_solution[bit]; } - // by default: if the fitness of the current solution is stricly higher than the other neighbor - virtual bool betterThan(const moNeighbor & __neighbor) { - return (this->fitness() > __neighbor.fitness()) ; - }; - - /** Return the class id. - * @return the class name as a std::string - */ - virtual std::string className() const { return "moBitNeighbor"; } + /** + * Return the class id. + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moBitNeighbor"; + } - /** - * 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. - * @throw runtime_std::exception If a valid object can't be read. - */ - virtual void readFrom(std::istream& _is) { - std::string fitness_str; - int pos = _is.tellg(); - _is >> fitness_str; - - if (fitness_str == "INVALID") - { - throw std::runtime_error("invalid fitness"); + /** + * 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. + * @throw runtime_std::exception If a valid object can't be read. + */ + virtual void readFrom(std::istream& _is) { + std::string fitness_str; + int pos = _is.tellg(); + _is >> fitness_str; + if (fitness_str == "INVALID"){ + throw std::runtime_error("invalid fitness"); + } + else{ + Fitness repFit ; + _is.seekg(pos); // rewind + _is >> repFit; + _is >> bit; + fitness(repFit); + } } - else - { - Fitness repFit ; - _is.seekg(pos); // rewind - _is >> repFit; - _is >> bit; - - fitness(repFit); - } - } /** - * 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 << fitness() << ' ' << bit << ' ' ; + _os << fitness() << ' ' << bit << std::endl; } }; #endif - - -// Local Variables: -// coding: iso-8859-1 -// mode: C++ -// c-file-offsets: ((c . 0)) -// c-file-style: "Stroustrup" -// fill-column: 80 -// End: diff --git a/branches/newMo/src/neighborhood/moBitNeighborhood.h b/branches/newMo/src/neighborhood/moBitNeighborhood.h index e225f2058..1dc051dd1 100644 --- a/branches/newMo/src/neighborhood/moBitNeighborhood.h +++ b/branches/newMo/src/neighborhood/moBitNeighborhood.h @@ -3,48 +3,62 @@ #include +/** + * Neighborhood related to a vector of Bit + */ template< class N > class moBitNeighborhood : public moNeighborhood { public: typedef N Neighbor ; - typedef typename Neighbor::EOType EOT ; + typedef typename Neighbor::EOT EOT ; + /** + * Default Constructor + */ moBitNeighborhood() : moNeighborhood() { } - virtual bool hasNeighbor(EOT & solution) { - - return true; - + /** + * Test if it exist a neighbor + * @param _solution the solution to explore + * @return always True + */ + virtual bool hasNeighbor(EOT& _solution) { + return true; } - /* - initialisation of the neighborhood - */ - virtual void init(EOT & solution, Neighbor & _neighbor) { + /** + * Initialization of the neighborhood + * @param _solution the solution to explore + * @param _neighbor the first neighbor + */ + virtual void init(EOT & _solution, Neighbor & _neighbor) { currentBit = 0 ; - _neighbor.bit = currentBit ; } - /* - Give the next neighbor - */ - virtual void next(EOT & solution, Neighbor & neighbor) { + /** + * Give the next neighbor + * @param _solution the solution to explore + * @param _neighbor the next neighbor + */ + virtual void next(EOT & _solution, Neighbor & _neighbor) { currentBit++ ; - - neighbor.bit = currentBit ; + _neighbor.bit = currentBit ; } - /* - if false, there is no neighbor left to explore - */ - virtual bool cont(EOT & solution) { - return (currentBit < solution.size()) ; + /** + * test if all neighbors are explore or not,if false, there is no neighbor left to explore + * @param _solution the solution to explore + * @return true if there is again a neighbor to explore + */ + virtual bool cont(EOT & _solution) { + return (currentBit < _solution.size()) ; } private: - unsigned currentBit; + //Position in the neighborhood + unsigned int currentBit; }; diff --git a/branches/newMo/src/neighborhood/moNeighbor.h b/branches/newMo/src/neighborhood/moNeighbor.h index 611c5830d..188843195 100644 --- a/branches/newMo/src/neighborhood/moNeighbor.h +++ b/branches/newMo/src/neighborhood/moNeighbor.h @@ -1,39 +1,3 @@ -/* - - Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008 - (C) OPAC Team, LIFL, 2002-2008 - - Sébastien Cahon, Jean-Charles Boisson (Jean-Charles.Boisson@lifl.fr) - - 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 _moNeighbor_h #define _moNeighbor_h diff --git a/branches/newMo/src/neighborhood/moNeighborhood.h b/branches/newMo/src/neighborhood/moNeighborhood.h index ef40114c3..d11fc7a3e 100644 --- a/branches/newMo/src/neighborhood/moNeighborhood.h +++ b/branches/newMo/src/neighborhood/moNeighborhood.h @@ -13,7 +13,7 @@ public: /** * Define type of a solution corresponding to Neighbor */ - typedef typename Neighbor::EOType EOT; + typedef typename Neighbor::EOT EOT; /** * Default Constructor