25#ifndef __INDIVIDUAL_H__
26#define __INDIVIDUAL_H__
47 typedef std::vector< std::pair<double, double> >
bounds_t;
66 std::cerr <<
"Individual::Individual(): names not equal length to bounds, shouldn't happen exiting" << std::endl;
72 for (
size_t i=0; i <
bounds_m.size(); i++) {
77 if (allSatisfied ==
true)
break;
90 id_m = individual->id_m;
94 template<
class Archive>
106 double delta = std::abs(
max -
min);
107 genes_m[gene_idx] = rand() / (RAND_MAX + 1.0) * delta +
min;
125 for (
size_t i=0; i <
bounds_m.size(); i++) {
129 bool is_valid = (value >=
min && value<=
max);
130 if (is_valid ==
false) {
141 std::set<std::string> req_vars = constraint->
getReqVars();
144 for (std::string req_var : req_vars) {
148 std::cerr <<
"Individual::checkConstraints(): " << req_var <<
" is not a design variable" << std::endl;
151 size_t gene_idx = std::distance(
names_m.begin(),it);
152 double value =
genes_m[gene_idx];
153 variable_dictionary.insert(std::pair<std::string, double>(req_var, value));
156 constraint->
evaluate(variable_dictionary);
158 double evaluation = boost::get<0>(result);
159 bool is_valid = boost::get<1>(result);
161 if (is_valid==
false || evaluation==0) {
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
std::map< std::string, double > variableDictionary_t
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
Expression Expr_t
type of an expression
boost::tuple< double, bool > Result_t
Expressions::Result_t evaluate(variableDictionary_t vars)
evaluate an expression given a value dictionary of free variables
std::set< std::string > getReqVars() const
void serialize(Archive &ar, const unsigned int)
serialization of structure
std::vector< std::string > names_t
gene names
genes_t genes_m
genes of an individual
names_t names_m
gene names
objectives_t objectives_m
values of objectives of an individual
bool checkBounds()
check bounds
std::vector< std::pair< double, double > > bounds_t
bounds on design variables
bool viable()
test if individual within bounds and constraints
double new_gene(size_t gene_idx)
Individual(bounds_t gene_bounds, names_t names, constraints_t constraints)
create a new individual and initialize with random genes
bounds_t bounds_m
bounds on each gene
constraints_t constraints_m
constraints that depend only on design variables
std::vector< double > genes_t
representation of genes
bool checkConstraints()
check if all constraints on design variables are checked
std::vector< double > objectives_t
objectives array
Expressions::Named_t constraints_t
constraints
Individual(std::shared_ptr< Individual > individual)
copy another individual