pub struct Model { /* private fields */ }Expand description
A validated LP or mixed-integer LP.
A Model can only be obtained through Model::new, so every instance
satisfies the invariants below and solvers do not re-validate it. It is
immutable and can be shared (for example behind an Arc) by any number of
independent solves.
Invariants: n >= 1 variables and m >= 0 rows; finite objective
coefficients, offset and matrix values; valid Bounds (infinite values
only as -inf lower or +inf upper bounds); binary bounds inside [0, 1];
a canonical CSR matrix of shape m x n (see CsrPattern).
Implementations§
Source§impl Model
impl Model
Sourcepub fn new(data: ModelData) -> Result<Self>
pub fn new(data: ModelData) -> Result<Self>
Validates and wraps data. Errors name the offending field and entry.
Examples found in repository?
examples/production.rs (lines 20-28)
19fn main() -> Result<()> {
20 let model = Model::new(ModelData {
21 sense: Sense::Maximize,
22 objective: vec![45.0, 80.0, 110.0],
23 objective_offset: 0.0,
24 variables: Bounds::non_negative(3),
25 kinds: vec![VariableKind::Continuous; 3],
26 matrix: CsrMatrix::from_dense(3, 3, &[5.0, 20.0, 25.0, 10.0, 15.0, 20.0, 1.0, 3.0, 5.0])?,
27 rows: Bounds::new(vec![f64::NEG_INFINITY; 3], vec![400.0, 450.0, 60.0]),
28 })?;
29
30 // The published optimum; the dummy only evaluates it.
31 let optimum = vec![30.0, 10.0, 0.0];
32 let result = DummySolver.solve(
33 &model,
34 &Options::default(),
35 Some(&WarmStart::from_primal(optimum.clone())),
36 &CancellationToken::default(),
37 )?;
38 println!("status: {:?} ({})", result.status, result.message);
39 let evaluation = result.evaluation.expect("the start was evaluated");
40 println!("evaluation: {evaluation:?}");
41 assert_eq!(evaluation.objective, 2150.0);
42
43 // Row duals (Gurobi Pi, HiGHS row_dual) and reduced costs (RC, col_dual) as
44 // published, in the crate's convention c = A^T y + z for the maximization.
45 let duals = Duals {
46 row_duals: vec![0.0, 11.0 / 3.0, 25.0 / 3.0],
47 reduced_costs: vec![0.0, 0.0, -5.0],
48 };
49 let residuals = lp_residuals(&model, &optimum, &duals)?;
50 println!("LP residuals with the published duals: {residuals:?}");
51 assert!(residuals.max() < 1e-12);
52 Ok(())
53}Sourcepub fn objective_offset(&self) -> f64
pub fn objective_offset(&self) -> f64
Constant objective term.
Sourcepub fn kinds(&self) -> &[VariableKind]
pub fn kinds(&self) -> &[VariableKind]
Variable domains.
Trait Implementations§
impl StructuralPartialEq for Model
Auto Trait Implementations§
impl Forget for Model
impl Freeze for Modelwhere
*const u8 is !null: Freeze,
PhantomData<f64>: Freeze,
PhantomData<VariableKind>: Freeze,
PhantomData<usize>: Freeze,
impl Move for Model
impl RefUnwindSafe for Model
impl Send for Modelwhere
RawVecInner: Send,
impl Sync for Modelwhere
RawVecInner: Sync,
impl Unpin for Model
impl UnsafeUnpin for Modelwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<f64>: UnsafeUnpin,
PhantomData<VariableKind>: UnsafeUnpin,
PhantomData<usize>: UnsafeUnpin,
impl UnwindSafe for Modelwhere
RawVecInner: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more