From 4f98176c498a53e1c092607b39daf0e91016b432 Mon Sep 17 00:00:00 2001 From: jhumeau Date: Wed, 3 Feb 2010 17:18:23 +0000 Subject: [PATCH] Aspiration Criteria Added git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1680 331e1502-861f-0410-8da2-ba01fb791d7f --- branches/newMo/src/memory/moAspiration.h | 17 +++++++ .../newMo/src/memory/moBestImprAspiration.h | 48 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 branches/newMo/src/memory/moAspiration.h create mode 100644 branches/newMo/src/memory/moBestImprAspiration.h diff --git a/branches/newMo/src/memory/moAspiration.h b/branches/newMo/src/memory/moAspiration.h new file mode 100644 index 000000000..96f529326 --- /dev/null +++ b/branches/newMo/src/memory/moAspiration.h @@ -0,0 +1,17 @@ +#ifndef _moAspiration_h +#define _moAspiration_h + +/** + * Abstract class for Aspiration Criteria + */ +template< class Neighbor > +class moAspiration : public eoBF +{ +public: + typedef typename Neighbor::EOT EOT; + + virtual void init(EOT & _sol) = 0; + virtual void update(EOT & _sol, Neighbor & _neighbor) = 0; +}; + +#endif diff --git a/branches/newMo/src/memory/moBestImprAspiration.h b/branches/newMo/src/memory/moBestImprAspiration.h new file mode 100644 index 000000000..57441e066 --- /dev/null +++ b/branches/newMo/src/memory/moBestImprAspiration.h @@ -0,0 +1,48 @@ +#ifndef _moBestImprAspiration_h +#define _moBestImprAspiration_h + +#include + +/** + * Aspiration criteria accepts a solution better than the best so far + */ +template< class Neighbor > +class moBestImprAspiration : public moAspiration +{ +public: + + typedef typename Neighbor::EOT EOT; + + /** + * init the best solution + * @param _sol the best solution found + */ + void init(EOT & _sol){ + bestFoundSoFar = _sol; + } + + /** + * update the "bestFoundSoFar" if a best solution is found + * @param _sol a solution + * @param _neighbor a neighbor + */ + void update(EOT & _sol, Neighbor & _neighbor){ + if (bestFoundSoFar.fitness() < _sol.fitness()) + bestFoundSoFar = _sol; + } + + /** + * test if a solution is better than the "bestFoundSoFar" + * @param _sol a solution + * @param _neighbor a neighbor + * @return true if _sol is better than the "bestFoundSoFar" + */ + bool operator()(EOT & _sol, Neighbor & _neighbor){ + return (bestFoundSoFar.fitness() < _sol.fitness()); + } + +private: + EOT bestFoundSoFar; +}; + +#endif