@@ -28,10 +28,13 @@ see https://www.gnu.org/licenses/. */
28
28
29
29
#include < cmath>
30
30
#include < cstdlib>
31
+ #include < limits>
31
32
#include < stdexcept>
32
33
#include < string>
33
34
#include < utility>
34
35
36
+ #include < boost/math/constants/constants.hpp>
37
+
35
38
#include < pagmo/exceptions.hpp>
36
39
#include < pagmo/problem.hpp>
37
40
#include < pagmo/problems/cec2014.hpp>
@@ -43,16 +46,6 @@ see https://www.gnu.org/licenses/. */
43
46
namespace pagmo
44
47
{
45
48
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
-
56
49
cec2014::cec2014 (unsigned prob_id, unsigned dim) : m_z(dim), m_y(dim), func_num(prob_id)
57
50
{
58
51
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
482
475
483
476
for (i = 0 ; i < nx; i++) {
484
477
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]);
486
479
}
487
480
sum1 = -0.2 * std::sqrt (sum1 / nx);
488
481
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 ;
490
483
}
491
484
492
485
/* Weierstrass's */
@@ -508,8 +501,8 @@ void cec2014::weierstrass_func(const double *x, double *f, const unsigned nx, co
508
501
sum = 0.0 ;
509
502
sum2 = 0.0 ;
510
503
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 );
513
506
}
514
507
f[0 ] += sum;
515
508
}
@@ -546,7 +539,7 @@ void cec2014::rastrigin_func(const double *x, double *f, const unsigned nx, cons
546
539
sr_func (x, m_z.data (), nx, Os, Mr, 5.12 / 100.0 , s_flag, r_flag); /* shift and rotate */
547
540
548
541
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 );
550
543
}
551
544
}
552
545
@@ -564,7 +557,7 @@ void cec2014::step_rastrigin_func(const double *x, double *f, const unsigned nx,
564
557
sr_func (x, m_z.data (), nx, Os, Mr, 5.12 / 100.0 , s_flag, r_flag); /* shift and rotate */
565
558
566
559
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 );
568
561
}
569
562
}
570
563
@@ -672,7 +665,7 @@ void cec2014::bi_rastrigin_func(const double *x, double *f, const unsigned nx, c
672
665
if (r_flag == 1 ) {
673
666
rotatefunc (m_z.data (), m_y.data (), nx, Mr);
674
667
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]);
676
669
}
677
670
if (tmp1 < tmp2) {
678
671
f[0 ] = tmp1;
@@ -682,7 +675,7 @@ void cec2014::bi_rastrigin_func(const double *x, double *f, const unsigned nx, c
682
675
f[0 ] += 10.0 * (nx - tmp);
683
676
} else {
684
677
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]);
686
679
}
687
680
if (tmp1 < tmp2) {
688
681
f[0 ] = tmp1;
@@ -1340,7 +1333,7 @@ void cec2014::cf_cal(const double *x, double *f, const unsigned nx, const double
1340
1333
if (w[i] != 0 )
1341
1334
w[i] = std::pow (1.0 / w[i], 0.5 ) * std::exp (-w[i] / 2.0 / nx / std::pow (delta[i], 2.0 ));
1342
1335
else
1343
- w[i] = INF ;
1336
+ w[i] = std::numeric_limits< double >:: max () ;
1344
1337
if (w[i] > w_max) w_max = w[i];
1345
1338
}
1346
1339
0 commit comments