Menu

New Stopping Criteria

2007-07-17
2013-06-04
  • carsten kemper

    carsten kemper - 2007-07-17

    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

     
    • Maarten Keijzer

      Maarten Keijzer - 2007-07-17

      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.

       
    • Maarten Keijzer

      Maarten Keijzer - 2007-07-17

      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

       
    • carsten kemper

      carsten kemper - 2007-07-17

      Wow, this was very fast.
      Thank you very much!
      ... but how do I use this new feature in the parameter file?

      Thanks,
      Carsten

       
    • carsten kemper

      carsten kemper - 2007-07-19

      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

       

Log in to post a comment.