pounce_algorithm/sqp/
result.rs1use pounce_common::Number;
5use pounce_qp::{QpError, WorkingSet};
6use std::fmt;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum SqpStatus {
10 Optimal,
12 MaxIter,
14 InfeasibleSubproblem,
17 LineSearchFailed,
20}
21
22impl fmt::Display for SqpStatus {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 match self {
25 SqpStatus::Optimal => write!(f, "optimal"),
26 SqpStatus::MaxIter => write!(f, "max-iter"),
27 SqpStatus::InfeasibleSubproblem => write!(f, "infeasible-subproblem"),
28 SqpStatus::LineSearchFailed => write!(f, "line-search-failed"),
29 }
30 }
31}
32
33#[derive(Debug)]
34pub enum SqpError {
35 QpFailure(QpError),
37 DimensionMismatch(String),
39}
40
41impl fmt::Display for SqpError {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 match self {
44 SqpError::QpFailure(e) => write!(f, "QP subproblem failure: {e}"),
45 SqpError::DimensionMismatch(s) => write!(f, "dimension mismatch: {s}"),
46 }
47 }
48}
49
50impl From<QpError> for SqpError {
51 fn from(e: QpError) -> Self {
52 SqpError::QpFailure(e)
53 }
54}
55
56#[derive(Debug, Clone)]
57pub struct SqpResult {
58 pub x: Vec<Number>,
59 pub lambda_g: Vec<Number>,
60 pub lambda_x: Vec<Number>,
61 pub obj: Number,
62 pub status: SqpStatus,
63 pub n_iter: u32,
64 pub n_qp_solves: u32,
65 pub final_stationarity: Number,
67 pub final_constr_viol: Number,
70 pub working_set: Option<WorkingSet>,
75}