Hello Maarten,
is it possible to stop the genetic algorithm after a specified time if the algorithm didn't found the optimum yet or didn't do the minimum generation?
I'm using your lib in a research project for adaptive online traffic control in urban road networks. The problem is, that I try to optimize the signal plans of traffic lights, but I don't have much time for it (approximately 3 to 4 minutes). It would be useful, if there is an other stopping criteria like "time spent for optimization".
Regards
Carsten
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
#include <eoContinue.h>
/**
Timed continuator: continues until a number of seconds is used
*/
template< class EOT>
class eoSecondsElapsedContinue: public eoContinue<EOT>
{
time_t start;
int seconds;
public:
Hello Maarten,
okay, I found out by myself how to use this feature in the parameter-file.
I added the following code to make_continue.h
// the seconds elapsed
eoSecondsElapsedContinue<Indi> *secondsCont;
eoValueParam<int> &secondsElapsedParam = _parser.createParam(int 300),"secondsElapsed","Stop when seconds elapsed",'\0',"Stopping criterion");
if (_parser.isItThere(secondsElapsedParam))
{
secondsCont = new eoSecondsElapsedContinue<Indi>(secondsElapsedParam.value());
// store
_state.storeFunctor(secondsCont);
// add to combinedContinue
continuator = make_combinedContinue<Indi>(continuator,secondsCont);
}
Thank you again for your support
Carsten
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello Maarten,
is it possible to stop the genetic algorithm after a specified time if the algorithm didn't found the optimum yet or didn't do the minimum generation?
I'm using your lib in a research project for adaptive online traffic control in urban road networks. The problem is, that I try to optimize the signal plans of traffic lights, but I don't have much time for it (approximately 3 to 4 minutes). It would be useful, if there is an other stopping criteria like "time spent for optimization".
Regards
Carsten
No, I doesn't seem to be present in EO (yet). It needs to be added.
It shouldn't be too difficult to add it yourself: subclass eoContinue, implement
bool operator()(const eoPop<EOT>&)
and return false when the alloted number of seconds has elapsed.
okay, added it into cvs as an 'eoSecondsElapsedContinue.h'
If you don't want to go to cvs, copy and paste the below
============================================
#ifndef _eoSecondsElapsedContinue_h
#define _eoSecondsElapsedContinue_h
#include <eoContinue.h>
/**
Timed continuator: continues until a number of seconds is used
*/
template< class EOT>
class eoSecondsElapsedContinue: public eoContinue<EOT>
{
time_t start;
int seconds;
public:
eoSecondsElapsedContinue(int nSeconds) : start(time(0)), seconds(nSeconds) {}
virtual bool operator() ( const eoPop<EOT>& _vEO ) {
time_t now = time(0);
time_t diff = now - start;
if (diff >= seconds) return false; // stop
return true;
}
virtual std::string className(void) const { return "eoSecondsElapsedContinue"; }
void readFrom (std :: istream & __is) {
__is >> start >> seconds; /* Loading the number of generations counted */
}
void printOn (std :: ostream & __os) const {
__os << start << ' ' << seconds << std :: endl; /* Saving the number of generations counted */
}
};
#endif
Wow, this was very fast.
Thank you very much!
... but how do I use this new feature in the parameter file?
Thanks,
Carsten
Hello Maarten,
okay, I found out by myself how to use this feature in the parameter-file.
I added the following code to make_continue.h
// the seconds elapsed
eoSecondsElapsedContinue<Indi> *secondsCont;
eoValueParam<int> &secondsElapsedParam = _parser.createParam(int 300),"secondsElapsed","Stop when seconds elapsed",'\0',"Stopping criterion");
if (_parser.isItThere(secondsElapsedParam))
{
secondsCont = new eoSecondsElapsedContinue<Indi>(secondsElapsedParam.value());
// store
_state.storeFunctor(secondsCont);
// add to combinedContinue
continuator = make_combinedContinue<Indi>(continuator,secondsCont);
}
Thank you again for your support
Carsten