use serde::{Deserialize, Serialize};
pub type Cost = i64;
pub type Weight = i64;
pub type Value = i64;
pub type Index = usize;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum SolverStatus {
Optimal,
Feasible,
Infeasible,
Unbounded,
Timeout,
IterationLimit,
Unknown,
}
impl SolverStatus {
pub fn has_solution(self) -> bool {
matches!(self, Self::Optimal | Self::Feasible)
}
pub fn is_optimal(self) -> bool {
matches!(self, Self::Optimal)
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct SolverStats {
pub solve_time_seconds: f64,
pub iterations: usize,
pub nodes_explored: usize,
pub objective_value: Option<f64>,
pub best_bound: Option<f64>,
pub gap: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SolverParams {
pub time_limit_seconds: f64,
pub iteration_limit: usize,
pub num_threads: usize,
pub random_seed: u64,
pub verbosity: u32,
}
impl Default for SolverParams {
fn default() -> Self {
Self {
time_limit_seconds: 0.0,
iteration_limit: 0,
num_threads: 0,
random_seed: 0,
verbosity: 0,
}
}
}
impl SolverParams {
pub fn with_time_limit(seconds: f64) -> Self {
Self {
time_limit_seconds: seconds,
..Default::default()
}
}
pub fn has_time_limit(&self) -> bool {
self.time_limit_seconds > 0.0
}
pub fn has_iteration_limit(&self) -> bool {
self.iteration_limit > 0
}
}