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:
parent
a000ce368c
commit
4d252c4373
30 changed files with 616 additions and 394 deletions
|
|
@ -133,10 +133,10 @@ class moILS:public moAlgo < typename M::EOType >
|
|||
double _initial_temperature, moCoolingSchedule & _cooling_schedule, moSolContinue <EOT> & _continue,
|
||||
moComparator<EOT> & _acceptance_criterion, eoMonOp<EOT> & _perturbation, eoEvalFunc<EOT> & _full_evaluation):
|
||||
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),
|
||||
algorithm_memory_allocation(true)
|
||||
{}
|
||||
{}
|
||||
|
||||
//! Destructor
|
||||
~moILS()
|
||||
|
|
|
|||
|
|
@ -143,6 +143,7 @@ class moSimpleSolutionTabuList: public moTabuList < M >
|
|||
if (it!=tabuList.end())
|
||||
{
|
||||
tabuList.erase(it);
|
||||
memory_size--;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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<testMove> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -61,11 +61,13 @@ public :
|
|||
int
|
||||
main()
|
||||
{
|
||||
std::string test_result;
|
||||
int return_value;
|
||||
unsigned int i, fitness;
|
||||
|
||||
moFirstImprSelect<testMove> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -52,6 +52,9 @@ typedef EO<unsigned int> solution;
|
|||
int
|
||||
main()
|
||||
{
|
||||
std::string test_result;
|
||||
int return_value;
|
||||
|
||||
solution sol1, sol2;
|
||||
|
||||
moFitComparator<solution> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -52,30 +52,50 @@ typedef EO<unsigned int> 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<solution> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -52,6 +52,9 @@ typedef EO<unsigned int> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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<testMove> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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<testMove> 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<testMove> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -61,6 +61,8 @@ class testMoveExplorer : public moMoveExpl<testMove>
|
|||
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<testMove> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ class solutionAlgo : public moAlgo <solution>
|
|||
public :
|
||||
bool operator () (solution & _solution)
|
||||
{
|
||||
_solution.fitness(2);
|
||||
solution solution(_solution);
|
||||
return true;
|
||||
}
|
||||
} ;
|
||||
|
|
@ -69,27 +69,49 @@ public :
|
|||
class solutionContinue : public moSolContinue<solution>
|
||||
{
|
||||
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<solution>
|
||||
{
|
||||
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<solution>
|
||||
|
|
@ -97,7 +119,7 @@ class solutionPerturbation : public eoMonOp<solution>
|
|||
public :
|
||||
bool operator () (solution & _solution)
|
||||
{
|
||||
solution sol(_solution);
|
||||
_solution.fitness(2);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -108,7 +130,7 @@ class solutionEval : public eoEvalFunc <solution>
|
|||
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<testMove> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -132,15 +132,25 @@ public :
|
|||
class solutionContinue : public moSolContinue<solution>
|
||||
{
|
||||
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<solution>
|
||||
|
|
@ -160,7 +170,7 @@ class solutionPerturbation : public eoMonOp<solution>
|
|||
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<testMove> hc(init, next, incrEval, select, eval);
|
||||
|
||||
solutionContinue continu;
|
||||
solutionComparator comparator;
|
||||
solutionPerturbation perturbation;
|
||||
|
||||
moILS<testMove> ils(hc, continu, comparator, perturbation, eval);
|
||||
|
||||
ils(sol);
|
||||
|
||||
if(sol.fitness()!=2)
|
||||
{
|
||||
cout << "KO" << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
moILS<testMove> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -94,34 +94,50 @@ class solutionEval : public eoEvalFunc <solution>
|
|||
public :
|
||||
void operator () (solution & _solution)
|
||||
{
|
||||
_solution.fitness(2);
|
||||
const solution solution(_solution);
|
||||
}
|
||||
} ;
|
||||
|
||||
class solutionContinue : public moSolContinue<solution>
|
||||
{
|
||||
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<solution>
|
||||
{
|
||||
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<solution>
|
||||
|
|
@ -129,7 +145,7 @@ class solutionPerturbation : public eoMonOp<solution>
|
|||
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<testMove> sa(rand, incrEval, continu, 10.0, cooling, eval);
|
||||
|
||||
solutionComparator comparator;
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -133,15 +133,25 @@ public:
|
|||
class solutionContinue : public moSolContinue<solution>
|
||||
{
|
||||
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<solution>
|
||||
|
|
@ -161,7 +171,7 @@ class solutionPerturbation : public eoMonOp<solution>
|
|||
public :
|
||||
bool operator () (solution & _solution)
|
||||
{
|
||||
solution sol(_solution);
|
||||
_solution.fitness(2);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -172,7 +182,7 @@ class solutionEval : public eoEvalFunc <solution>
|
|||
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<testMove> ts(init, next, incrEval, tabuList, aspirCrit, continu, eval);
|
||||
|
||||
solutionContinue continu_2;
|
||||
solutionComparator comparator;
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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<testMove> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -72,43 +72,45 @@ class testBF : public eoBF<const testMove & , const testMove::EOType &, void>
|
|||
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<testMove> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -61,20 +61,25 @@ public :
|
|||
int
|
||||
main()
|
||||
{
|
||||
std::string test_result;
|
||||
int return_value;
|
||||
|
||||
unsigned int i;
|
||||
moNoAspirCrit<testMove> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -52,30 +52,50 @@ typedef EO<unsigned int> solution;
|
|||
int
|
||||
main()
|
||||
{
|
||||
std::string test_result, test_1, test_2;
|
||||
int return_value, value_1, value_2;
|
||||
|
||||
|
||||
unsigned int i;
|
||||
solution sol;
|
||||
|
||||
moNoFitImprSolContinue<solution> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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<testMove> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -68,27 +68,50 @@ public :
|
|||
class testMoveIncrEval : public moMoveIncrEval <testMove>
|
||||
{
|
||||
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<solution>
|
||||
{
|
||||
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 <solution>
|
|||
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<testMove> 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<testMove> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -50,6 +50,9 @@ typedef EO<unsigned int> solution;
|
|||
class testMove : public moMove <solution>
|
||||
{
|
||||
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<testMove> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
{
|
||||
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<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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -52,33 +52,57 @@ typedef EO<unsigned int> 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<solution> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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<testMove> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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<testMove> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ class testMoveExplorer : public moMoveExpl<testMove>
|
|||
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<testMove> 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue