diff --git a/trunk/paradiseo-moeo/test/CMakeLists.txt b/trunk/paradiseo-moeo/test/CMakeLists.txt index e40e7c8d5..3b928247a 100644 --- a/trunk/paradiseo-moeo/test/CMakeLists.txt +++ b/trunk/paradiseo-moeo/test/CMakeLists.txt @@ -71,7 +71,8 @@ SET (TEST_LIST t-moeoDetArchiveSelect t-moeoASEEA #t-moeoEpsilonHyperboxArchive - t-moeoQuadTreeArchive + t-moeoQuadTreeIndex + t-moeoQuickUnboundedArchiveIndex t-moeoAggregationFitnessAssignment t-moeoConstraintFitnessAssignment t-moeoChebyshevMetric diff --git a/trunk/paradiseo-moeo/test/t-moeoQuadTreeArchive.cpp b/trunk/paradiseo-moeo/test/t-moeoQuadTreeArchive.cpp deleted file mode 100644 index 5e9a522ce..000000000 --- a/trunk/paradiseo-moeo/test/t-moeoQuadTreeArchive.cpp +++ /dev/null @@ -1,186 +0,0 @@ - /* -* -* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 -* (C) OPAC Team, LIFL, 2002-2007 -* -* Arnaud Liefooghe -* -* 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-moeoEpsilonHyperboxArchive.cpp -//----------------------------------------------------------------------------- - -#include -#include -#include - -//----------------------------------------------------------------------------- - -class ObjectiveVectorTraits : public moeoObjectiveVectorTraits -{ -public: - static bool minimizing (int i) - { - return true; - } - static bool maximizing (int i) - { - return false; - } - static unsigned int nObjectives () - { - return 3; - } -}; - -typedef moeoRealObjectiveVector < ObjectiveVectorTraits > ObjectiveVector; - -typedef MOEO < ObjectiveVector, double, double > Solution; - - - - - -//----------------------------------------------------------------------------- - -int main() -{ - std::cout << "[moeoQuadTreeArchive]\t=>\t"; - moeoQuadTree tree; - - bool empty= tree.isEmpty(); - std::cout <<"empty? " << empty << std::endl; - ObjectiveVector obj1; - obj1[0]=54.0; - obj1[1]=65.0; - obj1[2]=67.0; - ObjectiveVector obj2; - obj2[0]=23.0; - obj2[1]=25.0; - obj2[2]=52.0; - ObjectiveVector obj3; - obj3[0]=87.0; - obj3[1]=5.0; - obj3[2]=33.0; - ObjectiveVector obj4; - obj4[0]=52.0; - obj4[1]=50.0; - obj4[2]=72.0; - ObjectiveVector obj5; - obj5[0]=80.0; - obj5[1]=41.0; - obj5[2]=8.0; - ObjectiveVector obj6; - obj6[0]=26.0; - obj6[1]=0.0; - obj6[2]=5.0; - ObjectiveVector obj7; - obj7[0]=56.0; - obj7[1]=22.0; - obj7[2]=0.0; - ObjectiveVector obj8; - obj8[0]=87.0; - obj8[1]=42.0; - obj8[2]=62.0; - ObjectiveVector obj9; - obj9[0]=90.0; - obj9[1]=69.0; - obj9[2]=83.0; - ObjectiveVector obj10; - obj10[0]=68.0; - obj10[1]=89.0; - obj10[2]=22.0; -// QuadTreeNode hop(obj1); -// QuadTreeNode hop2(obj2); -// QuadTreeNode hop3(obj3); -// QuadTreeNode hop4(obj4); -// empty = hop.getSubTree().empty(); -// std::cout <<"empty? " << empty << std::endl; -// std::vector< QuadTreeNode > nodes; -// nodes.push_back(hop); -// nodes.push_back(hop2); -// nodes.push_back(hop3); -// std::cout << nodes[1].getVec() << std::endl; - -// std::cout << "size: " << nodes.size() << std::endl; - tree.insert(obj1); - tree.insert(obj2); - tree.insert(obj3); - tree.insert(obj4); - tree.insert(obj5); - std::cout << "\n\n\n"; - - tree.insert(obj6); -// tree.insert(obj7); -// tree.insert(obj8); -// tree.insert(obj9); -// tree.insert(obj10); - -// moeoUnboundedArchive archive(false); -// eoPop pop; -// pop.resize(1000); -// int tmp; -// -// for(int i= 0; i<1000 ; i++){ -// ObjectiveVector obj; -// obj[0]=floor(rng.uniform()*100); -// obj[1]=floor(rng.uniform()*100); -// obj[2]=floor(rng.uniform()*100); -// std::cout << obj << std::endl; -// pop[i].objectiveVector(obj); -// tree.insert(obj); -// archive(pop[i]); -// tree.printTree(); -// std::cout << std::endl; -// std::cout << std::endl; -// -// std::cout << "achive: " << archive << std::endl; -// std::cin >> tmp; -// } - - - -// QuadTreeNode * a = tree.getRoot(); -// QuadTreeNode * b = a->getSubTree()[1]; -// QuadTreeNode * c = b->getSubTree()[2]; -// -// tree.reinsert(a,c); - -// std::cout << "achive: " << archive << std::endl; - tree.printTree(); - - - - - std::cout << "OK" << std::endl; - return EXIT_SUCCESS; -} - -//----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-moeo/test/t-moeoQuadTreeIndex.cpp b/trunk/paradiseo-moeo/test/t-moeoQuadTreeIndex.cpp new file mode 100755 index 000000000..0febcec13 --- /dev/null +++ b/trunk/paradiseo-moeo/test/t-moeoQuadTreeIndex.cpp @@ -0,0 +1,333 @@ +//----------------------------------------------------------------------------- +// t-moeoQuickUnboundedArchive.cpp +//----------------------------------------------------------------------------- + +#include +#include +#include +#include +//----------------------------------------------------------------------------- + +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; + } +}; + +class ObjectiveVectorTraits3d : public moeoObjectiveVectorTraits +{ +public: + static bool minimizing (int i) + { + return true ; + } + static bool maximizing (int i) + { + return false ; + } + static unsigned int nObjectives () + { + return 3; + } +}; + + +typedef moeoRealObjectiveVector < ObjectiveVectorTraits > ObjectiveVector; +typedef moeoRealObjectiveVector < ObjectiveVectorTraits3d > ObjectiveVector3d; + +typedef MOEO < ObjectiveVector, double, double > Solution; +typedef MOEO < ObjectiveVector3d, double, double > Solution3d; + +//----------------------------------------------------------------------------- + +int main() +{ + std::cout << "[moeoArchive]\t=>\t"; + // First test is just to verify behavior of moeoQuickUnboundedArchive + // objective vectors + ObjectiveVector obj0, obj1, obj2, obj3, obj4, obj5,obj10; + obj0[0] = 12226; + obj0[1] = 427894; + obj1[0] = 12170; + obj1[1] = 431736; + obj2[0] = 11965; + obj2[1] = 435193; + obj3[0] = 11893; + obj3[1] = 441839; + obj4[0] = 11870; + obj4[1] = 450770; + obj5[0] = 11769; + obj5[1] = 460005; + obj10[0] = 11769; + obj10[1] = 46005; + // population + eoPop < Solution > pop; + pop.resize(6); + pop[0].objectiveVector(obj0); + pop[1].objectiveVector(obj1); + pop[2].objectiveVector(obj2); + pop[3].objectiveVector(obj3); + pop[4].objectiveVector(obj4); + pop[5].objectiveVector(obj5); + + // archive + moeoQuadTree index; + moeoIndexedArchive arch(index); +// moeoQuickUnboundedArchive< Solution > arch; + arch(pop); +// arch.printIndex(); + + // size + if (arch.size() > 6) + { + std::cout << "ERROR1 (too much solutions)" << std::endl; + return EXIT_FAILURE; + } + // obj0 must be in + if (! arch.contains(obj0)) + { + std::cout << "ERROR2 (obj0 not in)" << std::endl; + return EXIT_FAILURE; + } + // obj1 must be in + if (! arch.contains(obj1)) + { + std::cout << "ERROR3 (obj1 not in)" << std::endl; + return EXIT_FAILURE; + } + // obj2 must be in + if (! arch.contains(obj2)) + { + std::cout << "ERROR4 (obj2 not in)" << std::endl; + return EXIT_FAILURE; + } + // obj3 must be in + if (! arch.contains(obj3)) + { + std::cout << "ERROR5 (obj3 not in)" << std::endl; + return EXIT_FAILURE; + } + // obj4 must be in + if (!arch.contains(obj4)) + { + std::cout << "ERROR6 (obj4 not in)! " << obj4<< std::endl; +// arch.printIndex(); + return EXIT_FAILURE; + } + // obj5 must be in + if (! arch.contains(obj5)) + { + std::cout << "ERROR7 (obj5 not in)" << std::endl; + return EXIT_FAILURE; + } + + // Second test is to verify behavior with negative and comparator + ObjectiveVector obj6, obj7; + obj6[0] = -12170; + obj6[1] = 427894; + obj7[0] = -12226; + obj7[1] = 431736; + eoPop < Solution > pop2; + pop2.resize(2); + pop2[0].objectiveVector(obj6); + pop2[1].objectiveVector(obj7); + moeoQuadTree< Solution > index2; + moeoIndexedArchive< Solution > arch2(index2); + arch2(pop2); + + // size + if (arch2.size() != 2) + { + std::cout << "ERROR8 (too much solutions)" << std::endl; + return EXIT_FAILURE; + } + + //Third test is with two equals values + ObjectiveVector obj8, obj9; + obj8[0] = 10; + obj8[1] = 10; + obj9[0] = 10; + obj9[1] = 10; + eoPop < Solution > pop3; + pop3.resize(2); + pop3[0].objectiveVector(obj8); + pop3[1].objectiveVector(obj9); + + moeoQuadTree< Solution > index3; + moeoIndexedArchive< Solution > arch3(index3); + arch3(pop3); + + if (arch3.size() != 1) + { + std::cout << "ERROR9 (too much solutions)" << std::endl; + return EXIT_FAILURE; + } + eoPop < Solution > pop4; + pop4.resize(6); + pop4[0].objectiveVector(obj0); + pop4[1].objectiveVector(obj1); + pop4[2].objectiveVector(obj2); + pop4[3].objectiveVector(obj3); + pop4[4].objectiveVector(obj4); + pop4[5].objectiveVector(obj10); + moeoQuadTree< Solution > index4; + moeoIndexedArchive< Solution > arch4(index4); + arch4(pop4); + if (arch4.size() != 1) + { + std::cout << "ERROR10 (too much solutions)" << std::endl; + return EXIT_FAILURE; + } + + std::vectorbobj; + for (unsigned int i=0;i<3;i++){ + bobj.push_back(false); + } + + ObjectiveVectorTraits3d::setup(3,bobj); + moeoQuadTree < Solution3d> index5; + moeoIndexedArchive < Solution3d> arch5(index5); + eoPop pop5; + pop5.resize(6); + ObjectiveVector3d obj3d0, obj3d1, obj3d2, obj3d3, obj3d4, obj3d5, obj3d6,obj3d10; + obj3d0[0] = 12226; + obj3d0[1] = 427894; + obj3d0[2] = 10; + + obj3d1[0] = 12170; + obj3d1[1] = 431736; + obj3d1[2] = 10; + + obj3d2[0] = 11965; + obj3d2[1] = 435193; + obj3d2[2] = 10; + + obj3d3[0] = 11893; + obj3d3[1] = 441839; + obj3d3[2] = 10; + + obj3d4[0] = 11870; + obj3d4[1] = 450770; + obj3d4[2] = 10; + + obj3d5[0] = 11769; + obj3d5[1] = 46005; + obj3d5[2] = 2; + + obj3d10[0] = 11769; + obj3d10[1] = 46005; + obj3d10[2] = 10; + + obj3d6[0] = 11769; + obj3d6[1] = 460005; + obj3d6[2] = 1; + + + pop5[0].objectiveVector(obj3d0); + pop5[1].objectiveVector(obj3d1); + pop5[2].objectiveVector(obj3d2); + pop5[3].objectiveVector(obj3d3); + pop5[4].objectiveVector(obj3d4); + pop5[5].objectiveVector(obj3d10); + + + + arch5(pop5); + pop5.resize(7); + pop5[6].objectiveVector(obj3d5); + arch5(pop5[6]); +// index5.printTree(); +/* for (unsigned int i=0;i index6; + moeoIndexedArchive < Solution3d> arch6(index6); + eoPop pop6; + + ObjectiveVector3d jojo, jojo1, jojo2, jojo3, jojo4, jojo5, jojo6, jojo7, jojo8, jojo9 ; + jojo[0]=10; + jojo[1]=10; + jojo[2]=10; + + jojo1[0]=5; + jojo1[1]=5; + jojo1[2]=23; + + jojo2[0]=3; + jojo2[1]=25; + jojo2[2]=16; + + jojo3[0]=14; + jojo3[1]=18; + jojo3[2]=6; + + jojo4[0]=100; + jojo4[1]=100; + jojo4[2]=100; + + jojo5[0]=4; + jojo5[1]=8; + jojo5[2]=12; + + + jojo6[0]=11; + jojo6[1]=14; + jojo6[2]=9; + + + jojo7[0]=40; + jojo7[1]=12; + jojo7[2]=3; + + jojo8[0]=12; + jojo8[1]=8; + jojo8[2]=4; + + jojo9[0]=4; + jojo9[1]=4; + jojo9[2]=22; + + pop6.resize(8); + pop6[0].objectiveVector(jojo); + pop6[1].objectiveVector(jojo1); + pop6[2].objectiveVector(jojo2); + pop6[3].objectiveVector(jojo3); + pop6[4].objectiveVector(jojo4); + pop6[5].objectiveVector(jojo5); + pop6[6].objectiveVector(jojo6); + pop6[7].objectiveVector(jojo7); + Solution3d add; + Solution3d add2; + add.objectiveVector(jojo8); + add2.objectiveVector(jojo9); + /* pop[1].objectiveVector(jojo1); + pop[1].objectiveVector(jojo1); + pop[1].objectiveVector(jojo1);*/ + arch6(pop6); + + assert(arch6.size()==7); + bool res=arch6(add); + assert(res && arch6.size()==7); + res=arch6(add2); + assert(res && arch6.size()==7); + std::cout << "OK" << std::endl; + return EXIT_SUCCESS; +} + diff --git a/trunk/paradiseo-moeo/test/t-moeoQuickUnboundedArchiveIndex.cpp b/trunk/paradiseo-moeo/test/t-moeoQuickUnboundedArchiveIndex.cpp new file mode 100755 index 000000000..7f57b3948 --- /dev/null +++ b/trunk/paradiseo-moeo/test/t-moeoQuickUnboundedArchiveIndex.cpp @@ -0,0 +1,181 @@ +//----------------------------------------------------------------------------- +// t-moeoQuickUnboundedArchive.cpp +//----------------------------------------------------------------------------- + +#include +#include +#include +#include +//----------------------------------------------------------------------------- + +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 << "[moeoArchive]\t=>\t"; + // First test is just to verify behavior of moeoQuickUnboundedArchive + // objective vectors + ObjectiveVector obj0, obj1, obj2, obj3, obj4, obj5,obj10; + obj0[0] = 12226; + obj0[1] = 427894; + obj1[0] = 12170; + obj1[1] = 431736; + obj2[0] = 11965; + obj2[1] = 435193; + obj3[0] = 11893; + obj3[1] = 441839; + obj4[0] = 11870; + obj4[1] = 450770; + obj5[0] = 11769; + obj5[1] = 460005; + obj10[0] = 11769; + obj10[1] = 46005; + // population + eoPop < Solution > pop; + pop.resize(6); + pop[0].objectiveVector(obj0); + pop[1].objectiveVector(obj1); + pop[2].objectiveVector(obj2); + pop[3].objectiveVector(obj3); + pop[4].objectiveVector(obj4); + pop[5].objectiveVector(obj5); + + // archive + moeoQuickUnboundedArchiveIndex< Solution> index; + moeoIndexedArchive arch(index); +// moeoQuickUnboundedArchive< Solution > arch; + arch(pop); +// arch.printIndex(); + + // size + if (arch.size() > 6) + { + std::cout << "ERROR1 (too much solutions)" << std::endl; + return EXIT_FAILURE; + } + // obj0 must be in + if (! arch.contains(obj0)) + { + std::cout << "ERROR2 (obj0 not in)" << std::endl; + return EXIT_FAILURE; + } + // obj1 must be in + if (! arch.contains(obj1)) + { + std::cout << "ERROR3 (obj1 not in)" << std::endl; + return EXIT_FAILURE; + } + // obj2 must be in + if (! arch.contains(obj2)) + { + std::cout << "ERROR4 (obj2 not in)" << std::endl; + return EXIT_FAILURE; + } + // obj3 must be in + if (! arch.contains(obj3)) + { + std::cout << "ERROR5 (obj3 not in)" << std::endl; + return EXIT_FAILURE; + } + // obj4 must be in + if (!arch.contains(obj4)) + { + std::cout << "ERROR6 (obj4 not in)! " << obj4<< std::endl; +// arch.printIndex(); + return EXIT_FAILURE; + } + // obj5 must be in + if (! arch.contains(obj5)) + { + std::cout << "ERROR7 (obj5 not in)" << std::endl; + return EXIT_FAILURE; + } + + // Second test is to verify behavior with negative and comparator + ObjectiveVector obj6, obj7; + std::cout<<"test neg"< pop2; + pop2.resize(2); + pop2[0].objectiveVector(obj6); + pop2[1].objectiveVector(obj7); + std::cout<<"archive 2"< index2; + moeoIndexedArchive< Solution > arch2(index2); + arch2(pop2); + + // size + if (arch2.size() != 2) + { + std::cout << "ERROR8 (too much solutions)" << std::endl; + return EXIT_FAILURE; + } + + //Third test is with two equals values + ObjectiveVector obj8, obj9; + obj8[0] = 10; + obj8[1] = 10; + obj9[0] = 10; + obj9[1] = 10; + eoPop < Solution > pop3; + pop3.resize(2); + pop3[0].objectiveVector(obj8); + pop3[1].objectiveVector(obj9); + + std::cout<<"archive 3"< index3; + moeoIndexedArchive< Solution > arch3(index3); + arch3(pop3); + + if (arch3.size() != 1) + { + std::cout << "ERROR9 (too much solutions)" << std::endl; + return EXIT_FAILURE; + } + eoPop < Solution > pop4; + pop4.resize(6); + pop4[0].objectiveVector(obj0); + pop4[1].objectiveVector(obj1); + pop4[2].objectiveVector(obj2); + pop4[3].objectiveVector(obj3); + pop4[4].objectiveVector(obj4); + pop4[5].objectiveVector(obj10); + std::cout<<"archive 4"< index4; + moeoIndexedArchive< Solution > arch4(index4); + arch4(pop4); + if (arch4.size() != 1) + { + std::cout << "ERROR10 (too much solutions)" << std::endl; + return EXIT_FAILURE; + } + + + std::cout << "OK" << std::endl; + return EXIT_SUCCESS; +} +