Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

SteadyStateEvolution.h

Go to the documentation of this file.
00001 /*
00002 Teem - an open source evolutionary software framework
00003 http://lis.epfl.ch/resources/Teem
00004 Stephane Magnenat <stephane.magnenat@epfl.ch>,
00005 Antoine Beyeler <antoine.beyeler@epfl.ch>,
00006 and other contributors.
00007 Laboratory of Intelligent Systems, EPFL, Lausanne
00008 
00009 This program is free software; you can redistribute it and/or modify
00010 it under the terms of the GNU General Public License as published by
00011 the Free Software Foundation; either version 2 of the License, or
00012 (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 */
00023 
00024 #ifndef STEADY_STATE_EVOLUTION_H
00025 #define STEADY_STATE_EVOLUTION_H
00026 
00027 #include "Evolution.h"
00028 #include <set>
00029 #include <ishtar/settings.h>
00030 
00035 namespace Ishtar
00036 {
00037     class InputStream;
00038     class OutputStream;
00039 }
00040 
00041 namespace Teem
00042 {
00043     class Genome;
00044     
00045     class SteadyStateEvolutionRun;
00046     class Continuable;
00047     
00050     class SteadyStateIndividual
00051     {
00052     public:
00054         Genome *genome;
00056         double bornTime;
00058         double deathTime;
00060         unsigned childrenCount;
00062         Serializable *userData;
00063         
00064     public:
00066         SteadyStateIndividual(Genome *genome, double bornTime);
00068         SteadyStateIndividual(GenotypeDecoders &decoders, Continuable *experiment, Ishtar::InputStream *stream);
00070         ~SteadyStateIndividual();
00071         
00073         void load(GenotypeDecoders &decoders, Continuable *experiment, Ishtar::InputStream *stream);
00075         void save(Ishtar::OutputStream *stream);
00076     };
00077     
00080     typedef std::set<SteadyStateIndividual *> SteadyStatePopulation;
00081     
00085     class Continuable : public Setupable
00086     {
00087     public:
00089         virtual double step(SteadyStateEvolutionRun *evolution, double time) = 0;
00091         virtual Serializable *individualCreated(GenotypeDecoders &decoders, SteadyStateIndividual *self, SteadyStateIndividual *mother, SteadyStateIndividual *father) = 0;
00092     };
00093     
00096     class SteadyStateEvolutionRun : public EvolutionRun
00097     {
00098     protected:
00099         // inner class
00100         
00102         struct NewbornIndividuals
00103         {
00105             NewbornIndividuals(SteadyStateIndividual *self, SteadyStateIndividual *mother, SteadyStateIndividual *father) { this->self = self; this->mother = mother; this->father = father; }
00106             
00107             SteadyStateIndividual *self; 
00108             SteadyStateIndividual *mother; 
00109             SteadyStateIndividual *father; 
00110         };
00111         
00113         struct NewbornIndividualsCompareFunctor
00114         {
00116             bool operator()(const NewbornIndividuals &i1, const NewbornIndividuals &i2) const
00117             {
00118                 return i1.self < i2.self;
00119             }
00120         };
00121         
00123         typedef std::set<NewbornIndividuals, NewbornIndividualsCompareFunctor> NewbornPopulation;
00124         
00125     protected:
00126         // members
00128         Ishtar::Variable<unsigned> initialPopulationSize;
00130         Ishtar::Variable<double> evolutionDuration;
00132         Ishtar::Variable<std::string> genotypeDecoderName;
00134         Ishtar::Variable<double> timeSaveInterval;
00135         
00137         NewbornPopulation toCreate;
00139         SteadyStatePopulation toKill;
00141         double time;
00143         double nextSaveTime;
00144         
00145     public:
00147         SteadyStatePopulation population;
00148     
00149     protected:
00150         // protected methods used internally
00152         virtual bool savePopulation(Setupable *experiment);
00154         virtual bool loadPopulation(Experiment *experiment, double timeToLoad);
00156         virtual bool loadPopulationFromStream(Experiment *experiment, Ishtar::InputStream *stream);
00157     
00158     public:
00159         // public methods from Evolution
00161         SteadyStateEvolutionRun();
00163         virtual ~SteadyStateEvolutionRun();
00164         
00166         virtual void createGenotypeDecoders(Setupable *experiment);
00167         
00169         virtual void createRandomPopulation();
00170 
00172         virtual bool loadPopulation(Experiment *experiment);
00174         virtual bool loadPopulation(Experiment *experiment, const char *timeToLoad) { return loadPopulation(experiment, atof(timeToLoad)); }
00175         
00177         virtual void run(Setupable *experiment);
00178             
00180         virtual void testBestIndividual(Setupable *experiment);
00182         virtual void testIndividual(Setupable *experiment, const char *);
00183         
00184     public:
00185         // public methods to be called from Continuable
00187         virtual void createRandomIndividual();
00189         virtual void createIndividual(SteadyStateIndividual *parent);
00191         virtual void createIndividual(SteadyStateIndividual *mother, SteadyStateIndividual *father);
00193         virtual void killIndividual(SteadyStateIndividual *individual);
00194     };
00195 }
00196 
00197 #endif

Generated on Mon Oct 24 17:38:25 2005 for Teem by  doxygen 1.4.2