コード例 #1
0
ファイル: noisy.cpp プロジェクト: DominicDirkx/pagmo
/// 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;
		}
	}
}
コード例 #2
0
ファイル: robust.cpp プロジェクト: DinCahill/pagmo
/// 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;
		}
	}
}
コード例 #3
0
ファイル: noisy.cpp プロジェクト: DominicDirkx/pagmo
/// 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;
		}
	}
}