• Main Page
  • Classes
  • Files
  • File List

D:/Radagast_D/Projekt/ECF_trunk/ECF/State.h

00001 #ifndef State_h
00002 #define State_h
00003 
00004 #include "Population.h"
00005 #include "Randomizer.h"
00006 #include "Logger.h"
00007 #include "EvaluateOp.h"
00008 #include "HallOfFame.h"
00009 #include "StatCalc.h"
00010 #include "Operator.h"
00011 #include "Communicator.h"
00012 #include "Migration.h"
00013 
00014 #include <map>
00015 #include "boost/enable_shared_from_this.hpp"
00016 
00017 #define NODE_REGISTRY   "Registry"
00018 #define NODE_ALGORITHM  "Algorithm"
00019 #define NODE_GENOTYPE   "Genotype"
00020 #define NODE_MILESTONE  "Milestone"
00021 #define NODE_POPULATION "Population"
00022 
00023 class Algorithm;
00024 typedef boost::shared_ptr<Algorithm> AlgorithmP;
00025 class State;
00026 typedef boost::shared_ptr<State> StateP;
00027 
00035 class State : public boost::enable_shared_from_this<State>
00036 {
00037 private:
00038     // system components
00039     RandomizerP randomizer_;
00040     RegistryP registry_;
00041     LoggerP logger_;
00042     CommunicatorP comm_;
00043     MigrationP migration_;
00044 
00045     // evolutionary components
00046     PopulationP population_;    
00047     AlgorithmP algorithm_;      
00048     CrossoverP crossover_;      
00049     MutationP mutation_;        
00050     EvaluateOpP evalOp_;        
00051     FitnessP fitness_;          
00052     IndividualP individual_;    
00053     StatCalcP statistic_;
00054     std::vector<GenotypeP> genotype_;       
00055 
00056     std::map<std::string, AlgorithmP> mAlgorithms_; 
00057     typedef std::map<std::string, AlgorithmP>::iterator alg_iter;
00058     std::map<std::string, GenotypeP> mGenotypes_;   
00059     typedef std::map<std::string, GenotypeP>::iterator gen_iter;
00060     std::vector<OperatorP> allTerminationOps_;  
00061     std::vector<OperatorP> activeTerminationOps_;   
00062     std::vector<OperatorP> allUserOps_; 
00063     std::vector<OperatorP> activeUserOps_;  
00064     XMLNode xConfig_;   
00065 
00066     // system state
00067     bool bInitialized_;
00068     bool bSaveMilestone_;
00069     bool bLoadMilestone_;
00070     bool bAlgorithmSet_;
00071     bool bGenotypeSet_;
00072     bool bEvaluatorSet_;
00073     bool bBatchMode_;
00074     bool bBatchStart_;
00075     bool bBatchSingleMilestone_;
00076     bool bBatchWriteStats_;
00077     uint batchRepeats_;
00078     uint batchRemaining_;
00079     std::string batchStatsFile_;
00080     std::string batchLogFile_;
00081     std::string milestoneFilename_;
00082     uint milestoneInterval_;
00083     uint milestoneGeneration_;
00084     time_t milestoneElapsedTime_;
00085     time_t startTime_, currentTime_, elapsedTime_;
00086     int argc_;
00087     char **argv_;
00088 
00089     // evolutionary context
00090     bool bTerminate_;
00091     uint generationNo_;
00092 
00093     StateP state_;  // pointer to itself (to avoid http://www.boost.org/doc/libs/1_37_0/libs/smart_ptr/sp_techniques.html#from_this)
00094     virtual StateP getState()
00095     {   return shared_from_this();  }
00096 
00097     bool initializeComponents(int, char**);
00098     bool runBatch();
00099     bool parseConfig(std::string filename);
00100     bool parseAlgorithmNode(XMLNode node);
00101     bool parseGenotypeNode(XMLNode node);
00102     void registerParameters(void);
00103     void readParameters(void);
00104     void saveMilestone(void);
00105     void loadMilestone(void);
00106     void write(XMLNode&);
00107 
00108 public:
00109     State();
00110     virtual ~State()
00111     {   }
00112     bool initialize(int, char**);
00113     bool run();
00114 
00118     RandomizerP getRandomizer() 
00119     {   return randomizer_; }
00120 
00124     void setRandomizer(RandomizerP randomizer)  
00125     {   randomizer_ = randomizer;   }
00126 
00130     RegistryP getRegistry() 
00131     {   return registry_;   }
00132 
00133     LoggerP getLogger() 
00134     {   return logger_; }
00135 
00139     StatCalcP getStats()    
00140     {   return population_->stats_; }
00141 
00145     HallOfFameP getHoF()    
00146     {   return population_->hof_;   }
00147 
00151     CommunicatorP getCommunicator() 
00152     {   return comm_;   }
00153 
00157     uint getGenerationNo()  
00158     {   return generationNo_;   }
00159 
00163     uint getElapsedTime()
00164     {   return (uint) elapsedTime_; }
00165 
00169     bool getBatchMode()
00170     {   return bBatchMode_; }
00171 
00175     void setTerminateCond() 
00176     {   bTerminate_ = true; }
00177 
00181     bool getTerminateCond() 
00182     {   return bTerminate_; }
00183 
00187     FitnessP getFitnessObject()
00188     {   return fitness_;    }
00189 
00193     IndividualP getIndividualObject()
00194     {   return individual_; }
00195 
00199     std::vector<GenotypeP> getGenotypes()
00200     {   return genotype_;   }
00201 
00202     PopulationP getPopulation() 
00203     {   return population_; }
00204 
00208     AlgorithmP getAlgorithm()
00209     {   return algorithm_;  }
00210 
00211     bool isImplicitParallel();
00212     bool isAlgorithmParallel();
00213 
00214 
00215 // TODO: dynamic insertion of framework components
00216     //addMutationOp   // genotype
00217     //addCrossoverOp  // genotype
00218 
00219 public:
00220 // setting the components (the ones to be used)
00221     uint setGenotype(GenotypeP);
00222     void setAlgorithm(AlgorithmP);
00223     void setEvalOp(EvaluateOpP);
00224 
00225 // adding the components (that _may_ be used or configured)
00226     bool addGenotype(GenotypeP gen);
00227     bool addAlgorithm(AlgorithmP alg);
00228     bool addOperator(OperatorP op);
00229 
00230 };
00231 typedef boost::shared_ptr<State> StateP;
00232 
00233 #endif // State_h
00234 

Generated on Wed Sep 1 2010 14:31:21 for ECF by  doxygen 1.7.1