Skip to content

Commit 4497cbc

Browse files
committed
rmp: handle no selected candidates in tournament
Signed-off-by: Bartłomiej Chmiel <[email protected]>
1 parent 049da75 commit 4497cbc

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/rmp/src/genetic_strategy.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ std::vector<GiaOp> GeneticStrategy::RunStrategy(
5656
rsz::Resizer* resizer,
5757
utl::Logger* logger)
5858
{
59+
if (pop_size_ <= 0) {
60+
logger->error(RMP, 64, "Population size should be greater than 0");
61+
}
62+
5963
// Initial solution and slack
6064
debugPrint(logger,
6165
RMP,
@@ -139,10 +143,15 @@ std::vector<GiaOp> GeneticStrategy::RunStrategy(
139143
return absl::Bernoulli(random_, static_cast<double>(tourn_prob_));
140144
});
141145
if (winner != tournament.end()) {
142-
newPopulation.push_back(population[*winner]);
146+
newPopulation.emplace_back(population[*winner]);
143147
}
144148
}
145149
removeDuplicates(newPopulation, logger);
150+
151+
if (newPopulation.empty()) {
152+
newPopulation.emplace_back(population.front());
153+
}
154+
146155
population = std::move(newPopulation);
147156

148157
for (const auto& candidate : population) {

0 commit comments

Comments
 (0)