use crate::builder::CanBeAddedToModel;
use crate::{
Constraint, Model, ModelStageProblemOrSolving, ModelStageWithProblem, Row, SCIPConshdlr,
SCIPSeparator,
};
#[derive(Debug)]
pub struct RowBuilder<'a> {
pub(crate) lhs: f64,
pub(crate) rhs: f64,
pub(crate) name: Option<&'a str>,
pub(crate) modifiable: Option<bool>,
pub(crate) removable: Option<bool>,
pub(crate) local: Option<bool>,
pub(crate) source: Option<RowSource<'a>>,
}
#[derive(Debug)]
pub enum RowSource<'a> {
Separator(&'a SCIPSeparator),
ConstraintHandler(&'a SCIPConshdlr),
Constraint(&'a Constraint),
}
pub fn row() -> RowBuilder<'static> {
RowBuilder::default()
}
impl Default for RowBuilder<'_> {
fn default() -> Self {
RowBuilder {
lhs: f64::NEG_INFINITY,
rhs: f64::INFINITY,
name: None,
modifiable: None,
removable: None,
local: None,
source: None,
}
}
}
impl<'a> RowBuilder<'a> {
pub fn le(mut self, val: f64) -> Self {
self.rhs = val;
self.lhs = f64::NEG_INFINITY;
self
}
pub fn ge(mut self, val: f64) -> Self {
self.lhs = val;
self.rhs = f64::INFINITY;
self
}
pub fn eq(mut self, val: f64) -> Self {
self.lhs = val;
self.rhs = val;
self
}
pub fn bounds(mut self, lhs: f64, rhs: f64) -> Self {
self.lhs = lhs;
self.rhs = rhs;
self
}
pub fn name(mut self, name: &'a str) -> Self {
self.name = Some(name);
self
}
pub fn modifiable(mut self, modifiable: bool) -> Self {
self.modifiable = Some(modifiable);
self
}
pub fn removable(mut self, removable: bool) -> Self {
self.removable = Some(removable);
self
}
pub fn local(mut self, separate: bool) -> Self {
self.local = Some(separate);
self
}
pub fn source(mut self, source: RowSource<'a>) -> Self {
self.source = Some(source);
self
}
}
impl<S> CanBeAddedToModel<S> for RowBuilder<'_>
where
S: ModelStageProblemOrSolving + ModelStageWithProblem,
{
type Return = Row;
fn add(self, model: &mut Model<S>) -> Self::Return {
let row_ptr = model
.scip
.create_empty_row(&self)
.expect("Failed to create row");
Row {
raw: row_ptr,
scip: model.scip.clone(),
}
}
}