Skip to content

Commit

Permalink
Merge pull request #576 from Sceki/maco_gaco_bugfix
Browse files Browse the repository at this point in the history
bug fix
  • Loading branch information
bluescarni authored Jul 29, 2024
2 parents 5dc2e88 + 4ef7aa7 commit 3ef36a1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/algorithms/gaco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,9 +851,16 @@ void gaco::generate_new_ants(const population &pop, std::uniform_real_distributi
g_h = sol_archive[k_omega][1 + h] + sigma[h] * gauss_pdf(m_e);

if (g_h < lb[h] || g_h > ub[h]) {

while ((g_h < lb[h] || g_h > ub[h])) {
int iter_while=0;
while ((g_h < lb[h] || g_h > ub[h]) && iter_while < 10) {
g_h = sol_archive[k_omega][1 + h] + sigma[h] * gauss_pdf(m_e);
++iter_while;
}
if (g_h < lb[h]) {
g_h = lb[h];
}
if (g_h > ub[h]) {
g_h = ub[h];
}
}
if (h >= n_con) {
Expand Down
11 changes: 9 additions & 2 deletions src/algorithms/maco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,9 +727,16 @@ void maco::generate_new_ants(const population &pop, std::uniform_real_distributi
g_h = sol_archive[k_omega][h] + sigma[h] * gauss_pdf(m_e);

if (g_h < lb[h] || g_h > ub[h]) {

while ((g_h < lb[h] || g_h > ub[h])) {
int iter_while=0;
while ((g_h < lb[h] || g_h > ub[h]) && iter_while < 10) {
g_h = sol_archive[k_omega][h] + sigma[h] * gauss_pdf(m_e);
++iter_while;
}
if (g_h < lb[h]){
g_h = lb[h];
}
if (g_h > ub[h]){
g_h = ub[h];
}
}
if (h >= n_con) {
Expand Down
11 changes: 11 additions & 0 deletions tests/gaco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,14 @@ BOOST_AUTO_TEST_CASE(bfe_usage_test)

BOOST_CHECK_EQUAL(pop.champion_f()[0], pop_2.champion_f()[0]);
}

BOOST_AUTO_TEST_CASE(out_of_bounds_test)
{
population pop{rosenbrock{}, 10u, 23u};
pop.set_x(0, {-20., 12});//both out of bounds
gaco uda{10u, 10u, 1.0, 25.0, 0.01, 5u, 7u, 1000u, 1000u, 0.0, false, 23u};
uda.set_verbosity(1u);
uda.set_seed(23u);
pop = uda.evolve(pop);
}

12 changes: 12 additions & 0 deletions tests/maco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,15 @@ BOOST_AUTO_TEST_CASE(memory_test)
pop_2 = uda_2.evolve(pop_2);
BOOST_CHECK(pop_1.get_f() == pop_2.get_f());
}

BOOST_AUTO_TEST_CASE(out_of_bounds_test)
{
problem prob{dtlz(1, 5, 2)};
population pop{prob, 43};

pop.set_x(0, {-2., 2., -2., 2., -2.});//both out of bounds
maco uda{1u, 20u, 1.0, 8u, 7u, 10000u, 0., true, 23u};
uda.set_seed(23u);
pop = uda.evolve(pop);
}

0 comments on commit 3ef36a1

Please sign in to comment.