intermediate commit 2

This commit is contained in:
LPTK 2013-06-24 11:36:07 +02:00
commit bb27a3525a
2 changed files with 52 additions and 26 deletions

View file

@ -38,7 +38,6 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <eval/moEval.h> #include <eval/moEval.h>
#include <eoEvalFunc.h> #include <eoEvalFunc.h>
#include <eoOptional.h> #include <eoOptional.h>
#include <eval/moFullEvalByCopy.h>
/** /**
* Simulated Annealing * Simulated Annealing
@ -68,10 +67,10 @@ public:
moLocalSearch<Neighbor>(explorer, trueCont, _fullEval) moLocalSearch<Neighbor>(explorer, trueCont, _fullEval)
{ }*/ { }*/
moSA(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, double _initT=10, double _alpha=0.9, unsigned _span=100, double _finalT=0.01) moSA(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, double _initT=10, double _alpha=0.9, unsigned _span=100, double _finalT=0.01)
: moLocalSearch<Neighbor>(*(explorer = new moSAexplorer<Neighbor>(_neighborhood, _eval, *defaultSolNeighborComp, *defaultCool)), *(trueCont = new moTrueContinuator<Neighbor>()), _fullEval), : moLocalSearch<Neighbor>(explorer = *(defaultExplorer = new moSAexplorer<Neighbor>(_neighborhood, _eval, *defaultSolNeighborComp, *defaultCool)), *(trueCont = new moTrueContinuator<Neighbor>()), _fullEval),
defaultCool(new moSimpleCoolingSchedule<EOT>(_initT, _alpha, _span, _finalT)), defaultCool(new moSimpleCoolingSchedule<EOT>(_initT, _alpha, _span, _finalT))
default_eval(NULL), // removed in C++11 with unique_ptr //default_eval(NULL), // removed in C++11 with unique_ptr
defaultSolNeighborComp(new moSolNeighborComparator<Neighbor>()) //defaultSolNeighborComp(new moSolNeighborComparator<Neighbor>())
//explorer(_neighborhood, _eval, *defaultSolNeighborComp, *defaultCool) //explorer(_neighborhood, _eval, *defaultSolNeighborComp, *defaultCool)
{ } { }
@ -147,30 +146,32 @@ public:
_cool ) _cool )
{ }*/ { }*/
: moLocalSearch<Neighbor> ( : moLocalSearch<Neighbor> (
*(explorer = new moSAexplorer<Neighbor> ( explorer = *(defaultExplorer = new moSAexplorer<Neighbor> (
_neighborhood, _neighborhood,
_eval.hasValue()? _eval.get(): *(default_eval = new moFullEvalByCopy<Neighbor>(_fullEval)), _eval, //_eval.hasValue()? _eval.get(): *(default_eval = new moFullEvalByCopy<Neighbor>(_fullEval)),
// C++11: _eval.hasValue()? _eval.get(): default_eval = new moFullEvalByCopy<Neighbor>(), // C++11: _eval.hasValue()? _eval.get(): default_eval = new moFullEvalByCopy<Neighbor>(),
_comp.hasValue()? _comp.get(): *(defaultSolNeighborComp = new moSolNeighborComparator<Neighbor>()), _comp, //_comp.hasValue()? _comp.get(): *(defaultSolNeighborComp = new moSolNeighborComparator<Neighbor>()),
_cool )), _cool )),
_cont.hasValue()? _cont.get(): *(trueCont = new moTrueContinuator<Neighbor>()), _fullEval ), _cont.hasValue()? _cont.get(): *(trueCont = new moTrueContinuator<Neighbor>()),
_fullEval ),
defaultCool(NULL), // removed in C++11 with unique_ptr defaultCool(NULL), // removed in C++11 with unique_ptr
default_eval(NULL), // removed in C++11 with unique_ptr //default_eval(NULL), // removed in C++11 with unique_ptr
trueCont(NULL), // removed in C++11 with unique_ptr trueCont(NULL) // removed in C++11 with unique_ptr
defaultSolNeighborComp(NULL) // removed in C++11 with unique_ptr //defaultSolNeighborComp(NULL) // removed in C++11 with unique_ptr
{ } { }
moSA ( moSA (
moSAexplorer<Neighbor>& _explorer, moSAexplorer<Neighbor>& _explorer,
eoOptional< moContinuator<Neighbor> > _cont = NULL, eoOptional< moContinuator<Neighbor> > _cont = NULL
) )
: moLocalSearch<Neighbor> ( : moLocalSearch<Neighbor> (
*(explorer = &_explorer), *(explorer = &_explorer),
_cont.hasValue()? _cont.get(): *(trueCont = new moTrueContinuator<Neighbor>()), _fullEval ), _cont.hasValue()? _cont.get(): *(trueCont = new moTrueContinuator<Neighbor>()), _fullEval ),
defaultExplorer(NULL), // removed in C++11 with unique_ptr
defaultCool(NULL), // removed in C++11 with unique_ptr defaultCool(NULL), // removed in C++11 with unique_ptr
default_eval(NULL), // removed in C++11 with unique_ptr //default_eval(NULL), // removed in C++11 with unique_ptr
trueCont(NULL), // removed in C++11 with unique_ptr trueCont(NULL) // removed in C++11 with unique_ptr
defaultSolNeighborComp(NULL) // removed in C++11 with unique_ptr //defaultSolNeighborComp(NULL) // removed in C++11 with unique_ptr
{ } { }
virtual ~moSA () virtual ~moSA ()
@ -178,21 +179,17 @@ public:
// Note: using unique_ptr would allow us to remove this explicit destructor, but they were only introduced in C++11 // Note: using unique_ptr would allow us to remove this explicit destructor, but they were only introduced in C++11
if (trueCont != NULL) if (trueCont != NULL)
delete trueCont; delete trueCont;
if (defaultSolNeighborComp != NULL) if (explorer != NULL)
delete defaultSolNeighborComp; delete explorer;
if (default_eval != NULL)
delete default_eval;
if (defaultCool != NULL)
delete defaultCool;
delete explorer;
} }
private: private:
moSAexplorer<Neighbor>* explorer; // Not NULL moSAexplorer<Neighbor>* defaultExplorer;
moSAexplorer<Neighbor>& explorer; // Not NULL (ref)
moSimpleCoolingSchedule<EOT>* defaultCool; // C++11: const std::unique_ptr<moSimpleCoolingSchedule<EOT>> moSimpleCoolingSchedule<EOT>* defaultCool; // C++11: const std::unique_ptr<moSimpleCoolingSchedule<EOT>>
moFullEvalByCopy<Neighbor>* default_eval; //moFullEvalByCopy<Neighbor>* default_eval;
moTrueContinuator<Neighbor>* trueCont; moTrueContinuator<Neighbor>* trueCont;
moSolNeighborComparator<Neighbor>* defaultSolNeighborComp; //moSolNeighborComparator<Neighbor>* defaultSolNeighborComp;
}; };
#endif #endif

View file

@ -41,6 +41,8 @@
#include <comparator/moSolNeighborComparator.h> #include <comparator/moSolNeighborComparator.h>
#include <coolingSchedule/moCoolingSchedule.h> #include <coolingSchedule/moCoolingSchedule.h>
#include <neighborhood/moNeighborhood.h> #include <neighborhood/moNeighborhood.h>
#include <eoOptional.h>
#include <eval/moFullEvalByCopy.h>
#include <utils/eoRNG.h> #include <utils/eoRNG.h>
@ -68,6 +70,7 @@ public:
* @param _solNeighborComparator a solution vs neighbor comparator * @param _solNeighborComparator a solution vs neighbor comparator
* @param _coolingSchedule the cooling schedule * @param _coolingSchedule the cooling schedule
*/ */
/*
moSAexplorer ( moSAexplorer (
Neighborhood& _neighborhood, Neighborhood& _neighborhood,
moEval<Neighbor>& _eval, moEval<Neighbor>& _eval,
@ -80,6 +83,24 @@ public:
{ {
isAccept = false; isAccept = false;
if (!neighborhood.isRandom()) {
std::cout << "moSAexplorer::Warning -> the neighborhood used is not random" << std::endl;
}
}*/
moSAexplorer (
Neighborhood& _neighborhood,
moCoolingSchedule<EOT>& _cool,
eoOptional< moEval<Neighbor> > _eval = NULL,
eoOptional< moSolNeighborComparator<Neighbor> > _comp = NULL
)
: moNeighborhoodExplorer<Neighbor>(_neighborhood, _eval.hasValue()? _eval.get(): *(default_eval = new moFullEvalByCopy<Neighbor>(_fullEval))),
default_eval(NULL), // removed in C++11 with unique_ptr
defaultSolNeighborComp(NULL), // removed in C++11 with unique_ptr
solNeighborComparator(_comp.hasValue()? _comp.get(): *(defaultSolNeighborComp = new moSolNeighborComparator<Neighbor>())),
coolingSchedule(_coolingSchedule)
{
isAccept = false;
if (!neighborhood.isRandom()) { if (!neighborhood.isRandom()) {
std::cout << "moSAexplorer::Warning -> the neighborhood used is not random" << std::endl; std::cout << "moSAexplorer::Warning -> the neighborhood used is not random" << std::endl;
} }
@ -89,6 +110,10 @@ public:
* Destructor * Destructor
*/ */
~moSAexplorer() { ~moSAexplorer() {
if (defaultSolNeighborComp != NULL)
delete defaultSolNeighborComp;
if (default_eval != NULL)
delete default_eval;
} }
/** /**
@ -175,6 +200,10 @@ public:
} }
private: private:
moFullEvalByCopy<Neighbor>* default_eval;
moSolNeighborComparator<Neighbor>* defaultSolNeighborComp;
// comparator betwenn solution and neighbor // comparator betwenn solution and neighbor
moSolNeighborComparator<Neighbor>& solNeighborComparator; moSolNeighborComparator<Neighbor>& solNeighborComparator;