#[non_exhaustive]pub struct Problem {
pub sense: Sense,
pub objective: Vec<Rational>,
pub constraints: Vec<Constraint>,
pub var_names: Vec<String>,
}Expand description
A linear program with non-negative variables.
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 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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
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, …
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 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 and may
not look like a slack or artificial column (s1, a2, …); solve
rejects such problems.
pub fn num_vars(&self) -> usize
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Problem
impl<'de> Deserialize<'de> for Problem
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Problem
impl StructuralPartialEq for Problem
Auto Trait Implementations§
impl Freeze for Problem
impl RefUnwindSafe for Problem
impl Send for Problem
impl Sync for Problem
impl Unpin for Problem
impl UnsafeUnpin for Problem
impl UnwindSafe for Problem
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