cplex_rs/parameters/barrier/
limits.rs1use ffi::{
2    CPXPARAM_Barrier_Limits_Corrections, CPXPARAM_Barrier_Limits_Growth,
3    CPXPARAM_Barrier_Limits_Iteration, CPXPARAM_Barrier_Limits_ObjRange,
4};
5
6use crate::errors::{self, Result};
7use crate::parameters::{private, Parameter, ParameterValue};
8
9impl private::Parameter for Growth {}
10impl private::Parameter for Iteration {}
11impl private::Parameter for Corrections {}
12impl private::Parameter for ObjRange {}
13impl private::Parameter for Ordering {}
14
15#[derive(Copy, Clone, Debug)]
18pub struct Growth(f64);
19
20impl Growth {
21    pub fn new(value: f64) -> Result<Self> {
22        if value < 1.0 {
23            return Err(errors::Input::from_message(
24                "CPXPARAM_Barrier_Limits_Growth cannot be < 1.0".to_string(),
25            )
26            .into());
27        }
28        Ok(Self(value))
29    }
30}
31
32impl Parameter for Growth {
33    fn value(&self) -> ParameterValue {
34        ParameterValue::Double(self.0)
35    }
36
37    fn id(&self) -> u32 {
38        CPXPARAM_Barrier_Limits_Growth
39    }
40}
41
42#[derive(Copy, Clone, Debug)]
45pub struct Iteration(pub u64);
46
47impl Parameter for Iteration {
48    fn value(&self) -> ParameterValue {
49        ParameterValue::Long(self.0 as i64)
50    }
51
52    fn id(&self) -> u32 {
53        CPXPARAM_Barrier_Limits_Iteration
54    }
55}
56
57#[derive(Copy, Clone, Debug)]
60pub enum Corrections {
61    Automatic,
62    Number(u64),
63}
64
65impl Parameter for Corrections {
66    fn value(&self) -> ParameterValue {
67        ParameterValue::Long(match self {
68            Self::Automatic => -1,
69            &Self::Number(n) => n as i64,
70        })
71    }
72
73    fn id(&self) -> u32 {
74        CPXPARAM_Barrier_Limits_Corrections
75    }
76}
77
78#[derive(Copy, Clone, Debug)]
81pub struct ObjRange(f64);
82
83impl ObjRange {
84    pub fn new(value: f64) -> Result<Self> {
85        if value < 0.0 {
86            return Err(errors::Input::from_message(
87                "CPXPARAM_Barrier_Limits_ObjRange cannot be < 0.0".to_string(),
88            )
89            .into());
90        }
91        Ok(Self(value))
92    }
93}
94
95impl Parameter for ObjRange {
96    fn value(&self) -> ParameterValue {
97        ParameterValue::Double(self.0)
98    }
99
100    fn id(&self) -> u32 {
101        CPXPARAM_Barrier_Limits_ObjRange
102    }
103}
104
105#[derive(Copy, Clone, Debug)]
108pub enum Ordering {
109    Automatic,
110    ApproximateMinimumDegree,
111    ApproximateMinimumFill,
112    NestedDissection,
113}
114
115impl Parameter for Ordering {
116    fn value(&self) -> ParameterValue {
117        ParameterValue::Integer(match self {
118            Self::Automatic => 0,
119            Self::ApproximateMinimumDegree => 1,
120            Self::ApproximateMinimumFill => 2,
121            Self::NestedDissection => 3,
122        })
123    }
124
125    fn id(&self) -> u32 {
126        CPXPARAM_Barrier_Limits_Corrections
127    }
128}