1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use ffi::{CPX_BINARY, CPX_CONTINUOUS, CPX_INTEGER, CPX_SEMICONT, CPX_SEMIINT};

#[derive(Copy, Clone, Debug)]
pub enum VariableType {
    Continuous,
    Binary,
    Integer,
    SemiContinuous,
    SemiInteger,
}

impl VariableType {
    pub(crate) fn into_raw(self) -> u8 {
        match self {
            VariableType::Continuous => CPX_CONTINUOUS,
            VariableType::Binary => CPX_BINARY,
            VariableType::Integer => CPX_INTEGER,
            VariableType::SemiContinuous => CPX_SEMICONT,
            VariableType::SemiInteger => CPX_SEMIINT,
        }
    }
}

#[derive(Clone, Debug)]
pub struct Variable {
    type_: VariableType,
    weight: f64,
    lower_bound: f64,
    upper_bound: f64,
    name: String,
}

impl Variable {
    pub fn new<S>(ty: VariableType, obj: f64, lb: f64, ub: f64, name: S) -> Variable
    where
        String: From<S>,
    {
        let name = name.into();
        Variable {
            type_: ty,
            weight: obj,
            lower_bound: lb,
            upper_bound: ub,
            name,
        }
    }

    pub fn name(&self) -> &str {
        &self.name
    }

    pub fn upper_bound(&self) -> f64 {
        self.upper_bound
    }

    pub fn lower_bound(&self) -> f64 {
        self.lower_bound
    }

    pub fn weight(&self) -> f64 {
        self.weight
    }

    pub fn type_(&self) -> VariableType {
        self.type_
    }
}