27 #include <boost/functional/hash.hpp>
29 #include "../exceptions.h"
36 namespace pagmo {
namespace problem {
49 robust::robust(
const base & p,
unsigned int trials,
const double param_rho,
unsigned int seed):
56 m_original_problem(p.clone()),
63 pagmo_throw(value_error,
"Rho should be greater than 0");
71 m_original_problem(prob.m_original_problem->clone()),
72 m_uniform_dist(0, prob.m_rho),
73 m_trials(prob.m_trials),
114 for(
unsigned int i = 0; i < m_trials; ++i){
115 inject_noise_x(x_perturbed);
116 m_original_problem->objfun(tmp, x_perturbed);
117 for(fitness_vector::size_type j = 0; j < f.size(); ++j){
118 f[j] += tmp[j] / (double)m_trials;
136 for(
unsigned int i = 0; i < m_trials; ++i){
137 inject_noise_x(x_perturbed);
138 m_original_problem->compute_constraints(tmp, x_perturbed);
139 for(constraint_vector::size_type j = 0; j < c.size(); ++j){
140 c[j] = tmp[j] / (double)m_trials;
152 double radius = m_rho * pow(m_uniform_dist(
m_drng),1.0/x.size());
155 std::vector<double> perturbation(x.size(), 0.0);
157 for(
size_type i = 0; i < perturbation.size(); i++){
158 perturbation[i] = m_normal_dist(
m_drng);
159 c2 += perturbation[i]*perturbation[i];
163 for(
size_type i = 0; i < perturbation.size(); i++){
164 perturbation[i] *= (radius / sqrt(c2) );
165 x[i] += perturbation[i];
170 x[i] = std::max(x[i],
get_lb()[i]);
171 x[i] = std::min(x[i],
get_ub()[i]);
177 return m_original_problem->get_name() +
" [Robust]";
186 std::ostringstream oss;
187 oss << m_original_problem->human_readable_extra() << std::endl;
188 oss <<
"\tNeighbourhood radius = " << m_rho;
189 oss <<
"\n\ttrials: "<<m_trials;
190 oss <<
"\n\tseed: "<<
m_seed<< std::endl;
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base problem.
std::vector< double > decision_vector
Decision vector type.
void objfun_impl(fitness_vector &, const decision_vector &) const
std::string get_name() const
Get problem's name.
rng_double m_drng
Random number generator for double-precision floating point values.
unsigned int m_seed
Seed of the random number generator.
robust(const base &=ackley(1), unsigned int trials=1, const double param_rho=0.1, unsigned int seed=0u)
std::vector< double > fitness_vector
Fitness vector type.
std::vector< double > constraint_vector
Constraint vector type.
const decision_vector & get_ub() const
Upper bounds getter.
Base Stochastic Optimization Problem.
void compute_constraints_impl(constraint_vector &, const decision_vector &) const
const decision_vector & get_lb() const
Lower bounds getter.
base_ptr clone() const
Clone method.
void set_bounds(const decision_vector &, const decision_vector &)
Bounds setter from pagmo::decision_vector.
decision_vector::size_type size_type
Problem's size type: the same as pagmo::decision_vector's size type.
std::string human_readable_extra() const
Extra human readable info for the problem.