cplex_rs/parameters/
mod.rs1pub mod barrier;
2pub mod emphasis;
3pub mod mip;
4pub mod preprocessing;
5pub mod read;
6pub mod tolerances;
7
8use std::{
9 ffi::{c_double, c_int, c_long},
10 time::Duration,
11};
12
13use ffi::{
14 CPXPARAM_Advance, CPXPARAM_Parallel, CPXPARAM_RandomSeed, CPXPARAM_ScreenOutput,
15 CPXPARAM_Threads, CPXPARAM_TimeLimit,
16};
17
18pub(crate) mod private {
23 pub trait Parameter {}
24}
25
26impl private::Parameter for Advance {}
27impl private::Parameter for ParallelMode {}
28impl private::Parameter for Threads {}
29impl private::Parameter for ScreenOutput {}
30impl private::Parameter for RandomSeed {}
31impl private::Parameter for TimeLimit {}
32
33pub trait Parameter: private::Parameter {
36 fn value(&self) -> ParameterValue;
37 fn id(&self) -> u32;
38}
39
40#[derive(Copy, Clone, Debug)]
41pub enum ParameterValue {
42 Integer(c_int),
43 Long(c_long),
44 Double(c_double),
45 String(&'static str),
46}
47
48#[derive(Copy, Clone, Debug)]
51pub enum Advance {
52 Unused = 0,
53 AdvancedBasis = 1,
54 AdvancedBasisOrStartingVector = 2,
55}
56
57impl Parameter for Advance {
58 fn value(&self) -> ParameterValue {
59 ParameterValue::Integer(match self {
60 Self::Unused => 0,
61 Self::AdvancedBasis => 1,
62 Self::AdvancedBasisOrStartingVector => 2,
63 })
64 }
65
66 fn id(&self) -> u32 {
67 CPXPARAM_Advance
68 }
69}
70
71#[derive(Copy, Clone, Debug)]
74pub enum ParallelMode {
75 Opportunistic,
76 Auto,
77 Deterministic,
78}
79
80impl Parameter for ParallelMode {
81 fn value(&self) -> ParameterValue {
82 ParameterValue::Integer(match self {
83 ParallelMode::Opportunistic => -1,
84 ParallelMode::Auto => 0,
85 ParallelMode::Deterministic => 1,
86 })
87 }
88
89 fn id(&self) -> u32 {
90 CPXPARAM_Parallel
91 }
92}
93
94#[derive(Copy, Clone, Debug)]
97pub struct Threads(pub u32);
98
99impl Parameter for Threads {
100 fn value(&self) -> ParameterValue {
101 ParameterValue::Integer(self.0 as i32)
102 }
103
104 fn id(&self) -> u32 {
105 CPXPARAM_Threads
106 }
107}
108
109#[derive(Copy, Clone, Debug)]
112pub struct ScreenOutput(pub bool);
113
114impl Parameter for ScreenOutput {
115 fn value(&self) -> ParameterValue {
116 ParameterValue::Integer(if self.0 { 1 } else { 0 })
117 }
118
119 fn id(&self) -> u32 {
120 CPXPARAM_ScreenOutput
121 }
122}
123
124#[derive(Copy, Clone, Debug)]
127pub struct RandomSeed(pub u32);
128
129impl Parameter for RandomSeed {
130 fn value(&self) -> ParameterValue {
131 ParameterValue::Integer(self.0 as i32)
132 }
133
134 fn id(&self) -> u32 {
135 CPXPARAM_RandomSeed
136 }
137}
138
139#[derive(Copy, Clone, Debug)]
142pub struct TimeLimit(pub Duration);
143
144impl Parameter for TimeLimit {
145 fn value(&self) -> ParameterValue {
146 ParameterValue::Double(self.0.as_secs() as f64)
147 }
148
149 fn id(&self) -> u32 {
150 CPXPARAM_TimeLimit
151 }
152}