Skip to content

Commit

Permalink
Merge pull request #349 from Sceki/pso_gen_bug
Browse files Browse the repository at this point in the history
bug fix for PSO GEN
  • Loading branch information
darioizzo authored Sep 29, 2019
2 parents 41a2c1a + fd401d8 commit 448d92a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/algorithms/pso_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ population pso_gen::evolve(population pop) const
auto x2 = X[j];
double acc = 0.;
for (decltype(x1.size()) k = 0u; k < x1.size(); ++k) {
if (ub[j] > lb[j]) {
if (ub[k] > lb[k]) {
acc += (x1[k] - x2[k]) * (x1[k] - x2[k]) / (ub[k] - lb[k]) / (ub[k] - lb[k]);
} // else 0
}
Expand Down
9 changes: 9 additions & 0 deletions tests/pso_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,12 @@ BOOST_AUTO_TEST_CASE(serialization_test)
BOOST_CHECK_CLOSE(std::get<5>(before_log[i]), std::get<5>(after_log[i]), 1e-8);
}
}

BOOST_AUTO_TEST_CASE(bug)
{
problem prob{rosenbrock{10u}};
population pop1{prob, 11u, 23u};
pso_gen user_algo1{10u, 0.79, 2., 2., 0.1, 1u, 1u, 4u, false, 23u};
user_algo1.set_verbosity(1u);
pop1 = user_algo1.evolve(pop1);
}

0 comments on commit 448d92a

Please sign in to comment.