1 #ifndef __INDIVIDUAL_H__
2 #define __INDIVIDUAL_H__
12 #include "boost/smart_ptr.hpp"
32 typedef std::vector< std::pair<double, double> >
bounds_t;
51 std::cerr <<
"Individual::Individual(): names not equal length to bounds, shouldn't happen exiting" <<
std::endl;
57 for (
size_t i=0; i <
bounds_m.size(); i++) {
62 if (allSatisfied ==
true)
break;
75 id_m = individual->id_m;
79 template<
class Archive>
92 genes_m[gene_idx] = rand() / (RAND_MAX + 1.0) * delta +
min;
110 for (
size_t i=0; i <
bounds_m.size(); i++) {
114 bool is_valid = (value >= min && value<=
max);
115 if (is_valid ==
false) {
126 std::set<std::string> req_vars = constraint->
getReqVars();
129 for (std::string req_var : req_vars) {
133 std::cerr <<
"Individual::checkConstraints(): " << req_var <<
" is not a design variable" <<
std::endl;
136 size_t gene_idx = std::distance(
names_m.begin(),it);
137 double value =
genes_m[gene_idx];
138 variable_dictionary.insert(std::pair<std::string, double>(req_var, value));
141 constraint->
evaluate(variable_dictionary);
143 double evaluation = boost::get<0>(result);
144 bool is_valid = boost::get<1>(result);
146 if (is_valid==
false || evaluation==0) {
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
objectives_t objectives_m
values of objectives of an individual
bounds_t bounds_m
bounds on each gene
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
std::vector< double > genes_t
representation of genes
Expression to be evaluated in the framework.
bool checkBounds()
check bounds
Individual(boost::shared_ptr< Individual > individual)
copy another individual
double new_gene(size_t gene_idx)
genes_t genes_m
genes of an individual
boost::tuple< double, bool > Result_t
std::set< std::string > getReqVars() const
int version
opal version of input file
void serialize(Archive &ar, const unsigned int version)
serialization of structure
const T * find(const T table[], const std::string &name)
Look up name.
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
bool checkConstraints()
check if all constraints on design variables are checked
Expressions::Result_t evaluate(variableDictionary_t vars)
evaluate an expression given a value dictionary of free variables
constraints_t constraints_m
constraints that depend only on design variables
Individual(bounds_t gene_bounds, names_t names, constraints_t constraints)
create a new individual and initialize with random genes
std::map< std::string, double > variableDictionary_t
std::vector< std::string > names_t
gene names
Expressions::Named_t constraints_t
constraints
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
names_t names_m
gene names
std::vector< std::pair< double, double > > bounds_t
bounds on design variables
std::vector< double > objectives_t
objectives array
Inform & endl(Inform &inf)
bool viable()
test if individual within bounds and constraints