1use std::ffi::c_char;
2
3use crate::VariableId;
4
5#[derive(Copy, Clone, Debug)]
6pub enum ConstraintType {
7 LessThanEq,
8 Eq,
9 GreaterThanEq,
10}
11
12impl ConstraintType {
13 pub(crate) fn into_raw(self) -> c_char {
14 match self {
15 ConstraintType::LessThanEq => 'L' as c_char,
16 ConstraintType::Eq => 'E' as c_char,
17 ConstraintType::GreaterThanEq => 'G' as c_char,
18 }
19 }
20}
21
22#[derive(Clone, Debug)]
23pub struct Constraint {
24 weights: Vec<(VariableId, f64)>,
25 type_: ConstraintType,
26 rhs: f64,
27 name: Option<String>,
28}
29
30impl Constraint {
31 pub fn new(
32 ty: ConstraintType,
33 rhs: f64,
34 name: Option<String>,
35 vars: Vec<(VariableId, f64)>,
36 ) -> Constraint {
37 Constraint {
38 weights: vars,
39 type_: ty,
40 rhs,
41 name,
42 }
43 }
44
45 pub fn name(&self) -> Option<&str> {
46 self.name.as_deref()
47 }
48
49 pub fn weights(&self) -> &[(VariableId, f64)] {
50 &self.weights
51 }
52
53 pub fn rhs(&self) -> f64 {
54 self.rhs
55 }
56
57 pub fn type_(&self) -> ConstraintType {
58 self.type_
59 }
60}