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!(
40 f,
41 "INTORG marker not closed by a matching INTEND in COLUMNS"
42 )
43 }
44 }
45 }
46}
47
48impl std::error::Error for MpsError {}
49
50impl From<std::io::Error> for MpsError {
51 fn from(err: std::io::Error) -> Self {
52 MpsError::IoError(err)
53 }
54}
55
56#[non_exhaustive]
63#[derive(Debug)]
64pub enum SolverError {
65 DimensionMismatch {
69 field: &'static str,
71 expected: usize,
73 got: usize,
75 },
76
77 IndexOutOfBounds {
81 context: &'static str,
83 index: usize,
85 bound: usize,
87 },
88
89 SingularBasis {
91 step: usize,
93 },
94
95 EmptyInput {
97 context: &'static str,
99 },
100
101 DeadlineExceeded,
103
104 NonFiniteCoefficient {
108 field: &'static str,
110 index: usize,
112 },
113
114 InvalidBounds {
116 index: usize,
118 lb: f64,
120 ub: f64,
122 },
123}
124
125impl std::fmt::Display for SolverError {
126 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
127 match self {
128 SolverError::DimensionMismatch {
129 field,
130 expected,
131 got,
132 } => {
133 write!(
134 f,
135 "Dimension mismatch: {} expected {} but got {}",
136 field, expected, got
137 )
138 }
139 SolverError::IndexOutOfBounds {
140 context,
141 index,
142 bound,
143 } => {
144 write!(
145 f,
146 "{} index {} out of bounds (size={})",
147 context, index, bound
148 )
149 }
150 SolverError::SingularBasis { step } => {
151 write!(f, "Singular matrix detected at step {}", step)
152 }
153 SolverError::EmptyInput { context } => {
154 write!(f, "Empty input: {}", context)
155 }
156 SolverError::DeadlineExceeded => {
157 write!(f, "Deadline exceeded during computation")
158 }
159 SolverError::NonFiniteCoefficient { field, index } => {
160 write!(f, "Non-finite coefficient in {}: index {}", field, index)
161 }
162 SolverError::InvalidBounds { index, lb, ub } => {
163 write!(
164 f,
165 "Invalid bounds at index {}: lb={} > ub={} or NaN",
166 index, lb, ub
167 )
168 }
169 }
170 }
171}
172
173impl std::error::Error for SolverError {}