28 #include "../exceptions.h"
30 #include "../population.h"
31 #include "death_penalty.h"
33 namespace pagmo {
namespace problem {
48 problem.get_dimension(),
49 problem.get_i_dimension(),
50 problem.get_f_dimension(),
53 std::vector<double>()),
55 m_penalty_factors(penalty_factors)
58 pagmo_throw(value_error,
"The original problem is unconstrained.");
61 if( method > 2 || method < 0) {
62 pagmo_throw(value_error,
"the death penalty method must be set to 0 for simple death, 1 for Kuri death and 2 for static penalty with predefined penalty coefficients.");
66 pagmo_throw(value_error,
"the vector of penalties factors is missing or needs to match constraints size");
69 if(method !=
WEIGHTED && m_penalty_factors.size() > 0){
70 pagmo_throw(value_error,
"Methods which are not WEIGHTED do not make use of weight vectors");
91 double high_value = boost::numeric::bounds<double>::highest();
97 std::fill(f.begin(),f.end(),high_value);
102 constraint_vector::size_type number_of_constraints = c.size();
103 constraint_vector::size_type number_of_satisfied_constraints = 0;
106 for(
c_size_type i=0; i<number_of_constraints; i++){
108 number_of_satisfied_constraints += 1;
112 double penalization = high_value * (1. - (double)number_of_satisfied_constraints / (
double)number_of_constraints);
114 std::fill(f.begin(),f.end(),penalization);
125 double penalization = 0;
127 for(
c_size_type i=0; i<number_of_constraints; i++) {
128 if(i<number_of_eq_constraints){
129 c[i] = std::abs(c[i]) - c_tol[i];
132 c[i] = c[i] - c_tol[i];
136 for(
c_size_type i=0; i<number_of_constraints; i++) {
138 penalization += m_penalty_factors[i]*c[i];
144 f[i] += penalization;
150 pagmo_throw(value_error,
"Error: There are only 2 methods for the death penalty!");
162 std::ostringstream oss;
164 oss <<
"\n\tConstraints handled with death penalty, method ";
197 method =
"WEIGHTED ";
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base problem.
std::vector< double > decision_vector
Decision vector type.
std::string get_name() const
Get problem's name.
fitness_vector::size_type f_size_type
Fitness' size type: the same as pagmo::fitness_vector's size type.
base_ptr clone() const
Clone method.
method_type
Mechanism used to assign the penalty.
death_penalty(const base &=cec2006(4), const method_type=SIMPLE, const std::vector< double > &=std::vector< double >())
Constructor from a constrained problem.
std::vector< double > fitness_vector
Fitness vector type.
std::string human_readable_extra() const
Extra human readable info for the problem.
void objfun_impl(fitness_vector &, const decision_vector &) const
std::vector< double > constraint_vector
Constraint vector type.
Penalizes the fitness function according to the number of satisfied constraints.
Penalizes the fitness function with a high value id the decision vector is unfeasible.
constraint_vector::size_type c_size_type
Constraints' size type: the same as pagmo::constraint_vector's size type.
Penalizes the fitness function with the weighted sum of the violations.
Constrainted death penalty meta-problem.