use crate::{utils::DisplayWrapper, LinearConstraint};
use std::fmt::{Debug, Display, Formatter};
mod convert;
mod display;
pub struct LinearVariable<T> {
kind: LinearVariableKind,
symbol: String,
bound: LinearConstraint<T>,
}
#[derive(Debug)]
pub enum LinearVariableKind {
Boolean,
Decimal,
Integer,
}
impl<T> LinearVariable<T> {
pub fn new<S>(symbol: S) -> Self
where
S: Into<String>,
{
Self { kind: LinearVariableKind::Decimal, symbol: symbol.into(), bound: LinearConstraint::None }
}
pub fn ge<S>(symbol: S, lower: T) -> Self
where
S: Into<String>,
{
Self { kind: LinearVariableKind::Decimal, symbol: symbol.into(), bound: LinearConstraint::ge(lower) }
}
pub fn geq<S>(symbol: S, lower: T) -> Self
where
S: Into<String>,
{
Self { kind: LinearVariableKind::Decimal, symbol: symbol.into(), bound: LinearConstraint::geq(lower) }
}
pub fn le<S>(symbol: S, upper: T) -> Self
where
S: Into<String>,
{
Self { kind: LinearVariableKind::Decimal, symbol: symbol.into(), bound: LinearConstraint::le(upper) }
}
pub fn leq<S>(symbol: S, upper: T) -> Self
where
S: Into<String>,
{
Self { kind: LinearVariableKind::Decimal, symbol: symbol.into(), bound: LinearConstraint::leq(upper) }
}
pub fn bounds<S>(symbol: S, bound: LinearConstraint<T>) -> Self
where
S: Into<String>,
{
Self { kind: LinearVariableKind::Decimal, symbol: symbol.into(), bound }
}
}
impl<T> LinearVariable<T> {
pub fn get_symbol(&self) -> &str {
&self.symbol
}
pub fn get_kind(&self) -> &LinearVariableKind {
&self.kind
}
pub fn set_kind(&mut self, kind: LinearVariableKind) {
self.kind = kind;
}
pub fn with_kind(mut self, kind: LinearVariableKind) -> Self {
self.kind = kind;
self
}
}
impl<T: PartialOrd> LinearVariable<T> {
pub fn contains(&self, other: &T) -> bool {
self.bound.contains(other)
}
}