dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
BoundType.cpp
1
7#include "BoundType.h"
8
9#include <iostream>
10
11#include "dlinear/util/exception.h"
12
13namespace dlinear::mps {
14
15BoundType ParseBoundType(const std::string& bound_type) { return ParseBoundType(bound_type.c_str()); }
16
17BoundType ParseBoundType(const char bound_type[]) {
18 while (*bound_type == ' ') ++bound_type;
19 DLINEAR_ASSERT(strlen(bound_type) == 2, "Bound type must be exactly 2 characters long");
20 if (bound_type[2] != '\0' && bound_type[2] != ' ') DLINEAR_RUNTIME_ERROR_FMT("Invalid bound type: '{}'", bound_type);
21 if ((bound_type[0] == 'l' || bound_type[0] == 'L') && (bound_type[1] == 'o' || bound_type[1] == 'O')) {
22 return BoundType::LO;
23 }
24 if ((bound_type[0] == 'l' || bound_type[0] == 'L') && (bound_type[1] == 'i' || bound_type[1] == 'I')) {
25 return BoundType::LI;
26 }
27 if ((bound_type[0] == 'u' || bound_type[0] == 'U') && (bound_type[1] == 'p' || bound_type[1] == 'P')) {
28 return BoundType::UP;
29 }
30 if ((bound_type[0] == 'u' || bound_type[0] == 'U') && (bound_type[1] == 'i' || bound_type[1] == 'I')) {
31 return BoundType::UI;
32 }
33 if ((bound_type[0] == 'f' || bound_type[0] == 'F') && (bound_type[1] == 'x' || bound_type[1] == 'X')) {
34 return BoundType::FX;
35 }
36 if ((bound_type[0] == 'f' || bound_type[0] == 'F') && (bound_type[1] == 'r' || bound_type[1] == 'R')) {
37 return BoundType::FR;
38 }
39 if ((bound_type[0] == 'm' || bound_type[0] == 'M') && (bound_type[1] == 'i' || bound_type[1] == 'I')) {
40 return BoundType::MI;
41 }
42 if ((bound_type[0] == 'p' || bound_type[0] == 'P') && (bound_type[1] == 'l' || bound_type[1] == 'L')) {
43 return BoundType::PL;
44 }
45 if ((bound_type[0] == 'b' || bound_type[0] == 'B') && (bound_type[1] == 'v' || bound_type[1] == 'V')) {
46 return BoundType::BV;
47 }
48 DLINEAR_RUNTIME_ERROR_FMT("Invalid bound type: '{}'", bound_type);
49}
50
51std::ostream& operator<<(std::ostream& os, const BoundType& bound) {
52 switch (bound) {
53 case BoundType::LO:
54 return os << "LO";
55 case BoundType::LI:
56 return os << "LI";
57 case BoundType::UP:
58 return os << "UP";
59 case BoundType::UI:
60 return os << "UI";
61 case BoundType::FX:
62 return os << "FX";
63 case BoundType::FR:
64 return os << "FR";
65 case BoundType::MI:
66 return os << "MI";
67 case BoundType::PL:
68 return os << "PL";
69 case BoundType::BV:
70 return os << "BV";
71 default:
72 DLINEAR_UNREACHABLE();
73 }
74}
75
76} // namespace dlinear::mps
Namespace for the MPS parser of the dlinear library.
Definition BoundType.cpp:13
BoundType
Bound type.
Definition BoundType.h:27
BoundType ParseBoundType(const std::string &bound_type)
Parse a bound type from a string.
Definition BoundType.cpp:15