1#[non_exhaustive]
3#[derive(Debug)]
4pub enum MpsError {
5 IoError(std::io::Error),
7 ParseError { line: usize, message: String },
9 MissingSection(String),
11 DuplicateSection(String),
13 InvalidRowType(char),
15 InvalidBoundType(String),
17 UndefinedReference { kind: String, name: String },
19 UnclosedIntegerMarker,
22}
23
24impl std::fmt::Display for MpsError {
25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 match self {
27 MpsError::IoError(e) => write!(f, "I/O error: {}", e),
28 MpsError::ParseError { line, message } => {
29 write!(f, "Parse error at line {}: {}", line, message)
30 }
31 MpsError::MissingSection(s) => write!(f, "Missing required section: {}", s),
32 MpsError::DuplicateSection(s) => write!(f, "Duplicate section: {}", s),
33 MpsError::InvalidRowType(c) => write!(f, "Invalid row type: {}", c),
34 MpsError::InvalidBoundType(s) => write!(f, "Invalid bound type: {}", s),
35 MpsError::UndefinedReference { kind, name } => {
36 write!(f, "Undefined {} reference: {}", kind, name)
37 }
38 MpsError::UnclosedIntegerMarker => {
39 write!(f, "INTORG marker not closed by a matching INTEND in COLUMNS")
40 }
41 }
42 }
43}
44
45impl std::error::Error for MpsError {}
46
47impl From<std::io::Error> for MpsError {
48 fn from(err: std::io::Error) -> Self {
49 MpsError::IoError(err)
50 }
51}
52
53#[non_exhaustive]
61#[derive(Debug)]
62pub enum SolverError {
63 Mps(MpsError),
65
66 DimensionMismatch {
70 field: &'static str,
72 expected: usize,
74 got: usize,
76 },
77
78 IndexOutOfBounds {
82 context: &'static str,
84 index: usize,
86 bound: usize,
88 },
89
90 SingularBasis {
92 step: usize,
94 },
95
96 EmptyInput {
98 context: &'static str,
100 },
101
102 DeadlineExceeded,
104
105 NonFiniteCoefficient {
109 field: &'static str,
111 index: usize,
113 },
114
115 InvalidBounds {
117 index: usize,
119 lb: f64,
121 ub: f64,
123 },
124}
125
126impl std::fmt::Display for SolverError {
127 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
128 match self {
129 SolverError::Mps(e) => write!(f, "{}", e),
130 SolverError::DimensionMismatch { field, expected, got } => {
131 write!(f, "Dimension mismatch: {} expected {} but got {}", field, expected, got)
132 }
133 SolverError::IndexOutOfBounds { context, index, bound } => {
134 write!(f, "{} index {} out of bounds (size={})", context, index, bound)
135 }
136 SolverError::SingularBasis { step } => {
137 write!(f, "Singular matrix detected at step {}", step)
138 }
139 SolverError::EmptyInput { context } => {
140 write!(f, "Empty input: {}", context)
141 }
142 SolverError::DeadlineExceeded => {
143 write!(f, "Deadline exceeded during computation")
144 }
145 SolverError::NonFiniteCoefficient { field, index } => {
146 write!(f, "Non-finite coefficient in {}: index {}", field, index)
147 }
148 SolverError::InvalidBounds { index, lb, ub } => {
149 write!(f, "Invalid bounds at index {}: lb={} > ub={} or NaN", index, lb, ub)
150 }
151 }
152 }
153}
154
155impl std::error::Error for SolverError {}
156
157impl From<MpsError> for SolverError {
158 fn from(e: MpsError) -> Self {
159 SolverError::Mps(e)
160 }
161}