1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4pub type Bound = (i32, i32);
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Variable {
10 pub id: String,
12 pub bound: Bound,
14}
15
16impl Variable {
17 pub fn new(id: impl Into<String>, lower: i32, upper: i32) -> Self {
19 Self {
20 id: id.into(),
21 bound: (lower, upper),
22 }
23 }
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct Shape {
29 pub nrows: usize,
31 pub ncols: usize,
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct IntegerSparseMatrix {
38 pub rows: Vec<i32>,
40 pub cols: Vec<i32>,
42 pub vals: Vec<i32>,
44 pub shape: Shape,
46}
47
48impl IntegerSparseMatrix {
49 pub fn new(rows: Vec<i32>, cols: Vec<i32>, vals: Vec<i32>, nrows: usize, ncols: usize) -> Self {
51 Self {
52 rows,
53 cols,
54 vals,
55 shape: Shape { nrows, ncols },
56 }
57 }
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct SparseLEIntegerPolyhedron {
63 #[serde(rename = "A")]
65 pub a: IntegerSparseMatrix,
66 pub b: Vec<i32>,
68 pub variables: Vec<Variable>,
70}
71
72#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
74#[serde(rename_all = "lowercase")]
75pub enum SolverDirection {
76 Maximize,
78 Minimize,
80}
81
82pub type Objective = HashMap<String, f64>;
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87pub struct SolveRequest {
88 pub polyhedron: SparseLEIntegerPolyhedron,
90 pub objectives: Vec<Objective>,
92 pub direction: SolverDirection,
94}
95
96#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
98pub enum Status {
99 Undefined = 1,
101 Feasible = 2,
103 Infeasible = 3,
105 NoFeasible = 4,
107 Optimal = 5,
109 Unbounded = 6,
111 SimplexFailed = 7,
113 MIPFailed = 8,
115 EmptySpace = 9,
117}
118
119#[derive(Debug, Clone, Serialize, Deserialize)]
121pub struct Solution {
122 pub status: Status,
124 pub objective: i32,
126 pub solution: HashMap<String, i64>,
128 pub error: Option<String>,
130}
131
132#[derive(Debug, Clone, Serialize, Deserialize)]
134pub struct SolveResponse {
135 pub solutions: Vec<Solution>,
137}