fts_solver/
types.rs

1use std::fmt::Debug;
2use std::hash::Hash;
3
4mod submission;
5pub use submission::*;
6
7mod demand;
8pub use demand::*;
9
10mod outcome;
11pub use outcome::*;
12
13/// The Solver trait defines the interface for market-clearing solvers.
14///
15/// A Solver takes market participant submissions (bids/offers) and computes
16/// the optimal trades and market-clearing prices that maximize total welfare.
17///
18/// Implementations may use different optimization algorithms with varying
19/// performance and precision characteristics.
20pub trait Solver {
21    /// The configuration type for this solver
22    type Settings;
23
24    /// The status type (returned as Err when not successful)
25    type Status: Debug;
26
27    /// Create a new instance with the provided settings
28    fn new(settings: Self::Settings) -> Self;
29
30    /// Solve the market clearing problem for the given auction submissions
31    ///
32    /// # Parameters
33    /// * `auction` - A slice of Submission objects representing all bids and offers
34    ///
35    /// # Returns
36    /// * `AuctionOutcome` - Contains the clearing prices and trades for each product and authorization
37    fn solve<
38        T,
39        BidderId: Eq + Hash + Clone + Ord,
40        PortfolioId: Eq + Hash + Clone + Ord,
41        ProductId: Eq + Hash + Clone + Ord,
42    >(
43        &self,
44        auction: &T,
45        // TODO: warm-starts with the prices
46    ) -> Result<AuctionOutcome<BidderId, PortfolioId, ProductId>, Self::Status>
47    where
48        for<'t> &'t T: IntoIterator<Item = (&'t BidderId, &'t Submission<PortfolioId, ProductId>)>;
49}