Skip to content

Commit

Permalink
sort merged solutions by score
Browse files Browse the repository at this point in the history
  • Loading branch information
fleupold committed Mar 17, 2024
1 parent d33f5f0 commit fb6e7d4
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions crates/driver/src/domain/competition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Competition {
}
});

let merged = merge(solutions);
let merged = merge(solutions, auction);

// Encode solutions into settlements (streamed).
let encoded = merged
Expand Down Expand Up @@ -331,7 +331,7 @@ impl Competition {
/// Creates a vector with all possible combinations of the given solutions.
/// The result is sorted by the number of merges, so the first elements are the
/// original solutions.
fn merge(solutions: impl Iterator<Item = Solution>) -> Vec<Solution> {
fn merge(solutions: impl Iterator<Item = Solution>, auction: &Auction) -> Vec<Solution> {
let mut merged: Vec<Solution> = Vec::new();
for solution in solutions {
let mut extension = vec![];
Expand All @@ -350,9 +350,14 @@ fn merge(solutions: impl Iterator<Item = Solution>) -> Vec<Solution> {
extension.push(solution);
merged.extend(extension);
}
// Sort by "simplest", ie least merged solution.
// Maybe we should sort by score instead?
merged.sort_by_key(|solution| std::cmp::Reverse(solution.id().count_merges()));

// Sort merged solutions descending by score.
merged.sort_by_key(|solution| {
solution
.scoring(&auction.prices())
.map(|score| score.0)
.unwrap_or_default()
});
merged
}

Expand Down

0 comments on commit fb6e7d4

Please sign in to comment.