idol
A C++ Framework for Optimization
Loading...
Searching...
No Matches
types.h
1//
2// Created by henri on 13/02/23.
3//
4
5#ifndef IDOL_SOLUTION_TYPES_H
6#define IDOL_SOLUTION_TYPES_H
7
8#include <string>
9#include <stdexcept>
10#include <ostream>
11#include <iomanip>
12#include "idol/general/utils/exceptions/Exception.h"
13
14namespace idol {
15
16 enum SolutionStatus {
17 Loaded = 0,
18 Optimal = 1,
19 Feasible = 2,
20 Infeasible = 3,
21 InfOrUnbnd = 4,
22 Unbounded = 5,
23 Fail = 6,
24 SubOptimal = 7
25 };
26
27 enum SolutionReason {
28 NotSpecified = 0,
29 Proved = 1,
30 TimeLimit = 2,
31 IterLimit = 3,
32 ObjLimit = 4,
33 Numerical = 5,
34 MemoryLimit = 6,
35 Cycling = 7,
36 SolutionLimit = 8
37 };
38
39 template<class T>
40 bool is_in();
41
42 template<typename T>
43 bool is_in(T t_status, std::initializer_list<T> t_list) {
44 for (auto status: t_list) {
45 if (status == t_status) {
46 return true;
47 }
48 }
49 return false;
50 }
51
52 template<typename T>
53 bool is_in(typename T::value_type t_status, const T &t_list) {
54 for (auto status: t_list) {
55 if (status == t_status) {
56 return true;
57 }
58 }
59 return false;
60 }
61
62 static SolutionStatus dual(SolutionStatus t_status) {
63 switch (t_status) {
64 case Loaded:
65 return Loaded;
66 case Optimal:
67 return Optimal;
68 case Feasible:
69 return SubOptimal;
70 case Infeasible:
71 return Unbounded;
72 case InfOrUnbnd:
73 return InfOrUnbnd;
74 case Unbounded:
75 return Infeasible;
76 case Fail:
77 return Fail;
78 case SubOptimal:
79 return Feasible;
80 }
81 throw Exception("Unexpected status: " + std::to_string(t_status));
82 }
83
84 static std::ostream &operator<<(std::ostream &t_os, SolutionStatus t_status) {
85
86 switch (t_status) {
87 case Loaded:
88 return t_os << "Loaded";
89 case Optimal:
90 return t_os << "Optimal";
91 case Feasible:
92 return t_os << "Feasible";
93 case Infeasible:
94 return t_os << "Infeasible";
95 case InfOrUnbnd:
96 return t_os << "InfOrUnbnd";
97 case Unbounded:
98 return t_os << "Unbounded";
99 case Fail:
100 return t_os << "Fail";
101 case SubOptimal:
102 return t_os << "SubOptimal";
103 default:;
104 }
105
106 throw Exception("Unexpected status: " + std::to_string(t_status));
107 }
108
109 static std::ostream &operator<<(std::ostream &t_os, SolutionReason t_status) {
110
111 switch (t_status) {
112 case Proved:
113 return t_os << "Proved";
114 case NotSpecified:
115 return t_os << "-";
116 case TimeLimit:
117 return t_os << "TimeLimit";
118 case IterLimit:
119 return t_os << "IterLimit";
120 case ObjLimit:
121 return t_os << "ObjLimit";
122 case Numerical:
123 return t_os << "Numerical";
124 case MemoryLimit:
125 return t_os << "MemoryLimit";
126 case Cycling:
127 return t_os << "Cycling";
128 case SolutionLimit:
129 return t_os << "SolutionLimit";
130 default:;
131 }
132
133 throw Exception("Unexpected status: " + std::to_string(t_status));
134 }
135
136}
137
138#endif //IDOL_SOLUTION_TYPES_H