From 6095a660057fbebbdbd3cc567c450c1906e988ba Mon Sep 17 00:00:00 2001 From: marieeleonore Date: Tue, 14 Dec 2010 10:25:17 +0000 Subject: [PATCH] add equal comparator between 2 neighbors and between 1 sol and 1 neighbor git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2020 331e1502-861f-0410-8da2-ba01fb791d7f --- .../comparator/moEqualNeighborComparator.h | 69 +++++++++++++++++ .../comparator/moEqualSolNeighborComparator.h | 74 +++++++++++++++++++ .../src/comparator/moSolNeighborComparator.h | 2 +- .../src/continuator/moBooleanStat.h | 8 +- .../src/continuator/moUnsignedStat.h | 8 +- .../paradiseo-mo/src/explorer/moILSexplorer.h | 2 + .../explorer/moRandomNeutralWalkExplorer.h | 1 + trunk/paradiseo-mo/src/mo.h | 2 + 8 files changed, 157 insertions(+), 9 deletions(-) create mode 100644 trunk/paradiseo-mo/src/comparator/moEqualNeighborComparator.h create mode 100644 trunk/paradiseo-mo/src/comparator/moEqualSolNeighborComparator.h diff --git a/trunk/paradiseo-mo/src/comparator/moEqualNeighborComparator.h b/trunk/paradiseo-mo/src/comparator/moEqualNeighborComparator.h new file mode 100644 index 000000000..b53fb004b --- /dev/null +++ b/trunk/paradiseo-mo/src/comparator/moEqualNeighborComparator.h @@ -0,0 +1,69 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Sébastien Verel, 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 _moEqualNeighborComparator_h +#define _moEqualNeighborComparator_h + +#include +#include + +/** + * Comparator of two neighbors : a neighbor is better if the fitness is higher or equal + */ +template< class Neighbor > +class moEqualNeighborComparator : public moNeighborComparator +{ +public: + + /** + * Compare two neighbors + * @param _neighbor1 the first neighbor + * @param _neighbor2 the second neighbor + * @return true if the neighbor2 is better or equal than neighbor1 + */ + virtual bool operator()(const Neighbor& _neighbor1, const Neighbor& _neighbor2) { + return (_neighbor1.fitness() <= _neighbor2.fitness()); + } + + /** + * Return the class Name + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moEqualNeighborComparator"; + } +}; + + +#endif diff --git a/trunk/paradiseo-mo/src/comparator/moEqualSolNeighborComparator.h b/trunk/paradiseo-mo/src/comparator/moEqualSolNeighborComparator.h new file mode 100644 index 000000000..6f706dc73 --- /dev/null +++ b/trunk/paradiseo-mo/src/comparator/moEqualSolNeighborComparator.h @@ -0,0 +1,74 @@ +/* + + Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010 + + Sébastien Verel, 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 _moEqualSolNeighborComparator_h +#define _moEqualSolNeighborComparator_h + +#include +#include + +#include +#include + + +/** + * Comparator of a solution and its neighbor : a neighbor is better if the fitness is higher or equal + */ +template< class Neighbor > +class moEqualSolNeighborComparator : public moSolNeighborComparator +{ +public: + typedef typename Neighbor::EOT EOT ; + + /** + * Compare two neighbors + * @param _sol the solution + * @param _neighbor the neighbor + * @return true if the neighbor is better or equal than sol + */ + virtual bool operator()(const EOT& _sol, const Neighbor& _neighbor) { + return (_sol.fitness() <= _neighbor.fitness()); + } + + /** + * Return the class Name + * @return the class name as a std::string + */ + virtual std::string className() const { + return "moEqualSolNeighborComparator"; + } +}; + + +#endif diff --git a/trunk/paradiseo-mo/src/comparator/moSolNeighborComparator.h b/trunk/paradiseo-mo/src/comparator/moSolNeighborComparator.h index 1a49e8970..2275a6494 100644 --- a/trunk/paradiseo-mo/src/comparator/moSolNeighborComparator.h +++ b/trunk/paradiseo-mo/src/comparator/moSolNeighborComparator.h @@ -43,7 +43,7 @@ /** - * Comparator of two neighbors + * Comparator of a solution and its neighbor */ template< class Neighbor > class moSolNeighborComparator : public moComparator diff --git a/trunk/paradiseo-mo/src/continuator/moBooleanStat.h b/trunk/paradiseo-mo/src/continuator/moBooleanStat.h index c99b03988..a098efc23 100644 --- a/trunk/paradiseo-mo/src/continuator/moBooleanStat.h +++ b/trunk/paradiseo-mo/src/continuator/moBooleanStat.h @@ -49,7 +49,7 @@ public : /** * Default Constructor */ - moBooleanStat(bool & _b): moStat(_b, "boolean"), b(_b) { + moBooleanStat(bool * _b): moStat(*_b, "boolean"), b(_b) { } /** @@ -57,7 +57,7 @@ public : * @param _sol a solution */ virtual void init(EOT & _sol) { - value() = b; + value() = *b; } /** @@ -65,7 +65,7 @@ public : * @param _sol a solution */ virtual void operator()(EOT & _sol) { - value() = b; + value() = *b; } /** @@ -76,7 +76,7 @@ public : } private: - bool & b; + bool * b; }; #endif diff --git a/trunk/paradiseo-mo/src/continuator/moUnsignedStat.h b/trunk/paradiseo-mo/src/continuator/moUnsignedStat.h index ce80fc1be..c1f8342cd 100644 --- a/trunk/paradiseo-mo/src/continuator/moUnsignedStat.h +++ b/trunk/paradiseo-mo/src/continuator/moUnsignedStat.h @@ -49,7 +49,7 @@ public : /** * Default Constructor */ - moUnsignedStat(unsigned int & _b): moStat(_b, "unsigned"), b(_b) { + moUnsignedStat(unsigned int * _b): moStat(*_b, "unsigned"), b(_b) { } /** @@ -57,7 +57,7 @@ public : * @param _sol a solution */ virtual void init(EOT & _sol) { - value() = b; + value() = *b; } /** @@ -65,7 +65,7 @@ public : * @param _sol a solution */ virtual void operator()(EOT & _sol) { - value() = b; + value() = *b; } /** @@ -76,7 +76,7 @@ public : } private: - unsigned int & b; + unsigned int * b; }; #endif diff --git a/trunk/paradiseo-mo/src/explorer/moILSexplorer.h b/trunk/paradiseo-mo/src/explorer/moILSexplorer.h index a590d217f..ba6489832 100644 --- a/trunk/paradiseo-mo/src/explorer/moILSexplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moILSexplorer.h @@ -127,6 +127,8 @@ public: //apply the local search on the copy ls(current); +// std::cout << "(solution)\t" << current << std::endl; + }; /** diff --git a/trunk/paradiseo-mo/src/explorer/moRandomNeutralWalkExplorer.h b/trunk/paradiseo-mo/src/explorer/moRandomNeutralWalkExplorer.h index c139744c8..0b40d2d3e 100644 --- a/trunk/paradiseo-mo/src/explorer/moRandomNeutralWalkExplorer.h +++ b/trunk/paradiseo-mo/src/explorer/moRandomNeutralWalkExplorer.h @@ -111,6 +111,7 @@ public: * @param _solution */ virtual void operator()(EOT & _solution) { + //Test if _solution has a Neighbor if (neighborhood.hasNeighbor(_solution)) { //init the first neighbor diff --git a/trunk/paradiseo-mo/src/mo.h b/trunk/paradiseo-mo/src/mo.h index 595d6e51c..d3f3190cb 100755 --- a/trunk/paradiseo-mo/src/mo.h +++ b/trunk/paradiseo-mo/src/mo.h @@ -57,8 +57,10 @@ #include #include +#include #include #include +#include #include #include