Пример #1
0
/**
 * Updates the solution infeasibility vector with the population given.
 * @param[in] constraint_vector c.
 * @param[out] solution infeasibility.
 */
double cstrs_self_adaptive::compute_solution_infeasibility(const constraint_vector &c) const
{
	// get the constraints dimension
	problem::base::c_size_type prob_c_dimension = m_original_problem->get_c_dimension();
	problem::base::c_size_type number_of_eq_constraints =
			m_original_problem->get_c_dimension() -
			m_original_problem->get_ic_dimension();

	double solution_infeasibility = 0.;

	const std::vector<double> &c_tol = m_original_problem->get_c_tol();

	// computes solution infeasibility with the right definition of the constraints (can be in base problem? currently used
	// by con2mo as well)
	for(problem::base::c_size_type j=0; j<number_of_eq_constraints; j++) {
		// test needed otherwise the c_scaling can be 0, and division by 0 occurs
		if(m_c_scaling[j] > 0.) {
			solution_infeasibility += std::max(0.,(std::abs(c.at(j)) - c_tol.at(j))) / m_c_scaling[j];
		}
	}
	for(problem::base::c_size_type j=number_of_eq_constraints; j<prob_c_dimension; j++) {
		if(m_c_scaling[j] > 0.) {
			solution_infeasibility += std::max(0.,c.at(j) - c_tol.at(j)) / m_c_scaling[j];
		}
	}

	solution_infeasibility /= prob_c_dimension;

	return solution_infeasibility;
}
Пример #2
0
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;
}