Skip to content
Open
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
3 changes: 1 addition & 2 deletions src/algorithms/compass_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,12 @@ population compass_search::evolve(population pop) const
vector_double cur_best_x(std::move(sel_xf.first)), cur_best_f(std::move(sel_xf.second));

// We need some auxiliary variables
bool flag = false;
unsigned fevals = 0u;

double newrange = m_start_range;

while (newrange > m_stop_range && fevals <= m_max_fevals) {
flag = false;
bool flag = false;
for (decltype(dim) i = 0u; i < dim; i++) {
auto x_trial = cur_best_x;
// move up
Expand Down
3 changes: 1 addition & 2 deletions src/algorithms/ihs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ population ihs::evolve(population pop) const

// Declarations
vector_double new_x(dim, 0.);
std::vector<vector_double::size_type> best_idxs(pop.size());

// Main loop
for (decltype(m_gen) gen = 1u; gen <= m_gen; ++gen) {
Expand Down Expand Up @@ -185,7 +184,7 @@ population ihs::evolve(population pop) const
// we augment the list with the new fitness
fitnesses.push_back(new_f);
// select the best pop.size() individuals
best_idxs = select_best_N_mo(fitnesses, pop.size());
const std::vector<vector_double::size_type> best_idxs = select_best_N_mo(fitnesses, pop.size());
// define the new population
for (population::size_type i = 0u; i < pop.size(); ++i) {
if (best_idxs[i] == pop.size()) { // this is the new guy
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/nsga2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ population nsga2::evolve(population pop) const
m_log.clear();

// Declarations
std::vector<vector_double::size_type> best_idx(NP), shuffle1(NP), shuffle2(NP);
std::vector<vector_double::size_type> shuffle1(NP), shuffle2(NP);
vector_double::size_type parent1_idx, parent2_idx;
std::pair<vector_double, vector_double> children;

Expand Down Expand Up @@ -296,7 +296,7 @@ population nsga2::evolve(population pop) const
}
// This method returns the sorted N best individuals in the population according to the crowded comparison
// operator
best_idx = select_best_N_mo(popnew.get_f(), NP);
const std::vector<vector_double::size_type> best_idx = select_best_N_mo(popnew.get_f(), NP);
// We insert into the population
for (population::size_type i = 0; i < NP; ++i) {
pop.set_xf(i, popnew.get_x()[best_idx[i]], popnew.get_f()[best_idx[i]]);
Expand Down
19 changes: 8 additions & 11 deletions src/algorithms/pso.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,6 @@ population pso::evolve(population pop) const
double acceleration_coefficient = m_eta1 + m_eta2;
double sum_forces;

double r1 = 0.;
double r2 = 0.;

/* --- Main PSO loop ---
*/
// For each generation
Expand All @@ -240,8 +237,8 @@ population pso::evolve(population pop) const
/*-------Original algorithm used in the first PaGMO paper (~2007) ------------------------*/
if (m_variant == 1u) {
for (decltype(dim) d = 0u; d < dim; ++d) {
r1 = drng(m_e);
r2 = drng(m_e);
const double r1 = drng(m_e);
const double r2 = drng(m_e);
m_V[p][d] = m_omega * m_V[p][d] + m_eta1 * r1 * (lbX[p][d] - X[p][d])
+ m_eta2 * r2 * (best_neighb[d] - X[p][d]);
}
Expand All @@ -252,7 +249,7 @@ population pso::evolve(population pop) const
/*-------Check with Rastrigin-------------------------------------------------------------*/
else if (m_variant == 2u) {
for (decltype(dim) d = 0u; d < dim; ++d) {
r1 = drng(m_e);
const double r1 = drng(m_e);
m_V[p][d] = m_omega * m_V[p][d] + m_eta1 * r1 * (lbX[p][d] - X[p][d])
+ m_eta2 * r1 * (best_neighb[d] - X[p][d]);
}
Expand All @@ -261,8 +258,8 @@ population pso::evolve(population pop) const
/*-------PSO variant (commonly mistaken in literature for the canonical)----------------*/
/*-------Same random number for all components------------------------------------------*/
else if (m_variant == 3u) {
r1 = drng(m_e);
r2 = drng(m_e);
const double r1 = drng(m_e);
const double r2 = drng(m_e);
for (decltype(dim) d = 0u; d < dim; ++d) {
m_V[p][d] = m_omega * m_V[p][d] + m_eta1 * r1 * (lbX[p][d] - X[p][d])
+ m_eta2 * r2 * (best_neighb[d] - X[p][d]);
Expand All @@ -273,7 +270,7 @@ population pso::evolve(population pop) const
/*-------Same random number for all components------------------------------------------*/
/*-------and with equal random weights of social and cognitive components---------------*/
else if (m_variant == 4u) {
r1 = drng(m_e);
const double r1 = drng(m_e);
for (decltype(dim) d = 0u; d < dim; ++d) {
m_V[p][d] = m_omega * m_V[p][d] + m_eta1 * r1 * (lbX[p][d] - X[p][d])
+ m_eta2 * r1 * (best_neighb[d] - X[p][d]);
Expand All @@ -295,8 +292,8 @@ population pso::evolve(population pop) const
*-------------------------------------------------------------------------------------*/
else if (m_variant == 5u) {
for (decltype(dim) d = 0u; d < dim; ++d) {
r1 = drng(m_e);
r2 = drng(m_e);
const double r1 = drng(m_e);
const double r2 = drng(m_e);
m_V[p][d] = m_omega
* (m_V[p][d] + m_eta1 * r1 * (lbX[p][d] - X[p][d])
+ m_eta2 * r2 * (best_neighb[d] - X[p][d]));
Expand Down
19 changes: 8 additions & 11 deletions src/algorithms/pso_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,6 @@ population pso_gen::evolve(population pop) const
double acceleration_coefficient = m_eta1 + m_eta2;
double sum_forces;

double r1 = 0.;
double r2 = 0.;

/* --- Main PSO loop ---
*/
// For each generation
Expand All @@ -242,8 +239,8 @@ population pso_gen::evolve(population pop) const
/*-------Original algorithm used in the first PaGMO paper (~2007) ------------------------*/
if (m_variant == 1u) {
for (decltype(dim) d = 0u; d < dim; ++d) {
r1 = drng(m_e);
r2 = drng(m_e);
const double r1 = drng(m_e);
const double r2 = drng(m_e);
m_V[p][d] = m_omega * m_V[p][d] + m_eta1 * r1 * (lbX[p][d] - X[p][d])
+ m_eta2 * r2 * (best_neighb[d] - X[p][d]);
}
Expand All @@ -254,7 +251,7 @@ population pso_gen::evolve(population pop) const
/*-------Check with Rastrigin-------------------------------------------------------------*/
else if (m_variant == 2u) {
for (decltype(dim) d = 0u; d < dim; ++d) {
r1 = drng(m_e);
const double r1 = drng(m_e);
m_V[p][d] = m_omega * m_V[p][d] + m_eta1 * r1 * (lbX[p][d] - X[p][d])
+ m_eta2 * r1 * (best_neighb[d] - X[p][d]);
}
Expand All @@ -263,8 +260,8 @@ population pso_gen::evolve(population pop) const
/*-------PSO variant (commonly mistaken in literature for the canonical)----------------*/
/*-------Same random number for all components------------------------------------------*/
else if (m_variant == 3u) {
r1 = drng(m_e);
r2 = drng(m_e);
const double r1 = drng(m_e);
const double r2 = drng(m_e);
for (decltype(dim) d = 0u; d < dim; ++d) {
m_V[p][d] = m_omega * m_V[p][d] + m_eta1 * r1 * (lbX[p][d] - X[p][d])
+ m_eta2 * r2 * (best_neighb[d] - X[p][d]);
Expand All @@ -275,7 +272,7 @@ population pso_gen::evolve(population pop) const
/*-------Same random number for all components------------------------------------------*/
/*-------and with equal random weights of social and cognitive components---------------*/
else if (m_variant == 4u) {
r1 = drng(m_e);
const double r1 = drng(m_e);
for (decltype(dim) d = 0u; d < dim; ++d) {
m_V[p][d] = m_omega * m_V[p][d] + m_eta1 * r1 * (lbX[p][d] - X[p][d])
+ m_eta2 * r1 * (best_neighb[d] - X[p][d]);
Expand All @@ -297,8 +294,8 @@ population pso_gen::evolve(population pop) const
*-------------------------------------------------------------------------------------*/
else if (m_variant == 5u) {
for (decltype(dim) d = 0u; d < dim; ++d) {
r1 = drng(m_e);
r2 = drng(m_e);
const double r1 = drng(m_e);
const double r2 = drng(m_e);
m_V[p][d] = m_omega
* (m_V[p][d] + m_eta1 * r1 * (lbX[p][d] - X[p][d])
+ m_eta2 * r2 * (best_neighb[d] - X[p][d]));
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/simulated_annealing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ population simulated_annealing::evolve(population pop) const

// Stores the number of accepted points for each component
std::vector<int> acp(dim, 0u);
double ratio = 0., currentT = m_Ts, probab = 0.;
double currentT = m_Ts;

// Main SA loops
for (decltype(m_n_T_adj) jter = 0u; jter < m_n_T_adj; ++jter) {
Expand Down Expand Up @@ -174,7 +174,7 @@ population simulated_annealing::evolve(population pop) const
}
} else {
// test it with Boltzmann to decide the acceptance
probab = std::exp(-std::abs(fOLD[0] - fNEW[0]) / currentT);
const double probab = std::exp(-std::abs(fOLD[0] - fNEW[0]) / currentT);
// we compare prob with a random probability.
if (probab > drng(m_e)) {
xOLD[nter] = xNEW[nter];
Expand Down Expand Up @@ -209,7 +209,7 @@ population simulated_annealing::evolve(population pop) const
} // end for(kter = 0; ...
// adjust the step (adaptively)
for (decltype(dim) iter = 0u; iter < dim; ++iter) {
ratio = static_cast<double>(acp[iter]) / static_cast<double>(m_bin_size);
const double ratio = static_cast<double>(acp[iter]) / static_cast<double>(m_bin_size);
acp[iter] = 0u; // reset the counter
if (ratio > .6) {
// too many acceptances, increase the step by a factor 3 maximum
Expand Down
7 changes: 2 additions & 5 deletions src/problems/cec2006.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,6 @@ void cec2006::g19_objfun_impl(vector_double &f, const vector_double &x) const
/// Implementation of the constraint function.
void cec2006::g19_compute_constraints_impl(vector_double &c, const vector_double &x) const
{
double sum1 = 0.;
double sum2 = 0.;

double A[10][5] = {{-16.0, 2.0, 0.0, 1.0, 0.0}, {0.0, -2.0, 0.0, 0.4, 2.0}, {-3.5, 0.0, 2.0, 0.0, 0.0},
{0.0, -2.0, 0.0, -4.0, -1.0}, {0.0, -9.0, -2.0, 1.0, -2.8}, {2.0, 0.0, -4.0, 0.0, 0.0},
{-1.0, -1.0, -1.0, -1.0, -1.0}, {-1.0, -2.0, -3.0, -2.0, -1.0}, {1.0, 2.0, 3.0, 4.0, 5.0},
Expand All @@ -937,10 +934,10 @@ void cec2006::g19_compute_constraints_impl(vector_double &c, const vector_double

/* constraints g <= 0 */
for (unsigned j = 0u; j < 5u; ++j) {
sum1 = 0.0;
double sum1 = 0.0;
for (unsigned i = 0u; i < 5u; ++i)
sum1 += C[i][j] * x[10 + i];
sum2 = 0.0;
double sum2 = 0.0;
for (unsigned i = 0u; i < 10u; ++i)
sum2 += A[i][j] * x[i];
c[j] = -((2.0 * sum1) + (3.0 * D[j] * std::pow(x[10 + j], 2.0)) + E[j] - sum2);
Expand Down
4 changes: 2 additions & 2 deletions src/problems/cec2013.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ void cec2013::weierstrass_func(const double *x, double *f, const unsigned nx, co
int r_flag) const /* Weierstrass's */
{
unsigned i, j, k_max;
double sum = 0, sum2 = 0, a, b;
double sum2 = 0, a, b;

shiftfunc(x, &m_y[0], nx, Os);
for (i = 0u; i < nx; ++i) // shrink to the original search range
Expand All @@ -529,7 +529,7 @@ void cec2013::weierstrass_func(const double *x, double *f, const unsigned nx, co
k_max = 20;
f[0] = 0.0;
for (i = 0u; i < nx; ++i) {
sum = 0.0;
double sum = 0.0;
sum2 = 0.0;
for (j = 0u; j <= k_max; ++j) {
sum += std::pow(a, j) * std::cos(2.0 * detail::pi() * std::pow(b, j) * (m_y[i] + 0.5));
Expand Down
Loading