00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- 00002 00003 //----------------------------------------------------------------------------- 00004 // eoCheckPoint.h 00005 // (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2000 00006 /* 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 Contact: todos@geneura.ugr.es, http://geneura.ugr.es 00022 Marc.Schoenauer@polytechnique.fr 00023 mkeijzer@dhi.dk 00024 */ 00025 //----------------------------------------------------------------------------- 00026 00027 #ifndef _eoCheckPoint_h 00028 #define _eoCheckPoint_h 00029 00030 #include <eoContinue.h> 00031 #include <utils/eoUpdater.h> 00032 #include <utils/eoMonitor.h> 00033 #include <utils/eoStat.h> 00034 00045 template <class EOT> 00046 class eoCheckPoint : public eoContinue<EOT> 00047 { 00048 public : 00049 00050 eoCheckPoint(eoContinue<EOT>& _cont) 00051 { 00052 continuators.push_back(&_cont); 00053 } 00054 00055 bool operator()(const eoPop<EOT>& _pop); 00056 00057 void add(eoContinue<EOT>& _cont) { continuators.push_back(&_cont); } 00058 void add(eoSortedStatBase<EOT>& _stat) { sorted.push_back(&_stat); } 00059 void add(eoStatBase<EOT>& _stat) { stats.push_back(&_stat); } 00060 void add(eoMonitor& _mon) { monitors.push_back(&_mon); } 00061 void add(eoUpdater& _upd) { updaters.push_back(&_upd); } 00062 00063 virtual std::string className(void) const { return "eoCheckPoint"; } 00064 std::string allClassNames() const ; 00065 00066 private : 00067 00068 std::vector<eoContinue<EOT>*> continuators; 00069 std::vector<eoSortedStatBase<EOT>*> sorted; 00070 std::vector<eoStatBase<EOT>*> stats; 00071 std::vector<eoMonitor*> monitors; 00072 std::vector<eoUpdater*> updaters; 00073 }; 00074 00075 template <class EOT> 00076 bool eoCheckPoint<EOT>::operator()(const eoPop<EOT>& _pop) 00077 { 00078 unsigned i; 00079 00080 std::vector<const EOT*> sorted_pop; 00081 if (!sorted.empty()) 00082 { 00083 _pop.sort(sorted_pop); 00084 00085 for (i = 0; i < sorted.size(); ++i) 00086 { 00087 (*sorted[i])(sorted_pop); 00088 } 00089 } 00090 00091 for (i = 0; i < stats.size(); ++i) 00092 (*stats[i])(_pop); 00093 00094 for (i = 0; i < updaters.size(); ++i) 00095 (*updaters[i])(); 00096 00097 for (i = 0; i < monitors.size(); ++i) 00098 (*monitors[i])(); 00099 00100 bool bContinue = true; 00101 for (i = 0; i < continuators.size(); ++i) 00102 if ( !(*continuators[i])(_pop) ) 00103 bContinue = false; 00104 00105 if (! bContinue) // we're going to stop: lastCall, gentlemen 00106 { 00107 if (!sorted.empty()) 00108 { 00109 for (i = 0; i < sorted.size(); ++i) 00110 { 00111 sorted[i]->lastCall(sorted_pop); 00112 } 00113 } 00114 for (i = 0; i < stats.size(); ++i) 00115 stats[i]->lastCall(_pop); 00116 00117 for (i = 0; i < updaters.size(); ++i) 00118 updaters[i]->lastCall(); 00119 00120 for (i = 0; i < monitors.size(); ++i) 00121 monitors[i]->lastCall(); 00122 } 00123 return bContinue; 00124 } 00125 00129 template <class EOT> 00130 std::string eoCheckPoint<EOT>::allClassNames() const 00131 { 00132 unsigned i; 00133 std::string s = "\n" + className() + "\n"; 00134 00135 s += "Sorted Stats\n"; 00136 for (i = 0; i < sorted.size(); ++i) 00137 s += sorted[i]->className() + "\n"; 00138 s += "\n"; 00139 00140 s += "Stats\n"; 00141 for (i = 0; i < stats.size(); ++i) 00142 s += stats[i]->className() + "\n"; 00143 s += "\n"; 00144 00145 s += "Updaters\n"; 00146 for (i = 0; i < updaters.size(); ++i) 00147 s += updaters[i]->className() + "\n"; 00148 s += "\n"; 00149 00150 s += "Monitors\n"; 00151 for (i = 0; i < monitors.size(); ++i) 00152 s += monitors[i]->className() + "\n"; 00153 s += "\n"; 00154 00155 s += "Continuators\n"; 00156 for (i = 0; i < continuators.size(); ++i) 00157 s += continuators[i]->className() + "\n"; 00158 s += "\n"; 00159 00160 return s; 00161 } 00162 00163 #endif
1.4.7