Tests of new files added.

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1197 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2008-05-28 13:30:27 +00:00
commit a8723080f8
9 changed files with 1376 additions and 3 deletions

View file

@ -34,7 +34,7 @@ SET (TEST_LIST
t-moeo
t-moeoBitVector
t-moeoRealVector
t-moeoArchive
t-moeoUnboundedArchive
t-moeoParetoObjectiveVectorComparator
t-moeoAggregativeComparator
t-moeoDiversityThenFitnessComparator
@ -49,6 +49,13 @@ SET (TEST_LIST
t-moeoNSGAII
t-moeoMax3Obj
t-moeoEasyEA
t-moeoDominanceCountFitnessAssignment
t-moeoDominanceRankFitnessAssignment
t-moeoDominanceCountRankingFitnessAssignment
t-moeoNearestNeighborDiversityAssignment
t-moeoSPEA2Archive
t-moeoSPEA2
t-moeoDominanceMatrix
)
FOREACH (test ${TEST_LIST})

View file

@ -0,0 +1,183 @@
/*
* <t-moeoDominanceCountFitnessAssignment.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Lille-Nord Europe, 2006-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* Arnaud Liefooghe
* Jeremie 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
*
*/
//-----------------------------------------------------------------------------
// t-moeoDominanceCountFitnessAssignment.cpp
//-----------------------------------------------------------------------------
#include <eo>
#include <moeo>
//-----------------------------------------------------------------------------
class ObjectiveVectorTraits : public moeoObjectiveVectorTraits
{
public:
static bool minimizing (int i)
{
return true;
}
static bool maximizing (int i)
{
return false;
}
static unsigned int nObjectives ()
{
return 2;
}
};
typedef moeoRealObjectiveVector < ObjectiveVectorTraits > ObjectiveVector;
typedef MOEO < ObjectiveVector, double, double > Solution;
//-----------------------------------------------------------------------------
int test(const eoPop < Solution >& _pop, const moeoUnboundedArchive < Solution >& _archive, int _pop0, int _pop1, int _pop2, int _pop3, int _arch0, int _arch1, int _arch2) {
// pop[0]
if (_pop[0].fitness() != _pop0)
{
std::cout << "ERROR (bad fitness for pop[0])" << std::endl;
return EXIT_FAILURE;
}
// pop[1]
if (_pop[1].fitness() != _pop1)
{
std::cout << "ERROR (bad fitness for pop[1])" << std::endl;
return EXIT_FAILURE;
}
// pop[2]
if (_pop[2].fitness() != _pop2)
{
std::cout << "ERROR (bad fitness for pop[2])" << std::endl;
return EXIT_FAILURE;
}
// pop[3]
if (_pop[3].fitness() != _pop3)
{
std::cout << "ERROR (bad fitness for pop[3]) " << std::endl;
return EXIT_FAILURE;
}
// archive[0]
if ((_arch0 >= 0 ) && (_archive[0].fitness() != _arch0))
{
std::cout << "ERROR (bad fitness archive[0])" << std::endl;
return EXIT_FAILURE;
}
// archive[1]
if ((_arch1 >= 0 ) && (_archive[1].fitness() != _arch1))
{
std::cout << "ERROR (bad fitness for archive[1])" << std::endl;
return EXIT_FAILURE;
}
// archive[2]
if ((_arch2 >= 0) && (_archive[2].fitness() != _arch2))
{
std::cout << "ERROR (bad fitness for archive[2])" << std::endl;
return EXIT_FAILURE;
}
return 0;
}
int main()
{
int res=EXIT_SUCCESS;
std::cout << "[moeoDominanceCountFitnessAssignment]\n\n";
// objective vectors
ObjectiveVector obj0, obj1, obj2, obj3, obj4, obj5, obj6;
obj0[0] = 2;
obj0[1] = 5;
obj1[0] = 3;
obj1[1] = 3;
obj2[0] = 4;
obj2[1] = 1;
obj3[0] = 5;
obj3[1] = 5;
obj4[0] = 5;
obj4[1] = 1;
obj5[0] = 3;
obj5[1] = 3;
obj6[0] = 4;
obj6[1] = 4;
// population
eoPop < Solution > pop;
pop.resize(4);
pop[0].objectiveVector(obj0); // class 1
pop[1].objectiveVector(obj1); // class 1
pop[2].objectiveVector(obj2); // class 1
pop[3].objectiveVector(obj3); // class 3
moeoUnboundedArchive < Solution > archive;
archive.resize(3);
archive[0].objectiveVector(obj4);
archive[1].objectiveVector(obj5);
archive[2].objectiveVector(obj6);
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
// fitness assignment
moeoDominanceCountFitnessAssignment< Solution > fitnessAssignment(false);
moeoDominanceCountFitnessAssignment< Solution > fitnessAssignment2(archive,false);
moeoDominanceCountFitnessAssignment< Solution > fitnessAssignment3(paretoComparator);
moeoDominanceCountFitnessAssignment< Solution > fitnessAssignment4(paretoComparator, archive);
std::cout << "Constructor without parameter => ";
fitnessAssignment(pop);
if (test(pop, archive, 1, 1, 1, 0, -1, -1, -1) == 0)
std::cout << "OK" << std::endl;
else
res=EXIT_FAILURE;
std::cout << "Constructor with archive passed in parameter => ";
fitnessAssignment2(pop);
if (test(pop, archive, 1, 2, 3, 0, 1, 2, 1) == 0)
std::cout << "OK" << std::endl;
else
res=EXIT_FAILURE;
return res;
}
//-----------------------------------------------------------------------------

View file

@ -0,0 +1,187 @@
/*
* <t-moeoDominanceCountRankingFitnessAssignment.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Lille-Nord Europe, 2006-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* Arnaud Liefooghe
* Jeremie 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
*
*/
//-----------------------------------------------------------------------------
// t-moeoDominanceCountRankingFitnessAssignment.cpp
//-----------------------------------------------------------------------------
#include <eo>
#include <moeo>
#include <limits>
//-----------------------------------------------------------------------------
class ObjectiveVectorTraits : public moeoObjectiveVectorTraits
{
public:
static bool minimizing (int i)
{
return true;
}
static bool maximizing (int i)
{
return false;
}
static unsigned int nObjectives ()
{
return 2;
}
};
typedef moeoRealObjectiveVector < ObjectiveVectorTraits > ObjectiveVector;
typedef MOEO < ObjectiveVector, double, double > Solution;
//-----------------------------------------------------------------------------
int test(const eoPop < Solution >& _pop, const moeoUnboundedArchive < Solution >& _archive, double _pop0, double _pop1, double _pop2, double _pop3, double _arch0, double _arch1, double _arch2) {
// pop[0]
if (_pop[0].fitness() != _pop0)
{
std::cout << "ERROR (bad fitness for pop[0])" << std::endl;
return EXIT_FAILURE;
}
// pop[1]
if (_pop[1].fitness() != _pop1)
{
std::cout << "ERROR (bad fitness for pop[1])" << std::endl;
return EXIT_FAILURE;
}
// pop[2]
if (_pop[2].fitness() != _pop2)
{
std::cout << "ERROR (bad fitness for pop[2])" << std::endl;
return EXIT_FAILURE;
}
// pop[3]
if (_pop[3].fitness() != _pop3)
{
std::cout << "ERROR (bad fitness for pop[3]) " << std::endl;
return EXIT_FAILURE;
}
// archive[0]
if ((_arch0 <= 0 ) && (_archive[0].fitness() != _arch0))
{
std::cout << "ERROR (bad fitness archive[0])" << std::endl;
return EXIT_FAILURE;
}
// archive[1]
if ((_arch1 <= 0 ) && (_archive[1].fitness() != _arch1))
{
std::cout << "ERROR (bad fitness for archive[1])" << std::endl;
return EXIT_FAILURE;
}
// archive[2]
if ((_arch2 <= 0) && (_archive[2].fitness() != _arch2))
{
std::cout << "ERROR (bad fitness for archive[2])" << std::endl;
return EXIT_FAILURE;
}
return 0;
}
int main()
{
int res=EXIT_SUCCESS;
const double infinity = std::numeric_limits< double >::infinity();
std::cout << "[moeoDominanceCountRankingFitnessAssignment]\n";
// objective vectors
ObjectiveVector obj0, obj1, obj2, obj3, obj4, obj5, obj6;
obj0[0] = 2;
obj0[1] = 5;
obj1[0] = 3;
obj1[1] = 3;
obj2[0] = 4;
obj2[1] = 1;
obj3[0] = 5;
obj3[1] = 5;
obj4[0] = 5;
obj4[1] = 1;
obj5[0] = 3;
obj5[1] = 3;
obj6[0] = 4;
obj6[1] = 4;
// population
eoPop < Solution > pop;
pop.resize(4);
pop[0].objectiveVector(obj0); // class 1
pop[1].objectiveVector(obj1); // class 1
pop[2].objectiveVector(obj2); // class 1
pop[3].objectiveVector(obj3); // class 3
moeoUnboundedArchive < Solution > archive;
archive.resize(3);
archive[0].objectiveVector(obj4);
archive[1].objectiveVector(obj5);
archive[2].objectiveVector(obj6);
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
// fitness assignment
moeoDominanceCountRankingFitnessAssignment <Solution> fitnessAssignment;
moeoDominanceCountRankingFitnessAssignment <Solution> fitnessAssignment2(archive);
moeoDominanceCountRankingFitnessAssignment <Solution> fitnessAssignment3(paretoComparator,false);
moeoDominanceCountRankingFitnessAssignment <Solution> fitnessAssignment4(paretoComparator, archive,false);
std::cout << "Constructor without parameter => ";
fitnessAssignment(pop);
if (test(pop, archive, 0, 0, 0, -3, 1, 1, 1) == 0)
std::cout << "OK" << std::endl;
else
res=EXIT_FAILURE;
std::cout << "Constructor with archive passed in parameter => ";
fitnessAssignment2(pop);
for (int k=0; k<pop.size();k++)
std::cout << "pop " << k << " : " << pop[k].fitness() << "\n";
for (int k=0; k<archive.size();k++)
std::cout << "archive " << k << " : " << archive[k].fitness() << "\n";
if (test(pop, archive, 0, -14, 0, -13, -4, 0, -7) == 0)
std::cout << "OK" << std::endl;
else
res=EXIT_FAILURE;
return res;
}
//-----------------------------------------------------------------------------

View file

@ -0,0 +1,212 @@
/*
* <t-moeoDominanceMatrix.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Lille-Nord Europe, 2006-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* Arnaud Liefooghe
* Jeremie 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
*
*/
//-----------------------------------------------------------------------------
// t-moeoDominanceMatrix.cpp
//-----------------------------------------------------------------------------
#include <eo>
#include <moeo>
#include <assert.h>
#include <set>
#include <iostream>
//-----------------------------------------------------------------------------
class ObjectiveVectorTraits : public moeoObjectiveVectorTraits
{
public:
static bool minimizing (int i)
{
return true;
}
static bool maximizing (int i)
{
return false;
}
static unsigned int nObjectives ()
{
return 2;
}
};
typedef moeoRealObjectiveVector < ObjectiveVectorTraits > ObjectiveVector;
typedef MOEO < ObjectiveVector, double, double > Solution;
//-----------------------------------------------------------------------------
int main()
{
int res=EXIT_SUCCESS;
std::cout << "[moeoDominanceMatrix]\n\n";
// objective vectors
ObjectiveVector obj0, obj1, obj2, obj3, obj4, obj5, obj6;
obj0[0] = 2;
obj0[1] = 5;
obj1[0] = 3;
obj1[1] = 3;
obj2[0] = 4;
obj2[1] = 1;
obj3[0] = 5;
obj3[1] = 5;
obj4[0] = 5;
obj4[1] = 1;
obj5[0] = 3;
obj5[1] = 3;
obj6[0] = 4;
obj6[1] = 4;
// population
eoPop < Solution > pop;
pop.resize(4);
pop[0].objectiveVector(obj0); // class 1
pop[1].objectiveVector(obj1); // class 1
pop[2].objectiveVector(obj2); // class 1
pop[3].objectiveVector(obj3); // class 3
moeoUnboundedArchive < Solution > archive;
archive.resize(3);
archive[0].objectiveVector(obj4);
archive[1].objectiveVector(obj5);
archive[2].objectiveVector(obj6);
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
// fitness assignment
moeoDominanceMatrix< Solution > matrix;
moeoDominanceMatrix< Solution > matrix2(paretoComparator, false);
//test operator() with 2 parameters
matrix(pop,archive);
//test result of matrix
for (unsigned int i=0; i<7; i++)
for (unsigned int j=0; j<3; j++)
assert(!matrix[i][j]);
assert(matrix[0][3]);
assert(matrix[0][5]);
assert(matrix[1][3]);
assert(matrix[1][5]);
assert(matrix[1][6]);
assert(matrix[2][3]);
assert(matrix[2][4]);
assert(matrix[2][5]);
assert(matrix[2][6]);
assert(matrix[3][5]);
assert(matrix[4][3]);
assert(matrix[4][5]);
assert(matrix[6][3]);
assert(matrix[6][5]);
assert(!matrix[0][4]);
assert(!matrix[0][6]);
assert(!matrix[1][4]);
assert(!matrix[3][3]);
assert(!matrix[3][4]);
assert(!matrix[3][6]);
assert(!matrix[4][4]);
assert(!matrix[4][6]);
assert(!matrix[5][3]);
assert(!matrix[5][4]);
assert(!matrix[5][5]);
assert(!matrix[5][6]);
assert(!matrix[6][4]);
assert(!matrix[6][6]);
//test methode count
assert(matrix.count(0)==2);
assert(matrix.count(1)==3);
assert(matrix.count(2)==4);
assert(matrix.count(3)==1);
assert(matrix.count(4)==2);
assert(matrix.count(5)==0);
assert(matrix.count(6)==2);
//test methode rank
assert(matrix.rank(0)==0);
assert(matrix.rank(1)==0);
assert(matrix.rank(2)==0);
assert(matrix.rank(3)==5);
assert(matrix.rank(4)==1);
assert(matrix.rank(5)==6);
assert(matrix.rank(6)==2);
//test operator() with one parameter
matrix2(archive);
assert(!matrix2[0][0]);
assert(!matrix2[0][1]);
assert(!matrix2[0][2]);
assert(!matrix2[1][0]);
assert(!matrix2[1][1]);
assert(matrix2[1][2]);
assert(!matrix2[2][0]);
assert(!matrix2[2][1]);
assert(!matrix2[2][2]);
assert(matrix2.count(0)==0);
assert(matrix2.count(1)==1);
assert(matrix2.count(2)==0);
assert(matrix2.rank(0)==0);
assert(matrix2.rank(1)==0);
assert(matrix2.rank(2)==1);
std::set<int> hop;
hop.insert(2);
hop.insert(2);
hop.insert(10);
hop.insert(3);
hop.insert(45);
hop.insert(45);
hop.insert(45);
std::set<int>::iterator it=hop.begin();
while (it!=hop.end()) {
std::cout << *it << "\n";
it++;
}
std::cout << "OK";
return EXIT_SUCCESS;
}
//-----------------------------------------------------------------------------

View file

@ -0,0 +1,179 @@
/*
* <t-moeoDominanceRankFitnessAssignment.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Lille-Nord Europe, 2006-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* Arnaud Liefooghe
* Jeremie 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
*
*/
//-----------------------------------------------------------------------------
// t-moeoDominanceRankFitnessAssignment.cpp
//-----------------------------------------------------------------------------
#include <eo>
#include <moeo>
//-----------------------------------------------------------------------------
class ObjectiveVectorTraits : public moeoObjectiveVectorTraits
{
public:
static bool minimizing (int i)
{
return true;
}
static bool maximizing (int i)
{
return false;
}
static unsigned int nObjectives ()
{
return 2;
}
};
typedef moeoRealObjectiveVector < ObjectiveVectorTraits > ObjectiveVector;
typedef MOEO < ObjectiveVector, double, double > Solution;
//-----------------------------------------------------------------------------
int test(const eoPop < Solution >& _pop, const moeoUnboundedArchive < Solution >& _archive, int _pop0, int _pop1, int _pop2, int _pop3, int _arch0, int _arch1, int _arch2) {
// pop[0]
if (_pop[0].fitness() != _pop0)
{
std::cout << "ERROR (bad fitness for pop[0])" << std::endl;
return EXIT_FAILURE;
}
// pop[1]
if (_pop[1].fitness() != _pop1)
{
std::cout << "ERROR (bad fitness for pop[1])" << std::endl;
return EXIT_FAILURE;
}
// pop[2]
if (_pop[2].fitness() != _pop2)
{
std::cout << "ERROR (bad fitness for pop[2])" << std::endl;
return EXIT_FAILURE;
}
// pop[3]
if (_pop[3].fitness() != _pop3)
{
std::cout << "ERROR (bad fitness for pop[3]) " << std::endl;
return EXIT_FAILURE;
}
// archive[0]
if ((_arch0 <= 0 ) && (_archive[0].fitness() != _arch0))
{
std::cout << "ERROR (bad fitness archive[0])" << std::endl;
return EXIT_FAILURE;
}
// archive[1]
if ((_arch1 <= 0 ) && (_archive[1].fitness() != _arch1))
{
std::cout << "ERROR (bad fitness for archive[1])" << std::endl;
return EXIT_FAILURE;
}
// archive[2]
if ((_arch2 <= 0) && (_archive[2].fitness() != _arch2))
{
std::cout << "ERROR (bad fitness for archive[2])" << std::endl;
return EXIT_FAILURE;
}
return 0;
}
int main()
{
int res=EXIT_SUCCESS;
std::cout << "[moeoDominanceRankFitnessAssignment]\n";
// objective vectors
ObjectiveVector obj0, obj1, obj2, obj3, obj4, obj5, obj6;
obj0[0] = 2;
obj0[1] = 5;
obj1[0] = 3;
obj1[1] = 3;
obj2[0] = 4;
obj2[1] = 1;
obj3[0] = 5;
obj3[1] = 5;
obj4[0] = 5;
obj4[1] = 1;
obj5[0] = 3;
obj5[1] = 3;
obj6[0] = 4;
obj6[1] = 4;
// population
eoPop < Solution > pop;
pop.resize(4);
pop[0].objectiveVector(obj0); // class 1
pop[1].objectiveVector(obj1); // class 1
pop[2].objectiveVector(obj2); // class 1
pop[3].objectiveVector(obj3); // class 3
moeoUnboundedArchive < Solution > archive;
archive.resize(3);
archive[0].objectiveVector(obj4);
archive[1].objectiveVector(obj5);
archive[2].objectiveVector(obj6);
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
// fitness assignment
moeoDominanceRankFitnessAssignment< Solution > fitnessAssignment;
moeoDominanceRankFitnessAssignment< Solution > fitnessAssignment2(archive, 2.0,true);
moeoDominanceRankFitnessAssignment< Solution > fitnessAssignment3(paretoComparator, 3.0);
moeoDominanceRankFitnessAssignment< Solution > fitnessAssignment4(paretoComparator, archive);
std::cout << "Constructor without parameter => ";
fitnessAssignment(pop);
if (test(pop, archive, -1, -1, -1, -4, 1, 1, 1) == 0)
std::cout << "OK" << std::endl;
else
res=EXIT_FAILURE;
std::cout << "Constructor with archive passed in parameter => ";
fitnessAssignment2(pop);
if (test(pop, archive, -2, -8, -2, -7, -3, -2, -4) == 0)
std::cout << "OK" << std::endl;
else
res=EXIT_FAILURE;
return res;
}
//-----------------------------------------------------------------------------

View file

@ -0,0 +1,225 @@
/*
* <t-moeoFastNonDominatedSortingFitnessAssignment.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Lille-Nord Europe, 2006-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* Arnaud Liefooghe
* Jeremie 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
*
*/
//-----------------------------------------------------------------------------
// t-moeoNearestNeighborDiversityAssignment.cpp
//-----------------------------------------------------------------------------
#include <eo>
#include <moeo>
//-----------------------------------------------------------------------------
class ObjectiveVectorTraits : public moeoObjectiveVectorTraits
{
public:
static bool minimizing (int i)
{
return true;
}
static bool maximizing (int i)
{
return false;
}
static unsigned int nObjectives ()
{
return 2;
}
};
typedef moeoRealObjectiveVector < ObjectiveVectorTraits > ObjectiveVector;
typedef MOEO < ObjectiveVector, double, double > Solution;
//-----------------------------------------------------------------------------
int main()
{
std::cout << "[moeoNearestNeighborDiversityAssignment]\n";
// objective vectors
ObjectiveVector obj0, obj1, obj2, obj3, obj4, obj5, obj6;
obj0[0] = 2;
obj0[1] = 5;
obj1[0] = 3;
obj1[1] = 3;
obj2[0] = 4;
obj2[1] = 1;
obj3[0] = 5;
obj3[1] = 5;
obj4[0] = 5;
obj4[1] = 1;
obj5[0] = 3;
obj5[1] = 3;
obj6[0] = 4;
obj6[1] = 4;
// population
eoPop < Solution > pop;
pop.resize(4);
pop[0].objectiveVector(obj0); // class 1
pop[1].objectiveVector(obj1); // class 1
pop[2].objectiveVector(obj2); // class 1
pop[3].objectiveVector(obj3); // class 3
//archive
moeoUnboundedArchive < Solution > archive;
archive.resize(3);
archive[0].objectiveVector(obj4);
archive[1].objectiveVector(obj5);
archive[2].objectiveVector(obj6);
//distance
moeoEuclideanDistance<Solution> dist;
// diversity assignment
moeoNearestNeighborDiversityAssignment<Solution> diversityAssignment;
moeoNearestNeighborDiversityAssignment<Solution> diversityAssignment2(archive, 2);
moeoNearestNeighborDiversityAssignment<Solution> diversityAssignment3(dist);
moeoNearestNeighborDiversityAssignment<Solution> diversityAssignment4(dist,archive, 2);
int res=EXIT_SUCCESS;
for (unsigned int i=0; i<2; i++) {
float tmp1=0;
float tmp2=0;
if (i==0) {
diversityAssignment(pop);
// pop[0]
tmp1=pop[0].diversity();
tmp2=-1/(2+sqrt(5.0));
if (tmp1 != tmp2)
{
std::cout << "ERROR (bad diversity for pop[0])" << std::endl;
res=EXIT_FAILURE;
}
// pop[1]
tmp1=pop[1].diversity();
tmp2=-1/(2+sqrt(5.0));
if (tmp1 != tmp2)
{
std::cout << "ERROR (bad diversity for pop[1])" << std::endl;
res=EXIT_FAILURE;
}
// pop[2]
tmp1=pop[2].diversity();
tmp2=-1/(2+sqrt(5.0));
if (tmp1 != tmp2)
{
std::cout << "ERROR (bad diversity for pop[2])" << std::endl;
res=EXIT_FAILURE;
}
// pop[3]
tmp1=pop[3].diversity();
tmp2=-1/(2+sqrt(8.0));
if (tmp1 != tmp2)
{
std::cout << "ERROR (bad diversity for pop[3]) " << std::endl;
res=EXIT_FAILURE;
}
}
else {
diversityAssignment4(pop);
// pop[0]
tmp1=pop[0].diversity();
tmp2=-1/(2+sqrt(5.0));
if (tmp1 != tmp2)
{
std::cout << "ERROR (bad diversity for pop[0])" << std::endl;
res=EXIT_FAILURE;
}
// pop[1]
tmp1=pop[1].diversity();
tmp2=-1/(2+sqrt(2.0));
if (tmp1 != tmp2)
{
std::cout << "ERROR (bad diversity for pop[1])" << std::endl;
res=EXIT_FAILURE;
}
// pop[2]
tmp1=pop[2].diversity();
tmp2=-1/(2+sqrt(5.0));
if (tmp1 != tmp2)
{
std::cout << "ERROR (bad diversity for pop[2])" << std::endl;
res=EXIT_FAILURE;
}
// pop[3]
tmp1=pop[3].diversity();
tmp2=-1/(2+sqrt(8.0));
if (tmp1 != tmp2)
{
std::cout << "ERROR (bad diversity for pop[3]) " << std::endl;
res=EXIT_FAILURE;
}
// archive[0]
tmp1=archive[0].diversity();
tmp2=-1/(2+sqrt(8.0));
if (tmp1 != tmp2)
{
std::cout << "ERROR (bad diversity archive[0])" << std::endl;
res=EXIT_FAILURE;
}
// archive[1]
tmp1=archive[1].diversity();
tmp2=-1/(2+sqrt(2.0));
if (tmp1 != tmp2)
{
std::cout << "ERROR (bad diversity for archive[1])" << std::endl;
res=EXIT_FAILURE;
}
// archive[2]
tmp1=archive[2].diversity();
tmp2=-1/(2+sqrt(2.0));
if (tmp1 != tmp2)
{
std::cout << "ERROR (bad diversity for archive[2])" << std::endl;
res=EXIT_FAILURE;
}
}
}
std::cout << "OK" << std::endl;
return res;
}
//-----------------------------------------------------------------------------

View file

@ -0,0 +1,128 @@
/*
* <t-moeoSPEA2.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Lille-Nord Europe, 2006-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* Arnaud Liefooghe
* Jeremie 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
*
*/
//-----------------------------------------------------------------------------
// t-moeoSPEA2.cpp
//-----------------------------------------------------------------------------
#include <eo>
#include <es/eoRealInitBounded.h>
#include <es/eoRealOp.h>
#include <moeo>
//-----------------------------------------------------------------------------
class ObjectiveVectorTraits : public moeoObjectiveVectorTraits
{
public:
static bool minimizing (int i)
{
return true;
}
static bool maximizing (int i)
{
return false;
}
static unsigned int nObjectives ()
{
return 2;
}
};
typedef moeoRealObjectiveVector < ObjectiveVectorTraits > ObjectiveVector;
class Solution : public moeoRealVector < ObjectiveVector, double, double >
{
public:
Solution() : moeoRealVector < ObjectiveVector, double, double > (1) {}
};
class TestEval : public moeoEvalFunc < Solution >
{
public:
void operator () (Solution & _sol)
{
ObjectiveVector objVec;
objVec[0] = _sol[0];
objVec[1] = _sol[0] * _sol[0];
_sol.objectiveVector(objVec);
}
};
//-----------------------------------------------------------------------------
int main()
{
std::cout << "[moeoSPEA2]" << std::endl;
TestEval eval;
eoQuadCloneOp < Solution > xover;
eoUniformMutation < Solution > mutation(0.05);
eoRealVectorBounds bounds(1, 1.0, 2.0);
eoRealInitBounded < Solution > init(bounds);
eoPop < Solution > pop(20, init);
eoQuadGenOp <Solution> genOp(xover);
eoSGATransform < Solution > transform(xover, 0.1, mutation, 0.1);
eoGenContinue <Solution > continuator(10);
moeoSPEA2Archive < Solution > archive(3);
eoPopLoopEval <Solution> loopEval(eval);
eoPopEvalFunc <Solution>& popEval(loopEval);
// build NSGA-II
moeoSPEA2 < Solution > algo(20, eval, xover, 1.0, mutation, 1.0,archive);
moeoSPEA2 < Solution > algo2(continuator, eval, xover, 1.0, mutation, 1.0,archive);
moeoSPEA2 < Solution > algo3(continuator, popEval, xover, 1.0, mutation, 1.0,archive);
moeoSPEA2 < Solution > algo4(continuator, eval, genOp, archive);
moeoSPEA2 < Solution > algo5(continuator, popEval, genOp, archive);
moeoSPEA2 < Solution > algo6(continuator, eval, transform, archive);
moeoSPEA2 < Solution > algo7(continuator, popEval, transform, archive);
// run the algo
algo7(pop);
// final pop
std::cout << "Final population" << std::endl;
std::cout << pop << std::endl;
std::cout << "[moeoSPEA2] OK" << std::endl;
return EXIT_SUCCESS;
}
//-----------------------------------------------------------------------------

View file

@ -0,0 +1,252 @@
/*
* <t-moeoSPEA2Archive.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Lille-Nord Europe, 2006-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* Arnaud Liefooghe
* Jeremie 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
*
*/
//-----------------------------------------------------------------------------
// t-moeoSPEA2Archive.cpp
//-----------------------------------------------------------------------------
#include <eo>
#include <moeo>
//-----------------------------------------------------------------------------
class ObjectiveVectorTraits : public moeoObjectiveVectorTraits
{
public:
static bool minimizing (int i)
{
return true;
}
static bool maximizing (int i)
{
return false;
}
static unsigned int nObjectives ()
{
return 2;
}
};
typedef moeoRealObjectiveVector < ObjectiveVectorTraits > ObjectiveVector;
typedef MOEO < ObjectiveVector, double, double > Solution;
//-----------------------------------------------------------------------------
int main()
{
std::cout << "[moeoSPEA2Archive] => ";
float tmp1=0;
float tmp2=0;
// objective vectors
ObjectiveVector obj0, obj1, obj2, obj3;
obj0[0] = 2;
obj0[1] = 1;
obj1[0] = 1;
obj1[1] = 2;
obj2[0] = 0;
obj2[1] = 4;
obj3[0] = 5;
obj3[1] = 0;
// population
eoPop < Solution > pop;
pop.resize(4);
pop[0].objectiveVector(obj0);
pop[1].objectiveVector(obj1);
pop[2].objectiveVector(obj2);
pop[3].objectiveVector(obj3);
//distance
moeoEuclideanDistance<Solution> dist;
//objective vector comparator
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
//comparator
moeoFitnessThenDiversityComparator < Solution > indiComparator;
//archive
moeoSPEA2Archive<Solution> archive(dist,3);
moeoSPEA2Archive<Solution> archive2;
moeoSPEA2Archive<Solution> archive3(indiComparator,1);
moeoSPEA2Archive<Solution> archive4(paretoComparator);
moeoSPEA2Archive<Solution> archive5(indiComparator, dist, paretoComparator, 3);
// diversity assignment
moeoNearestNeighborDiversityAssignment<Solution> diversityassignement(dist,archive, 2);
diversityassignement(pop);
// fitness assignment
moeoDominanceCountRankingFitnessAssignment <Solution> fitnessassignement(archive,false);
fitnessassignement(pop);
//-----------------------------------------------------------------------------
//first test archive: the archive is empty -> the best element of the pop must be copy in the archive.
archive(pop);
//archive[0]
tmp1=archive[0].diversity();
tmp2=-1/(2+sqrt(20.0));
if ( (tmp1 != tmp2) || (archive[0].fitness() != 0.0) )
{
std::cout << "ERROR (Test 1: bad result for archive[0])" << std::endl;
return EXIT_FAILURE;
}
//archive[1]
tmp1=archive[1].diversity();
tmp2=-1/(2+sqrt(13.0));
if ( (tmp1 != tmp2) || (archive[1].fitness() != 0.0) )
{
std::cout << "ERROR (Test 1: bad result for archive[1])" << std::endl;
return EXIT_FAILURE;
}
//archive[2]
tmp1=archive[2].diversity();
tmp2=-1/(2+sqrt(10.0));
if ( (tmp1 != tmp2) || (archive[2].fitness() != 0.0) )
{
std::cout << "ERROR (Test 1: bad result for archive[2])" << std::endl;
return EXIT_FAILURE;
}
//-----------------------------------------------------------------------------
obj0[0] = 3;
obj0[1] = 1;
obj1[0] = 2;
obj1[1] = 2;
obj3[0] = 1;
obj3[1] = 3;
pop[0].objectiveVector(obj0);
pop[1].objectiveVector(obj1);
pop[3].objectiveVector(obj3);
diversityassignement(pop);
fitnessassignement(pop);
//-----------------------------------------------------------------------------
//second test archive : (there are more elements with fitness=0 than the size of the archive)
//depends of the good result of the first test
archive(pop);
//archive[0]
tmp1=archive[0].diversity();
tmp2=-1/3.0;
if ( (tmp1 != tmp2) || (archive[0].fitness() != 0.0) )
{
std::cout << "ERROR (Test 2: bad result for archive[0])" << std::endl;
return EXIT_FAILURE;
}
//archive[1]
tmp1=archive[1].diversity();
tmp2=-1/(2+sqrt(2.0));
if ( (tmp1 != tmp2) || (archive[1].fitness() != 0.0) )
{
std::cout << "ERROR (Test 2: bad result for archive[1])" << std::endl;
return EXIT_FAILURE;
}
//archive[2]
tmp1=archive[2].diversity();
tmp2=-1/(2+sqrt(10.0));
if ( (tmp1 != tmp2) || (archive[2].fitness() != 0.0) )
{
std::cout << "ERROR (Test 2: bad result for archive[2])" << std::endl;
return EXIT_FAILURE;
}
//-----------------------------------------------------------------------------
obj0[0] = 5;
obj0[1] = 5;
obj1[0] = 4;
obj1[1] = 4;
obj2[0] = 4;
obj2[1] = 5;
obj3[0] = 4;
obj3[1] = 0;
pop[0].objectiveVector(obj0);
pop[1].objectiveVector(obj1);
pop[2].objectiveVector(obj2);
pop[3].objectiveVector(obj3);
diversityassignement(pop);
fitnessassignement(pop);
//-----------------------------------------------------------------------------
//third test archive : a pop element with fitness=0 replace a worst archive element
//depends of the good result of the two first tests
archive(pop);
//archive[0]
tmp1=archive[0].diversity();
tmp2=-1/(2+sqrt(16.0));
if ( (tmp1 != tmp2) || (archive[0].fitness() != 0.0) )
{
std::cout << "ERROR (Test 3: bad result for archive[0])" << std::endl;
return EXIT_FAILURE;
}
//archive[1]
tmp1=archive[1].diversity();
tmp2=-1/(2+sqrt(10.0));
if ( (tmp1 != tmp2) || (archive[1].fitness() != -0.0) )
{
std::cout << "ERROR (Test 3: bad result for archive[1])" << std::endl;
return EXIT_FAILURE;
}
//archive[2]
tmp1=archive[2].diversity();
tmp2=-1/(2+sqrt(5.0));
if ( (tmp1 != tmp2) || (archive[2].fitness() != 0.0) )
{
std::cout << "ERROR (Test 3: bad result for archive[2])" << std::endl;
return EXIT_FAILURE;
}
//-----------------------------------------------------------------------------
archive(pop[0]);
std::cout << "OK" << std::endl;
return EXIT_SUCCESS;
}
//-----------------------------------------------------------------------------

View file

@ -95,8 +95,8 @@ int main()
pop[5].objectiveVector(obj5);
// archive
moeoArchive< Solution > arch;
arch.update(pop);
moeoUnboundedArchive< Solution > arch;
arch(pop);
// size
if (arch.size() != 3)