Skip to main content

Problem

Struct Problem 

Source
#[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
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, …

§signs: Vec<Sign>

Sign restriction of each variable. Empty means every variable is non-negative.

Implementations§

Source§

impl Problem

Source

pub fn maximize<T: IntoRational>(objective: impl IntoIterator<Item = T>) -> Self

Source

pub fn minimize<T: IntoRational>(objective: impl IntoIterator<Item = T>) -> Self

Source

pub fn free(self, j: usize) -> Self

Declares variable j (0-based) free: it may take any sign.

Source

pub fn non_positive(self, j: usize) -> Self

Declares variable j (0-based) non-positive: x_j <= 0.

Source

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.

Source

pub fn sign(&self, j: usize) -> Sign

Sign restriction of variable j (0-based).

Source

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.

Source

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.

Source

pub fn num_vars(&self) -> usize

Source

pub fn var_name(&self, j: usize) -> String

Name of variable j (0-based): the given name, or x{j+1} by default.

Trait Implementations§

Source§

impl Clone for Problem

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Problem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Problem

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Problem

Source§

impl PartialEq for Problem

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Problem

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Problem

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.