Solution

Struct Solution 

Source
pub struct Solution { /* private fields */ }
Expand description

A solution of a problem: optimal objective function value and variable values.

Note that a Solution instance contains the whole solver machinery which can require a lot of memory for larger problems. Thus saving the Solution instance (as opposed to getting the values of interest and discarding the solution) is mainly useful if you want to add more constraints to it later.

Implementations§

Source§

impl Solution

Source

pub fn objective(&self) -> f64

Optimal value of the objective function.

Source

pub fn var_value(&self, var: Variable) -> &f64

Value of the variable at optimum.

Note that you can use indexing operations to get variable values.

§Warning

If the variable is an integer, there might be rounding errors. For example you could see 0.999999999999 instead of 1.0.

Source

pub fn var_value_rounded(&self, var: Variable) -> f64

Value of the variable at optimum.

If the variable was defined as an integer, it rounds it remove precision errors

Source

pub fn iter(&self) -> SolutionIter<'_>

Iterate over the variable-value pairs of the solution.

§Warning

If you used integer variables, there might be rounding errors in the variable results for example you could see 0.999999999999 instead of 1.0.

Source

pub fn add_constraint( self, expr: impl Into<LinearExpr>, cmp_op: ComparisonOp, rhs: f64, ) -> Result<Self, Error>

Add another constraint and return the solution to the updated problem.

This method will consume the solution and not return it in case of error. See also examples of specifying the left-hand side in the docs for the Problem::add_constraint method.

§Errors

Will return an error if the problem becomes infeasible with the additional constraint.

Source

pub fn fix_var(self, var: Variable, val: f64) -> Result<Self, Error>

Fix the variable to the specified value and return the solution to the updated problem.

This method will consume the solution and not return it in case of error.

§Errors

Will return an error if the problem becomes infeasible with the additional constraint.

Source

pub fn unfix_var(self, var: Variable) -> (Self, bool)

If the variable was fixed with fix_var before, remove that constraint and return the solution to the updated problem and a boolean indicating if the variable was really fixed before.

Source

pub fn add_gomory_cut(self, var: Variable) -> Result<Self, Error>

Add a Gomory cut constraint to the problem and return the solution.

§Errors

Will return an error if the problem becomes infeasible with the additional constraint.

§Panics

Will panic if the variable is not basic (variable is basic if it has value other than its bounds).

Trait Implementations§

Source§

impl Clone for Solution

Source§

fn clone(&self) -> Solution

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Solution

Source§

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

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

impl Index<Variable> for Solution

Source§

type Output = f64

The returned type after indexing.
Source§

fn index(&self, var: Variable) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a> IntoIterator for &'a Solution

Source§

type Item = (Variable, &'a f64)

The type of the elements being iterated over.
Source§

type IntoIter = SolutionIter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.