Skip to content

Commit 4667ff5

Browse files
authored
Merge branch 'esa:master' into nsga3
2 parents ca66f44 + 1166e3e commit 4667ff5

File tree

4 files changed

+17
-31
lines changed

4 files changed

+17
-31
lines changed

.github/workflows/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ on:
77
branches:
88
- master
99
jobs:
10-
osx_10_15:
11-
runs-on: macos-10.15
10+
osx:
11+
runs-on: macos-latest
1212
steps:
1313
- uses: actions/checkout@v2
1414
- name: Build

src/problems/cec2013.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ see https://www.gnu.org/licenses/. */
3333
#include <string>
3434
#include <utility>
3535

36+
#include <boost/math/constants/constants.hpp>
37+
3638
#include <pagmo/detail/constants.hpp>
3739
#include <pagmo/exceptions.hpp>
3840
#include <pagmo/problem.hpp>
@@ -45,13 +47,6 @@ see https://www.gnu.org/licenses/. */
4547
namespace pagmo
4648
{
4749

48-
namespace
49-
{
50-
51-
constexpr double E = 2.7182818284590452353602874713526625;
52-
53-
}
54-
5550
cec2013::cec2013(unsigned prob_id, unsigned dim)
5651
: m_prob_id(prob_id), m_rotation_matrix(), m_origin_shift(), m_y(dim), m_z(dim)
5752
{
@@ -500,7 +495,7 @@ void cec2013::ackley_func(const double *x, double *f, const unsigned nx, const d
500495
}
501496
sum1 = -0.2 * std::sqrt(sum1 / nx);
502497
sum2 /= nx;
503-
f[0] = E - 20.0 * std::exp(sum1) - std::exp(sum2) + 20.0;
498+
f[0] = boost::math::constants::e<double>() - 20.0 * std::exp(sum1) - std::exp(sum2) + 20.0;
504499
}
505500

506501
void cec2013::weierstrass_func(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,

src/problems/cec2014.cpp

+12-19
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ see https://www.gnu.org/licenses/. */
2828

2929
#include <cmath>
3030
#include <cstdlib>
31+
#include <limits>
3132
#include <stdexcept>
3233
#include <string>
3334
#include <utility>
3435

36+
#include <boost/math/constants/constants.hpp>
37+
3538
#include <pagmo/exceptions.hpp>
3639
#include <pagmo/problem.hpp>
3740
#include <pagmo/problems/cec2014.hpp>
@@ -43,16 +46,6 @@ see https://www.gnu.org/licenses/. */
4346
namespace pagmo
4447
{
4548

46-
namespace
47-
{
48-
49-
// "Research code", ladies and gentlemen!
50-
constexpr double INF = 1.0e99;
51-
constexpr double E = 2.7182818284590452353602874713526625;
52-
constexpr double PI = 3.1415926535897932384626433832795029;
53-
54-
} // namespace
55-
5649
cec2014::cec2014(unsigned prob_id, unsigned dim) : m_z(dim), m_y(dim), func_num(prob_id)
5750
{
5851
if (!(dim == 2u || dim == 10u || dim == 20u || dim == 30u || dim == 50u || dim == 100u)) {
@@ -482,11 +475,11 @@ void cec2014::ackley_func(const double *x, double *f, const unsigned nx, const d
482475

483476
for (i = 0; i < nx; i++) {
484477
sum1 += m_z[i] * m_z[i];
485-
sum2 += std::cos(2.0 * PI * m_z[i]);
478+
sum2 += std::cos(2.0 * boost::math::constants::pi<double>() * m_z[i]);
486479
}
487480
sum1 = -0.2 * std::sqrt(sum1 / nx);
488481
sum2 /= nx;
489-
f[0] = E - 20.0 * std::exp(sum1) - std::exp(sum2) + 20.0;
482+
f[0] = boost::math::constants::e<double>() - 20.0 * std::exp(sum1) - std::exp(sum2) + 20.0;
490483
}
491484

492485
/* Weierstrass's */
@@ -508,8 +501,8 @@ void cec2014::weierstrass_func(const double *x, double *f, const unsigned nx, co
508501
sum = 0.0;
509502
sum2 = 0.0;
510503
for (j = 0; j <= k_max; j++) {
511-
sum += std::pow(a, j) * std::cos(2.0 * PI * std::pow(b, j) * (m_z[i] + 0.5));
512-
sum2 += std::pow(a, j) * std::cos(2.0 * PI * std::pow(b, j) * 0.5);
504+
sum += std::pow(a, j) * std::cos(2.0 * boost::math::constants::pi<double>() * std::pow(b, j) * (m_z[i] + 0.5));
505+
sum2 += std::pow(a, j) * std::cos(2.0 * boost::math::constants::pi<double>() * std::pow(b, j) * 0.5);
513506
}
514507
f[0] += sum;
515508
}
@@ -546,7 +539,7 @@ void cec2014::rastrigin_func(const double *x, double *f, const unsigned nx, cons
546539
sr_func(x, m_z.data(), nx, Os, Mr, 5.12 / 100.0, s_flag, r_flag); /* shift and rotate */
547540

548541
for (i = 0; i < nx; i++) {
549-
f[0] += (m_z[i] * m_z[i] - 10.0 * std::cos(2.0 * PI * m_z[i]) + 10.0);
542+
f[0] += (m_z[i] * m_z[i] - 10.0 * std::cos(2.0 * boost::math::constants::pi<double>() * m_z[i]) + 10.0);
550543
}
551544
}
552545

@@ -564,7 +557,7 @@ void cec2014::step_rastrigin_func(const double *x, double *f, const unsigned nx,
564557
sr_func(x, m_z.data(), nx, Os, Mr, 5.12 / 100.0, s_flag, r_flag); /* shift and rotate */
565558

566559
for (i = 0; i < nx; i++) {
567-
f[0] += (m_z[i] * m_z[i] - 10.0 * std::cos(2.0 * PI * m_z[i]) + 10.0);
560+
f[0] += (m_z[i] * m_z[i] - 10.0 * std::cos(2.0 * boost::math::constants::pi<double>() * m_z[i]) + 10.0);
568561
}
569562
}
570563

@@ -672,7 +665,7 @@ void cec2014::bi_rastrigin_func(const double *x, double *f, const unsigned nx, c
672665
if (r_flag == 1) {
673666
rotatefunc(m_z.data(), m_y.data(), nx, Mr);
674667
for (i = 0; i < nx; i++) {
675-
tmp += std::cos(2.0 * PI * m_y[i]);
668+
tmp += std::cos(2.0 * boost::math::constants::pi<double>() * m_y[i]);
676669
}
677670
if (tmp1 < tmp2) {
678671
f[0] = tmp1;
@@ -682,7 +675,7 @@ void cec2014::bi_rastrigin_func(const double *x, double *f, const unsigned nx, c
682675
f[0] += 10.0 * (nx - tmp);
683676
} else {
684677
for (i = 0; i < nx; i++) {
685-
tmp += std::cos(2.0 * PI * m_z[i]);
678+
tmp += std::cos(2.0 * boost::math::constants::pi<double>() * m_z[i]);
686679
}
687680
if (tmp1 < tmp2) {
688681
f[0] = tmp1;
@@ -1340,7 +1333,7 @@ void cec2014::cf_cal(const double *x, double *f, const unsigned nx, const double
13401333
if (w[i] != 0)
13411334
w[i] = std::pow(1.0 / w[i], 0.5) * std::exp(-w[i] / 2.0 / nx / std::pow(delta[i], 2.0));
13421335
else
1343-
w[i] = INF;
1336+
w[i] = std::numeric_limits<double>::max();
13441337
if (w[i] > w_max) w_max = w[i];
13451338
}
13461339

src/problems/wfg.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -916,10 +916,8 @@ vector_double wfg::wfg8_fitness(const vector_double &x) const
916916
for (decltype(m_dim_k) i = m_dim_k; i < m_dim_dvs; ++i) {
917917
vector_double first_input(i);
918918
vector_double weights(i, 1.0);
919-
decltype(m_dim_obj) index = 0u;
920919
for (decltype(i) j = 0u; j < i; ++j) {
921920
first_input[j] = y[j];
922-
++index;
923921
}
924922
t_1[i] = b_param(x_norm[i], r_sum(first_input, weights), 0.98 / 49.98, 0.02, 50);
925923
y[i] = t_1[i];

0 commit comments

Comments
 (0)