cplex_rs/parameters/mip/
limits.rs

1use ffi::{
2    CPXPARAM_MIP_Limits_AggForCut, CPXPARAM_MIP_Limits_Nodes, CPXPARAM_MIP_Limits_Solutions,
3};
4
5use crate::{
6    errors::{self, Result},
7    parameters::{private, Parameter, ParameterValue},
8};
9
10impl private::Parameter for AggForCut {}
11impl private::Parameter for Solutions {}
12impl private::Parameter for Nodes {}
13
14/// AggForCut.
15/// <https://www.ibm.com/docs/en/icos/22.1.1?topic=parameters-constraint-aggregation-limit-cut-generation>
16#[derive(Copy, Clone, Debug)]
17pub struct AggForCut(pub u32);
18
19impl Parameter for AggForCut {
20    fn value(&self) -> ParameterValue {
21        ParameterValue::Integer(self.0 as i32)
22    }
23
24    fn id(&self) -> u32 {
25        CPXPARAM_MIP_Limits_AggForCut
26    }
27}
28
29/// Solutions.
30/// <https://www.ibm.com/docs/en/icos/22.1.1?topic=parameters-mip-integer-solution-limit>
31#[derive(Copy, Clone, Debug)]
32pub struct Solutions(u64);
33
34impl Solutions {
35    pub fn new(value: u64) -> Result<Self> {
36        if value == 0 {
37            return Err(errors::Input::from_message(
38                "CPXPARAM_MIP_Limits_Solutions cannot be == 0".to_string(),
39            )
40            .into());
41        }
42
43        Ok(Self(value))
44    }
45}
46
47impl Parameter for Solutions {
48    fn value(&self) -> ParameterValue {
49        ParameterValue::Long(self.0 as i64)
50    }
51
52    fn id(&self) -> u32 {
53        CPXPARAM_MIP_Limits_Solutions
54    }
55}
56
57/// MIP node limit.
58/// <https://www.ibm.com/docs/en/icos/12.9.0?topic=parameters-mip-node-limit>
59#[derive(Copy, Clone, Debug)]
60pub struct Nodes(pub u64);
61
62impl Parameter for Nodes {
63    fn value(&self) -> ParameterValue {
64        ParameterValue::Long(self.0 as i64)
65    }
66
67    fn id(&self) -> u32 {
68        CPXPARAM_MIP_Limits_Nodes
69    }
70}