dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
NumericDataContainer.hpp
1
11#pragma once
12
13#include <iostream>
14#include <type_traits>
15#include <utility>
16
17#include "dlinear/util/concepts.h"
18
19namespace dlinear {
20
30template <Numeric N, std::default_initializable D>
32 using NumericType = N;
33 using DataType = D;
34
35 NumericDataContainer() : numeric{0}, data{} {}
36 explicit NumericDataContainer(N input_numeric) : numeric{input_numeric}, data{} {}
37 NumericDataContainer(N input_numeric, D input_data) : numeric{input_numeric}, data{input_data} {}
38
39 template <std::convertible_to<N> T>
40 std::strong_ordering operator<=>(const NumericDataContainer<T, D> &rhs) const {
41 return numeric < static_cast<N>(rhs.numeric) ? std::strong_ordering::less
42 : numeric > static_cast<N>(rhs.numeric) ? std::strong_ordering::greater
43 : std::strong_ordering::equal;
44 }
45 template <std::convertible_to<N> T>
46 bool operator==(const NumericDataContainer<T, D> &rhs) const {
47 return numeric == N{rhs.numeric};
48 }
49
50 template <std::convertible_to<N> T>
51 std::strong_ordering operator<=>(const T &rhs) const {
52 return numeric < static_cast<N>(rhs) ? std::strong_ordering::less
53 : numeric > static_cast<N>(rhs) ? std::strong_ordering::greater
54 : std::strong_ordering::equal;
55 }
56 template <std::convertible_to<N> T>
57 bool operator==(const T &rhs) const {
58 return numeric == N{rhs};
59 }
60
61 bool EqualTo(const NumericDataContainer<N, D> &rhs) const { return numeric == rhs.numeric && data == rhs.data; }
62
63 template <std::convertible_to<N> T>
64 NumericDataContainer &operator+=(const NumericDataContainer<T, D> &rhs) {
65 numeric += N{rhs.numeric};
66 return *this;
67 }
68 template <std::convertible_to<N> T>
69 NumericDataContainer &operator-=(const NumericDataContainer<T, D> &rhs) {
70 numeric -= N{rhs.numeric};
71 return *this;
72 }
73 template <std::convertible_to<N> T>
74 NumericDataContainer &operator*=(const NumericDataContainer<T, D> &rhs) {
75 numeric *= N{rhs.numeric};
76 return *this;
77 }
78 template <std::convertible_to<N> T>
79 NumericDataContainer &operator/=(const NumericDataContainer<T, D> &rhs) {
80 numeric /= N{rhs.numeric};
81 return *this;
82 }
83
84 template <std::convertible_to<N> T>
85 NumericDataContainer &operator+=(const T &rhs) {
86 numeric += N{rhs};
87 return *this;
88 }
89 template <std::convertible_to<N> T>
90 NumericDataContainer &operator-=(const T &rhs) {
91 numeric -= N{rhs};
92 return *this;
93 }
94 template <std::convertible_to<N> T>
95 NumericDataContainer &operator*=(const T &rhs) {
96 numeric *= N{rhs};
97 return *this;
98 }
99 template <std::convertible_to<N> T>
100 NumericDataContainer &operator/=(const T &rhs) {
101 numeric /= N{rhs};
102 return *this;
103 }
104
105 template <std::convertible_to<N> T>
106 NumericDataContainer operator+(const NumericDataContainer<T, D> &rhs) const {
107 return {numeric + N{rhs.numeric}, data};
108 }
109 template <std::convertible_to<N> T>
110 NumericDataContainer operator-(const NumericDataContainer<T, D> &rhs) const {
111 return {numeric - N{rhs.numeric}, data};
112 }
113 template <std::convertible_to<N> T>
114 NumericDataContainer operator*(const NumericDataContainer<T, D> &rhs) const {
115 return {numeric * N{rhs.numeric}, data};
116 }
117 template <std::convertible_to<N> T>
118 NumericDataContainer operator/(const NumericDataContainer<T, D> &rhs) const {
119 return {numeric / N{rhs.numeric}, data};
120 }
121
122 template <std::convertible_to<N> T>
123 NumericDataContainer operator+(const T &rhs) const {
124 return {numeric + N{rhs}, data};
125 }
126 template <std::convertible_to<N> T>
127 NumericDataContainer operator-(const T &rhs) const {
128 return {numeric - N{rhs}, data};
129 }
130 template <std::convertible_to<N> T>
131 NumericDataContainer operator*(const T &rhs) const {
132 return {numeric * N{rhs}, data};
133 }
134 template <std::convertible_to<N> T>
135 NumericDataContainer operator/(const T &rhs) const {
136 return {numeric / N{rhs}, data};
137 }
138
139 NumericDataContainer operator-() const { return {-numeric, data}; }
140
141 NumericDataContainer &operator++() {
142 ++numeric;
143 return *this;
144 }
145 const NumericDataContainer operator++(int) {
146 NumericDataContainer tmp(*this);
147 operator++();
148 return tmp;
149 }
150 NumericDataContainer &operator--() {
151 --numeric;
152 return *this;
153 }
154 const NumericDataContainer operator--(int) {
155 NumericDataContainer tmp(*this);
156 operator--();
157 return tmp;
158 }
159
160 N numeric;
161 D data;
162};
163
164template <class N, class D, class T>
165NumericDataContainer<N, D> operator+(const T &lhs, const NumericDataContainer<N, D> &rhs) {
166 return {N{lhs} + rhs.numeric, rhs.data};
167}
168template <class N, class D, class T>
169NumericDataContainer<N, D> operator-(const T &lhs, const NumericDataContainer<N, D> &rhs) {
170 return {N{lhs} - rhs.numeric, rhs.data};
171}
172template <class N, class D, class T>
173NumericDataContainer<N, D> operator*(const T &lhs, const NumericDataContainer<N, D> &rhs) {
174 return {N{lhs} * rhs.numeric, rhs.data};
175}
176template <class N, class D, class T>
177NumericDataContainer<N, D> operator/(const T &lhs, const NumericDataContainer<N, D> &rhs) {
178 return {N{lhs} / rhs.numeric, rhs.data};
179}
180
181template <class N, class D, class T>
182std::strong_ordering operator<=>(const T &lhs, const NumericDataContainer<N, D> &rhs) {
183 return static_cast<N>(lhs) < rhs.numeric ? std::strong_ordering::less
184 : static_cast<N>(lhs) > rhs.numeric ? std::strong_ordering::greater
185 : std::strong_ordering::equal;
186}
187
188template <class N, class D>
189std::ostream &operator<<(std::ostream &os, const NumericDataContainer<N, D> &ndc) {
190 return os << "{" << ndc.numeric << ", " << ndc.data << "}";
191}
192
193} // namespace dlinear
@ N
No sense, used for the objective function.
Global namespace for the dlinear library.
@ D
Variable must be different from the bound.
LpColBound operator-(LpColBound bound)
Invert the bound with delta > 0.
STL namespace.
NumericDataContainer class.