use crate::{Constraint, expr::LinExpr};
use std::ops::Mul;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct VarId(pub usize);
impl VarId {
pub fn leq(self, rhs: f64) -> Constraint {
LinExpr::from(self).leq(rhs)
}
pub fn geq(self, rhs: f64) -> Constraint {
LinExpr::from(self).geq(rhs)
}
pub fn eq(self, rhs: f64) -> Constraint {
LinExpr::from(self).eq(rhs)
}
}
#[derive(Clone, Debug)]
pub struct Var {
pub id: VarId,
pub lb: Option<f64>,
pub ub: Option<f64>,
pub is_integer: bool,
pub is_artificial: bool,
}
pub struct VarBuilder<'a> {
pub model: &'a mut crate::Model,
pub var: VarId,
}
impl<'a> VarBuilder<'a> {
pub fn lower_bound(self, lb: f64) -> Self {
_ = lb;
panic!("Lower bound not implemented yet");
}
pub fn upper_bound(self, ub: f64) -> Self {
_ = ub;
panic!("Upper bound not implemented yet");
}
pub fn integer(self) -> Self {
self.model.vars[self.var.0].is_integer = true;
self
}
pub fn binary(self) -> Self {
let var = &mut self.model.vars[self.var.0];
var.is_integer = true;
var.lb = Some(0.0);
var.ub = Some(1.0);
self
}
pub fn finish(self) -> VarId {
self.var
}
}
impl Mul<f64> for VarId {
type Output = LinExpr;
fn mul(self, rhs: f64) -> LinExpr {
LinExpr::new(self, rhs)
}
}
impl Mul<VarId> for f64 {
type Output = LinExpr;
fn mul(self, rhs: VarId) -> LinExpr {
rhs * self
}
}