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