edoCheckPoint.h
00001 /*
00002 The Evolving Distribution Objects framework (EDO) is a template-based,
00003 ANSI-C++ evolutionary computation library which helps you to write your
00004 own estimation of distribution algorithms.
00005 
00006 This library is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU Lesser General Public
00008 License as published by the Free Software Foundation; either
00009 version 2.1 of the License, or (at your option) any later version.
00010 
00011 This library is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public
00017 License along with this library; if not, write to the Free Software
00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019 
00020 Copyright (C) 2010 Thales group
00021 */
00022 /*
00023 Authors:
00024     Johann Dréo <johann.dreo@thalesgroup.com>
00025     Caner Candan <caner.candan@thalesgroup.com>
00026 */
00027 
00028 #ifndef _edoCheckPoint_h
00029 #define _edoCheckPoint_h
00030 
00031 #include <utils/eoUpdater.h>
00032 #include <utils/eoMonitor.h>
00033 
00034 #include "edoContinue.h"
00035 #include "edoStat.h"
00036 
00038 
00039 template < typename D >
00040 class edoCheckPoint : public edoContinue< D >
00041 {
00042 public:
00043     typedef typename D::EOType EOType;
00044 
00045     edoCheckPoint(edoContinue< D >& _cont)
00046     {
00047         _continuators.push_back( &_cont );
00048     }
00049 
00050     bool operator()(const D& distrib)
00051     {
00052         for ( unsigned int i = 0, size = _stats.size(); i < size; ++i )
00053             {
00054                 (*_stats[i])( distrib );
00055             }
00056 
00057         for ( unsigned int i = 0, size = _updaters.size(); i < size; ++i )
00058             {
00059                 (*_updaters[i])();
00060             }
00061 
00062         for ( unsigned int i = 0, size = _monitors.size(); i < size; ++i )
00063             {
00064                 (*_monitors[i])();
00065             }
00066 
00067         bool bContinue = true;
00068         for ( unsigned int i = 0, size = _continuators.size(); i < size; ++i )
00069             {
00070                 if ( !(*_continuators[i])( distrib ) )
00071                     {
00072                         bContinue = false;
00073                     }
00074             }
00075 
00076         if ( !bContinue )
00077             {
00078                 for ( unsigned int i = 0, size = _stats.size(); i < size; ++i )
00079                     {
00080                         _stats[i]->lastCall( distrib );
00081                     }
00082 
00083                 for ( unsigned int i = 0, size = _updaters.size(); i < size; ++i )
00084                     {
00085                         _updaters[i]->lastCall();
00086                     }
00087 
00088                 for ( unsigned int i = 0, size = _monitors.size(); i < size; ++i )
00089                     {
00090                         _monitors[i]->lastCall();
00091                     }
00092             }
00093 
00094         return bContinue;
00095     }
00096 
00097     void add(edoContinue< D >& cont) { _continuators.push_back( &cont ); }
00098     void add(edoStatBase< D >& stat) { _stats.push_back( &stat ); }
00099     void add(eoMonitor& mon) { _monitors.push_back( &mon ); }
00100     void add(eoUpdater& upd) { _updaters.push_back( &upd ); }
00101 
00102     virtual std::string className(void) const { return "edoCheckPoint"; }
00103 
00104     std::string allClassNames() const
00105     {
00106         std::string s("\n" + className() + "\n");
00107 
00108         s += "Stats\n";
00109         for ( unsigned int i = 0, size = _stats.size(); i < size; ++i )
00110             {
00111                 s += _stats[i]->className() + "\n";
00112             }
00113         s += "\n";
00114 
00115         s += "Updaters\n";
00116         for ( unsigned int i = 0; i < _updaters.size(); ++i )
00117             {
00118                 s += _updaters[i]->className() + "\n";
00119             }
00120         s += "\n";
00121 
00122         s += "Monitors\n";
00123         for ( unsigned int i = 0; i < _monitors.size(); ++i )
00124             {
00125                 s += _monitors[i]->className() + "\n";
00126             }
00127         s += "\n";
00128 
00129         s += "Continuators\n";
00130         for ( unsigned int i = 0, size = _continuators.size(); i < size; ++i )
00131             {
00132                 s += _continuators[i]->className() + "\n";
00133             }
00134         s += "\n";
00135 
00136         return s;
00137     }
00138 
00139 private:
00140     std::vector< edoContinue< D >* > _continuators;
00141     std::vector< edoStatBase< D >* > _stats;
00142     std::vector< eoMonitor* > _monitors;
00143     std::vector< eoUpdater* > _updaters;
00144 };
00145 
00146 #endif // !_edoCheckPoint_h
 All Classes Functions Variables Typedefs