Skip to main content

Solution

Struct Solution 

Source
pub struct Solution {
    pub values: Vec<f64>,
    pub objective_value: Option<f64>,
    pub status: SolveStatus,
}
Expand description

Represents the result of solving an optimization problem.

Contains the values assigned to each variable, the value of the objective function, and the solver status.

§Examples

use cnvx_core::{Solution, SolveStatus, VarId};

// Example solution with 3 variables
let solution = Solution {
    values: vec![1.0, 2.0, 3.0],
    objective_value: Some(10.0),
    status: SolveStatus::Optimal,
};

assert_eq!(solution.value(VarId(0)), 1.0);
assert_eq!(solution.value(VarId(2)), 3.0);

Fields§

§values: Vec<f64>

Variable assignments, indexed by variable ID.

The value at index i corresponds to the variable with ID VarId(i).

§objective_value: Option<f64>

The value of the objective function at the solution.

None if the solver did not produce an objective value (e.g., infeasible or unbounded problem).

§status: SolveStatus

The solver status indicating whether the solution is optimal, feasible, infeasible, or unbounded.

Implementations§

Source§

impl Solution

Source

pub fn value(&self, var: VarId) -> f64

Returns the value assigned to the variable with the given VarId.

§Example
let x1: VarId = model.add_var().finish();
let solution = Solution {
    values: vec![1.0], // Assuming x1 has ID 0
    objective_value: Some(10.0),
    status: SolveStatus::Optimal,
};
let value = solution.value(x1);

Trait Implementations§

Source§

impl Debug for Solution

Source§

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

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

impl Display for Solution

Source§

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

Formats the value using the given formatter. 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.