lpinterface
 All Classes Namespaces Files Functions Variables Enumerations Enumerator
errors.hpp
1 #ifndef LPINTERFACE_ERRORS_H
2 #define LPINTERFACE_ERRORS_H
3 
4 #include <exception>
5 #include <iostream>
6 #include <sstream>
7 
8 namespace lpint {
9 
17 class LpException : public std::runtime_error {
18  public:
19  explicit LpException(const char *msg) : std::runtime_error(msg) {}
20 
21  template <typename... Args>
22  explicit LpException(Args &&... args)
23  : std::runtime_error(std::forward<Args>(args)...) {}
24 };
25 
28  public:
29  NotImplementedError() : LpException("Feature not implemented") {}
30 };
31 
34  public:
35  ModelNotSolvedException() : LpException("Model has not yet been solved") {}
36 };
37 
40  public:
42  : LpException("Invalid parameter was supplied") {}
43 };
44 
48  public:
50  : LpException("Unsupported constraint type was supplied") {}
51 };
52 
55  public:
57  : LpException(
58  "Invalid matrix entry; does your row/column contain duplicate "
59  "indices?") {}
60 };
61 
64  public:
66  : LpException("Unsupported variable type for this backend") {}
67 };
68 
71  public:
73  : LpException("Variable lower bound should be smaller than upper bound") {}
74 };
75 
77 class GurobiException : public LpException {
78  public:
79  explicit GurobiException(int code)
80  : LpException("Error occured in Gurobi, code " + std::to_string(code)),
81  code_(code) {}
82 
83  GurobiException(int code, const char *msg)
84  : LpException("Error occured in Gurobi, code " + std::to_string(code) +
85  " - " + std::string(msg)),
86  code_(code) {}
87 
88  int code() const { return code_; }
89 
90  private:
91  int code_;
92 };
93 
96  public:
97  explicit UnknownStatusException(int code)
98  : LpException("Unknown status code encountered: " +
99  std::to_string(code)) {}
100 };
101 
104  public:
106  : LpException("Feature not available for this solver backend") {}
107 };
108 
111  public:
113  : LpException("Failed to set an LP solver parameter") {}
114 };
115 
117 class SoplexException : public LpException {
118  public:
119  SoplexException() : LpException("SoPlex ran into an error solving an LP") {}
120 };
121 
123  public:
125  : LpException("Array dimensions mismatched") {}
126 };
127 
129 enum class Status : int {
131  NotLoaded,
135  Optimal,
137  Infeasible,
141  Unbounded,
144  Cutoff,
149  NodeLimit,
151  TimeOut,
155  Interrupted,
161  InProgress,
167  NoPricer,
169  NoSolver,
175  Cycling,
183  Regular,
184 };
185 
186 // LCOV_EXCL_START
187 inline std::ostream &operator<<(std::ostream &os, const Status &status) {
188  os << static_cast<int>(status);
189  return os;
190 }
191 // LCOV_EXCL_STOP
192 
193 } // namespace lpint
194 
195 #endif // LPINTERFACE_ERRORS_H
Equivalent to SoPlex NOT_INIT status.
Attempt to construct a variable with invalid bounds.
Definition: errors.hpp:70
Solutions found exceeded solution limit.
No Linear Program has been loaded.
Model was proven to be unbounded.
Attempt set a parameter that is not supported by the current backend.
Definition: errors.hpp:39
No pricer loaded (SoPlex).
Attempt to use a status code that is not supported.
Definition: errors.hpp:95
Optimization is currently in progress.
Class for wrapping exception occurring in lpinterface. The linear program interface can return errors...
Definition: errors.hpp:17
Model was proven to be infeasible.
Solving process aborted as objective limit has been reached.
Attempt to use a variable type that is not supported by the current backend.
Definition: errors.hpp:63
LP has a usable basis (SoPlex).
Attempt to add a matrix entry containing duplicate indices.
Definition: errors.hpp:54
Solving process aborted due to presence of cycling.
Definition: errors.hpp:122
Solving process aborted due to commence decomposition simplex (SoPlex).
Optimization interrupted by user.
Failed to set a parameter value.
Definition: errors.hpp:110
Attempt to use a feature that is not supported by the current backend.
Definition: errors.hpp:103
No solver loaded.
Time limit reached.
Number of iterations exceeded user-specified iteration limit.
User-specified objective limit has been reached.
Model was solved to optimality, solution available.
Solving process aborted to exit decomposition simplex (SoPlex).
Could not satisfy tolerances; sub-optimal solution is available.
No ratiotester loaded (SoPlex).
Internal error occured in SoPlex.
Definition: errors.hpp:117
Definition: errors.hpp:47
Model was proven to be either infeasible or unbounded.
Linear program loaded, but no solution information available.
Optimizer ran into unrecoverable numerical difficulties.
Attempt to access solution of an unsolved model.
Definition: errors.hpp:33
Status
Enum class representing LP solution status.
Definition: errors.hpp:129
Internal error occured in Gurobi.
Definition: errors.hpp:77
Attempt to use a feature that is not yet implemented.
Definition: errors.hpp:27
Problem solved to optimality, but unscaled solution contains violations.