converge_optimization/
types.rs1use serde::{Deserialize, Serialize};
4
5pub type Cost = i64;
7
8pub type Weight = i64;
10
11pub type Value = i64;
13
14pub type Index = usize;
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
19pub enum SolverStatus {
20 Optimal,
22 Feasible,
24 Infeasible,
26 Unbounded,
28 Timeout,
30 IterationLimit,
32 Unknown,
34}
35
36impl SolverStatus {
37 pub fn has_solution(self) -> bool {
39 matches!(self, Self::Optimal | Self::Feasible)
40 }
41
42 pub fn is_optimal(self) -> bool {
44 matches!(self, Self::Optimal)
45 }
46}
47
48#[derive(Debug, Clone, Default, Serialize, Deserialize)]
50pub struct SolverStats {
51 pub solve_time_seconds: f64,
53 pub iterations: usize,
55 pub nodes_explored: usize,
57 pub objective_value: Option<f64>,
59 pub best_bound: Option<f64>,
61 pub gap: Option<f64>,
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
67pub struct SolverParams {
68 pub time_limit_seconds: f64,
70 pub iteration_limit: usize,
72 pub num_threads: usize,
74 pub random_seed: u64,
76 pub verbosity: u32,
78}
79
80impl Default for SolverParams {
81 fn default() -> Self {
82 Self {
83 time_limit_seconds: 0.0,
84 iteration_limit: 0,
85 num_threads: 0,
86 random_seed: 0,
87 verbosity: 0,
88 }
89 }
90}
91
92impl SolverParams {
93 pub fn with_time_limit(seconds: f64) -> Self {
95 Self {
96 time_limit_seconds: seconds,
97 ..Default::default()
98 }
99 }
100
101 pub fn has_time_limit(&self) -> bool {
103 self.time_limit_seconds > 0.0
104 }
105
106 pub fn has_iteration_limit(&self) -> bool {
108 self.iteration_limit > 0
109 }
110}