Skip to content

Commit

Permalink
Don't send empty solutions to the driver (#2076)
Browse files Browse the repository at this point in the history
# Description
I don't find empty solutions useful in driver/solvers communication.
Currently, all solvers except legacy solvers return empty vector when
they can't find a solution, while legacy sends empty solution:

https://production-6de61f.kb.eu-central-1.aws.cloud.es.io/app/r/s/ldj1i

I find it hard to read. Solvers should be consistent.

This PR changes legacy solver to send no solutions to the driver.
I still we should still keep the proper handling of empty solutions in
the `driver` since we won't control the solvers forever.
  • Loading branch information
sunce86 authored Nov 24, 2023
1 parent e185f8e commit 9701fc7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions crates/solvers/src/domain/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ impl Solution {

self
}

pub fn is_empty(&self) -> bool {
self.prices.0.is_empty() && self.trades.is_empty() && self.interactions.is_empty()
}
}

/// A solution for a settling a single order.
Expand Down
8 changes: 7 additions & 1 deletion crates/solvers/src/domain/solver/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ impl Legacy {

pub async fn solve(&self, auction: auction::Auction) -> Vec<solution::Solution> {
match self.0.solve(&auction).await {
Ok(solution) => vec![solution.with_id(solution::Id(0))],
Ok(solution) => {
if solution.is_empty() {
vec![]
} else {
vec![solution]
}
}
Err(err) => {
tracing::warn!(?err, "failed to solve auction");
if err.is_timeout() {
Expand Down

0 comments on commit 9701fc7

Please sign in to comment.