Skip to content

Commit

Permalink
Merge pull request #454 from mlooz/master
Browse files Browse the repository at this point in the history
fix in unconstrain meta problem
  • Loading branch information
bluescarni authored Sep 24, 2020
2 parents de3d0b5 + f9340dc commit 28975a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/problems/unconstrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void unconstrain::generic_ctor_impl(const std::string &method, const vector_doub
// 3 - We throw if the method selected is not supported
if (method != "death penalty" && method != "kuri" && method != "weighted" && method != "ignore_c"
&& method != "ignore_o") {
pagmo_throw(std::invalid_argument, "The method " + method + " is not supported (did you mispell?)");
pagmo_throw(std::invalid_argument, "The method " + method + " is not supported (did you misspell?)");
}
// 4 - We throw if a non empty weight vector is passed but the method weghted is not selected
if (weights.size() != 0u && method != "weighted") {
Expand Down Expand Up @@ -167,7 +167,7 @@ vector_double unconstrain::fitness(const vector_double &x) const
}
}
for (decltype(nc) i = 0u; i < nc; ++i) {
if (c[i] > 0.) {
if (!(c[i] <= 0.)) {
penalty += m_weights[i] * c[i];
}
}
Expand Down
6 changes: 5 additions & 1 deletion tests/unconstrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ see https://www.gnu.org/licenses/. */

#include <boost/lexical_cast.hpp>
#include <boost/test/tools/floating_point_comparison.hpp>
#include <cmath>
#include <limits>
#include <stdexcept>
#include <string>
Expand Down Expand Up @@ -140,6 +141,9 @@ BOOST_AUTO_TEST_CASE(unconstrain_fitness_test)
BOOST_CHECK(p0.fitness(vector_double{0., 0., 1., 1., -1., 1.}) == vector_double(2, 3.));
BOOST_CHECK(p0.fitness(vector_double{0., 0., 1., 1., -1., -1.}) == vector_double(2, 2.));
BOOST_CHECK(p0.fitness(vector_double{0., 0., 0., 1., 0., 0.}) == vector_double(2, 1.));
vector_double nan_fitness = p0.fitness(vector_double{0., 0., std::numeric_limits<double>::quiet_NaN(), 1., -1., 1.});
BOOST_CHECK(std::isnan(nan_fitness[0]));
BOOST_CHECK(std::isnan(nan_fitness[1]));
}
{
unconstrain p0{my_udp{}, "ignore_c"};
Expand Down Expand Up @@ -294,4 +298,4 @@ BOOST_AUTO_TEST_CASE(unconstrain_thread_safety_test)
unconstrain t{p0};
BOOST_CHECK(t.get_thread_safety() == thread_safety::basic);
BOOST_CHECK((unconstrain{ts2{}}.get_thread_safety() == thread_safety::none));
}
}

0 comments on commit 28975a2

Please sign in to comment.