26 #include <boost/integer_traits.hpp>
27 #include <boost/numeric/conversion/cast.hpp>
36 #include "../exceptions.h"
38 #include "golomb_ruler.h"
40 namespace pagmo {
namespace problem {
42 static inline int check_golomb_order(
int n)
45 pagmo_throw(value_error,
"Golomb ruler problem must have at least order 2");
59 if (!m_max_length || m_max_length > static_cast<std::size_t>(INT_MAX)) {
60 pagmo_throw(value_error,
"maximum distance between consecutive marks must be in the ]0,32767] range");
62 if (
get_dimension() == boost::integer_traits<size_type>::const_max) {
63 pagmo_throw(std::overflow_error,
"size overflow in Golomb ruler problem");
65 if (
double(m_max_length) *
get_dimension() > static_cast<double>(INT_MAX)) {
66 pagmo_throw(std::overflow_error,
"fitness value overflow in Golomb ruler problem");
84 pagmo_assert(
typeid(*
this) ==
typeid(other));
85 return (m_max_length == dynamic_cast<golomb_ruler const &>(other).m_max_length);
98 compute_marks_and_dist(x);
100 f[0] = *std::max_element(m_tmp_dist.begin(),m_tmp_dist.end());
114 compute_marks_and_dist(x);
116 std::sort(m_tmp_dist.begin(),m_tmp_dist.end());
118 c[0] = boost::numeric_cast<
double>(m_tmp_dist.size()) - std::distance(m_tmp_dist.begin(),std::unique(m_tmp_dist.begin(),m_tmp_dist.end()));
122 void golomb_ruler::compute_marks_and_dist(
const decision_vector &x)
const
129 const size_type size = m_tmp_x.size(), marks_size = size + 1;
130 m_tmp_marks.resize(marks_size);
134 m_tmp_marks[i + 1] = m_tmp_marks[i] + m_tmp_x[i];
138 for (
size_type i = 0; i < marks_size - 1; ++i) {
139 for (
size_type j = i + 1; j < marks_size; ++j) {
140 const double tmp = m_tmp_marks[j] - m_tmp_marks[i];
141 pagmo_assert(tmp >= 0);
142 m_tmp_dist.push_back(tmp);
149 return "Golomb ruler";
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base problem.
void compute_constraints_impl(constraint_vector &, const decision_vector &) const
Implementation of constraint calculation.
std::vector< double > decision_vector
Decision vector type.
base_ptr clone() const
Clone method.
golomb_ruler(int=5, int=10)
Constructor from order and maximum distance between consecutive marks.
size_type get_dimension() const
Return global dimension.
bool equality_operator_extra(const base &) const
Additional requirements for equality.
void set_ub(const decision_vector &)
Set upper bounds from pagmo::decision_vector.
std::vector< double > fitness_vector
Fitness vector type.
std::vector< double > constraint_vector
Constraint vector type.
void objfun_impl(fitness_vector &, const decision_vector &) const
Implementation of the objective function.
decision_vector::size_type size_type
Problem's size type: the same as pagmo::decision_vector's size type.
std::string get_name() const
Get problem's name.