- Main Page
- Namespaces
- Classes
- Files

- Search for |

# moSteadyFitSolContinue.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 // "moSteadyFitSolContinue.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 __moSteadyFitSolContinue_h
    00013 #define __moSteadyFitSolContinue_h
    00014
    00015 #include "moSolContinue.h"
    00016
    00018
    00021 template < class EOT > class moSteadyFitSolContinue:public moSolContinue < EOT >
    00022 {
    00023
    00024 public:
    00025
    00027   typedef typename EOT::Fitness Fitness;
    00028
    00030
    00034   moSteadyFitSolContinue (unsigned int __maxNumberOfIterations, unsigned int __maxNumberOfIterationWithoutImprovement)
    00035     : maxNumberOfIterations (__maxNumberOfIterations), maxNumberOfIterationsWithoutImprovement(__maxNumberOfIterationWithoutImprovement),
    00036       maxNumberOfIterationsReached(false), firstFitnessSaved(true), counter(0)
    00037   {}
    00038
    00040
    00046   bool operator   () (const EOT & __sol)
    00047   {
    00048     if(!maxNumberOfIterationsReached)
    00049       {
    00050         maxNumberOfIterationsReached=((++counter)==maxNumberOfIterations);
    00051         if(maxNumberOfIterationsReached)
    00052           {
    00053             std::cout << "moSteadyFitSolContinue: Done the minimum number of iterations [" << counter << "]." << std::endl;
    00054           }
    00055         return true;
    00056       }
    00057
    00058     if(__sol.invalid())
    00059       {
    00060         return true;
    00061       }
    00062
    00063     if(firstFitnessSaved)
    00064       {
    00065         fitness=__sol.fitness();
    00066         counter=0;
    00067         firstFitnessSaved=false;
    00068         return true;
    00069       }
    00070
    00071     counter++;
    00072
    00073     if( __sol.fitness() > fitness )
    00074       {
    00075         fitness=__sol.fitness();
    00076         counter=0;
    00077       }
    00078
    00079     if(counter==maxNumberOfIterationsWithoutImprovement)
    00080       {
    00081         std::cout << "moSteadyFitSolContinue: Done [" << counter  << "] iterations without improvement." << std::endl;
    00082       }
    00083     return counter!=maxNumberOfIterationsWithoutImprovement;
    00084   }
    00085
    00087
    00090   void init ()
    00091   {
    00092     maxNumberOfIterationsReached=false;
    00093     counter=0;
    00094     firstFitnessSaved=true;
    00095   }
    00096
    00097 private:
    00098
    00100   unsigned int maxNumberOfIterations;
    00101
    00103   unsigned int maxNumberOfIterationsWithoutImprovement;
    00104
    00106   bool maxNumberOfIterationsReached;
    00107
    00109   bool firstFitnessSaved;
    00110
    00112   Fitness fitness;
    00113
    00115   unsigned int counter;
    00116 };
    00117
    00118 #endif