Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Hyperrectangle.h
Go to the documentation of this file.
1#pragma once
2
3#include <iomanip>
4#include <iostream>
5
10
11namespace storm {
12namespace storage {
13namespace geometry {
14
15/*
16 * This class represents a hyperrectangle, i.e., the intersection of finitely many intervals
17 */
18
19template<typename ValueType>
21 public:
22 Hyperrectangle(std::vector<ValueType> const& lowerBounds, std::vector<ValueType> const& upperBounds)
23 : mLowerBounds(lowerBounds), mUpperBounds(upperBounds) {
24 STORM_LOG_THROW(lowerBounds.size() == upperBounds.size(), storm::exceptions::InvalidArgumentException,
25 "Tried to construct a hyperrectangle but the number of given lower bounds does not equal the number of given upper bounds.");
26 }
27
28 Hyperrectangle(std::vector<ValueType>&& lowerBounds, std::vector<ValueType>&& upperBounds) : mLowerBounds(lowerBounds), mUpperBounds(upperBounds) {
29 STORM_LOG_THROW(lowerBounds.size() == upperBounds.size(), storm::exceptions::InvalidArgumentException,
30 "Tried to construct a hyperrectangle but the number of given lower bounds does not equal the number of given upper bounds.");
31 }
32
33 std::vector<ValueType> const& lowerBounds() const {
34 return mLowerBounds;
35 }
36
37 std::vector<ValueType>& lowerBounds() {
38 return mLowerBounds;
39 }
40
41 std::vector<ValueType> const& upperBounds() const {
42 return mUpperBounds;
43 }
44
45 std::vector<ValueType>& upperBounds() {
46 return mUpperBounds;
47 }
48
49 /*
50 * Enlarges this hyperrectangle such that it contains the given point
51 */
52 void enlarge(std::vector<ValueType> const& point) {
53 STORM_LOG_THROW(point.size() == lowerBounds().size() && point.size() == upperBounds().size(), storm::exceptions::InvalidArgumentException,
54 "Tried to enlarge a hyperrectangle but the dimension of the given point does not match.");
55 for (uint_fast64_t i = 0; i < lowerBounds().size(); ++i) {
56 lowerBounds()[i] = std::min(lowerBounds()[i], point[i]);
57 upperBounds()[i] = std::max(upperBounds()[i], point[i]);
58 }
59 }
60
61 std::shared_ptr<Polytope<ValueType>> asPolytope() const {
62 STORM_LOG_THROW(lowerBounds().size() == upperBounds().size(), storm::exceptions::InvalidArgumentException,
63 "Tried to construct a polytope form a hyperrectangle but the numbers of given lower and upper bounds do not match.");
64 std::vector<Halfspace<ValueType>> halfspaces;
65 halfspaces.reserve(2 * lowerBounds().size());
66 for (uint_fast64_t i = 0; i < lowerBounds().size(); ++i) {
67 std::vector<ValueType> direction(lowerBounds().size(), storm::utility::zero<ValueType>());
68 direction[i] = -storm::utility::one<ValueType>();
69 ValueType offset = -lowerBounds()[i];
70 halfspaces.emplace_back(std::move(direction), std::move(offset));
71
72 direction = std::vector<ValueType>(lowerBounds().size(), storm::utility::zero<ValueType>());
73 direction[i] = storm::utility::one<ValueType>();
74 offset = upperBounds()[i];
75 halfspaces.emplace_back(std::move(direction), std::move(offset));
76 }
77 return Polytope<ValueType>::create(halfspaces);
78 }
79
80 private:
81 std::vector<ValueType> mLowerBounds;
82 std::vector<ValueType> mUpperBounds;
83};
84} // namespace geometry
85} // namespace storage
86} // namespace storm
Hyperrectangle(std::vector< ValueType > const &lowerBounds, std::vector< ValueType > const &upperBounds)
void enlarge(std::vector< ValueType > const &point)
std::vector< ValueType > const & lowerBounds() const
std::shared_ptr< Polytope< ValueType > > asPolytope() const
std::vector< ValueType > const & upperBounds() const
std::vector< ValueType > & upperBounds()
std::vector< ValueType > & lowerBounds()
Hyperrectangle(std::vector< ValueType > &&lowerBounds, std::vector< ValueType > &&upperBounds)
static std::shared_ptr< Polytope< ValueType > > create(std::vector< Halfspace< ValueType > > const &halfspaces)
Creates a polytope from the given halfspaces.
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28
ValueType zero()
Definition constants.cpp:24
ValueType one()
Definition constants.cpp:19