std::string PopulationLocus::flatten(Gene* index) { if (this->outOfRange(index)) throw ValueOutOfRangeException(); std::stringstream ss; ss << boost::any_cast<Genome*>(this->getIndex(index))->flatten(); return ss.str(); }
void UniformCrossover::init(std::vector<double> parentProbabilities) { if (!parentProbabilities.empty()) { double sum = std::accumulate( parentProbabilities.begin(), parentProbabilities.end(), 0.0 ); if (sum != 1.0) throw ValueOutOfRangeException("Parent probabilities must sum to 1!"); } this->parentProbabilities = parentProbabilities; }
double linearInterpolation (double x, vector<Vector> points) throw(ValueOutOfRangeException, CoincidentPointsException) { int first_index = -1, last_index = -1; sort (points.begin(), points.end(), interpolateNS::vectorCmp); if ((x < points[0][0]) || (x > points[points.size()-1][0])) throw ValueOutOfRangeException(); for (size_t i=0; i < points.size()-1; i++) { if (x >= points[i][0] && x <= points[i+1][0]) { first_index = i; last_index = i+1; break; } } double x0 = points[first_index][0], x1 = points[last_index][0], y0 = points[first_index][1], y1 = points[last_index][1]; return ( (y1-y0)/(x1-x0) )*(x-x0) + y0; }
std::vector<unsigned int> TreeBuilder::getLevelCounts(unsigned int level) { if (level >= this->numLevels()) throw ValueOutOfRangeException(); return this->counts[level]; }
void MuLambdaES::init(unsigned int lambda, unsigned int rho) { this->init(lambda); if (rho < 2) throw ValueOutOfRangeException("Rho parameter must be at least 2."); this->rho = rho; }
void MuLambdaES::init(unsigned int lambda) { if (lambda == 0) throw ValueOutOfRangeException("Lambda parameter must be at least 1."); this->lambda = lambda; this->rho = 0; }