Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Halfspace.h
Go to the documentation of this file.
1#pragma once
2
3#include <iomanip>
4#include <iostream>
9
10namespace storm {
11namespace storage {
12namespace geometry {
13
14/*
15 * This class represents a closed Halfspace, i.e., the set { x | a*x<=c } for a normalVector a and an offset c
16 */
17
18template<typename ValueType>
19class Halfspace {
20 public:
21 Halfspace(std::vector<ValueType> const& normalVector, ValueType const& offset) : mNormalVector(normalVector), mOffset(offset) {
22 // Intentionally left empty
23 }
24
25 Halfspace(std::vector<ValueType>&& normalVector, ValueType&& offset) : mNormalVector(normalVector), mOffset(offset) {
26 // Intentionally left empty
27 }
28
29 /*
30 * Returns true iff the given point is contained in this halfspace, i.e., normalVector*point <= offset holds.
31 */
32 bool contains(std::vector<ValueType> const& point) const {
34 }
35
36 /*
37 * Returns the (scaled) distance of the given point from this halfspace.
38 * If the point is inside this halfspace, the distance is 0.
39 * The returned value is the euclidean distance times the 2-norm of the normalVector.
40 * In contrast to the euclideanDistance method, there are no inaccuracies introduced (providing ValueType is exact for +, -, and *)
41 */
42 ValueType distance(std::vector<ValueType> const& point) const {
44 }
45
46 /*
47 * Returns the euclidean distance of the point from this halfspace.
48 * If the point is inside this halfspace, the distance is 0.
49 * Note that the euclidean distance is in general not a rational number (which can introduce inaccuracies).
50 */
51 ValueType euclideanDistance(std::vector<ValueType> const& point) const {
52 // divide the distance with the 2-norm of the normal vector
54 }
55
56 /*
57 * Returns true iff the given point lies on the boundary of this halfspace (i.e., on the hyperplane given by normalVector()*x =offset
58 */
59 bool isPointOnBoundary(std::vector<ValueType> const& point) const {
61 }
62
63 /*
64 * Returns the inverted Halfspace of this which represents the set (R^n \ this) union { x | x is on the boundary of this}
65 */
67 std::vector<ValueType> resNormalVector = normalVector();
69 return Halfspace<ValueType>(std::move(resNormalVector), -offset());
70 }
71
72 /*
73 * Returns a string representation of this Halfspace.
74 * If the given flag is true, the occurring numbers are converted to double before printing to increase readability
75 */
76 std::string toString(bool numbersAsDouble = false) const {
77 std::stringstream stream;
78 stream << "(";
79 for (auto it = normalVector().begin(); it != normalVector().end(); ++it) {
80 if (it != normalVector().begin()) {
81 stream << ", ";
82 }
83 std::stringstream numberStream;
84 if (numbersAsDouble) {
85 numberStream << storm::utility::convertNumber<double>(*it);
86 } else {
87 numberStream << *it;
88 }
89 stream << std::setw(10) << numberStream.str();
90 }
91 stream << ") * x <= ";
92 if (numbersAsDouble) {
93 stream << storm::utility::convertNumber<double>(offset());
94 } else {
95 stream << offset();
96 }
97 return stream.str();
98 }
99
101 std::vector<storm::expressions::Variable> const& variables) {
102 STORM_LOG_ASSERT(variables.size() == normalVector().size(), "Dimension missmatch.");
103 STORM_LOG_ASSERT(normalVector().size() != 0, "Invalid dimension.");
104 storm::expressions::Expression lhs = manager.rational(normalVector()[0]) * variables[0].getExpression();
105 for (uint64_t dim = 1; dim < normalVector().size(); ++dim) {
106 lhs = lhs + manager.rational(normalVector()[dim]) * variables[dim].getExpression();
107 }
108 return lhs <= manager.rational(offset());
109 }
110
111 std::vector<ValueType> const& normalVector() const {
112 return mNormalVector;
113 }
114
115 std::vector<ValueType>& normalVector() {
116 return mNormalVector;
117 }
118
119 ValueType const& offset() const {
120 return mOffset;
121 }
122
123 ValueType& offset() {
124 return mOffset;
125 }
126
127 private:
128 std::vector<ValueType> mNormalVector;
129 ValueType mOffset;
130};
131} // namespace geometry
132} // namespace storage
133} // namespace storm
This class is responsible for managing a set of typed variables and all expressions using these varia...
ValueType euclideanDistance(std::vector< ValueType > const &point) const
Definition Halfspace.h:51
bool contains(std::vector< ValueType > const &point) const
Definition Halfspace.h:32
Halfspace< ValueType > invert() const
Definition Halfspace.h:66
std::vector< GeometryValueType > const & normalVector() const
Definition Halfspace.h:111
Halfspace(std::vector< ValueType > const &normalVector, ValueType const &offset)
Definition Halfspace.h:21
ValueType distance(std::vector< ValueType > const &point) const
Definition Halfspace.h:42
std::string toString(bool numbersAsDouble=false) const
Definition Halfspace.h:76
bool isPointOnBoundary(std::vector< ValueType > const &point) const
Definition Halfspace.h:59
Halfspace(std::vector< ValueType > &&normalVector, ValueType &&offset)
Definition Halfspace.h:25
storm::expressions::Expression toExpression(storm::expressions::ExpressionManager const &manager, std::vector< storm::expressions::Variable > const &variables)
Definition Halfspace.h:100
std::vector< ValueType > & normalVector()
Definition Halfspace.h:115
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
T dotProduct(std::vector< T > const &firstOperand, std::vector< T > const &secondOperand)
Computes the dot product (aka scalar product) and returns the result.
Definition vector.h:473
void scaleVectorInPlace(std::vector< ValueType1 > &target, ValueType2 const &factor)
Multiplies each element of the given vector with the given factor and writes the result into the vect...
Definition vector.h:447
ValueType zero()
Definition constants.cpp:24
ValueType one()
Definition constants.cpp:19
ValueType sqrt(ValueType const &number)