use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
InvalidProblem(String),
ArtificialVariablesRequired,
NotDualFeasible(String),
NotOptimal,
IterationLimit(usize),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::InvalidProblem(msg) => write!(f, "invalid problem: {msg}"),
Error::ArtificialVariablesRequired => write!(
f,
"this problem needs artificial variables; use Method::BigM or Method::TwoPhase"
),
Error::NotDualFeasible(msg) => write!(
f,
"the dual simplex cannot start from the slack basis: {msg}; use Method::BigM or Method::TwoPhase"
),
Error::NotOptimal => write!(
f,
"the previous solution is not optimal; solve the extended problem from scratch"
),
Error::IterationLimit(n) => write!(f, "iteration limit of {n} reached"),
}
}
}
impl std::error::Error for Error {}