5typedef boost::shared_ptr<Algorithm> AlgorithmP;
7typedef boost::shared_ptr<State> StateP;
10#include "Randomizer.h"
12#include "EvaluateOp.h"
13#include "HallOfFame.h"
16#include "Communicator.h"
21#include "boost/enable_shared_from_this.hpp"
24#define NODE_REGISTRY "Registry"
25#define NODE_ALGORITHM "Algorithm"
26#define NODE_GENOTYPE "Genotype"
27#define NODE_MILESTONE "Milestone"
28#define NODE_POPULATION "Population"
38class State :
public boost::enable_shared_from_this<State>
42 RandomizerP randomizer_;
46 MigrationP migration_;
49 PopulationP population_;
50 AlgorithmP algorithm_;
51 CrossoverP crossover_;
53 EvolutionContextP context_;
56 IndividualP individual_;
57 std::vector<GenotypeP> genotype_;
59 std::map<std::string, AlgorithmP> mAlgorithms_;
60 typedef std::map<std::string, AlgorithmP>::iterator alg_iter;
61 std::map<std::string, GenotypeP> mGenotypes_;
62 typedef std::map<std::string, GenotypeP>::iterator gen_iter;
63 std::vector<OperatorP> allTerminationOps_;
64 std::vector<OperatorP> activeTerminationOps_;
65 std::vector<OperatorP> allUserOps_;
66 std::vector<OperatorP> activeUserOps_;
79 bool bBatchSingleMilestone_;
80 bool bBatchWriteStats_;
83 std::string batchStatsFile_;
84 std::string batchLogFile_;
85 std::string milestoneFilename_;
86 uint milestoneInterval_;
87 uint milestoneGeneration_;
88 time_t milestoneElapsedTime_;
89 time_t startTime_, currentTime_, elapsedTime_;
94 virtual StateP getState()
95 {
return shared_from_this(); }
97 bool initializeComponents(
int,
char**);
99 bool parseCommandLine(
int,
char**);
100 bool parseConfig(std::string filename);
101 bool parseAlgorithmNode(XMLNode
node);
102 bool parseGenotypeNode(XMLNode
node);
103 void registerParameters(
void);
104 void readParameters(
void);
105 void saveMilestone(
void);
106 void loadMilestone(
void);
107 void write(XMLNode&);
108 void dumpParameters(std::string fileName,
bool addClear =
true);
121 {
return randomizer_; }
125 { randomizer_ = randomizer; }
129 {
return registry_; }
137 {
return population_->getStats(); }
141 {
return population_->getHof(); }
149 {
return context_->generationNo_; }
153 {
return (uint) elapsedTime_; }
157 {
return bBatchMode_; }
161 { context_->bTerminate_ =
true; }
165 {
return population_->at(0)->stats_->increaseEvaluations(nEval); }
169 {
return population_->getStats()->getEvaluations(); }
173 {
return context_->bTerminate_; }
181 {
return individual_; }
185 {
return genotype_; }
189 {
return population_; }
193 {
return algorithm_; }
219typedef boost::shared_ptr<State> StateP;
State class - backbone of the framework.
PopulationP getPopulation()
get Population
EvolutionContextP getContext()
get evolutionary context
IndividualP getIndividualObject()
get one initial Individual object
void setAlgorithm(AlgorithmP)
Set the desired algorithm (overrides the current choice)
FitnessP getFitnessObject()
get one initial Fitness object (create on demand)
bool addGenotype(GenotypeP gen)
Add user-defined or user customized genotype. (The genotype can then be specified and used in config ...
void setEvalOp(EvaluateOpP)
Set user defined evaluation operator.
bool addAlgorithm(AlgorithmP alg)
Add user-defined or user customized algorithm. (It can then be specified and used in config file....
AlgorithmP getAlgorithm()
access current active Algorithm
bool run()
Driver of the evolution process - serial version.
bool isImplicitParallel()
Is the algorithm executed implicitly parallel.
CommunicatorP getCommunicator()
access current process communicator mechanism
bool initialize(int, char **)
Initialize the whole system.
RandomizerP getRandomizer()
get current Randomizer
uint setGenotype(GenotypeP)
Set a genotype to be used in individuals.
RegistryP getRegistry()
get access to parameter repository
HallOfFameP getHoF()
get population hall of fame
EvaluateOpP getEvalOp()
access evaluation operator
bool getBatchMode()
get batch mode info (yes or no)
uint getEvaluations()
get number of evaluations (global population)
bool isAlgorithmParallel()
Is current algorithm parallel.
LoggerP getLogger()
get Logger
void setTerminateCond()
set termination condition (evolution ends with current generation)
StatCalcP getStats()
get population statistics
State()
Construct the one and only State object.
uint increaseEvaluations(uint nEval=1)
increase and return number of evaluations (local deme)
bool addOperator(OperatorP op)
Add user-defined operator. (Its parameters can now be specified and used in config file....
bool getTerminateCond()
is termination condition set
std::vector< GenotypeP > getGenotypes()
access all active (currently used) genotypes
uint getGenerationNo()
get current generation number
void setRandomizer(RandomizerP randomizer)
set Randomizer to be used
uint getElapsedTime()
get elapsed time (in seconds)