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