pub struct SolveResult { /* private fields */ }Expand description
Full outcome of a solve attempt.
Implementations§
Source§impl SolveResult
impl SolveResult
pub fn new( status: SolveStatus, solution: Option<Solution>, objective_value: Option<f64>, diagnostics: SolveDiagnostics, ) -> Self
Sourcepub fn status(&self) -> SolveStatus
pub fn status(&self) -> SolveStatus
Examples found in repository?
examples/basic_l2.rs (line 26)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 // Problem:
5 // minimize_x 1/2 ||M x - r||_2^2
6 //
7 // with
8 // M = [[1, 0],
9 // [0, 1],
10 // [1, 1]]
11 // r = [1, 2, 2.5]
12 //
13 // Least-squares intuition:
14 // x should be close to [0.8333, 1.8333]
15
16 let residual = LinearResidual::new(
17 Matrix::from_row_major(3, 2, vec![1.0, 0.0, 0.0, 1.0, 1.0, 1.0])?,
18 vec![1.0, 2.0, 2.5],
19 )?;
20
21 let problem = ConstrainedResidualProblem::new(residual, Loss::L2Squared)?;
22
23 let result = problem.solve()?;
24
25 println!("=== basic_l2 ===");
26 println!("status : {:?}", result.status());
27 println!("objective : {:?}", result.objective_value());
28 println!("diagnostics : {:?}", result.diagnostics());
29
30 if let Some(solution) = result.solution() {
31 println!("x : {:?}", solution.x());
32 println!("residual : {:?}", solution.residual());
33 } else {
34 println!("no solution returned");
35 }
36
37 Ok(())
38}More examples
examples/clarabel_constrained_l2.rs (line 25)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let residual = LinearResidual::new(
8 Matrix::from_row_major(3, 2, vec![1.0, 0.0, 0.0, 1.0, 1.0, 1.0])?,
9 vec![1.0, 2.0, 2.5],
10 )?;
11
12 let eq = LinearEqualities::new(Matrix::from_row_major(1, 2, vec![1.0, -1.0])?, vec![0.0])?;
13
14 let ineq = LinearInequalities::new(Matrix::from_row_major(1, 2, vec![1.0, 1.0])?, vec![3.0])?;
15
16 let bounds = Bounds::new(vec![Some(0.0), Some(0.0)], vec![Some(10.0), Some(10.0)])?;
17
18 let problem = ConstrainedResidualProblem::new(residual, Loss::L2Squared)?
19 .add_equalities(eq)?
20 .add_inequalities(ineq)?
21 .with_bounds(bounds)?;
22
23 let result = problem.solve()?;
24
25 println!("status : {:?}", result.status());
26 println!("objective : {:?}", result.objective_value());
27 println!("diagnostics : {:?}", result.diagnostics());
28
29 if let Some(solution) = result.solution() {
30 println!("x : {:?}", solution.x());
31 println!("residual : {:?}", solution.residual());
32 }
33
34 Ok(())
35}Sourcepub fn solution(&self) -> Option<&Solution>
pub fn solution(&self) -> Option<&Solution>
Examples found in repository?
examples/basic_l2.rs (line 30)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 // Problem:
5 // minimize_x 1/2 ||M x - r||_2^2
6 //
7 // with
8 // M = [[1, 0],
9 // [0, 1],
10 // [1, 1]]
11 // r = [1, 2, 2.5]
12 //
13 // Least-squares intuition:
14 // x should be close to [0.8333, 1.8333]
15
16 let residual = LinearResidual::new(
17 Matrix::from_row_major(3, 2, vec![1.0, 0.0, 0.0, 1.0, 1.0, 1.0])?,
18 vec![1.0, 2.0, 2.5],
19 )?;
20
21 let problem = ConstrainedResidualProblem::new(residual, Loss::L2Squared)?;
22
23 let result = problem.solve()?;
24
25 println!("=== basic_l2 ===");
26 println!("status : {:?}", result.status());
27 println!("objective : {:?}", result.objective_value());
28 println!("diagnostics : {:?}", result.diagnostics());
29
30 if let Some(solution) = result.solution() {
31 println!("x : {:?}", solution.x());
32 println!("residual : {:?}", solution.residual());
33 } else {
34 println!("no solution returned");
35 }
36
37 Ok(())
38}More examples
examples/clarabel_constrained_l2.rs (line 29)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let residual = LinearResidual::new(
8 Matrix::from_row_major(3, 2, vec![1.0, 0.0, 0.0, 1.0, 1.0, 1.0])?,
9 vec![1.0, 2.0, 2.5],
10 )?;
11
12 let eq = LinearEqualities::new(Matrix::from_row_major(1, 2, vec![1.0, -1.0])?, vec![0.0])?;
13
14 let ineq = LinearInequalities::new(Matrix::from_row_major(1, 2, vec![1.0, 1.0])?, vec![3.0])?;
15
16 let bounds = Bounds::new(vec![Some(0.0), Some(0.0)], vec![Some(10.0), Some(10.0)])?;
17
18 let problem = ConstrainedResidualProblem::new(residual, Loss::L2Squared)?
19 .add_equalities(eq)?
20 .add_inequalities(ineq)?
21 .with_bounds(bounds)?;
22
23 let result = problem.solve()?;
24
25 println!("status : {:?}", result.status());
26 println!("objective : {:?}", result.objective_value());
27 println!("diagnostics : {:?}", result.diagnostics());
28
29 if let Some(solution) = result.solution() {
30 println!("x : {:?}", solution.x());
31 println!("residual : {:?}", solution.residual());
32 }
33
34 Ok(())
35}Sourcepub fn objective_value(&self) -> Option<f64>
pub fn objective_value(&self) -> Option<f64>
Examples found in repository?
examples/basic_l2.rs (line 27)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 // Problem:
5 // minimize_x 1/2 ||M x - r||_2^2
6 //
7 // with
8 // M = [[1, 0],
9 // [0, 1],
10 // [1, 1]]
11 // r = [1, 2, 2.5]
12 //
13 // Least-squares intuition:
14 // x should be close to [0.8333, 1.8333]
15
16 let residual = LinearResidual::new(
17 Matrix::from_row_major(3, 2, vec![1.0, 0.0, 0.0, 1.0, 1.0, 1.0])?,
18 vec![1.0, 2.0, 2.5],
19 )?;
20
21 let problem = ConstrainedResidualProblem::new(residual, Loss::L2Squared)?;
22
23 let result = problem.solve()?;
24
25 println!("=== basic_l2 ===");
26 println!("status : {:?}", result.status());
27 println!("objective : {:?}", result.objective_value());
28 println!("diagnostics : {:?}", result.diagnostics());
29
30 if let Some(solution) = result.solution() {
31 println!("x : {:?}", solution.x());
32 println!("residual : {:?}", solution.residual());
33 } else {
34 println!("no solution returned");
35 }
36
37 Ok(())
38}More examples
examples/clarabel_constrained_l2.rs (line 26)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let residual = LinearResidual::new(
8 Matrix::from_row_major(3, 2, vec![1.0, 0.0, 0.0, 1.0, 1.0, 1.0])?,
9 vec![1.0, 2.0, 2.5],
10 )?;
11
12 let eq = LinearEqualities::new(Matrix::from_row_major(1, 2, vec![1.0, -1.0])?, vec![0.0])?;
13
14 let ineq = LinearInequalities::new(Matrix::from_row_major(1, 2, vec![1.0, 1.0])?, vec![3.0])?;
15
16 let bounds = Bounds::new(vec![Some(0.0), Some(0.0)], vec![Some(10.0), Some(10.0)])?;
17
18 let problem = ConstrainedResidualProblem::new(residual, Loss::L2Squared)?
19 .add_equalities(eq)?
20 .add_inequalities(ineq)?
21 .with_bounds(bounds)?;
22
23 let result = problem.solve()?;
24
25 println!("status : {:?}", result.status());
26 println!("objective : {:?}", result.objective_value());
27 println!("diagnostics : {:?}", result.diagnostics());
28
29 if let Some(solution) = result.solution() {
30 println!("x : {:?}", solution.x());
31 println!("residual : {:?}", solution.residual());
32 }
33
34 Ok(())
35}Sourcepub fn diagnostics(&self) -> &SolveDiagnostics
pub fn diagnostics(&self) -> &SolveDiagnostics
Examples found in repository?
examples/basic_l2.rs (line 28)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 // Problem:
5 // minimize_x 1/2 ||M x - r||_2^2
6 //
7 // with
8 // M = [[1, 0],
9 // [0, 1],
10 // [1, 1]]
11 // r = [1, 2, 2.5]
12 //
13 // Least-squares intuition:
14 // x should be close to [0.8333, 1.8333]
15
16 let residual = LinearResidual::new(
17 Matrix::from_row_major(3, 2, vec![1.0, 0.0, 0.0, 1.0, 1.0, 1.0])?,
18 vec![1.0, 2.0, 2.5],
19 )?;
20
21 let problem = ConstrainedResidualProblem::new(residual, Loss::L2Squared)?;
22
23 let result = problem.solve()?;
24
25 println!("=== basic_l2 ===");
26 println!("status : {:?}", result.status());
27 println!("objective : {:?}", result.objective_value());
28 println!("diagnostics : {:?}", result.diagnostics());
29
30 if let Some(solution) = result.solution() {
31 println!("x : {:?}", solution.x());
32 println!("residual : {:?}", solution.residual());
33 } else {
34 println!("no solution returned");
35 }
36
37 Ok(())
38}More examples
examples/clarabel_constrained_l2.rs (line 27)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let residual = LinearResidual::new(
8 Matrix::from_row_major(3, 2, vec![1.0, 0.0, 0.0, 1.0, 1.0, 1.0])?,
9 vec![1.0, 2.0, 2.5],
10 )?;
11
12 let eq = LinearEqualities::new(Matrix::from_row_major(1, 2, vec![1.0, -1.0])?, vec![0.0])?;
13
14 let ineq = LinearInequalities::new(Matrix::from_row_major(1, 2, vec![1.0, 1.0])?, vec![3.0])?;
15
16 let bounds = Bounds::new(vec![Some(0.0), Some(0.0)], vec![Some(10.0), Some(10.0)])?;
17
18 let problem = ConstrainedResidualProblem::new(residual, Loss::L2Squared)?
19 .add_equalities(eq)?
20 .add_inequalities(ineq)?
21 .with_bounds(bounds)?;
22
23 let result = problem.solve()?;
24
25 println!("status : {:?}", result.status());
26 println!("objective : {:?}", result.objective_value());
27 println!("diagnostics : {:?}", result.diagnostics());
28
29 if let Some(solution) = result.solution() {
30 println!("x : {:?}", solution.x());
31 println!("residual : {:?}", solution.residual());
32 }
33
34 Ok(())
35}pub fn is_solved(&self) -> bool
Trait Implementations§
Source§impl Clone for SolveResult
impl Clone for SolveResult
Source§fn clone(&self) -> SolveResult
fn clone(&self) -> SolveResult
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SolveResult
impl Debug for SolveResult
Source§impl PartialEq for SolveResult
impl PartialEq for SolveResult
impl StructuralPartialEq for SolveResult
Auto Trait Implementations§
impl Freeze for SolveResult
impl RefUnwindSafe for SolveResult
impl Send for SolveResult
impl Sync for SolveResult
impl Unpin for SolveResult
impl UnsafeUnpin for SolveResult
impl UnwindSafe for SolveResult
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more