1 #include "IPopulation.h" 4 #include "IFigureOfMerit.h" 40 for(
int i=0; i<
size(); i++) {
58 for(
int i=0; i<
size(); i++) {
82 if(rate<0 || rate > 1) {
83 std::ostringstream ostr;
84 ostr <<
"Specified rate (" << rate <<
") is out of range [0,1]";
85 throw std::runtime_error(ostr.str().c_str());
102 for(
int i=0; i<
size(); i++) {
140 if(rank < 0 || rank >=
size()) {
141 std::ostringstream ostr;
142 ostr <<
"Rank (" << rank <<
") is out of range [" << 0 <<
", " <<
size() <<
"[";
143 throw std::runtime_error(ostr.str().c_str());
177 for(
int i=0; i<
size(); i++) {
191 if(
size() <= 1)
return;
196 for (
int i = 1; i<=n-1; i++) {
213 throw std::runtime_error(
"Figure of merit not assigned for this population.");
234 while(p1 == p2 || p2 > f2);
TRandom3 * m_random
Stores a random number generator.
double m_scoreMean
Stores the mean score for the population.
IModel * getBestFitted(int rank=0)
virtual void selectParents(int &p1, int &p2)
void setMutateRate(double rate)
void setFigureOfMerit(IFigureOfMerit *fom)
IFigureOfMerit * getFigureOfMerit()
bool m_sorted
Stores whether the ranking is valid or needs to be redone.
double m_mutateRate
Stores the mutate rate.
std::vector< std::vector< IModel * > > m_parents
Stores the list of parents about to be crossed-over.
void checkFigureOfMerit()
virtual void doMutate(IModel *model)=0
IFigureOfMerit * m_fom
Stores the figure of merit to be used to calculate scores and perform the ranking.
void setRandomSeed(int seed)
std::vector< IModel * > m_individuals
Stores the individuals of this population.
virtual void doInitialize(int n)=0
virtual void doCrossOver(const std::vector< std::vector< IModel *> > &parents)=0
Abstract class describing the interface for a model.
double m_scoreRMS
Stores the score RMS for the population.