25 #include <boost/numeric/conversion/cast.hpp>
26 #include <boost/random/uniform_int.hpp>
27 #include <boost/random/uniform_real.hpp>
35 #include "../exceptions.h"
36 #include "../population.h"
37 #include "../problem/base.h"
59 ihs::ihs(
int iterations,
const double &phmcr,
const double &ppar_min,
const double &ppar_max,
const double &bw_min,
const double &bw_max):
60 base(),m_gen(
boost::numeric_cast<
std::size_t>(iterations)),m_phmcr(phmcr),m_ppar_min(ppar_min),m_ppar_max(ppar_max),m_bw_min(bw_min),m_bw_max(bw_max)
62 if (phmcr > 1 || phmcr < 0 || ppar_min > 1 || ppar_min < 0 || ppar_max > 1 || ppar_max < 0) {
63 pagmo_throw(value_error,
"probability of choosing from memory and pitch adjustment rates must be in the [0,1] range");
65 if (ppar_min > ppar_max) {
66 pagmo_throw(value_error,
"minimum pitch adjustment rate must not be greater than maximum pitch adjustment rate");
68 if (bw_min <= 0 || bw_max < bw_min) {
69 pagmo_throw(value_error,
"bandwidth values must be positive, and minimum bandwidth must not be greater than maximum bandwidth");
86 if (pop_size == 0 || m_gen == 0) {
91 lu_diff[i] = ub[i] - lb[i];
94 boost::uniform_int<population::size_type> uni_int(0,pop_size - 1);
95 const double c = std::log(m_bw_min/m_bw_max) / m_gen;
98 tmp.
cur_x.resize(prob_dimension);
101 for (std::size_t g = 0; g < m_gen; ++g) {
102 const double ppar_cur = m_ppar_min + ((m_ppar_max - m_ppar_min) * g) / m_gen, bw_cur = m_bw_max * std::exp(c * g);
109 if (
m_drng() < ppar_cur) {
118 if (tmp.
cur_x[i] > ub[i]) {
119 tmp.
cur_x[i] = boost::uniform_real<double>(lb[i],ub[i])(
m_drng);
120 }
else if (tmp.
cur_x[i] < lb[i]) {
121 tmp.
cur_x[i] = boost::uniform_real<double>(lb[i],ub[i])(
m_drng);
126 tmp.
cur_x[i] = boost::uniform_real<double>(lb[i],ub[i])(
m_drng);
134 if (
m_drng() < ppar_cur) {
136 tmp.
cur_x[i] += double_to_int::convert(
m_drng() * bw_cur * lu_diff[i]);
138 tmp.
cur_x[i] -= double_to_int::convert(
m_drng() * bw_cur * lu_diff[i]);
141 if (tmp.
cur_x[i] > ub[i]) {
142 tmp.
cur_x[i] = lb[i] + double_to_int::convert(tmp.
cur_x[i] - ub[i]) %
static_cast<int>(lu_diff[i]);
143 }
else if (tmp.
cur_x[i] < lb[i]) {
144 tmp.
cur_x[i] = ub[i] - double_to_int::convert(lb[i] - tmp.
cur_x[i]) %
static_cast<int>(lu_diff[i]);
149 tmp.
cur_x[i] = boost::uniform_int<int>(lb[i],ub[i])(
m_urng);
153 pop.push_back(tmp.
cur_x);
157 pop.erase(worst_idx);
165 return "Improved Harmony Search";
174 std::ostringstream s;
175 s <<
"iter:" << m_gen <<
' ';
176 s <<
"phmcr:" << m_phmcr <<
' ';
177 s <<
"ppar_min:" << m_ppar_min <<
' ';
178 s <<
"ppar_max:" << m_ppar_max <<
' ';
179 s <<
"bw_min:" << m_bw_min <<
' ';
180 s <<
"bw_max:" << m_bw_max <<
' ';
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base algorithm.
std::vector< double > decision_vector
Decision vector type.
ihs(int gen=1, const double &phmcr=0.85, const double &ppar_min=0.35, const double &ppar_max=0.99, const double &bw_min=1E-5, const double &bw_max=1)
Constructor.
fitness_vector cur_f
Current fitness vector.
const individual_type & get_individual(const size_type &) const
Get constant reference to individual at position n.
void evolve(population &) const
Evolve method.
constraint_vector cur_c
Current constraint vector.
Individuals stored in the population.
size_type get_dimension() const
Return global dimension.
size_type get_i_dimension() const
Return integer dimension.
std::string human_readable_extra() const
Extra human readable algorithm info.
c_size_type get_c_dimension() const
Return global constraints dimension.
const decision_vector & get_ub() const
Upper bounds getter.
base_ptr clone() const
Clone method.
container_type::size_type size_type
Population size type.
decision_vector cur_x
Current decision vector.
std::string get_name() const
Algorithm name.
rng_uint32 m_urng
Random number generator for unsigned integer values.
f_size_type get_f_dimension() const
Return fitness dimension.
const decision_vector & get_lb() const
Lower bounds getter.
Improved harmony search algorithm.
rng_double m_drng
Random number generator for double-precision floating point values.
decision_vector::size_type size_type
Problem's size type: the same as pagmo::decision_vector's size type.