Comparator updated and test added
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1694 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
8f1cdb68d5
commit
4e00b61d79
6 changed files with 150 additions and 16 deletions
|
|
@ -52,22 +52,13 @@
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comparator of two solutions
|
* Comparator of two types
|
||||||
*/
|
*/
|
||||||
template< class EOT >
|
template< class T1, class T2 >
|
||||||
class moComparator : public eoBF<const EOT & , const EOT & , bool>
|
class moComparator : public eoBF<const T1 & , const T2 & , bool>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual bool equals(const T1&, const T2&) = 0;
|
||||||
/**
|
|
||||||
* 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 id.
|
||||||
|
|
|
||||||
|
|
@ -39,13 +39,14 @@
|
||||||
#include <eoFunctor.h>
|
#include <eoFunctor.h>
|
||||||
|
|
||||||
#include <neighborhood/moNeighbor.h>
|
#include <neighborhood/moNeighbor.h>
|
||||||
|
#include <comparator/moComparator.h>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comparator of two neighbors
|
* Comparator of two neighbors
|
||||||
*/
|
*/
|
||||||
template< class Neighbor >
|
template< class Neighbor >
|
||||||
class moNeighborComparator : public eoBF<const Neighbor & , const Neighbor & , bool>
|
class moNeighborComparator : public moComparator<Neighbor, Neighbor>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,13 +39,14 @@
|
||||||
#include <eoFunctor.h>
|
#include <eoFunctor.h>
|
||||||
|
|
||||||
#include <neighborhood/moNeighbor.h>
|
#include <neighborhood/moNeighbor.h>
|
||||||
|
#include <comparator/moComparator.h>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comparator of two neighbors
|
* Comparator of two neighbors
|
||||||
*/
|
*/
|
||||||
template< class Neighbor >
|
template< class Neighbor >
|
||||||
class moSolNeighborComparator : public eoBF<const typename Neighbor::EOT & , const Neighbor & , bool>
|
class moSolNeighborComparator : public moComparator<typename Neighbor::EOT, Neighbor>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Neighbor::EOT EOT ;
|
typedef typename Neighbor::EOT EOT ;
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,10 @@ SET (TEST_LIST
|
||||||
t-moOrderNeighborhood
|
t-moOrderNeighborhood
|
||||||
t-moFullEvalByCopy
|
t-moFullEvalByCopy
|
||||||
t-moFullEvalByModif
|
t-moFullEvalByModif
|
||||||
t-moSimpleHCexplorer)
|
t-moSimpleHCexplorer
|
||||||
|
t-moNeighborComparator
|
||||||
|
t-moSolNeighborComparator
|
||||||
|
)
|
||||||
|
|
||||||
FOREACH (test ${TEST_LIST})
|
FOREACH (test ${TEST_LIST})
|
||||||
SET ("T_${test}_SOURCES" "${test}.cpp")
|
SET ("T_${test}_SOURCES" "${test}.cpp")
|
||||||
|
|
|
||||||
67
branches/newMo/test/t-moNeighborComparator.cpp
Normal file
67
branches/newMo/test/t-moNeighborComparator.cpp
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
<t-moNeighborComparator.cpp>
|
||||||
|
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 <neighborhood/moBitNeighbor.h>
|
||||||
|
#include <comparator/moNeighborComparator.h>
|
||||||
|
#include <ga/eoBit.h>
|
||||||
|
#include <eoScalarFitness.h>
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
|
||||||
|
std::cout << "[t-moNeighborComparator] => START" << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
moBitNeighbor<eoMinimizingFitness> neighbor1;
|
||||||
|
moBitNeighbor<eoMinimizingFitness> neighbor2;
|
||||||
|
|
||||||
|
moNeighborComparator< moBitNeighbor<eoMinimizingFitness> > 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;
|
||||||
|
}
|
||||||
71
branches/newMo/test/t-moSolNeighborComparator.cpp
Normal file
71
branches/newMo/test/t-moSolNeighborComparator.cpp
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
<t-moSolNeighborComparator.cpp>
|
||||||
|
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 <neighborhood/moBitNeighbor.h>
|
||||||
|
#include <eoScalarFitness.h>
|
||||||
|
#include <comparator/moSolNeighborComparator.h>
|
||||||
|
#include <ga/eoBit.h>
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
|
||||||
|
std::cout << "[t-moSolNeighborComparator] => START" << std::endl;
|
||||||
|
|
||||||
|
moBitNeighbor<eoMinimizingFitness> neighbor;
|
||||||
|
eoBit<eoMinimizingFitness> sol;
|
||||||
|
|
||||||
|
moSolNeighborComparator< moBitNeighbor<eoMinimizingFitness> > 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;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue