13 #include <boost/unordered_map.hpp>
15 #include "common_types.hh"
16 #include "constraint.hh"
18 using Bounds = std::pair<double, bool>;
19 static inline Bounds
operator+(
const Bounds &a,
const Bounds &b) {
20 return Bounds(a.first + b.first, a.second && b.second);
22 static inline Bounds operator-(
const Bounds &a,
const Bounds &b) {
23 return Bounds(a.first - b.first, a.second && b.second);
25 static inline void operator+=(Bounds &a,
const Bounds b) {
27 a.second = a.second && b.second;
29 static inline std::ostream &operator<<(std::ostream &os,
const Bounds &b) {
30 os <<
"(" << b.first <<
", " << b.second <<
")";
44 using Tuple = std::tuple<std::vector<Bounds>, Bounds>;
45 Eigen::Matrix<Bounds, Eigen::Dynamic, Eigen::Dynamic> value;
52 inline std::size_t
getNumOfVar() const noexcept {
return value.cols() - 1; }
54 inline void cutVars(std::shared_ptr<Zone> &out, std::size_t from,
56 out = std::make_shared<Zone>();
57 out->value.resize(to - from + 2, to - from + 2);
58 out->value.block(0, 0, 1, 1) << Bounds(0,
true);
59 out->value.block(1, 1, to - from + 1, to - from + 1) =
60 value.block(from + 1, from + 1, to - from + 1, to - from + 1);
61 out->value.block(1, 0, to - from + 1, 1) =
62 value.block(from + 1, 0, to - from + 1, 1);
63 out->value.block(0, 1, 1, to - from + 1) =
64 value.block(0, from + 1, 1, to - from + 1);
68 static Zone zero(
int size) {
70 if (zeroZone.value.cols() == size) {
73 zeroZone.value.resize(size, size);
74 zeroZone.value.fill(Bounds(0,
true));
78 static Zone universal(
int size) {
80 static constexpr Bounds infinity =
81 Bounds(std::numeric_limits<double>::infinity(),
false);
82 if (zeroZone.value.cols() == size + 1) {
85 zeroZone.value.resize(size + 1, size + 1);
86 zeroZone.value.fill(infinity);
87 zeroZone.value(0, 0) = Bounds(0,
true);
91 std::tuple<std::vector<Bounds>, Bounds> toTuple()
const {
93 return std::tuple<std::vector<Bounds>, Bounds>(
94 std::vector<Bounds>(value.data() + 1, value.data() + value.size()), M);
98 void tighten(ClockVariables x, ClockVariables y, Bounds c) {
101 value(x, y) = std::min(value(x, y), c);
106 void close1(ClockVariables x) {
107 for (
int i = 0; i < value.rows(); i++) {
109 value.row(i).array().min(value.row(x).array() + value(i, x));
117 void reset(ClockVariables x) {
120 value(0, x) = Bounds(0,
true);
121 value(x, 0) = Bounds(0,
true);
122 value.col(x).tail(value.rows() - 1) = value.col(0).tail(value.rows() - 1);
123 value.row(x).tail(value.cols() - 1) = value.row(0).tail(value.cols() - 1);
127 static constexpr Bounds infinity =
128 Bounds(std::numeric_limits<double>::infinity(),
false);
129 value.col(0).fill(Bounds(infinity));
130 for (
int i = 0; i < value.row(0).size(); ++i) {
131 value.row(0)[i].second =
false;
139 for (
int k = 0; k < value.cols(); k++) {
147 bool isSatisfiable() {
149 return (value + value.transpose()).minCoeff() >= Bounds(0.0,
true);
157 static constexpr Bounds infinity =
158 Bounds(std::numeric_limits<double>::infinity(),
false);
159 for (
auto it = value.data(); it < value.data() + value.size(); it++) {
161 *it = Bounds(infinity);
170 value(0, 0) = Bounds(-std::numeric_limits<double>::infinity(),
false);
175 std::vector<Constraint> guard;
181 Bounds lowerBound = value(0, i + 1);
182 if (lowerBound.first > 0 or
183 (lowerBound.first == 0 and lowerBound.second ==
false)) {
184 if (lowerBound.second) {
190 Bounds upperBound = value(i + 1, 0);
191 if (upperBound < M) {
192 if (upperBound.second) {
202 bool operator==(
Zone z)
const {
203 z.value(0, 0) = value(0, 0);
204 return value == z.value;
207 void intersectionAssign(
Zone z) {
208 assert(value.size() == z.value.size());
209 value.cwiseMin(z.value);
Definition: constraint.hh:73
static Interval operator+(Interval left, const Interval &right)
The sum of two intervals. The formal definition is as follows.
Definition: interval.hh:168
static void operator+=(std::vector< std::shared_ptr< Interval >> &left, const std::vector< std::shared_ptr< Interval >> &right)
The sum of two sets of intervals.
Definition: interval.hh:189
Implementation of a zone with DBM.
Definition: zone.hh:43
void makeUnsat()
make the zone unsatisfiable
Definition: zone.hh:169
void tighten(ClockVariables x, ClockVariables y, Bounds c)
add the constraint x - y \le (c,s)
Definition: zone.hh:98
std::size_t getNumOfVar() const noexcept
Definition: zone.hh:52
std::vector< Constraint > makeGuard()
make the strongest guard including the zone
Definition: zone.hh:174