New test for each constructor of moHS, moTS, moILS. No memory leaks under Windows. No compilation errors or warning under Unix and Windows XP (visual studio 2005)
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1102 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
59027b4e24
commit
094c812050
7 changed files with 51 additions and 93 deletions
|
|
@ -80,7 +80,7 @@ class moHC:public moAlgo < typename M::EOType >
|
|||
\param _full_evaluation a full evaluation function.
|
||||
*/
|
||||
moHC (moMoveExpl < M > & _move_explorer, eoEvalFunc < EOT > & _full_evaluation):
|
||||
move_explorer (_move_explorer), full_evaluation (_full_evaluation), move_explorer_memory_allocation(false)
|
||||
move_explorer (&_move_explorer), full_evaluation (_full_evaluation), move_explorer_memory_allocation(false)
|
||||
{}
|
||||
|
||||
//! Destructor
|
||||
|
|
|
|||
|
|
@ -69,8 +69,8 @@ class moILS:public moAlgo < typename M::EOType >
|
|||
*/
|
||||
moILS (moAlgo<EOT> & _algorithm, moSolContinue <EOT> & _continue, moComparator<EOT> & _acceptance_criterion,
|
||||
eoMonOp<EOT> & _perturbation, eoEvalFunc<EOT> & _full_evaluation):
|
||||
algorithm(_algorithm), continu(_continue), acceptance_criterion(_acceptance_criterion),
|
||||
perturbation(_perturbation), full_evaluation(_full_evaluation)
|
||||
algorithm(& _algorithm), continu(_continue), acceptance_criterion(_acceptance_criterion),
|
||||
perturbation(_perturbation), full_evaluation(_full_evaluation), algorithm_memory_allocation(false)
|
||||
{}
|
||||
|
||||
//! Constructor for using a moHC for the moAlgo
|
||||
|
|
@ -88,8 +88,9 @@ class moILS:public moAlgo < typename M::EOType >
|
|||
moMoveIncrEval < M > & _incremental_evaluation, moMoveSelect < M > & _move_selection,
|
||||
moSolContinue <EOT> & _continue, moComparator<EOT> & _acceptance_criterion,
|
||||
eoMonOp<EOT> & _perturbation, eoEvalFunc<EOT> & _full_evaluation):
|
||||
algorithm( *new moHC<M>(_move_initializer, _next_move_generator, _incremental_evaluation, _move_selection, _full_evaluation) ),
|
||||
continu(_continue), acceptance_criterion(_acceptance_criterion), perturbation(_perturbation), full_evaluation(_full_evaluation)
|
||||
algorithm(new moHC<M>(_move_initializer, _next_move_generator, _incremental_evaluation, _move_selection, _full_evaluation) ),
|
||||
continu(_continue), acceptance_criterion(_acceptance_criterion), perturbation(_perturbation), full_evaluation(_full_evaluation),
|
||||
algorithm_memory_allocation(true)
|
||||
{}
|
||||
|
||||
//! Constructor for using a moTS for the moAlgo
|
||||
|
|
@ -110,9 +111,10 @@ class moILS:public moAlgo < typename M::EOType >
|
|||
moAspirCrit <M> & _aspiration_criterion, moSolContinue <EOT> & _moTS_continue,
|
||||
moSolContinue <EOT> & _continue, moComparator<EOT> & _acceptance_criterion, eoMonOp<EOT> & _perturbation,
|
||||
eoEvalFunc<EOT> & _full_evaluation):
|
||||
algorithm( *new moTS<M>(_move_initializer, _next_move_generator, _incremental_evaluation, _tabu_list, _aspiration_criterion,
|
||||
algorithm(new moTS<M>(_move_initializer, _next_move_generator, _incremental_evaluation, _tabu_list, _aspiration_criterion,
|
||||
_moTS_continue, _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)
|
||||
{}
|
||||
|
||||
//! Constructor for using a moSA for the moAlgo
|
||||
|
|
@ -130,11 +132,21 @@ class moILS:public moAlgo < typename M::EOType >
|
|||
moILS (moRandMove<M> & _random_move_generator, moMoveIncrEval <M> & _incremental_evaluation, moSolContinue <EOT> & _moSA_continue,
|
||||
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,
|
||||
algorithm(new moSA<M>(_random_move_generator, _incremental_evaluation, _moSA_continue, _initial_temperature,
|
||||
_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)
|
||||
{}
|
||||
|
||||
//! Destructor
|
||||
~moILS()
|
||||
{
|
||||
if(algorithm_memory_allocation)
|
||||
{
|
||||
delete(algorithm);
|
||||
}
|
||||
}
|
||||
|
||||
//! Function which launches the ILS
|
||||
/*!
|
||||
The ILS has to improve a current solution.
|
||||
|
|
@ -152,7 +164,7 @@ class moILS:public moAlgo < typename M::EOType >
|
|||
// some code has been duplicated in order to avoid one perturbation and one evaluation without adding a test in the loop.
|
||||
// better than a do {} while; with a test in the loop.
|
||||
|
||||
algorithm(_solution);
|
||||
(*algorithm)(_solution);
|
||||
|
||||
if ( acceptance_criterion(_solution, _solution_saved) )
|
||||
{
|
||||
|
|
@ -169,7 +181,7 @@ class moILS:public moAlgo < typename M::EOType >
|
|||
perturbation(_solution);
|
||||
full_evaluation(_solution);
|
||||
|
||||
algorithm(_solution);
|
||||
(*algorithm)(_solution);
|
||||
|
||||
if ( acceptance_criterion(_solution, _solution_saved) )
|
||||
{
|
||||
|
|
@ -187,7 +199,7 @@ class moILS:public moAlgo < typename M::EOType >
|
|||
private:
|
||||
|
||||
//! The solution based heuristic.
|
||||
moAlgo<EOT> & algorithm;
|
||||
moAlgo<EOT> * algorithm;
|
||||
|
||||
//! The stopping criterion.
|
||||
moSolContinue<EOT> & continu;
|
||||
|
|
@ -200,6 +212,9 @@ class moILS:public moAlgo < typename M::EOType >
|
|||
|
||||
//! The full evaluation function
|
||||
eoEvalFunc<EOT> & full_evaluation;
|
||||
|
||||
//! Indicate if the memory has been allocated for the algorithm.
|
||||
bool algorithm_memory_allocation;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ class moTS:public moAlgo < typename M::EOType >
|
|||
\param _full_evaluation A full evaluation function.
|
||||
*/
|
||||
moTS (moMoveExpl < M > & _move_explorer, moSolContinue < EOT > & _continue, eoEvalFunc < EOT > & _full_evaluation):
|
||||
move_explorer (_move_explorer), continu (_continue), full_evaluation (_full_evaluation), move_explorer_memory_allocation(false)
|
||||
move_explorer (&_move_explorer), continu (_continue), full_evaluation (_full_evaluation), move_explorer_memory_allocation(false)
|
||||
{}
|
||||
|
||||
//! Destructor
|
||||
|
|
|
|||
|
|
@ -37,8 +37,12 @@ SET (TEST_LIST t-moBestImprSelect
|
|||
t-moFitSolContinue
|
||||
t-moGenSolContinue
|
||||
t-moHC
|
||||
t-moHC_2
|
||||
t-moHCMoveLoopExpl
|
||||
t-moILS
|
||||
t-moILS
|
||||
t-moILS_HC
|
||||
t-moILS_TS
|
||||
t-moILS_SA
|
||||
t-moImprBestFitAspirCrit
|
||||
t-moItRandNextMove
|
||||
t-moLinearCoolingSchedule
|
||||
|
|
@ -51,6 +55,7 @@ SET (TEST_LIST t-moBestImprSelect
|
|||
t-moSimpleSolutionTabuList
|
||||
t-moSteadyFitSolContinue
|
||||
t-moTS
|
||||
t-moTS_2
|
||||
t-moTSMoveLoopExpl )
|
||||
|
||||
FOREACH (test ${TEST_LIST})
|
||||
|
|
|
|||
|
|
@ -139,8 +139,6 @@ main()
|
|||
|
||||
solution sol;
|
||||
|
||||
sol.fitness(0);
|
||||
|
||||
testMoveInit init;
|
||||
testMoveNext next;
|
||||
testMoveIncrEval incrEval;
|
||||
|
|
|
|||
|
|
@ -56,76 +56,13 @@ public :
|
|||
}
|
||||
} ;
|
||||
|
||||
class testMoveInit : public moMoveInit <testMove>
|
||||
class solutionAlgo : public moAlgo <solution>
|
||||
{
|
||||
public :
|
||||
void operator () (testMove & _move, const solution & _solution)
|
||||
{
|
||||
testMove move=_move;
|
||||
const solution sol(_solution);
|
||||
}
|
||||
} ;
|
||||
|
||||
class testMoveNext : public moNextMove <testMove>
|
||||
{
|
||||
public :
|
||||
bool operator () (testMove & _move, const solution & _solution)
|
||||
{
|
||||
testMove move=_move;
|
||||
const solution sol(_solution);
|
||||
|
||||
return false;
|
||||
}
|
||||
} ;
|
||||
|
||||
class testMoveIncrEval : public moMoveIncrEval <testMove>
|
||||
{
|
||||
public :
|
||||
unsigned int operator () (const testMove & _move, const solution & _solution)
|
||||
{
|
||||
const testMove move(_move);
|
||||
const solution solution(_solution);
|
||||
|
||||
return 2;
|
||||
}
|
||||
} ;
|
||||
|
||||
class testMoveSelect : public moMoveSelect <testMove>
|
||||
{
|
||||
public :
|
||||
void operator () (testMove & _move, unsigned int & _fitness)
|
||||
{
|
||||
testMove move;
|
||||
|
||||
move=_move;
|
||||
|
||||
_fitness=2;
|
||||
}
|
||||
|
||||
void init(const unsigned int & _fitness)
|
||||
{
|
||||
unsigned int fitness;
|
||||
fitness=(unsigned int)_fitness;
|
||||
}
|
||||
|
||||
bool update(const testMove & _move, const unsigned int & _fitness)
|
||||
{
|
||||
testMove move;
|
||||
unsigned int fitness;
|
||||
|
||||
move=(testMove)_move;
|
||||
fitness=(unsigned int)_fitness;
|
||||
|
||||
return true;
|
||||
}
|
||||
} ;
|
||||
|
||||
class solutionEval : public eoEvalFunc <solution>
|
||||
{
|
||||
public :
|
||||
void operator () (solution & _solution)
|
||||
bool operator () (solution & _solution)
|
||||
{
|
||||
_solution.fitness(2);
|
||||
return true;
|
||||
}
|
||||
} ;
|
||||
|
||||
|
|
@ -166,6 +103,15 @@ public :
|
|||
}
|
||||
} ;
|
||||
|
||||
class solutionEval : public eoEvalFunc <solution>
|
||||
{
|
||||
public :
|
||||
void operator () (solution & _solution)
|
||||
{
|
||||
_solution.fitness(0);
|
||||
}
|
||||
} ;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
int
|
||||
|
|
@ -177,19 +123,13 @@ main()
|
|||
|
||||
sol.fitness(0);
|
||||
|
||||
testMoveInit init;
|
||||
testMoveNext next;
|
||||
testMoveIncrEval incrEval;
|
||||
testMoveSelect select;
|
||||
solutionEval eval;
|
||||
|
||||
moHC<testMove> hc(init, next, incrEval, select, eval);
|
||||
|
||||
solutionAlgo algorithm;
|
||||
solutionContinue continu;
|
||||
solutionComparator comparator;
|
||||
solutionPerturbation perturbation;
|
||||
solutionEval eval;
|
||||
|
||||
moILS<testMove> ils(hc, continu, comparator, perturbation, eval);
|
||||
moILS<testMove> ils(algorithm, continu, comparator, perturbation, eval);
|
||||
|
||||
ils(sol);
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ using std::endl;
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
typedef EO<unsigned int> solution;
|
||||
typedef EO<int> solution;
|
||||
|
||||
class testMove : public moMove <solution>
|
||||
{
|
||||
|
|
@ -68,7 +68,7 @@ public :
|
|||
class testMoveIncrEval : public moMoveIncrEval <testMove>
|
||||
{
|
||||
public :
|
||||
unsigned int operator () (const testMove & _move, const solution & _solution)
|
||||
int operator () (const testMove & _move, const solution & _solution)
|
||||
{
|
||||
const testMove move(_move);
|
||||
const solution solution(_solution);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue