- Main Page
- Classes
- Files

- Search for |

# moRandImprSelect.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 // "moRandImprSelect.h"
    00004
    00005 // (c) OPAC Team, LIFL, 2003-2006
    00006
    00007 /* LICENCE TEXT
    00008
    00009    Contact: paradiseo-help@lists.gforge.inria.fr
    00010 */
    00011
    00012 #ifndef __moRandImprSelect_h
    00013 #define __moRandImprSelect_h
    00014
    00015 #include <vector>
    00016
    00017 #include <utils/eoRNG.h>
    00018 #include "moMoveSelect.h"
    00019
    00021
    00025 template < class M > class moRandImprSelect:public moMoveSelect < M >
    00026 {
    00027
    00028 public:
    00029
    00031   typedef typename M::EOType::Fitness Fitness;
    00032
    00034
    00040   void init (const Fitness & __fit)
    00041   {
    00042     init_fit = __fit;
    00043     vect_better_fit.clear ();
    00044     vect_better_moves.clear ();
    00045   }
    00046
    00048
    00056   bool update (const M & __move, const Fitness & __fit)
    00057   {
    00058
    00059     if (__fit > init_fit)
    00060       {
    00061
    00062         vect_better_fit.push_back (__fit);
    00063         vect_better_moves.push_back (__move);
    00064       }
    00065
    00066     return true;
    00067   }
    00068
    00070
    00077   void operator   () (M & __move, Fitness & __fit) throw (EmptySelection)
    00078   {
    00079
    00080     if (!vect_better_fit.empty ())
    00081       {
    00082
    00083         unsigned n = rng.random (vect_better_fit.size ());
    00084
    00085         __move = vect_better_moves[n];
    00086         __fit = vect_better_fit[n];
    00087       }
    00088     else
    00089       throw EmptySelection ();
    00090   }
    00091
    00092 private:
    00093
    00095   Fitness init_fit;
    00096
    00098   std::vector < Fitness > vect_better_fit;
    00099
    00101   std::vector < M > vect_better_moves;
    00102 };
    00103
    00104 #endif