28 #include "../exceptions.h"
30 #include "../population.h"
32 #include "antibodies_problem.h"
34 namespace pagmo {
namespace problem {
46 base((int)problem.get_dimension(),
47 problem.get_i_dimension(),
48 problem.get_f_dimension(),
52 m_original_problem(problem.clone()),
56 if(m_original_problem->get_c_dimension() <= 0){
57 pagmo_throw(value_error,
"The original problem has no constraints.");
61 if(m_original_problem->get_f_dimension() != 1) {
62 pagmo_throw(value_error,
"The original fitness dimension of the problem must be one, multi objective problems can't be handled with co-evolution meta problem.");
67 m_max_encoding_integer = int(std::pow(2., m_bit_encoding));
69 set_bounds(m_original_problem->get_lb(),m_original_problem->get_ub());
74 base((int)prob.get_dimension(),
75 prob.get_i_dimension(),
76 prob.get_f_dimension(),
77 prob.get_c_dimension(),
78 prob.get_ic_dimension(),
80 m_original_problem(prob.m_original_problem->clone()),
81 m_pop_antigens(prob.m_pop_antigens),
82 m_method(prob.m_method),
83 m_bit_encoding(prob.m_bit_encoding),
84 m_max_encoding_integer(prob.m_max_encoding_integer)
86 set_bounds(m_original_problem->get_lb(),m_original_problem->get_ub());
103 f[0] = compute_distance(x);
113 return m_original_problem->compare_fitness(v_f1,v_f2);
122 std::ostringstream oss;
123 oss << m_original_problem->human_readable_extra() << std::endl;
124 oss <<
"\n\tWith antibodies method";
131 return m_original_problem->get_name() +
" [antibodies_problem]";
140 if(pop_antigens.size() == 0) {
141 pagmo_throw(value_error,
"The size of the antigens population must be different from 0.");
143 m_pop_antigens = pop_antigens;
150 double antibodies_problem::compute_distance(
const decision_vector &x)
const {
151 double distance = 0.;
156 case(algorithm::cstrs_immune_system::HAMMING): {
160 for(decision_vector::size_type i=0; i<x.size(); i++) {
162 std::vector<int> current_binary_gene = double_to_binary(x.at(i), lb.at(i), ub.at(i));
164 for(decision_vector::size_type j=0; j<m_pop_antigens.size(); j++) {
166 std::vector<int> antigens_binary_gene = double_to_binary((m_pop_antigens.at(j)).at(i), lb.at(i), ub.at(i));
168 for(std::vector<int>::size_type k=0; k<antigens_binary_gene.size(); k++) {
169 distance += antigens_binary_gene.at(k) && current_binary_gene.at(k);
177 distance = - distance;
180 case(algorithm::cstrs_immune_system::EUCLIDEAN): {
181 for(decision_vector::size_type j=0; j<m_pop_antigens.size(); j++) {
186 for(decision_vector::size_type i=0; i<x.size(); i++) {
187 euclid += std::pow(x.at(i) - antigen_decision.at(i),2);
189 distance += std::sqrt(euclid);
207 std::vector<int> antibodies_problem::double_to_binary(
const double &number,
const double &lb,
const double &ub)
const
210 std::vector<int> binary(m_bit_encoding, 0);
214 int temp_number = (number - lb) * (m_max_encoding_integer - 1) / (ub - lb) ;
218 while (temp_number!=0)
220 if( (temp_number % 2) == 0 ) {
221 binary[position] = 0;
223 binary[position] = 1;
225 temp_number = (int)std::floor(temp_number/2);
229 std::reverse(binary.begin(),binary.end());
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base problem.
std::vector< double > decision_vector
Decision vector type.
base_ptr clone() const
Clone method.
antibodies_problem(const base &=cec2006(4), const algorithm::cstrs_immune_system::distance_method_type=algorithm::cstrs_immune_system::HAMMING)
distance_method_type
Type of antibodies problem distance method.
void objfun_impl(fitness_vector &, const decision_vector &) const
void set_antigens(const std::vector< decision_vector > &)
Updates the antigens population used to compute the fitness.
std::vector< double > fitness_vector
Fitness vector type.
const decision_vector & get_ub() const
Upper bounds getter.
bool compare_fitness_impl(const fitness_vector &, const fitness_vector &) const
Implementation of fitness vectors comparison.
std::string human_readable_extra() const
Extra human readable info for the problem.
const decision_vector & get_lb() const
Lower bounds getter.
void set_bounds(const decision_vector &, const decision_vector &)
Bounds setter from pagmo::decision_vector.
std::string get_name() const
Get problem's name.