• Main Page
  • Modules
  • Classes
  • Files
  • File List

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

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

Generated on Fri Jul 5 2013 09:34:23 for ECF by  doxygen 1.7.1