moHC and moTS have been updated to avoid memory leaks... must be tested under windows
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1101 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
f3ed7eac89
commit
59027b4e24
2 changed files with 34 additions and 10 deletions
|
|
@ -68,8 +68,8 @@ class moHC:public moAlgo < typename M::EOType >
|
|||
*/
|
||||
moHC (moMoveInit < M > & _move_initializer, moNextMove < M > & _next_move_generator,
|
||||
moMoveIncrEval < M > & _incremental_evaluation, moMoveSelect < M > & _move_selection, eoEvalFunc < EOT > & _full_evaluation) :
|
||||
move_explorer ( *new moHCMoveLoopExpl < M > (_move_initializer, _next_move_generator, _incremental_evaluation, _move_selection) ),
|
||||
full_evaluation (_full_evaluation)
|
||||
move_explorer(new moHCMoveLoopExpl<M>(_move_initializer, _next_move_generator, _incremental_evaluation, _move_selection)),
|
||||
full_evaluation (_full_evaluation), move_explorer_memory_allocation(true)
|
||||
{}
|
||||
|
||||
//! Light constructor.
|
||||
|
|
@ -80,9 +80,18 @@ 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 (_move_explorer), full_evaluation (_full_evaluation), move_explorer_memory_allocation(false)
|
||||
{}
|
||||
|
||||
//! Destructor
|
||||
~moHC()
|
||||
{
|
||||
if(move_explorer_memory_allocation)
|
||||
{
|
||||
delete(move_explorer);
|
||||
}
|
||||
}
|
||||
|
||||
//! Function which launches the HC
|
||||
/*!
|
||||
The HC has to improve a current solution.
|
||||
|
|
@ -105,7 +114,7 @@ class moHC:public moAlgo < typename M::EOType >
|
|||
do
|
||||
{
|
||||
_solution=new_solution;
|
||||
move_explorer (_solution, new_solution);
|
||||
(*move_explorer) (_solution, new_solution);
|
||||
}
|
||||
while ( new_solution.fitness() > _solution.fitness() );
|
||||
|
||||
|
|
@ -115,10 +124,13 @@ class moHC:public moAlgo < typename M::EOType >
|
|||
private:
|
||||
|
||||
//! Complete exploration of the neighborhood.
|
||||
moMoveExpl < M > & move_explorer;
|
||||
moMoveExpl < M > * move_explorer;
|
||||
|
||||
//! A full evaluation function.
|
||||
eoEvalFunc < EOT > & full_evaluation;
|
||||
|
||||
//! Indicate if the memory has been allocated for the move_explorer.
|
||||
bool move_explorer_memory_allocation;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -73,9 +73,9 @@ class moTS:public moAlgo < typename M::EOType >
|
|||
moMoveIncrEval < M > & _incremental_evaluation, moTabuList < M > & _tabu_list,
|
||||
moAspirCrit < M > & _aspiration_criterion, moSolContinue < EOT > & _continue,
|
||||
eoEvalFunc < EOT > & _full_evaluation):
|
||||
move_explorer ( *new moTSMoveLoopExpl < M >(_move_initializer, _next_move_generator, _incremental_evaluation,
|
||||
move_explorer (new moTSMoveLoopExpl < M >(_move_initializer, _next_move_generator, _incremental_evaluation,
|
||||
_tabu_list,_aspiration_criterion) ),
|
||||
continu (_continue), full_evaluation (_full_evaluation)
|
||||
continu (_continue), full_evaluation (_full_evaluation), move_explorer_memory_allocation(true)
|
||||
{}
|
||||
|
||||
//! Constructor with less parameters
|
||||
|
|
@ -87,8 +87,17 @@ 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 (_move_explorer), continu (_continue), full_evaluation (_full_evaluation), move_explorer_memory_allocation(false)
|
||||
{}
|
||||
|
||||
//! Destructor
|
||||
~moTS()
|
||||
{
|
||||
if(move_explorer_memory_allocation)
|
||||
{
|
||||
delete(move_explorer);
|
||||
}
|
||||
}
|
||||
|
||||
//! Function which launchs the Tabu Search
|
||||
/*!
|
||||
|
|
@ -119,7 +128,7 @@ class moTS:public moAlgo < typename M::EOType >
|
|||
|
||||
do
|
||||
{
|
||||
move_explorer (_solution, new_solution);
|
||||
(*move_explorer) (_solution, new_solution);
|
||||
|
||||
// Updating the best solution found until now ?
|
||||
if (new_solution.fitness() > _solution.fitness())
|
||||
|
|
@ -139,13 +148,16 @@ class moTS:public moAlgo < typename M::EOType >
|
|||
private:
|
||||
|
||||
//! Neighborhood explorer
|
||||
moMoveExpl < M > & move_explorer;
|
||||
moMoveExpl < M > * move_explorer;
|
||||
|
||||
//! Stop criterion
|
||||
moSolContinue < EOT > & continu;
|
||||
|
||||
//! Full evaluation function
|
||||
eoEvalFunc < EOT > & full_evaluation;
|
||||
|
||||
//! Indicate if the memory has been allocated for the move_explorer.
|
||||
bool move_explorer_memory_allocation;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue