Skip to content

Commit

Permalink
making sure the champion is only updated if allocation is succesfull
Browse files Browse the repository at this point in the history
  • Loading branch information
darioizzo committed May 18, 2020
1 parent d15a0c6 commit 84a1975
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/population.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,20 +593,18 @@ void population::push_back_impl(T &&x, U &&f)
auto x_copy(std::forward<T>(x));
auto f_copy(std::forward<U>(f));

// update_champion() either throws before modfying anything, or it completes successfully. The rest is noexcept.
update_champion(x_copy, f_copy);
auto n = pop.size();
try {
m_ID.push_back(new_id);
m_x.push_back(std::move(x_copy));
m_f.push_back(std::move(f_copy));
} catch (...) {
auto n = m_ID.size();
n = std::min(n, m_x.size());
n = std::min(n, m_f.size());
m_ID.resize(n);
m_x.resize(n);
m_f.resize(n);
}
// update_champion() either throws before modfying anything, or it completes successfully. The rest is noexcept.
update_champion(pop.get_x(n+1), pop.get_f(n+1));
}

// Short routine to update the champion. Does nothing if the problem is MO
Expand Down

0 comments on commit 84a1975

Please sign in to comment.