- Main Page
- Classes
- Files

- Search for |

# moNoFitImprSolContinue.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 // "moNoFitImprSolContinue.h"
    00004
    00005 // (c) OPAC Team (LIFL), Dolphin project (INRIA), 2003-2007
    00006
    00007 /* LICENCE TEXT
    00008
    00009    Contact: paradiseo-help@lists.gforge.inria.fr
    00010 */
    00011
    00012 #ifndef __moNoFitImprSolContinue_h
    00013 #define __moNoFitImprSolContinue_h
    00014
    00015 #include "moSolContinue.h"
    00016
    00018
    00021 template < class EOT > class moNoFitImprSolContinue:public moSolContinue < EOT >
    00022 {
    00023
    00024 public:
    00025
    00027   typedef typename EOT::Fitness Fitness;
    00028
    00030
    00033   moNoFitImprSolContinue (unsigned int __maxNumberOfIterationWithoutImprovement)
    00034     : maxNumberOfIterationsWithoutImprovement(__maxNumberOfIterationWithoutImprovement), firstFitnessSaved(true), counter(0)
    00035   {}
    00036
    00038
    00043   bool operator   () (const EOT & __sol)
    00044   {
    00045     if(__sol.invalid())
    00046       {
    00047         return true;
    00048       }
    00049
    00050     if(firstFitnessSaved)
    00051       {
    00052         fitness=__sol.fitness();
    00053         counter=0;
    00054         firstFitnessSaved=false;
    00055         return true;
    00056       }
    00057
    00058     counter++;
    00059
    00060     if( __sol.fitness() > fitness)
    00061       {
    00062         fitness=__sol.fitness();
    00063         counter=0;
    00064       }
    00065
    00066     if(counter==maxNumberOfIterationsWithoutImprovement)
    00067       {
    00068         std::cout << "moNoFitImrpSolContinue: Done [" << counter  << "] iterations without improvement." << std::endl;
    00069       }
    00070     return counter!=maxNumberOfIterationsWithoutImprovement;
    00071   }
    00072
    00074
    00077   void init ()
    00078   {
    00079     firstFitnessSaved=true;
    00080     counter=0;
    00081   }
    00082
    00083 private:
    00084
    00086   unsigned int maxNumberOfIterationsWithoutImprovement;
    00087
    00089   bool firstFitnessSaved;
    00090
    00092   Fitness fitness;
    00093
    00095   unsigned int counter;
    00096 };
    00097
    00098 #endif