Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
PolytopeTree.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <vector>
6
7namespace storm {
8namespace storage {
9namespace geometry {
10
18template<typename ValueType>
20 public:
21 PolytopeTree(std::shared_ptr<Polytope<ValueType>> const& polytope = nullptr) : polytope(polytope) {
22 // Intentionally left empty
23 }
24
29 void setMinus(std::shared_ptr<Polytope<ValueType>> const& rhs) {
30 // This operation only has an effect if the intersection of this and rhs is non-empty.
31 if (!isEmpty() && !polytope->intersection(rhs)->isEmpty()) {
32 if (children.empty()) {
33 // This is a leaf node.
34 // Apply splitting.
35 auto newChildren = polytope->setMinus(rhs);
36 if (newChildren.empty()) {
37 // Delete this node.
38 polytope = nullptr;
39 } else if (newChildren.size() == 1) {
40 // Replace this node with its only child
41 polytope = newChildren.front()->clean();
42 } else {
43 // Add the new children to this node. There is no need to traverse them.
44 for (auto& c : newChildren) {
45 children.push_back(c->clean());
46 }
47 }
48 } else {
49 // This is an inner node. Traverse the children and set this to the convex union of its children.
50 std::vector<PolytopeTree<ValueType>> newChildren;
51 std::vector<std::vector<ValueType>> newPolytopeVertices;
52 for (auto& c : children) {
53 c.setMinus(rhs);
54 if (c.polytope != nullptr) {
55 newChildren.push_back(c);
56 auto cVertices = c.polytope->getVertices();
57 newPolytopeVertices.insert(newPolytopeVertices.end(), cVertices.begin(), cVertices.end());
58 }
59 }
60 if (newPolytopeVertices.empty()) {
61 polytope = nullptr;
62 } else {
63 polytope = storm::storage::geometry::Polytope<ValueType>::create(newPolytopeVertices);
64 }
65 children = std::move(newChildren);
66 }
67 }
68 }
69
75 void substractDownwardClosure(std::vector<ValueType> const& point) {
77 }
78
84 void substractDownwardClosure(std::vector<ValueType> const& point, std::vector<ValueType> const& offset) {
85 assert(point.size() == offset.size());
86 std::vector<ValueType> pointPrime(point.size());
87 storm::utility::vector::addVectors(point, offset, pointPrime);
89 }
90
94 bool isEmpty() const {
95 return polytope == nullptr;
96 }
97
101 void clear() {
102 children.clear();
103 polytope = nullptr;
104 }
105
109 std::shared_ptr<Polytope<ValueType>>& getPolytope() {
110 return polytope;
111 }
112
116 std::vector<PolytopeTree>& getChildren() {
117 return children;
118 }
119
120 std::string toId() {
121 if (isEmpty()) {
122 return "empty";
123 }
124 std::stringstream s;
125 s << "p";
126 auto vertices = getPolytope()->getVertices();
127 for (auto const& v : vertices) {
128 s << "_";
129 for (auto const& vi : v) {
130 s << storm::utility::convertNumber<double>(vi) << "-";
131 }
132 }
133 s << "_id" << children.data();
134 return s.str();
135 }
136
140 std::string toString() {
141 if (isEmpty()) {
142 return "Empty PolytopeTree";
143 }
144 std::stringstream s;
145 s << "PolytopeTree node with " << getChildren().size() << " children: " << getPolytope()->toString(true) << "\nVertices: ";
146 auto vertices = getPolytope()->getVertices();
147 for (auto const& v : vertices) {
148 s << "[";
149 for (auto const& vi : v) {
150 s << storm::utility::convertNumber<double>(vi) << ",";
151 }
152 s << "]\t";
153 }
154 s << '\n';
155 return s.str();
156 }
157
158 private:
159 std::shared_ptr<Polytope<ValueType>> polytope;
160 std::vector<PolytopeTree<ValueType>> children;
161};
162} // namespace geometry
163} // namespace storage
164} // namespace storm
static std::shared_ptr< Polytope< ValueType > > create(std::vector< Halfspace< ValueType > > const &halfspaces)
Creates a polytope from the given halfspaces.
Represents a set of points in Euclidean space.
std::shared_ptr< Polytope< ValueType > > & getPolytope()
Gets the polytope at this node.
void substractDownwardClosure(std::vector< ValueType > const &point)
Substracts the downward closure of the given point from this set.
void setMinus(std::shared_ptr< Polytope< ValueType > > const &rhs)
Substracts the given rhs from this polytope.
PolytopeTree(std::shared_ptr< Polytope< ValueType > > const &polytope=nullptr)
bool isEmpty() const
Returns true if this is the empty set.
std::vector< PolytopeTree > & getChildren()
Gets the children at this node.
std::string toString()
Returns a string representation of this node (for debugging purposes)
void clear()
Clears all contents of this set, making it the empty set.
void substractDownwardClosure(std::vector< ValueType > const &point, std::vector< ValueType > const &offset)
Substracts the downward closure of the given point from this set.
void addVectors(std::vector< InValueType1 > const &firstOperand, std::vector< InValueType2 > const &secondOperand, std::vector< OutValueType > &target)
Adds the two given vectors and writes the result to the target vector.
Definition vector.h:443
LabParser.cpp.
Definition cli.cpp:18