Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/algorithms/cmaes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,22 @@ cmaes::cmaes(unsigned gen, double cc, double cs, double c1, double cmu, double s
: m_gen(gen), m_cc(cc), m_cs(cs), m_c1(c1), m_cmu(cmu), m_sigma0(sigma0), m_ftol(ftol), m_xtol(xtol),
m_memory(memory), m_force_bounds(force_bounds), m_e(seed), m_seed(seed), m_verbosity(0u)
{
if (((cc < 0.) || (cc > 1.)) && !(cc == -1)) {
if ((!(cc >= 0.) || !(cc <= 1.)) && !(cc == -1)) {
pagmo_throw(std::invalid_argument,
"cc must be in [0,1] or -1 if its value has to be initialized automatically, a value of "
+ std::to_string(cc) + " was detected");
}
if (((cs < 0.) || (cs > 1.)) && !(cs == -1)) {
if ((!(cs >= 0.) || !(cs <= 1.)) && !(cs == -1)) {
pagmo_throw(std::invalid_argument,
"cs needs to be in [0,1] or -1 if its value has to be initialized automatically, a value of "
+ std::to_string(cs) + " was detected");
}
if (((c1 < 0.) || (c1 > 1.)) && !(c1 == -1)) {
if ((!(c1 >= 0.) || !(c1 <= 1.)) && !(c1 == -1)) {
pagmo_throw(std::invalid_argument,
"c1 needs to be in [0,1] or -1 if its value has to be initialized automatically, a value of "
+ std::to_string(c1) + " was detected");
}
if (((cmu < 0.) || (cmu > 1.)) && !(cmu == -1)) {
if ((!(cmu >= 0.) || !(cmu <= 1.)) && !(cmu == -1)) {
pagmo_throw(std::invalid_argument,
"cmu needs to be in [0,1] or -1 if its value has to be initialized automatically, a value of "
+ std::to_string(cmu) + " was detected");
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/de.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ de::de(unsigned gen, double F, double CR, unsigned variant, double ftol, double
"The Differential Evolution variant must be in [1, .., 10], while a value of "
+ std::to_string(variant) + " was detected.");
}
if (CR < 0. || F < 0. || CR > 1. || F > 1.) {
if (!(CR >= 0.) || !(CR <= 1.) || !(F >= 0.) || !(F <= 1.)) {
pagmo_throw(std::invalid_argument, "The F and CR parameters must be in the [0,1] range");
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/gaco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ gaco::gaco(unsigned gen, unsigned ker, double q, double oracle, double acc, unsi
m_n_gen_mark(n_gen_mark), m_memory(memory), m_counter(0u), m_sol_archive(), m_n_evalstop(1u), m_n_impstop(1u),
m_gen_mark(1u), m_fevals(0u)
{
if (acc < 0.) {
if (!(acc >= 0.)) {
pagmo_throw(std::invalid_argument,
"The accuracy parameter must be >=0, while a value of " + std::to_string(acc) + " was detected");
}
if (focus < 0.) {
if (!(focus >= 0.)) {
pagmo_throw(std::invalid_argument,
"The focus parameter must be >=0 while a value of " + std::to_string(focus) + " was detected");
}
Expand All @@ -81,7 +81,7 @@ gaco::gaco(unsigned gen, unsigned ker, double q, double oracle, double acc, unsi
pagmo_throw(std::invalid_argument, "If memory is active, the threshold parameter must be >=1 while a value of "
+ std::to_string(threshold) + " was detected");
}
if (q < 0.) {
if (!(q >= 0.)) {
pagmo_throw(std::invalid_argument, "The convergence speed parameter must be >=0 while a value of "
+ std::to_string(q) + " was detected");
}
Expand Down
7 changes: 4 additions & 3 deletions src/algorithms/ihs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ ihs::ihs(unsigned gen, double phmcr, double ppar_min, double ppar_max, double bw
: m_gen(gen), m_phmcr(phmcr), m_ppar_min(ppar_min), m_ppar_max(ppar_max), m_bw_min(bw_min), m_bw_max(bw_max),
m_e(seed), m_seed(seed), m_verbosity(0u)
{
if (phmcr > 1 || phmcr < 0 || ppar_min > 1 || ppar_min < 0 || ppar_max > 1 || ppar_max < 0) {
if (!(phmcr >= 0.) || !(phmcr <= 1.) || !(ppar_min >= 0.) || !(ppar_min <= 1.) || !(ppar_max >= 0.)
|| !(ppar_max <= 1.)) {
pagmo_throw(std::invalid_argument, "The probability of choosing from memory (phmcr) and the pitch "
"adjustment rates (ppar_min, ppar_max) must all be in the [0,1] range");
}
if (ppar_min > ppar_max) {
if (!(ppar_min <= ppar_max)) {
pagmo_throw(std::invalid_argument,
"The minimum pitch adjustment rate must not be greater than maximum pitch adjustment rate");
}
if (bw_min <= 0 || bw_max < bw_min) {
if (!(bw_min > 0.) || !(bw_max >= bw_min)) {
pagmo_throw(std::invalid_argument, "The bandwidth values must be positive, and minimum bandwidth must not "
"be greater than maximum bandwidth");
}
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/maco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ maco::maco(unsigned gen, unsigned ker, double q, unsigned threshold, unsigned n_
m_threshold(threshold), m_q(q), m_n_gen_mark(n_gen_mark), m_memory(memory), m_counter(0u), m_sol_archive(),
m_n_evalstop(0u), m_gen_mark(1u), m_pop()
{
if (focus < 0.) {
if (!(focus >= 0.)) {
pagmo_throw(std::invalid_argument,
"The focus parameter must be >=0 while a value of " + std::to_string(focus) + " was detected");
}
Expand Down
8 changes: 4 additions & 4 deletions src/algorithms/moead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,24 @@ moead::moead(unsigned gen, std::string weight_generation, std::string decomposit
pagmo_throw(std::invalid_argument, "Weight generation method requested is '" + m_decomposition
+ "', but only one of 'tchebycheff', 'weighted', 'bi' is allowed");
}
if (CR > 1.0 || CR < 0.) {
if (!(CR >= 0.) || !(CR <= 1.)) {
pagmo_throw(
std::invalid_argument,
"The parameter CR (used by the differential evolution operator) needs to be in [0,1], while a value of "
+ std::to_string(CR) + " was detected");
}
if (F > 1.0 || F < 0.) {
if (!(F >= 0.) || !(F <= 1.)) {
pagmo_throw(
std::invalid_argument,
"The parameter F (used by the differential evolution operator) needs to be in [0,1], while a value of "
+ std::to_string(F) + " was detected");
}
if (eta_m < 0.) {
if (!(eta_m >= 0.)) {
pagmo_throw(std::invalid_argument,
"The distribution index for the polynomial mutation (eta_m) needs to be positive, while a value of "
+ std::to_string(eta_m) + " was detected");
}
if (realb > 1.0 || realb < 0.) {
if (!(realb >= 0.) || !(realb <= 1.)) {
pagmo_throw(std::invalid_argument,
"The chance of considering a neighbourhood (realb) needs to be in [0,1], while a value of "
+ std::to_string(realb) + " was detected");
Expand Down
8 changes: 4 additions & 4 deletions src/algorithms/moead_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,24 @@ moead_gen::moead_gen(unsigned gen, std::string weight_generation, std::string de
pagmo_throw(std::invalid_argument, "Weight generation method requested is '" + m_decomposition
+ "', but only one of 'tchebycheff', 'weighted', 'bi' is allowed");
}
if (CR > 1.0 || CR < 0.) {
if (!(CR >= 0.) || !(CR <= 1.)) {
pagmo_throw(
std::invalid_argument,
"The parameter CR (used by the differential evolution operator) needs to be in [0,1], while a value of "
+ std::to_string(CR) + " was detected");
}
if (F > 1.0 || F < 0.) {
if (!(F >= 0.) || !(F <= 1.)) {
pagmo_throw(
std::invalid_argument,
"The parameter F (used by the differential evolution operator) needs to be in [0,1], while a value of "
+ std::to_string(F) + " was detected");
}
if (eta_m < 0.) {
if (!(eta_m >= 0.)) {
pagmo_throw(std::invalid_argument,
"The distribution index for the polynomial mutation (eta_m) needs to be positive, while a value of "
+ std::to_string(eta_m) + " was detected");
}
if (realb > 1.0 || realb < 0.) {
if (!(realb >= 0.) || !(realb <= 1.)) {
pagmo_throw(std::invalid_argument,
"The chance of considering a neighbourhood (realb) needs to be in [0,1], while a value of "
+ std::to_string(realb) + " was detected");
Expand Down
8 changes: 4 additions & 4 deletions src/algorithms/nsga2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ namespace pagmo
nsga2::nsga2(unsigned gen, double cr, double eta_c, double m, double eta_m, unsigned seed)
: m_gen(gen), m_cr(cr), m_eta_c(eta_c), m_m(m), m_eta_m(eta_m), m_e(seed), m_seed(seed), m_verbosity(0u)
{
if (cr >= 1. || cr < 0.) {
if (!(cr >= 0.) || !(cr < 1.)) {
pagmo_throw(std::invalid_argument, "The crossover probability must be in the [0,1[ range, while a value of "
+ std::to_string(cr) + " was detected");
}
if (m < 0. || m > 1.) {
if (!(m >= 0.) || !(m <= 1.)) {
pagmo_throw(std::invalid_argument, "The mutation probability must be in the [0,1] range, while a value of "
+ std::to_string(cr) + " was detected");
}
if (eta_c < 1. || eta_c > 100.) {
if (!(eta_c >= 1.) || !(eta_c <= 100.)) {
pagmo_throw(std::invalid_argument, "The distribution index for crossover must be in [1, 100], while a value of "
+ std::to_string(eta_c) + " was detected");
}
if (eta_m < 1. || eta_m > 100.) {
if (!(eta_m >= 1.) || !(eta_m <= 100.)) {
pagmo_throw(std::invalid_argument, "The distribution index for mutation must be in [1, 100], while a value of "
+ std::to_string(eta_m) + " was detected");
}
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/nspso.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ nspso::nspso(unsigned gen, double omega, double c1, double c2, double chi, doubl
m_leader_selection_range(leader_selection_range), m_diversity_mechanism(diversity_mechanism), m_memory(memory),
m_velocity(), m_e(seed), m_seed(seed), m_verbosity(0u)
{
if (omega < 0. || omega > 1.) {
if (!(omega >= 0.) || !(omega <= 1.)) {
pagmo_throw(std::invalid_argument, "The particles' inertia weight must be in the [0,1] range, while a value of "
+ std::to_string(m_omega) + " was detected");
}
if (c1 <= 0 || c2 <= 0 || chi <= 0) {
if (!(c1 > 0.) || !(c2 > 0.) || !(chi > 0.)) {
pagmo_throw(std::invalid_argument, "first and second magnitude of the force "
"coefficients and velocity scaling factor should be greater than 0");
}
if (v_coeff <= 0 || v_coeff > 1) {
if (!(v_coeff > 0.) || !(v_coeff <= 1.)) {
pagmo_throw(std::invalid_argument, "velocity scaling factor should be in ]0,1] range, while a value of"
+ std::to_string(v_coeff) + " was detected");
}
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/pso.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,18 @@ pso::pso(unsigned gen, double omega, double eta1, double eta2, double max_vel, u
m_neighb_type(neighb_type), m_neighb_param(neighb_param), m_memory(memory), m_e(seed), m_seed(seed),
m_verbosity(0u), m_log()
{
if (m_omega < 0. || m_omega > 1.) {
if (!(m_omega >= 0.) || !(m_omega <= 1.)) {
// variants using Inertia weight
pagmo_throw(std::invalid_argument,
"The particles' inertia (or the constriction factor) must be in the [0,1] range, while a value of "
+ std::to_string(m_omega) + " was detected");
}
if (m_eta1 < 0. || m_eta2 < 0. || m_eta1 > 4. || m_eta2 > 4.) {
if (!(m_eta1 >= 0.) || !(m_eta2 >= 0.) || !(m_eta1 <= 4.) || !(m_eta2 <= 4.)) {
pagmo_throw(std::invalid_argument,
"The eta parameters must be in the [0,4] range, while eta1 = " + std::to_string(m_eta1)
+ ", eta2 = " + std::to_string(m_eta2) + " was detected");
}
if (m_max_vel <= 0. || m_max_vel > 1.) {
if (!(m_max_vel > 0.) || !(m_max_vel <= 1.)) {
pagmo_throw(std::invalid_argument, "The maximum particle velocity (as a fraction of the bounds) should be "
"in the (0,1] range, while a value of "
+ std::to_string(m_max_vel) + " was detected");
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/pso_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ pso_gen::pso_gen(unsigned gen, double omega, double eta1, double eta2, double ma
m_neighb_type(neighb_type), m_neighb_param(neighb_param), m_memory(memory), m_e(seed), m_seed(seed),
m_verbosity(0u), m_log()
{
if (m_omega < 0. || m_omega > 1.) {
if (!(m_omega >= 0.) || !(m_omega <= 1.)) {
// variants using Inertia weight
pagmo_throw(std::invalid_argument,
"The particles' inertia (or the constriction factor) must be in the [0,1] range, while a value of "
+ std::to_string(m_variant) + " was detected");
}
if (m_eta1 < 0. || m_eta2 < 0. || m_eta1 > 4. || m_eta2 > 4.) {
if (!(m_eta1 >= 0.) || !(m_eta2 >= 0.) || !(m_eta1 <= 4.) || !(m_eta2 <= 4.)) {
pagmo_throw(std::invalid_argument,
"The eta parameters must be in the [0,4] range, while eta1 = " + std::to_string(m_eta1)
+ ", eta2 = " + std::to_string(m_eta2) + " was detected");
}
if (m_max_vel <= 0. || m_max_vel > 1.) {
if (!(m_max_vel > 0.) || !(m_max_vel <= 1.)) {
pagmo_throw(std::invalid_argument, "The maximum particle velocity (as a fraction of the bounds) should be "
"in the (0,1] range, while a value of "
+ std::to_string(m_max_vel) + " was detected");
Expand Down
10 changes: 5 additions & 5 deletions src/algorithms/sga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,16 @@ sga::sga(unsigned gen, double cr, double eta_c, double m, double param_m, unsign
: m_gen(gen), m_cr(cr), m_eta_c(eta_c), m_m(m), m_param_m(param_m), m_param_s(param_s), m_e(seed), m_seed(seed),
m_verbosity(0u), m_log()
{
if (cr > 1. || cr < 0.) {
if (!(cr >= 0.) || !(cr <= 1.)) {
pagmo_throw(std::invalid_argument, "The crossover probability must be in the [0,1] range, while a value of "
+ std::to_string(cr) + " was detected");
}
if (eta_c < 1. || eta_c > 100.) {
if (!(eta_c >= 1.) || !(eta_c <= 100.)) {
pagmo_throw(std::invalid_argument,
"The distribution index for SBX crossover must be in [1, 100], while a value of "
+ std::to_string(eta_c) + " was detected");
}
if (m < 0. || m > 1.) {
if (!(m >= 0.) || !(m <= 1.)) {
pagmo_throw(std::invalid_argument, "The mutation probability must be in the [0,1] range, while a value of "
+ std::to_string(cr) + " was detected");
}
Expand All @@ -154,14 +154,14 @@ sga::sga(unsigned gen, double cr, double eta_c, double m, double param_m, unsign
+ crossover);
}
// param_m represents the distribution index if polynomial mutation is selected
if (mutation == "polynomial" && (param_m < 1. || param_m > 100.)) {
if (mutation == "polynomial" && (!(param_m >= 1.) || !(param_m <= 100.))) {
pagmo_throw(std::invalid_argument, "Polynomial mutation was selected, the mutation parameter (distribution "
"index) must be in [1, 100], while a value of "
+ std::to_string(param_m) + " was detected");
}

// otherwise param_m represents the width of the mutation relative to the box bounds
if (mutation != "polynomial" && (param_m < 0 || param_m > 1.)) {
if (mutation != "polynomial" && (!(param_m >= 0.) || !(param_m <= 1.))) {
pagmo_throw(std::invalid_argument, "The mutation parameter must be in [0,1], while a value of "
+ std::to_string(param_m) + " was detected");
}
Expand Down
8 changes: 4 additions & 4 deletions src/algorithms/xnes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,22 @@ xnes::xnes(unsigned gen, double eta_mu, double eta_sigma, double eta_b, double s
: m_gen(gen), m_eta_mu(eta_mu), m_eta_sigma(eta_sigma), m_eta_b(eta_b), m_sigma0(sigma0), m_ftol(ftol),
m_xtol(xtol), m_memory(memory), m_force_bounds(force_bounds), m_e(seed), m_seed(seed), m_verbosity(0u), m_log()
{
if (((eta_mu <= 0.) || (eta_mu > 1.)) && !(eta_mu == -1)) {
if ((!(eta_mu > 0.) || !(eta_mu <= 1.)) && !(eta_mu == -1)) {
pagmo_throw(std::invalid_argument,
"eta_mu must be in ]0,1] or -1 if its value has to be initialized automatically, a value of "
+ std::to_string(eta_mu) + " was detected");
}
if (((eta_sigma <= 0.) || (eta_sigma > 1.)) && !(eta_sigma == -1)) {
if ((!(eta_sigma > 0.) || !(eta_sigma <= 1.)) && !(eta_sigma == -1)) {
pagmo_throw(std::invalid_argument,
"eta_sigma needs to be in ]0,1] or -1 if its value has to be initialized automatically, a value of "
+ std::to_string(eta_sigma) + " was detected");
}
if (((eta_b <= 0.) || (eta_b > 1.)) && !(eta_b == -1)) {
if ((!(eta_b > 0.) || !(eta_b <= 1.)) && !(eta_b == -1)) {
pagmo_throw(std::invalid_argument,
"eta_b needs to be in ]0,1] or -1 if its value has to be initialized automatically, a value of "
+ std::to_string(eta_b) + " was detected");
}
if (((sigma0 <= 0.) || (sigma0 > 1.)) && !(sigma0 == -1)) {
if ((!(sigma0 > 0.) || !(sigma0 <= 1.)) && !(sigma0 == -1)) {
pagmo_throw(std::invalid_argument,
"sigma0 needs to be in ]0,1] or -1 if its value has to be initialized automatically, a value of "
+ std::to_string(sigma0) + " was detected");
Expand Down
5 changes: 5 additions & 0 deletions tests/cmaes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ BOOST_AUTO_TEST_CASE(cmaes_algorithm_construction)
BOOST_CHECK_THROW((cmaes{10u, -1, -1, -1.2, -1, 0.5, 1e-6, 1e-6, false, false, 23u}), std::invalid_argument);
BOOST_CHECK_THROW((cmaes{10u, -1, -1, -1, -1.2, 0.5, 1e-6, 1e-6, false, false, 23u}), std::invalid_argument);
BOOST_CHECK_THROW((cmaes{10u, -1, -1, -1, -1.2, 0.5, 1e-6, 1e-6, false, false, 23u}), std::invalid_argument);
const auto nan = std::numeric_limits<double>::quiet_NaN();
BOOST_CHECK_THROW((cmaes{10u, nan, -1, -1, -1, 0.5, 1e-6, 1e-6, false, false, 23u}), std::invalid_argument);
BOOST_CHECK_THROW((cmaes{10u, -1, nan, -1, -1, 0.5, 1e-6, 1e-6, false, false, 23u}), std::invalid_argument);
BOOST_CHECK_THROW((cmaes{10u, -1, -1, nan, -1, 0.5, 1e-6, 1e-6, false, false, 23u}), std::invalid_argument);
BOOST_CHECK_THROW((cmaes{10u, -1, -1, -1, nan, 0.5, 1e-6, 1e-6, false, false, 23u}), std::invalid_argument);
}

struct unbounded_lb {
Expand Down
5 changes: 5 additions & 0 deletions tests/de.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ see https://www.gnu.org/licenses/. */
#include <boost/test/unit_test.hpp>

#include <iostream>
#include <limits>
#include <string>

#include <boost/lexical_cast.hpp>
Expand Down Expand Up @@ -64,6 +65,10 @@ BOOST_AUTO_TEST_CASE(de_algorithm_construction)

BOOST_CHECK_THROW((de{1234u, 0.7, 1.5, 2u, 1e-6, 1e-6, 23u}), std::invalid_argument);
BOOST_CHECK_THROW((de{1234u, 0.7, -0.5, 2u, 1e-6, 1e-6, 23u}), std::invalid_argument);

const auto nan = std::numeric_limits<double>::quiet_NaN();
BOOST_CHECK_THROW((de{1234u, nan, 0.5, 2u, 1e-6, 1e-6, 23u}), std::invalid_argument);
BOOST_CHECK_THROW((de{1234u, 0.7, nan, 2u, 1e-6, 1e-6, 23u}), std::invalid_argument);
}

BOOST_AUTO_TEST_CASE(de_evolve_test)
Expand Down
Loading
Loading