#[non_exhaustive]
#[derive(Debug)]
pub enum MpsError {
IoError(std::io::Error),
ParseError { line: usize, message: String },
MissingSection(String),
DuplicateSection(String),
InvalidRowType(char),
InvalidBoundType(String),
UndefinedReference { kind: String, name: String },
UnclosedIntegerMarker,
}
impl std::fmt::Display for MpsError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
MpsError::IoError(e) => write!(f, "I/O error: {}", e),
MpsError::ParseError { line, message } => {
write!(f, "Parse error at line {}: {}", line, message)
}
MpsError::MissingSection(s) => write!(f, "Missing required section: {}", s),
MpsError::DuplicateSection(s) => write!(f, "Duplicate section: {}", s),
MpsError::InvalidRowType(c) => write!(f, "Invalid row type: {}", c),
MpsError::InvalidBoundType(s) => write!(f, "Invalid bound type: {}", s),
MpsError::UndefinedReference { kind, name } => {
write!(f, "Undefined {} reference: {}", kind, name)
}
MpsError::UnclosedIntegerMarker => {
write!(f, "INTORG marker not closed by a matching INTEND in COLUMNS")
}
}
}
}
impl std::error::Error for MpsError {}
impl From<std::io::Error> for MpsError {
fn from(err: std::io::Error) -> Self {
MpsError::IoError(err)
}
}
#[non_exhaustive]
#[derive(Debug)]
pub enum SolverError {
Mps(MpsError),
DimensionMismatch {
field: &'static str,
expected: usize,
got: usize,
},
IndexOutOfBounds {
context: &'static str,
index: usize,
bound: usize,
},
SingularBasis {
step: usize,
},
EmptyInput {
context: &'static str,
},
DeadlineExceeded,
NonFiniteCoefficient {
field: &'static str,
index: usize,
},
InvalidBounds {
index: usize,
lb: f64,
ub: f64,
},
}
impl std::fmt::Display for SolverError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SolverError::Mps(e) => write!(f, "{}", e),
SolverError::DimensionMismatch { field, expected, got } => {
write!(f, "Dimension mismatch: {} expected {} but got {}", field, expected, got)
}
SolverError::IndexOutOfBounds { context, index, bound } => {
write!(f, "{} index {} out of bounds (size={})", context, index, bound)
}
SolverError::SingularBasis { step } => {
write!(f, "Singular matrix detected at step {}", step)
}
SolverError::EmptyInput { context } => {
write!(f, "Empty input: {}", context)
}
SolverError::DeadlineExceeded => {
write!(f, "Deadline exceeded during computation")
}
SolverError::NonFiniteCoefficient { field, index } => {
write!(f, "Non-finite coefficient in {}: index {}", field, index)
}
SolverError::InvalidBounds { index, lb, ub } => {
write!(f, "Invalid bounds at index {}: lb={} > ub={} or NaN", index, lb, ub)
}
}
}
}
impl std::error::Error for SolverError {}
impl From<MpsError> for SolverError {
fn from(e: MpsError) -> Self {
SolverError::Mps(e)
}
}