double mean_violated_constraints(const constraint_vector &c, problem::base_ptr original_problem) { double viol = 0; constraint_vector::size_type c_dim = original_problem->get_c_dimension(); problem::base::c_size_type number_of_eq_constraints = original_problem->get_c_dimension() - original_problem->get_ic_dimension(); const std::vector<double> &c_tol = original_problem->get_c_tol(); for(constraint_vector::size_type j=0; j<number_of_eq_constraints; j++) { viol += std::max(0.,(std::abs(c.at(j)) - c_tol.at(j))); } for(constraint_vector::size_type j=number_of_eq_constraints; j<c_dim; j++) { viol += std::max(0.,c.at(j)); } viol /= c_dim; return viol; }
int number_violated_constraints(const constraint_vector &c, problem::base_ptr original_problem) { int viol = 0; constraint_vector::size_type c_dim = original_problem->get_c_dimension(); for(constraint_vector::size_type i=0; i<c_dim; i++) { if (!original_problem->test_constraint(c,i)) { viol++; } } return viol; }