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
impl Solution
Sourcepub fn var_value(&self, var: Variable) -> &f64
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.
Sourcepub fn var_value_rounded(&self, var: Variable) -> f64
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
Sourcepub fn iter(&self) -> SolutionIter<'_> ⓘ
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.
Sourcepub fn add_constraint(
self,
expr: impl Into<LinearExpr>,
cmp_op: ComparisonOp,
rhs: f64,
) -> Result<Self, Error>
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.
Sourcepub fn fix_var(self, var: Variable, val: f64) -> Result<Self, Error>
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.
Sourcepub fn unfix_var(self, var: Variable) -> (Self, bool)
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.
Sourcepub fn add_gomory_cut(self, var: Variable) -> Result<Self, Error>
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).