use serde::{Deserialize, Serialize};
use std::collections::HashMap;
pub type Bound = (i32, i32);
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Variable {
pub id: String,
pub bound: Bound,
}
impl Variable {
pub fn new(id: impl Into<String>, lower: i32, upper: i32) -> Self {
Self {
id: id.into(),
bound: (lower, upper),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Shape {
pub nrows: usize,
pub ncols: usize,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IntegerSparseMatrix {
pub rows: Vec<i32>,
pub cols: Vec<i32>,
pub vals: Vec<i32>,
pub shape: Shape,
}
impl IntegerSparseMatrix {
pub fn new(rows: Vec<i32>, cols: Vec<i32>, vals: Vec<i32>, nrows: usize, ncols: usize) -> Self {
Self {
rows,
cols,
vals,
shape: Shape { nrows, ncols },
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SparseLEIntegerPolyhedron {
#[serde(rename = "A")]
pub a: IntegerSparseMatrix,
pub b: Vec<i32>,
pub variables: Vec<Variable>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum SolverDirection {
Maximize,
Minimize,
}
pub type Objective = HashMap<String, f64>;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SolveRequest {
pub polyhedron: SparseLEIntegerPolyhedron,
pub objectives: Vec<Objective>,
pub direction: SolverDirection,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum Status {
Undefined = 1,
Feasible = 2,
Infeasible = 3,
NoFeasible = 4,
Optimal = 5,
Unbounded = 6,
SimplexFailed = 7,
MIPFailed = 8,
EmptySpace = 9,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Solution {
pub status: Status,
pub objective: i32,
pub solution: HashMap<String, i64>,
pub error: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SolveResponse {
pub solutions: Vec<Solution>,
}