simplex_trace/error.rs
1use std::fmt;
2
3/// Errors returned by [`solve`](crate::solve).
4///
5/// Infeasible and unbounded problems are *not* errors: they are reported
6/// through [`Status`](crate::Status).
7#[derive(Clone, Debug, PartialEq, Eq)]
8#[non_exhaustive]
9pub enum Error {
10 /// The problem is malformed (e.g. a constraint with the wrong number of coefficients).
11 InvalidProblem(String),
12 /// [`Method::Simplex`](crate::Method::Simplex) was requested but the problem has `>=` or `=`
13 /// constraints, which need artificial variables. Use `BigM` or `TwoPhase`.
14 ArtificialVariablesRequired,
15 /// The iteration limit in [`Options`](crate::Options) was reached (possible cycling).
16 IterationLimit(usize),
17}
18
19impl fmt::Display for Error {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 match self {
22 Error::InvalidProblem(msg) => write!(f, "invalid problem: {msg}"),
23 Error::ArtificialVariablesRequired => write!(
24 f,
25 "this problem needs artificial variables; use Method::BigM or Method::TwoPhase"
26 ),
27 Error::IterationLimit(n) => write!(f, "iteration limit of {n} reached"),
28 }
29 }
30}
31
32impl std::error::Error for Error {}