diff --git a/trunk/paradiseo-mo/src/moILS.h b/trunk/paradiseo-mo/src/moILS.h index 8fb4f343e..448b7eb93 100644 --- a/trunk/paradiseo-mo/src/moILS.h +++ b/trunk/paradiseo-mo/src/moILS.h @@ -133,10 +133,10 @@ class moILS:public moAlgo < typename M::EOType > double _initial_temperature, moCoolingSchedule & _cooling_schedule, moSolContinue & _continue, moComparator & _acceptance_criterion, eoMonOp & _perturbation, eoEvalFunc & _full_evaluation): algorithm(new moSA(_random_move_generator, _incremental_evaluation, _moSA_continue, _initial_temperature, - _cooling_schedule, _full_evaluation) ), + _cooling_schedule, _full_evaluation) ), continu(_continue), acceptance_criterion(_acceptance_criterion), perturbation(_perturbation), full_evaluation(_full_evaluation), algorithm_memory_allocation(true) - {} + {} //! Destructor ~moILS() diff --git a/trunk/paradiseo-mo/src/moSimpleSolutionTabuList.h b/trunk/paradiseo-mo/src/moSimpleSolutionTabuList.h index 6cc1459e1..f00a1523e 100755 --- a/trunk/paradiseo-mo/src/moSimpleSolutionTabuList.h +++ b/trunk/paradiseo-mo/src/moSimpleSolutionTabuList.h @@ -143,6 +143,7 @@ class moSimpleSolutionTabuList: public moTabuList < M > if (it!=tabuList.end()) { tabuList.erase(it); + memory_size--; } } diff --git a/trunk/paradiseo-mo/src/moSteadyFitSolContinue.h b/trunk/paradiseo-mo/src/moSteadyFitSolContinue.h index 10457da05..ff79bdb17 100644 --- a/trunk/paradiseo-mo/src/moSteadyFitSolContinue.h +++ b/trunk/paradiseo-mo/src/moSteadyFitSolContinue.h @@ -81,7 +81,7 @@ class moSteadyFitSolContinue:public moSolContinue < EOT > if (_solution.invalid()) { - return true; + throw std::runtime_error("[moSteadyFitSolContinue.h]: The current solution has not been evaluated."); } if (firstFitnessSaved) diff --git a/trunk/paradiseo-mo/test/t-moBestImprSelect.cpp b/trunk/paradiseo-mo/test/t-moBestImprSelect.cpp index d964cf85b..63a05902a 100644 --- a/trunk/paradiseo-mo/test/t-moBestImprSelect.cpp +++ b/trunk/paradiseo-mo/test/t-moBestImprSelect.cpp @@ -61,11 +61,14 @@ public : int main() { + std::string test_result, test_1, test_2; + int return_value, value_1, value_2; + unsigned int i, fitness; moBestImprSelect selection; - solution sol; + solution solution; testMove move; @@ -75,27 +78,31 @@ main() selection.init(0); - for(i=1;i<10;i++) + test_1="KO"; + + try { - if(! selection.update(move, i) ) - { - cout << "KO" << endl; - cout << "update is false" << endl; - return EXIT_FAILURE; - } + selection(move, fitness); } + catch(std::runtime_error e) + { + test_1="OK"; + } + + value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + test_2=((!selection.update(move, i))?"KO":"OK"); + value_2=((test_2.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); selection(move, fitness); - if(fitness!=9) - { - cout << "KO" << endl; - cout << "fitness = " << fitness << endl; - return EXIT_FAILURE; - } + move(solution); + + test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO"); + return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE); - cout << "OK" << endl; - return EXIT_SUCCESS; + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moExponentialCoolingSchedule.cpp b/trunk/paradiseo-mo/test/t-moExponentialCoolingSchedule.cpp index 6b916ea84..6ae395dce 100644 --- a/trunk/paradiseo-mo/test/t-moExponentialCoolingSchedule.cpp +++ b/trunk/paradiseo-mo/test/t-moExponentialCoolingSchedule.cpp @@ -51,6 +51,9 @@ using std::endl; int main() { + int return_value; + std::string test_result; + unsigned int i; double temperature; @@ -66,15 +69,11 @@ main() i++; } - if(i!=1) - { - cout << "KO" << endl; - cout << "i = " << i << endl; - return EXIT_FAILURE; - } - - cout << "OK" << endl; - return EXIT_SUCCESS; + test_result=((i!=1)?"KO":"OK"); + return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moFirstImprSelect.cpp b/trunk/paradiseo-mo/test/t-moFirstImprSelect.cpp index 6bcb9e7bb..ba3b36af4 100644 --- a/trunk/paradiseo-mo/test/t-moFirstImprSelect.cpp +++ b/trunk/paradiseo-mo/test/t-moFirstImprSelect.cpp @@ -61,11 +61,13 @@ public : int main() { + std::string test_result; + int return_value; unsigned int i, fitness; moFirstImprSelect selection; - solution sol; + solution solution; testMove move; @@ -82,15 +84,13 @@ main() selection(move, fitness); - if(fitness!=11) - { - cout << "KO" << endl; - cout << "fitness = " << fitness << endl; - return EXIT_FAILURE; - } - - cout << "OK" << std::endl; - return EXIT_SUCCESS; + move(solution); + + test_result=((fitness!=11)?"KO":"OK"); + return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moFitComparator.cpp b/trunk/paradiseo-mo/test/t-moFitComparator.cpp index 22fc1975b..59dc5b696 100644 --- a/trunk/paradiseo-mo/test/t-moFitComparator.cpp +++ b/trunk/paradiseo-mo/test/t-moFitComparator.cpp @@ -52,6 +52,9 @@ typedef EO solution; int main() { + std::string test_result; + int return_value; + solution sol1, sol2; moFitComparator comparator; @@ -61,14 +64,11 @@ main() cout << "[ moFitComparator ] ==> "; - if( comparator(sol1,sol2) ) - { - cout << "KO" << endl; - return EXIT_FAILURE; - } - - cout << "OK" << endl; - return EXIT_SUCCESS; + test_result=((comparator(sol1,sol2))?"KO":"OK"); + return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moFitSolContinue.cpp b/trunk/paradiseo-mo/test/t-moFitSolContinue.cpp index c0e3feffc..6214a73b0 100644 --- a/trunk/paradiseo-mo/test/t-moFitSolContinue.cpp +++ b/trunk/paradiseo-mo/test/t-moFitSolContinue.cpp @@ -52,30 +52,50 @@ typedef EO solution; int main() { - unsigned int i; - solution sol; + std::string test_result, test_1, test_2; + int return_value, value_1, value_2; + unsigned int i; + moFitSolContinue continu(10); + solution solution; + cout << "[ moFitSolContinue ] ==> "; - i=0; - sol.fitness(i); - while( continu(sol) ) + continu.init(); + + test_1="KO"; + + try { - i++; - sol.fitness(i); + continu(solution); + } + catch(std::runtime_error e) + { + test_1="OK"; } - if(i!=10) - { - cout << "KO" << endl; - cout << "i = " << i << endl; - return EXIT_FAILURE; - } + value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + - cout << "OK" << endl; - return EXIT_SUCCESS; + + i=0; + solution.fitness(i); + while( continu(solution) ) + { + i++; + solution.fitness(i); + } + + test_2=((i!=10)?"KO":"OK"); + value_2=((test_2.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO"); + return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moGenSolContinue.cpp b/trunk/paradiseo-mo/test/t-moGenSolContinue.cpp index 24e8a568b..367f274f3 100644 --- a/trunk/paradiseo-mo/test/t-moGenSolContinue.cpp +++ b/trunk/paradiseo-mo/test/t-moGenSolContinue.cpp @@ -52,6 +52,9 @@ typedef EO solution; int main() { + std::string test_result, test_1, test_2; + int value_1, value_2, return_value; + unsigned int i; solution sol; @@ -65,12 +68,8 @@ main() i++; } - if(i!=9) - { - cout << "KO" << endl; - cout << "before init: i = " << i << endl; - return EXIT_FAILURE; - } + test_1=((i!=9)?"KO":"OK"); + value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); continu.init(); @@ -79,16 +78,15 @@ main() { i++; } + + test_2=((i!=9)?"KO":"OK"); + value_2=((test_2.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO"); + return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE); - if(i!=9) - { - cout << "KO" << endl; - cout << "after init: i = " << i << endl; - return EXIT_FAILURE; - } - - cout << "OK" << endl; - return EXIT_SUCCESS; + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moHC.cpp b/trunk/paradiseo-mo/test/t-moHC.cpp index 1fb6255a4..bbcb90b55 100644 --- a/trunk/paradiseo-mo/test/t-moHC.cpp +++ b/trunk/paradiseo-mo/test/t-moHC.cpp @@ -135,9 +135,10 @@ public : int main() { - cout << "[ moHC ] ==> "; - - solution sol; + std::string test_result; + int return_value; + + solution solution; testMoveInit init; testMoveNext next; @@ -147,16 +148,15 @@ main() moHC hc(init, next, incrEval, select, eval); - hc(sol); - - if(sol.fitness()!=2) - { - cout << "KO" << endl; - return EXIT_FAILURE; - } + cout << "[ moHC ] ==> "; - cout << "OK" << endl; - return EXIT_SUCCESS; + hc(solution); + + test_result=((solution.fitness()!=2)?"KO":"OK"); + return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moHCMoveLoopExpl.cpp b/trunk/paradiseo-mo/test/t-moHCMoveLoopExpl.cpp index a742946e2..73de0ac85 100644 --- a/trunk/paradiseo-mo/test/t-moHCMoveLoopExpl.cpp +++ b/trunk/paradiseo-mo/test/t-moHCMoveLoopExpl.cpp @@ -125,30 +125,46 @@ public : int main() { - cout << "[ moHCMoveLoopExpl ] ==> "; + std::string test_result, test_1, test_2; + int return_value, value_1, value_2; - solution sol1, sol2; - - sol1.fitness(0); - sol2.fitness(0); + solution solution_1, solution_2; testMoveInit init; testMoveNext next; testMoveIncrEval incrEval; testMoveSelect select; - - moHCMoveLoopExpl explorer(init, next, incrEval, select); - - explorer(sol1, sol2); - - if(sol2.fitness()!=2) - { - cout << "KO" << endl; - return EXIT_FAILURE; - } - cout << "OK" << endl; - return EXIT_SUCCESS; + moHCMoveLoopExpl explorer(init, next, incrEval, select); + + cout << "[ moHCMoveLoopExpl ] ==> "; + + test_1="KO"; + + try + { + explorer(solution_1, solution_2); + } + catch(std::runtime_error e) + { + test_1="OK"; + } + + value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + solution_1.fitness(0); + solution_2.fitness(0); + + explorer(solution_1, solution_2); + + test_2=((solution_2.fitness()!=2)?"KO":"OK"); + value_2=((test_2.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO"); + return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moHC_2.cpp b/trunk/paradiseo-mo/test/t-moHC_2.cpp index 920c3c58a..eecc80e60 100644 --- a/trunk/paradiseo-mo/test/t-moHC_2.cpp +++ b/trunk/paradiseo-mo/test/t-moHC_2.cpp @@ -61,6 +61,8 @@ class testMoveExplorer : public moMoveExpl public : void operator () (const solution & _solution_1, solution & _solution_2) { + const solution sol(_solution_1); + _solution_2.fitness(2); } }; @@ -80,25 +82,25 @@ public : int main() { - cout << "[ moHC_2 ] ==> "; - - solution sol; + std::string test_result; + int return_value; + + solution solution; solutionEval eval; testMoveExplorer explorer; moHC hc(explorer, eval); - hc(sol); - - if(sol.fitness()!=2) - { - cout << "KO" << endl; - return EXIT_FAILURE; - } + cout << "[ moHC_2 ] ==> "; - cout << "OK" << endl; - return EXIT_SUCCESS; + hc(solution); + + test_result=((solution.fitness()!=2)?"KO":"OK"); + return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moILS.cpp b/trunk/paradiseo-mo/test/t-moILS.cpp index d29221442..644a75222 100644 --- a/trunk/paradiseo-mo/test/t-moILS.cpp +++ b/trunk/paradiseo-mo/test/t-moILS.cpp @@ -61,7 +61,7 @@ class solutionAlgo : public moAlgo public : bool operator () (solution & _solution) { - _solution.fitness(2); + solution solution(_solution); return true; } } ; @@ -69,27 +69,49 @@ public : class solutionContinue : public moSolContinue { public : + solutionContinue(): counter(0) + {} + bool operator () (const solution & _solution) { const solution sol(_solution); + if(counter<2) + { + counter++; + return true; + } return false; } void init() {} +private : + unsigned int counter; } ; class solutionComparator : public moComparator { public : + + solutionComparator() : counter(0) + {} + bool operator () (const solution & _solution1 , const solution & _solution2) { const solution sol1(_solution1); const solution sol2(_solution2); + if(counter<2) + { + counter++; + return false; + } + return true; } +private : + unsigned int counter; } ; class solutionPerturbation : public eoMonOp @@ -97,7 +119,7 @@ class solutionPerturbation : public eoMonOp public : bool operator () (solution & _solution) { - solution sol(_solution); + _solution.fitness(2); return true; } @@ -108,7 +130,7 @@ class solutionEval : public eoEvalFunc public : void operator () (solution & _solution) { - _solution.fitness(0); + solution solution(_solution); } } ; @@ -117,30 +139,30 @@ public : int main() { - cout << "[ moILS ] ==> "; + std::string test_result; + int return_value; + + solution solution; - solution sol; - - sol.fitness(0); - solutionAlgo algorithm; solutionContinue continu; solutionComparator comparator; solutionPerturbation perturbation; solutionEval eval; - + moILS ils(algorithm, continu, comparator, perturbation, eval); - ils(sol); - - if(sol.fitness()!=2) - { - cout << "KO" << endl; - return EXIT_FAILURE; - } + cout << "[ moILS ] ==> "; - cout << "OK" << endl; - return EXIT_SUCCESS; + solution.fitness(0); + + ils(solution); + + test_result=((solution.fitness()!=2)?"KO":"OK"); + return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moILS_HC.cpp b/trunk/paradiseo-mo/test/t-moILS_HC.cpp index 15072af40..98bf88cf0 100644 --- a/trunk/paradiseo-mo/test/t-moILS_HC.cpp +++ b/trunk/paradiseo-mo/test/t-moILS_HC.cpp @@ -132,15 +132,25 @@ public : class solutionContinue : public moSolContinue { public : + solutionContinue(): counter(0) + {} + bool operator () (const solution & _solution) { const solution sol(_solution); + if(counter==0) + { + counter++; + return true; + } return false; } void init() {} +private : + unsigned int counter; } ; class solutionComparator : public moComparator @@ -160,7 +170,7 @@ class solutionPerturbation : public eoMonOp public : bool operator () (solution & _solution) { - solution sol(_solution); + _solution.fitness(2); return true; } @@ -171,34 +181,31 @@ public : int main() { - cout << "[ moILS_HC ] ==> "; - - solution sol; + std::string test_result; + int return_value; + solution solution; + testMoveInit init; testMoveNext next; testMoveIncrEval incrEval; testMoveSelect select; solutionEval eval; - - moHC hc(init, next, incrEval, select, eval); - solutionContinue continu; solutionComparator comparator; solutionPerturbation perturbation; - moILS ils(hc, continu, comparator, perturbation, eval); - - ils(sol); - - if(sol.fitness()!=2) - { - cout << "KO" << endl; - return EXIT_FAILURE; - } + moILS ils(init, next, incrEval, select, continu, comparator, perturbation, eval); - cout << "OK" << endl; - return EXIT_SUCCESS; + cout << "[ moILS_HC ] ==> "; + + ils(solution); + + test_result=((solution.fitness()!=2)?"KO":"OK"); + return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moILS_SA.cpp b/trunk/paradiseo-mo/test/t-moILS_SA.cpp index a8e50ec4d..4cbd940c6 100644 --- a/trunk/paradiseo-mo/test/t-moILS_SA.cpp +++ b/trunk/paradiseo-mo/test/t-moILS_SA.cpp @@ -94,34 +94,50 @@ class solutionEval : public eoEvalFunc public : void operator () (solution & _solution) { - _solution.fitness(2); + const solution solution(_solution); } } ; class solutionContinue : public moSolContinue { public : + solutionContinue(): counter(0) + {} + bool operator () (const solution & _solution) { const solution sol(_solution); + if(counter==0) + { + counter++; + return true; + } return false; } void init() {} +private : + unsigned int counter; } ; class solutionComparator : public moComparator { public : + + solutionComparator() : counter(0) + {} + bool operator () (const solution & _solution1 , const solution & _solution2) { - const solution sol1(_solution1); - const solution sol2(_solution2); + const solution solution1(_solution1); + const solution solution2(_solution2); return true; } +private : + unsigned int counter; } ; class solutionPerturbation : public eoMonOp @@ -129,7 +145,7 @@ class solutionPerturbation : public eoMonOp public : bool operator () (solution & _solution) { - solution sol(_solution); + _solution.fitness(2); return true; } @@ -140,35 +156,35 @@ public : int main() { - cout << "[ moILS_SA ] ==> "; + std::string test_result; + int return_value; - solution sol; - - sol.fitness(0); + solution solution; testRandMove rand; testMoveIncrEval incrEval; solutionContinue continu; + solutionContinue continu_2; testCooling cooling; solutionEval eval; - - moSA sa(rand, incrEval, continu, 10.0, cooling, eval); - solutionComparator comparator; solutionPerturbation perturbation; - moILS ils(sa, continu, comparator, perturbation, eval); + moILS ils(rand, incrEval, continu, 10.0, cooling, continu_2, comparator, perturbation, eval); - ils(sol); + cout << "[ moILS_SA ] ==> "; - if(sol.fitness()!=2) - { - cout << "KO" << endl; - return EXIT_FAILURE; - } + solution.fitness(0); + + eval(solution); - cout << "OK" << endl; - return EXIT_SUCCESS; + ils(solution); + + test_result=((solution.fitness()!=2)?"KO":"OK"); + return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moILS_TS.cpp b/trunk/paradiseo-mo/test/t-moILS_TS.cpp index a5db0fbe7..dc6c3f296 100644 --- a/trunk/paradiseo-mo/test/t-moILS_TS.cpp +++ b/trunk/paradiseo-mo/test/t-moILS_TS.cpp @@ -133,15 +133,25 @@ public: class solutionContinue : public moSolContinue { public : + solutionContinue(): counter(0) + {} + bool operator () (const solution & _solution) { const solution sol(_solution); + if(counter==0) + { + counter++; + return true; + } return false; } void init() {} +private : + unsigned int counter; } ; class solutionComparator : public moComparator @@ -161,7 +171,7 @@ class solutionPerturbation : public eoMonOp public : bool operator () (solution & _solution) { - solution sol(_solution); + _solution.fitness(2); return true; } @@ -172,7 +182,7 @@ class solutionEval : public eoEvalFunc public : void operator () (solution & _solution) { - _solution.fitness(2); + _solution.fitness(0); } } ; @@ -181,11 +191,10 @@ public : int main() { - cout << "[ moILS_TS ] ==> "; - - solution sol; + std::string test_result; + int return_value; - sol.fitness(0); + solution solution; testMoveInit init; testMoveNext next; @@ -194,24 +203,21 @@ main() testAspirCrit aspirCrit; solutionEval eval; solutionContinue continu; - - moTS ts(init, next, incrEval, tabuList, aspirCrit, continu, eval); - + solutionContinue continu_2; solutionComparator comparator; solutionPerturbation perturbation; - moILS ils(ts, continu, comparator, perturbation, eval); + moILS ils(init, next, incrEval, tabuList, aspirCrit, continu, continu_2, comparator, perturbation, eval); - ils(sol); - - if(sol.fitness()!=2) - { - cout << "KO" << endl; - return EXIT_FAILURE; - } + cout << "[ moILS_TS ] ==> "; - cout << "OK" << endl; - return EXIT_SUCCESS; + ils(solution); + + test_result=((solution.fitness()!=2)?"KO":"OK"); + return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moImprBestFitAspirCrit.cpp b/trunk/paradiseo-mo/test/t-moImprBestFitAspirCrit.cpp index f0ce954b9..fda39ab7a 100644 --- a/trunk/paradiseo-mo/test/t-moImprBestFitAspirCrit.cpp +++ b/trunk/paradiseo-mo/test/t-moImprBestFitAspirCrit.cpp @@ -61,6 +61,11 @@ public : int main() { + std::string test_result, test_1, test_2; + int return_value, value_1, value_2; + + solution solution; + unsigned int i; moImprBestFitAspirCrit aspirCriterion; @@ -77,12 +82,8 @@ main() i++; } - if(i!=10) - { - cout << "KO" << endl; - cout << "before init, i = " << i << endl; - return EXIT_FAILURE; - } + test_1=((i!=10)?"KO":"OK"); + value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); aspirCriterion.init(); aspirCriterion(move, i); @@ -93,15 +94,16 @@ main() i++; } - if(i!=10) - { - cout << "KO" << endl; - cout << "after init, i = " << i << endl; - return EXIT_FAILURE; - } - - cout << "OK" << std::endl; - return EXIT_SUCCESS; + move(solution); + + test_2=((i!=10)?"KO":"OK"); + value_2=((test_2.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO"); + return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moItRandNextMove.cpp b/trunk/paradiseo-mo/test/t-moItRandNextMove.cpp index ed7220086..dbd5acffa 100644 --- a/trunk/paradiseo-mo/test/t-moItRandNextMove.cpp +++ b/trunk/paradiseo-mo/test/t-moItRandNextMove.cpp @@ -70,10 +70,13 @@ public : int main() { + std::string test_result, test_1, test_2; + int value_1, value_2, return_value; + unsigned int i; testMove move; - solution sol; + solution solution; testRandMove rand; @@ -82,33 +85,30 @@ main() cout << "[ moItRandNextMove ] ==> "; i=0; - while( next(move, sol) && i<15 ) + while( next(move, solution) && i<15 ) { i++; } - if(i!=11) - { - cout << "KO" << endl; - cout << "First time, i = " << i << endl; - return EXIT_FAILURE; - } + test_1=((i!=11)?"KO":"OK"); + value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); i=0; - while( next(move, sol) && i<15 ) + while( next(move, solution) && i<15 ) { i++; } - if(i!=11) - { - cout << "KO" << endl; - cout << "Second time, i = " << i << endl; - return EXIT_FAILURE; - } - - cout << "OK" << endl; - return EXIT_SUCCESS; + move(solution); + + test_2=((i!=11)?"KO":"OK"); + value_2=((test_2.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO"); + return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moLSCheckPoint.cpp b/trunk/paradiseo-mo/test/t-moLSCheckPoint.cpp index 0ef842248..190f92e9b 100644 --- a/trunk/paradiseo-mo/test/t-moLSCheckPoint.cpp +++ b/trunk/paradiseo-mo/test/t-moLSCheckPoint.cpp @@ -72,43 +72,45 @@ class testBF : public eoBF int main() { + std::string test_result, test_1, test_2; + int value_1, value_2, return_value; + unsigned int i; std::string result; testBF test; moLSCheckPoint checkpoint; - solution sol; + solution solution; testMove move; + std::ifstream is; + cout << "[ moLSCheckPoint ] ==> "; i=0; checkpoint.add(test); - checkpoint(move, sol); + checkpoint(move, solution); - std::ifstream is("test.txt"); + move(solution); - if(!is.is_open()) - { - cout << "KO" << endl; - cout << "test.txt does not exist" << endl; - return EXIT_FAILURE; - } + is.open("test.txt"); + + test_1=((!is.is_open())?"KO":"OK"); + value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); is >> result; - if(result.compare("OK")!=0) - { - cout << "KO" << endl; - cout << "result = " << result << endl; - return EXIT_FAILURE; - } + test_2=((result.compare("OK")!=0)?"KO":"OK"); + value_2=((test_2.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO"); + return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE); - cout << "OK" << endl; - return EXIT_SUCCESS; + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moLinearCoolingSchedule.cpp b/trunk/paradiseo-mo/test/t-moLinearCoolingSchedule.cpp index f8155d669..76d264da2 100644 --- a/trunk/paradiseo-mo/test/t-moLinearCoolingSchedule.cpp +++ b/trunk/paradiseo-mo/test/t-moLinearCoolingSchedule.cpp @@ -51,30 +51,29 @@ using std::endl; int main() { + std::string test_result; + int return_value; + unsigned int i; double temperature; moLinearCoolingSchedule coolingSchedule( 1.0, 0.5 ); - temperature=2.0; - cout << "[ moLinearCoolingSchedule ] ==> "; + temperature=2.0; + i=0; while( coolingSchedule(temperature) ) { i++; } - if(i!=1) - { - cout << "KO" << endl; - cout << "i = " << i << endl; - return EXIT_FAILURE; - } - - cout << "OK" << endl; - return EXIT_SUCCESS; + test_result=((i!=1)?"KO":"OK"); + return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moNoAspirCrit.cpp b/trunk/paradiseo-mo/test/t-moNoAspirCrit.cpp index ca4e05c71..2fe273f43 100644 --- a/trunk/paradiseo-mo/test/t-moNoAspirCrit.cpp +++ b/trunk/paradiseo-mo/test/t-moNoAspirCrit.cpp @@ -61,20 +61,25 @@ public : int main() { + std::string test_result; + int return_value; + unsigned int i; moNoAspirCrit aspirCriterion; testMove move; + solution solution; cout << "[ moNoAspirCrit ] ==> "; - - if( aspirCriterion(move, i) ) - { - cout << "KO" << endl; - return EXIT_FAILURE; - } - cout << "OK" << std::endl; - return EXIT_SUCCESS; + move(solution); + + aspirCriterion.init(); + + test_result=((aspirCriterion(move, i))?"KO":"OK"); + return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moNoFitImprSolContinue.cpp b/trunk/paradiseo-mo/test/t-moNoFitImprSolContinue.cpp index 98d281443..653b39b61 100644 --- a/trunk/paradiseo-mo/test/t-moNoFitImprSolContinue.cpp +++ b/trunk/paradiseo-mo/test/t-moNoFitImprSolContinue.cpp @@ -52,30 +52,50 @@ typedef EO solution; int main() { + std::string test_result, test_1, test_2; + int return_value, value_1, value_2; + + unsigned int i; - solution sol; moNoFitImprSolContinue continu(10); + + solution solution; cout << "[ moNoFitImprSolContinue ] ==> "; - sol.fitness(2); + continu.init(); - i=0; - while( continu(sol) ) + test_1="KO"; + + try { - i++; + continu(solution); } - - if(i!=10) + catch(std::runtime_error e) { - cout << "KO" << endl; - cout << "i = " << i << endl; - return EXIT_FAILURE; + test_1="OK"; } - cout << "OK" << endl; - return EXIT_SUCCESS; + value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + solution.fitness(0); + + i=0; + while( continu(solution) ) + { + i++; + solution.fitness(2); + } + + test_2=((i!=11)?"KO":"OK"); + value_2=((test_2.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO"); + return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moRandImprSelect.cpp b/trunk/paradiseo-mo/test/t-moRandImprSelect.cpp index 9a66fd961..e44fe1039 100644 --- a/trunk/paradiseo-mo/test/t-moRandImprSelect.cpp +++ b/trunk/paradiseo-mo/test/t-moRandImprSelect.cpp @@ -61,43 +61,55 @@ public : int main() { - unsigned int i, fitness; + std::string test_result, test_1, test_2, test_3; + int value_1, value_2, value_3, return_value; + + unsigned int i; moRandImprSelect selection; - solution sol; + solution solution; testMove move; cout << "[ moRandImprSelect ] ==> "; - i=fitness=0; + selection.init(0); - selection.init(5); + test_1="KO"; + + i=0; - for(i=1;i<10;i++) + try { - if(! selection.update(move, i) ) - { - cout << "KO" << endl; - cout << "update is false" << endl; - return EXIT_FAILURE; - } + selection(move, i); } - - for(i=0;i<10;i++) + catch(std::runtime_error e) { - selection(move, fitness); - if(fitness<=5) - { - cout << "KO" << endl; - cout << "fitness = " << fitness << endl; - return EXIT_FAILURE; - } + test_1="OK"; } - cout << "OK" << endl; - return EXIT_SUCCESS; + value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + move(solution); + + test_2=((!selection.update(move, i))?"KO":"OK"); + value_2=((test_2.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + selection(move, i); + + i++; + + test_3=((!selection.update(move, i))?"KO":"OK"); + value_3=((test_3.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + selection(move, i); + + test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0)&&(test_3.compare("OK")==0))?"OK":"KO"); + return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS)&&(value_3==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moSA.cpp b/trunk/paradiseo-mo/test/t-moSA.cpp index 008fb8bc8..6a0d117f0 100644 --- a/trunk/paradiseo-mo/test/t-moSA.cpp +++ b/trunk/paradiseo-mo/test/t-moSA.cpp @@ -68,27 +68,50 @@ public : class testMoveIncrEval : public moMoveIncrEval { public : + + testMoveIncrEval() : counter(0) + {} + int operator () (const testMove & _move, const solution & _solution) { const testMove move(_move); const solution solution(_solution); - return 2; + if(counter==0) + { + counter++; + return 2; + } + return 0; } +private : + unsigned int counter; } ; class solutionContinue : public moSolContinue { public : + + solutionContinue() : counter(0) + {} + bool operator () (const solution & _solution) { const solution sol(_solution); - + + if(counter==0) + { + counter++; + return true; + } + return false; } void init() {} +private : + unsigned int counter; } ; class testCooling : public moCoolingSchedule @@ -108,7 +131,7 @@ class solutionEval : public eoEvalFunc public : void operator () (solution & _solution) { - _solution.fitness(2); + _solution.fitness(0); } } ; @@ -118,30 +141,28 @@ public : int main() { - cout << "[ moSA ] ==> "; + std::string test_result; + int return_value; + + solution solution; - solution sol; - - sol.fitness(0); - testRandMove rand; testMoveIncrEval incrEval; solutionContinue continu; testCooling cooling; solutionEval eval; - - moSA sa(rand, incrEval, continu, 10.0, cooling, eval); - - sa(sol); - - if(sol.fitness()!=2) - { - cout << "KO" << endl; - return EXIT_FAILURE; - } - cout << "OK" << endl; - return EXIT_SUCCESS; + moSA sa(rand, incrEval, continu, 10.0, cooling, eval); + + cout << "[ moSA ] ==> "; + + sa(solution); + + test_result=((solution.fitness()!=2)?"KO":"OK"); + return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moSimpleMoveTabuList.cpp b/trunk/paradiseo-mo/test/t-moSimpleMoveTabuList.cpp index fe4f0c94c..e9937bdac 100644 --- a/trunk/paradiseo-mo/test/t-moSimpleMoveTabuList.cpp +++ b/trunk/paradiseo-mo/test/t-moSimpleMoveTabuList.cpp @@ -50,6 +50,9 @@ typedef EO solution; class testMove : public moMove { public : + testMove(unsigned int _value): value(_value) + {} + void operator () (solution & _solution) { _solution=_solution; @@ -57,11 +60,10 @@ public : bool operator == (const testMove & _move) { - testMove move; - move=(testMove)_move; - - return true; + return (value==_move.value); } +private : + unsigned int value; } ; //----------------------------------------------------------------------------- @@ -69,24 +71,34 @@ public : int main() { + std::string test_result; + int return_value; + moSimpleMoveTabuList tabuList(1); - solution sol; + solution solution; - testMove move; + testMove move_1(1), move_2(2); cout << "[ moSimpleMoveTabuList ] ==> "; - tabuList.add(move, sol); + tabuList.init(); + tabuList.update(); - if( !tabuList(move, sol) ) - { - cout << "KO" << endl; - return EXIT_FAILURE; - } - - cout << "OK" << endl; - return EXIT_SUCCESS; + tabuList.add(move_1, solution); + + tabuList(move_2, solution); + + move_1(solution); + + tabuList.add(move_2, solution); + tabuList.add(move_2, solution); + + test_result=((tabuList(move_1, solution))?"KO":"OK"); + return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moSimpleSolutionTabuList.cpp b/trunk/paradiseo-mo/test/t-moSimpleSolutionTabuList.cpp index 9ed64fe13..85d63a5cb 100644 --- a/trunk/paradiseo-mo/test/t-moSimpleSolutionTabuList.cpp +++ b/trunk/paradiseo-mo/test/t-moSimpleSolutionTabuList.cpp @@ -45,48 +45,62 @@ using std::endl; //----------------------------------------------------------------------------- -typedef EO solution; +class solution : public EO +{ +public: + solution(unsigned int _value): value(_value) + {} + + bool operator == (const solution & _solution) + { + return (value==_solution.value); + } + +private: + unsigned int value; +}; class testMove : public moMove { public : void operator () (solution & _solution) { - _solution=_solution; + solution solution(_solution); } - - bool operator == (const testMove & _move) - { - testMove move; - move=(testMove)_move; - - return true; - } -} ; +}; //----------------------------------------------------------------------------- int main() { - moSimpleMoveTabuList tabuList(1); + std::string test_result; + int return_value; - solution sol; + moSimpleSolutionTabuList tabuList(1); + + solution solution_1(1), solution_2(2); testMove move; cout << "[ moSimpleSolutionTabuList ] ==> "; - tabuList.add(move, sol); + tabuList.init(); + tabuList.update(); - if( !tabuList(move, sol) ) - { - cout << "KO" << endl; - return EXIT_FAILURE; - } - - cout << "OK" << endl; - return EXIT_SUCCESS; + tabuList.add(move, solution_1); + + move(solution_1); + + tabuList.add(move, solution_2); + + tabuList.add(move, solution_2); + + test_result=((tabuList(move, solution_1))?"KO":"OK"); + return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moSteadyFitSolContinue.cpp b/trunk/paradiseo-mo/test/t-moSteadyFitSolContinue.cpp index 26b25e2d3..d70630102 100644 --- a/trunk/paradiseo-mo/test/t-moSteadyFitSolContinue.cpp +++ b/trunk/paradiseo-mo/test/t-moSteadyFitSolContinue.cpp @@ -52,33 +52,57 @@ typedef EO solution; int main() { + std::string test_result, test_1, test_2; + int return_value, value_1, value_2; + unsigned int i; - solution sol; + solution solution_1, solution_2; moSteadyFitSolContinue continu(10,10); cout << "[ moSteadyFitSolContinue ] ==> "; + continu.init(); + i=0; - sol.fitness(i); - while( continu(sol) && i<50) + solution_1.fitness(i); + while( continu(solution_1) && i<50) { i++; + if(i<11) { - sol.fitness(i); + solution_1.fitness(i); + } + + if(i==11) + { + test_1="KO"; + try + { + continu(solution_2); + } + catch(std::runtime_error e) + { + test_1="OK"; + } + value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + } + + if(i==15) + { + solution_1.fitness(i); } } - if(i!=20) - { - cout << "KO" << endl; - cout << "i = " << i << endl; - return EXIT_FAILURE; - } - - cout << "OK" << endl; - return EXIT_SUCCESS; + test_2=((i!=25)?"KO":"OK"); + value_2=((test_2.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO"); + return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moTS.cpp b/trunk/paradiseo-mo/test/t-moTS.cpp index 65eb63de1..96908ef27 100644 --- a/trunk/paradiseo-mo/test/t-moTS.cpp +++ b/trunk/paradiseo-mo/test/t-moTS.cpp @@ -159,11 +159,10 @@ public : int main() { - cout << "[ moTS ] ==> "; - - solution sol; + std::string test_result; + int return_value; - sol.fitness(0); + solution solution; testMoveInit init; testMoveNext next; @@ -174,17 +173,16 @@ main() solutionEval eval; moTS ts(init, next, incrEval, tabuList, aspirCrit, continu, eval); - - ts(sol); - - if(sol.fitness()!=2) - { - cout << "KO" << endl; - return EXIT_FAILURE; - } - cout << "OK" << endl; - return EXIT_SUCCESS; + cout << "[ moTS ] ==> "; + + ts(solution); + + test_result=((solution.fitness()!=2)?"KO":"OK"); + return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moTSMoveLoopExpl.cpp b/trunk/paradiseo-mo/test/t-moTSMoveLoopExpl.cpp index 374f8f753..75aaaeebc 100644 --- a/trunk/paradiseo-mo/test/t-moTSMoveLoopExpl.cpp +++ b/trunk/paradiseo-mo/test/t-moTSMoveLoopExpl.cpp @@ -135,12 +135,10 @@ public: int main() { - cout << "[ moTSMoveLoopExpl ] ==> "; - - solution sol1 ,sol2; + std::string test_result, test_1, test_2; + int return_value, value_1, value_2; - sol1.fitness(0); - sol2.fitness(0); + solution solution_1 ,solution_2; testMoveInit init; testMoveNext next; @@ -150,16 +148,33 @@ main() moTSMoveLoopExpl explorer(init, next, incrEval, tabuList, aspirCrit); - explorer(sol1, sol2); + cout << "[ moTSMoveLoopExpl ] ==> "; - if(sol2.fitness()!=2) + test_1="KO"; + + try { - cout << "KO" << endl; - return EXIT_FAILURE; + explorer(solution_1, solution_2); + } + catch(std::runtime_error e) + { + test_1="OK"; } - cout << "OK" << endl; - return EXIT_SUCCESS; + value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + solution_1.fitness(0); + + explorer(solution_1, solution_2); + + test_2=((solution_2.fitness()!=2)?"KO":"OK"); + value_2=((test_2.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO"); + return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE); + + cout << test_result << endl; + return return_value; } //----------------------------------------------------------------------------- diff --git a/trunk/paradiseo-mo/test/t-moTS_2.cpp b/trunk/paradiseo-mo/test/t-moTS_2.cpp index 8f4897f25..eebaa532b 100644 --- a/trunk/paradiseo-mo/test/t-moTS_2.cpp +++ b/trunk/paradiseo-mo/test/t-moTS_2.cpp @@ -61,6 +61,7 @@ class testMoveExplorer : public moMoveExpl public : void operator () (const solution & _solution_1, solution & _solution_2) { + const solution solution(_solution_1); _solution_2.fitness(2); } }; @@ -94,26 +95,29 @@ public : int main() { - cout << "[ moTS_2 ] ==> "; - - solution sol; + std::string test_result; + int return_value; + + solution solution; testMoveExplorer explorer; solutionContinue continu; solutionEval eval; + testMove move; moTS ts(explorer, continu, eval); - ts(sol); + cout << "[ moTS_2 ] ==> "; - if(sol.fitness()!=2) - { - cout << "KO" << endl; - return EXIT_FAILURE; - } - - cout << "OK" << endl; - return EXIT_SUCCESS; + ts(solution); + + move(solution); + + test_result=((solution.fitness()!=2)?"KO":"OK"); + return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS); + + cout << test_result << endl; + return return_value; } //-----------------------------------------------------------------------------