[CSOptimizer] Rank disjunctions based on score only if both sides are supported

This commit is contained in:
Pavel Yaskevich
2024-09-17 09:27:48 -07:00
parent 3996b25fbd
commit 8818d399f9

View File

@@ -677,6 +677,9 @@ static Constraint *determineBestChoicesInContext(
getLogger() << ")\n";
}
if (bestOverallScore == 0)
return nullptr;
for (auto &entry : disjunctionScores) {
TinyPtrVector<Constraint *> favoredChoices;
for (auto *choice : favoredChoicesPerDisjunction[entry.first])
@@ -684,9 +687,6 @@ static Constraint *determineBestChoicesInContext(
favorings[entry.first] = std::make_pair(entry.second, favoredChoices);
}
if (bestOverallScore == 0)
return nullptr;
Constraint *bestDisjunction = nullptr;
for (auto *disjunction : disjunctions) {
if (disjunctionScores[disjunction] != bestOverallScore)
@@ -788,8 +788,13 @@ ConstraintSystem::selectDisjunction() {
auto &[firstScore, firstFavoredChoices] = favorings[first];
auto &[secondScore, secondFavoredChoices] = favorings[second];
if (firstScore > secondScore)
return true;
// Rank based on scores only if both disjunctions are supported.
if (isSupportedDisjunction(first) && isSupportedDisjunction(second)) {
// If both disjunctions have the same score they should be ranked
// based on number of favored/active choices.
if (firstScore != secondScore)
return firstScore > secondScore;
}
unsigned numFirstFavored = firstFavoredChoices.size();
unsigned numSecondFavored = secondFavoredChoices.size();