27 upperBound = Bounds{std::numeric_limits<double>::infinity(),
false};
37 upperBound = Bounds{std::numeric_limits<double>::infinity(),
false};
70 inline void plus(std::vector<std::shared_ptr<Interval>> &plusIntervals) {
71 plusIntervals.clear();
78 plusIntervals.reserve(m + 1);
79 for (
int i = 1; i < m; i++) {
80 plusIntervals.emplace_back(std::make_shared<Interval>(
84 plusIntervals.emplace_back(std::make_shared<Interval>(
86 Bounds{std::numeric_limits<double>::infinity(),
false}));
89 inline bool contain(
double value)
const {
118 inline static void land(std::vector<std::shared_ptr<Interval>> &left,
120 for (
auto interval : left) {
121 (*interval) = (*interval) && right;
123 left.erase(std::remove_if(left.begin(), left.end(),
124 [](std::shared_ptr<Interval> interval) {
125 return interval->lowerBound >
126 interval->upperBound;
145 inline static void land(std::vector<std::shared_ptr<Interval>> &left,
146 const std::vector<std::shared_ptr<Interval>> &right) {
147 std::vector<std::shared_ptr<Interval>> tmp;
148 for (
auto interval : right) {
149 std::vector<std::shared_ptr<Interval>> tmpL = left;
150 for (
auto &ptr : tmpL) {
151 ptr = std::make_shared<Interval>(*ptr);
153 land(tmpL, *interval);
154 tmp.insert(tmp.end(), tmpL.begin(), tmpL.end());
158 assert(left.size() * right.size() == tmp.size());
190 const std::vector<std::shared_ptr<Interval>> &right) {
191 std::vector<std::shared_ptr<Interval>> ans;
192 ans.reserve(left.size() * right.size());
193 for (
auto intervalLeft : left) {
194 for (
auto intervalRight : right) {
196 std::make_shared<Interval>(*intervalLeft + *intervalRight));
199 left = std::move(ans);
203 inline void plus(std::vector<std::shared_ptr<Interval>> &intervals) {
204 if (intervals.size() >= 32) {
205 throw "too large expression";
207 std::vector<std::vector<std::shared_ptr<Interval>>> plusIntervals;
208 plusIntervals.resize(intervals.size());
209 for (std::size_t i = 0; i < intervals.size(); i++) {
210 if (std::isinf(intervals[i]->upperBound.first)) {
211 plusIntervals[i] = {intervals[i]};
213 intervals[i]->plus(plusIntervals[i]);
216 if (plusIntervals.size() == 1) {
217 intervals = std::move(plusIntervals[0]);
221 std::vector<std::shared_ptr<Interval>> ansIntervals;
222 const uint32_t subsetSize = 1 << intervals.size();
223 for (uint32_t i = 1; i < subsetSize; i++) {
224 std::vector<const std::vector<std::shared_ptr<Interval>> *> subSetVec;
225 subSetVec.reserve(intervals.size());
226 for (std::size_t j = 0; j < intervals.size(); j++) {
228 subSetVec.emplace_back(&(plusIntervals[j]));
231 std::vector<std::shared_ptr<Interval>> tmpIntervals = {
232 std::make_shared<Interval>(Bounds{0,
true}, Bounds{0,
true})};
233 for (
const auto &intervals : subSetVec) {
234 tmpIntervals += *intervals;
236 ansIntervals.insert(ansIntervals.end(), tmpIntervals.begin(),
239 intervals = std::move(ansIntervals);
249 inline static std::ostream &operator<<(std::ostream &stream,
static void land(std::vector< std::shared_ptr< Interval >> &left, const Interval &right)
The intersection of a set of intervals and an interval.
Definition: interval.hh:118
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
static Interval operator&&(const Interval &left, const Interval &right)
The intersection of two intervals.
Definition: interval.hh:98
void plus(std::vector< std::shared_ptr< Interval >> &intervals)
Definition: interval.hh:203
Class for an interval.
Definition: interval.hh:15
Interval(int lower, int upper)
Constructor returning the interval (lower, upper)
Definition: interval.hh:47
void plus(std::vector< std::shared_ptr< Interval >> &plusIntervals)
The Kleene plus operator on intervals in [Dima'00].
Definition: interval.hh:70
Bounds lowerBound
the lower bound of the interval
Definition: interval.hh:17
Bounds upperBound
the upper bound of the interval
Definition: interval.hh:19
Interval(int lower)
Constructor returning the interval (lower, ∞)
Definition: interval.hh:36
Interval()
Defail constructor.
Definition: interval.hh:26