Skip to main content

milp_types/mixed/
mod.rs

1use lp_types::{LinearConstraint, LinearEquation, LinearVariable};
2use num::{BigInt, BigUint};
3use std::fmt::{Debug, Display, Formatter};
4mod convert;
5mod display;
6
7pub enum MixedValue {
8    Boolean(bool),
9    Decimal(f64),
10    Integer(BigInt),
11}
12
13pub struct MixedConstraint {
14    wrapper: LinearConstraint<MixedValue>,
15}
16
17pub struct MixedVariable {
18    wrapper: LinearVariable<MixedValue>,
19}
20
21pub struct MixedEquation {
22    wrapper: LinearEquation<MixedValue>,
23}
24
25impl MixedVariable {
26    pub fn free<S>(symbol: S) -> Self
27    where
28        S: Into<String>,
29    {
30        Self { wrapper: LinearVariable::new(symbol) }
31    }
32    pub fn ge<S, V>(symbol: S, lower: V) -> Self
33    where
34        S: Into<String>,
35        V: Into<MixedValue>,
36    {
37        Self { wrapper: LinearVariable::ge(symbol, lower.into()) }
38    }
39    pub fn geq<S, V>(symbol: S, lower: V) -> Self
40    where
41        S: Into<String>,
42        V: Into<MixedValue>,
43    {
44        Self { wrapper: LinearVariable::geq(symbol, lower.into()) }
45    }
46    pub fn le<S, V>(symbol: S, upper: V) -> Self
47    where
48        S: Into<String>,
49        V: Into<MixedValue>,
50    {
51        Self { wrapper: LinearVariable::le(symbol, upper.into()) }
52    }
53    pub fn leq<S, V>(symbol: S, upper: V) -> Self
54    where
55        S: Into<String>,
56        V: Into<MixedValue>,
57    {
58        Self { wrapper: LinearVariable::leq(symbol, upper.into()) }
59    }
60    pub fn bounds<S, V>(symbol: S, bound: MixedConstraint) -> Self
61    where
62        S: Into<String>,
63        V: Into<MixedValue>,
64    {
65        Self { wrapper: LinearVariable::bounds(symbol, bound.wrapper) }
66    }
67    pub fn get_symbol(&self) -> &str {
68        self.wrapper.get_symbol()
69    }
70    // pub fn get_kind(&self) -> &MixedVariableKind {
71    //     self.wrapper.get_kind()
72    // }
73    // pub fn get_bound(&self) -> &MixedConstraint {
74    //     self.wrapper.get_bound()
75    // }
76}
77
78impl MixedEquation {
79    pub fn variables(&self) -> impl Iterator<Item = &str> {
80        self.wrapper.variables()
81    }
82}