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,
|
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()
|
||||||
|
|
|
||||||
|
|
@ -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--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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;
|
test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO");
|
||||||
cout << "fitness = " << fitness << endl;
|
return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE);
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "OK" << endl;
|
cout << test_result << endl;
|
||||||
return EXIT_SUCCESS;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -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;
|
cout << test_result << endl;
|
||||||
return EXIT_FAILURE;
|
return return_value;
|
||||||
}
|
|
||||||
|
|
||||||
cout << "OK" << endl;
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -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;
|
test_result=((fitness!=11)?"KO":"OK");
|
||||||
cout << "fitness = " << fitness << endl;
|
return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
cout << test_result << endl;
|
||||||
|
return return_value;
|
||||||
cout << "OK" << std::endl;
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -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 << test_result << endl;
|
||||||
}
|
return return_value;
|
||||||
|
|
||||||
cout << "OK" << endl;
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -52,30 +52,50 @@ typedef EO<unsigned int> solution;
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
unsigned int i;
|
std::string test_result, test_1, test_2;
|
||||||
solution sol;
|
int return_value, value_1, value_2;
|
||||||
|
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
moFitSolContinue<solution> continu(10);
|
moFitSolContinue<solution> continu(10);
|
||||||
|
|
||||||
|
solution solution;
|
||||||
|
|
||||||
cout << "[ moFitSolContinue ] ==> ";
|
cout << "[ moFitSolContinue ] ==> ";
|
||||||
|
|
||||||
i=0;
|
continu.init();
|
||||||
sol.fitness(i);
|
|
||||||
while( continu(sol) )
|
test_1="KO";
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
i++;
|
continu(solution);
|
||||||
sol.fitness(i);
|
}
|
||||||
|
catch(std::runtime_error e)
|
||||||
|
{
|
||||||
|
test_1="OK";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(i!=10)
|
value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
|
||||||
{
|
|
||||||
cout << "KO" << endl;
|
|
||||||
cout << "i = " << i << endl;
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
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();
|
||||||
|
|
||||||
|
|
@ -79,16 +78,15 @@ main()
|
||||||
{
|
{
|
||||||
i++;
|
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 << test_result << endl;
|
||||||
{
|
return return_value;
|
||||||
cout << "KO" << endl;
|
|
||||||
cout << "after init: i = " << i << endl;
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "OK" << endl;
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -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)
|
|
||||||
{
|
|
||||||
cout << "KO" << endl;
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "OK" << endl;
|
hc(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -125,30 +125,46 @@ 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;
|
||||||
testMoveIncrEval incrEval;
|
testMoveIncrEval incrEval;
|
||||||
testMoveSelect select;
|
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;
|
moHCMoveLoopExpl<testMove> explorer(init, next, incrEval, select);
|
||||||
return EXIT_SUCCESS;
|
|
||||||
|
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 :
|
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)
|
|
||||||
{
|
|
||||||
cout << "KO" << endl;
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "OK" << endl;
|
hc(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -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,30 +139,30 @@ public :
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
cout << "[ moILS ] ==> ";
|
std::string test_result;
|
||||||
|
int return_value;
|
||||||
|
|
||||||
|
solution solution;
|
||||||
|
|
||||||
solution sol;
|
|
||||||
|
|
||||||
sol.fitness(0);
|
|
||||||
|
|
||||||
solutionAlgo algorithm;
|
solutionAlgo algorithm;
|
||||||
solutionContinue continu;
|
solutionContinue continu;
|
||||||
solutionComparator comparator;
|
solutionComparator comparator;
|
||||||
solutionPerturbation perturbation;
|
solutionPerturbation perturbation;
|
||||||
solutionEval eval;
|
solutionEval eval;
|
||||||
|
|
||||||
moILS<testMove> ils(algorithm, continu, comparator, perturbation, eval);
|
moILS<testMove> ils(algorithm, continu, comparator, perturbation, eval);
|
||||||
|
|
||||||
ils(sol);
|
cout << "[ moILS ] ==> ";
|
||||||
|
|
||||||
if(sol.fitness()!=2)
|
|
||||||
{
|
|
||||||
cout << "KO" << endl;
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "OK" << endl;
|
solution.fitness(0);
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
|
|
||||||
if(sol.fitness()!=2)
|
|
||||||
{
|
|
||||||
cout << "KO" << endl;
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "OK" << endl;
|
cout << "[ moILS_HC ] ==> ";
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -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;
|
eval(solution);
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -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;
|
|
||||||
|
|
||||||
sol.fitness(0);
|
solution solution;
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -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;
|
test_2=((i!=10)?"KO":"OK");
|
||||||
cout << "after init, i = " << i << endl;
|
value_2=((test_2.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
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" << std::endl;
|
|
||||||
return EXIT_SUCCESS;
|
cout << test_result << endl;
|
||||||
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -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;
|
test_2=((i!=11)?"KO":"OK");
|
||||||
cout << "Second time, i = " << i << endl;
|
value_2=((test_2.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -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;
|
test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO");
|
||||||
return EXIT_FAILURE;
|
return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE);
|
||||||
}
|
|
||||||
|
|
||||||
cout << "OK" << endl;
|
cout << test_result << endl;
|
||||||
return EXIT_SUCCESS;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -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;
|
cout << test_result << endl;
|
||||||
return EXIT_FAILURE;
|
return return_value;
|
||||||
}
|
|
||||||
|
|
||||||
cout << "OK" << endl;
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -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) )
|
|
||||||
{
|
|
||||||
cout << "KO" << endl;
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "OK" << std::endl;
|
move(solution);
|
||||||
return EXIT_SUCCESS;
|
|
||||||
|
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
|
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();
|
||||||
|
|
||||||
i=0;
|
test_1="KO";
|
||||||
while( continu(sol) )
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
i++;
|
continu(solution);
|
||||||
}
|
}
|
||||||
|
catch(std::runtime_error e)
|
||||||
if(i!=10)
|
|
||||||
{
|
{
|
||||||
cout << "KO" << endl;
|
test_1="OK";
|
||||||
cout << "i = " << i << endl;
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "OK" << endl;
|
value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
|
||||||
return 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
|
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";
|
||||||
|
|
||||||
|
i=0;
|
||||||
|
|
||||||
for(i=1;i<10;i++)
|
try
|
||||||
{
|
{
|
||||||
if(! selection.update(move, i) )
|
selection(move, i);
|
||||||
{
|
|
||||||
cout << "KO" << endl;
|
|
||||||
cout << "update is false" << endl;
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
catch(std::runtime_error e)
|
||||||
for(i=0;i<10;i++)
|
|
||||||
{
|
{
|
||||||
selection(move, fitness);
|
test_1="OK";
|
||||||
if(fitness<=5)
|
|
||||||
{
|
|
||||||
cout << "KO" << endl;
|
|
||||||
cout << "fitness = " << fitness << endl;
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "OK" << endl;
|
value_1=((test_1.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
|
||||||
return 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>
|
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,30 +141,28 @@ public :
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
cout << "[ moSA ] ==> ";
|
std::string test_result;
|
||||||
|
int return_value;
|
||||||
|
|
||||||
|
solution solution;
|
||||||
|
|
||||||
solution sol;
|
|
||||||
|
|
||||||
sol.fitness(0);
|
|
||||||
|
|
||||||
testRandMove rand;
|
testRandMove rand;
|
||||||
testMoveIncrEval incrEval;
|
testMoveIncrEval incrEval;
|
||||||
solutionContinue continu;
|
solutionContinue continu;
|
||||||
testCooling cooling;
|
testCooling cooling;
|
||||||
solutionEval eval;
|
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;
|
moSA<testMove> sa(rand, incrEval, continu, 10.0, cooling, eval);
|
||||||
return EXIT_SUCCESS;
|
|
||||||
|
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>
|
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;
|
tabuList(move_2, solution);
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
move_1(solution);
|
||||||
|
|
||||||
cout << "OK" << endl;
|
tabuList.add(move_2, solution);
|
||||||
return EXIT_SUCCESS;
|
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>
|
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;
|
move(solution_1);
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
tabuList.add(move, solution_2);
|
||||||
|
|
||||||
cout << "OK" << endl;
|
tabuList.add(move, solution_2);
|
||||||
return EXIT_SUCCESS;
|
|
||||||
|
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
|
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;
|
test_result=(((test_1.compare("OK")==0)&&(test_2.compare("OK")==0))?"OK":"KO");
|
||||||
return EXIT_FAILURE;
|
return_value=(((value_1==EXIT_SUCCESS)&&(value_2==EXIT_SUCCESS))?EXIT_SUCCESS:EXIT_FAILURE);
|
||||||
}
|
|
||||||
|
cout << test_result << endl;
|
||||||
cout << "OK" << endl;
|
return return_value;
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -159,11 +159,10 @@ public :
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
cout << "[ moTS ] ==> ";
|
std::string test_result;
|
||||||
|
int return_value;
|
||||||
solution sol;
|
|
||||||
|
|
||||||
sol.fitness(0);
|
solution solution;
|
||||||
|
|
||||||
testMoveInit init;
|
testMoveInit init;
|
||||||
testMoveNext next;
|
testMoveNext next;
|
||||||
|
|
@ -174,17 +173,16 @@ main()
|
||||||
solutionEval eval;
|
solutionEval eval;
|
||||||
|
|
||||||
moTS<testMove> ts(init, next, incrEval, tabuList, aspirCrit, continu, 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;
|
cout << "[ moTS ] ==> ";
|
||||||
return EXIT_SUCCESS;
|
|
||||||
|
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
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
cout << "[ moTSMoveLoopExpl ] ==> ";
|
std::string test_result, test_1, test_2;
|
||||||
|
int return_value, value_1, value_2;
|
||||||
solution sol1 ,sol2;
|
|
||||||
|
|
||||||
sol1.fitness(0);
|
solution solution_1 ,solution_2;
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -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;
|
move(solution);
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
test_result=((solution.fitness()!=2)?"KO":"OK");
|
||||||
|
return_value=((test_result.compare("KO")==0)?EXIT_FAILURE:EXIT_SUCCESS);
|
||||||
cout << "OK" << endl;
|
|
||||||
return EXIT_SUCCESS;
|
cout << test_result << endl;
|
||||||
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue