From 4e00b61d79c61dacb91058ac16ecc017336c542b Mon Sep 17 00:00:00 2001 From: jhumeau Date: Mon, 15 Mar 2010 16:48:18 +0000 Subject: [PATCH] Comparator updated and test added git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1694 331e1502-861f-0410-8da2-ba01fb791d7f --- branches/newMo/src/comparator/moComparator.h | 17 ++--- .../src/comparator/moNeighborComparator.h | 3 +- .../src/comparator/moSolNeighborComparator.h | 3 +- branches/newMo/test/CMakeLists.txt | 5 +- .../newMo/test/t-moNeighborComparator.cpp | 67 +++++++++++++++++ .../newMo/test/t-moSolNeighborComparator.cpp | 71 +++++++++++++++++++ 6 files changed, 150 insertions(+), 16 deletions(-) create mode 100644 branches/newMo/test/t-moNeighborComparator.cpp create mode 100644 branches/newMo/test/t-moSolNeighborComparator.cpp diff --git a/branches/newMo/src/comparator/moComparator.h b/branches/newMo/src/comparator/moComparator.h index b7e185372..d33ad59a7 100644 --- a/branches/newMo/src/comparator/moComparator.h +++ b/branches/newMo/src/comparator/moComparator.h @@ -52,22 +52,13 @@ /** - * Comparator of two solutions + * Comparator of two types */ -template< class EOT > -class moComparator : public eoBF +template< class T1, class T2 > +class moComparator : public eoBF { public: - - /** - * 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()); - } + virtual bool equals(const T1&, const T2&) = 0; /** * Return the class id. diff --git a/branches/newMo/src/comparator/moNeighborComparator.h b/branches/newMo/src/comparator/moNeighborComparator.h index a24ce7331..7a9358611 100644 --- a/branches/newMo/src/comparator/moNeighborComparator.h +++ b/branches/newMo/src/comparator/moNeighborComparator.h @@ -39,13 +39,14 @@ #include #include +#include /** * Comparator of two neighbors */ template< class Neighbor > -class moNeighborComparator : public eoBF +class moNeighborComparator : public moComparator { public: diff --git a/branches/newMo/src/comparator/moSolNeighborComparator.h b/branches/newMo/src/comparator/moSolNeighborComparator.h index 536a65deb..2e8027d98 100644 --- a/branches/newMo/src/comparator/moSolNeighborComparator.h +++ b/branches/newMo/src/comparator/moSolNeighborComparator.h @@ -39,13 +39,14 @@ #include #include +#include /** * Comparator of two neighbors */ template< class Neighbor > -class moSolNeighborComparator : public eoBF +class moSolNeighborComparator : public moComparator { public: typedef typename Neighbor::EOT EOT ; diff --git a/branches/newMo/test/CMakeLists.txt b/branches/newMo/test/CMakeLists.txt index 6a8f5de9a..0bd6d16c0 100644 --- a/branches/newMo/test/CMakeLists.txt +++ b/branches/newMo/test/CMakeLists.txt @@ -34,7 +34,10 @@ SET (TEST_LIST t-moOrderNeighborhood t-moFullEvalByCopy t-moFullEvalByModif - t-moSimpleHCexplorer) + t-moSimpleHCexplorer + t-moNeighborComparator + t-moSolNeighborComparator + ) FOREACH (test ${TEST_LIST}) SET ("T_${test}_SOURCES" "${test}.cpp") diff --git a/branches/newMo/test/t-moNeighborComparator.cpp b/branches/newMo/test/t-moNeighborComparator.cpp new file mode 100644 index 000000000..5d694bebf --- /dev/null +++ b/branches/newMo/test/t-moNeighborComparator.cpp @@ -0,0 +1,67 @@ +/* + + 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 +*/ + +#include +#include +#include +#include + +#include +#include + +int main(){ + + std::cout << "[t-moNeighborComparator] => START" << std::endl; + + + moBitNeighbor neighbor1; + moBitNeighbor neighbor2; + + moNeighborComparator< moBitNeighbor > test; + + neighbor1.fitness(3); + neighbor2.fitness(2); + //test with a minimizing fitness neighbor2 must be better than neighbor1 and reversly + assert(test(neighbor1, neighbor2)); + assert(!test(neighbor2, neighbor1)); + + //test equals + assert(!test.equals(neighbor1,neighbor2)); + + neighbor2.fitness(3); + assert(test.equals(neighbor1,neighbor2)); + + std::cout << "[t-moNeighborComparator] => OK" << std::endl; + return EXIT_SUCCESS; +} diff --git a/branches/newMo/test/t-moSolNeighborComparator.cpp b/branches/newMo/test/t-moSolNeighborComparator.cpp new file mode 100644 index 000000000..b811e70e6 --- /dev/null +++ b/branches/newMo/test/t-moSolNeighborComparator.cpp @@ -0,0 +1,71 @@ +/* + + 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 +*/ + +#include +#include +#include +#include + +#include +#include + +int main(){ + + std::cout << "[t-moSolNeighborComparator] => START" << std::endl; + + moBitNeighbor neighbor; + eoBit sol; + + moSolNeighborComparator< moBitNeighbor > test; + + neighbor.fitness(3); + sol.fitness(2); + //test with a minimizing fitness, neighbor must not be better than sol + assert(!test(sol, neighbor)); + + //reversly + neighbor.fitness(2); + sol.fitness(3); + assert(test(sol, neighbor)); + + //test equals + assert(!test.equals(sol, neighbor)); + + neighbor.fitness(3); + assert(test.equals(sol, neighbor)); + + + std::cout << "[t-moSolNeighborComparator] => OK" << std::endl; + return EXIT_SUCCESS; +}