#[non_exhaustive]pub struct Problem {
pub sense: Sense,
pub objective: Vec<Rational>,
pub constraints: Vec<Constraint>,
pub var_names: Vec<String>,
pub signs: Vec<Sign>,
}Expand description
A linear program. Variables are non-negative unless declared free or
non_positive.
use simplex_trace::{Problem, Relation};
// max 3x1 + 5x2 s.t. x1 <= 4, 2x2 <= 12, 3x1 + 2x2 <= 18
let problem = Problem::maximize([3, 5])
.subject_to([1, 0], Relation::Le, 4)
.subject_to([0, 2], Relation::Le, 12)
.subject_to([3, 2], Relation::Le, 18);
assert_eq!(problem.num_vars(), 2);With the serde feature, numbers are exact strings ("3", "-1/2"), never JSON
floats, and var_names and signs may be omitted:
{
"sense": "maximize",
"objective": ["3", "5"],
"constraints": [
{ "coeffs": ["1", "0"], "relation": "<=", "rhs": "4" },
{ "coeffs": ["3", "2"], "relation": "<=", "rhs": "18" }
]
}Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.sense: Sense§objective: Vec<Rational>§constraints: Vec<Constraint>§var_names: Vec<String>Names of the variables. Empty means the defaults x1, x2, …
signs: Vec<Sign>Sign restriction of each variable. Empty means every variable is non-negative.
Implementations§
Source§impl Problem
impl Problem
pub fn maximize<T: IntoRational>(objective: impl IntoIterator<Item = T>) -> Self
pub fn minimize<T: IntoRational>(objective: impl IntoIterator<Item = T>) -> Self
Sourcepub fn non_positive(self, j: usize) -> Self
pub fn non_positive(self, j: usize) -> Self
Declares variable j (0-based) non-positive: x_j <= 0.
Sourcepub fn with_sign(self, j: usize, sign: Sign) -> Self
pub fn with_sign(self, j: usize, sign: Sign) -> Self
Sets the sign restriction of variable j (0-based). An index out of range is reported
by solve.
Sourcepub fn subject_to<T: IntoRational>(
self,
coeffs: impl IntoIterator<Item = T>,
relation: Relation,
rhs: impl IntoRational,
) -> Self
pub fn subject_to<T: IntoRational>( self, coeffs: impl IntoIterator<Item = T>, relation: Relation, rhs: impl IntoRational, ) -> Self
Adds a constraint. Length mismatches are reported by solve.
Sourcepub fn with_names<S: Into<String>>(
self,
names: impl IntoIterator<Item = S>,
) -> Self
pub fn with_names<S: Into<String>>( self, names: impl IntoIterator<Item = S>, ) -> Self
Overrides the default variable names (x1, x2, …). Names must be unique, may not
look like a slack or artificial column (s1, a2, …) and may not end in + or -
(the columns of free and non-positive variables); solve rejects such
problems.