eoUpdateUnderConstraint.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // eoUpdateUnderConstraint.h
00005 // (c) OPAC 2007
00006 /*
00007     Contact: paradiseo-help@lists.gforge.inria.fr
00008  */
00009 //-----------------------------------------------------------------------------
00010 
00011 #ifndef _EOUPDATEIUNDERCONSTRAINT_H
00012 #define _EOUPDATEIUNDERCONSTRAINT_H
00013 
00014 //-----------------------------------------------------------------------------
00015 #include <eoParticleBestUpdater.h>
00016 
00017 
00021 template < class POT , class CSTYPE > class eoUpdateUnderConstraint:public eoParticleBestUpdater < POT >
00022 {
00023 
00024 public:
00025 
00029     eoUpdateUnderConstraint(const CSTYPE & _epsilon):epsilon(_epsilon) {}
00030 
00031     void operator  () (POT & _po)
00032     {
00033         if ((_po.fitness () - _po.best ()) >= epsilon)
00034         {
00035             // update positions
00036             for (unsigned i = 0; i < _po.size (); i++){
00037                 _po.bestPositions[i] = _po[i];
00038             }
00039             // invalidate the best fitness, just "semantic" because the best fitness is updated below
00040             _po.invalidateBest();
00041 
00042             // update local best fitness
00043             _po.best (_po.fitness ());
00044         }
00045     }
00046 
00047 protected:
00048      const CSTYPE & epsilon;
00049 
00050 };
00051 
00052 #endif /*_EOUPDATEIUNDERCONSTRAINT_H */

Generated on Thu Apr 19 11:02:28 2007 for EO by  doxygen 1.4.7