Test and sources have been updated to improve coverage and dynamic tests

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1122 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jboisson 2008-03-12 14:10:00 +00:00
commit 4d252c4373
30 changed files with 616 additions and 394 deletions

View file

@ -133,10 +133,10 @@ class moILS:public moAlgo < typename M::EOType >
double _initial_temperature, moCoolingSchedule & _cooling_schedule, moSolContinue <EOT> & _continue, double _initial_temperature, moCoolingSchedule & _cooling_schedule, moSolContinue <EOT> & _continue,
moComparator<EOT> & _acceptance_criterion, eoMonOp<EOT> & _perturbation, eoEvalFunc<EOT> & _full_evaluation): moComparator<EOT> & _acceptance_criterion, eoMonOp<EOT> & _perturbation, eoEvalFunc<EOT> & _full_evaluation):
algorithm(new moSA<M>(_random_move_generator, _incremental_evaluation, _moSA_continue, _initial_temperature, algorithm(new moSA<M>(_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), continu(_continue), acceptance_criterion(_acceptance_criterion), perturbation(_perturbation), full_evaluation(_full_evaluation),
algorithm_memory_allocation(true) algorithm_memory_allocation(true)
{} {}
//! Destructor //! Destructor
~moILS() ~moILS()

View file

@ -143,6 +143,7 @@ class moSimpleSolutionTabuList: public moTabuList < M >
if (it!=tabuList.end()) if (it!=tabuList.end())
{ {
tabuList.erase(it); tabuList.erase(it);
memory_size--;
} }
} }

View file

@ -81,7 +81,7 @@ class moSteadyFitSolContinue:public moSolContinue < EOT >
if (_solution.invalid()) if (_solution.invalid())
{ {
return true; throw std::runtime_error("[moSteadyFitSolContinue.h]: The current solution has not been evaluated.");
} }
if (firstFitnessSaved) if (firstFitnessSaved)

View file

@ -61,11 +61,14 @@ public :
int int
main() main()
{ {
std::string test_result, test_1, test_2;
int return_value, value_1, value_2;
unsigned int i, fitness; unsigned int i, fitness;
moBestImprSelect<testMove> selection; moBestImprSelect<testMove> selection;
solution sol; solution solution;
testMove move; testMove move;
@ -75,27 +78,31 @@ main()
selection.init(0); selection.init(0);
for(i=1;i<10;i++) test_1="KO";
try
{ {
if(! selection.update(move, i) ) selection(move, fitness);
{
cout << "KO" << endl;
cout << "update is false" << endl;
return EXIT_FAILURE;
}
} }
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); selection(move, fitness);
if(fitness!=9) move(solution);
{
cout << "KO" << endl;
cout << "fitness = " << fitness << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO");
return EXIT_SUCCESS; return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE);
cout << test_result << endl;
return return_value;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -51,6 +51,9 @@ using std::endl;
int int
main() main()
{ {
int return_value;
std::string test_result;
unsigned int i; unsigned int i;
double temperature; double temperature;
@ -66,15 +69,11 @@ main()
i++; i++;
} }
if(i!=1) test_result=((i!=1)?"KO":"OK");
{ return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
cout << "KO" << endl;
cout << "i = " << i << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; cout << test_result << endl;
return EXIT_SUCCESS; return return_value;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -61,11 +61,13 @@ public :
int int
main() main()
{ {
std::string test_result;
int return_value;
unsigned int i, fitness; unsigned int i, fitness;
moFirstImprSelect<testMove> selection; moFirstImprSelect<testMove> selection;
solution sol; solution solution;
testMove move; testMove move;
@ -82,15 +84,13 @@ main()
selection(move, fitness); selection(move, fitness);
if(fitness!=11) move(solution);
{
cout << "KO" << endl;
cout << "fitness = " << fitness << endl;
return EXIT_FAILURE;
}
cout << "OK" << std::endl; test_result=((fitness!=11)?"KO":"OK");
return EXIT_SUCCESS; return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
cout << test_result << endl;
return return_value;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -52,6 +52,9 @@ typedef EO<unsigned int> solution;
int int
main() main()
{ {
std::string test_result;
int return_value;
solution sol1, sol2; solution sol1, sol2;
moFitComparator<solution> comparator; moFitComparator<solution> comparator;
@ -61,14 +64,11 @@ main()
cout << "[ moFitComparator ] ==> "; cout << "[ moFitComparator ] ==> ";
if( comparator(sol1,sol2) ) test_result=((comparator(sol1,sol2))?"KO":"OK");
{ return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
cout << "KO" << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; cout << test_result << endl;
return EXIT_SUCCESS; return return_value;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -52,30 +52,50 @@ typedef EO<unsigned int> solution;
int int
main() main()
{ {
std::string test_result, test_1, test_2;
int return_value, value_1, value_2;
unsigned int i; unsigned int i;
solution sol;
moFitSolContinue<solution> continu(10); moFitSolContinue<solution> continu(10);
solution solution;
cout << "[ moFitSolContinue ] ==> "; cout << "[ moFitSolContinue ] ==> ";
continu.init();
test_1="KO";
try
{
continu(solution);
}
catch(std::runtime_error e)
{
test_1="OK";
}
value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
i=0; i=0;
sol.fitness(i); solution.fitness(i);
while( continu(sol) ) while( continu(solution) )
{ {
i++; i++;
sol.fitness(i); solution.fitness(i);
} }
if(i!=10) test_2=((i!=10)?"KO":"OK");
{ value_2=((test_2.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
cout << "KO" << endl;
cout << "i = " << i << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO");
return EXIT_SUCCESS; return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE);
cout << test_result << endl;
return return_value;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -52,6 +52,9 @@ typedef EO<unsigned int> solution;
int int
main() main()
{ {
std::string test_result, test_1, test_2;
int value_1, value_2, return_value;
unsigned int i; unsigned int i;
solution sol; solution sol;
@ -65,12 +68,8 @@ main()
i++; i++;
} }
if(i!=9) test_1=((i!=9)?"KO":"OK");
{ value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
cout << "KO" << endl;
cout << "before init: i = " << i << endl;
return EXIT_FAILURE;
}
continu.init(); continu.init();
@ -80,15 +79,14 @@ main()
i++; i++;
} }
if(i!=9) test_2=((i!=9)?"KO":"OK");
{ value_2=((test_2.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
cout << "KO" << endl;
cout << "after init: i = " << i << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO");
return EXIT_SUCCESS; return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE);
cout << test_result << endl;
return return_value;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -135,9 +135,10 @@ public :
int int
main() main()
{ {
cout << "[ moHC ] ==> "; std::string test_result;
int return_value;
solution sol; solution solution;
testMoveInit init; testMoveInit init;
testMoveNext next; testMoveNext next;
@ -147,16 +148,15 @@ main()
moHC<testMove> hc(init, next, incrEval, select, eval); moHC<testMove> hc(init, next, incrEval, select, eval);
hc(sol); cout << "[ moHC ] ==> ";
if(sol.fitness()!=2) hc(solution);
{
cout << "KO" << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; test_result=((solution.fitness()!=2)?"KO":"OK");
return EXIT_SUCCESS; return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
cout << test_result << endl;
return return_value;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -125,12 +125,10 @@ public :
int int
main() main()
{ {
cout << "[ moHCMoveLoopExpl ] ==> "; std::string test_result, test_1, test_2;
int return_value, value_1, value_2;
solution sol1, sol2; solution solution_1, solution_2;
sol1.fitness(0);
sol2.fitness(0);
testMoveInit init; testMoveInit init;
testMoveNext next; testMoveNext next;
@ -139,16 +137,34 @@ main()
moHCMoveLoopExpl<testMove> explorer(init, next, incrEval, select); moHCMoveLoopExpl<testMove> explorer(init, next, incrEval, select);
explorer(sol1, sol2); cout << "[ moHCMoveLoopExpl ] ==> ";
if(sol2.fitness()!=2) test_1="KO";
try
{ {
cout << "KO" << endl; explorer(solution_1, solution_2);
return EXIT_FAILURE; }
catch(std::runtime_error e)
{
test_1="OK";
} }
cout << "OK" << endl; value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
return 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;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -61,6 +61,8 @@ class testMoveExplorer : public moMoveExpl<testMove>
public : public :
void operator () (const solution & _solution_1, solution & _solution_2) void operator () (const solution & _solution_1, solution & _solution_2)
{ {
const solution sol(_solution_1);
_solution_2.fitness(2); _solution_2.fitness(2);
} }
}; };
@ -80,25 +82,25 @@ public :
int int
main() main()
{ {
cout << "[ moHC_2 ] ==> "; std::string test_result;
int return_value;
solution sol; solution solution;
solutionEval eval; solutionEval eval;
testMoveExplorer explorer; testMoveExplorer explorer;
moHC<testMove> hc(explorer, eval); moHC<testMove> hc(explorer, eval);
hc(sol); cout << "[ moHC_2 ] ==> ";
if(sol.fitness()!=2) hc(solution);
{
cout << "KO" << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; test_result=((solution.fitness()!=2)?"KO":"OK");
return EXIT_SUCCESS; return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
cout << test_result << endl;
return return_value;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -61,7 +61,7 @@ class solutionAlgo : public moAlgo <solution>
public : public :
bool operator () (solution & _solution) bool operator () (solution & _solution)
{ {
_solution.fitness(2); solution solution(_solution);
return true; return true;
} }
} ; } ;
@ -69,27 +69,49 @@ public :
class solutionContinue : public moSolContinue<solution> class solutionContinue : public moSolContinue<solution>
{ {
public : public :
solutionContinue(): counter(0)
{}
bool operator () (const solution & _solution) bool operator () (const solution & _solution)
{ {
const solution sol(_solution); const solution sol(_solution);
if(counter<2)
{
counter++;
return true;
}
return false; return false;
} }
void init() void init()
{} {}
private :
unsigned int counter;
} ; } ;
class solutionComparator : public moComparator<solution> class solutionComparator : public moComparator<solution>
{ {
public : public :
solutionComparator() : counter(0)
{}
bool operator () (const solution & _solution1 , const solution & _solution2) bool operator () (const solution & _solution1 , const solution & _solution2)
{ {
const solution sol1(_solution1); const solution sol1(_solution1);
const solution sol2(_solution2); const solution sol2(_solution2);
if(counter<2)
{
counter++;
return false;
}
return true; return true;
} }
private :
unsigned int counter;
} ; } ;
class solutionPerturbation : public eoMonOp<solution> class solutionPerturbation : public eoMonOp<solution>
@ -97,7 +119,7 @@ class solutionPerturbation : public eoMonOp<solution>
public : public :
bool operator () (solution & _solution) bool operator () (solution & _solution)
{ {
solution sol(_solution); _solution.fitness(2);
return true; return true;
} }
@ -108,7 +130,7 @@ class solutionEval : public eoEvalFunc <solution>
public : public :
void operator () (solution & _solution) void operator () (solution & _solution)
{ {
_solution.fitness(0); solution solution(_solution);
} }
} ; } ;
@ -117,11 +139,10 @@ public :
int int
main() main()
{ {
cout << "[ moILS ] ==> "; std::string test_result;
int return_value;
solution sol; solution solution;
sol.fitness(0);
solutionAlgo algorithm; solutionAlgo algorithm;
solutionContinue continu; solutionContinue continu;
@ -131,16 +152,17 @@ main()
moILS<testMove> ils(algorithm, continu, comparator, perturbation, eval); moILS<testMove> ils(algorithm, continu, comparator, perturbation, eval);
ils(sol); cout << "[ moILS ] ==> ";
if(sol.fitness()!=2) solution.fitness(0);
{
cout << "KO" << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; ils(solution);
return EXIT_SUCCESS;
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;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -132,15 +132,25 @@ public :
class solutionContinue : public moSolContinue<solution> class solutionContinue : public moSolContinue<solution>
{ {
public : public :
solutionContinue(): counter(0)
{}
bool operator () (const solution & _solution) bool operator () (const solution & _solution)
{ {
const solution sol(_solution); const solution sol(_solution);
if(counter==0)
{
counter++;
return true;
}
return false; return false;
} }
void init() void init()
{} {}
private :
unsigned int counter;
} ; } ;
class solutionComparator : public moComparator<solution> class solutionComparator : public moComparator<solution>
@ -160,7 +170,7 @@ class solutionPerturbation : public eoMonOp<solution>
public : public :
bool operator () (solution & _solution) bool operator () (solution & _solution)
{ {
solution sol(_solution); _solution.fitness(2);
return true; return true;
} }
@ -171,34 +181,31 @@ public :
int int
main() main()
{ {
cout << "[ moILS_HC ] ==> "; std::string test_result;
int return_value;
solution sol; solution solution;
testMoveInit init; testMoveInit init;
testMoveNext next; testMoveNext next;
testMoveIncrEval incrEval; testMoveIncrEval incrEval;
testMoveSelect select; testMoveSelect select;
solutionEval eval; solutionEval eval;
moHC<testMove> hc(init, next, incrEval, select, eval);
solutionContinue continu; solutionContinue continu;
solutionComparator comparator; solutionComparator comparator;
solutionPerturbation perturbation; solutionPerturbation perturbation;
moILS<testMove> ils(hc, continu, comparator, perturbation, eval); moILS<testMove> ils(init, next, incrEval, select, continu, comparator, perturbation, eval);
ils(sol); cout << "[ moILS_HC ] ==> ";
if(sol.fitness()!=2) ils(solution);
{
cout << "KO" << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; test_result=((solution.fitness()!=2)?"KO":"OK");
return EXIT_SUCCESS; return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
cout << test_result << endl;
return return_value;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -94,34 +94,50 @@ class solutionEval : public eoEvalFunc <solution>
public : public :
void operator () (solution & _solution) void operator () (solution & _solution)
{ {
_solution.fitness(2); const solution solution(_solution);
} }
} ; } ;
class solutionContinue : public moSolContinue<solution> class solutionContinue : public moSolContinue<solution>
{ {
public : public :
solutionContinue(): counter(0)
{}
bool operator () (const solution & _solution) bool operator () (const solution & _solution)
{ {
const solution sol(_solution); const solution sol(_solution);
if(counter==0)
{
counter++;
return true;
}
return false; return false;
} }
void init() void init()
{} {}
private :
unsigned int counter;
} ; } ;
class solutionComparator : public moComparator<solution> class solutionComparator : public moComparator<solution>
{ {
public : public :
solutionComparator() : counter(0)
{}
bool operator () (const solution & _solution1 , const solution & _solution2) bool operator () (const solution & _solution1 , const solution & _solution2)
{ {
const solution sol1(_solution1); const solution solution1(_solution1);
const solution sol2(_solution2); const solution solution2(_solution2);
return true; return true;
} }
private :
unsigned int counter;
} ; } ;
class solutionPerturbation : public eoMonOp<solution> class solutionPerturbation : public eoMonOp<solution>
@ -129,7 +145,7 @@ class solutionPerturbation : public eoMonOp<solution>
public : public :
bool operator () (solution & _solution) bool operator () (solution & _solution)
{ {
solution sol(_solution); _solution.fitness(2);
return true; return true;
} }
@ -140,35 +156,35 @@ public :
int int
main() main()
{ {
cout << "[ moILS_SA ] ==> "; std::string test_result;
int return_value;
solution sol; solution solution;
sol.fitness(0);
testRandMove rand; testRandMove rand;
testMoveIncrEval incrEval; testMoveIncrEval incrEval;
solutionContinue continu; solutionContinue continu;
solutionContinue continu_2;
testCooling cooling; testCooling cooling;
solutionEval eval; solutionEval eval;
moSA<testMove> sa(rand, incrEval, continu, 10.0, cooling, eval);
solutionComparator comparator; solutionComparator comparator;
solutionPerturbation perturbation; solutionPerturbation perturbation;
moILS<testMove> ils(sa, continu, comparator, perturbation, eval); moILS<testMove> ils(rand, incrEval, continu, 10.0, cooling, continu_2, comparator, perturbation, eval);
ils(sol); cout << "[ moILS_SA ] ==> ";
if(sol.fitness()!=2) solution.fitness(0);
{
cout << "KO" << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; eval(solution);
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;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -133,15 +133,25 @@ public:
class solutionContinue : public moSolContinue<solution> class solutionContinue : public moSolContinue<solution>
{ {
public : public :
solutionContinue(): counter(0)
{}
bool operator () (const solution & _solution) bool operator () (const solution & _solution)
{ {
const solution sol(_solution); const solution sol(_solution);
if(counter==0)
{
counter++;
return true;
}
return false; return false;
} }
void init() void init()
{} {}
private :
unsigned int counter;
} ; } ;
class solutionComparator : public moComparator<solution> class solutionComparator : public moComparator<solution>
@ -161,7 +171,7 @@ class solutionPerturbation : public eoMonOp<solution>
public : public :
bool operator () (solution & _solution) bool operator () (solution & _solution)
{ {
solution sol(_solution); _solution.fitness(2);
return true; return true;
} }
@ -172,7 +182,7 @@ class solutionEval : public eoEvalFunc <solution>
public : public :
void operator () (solution & _solution) void operator () (solution & _solution)
{ {
_solution.fitness(2); _solution.fitness(0);
} }
} ; } ;
@ -181,11 +191,10 @@ public :
int int
main() main()
{ {
cout << "[ moILS_TS ] ==> "; std::string test_result;
int return_value;
solution sol; solution solution;
sol.fitness(0);
testMoveInit init; testMoveInit init;
testMoveNext next; testMoveNext next;
@ -194,24 +203,21 @@ main()
testAspirCrit aspirCrit; testAspirCrit aspirCrit;
solutionEval eval; solutionEval eval;
solutionContinue continu; solutionContinue continu;
solutionContinue continu_2;
moTS<testMove> ts(init, next, incrEval, tabuList, aspirCrit, continu, eval);
solutionComparator comparator; solutionComparator comparator;
solutionPerturbation perturbation; solutionPerturbation perturbation;
moILS<testMove> ils(ts, continu, comparator, perturbation, eval); moILS<testMove> ils(init, next, incrEval, tabuList, aspirCrit, continu, continu_2, comparator, perturbation, eval);
ils(sol); cout << "[ moILS_TS ] ==> ";
if(sol.fitness()!=2) ils(solution);
{
cout << "KO" << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; test_result=((solution.fitness()!=2)?"KO":"OK");
return EXIT_SUCCESS; return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
cout << test_result << endl;
return return_value;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -61,6 +61,11 @@ public :
int int
main() main()
{ {
std::string test_result, test_1, test_2;
int return_value, value_1, value_2;
solution solution;
unsigned int i; unsigned int i;
moImprBestFitAspirCrit<testMove> aspirCriterion; moImprBestFitAspirCrit<testMove> aspirCriterion;
@ -77,12 +82,8 @@ main()
i++; i++;
} }
if(i!=10) test_1=((i!=10)?"KO":"OK");
{ value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
cout << "KO" << endl;
cout << "before init, i = " << i << endl;
return EXIT_FAILURE;
}
aspirCriterion.init(); aspirCriterion.init();
aspirCriterion(move, i); aspirCriterion(move, i);
@ -93,15 +94,16 @@ main()
i++; i++;
} }
if(i!=10) move(solution);
{
cout << "KO" << endl;
cout << "after init, i = " << i << endl;
return EXIT_FAILURE;
}
cout << "OK" << std::endl; test_2=((i!=10)?"KO":"OK");
return EXIT_SUCCESS; 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;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -70,10 +70,13 @@ public :
int int
main() main()
{ {
std::string test_result, test_1, test_2;
int value_1, value_2, return_value;
unsigned int i; unsigned int i;
testMove move; testMove move;
solution sol; solution solution;
testRandMove rand; testRandMove rand;
@ -82,33 +85,30 @@ main()
cout << "[ moItRandNextMove ] ==> "; cout << "[ moItRandNextMove ] ==> ";
i=0; i=0;
while( next(move, sol) && i<15 ) while( next(move, solution) && i<15 )
{ {
i++; i++;
} }
if(i!=11) test_1=((i!=11)?"KO":"OK");
{ value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
cout << "KO" << endl;
cout << "First time, i = " << i << endl;
return EXIT_FAILURE;
}
i=0; i=0;
while( next(move, sol) && i<15 ) while( next(move, solution) && i<15 )
{ {
i++; i++;
} }
if(i!=11) move(solution);
{
cout << "KO" << endl;
cout << "Second time, i = " << i << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; test_2=((i!=11)?"KO":"OK");
return EXIT_SUCCESS; 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;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -72,43 +72,45 @@ class testBF : public eoBF<const testMove & , const testMove::EOType &, void>
int int
main() main()
{ {
std::string test_result, test_1, test_2;
int value_1, value_2, return_value;
unsigned int i; unsigned int i;
std::string result; std::string result;
testBF test; testBF test;
moLSCheckPoint<testMove> checkpoint; moLSCheckPoint<testMove> checkpoint;
solution sol; solution solution;
testMove move; testMove move;
std::ifstream is;
cout << "[ moLSCheckPoint ] ==> "; cout << "[ moLSCheckPoint ] ==> ";
i=0; i=0;
checkpoint.add(test); checkpoint.add(test);
checkpoint(move, sol); checkpoint(move, solution);
std::ifstream is("test.txt"); move(solution);
if(!is.is_open()) is.open("test.txt");
{
cout << "KO" << endl; test_1=((!is.is_open())?"KO":"OK");
cout << "test.txt does not exist" << endl; value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
return EXIT_FAILURE;
}
is >> result; is >> result;
if(result.compare("OK")!=0) test_2=((result.compare("OK")!=0)?"KO":"OK");
{ value_2=((test_2.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
cout << "KO" << endl;
cout << "result = " << result << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO");
return EXIT_SUCCESS; return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE);
cout << test_result << endl;
return return_value;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -51,30 +51,29 @@ using std::endl;
int int
main() main()
{ {
std::string test_result;
int return_value;
unsigned int i; unsigned int i;
double temperature; double temperature;
moLinearCoolingSchedule coolingSchedule( 1.0, 0.5 ); moLinearCoolingSchedule coolingSchedule( 1.0, 0.5 );
temperature=2.0;
cout << "[ moLinearCoolingSchedule ] ==> "; cout << "[ moLinearCoolingSchedule ] ==> ";
temperature=2.0;
i=0; i=0;
while( coolingSchedule(temperature) ) while( coolingSchedule(temperature) )
{ {
i++; i++;
} }
if(i!=1) test_result=((i!=1)?"KO":"OK");
{ return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
cout << "KO" << endl;
cout << "i = " << i << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; cout << test_result << endl;
return EXIT_SUCCESS; return return_value;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -61,20 +61,25 @@ public :
int int
main() main()
{ {
std::string test_result;
int return_value;
unsigned int i; unsigned int i;
moNoAspirCrit<testMove> aspirCriterion; moNoAspirCrit<testMove> aspirCriterion;
testMove move; testMove move;
solution solution;
cout << "[ moNoAspirCrit ] ==> "; cout << "[ moNoAspirCrit ] ==> ";
if( aspirCriterion(move, i) ) move(solution);
{
cout << "KO" << endl;
return EXIT_FAILURE;
}
cout << "OK" << std::endl; aspirCriterion.init();
return EXIT_SUCCESS;
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;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -52,30 +52,50 @@ typedef EO<unsigned int> solution;
int int
main() main()
{ {
std::string test_result, test_1, test_2;
int return_value, value_1, value_2;
unsigned int i; unsigned int i;
solution sol;
moNoFitImprSolContinue<solution> continu(10); moNoFitImprSolContinue<solution> continu(10);
solution solution;
cout << "[ moNoFitImprSolContinue ] ==> "; cout << "[ moNoFitImprSolContinue ] ==> ";
sol.fitness(2); continu.init();
test_1="KO";
try
{
continu(solution);
}
catch(std::runtime_error e)
{
test_1="OK";
}
value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
solution.fitness(0);
i=0; i=0;
while( continu(sol) ) while( continu(solution) )
{ {
i++; i++;
solution.fitness(2);
} }
if(i!=10) test_2=((i!=11)?"KO":"OK");
{ value_2=((test_2.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
cout << "KO" << endl;
cout << "i = " << i << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO");
return EXIT_SUCCESS; return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE);
cout << test_result << endl;
return return_value;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -61,43 +61,55 @@ public :
int int
main() 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<testMove> selection; moRandImprSelect<testMove> selection;
solution sol; solution solution;
testMove move; testMove move;
cout << "[ moRandImprSelect ] ==> "; cout << "[ moRandImprSelect ] ==> ";
i=fitness=0; selection.init(0);
selection.init(5); test_1="KO";
for(i=1;i<10;i++) i=0;
try
{ {
if(! selection.update(move, i) ) selection(move, i);
{ }
cout << "KO" << endl; catch(std::runtime_error e)
cout << "update is false" << endl; {
return EXIT_FAILURE; test_1="OK";
}
} }
for(i=0;i<10;i++) value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
{
selection(move, fitness);
if(fitness<=5)
{
cout << "KO" << endl;
cout << "fitness = " << fitness << endl;
return EXIT_FAILURE;
}
}
cout << "OK" << endl; move(solution);
return EXIT_SUCCESS;
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;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -68,27 +68,50 @@ public :
class testMoveIncrEval : public moMoveIncrEval <testMove> class testMoveIncrEval : public moMoveIncrEval <testMove>
{ {
public : public :
testMoveIncrEval() : counter(0)
{}
int operator () (const testMove & _move, const solution & _solution) int operator () (const testMove & _move, const solution & _solution)
{ {
const testMove move(_move); const testMove move(_move);
const solution solution(_solution); const solution solution(_solution);
return 2; if(counter==0)
{
counter++;
return 2;
}
return 0;
} }
private :
unsigned int counter;
} ; } ;
class solutionContinue : public moSolContinue<solution> class solutionContinue : public moSolContinue<solution>
{ {
public : public :
solutionContinue() : counter(0)
{}
bool operator () (const solution & _solution) bool operator () (const solution & _solution)
{ {
const solution sol(_solution); const solution sol(_solution);
if(counter==0)
{
counter++;
return true;
}
return false; return false;
} }
void init() void init()
{} {}
private :
unsigned int counter;
} ; } ;
class testCooling : public moCoolingSchedule class testCooling : public moCoolingSchedule
@ -108,7 +131,7 @@ class solutionEval : public eoEvalFunc <solution>
public : public :
void operator () (solution & _solution) void operator () (solution & _solution)
{ {
_solution.fitness(2); _solution.fitness(0);
} }
} ; } ;
@ -118,11 +141,10 @@ public :
int int
main() main()
{ {
cout << "[ moSA ] ==> "; std::string test_result;
int return_value;
solution sol; solution solution;
sol.fitness(0);
testRandMove rand; testRandMove rand;
testMoveIncrEval incrEval; testMoveIncrEval incrEval;
@ -132,16 +154,15 @@ main()
moSA<testMove> sa(rand, incrEval, continu, 10.0, cooling, eval); moSA<testMove> sa(rand, incrEval, continu, 10.0, cooling, eval);
sa(sol); cout << "[ moSA ] ==> ";
if(sol.fitness()!=2) sa(solution);
{
cout << "KO" << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; test_result=((solution.fitness()!=2)?"KO":"OK");
return EXIT_SUCCESS; return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
cout << test_result << endl;
return return_value;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -50,6 +50,9 @@ typedef EO<unsigned int> solution;
class testMove : public moMove <solution> class testMove : public moMove <solution>
{ {
public : public :
testMove(unsigned int _value): value(_value)
{}
void operator () (solution & _solution) void operator () (solution & _solution)
{ {
_solution=_solution; _solution=_solution;
@ -57,11 +60,10 @@ public :
bool operator == (const testMove & _move) bool operator == (const testMove & _move)
{ {
testMove move; return (value==_move.value);
move=(testMove)_move;
return true;
} }
private :
unsigned int value;
} ; } ;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -69,24 +71,34 @@ public :
int int
main() main()
{ {
std::string test_result;
int return_value;
moSimpleMoveTabuList<testMove> tabuList(1); moSimpleMoveTabuList<testMove> tabuList(1);
solution sol; solution solution;
testMove move; testMove move_1(1), move_2(2);
cout << "[ moSimpleMoveTabuList ] ==> "; cout << "[ moSimpleMoveTabuList ] ==> ";
tabuList.add(move, sol); tabuList.init();
tabuList.update();
if( !tabuList(move, sol) ) tabuList.add(move_1, solution);
{
cout << "KO" << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; tabuList(move_2, solution);
return EXIT_SUCCESS;
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;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -45,48 +45,62 @@ using std::endl;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
typedef EO<unsigned int> solution; class solution : public EO<unsigned int>
{
public:
solution(unsigned int _value): value(_value)
{}
bool operator == (const solution & _solution)
{
return (value==_solution.value);
}
private:
unsigned int value;
};
class testMove : public moMove <solution> class testMove : public moMove <solution>
{ {
public : public :
void operator () (solution & _solution) void operator () (solution & _solution)
{ {
_solution=_solution; solution solution(_solution);
} }
};
bool operator == (const testMove & _move)
{
testMove move;
move=(testMove)_move;
return true;
}
} ;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
int int
main() main()
{ {
moSimpleMoveTabuList<testMove> tabuList(1); std::string test_result;
int return_value;
solution sol; moSimpleSolutionTabuList<testMove> tabuList(1);
solution solution_1(1), solution_2(2);
testMove move; testMove move;
cout << "[ moSimpleSolutionTabuList ] ==> "; cout << "[ moSimpleSolutionTabuList ] ==> ";
tabuList.add(move, sol); tabuList.init();
tabuList.update();
if( !tabuList(move, sol) ) tabuList.add(move, solution_1);
{
cout << "KO" << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; move(solution_1);
return EXIT_SUCCESS;
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;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -52,33 +52,57 @@ typedef EO<unsigned int> solution;
int int
main() main()
{ {
std::string test_result, test_1, test_2;
int return_value, value_1, value_2;
unsigned int i; unsigned int i;
solution sol; solution solution_1, solution_2;
moSteadyFitSolContinue<solution> continu(10,10); moSteadyFitSolContinue<solution> continu(10,10);
cout << "[ moSteadyFitSolContinue ] ==> "; cout << "[ moSteadyFitSolContinue ] ==> ";
continu.init();
i=0; i=0;
sol.fitness(i); solution_1.fitness(i);
while( continu(sol) && i<50) while( continu(solution_1) && i<50)
{ {
i++; i++;
if(i<11) 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) test_2=((i!=25)?"KO":"OK");
{ value_2=((test_2.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
cout << "KO" << endl;
cout << "i = " << i << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO");
return EXIT_SUCCESS; return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE);
cout << test_result << endl;
return return_value;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -159,11 +159,10 @@ public :
int int
main() main()
{ {
cout << "[ moTS ] ==> "; std::string test_result;
int return_value;
solution sol; solution solution;
sol.fitness(0);
testMoveInit init; testMoveInit init;
testMoveNext next; testMoveNext next;
@ -175,16 +174,15 @@ main()
moTS<testMove> ts(init, next, incrEval, tabuList, aspirCrit, continu, eval); moTS<testMove> ts(init, next, incrEval, tabuList, aspirCrit, continu, eval);
ts(sol); cout << "[ moTS ] ==> ";
if(sol.fitness()!=2) ts(solution);
{
cout << "KO" << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; test_result=((solution.fitness()!=2)?"KO":"OK");
return EXIT_SUCCESS; return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
cout << test_result << endl;
return return_value;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -135,12 +135,10 @@ public:
int int
main() main()
{ {
cout << "[ moTSMoveLoopExpl ] ==> "; std::string test_result, test_1, test_2;
int return_value, value_1, value_2;
solution sol1 ,sol2; solution solution_1 ,solution_2;
sol1.fitness(0);
sol2.fitness(0);
testMoveInit init; testMoveInit init;
testMoveNext next; testMoveNext next;
@ -150,16 +148,33 @@ main()
moTSMoveLoopExpl<testMove> explorer(init, next, incrEval, tabuList, aspirCrit); moTSMoveLoopExpl<testMove> explorer(init, next, incrEval, tabuList, aspirCrit);
explorer(sol1, sol2); cout << "[ moTSMoveLoopExpl ] ==> ";
if(sol2.fitness()!=2) test_1="KO";
try
{ {
cout << "KO" << endl; explorer(solution_1, solution_2);
return EXIT_FAILURE; }
catch(std::runtime_error e)
{
test_1="OK";
} }
cout << "OK" << endl; value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
return 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;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -61,6 +61,7 @@ class testMoveExplorer : public moMoveExpl<testMove>
public : public :
void operator () (const solution & _solution_1, solution & _solution_2) void operator () (const solution & _solution_1, solution & _solution_2)
{ {
const solution solution(_solution_1);
_solution_2.fitness(2); _solution_2.fitness(2);
} }
}; };
@ -94,26 +95,29 @@ public :
int int
main() main()
{ {
cout << "[ moTS_2 ] ==> "; std::string test_result;
int return_value;
solution sol; solution solution;
testMoveExplorer explorer; testMoveExplorer explorer;
solutionContinue continu; solutionContinue continu;
solutionEval eval; solutionEval eval;
testMove move;
moTS<testMove> ts(explorer, continu, eval); moTS<testMove> ts(explorer, continu, eval);
ts(sol); cout << "[ moTS_2 ] ==> ";
if(sol.fitness()!=2) ts(solution);
{
cout << "KO" << endl;
return EXIT_FAILURE;
}
cout << "OK" << endl; move(solution);
return EXIT_SUCCESS;
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;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------