use crate::LinExpr;
use std::fmt::Display;
#[derive(Copy, Clone, Debug)]
pub enum Cmp {
Eq,
Leq,
Geq,
}
#[derive(Clone, Debug)]
pub struct Constraint {
pub expr: LinExpr,
pub rhs: f64,
pub cmp: Cmp,
}
impl Constraint {
pub fn leq(lhs: LinExpr, rhs: f64) -> Self {
Self { expr: lhs, rhs, cmp: Cmp::Leq }
}
pub fn geq(lhs: LinExpr, rhs: f64) -> Self {
Self { expr: lhs, rhs, cmp: Cmp::Geq }
}
pub fn eq(lhs: LinExpr, rhs: f64) -> Self {
Self { expr: lhs, rhs, cmp: Cmp::Eq }
}
}
impl Display for Constraint {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let cmp_str = match self.cmp {
Cmp::Eq => "==",
Cmp::Leq => "<=",
Cmp::Geq => ">=",
};
write!(f, "{} {} {}", self.expr, cmp_str, self.rhs)
}
}