Пример #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
/// Implementation of the constraints computation.
/// Add noises to the computed constraint vector.
void noisy::compute_constraints_impl(constraint_vector &c, const decision_vector &x) const
{
	//1 - Initialize a temporary constraint vector storing one trial result
	//and we use it also to init the return value 
	constraint_vector tmp(c.size(),0.0);
	c=tmp;
	//2 - We set the seed
	m_drng.seed(m_seed+m_decision_vector_hash(x));
	//3 - We average upon multiple runs
	for (unsigned int j=0; j< m_trials; ++j) {
		m_original_problem->compute_constraints(tmp, x);
		inject_noise_c(tmp);
		for (constraint_vector::size_type i=0; i<c.size();++i) {
			c[i] = c[i] + tmp[i] / (double)m_trials;
		}
	}
}
Пример #3
0
/// Implementation of the constraint function.
void gtoc5_rendezvous::compute_constraints_impl(constraint_vector &c, const decision_vector &x) const
{
	using namespace kep_toolbox;
	// We set the leg.
	const epoch epoch_i(x[0],epoch::MJD), epoch_f(x[1] + x[0],epoch::MJD);
	array3D v0, r0, vf, rf;
	m_source.eph(epoch_i,r0,v0);
	m_target.eph(epoch_f,rf,vf);
	m_leg.set_leg(epoch_i,sc_state(r0,v0,m_leg.get_spacecraft().get_mass()),x.begin() + 3, x.end(),epoch_f,sc_state(rf,vf,x[2]),ASTRO_MU_SUN);

	// We evaluate the state mismatch at the mid-point. And we use astronomical units to scale them
	m_leg.get_mismatch_con(c.begin(), c.begin() + 7);
	for (int i=0; i<3; ++i) c[i]/=ASTRO_AU;
	for (int i=3; i<6; ++i) c[i]/=ASTRO_EARTH_VELOCITY;
	c[6] /= m_leg.get_spacecraft().get_mass();
	// We evaluate the constraints on the throttles writing on the 7th mismatch constrant (mass is off)
	m_leg.get_throttles_con(c.begin() + 7, c.begin() + 7 + m_n_segments);
}
Пример #4
0
/// Implementation of the constraints computation.
/// Add noises to the decision vector before calling the actual constraint function.
void robust::compute_constraints_impl(constraint_vector &c, const decision_vector &x) const
{
	// Temporary storage used for averaging
	constraint_vector tmp(c.size(), 0.0);
	c = tmp;

	// Set the seed
	m_drng.seed(m_seed);

	// Perturb decision vector and evaluate
	decision_vector x_perturbed(x);
	for(unsigned int i = 0; i < m_trials; ++i){
		inject_noise_x(x_perturbed);
		m_original_problem->compute_constraints(tmp, x_perturbed);
		for(constraint_vector::size_type j = 0; j < c.size(); ++j){
			c[j] = tmp[j] / (double)m_trials;
		}
	}
}
Пример #5
0
/// Implementation of the constraint function.
void earth_planet::compute_constraints_impl(constraint_vector &c, const decision_vector &x) const
{
	// We decode the decision vector into a multiple fly-by trajectory
	trajectory.init_from_full_vector(x.begin(),x.end(),encoding);

	// We evaluate the state mismatch at the mid-point. And we use astronomical units to scale them
	trajectory.evaluate_all_mismatch_con(c.begin(), c.begin() + 7);
	for (int i=0; i<3; ++i) c[i]/=ASTRO_AU;
	for (int i=3; i<6; ++i) c[i]/=ASTRO_EARTH_VELOCITY;

	// We evaluate the constraints on the throttles writing on the 7th mismatch constrant (mass is off)
	trajectory.get_leg(0).get_throttles_con(c.begin() + 6, c.begin() + 6 + n_segments);

	// We evaluate the constraint on the initial launch velocity
	c[6 + n_segments] = (trajectory.evaluate_leg_vinf2_i(0) - vmax*vmax) / ASTRO_EARTH_VELOCITY / ASTRO_EARTH_VELOCITY;

	// We evaluate the linear constraint on the epochs (tf > ti)
	c[7 + n_segments] = trajectory.get_leg(0).get_t_i().mjd2000() - trajectory.get_leg(0).get_t_f().mjd2000();
}
Пример #6
0
/// Apply noise on a constraint vector
void noisy::inject_noise_c(constraint_vector& c) const
{
	for(c_size_type i = 0; i < c.size(); i++){
		if(m_noise_type == NORMAL){
			c[i] += m_normal_dist(m_drng)*m_param_second+m_param_first;
		}
		else if(m_noise_type == UNIFORM){
			c[i] += m_uniform_dist(m_drng)*(m_param_second-m_param_first)+m_param_first;
		}
	}
}
Пример #7
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;
}