Skip to content

Commit

Permalink
use custom struct for CandidatePair instead of std::pair
Browse files Browse the repository at this point in the history
  • Loading branch information
KRM7 committed Sep 1, 2024
1 parent fa572a3 commit 7937be5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/core/candidate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ namespace gapp

/** A pair of candidates. */
template<typename T>
using CandidatePair = std::pair<Candidate<T>, Candidate<T>>;
struct CandidatePair
{
Candidate<T> first;
Candidate<T> second;
};


/**
Expand Down
6 changes: 3 additions & 3 deletions src/core/ga_base.impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,9 @@ namespace gapp
prepareSelections();
detail::parallel_for(detail::iota_iterator(0_sz), detail::iota_iterator(population_size_ / 2), [&](size_t i)
{
Candidate<T>& child1 = children[2 * i];
Candidate<T>& child2 = children[2 * i + 1];
std::tie(child1, child2) = crossover(select(), select());
CandidatePair child_pair = crossover(select(), select());
children[2 * i] = std::move(child_pair.first);
children[2 * i + 1] = std::move(child_pair.second);
});

if (population_size_ % 2) children.back() = crossover(select(), select()).first;
Expand Down

0 comments on commit 7937be5

Please sign in to comment.