#ifndef _eoTenTimeContinue_h #define _eoTenTimeContinue_h #include #include #include #include #include template< class EOT> class eoTenTimeContinue: public eoContinue { public: eoTenTimeContinue(unsigned int _maxTime, unsigned int _cut, std::string _fileName, moeoArchive & _arch) : start(time(0)), maxTime(_maxTime), cut(_cut), id(1), fileName(_fileName), arch(_arch) {} // _pop must be an archive virtual bool operator() (const eoPop & _pop) { unsigned int diff = (unsigned int) difftime(time(0), start); if (diff >= (id * maxTime/cut) ) { time_t begin=time(0); save(_pop); id++; start= start - (time(0)-begin); operator()(_pop); } if (diff >= maxTime) { return false; } return true; } virtual std::string className(void) const { return "eoTenTimeContinue"; } void readFrom (std :: istream & __is) { __is >> start; } void printOn (std :: ostream & __os) const { __os << start << ' ' << std :: endl; } private: time_t start; unsigned int maxTime; unsigned int id; unsigned int cut; std::string fileName; moeoArchive & arch; void save(const eoPop & _pop) { // update the archive arch(_pop); // save the archive contents in a file std::string tmp = fileName; std::ostringstream os; os << id; tmp += '.'; tmp += os.str(); std::ofstream outfile(tmp.c_str()); // std::cout << "save " << tmp << " - " << difftime(time(0), start) << std::endl; unsigned int nObj = EOT::ObjectiveVector::nObjectives(); for (unsigned int i=0; i