Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
QuickHull.h
Go to the documentation of this file.
1#pragma once
2
3#include <set>
4
7
8namespace storm {
9namespace storage {
10namespace geometry {
11
12template<typename ValueType>
13class QuickHull {
14 public:
15 typedef Eigen::Matrix<ValueType, Eigen::Dynamic, Eigen::Dynamic> EigenMatrix;
16 typedef Eigen::Matrix<ValueType, Eigen::Dynamic, 1> EigenVector;
17
18 QuickHull() = default;
19 ~QuickHull() = default;
20
21 /*
22 * Generates the halfspaces of the given set of Points by the QuickHull-algorithm
23 * If the given flag is true, this method will also compute
24 * * the minimal set of vertices which represent the given polytope (can be used to remove redundant vertices), and
25 * * for each hyperplane, the set of (non-redundant) vertices that lie on each hyperplane.
26 *
27 * Use the provided getter methods to retrieve the results
28 *
29 * @return true iff conversion was successful.
30 */
31 void generateHalfspacesFromPoints(std::vector<EigenVector>& points, bool generateRelevantVerticesAndVertexSets);
32
34
36
41 std::vector<EigenVector>& getRelevantVertices();
42
48 std::vector<std::vector<std::uint_fast64_t>>& getVertexSets();
49
50 private:
51 struct Facet {
52 EigenVector normal;
53 ValueType offset;
54 std::vector<uint_fast64_t> points;
55 std::vector<uint_fast64_t> neighbors;
56 // maxOutsidePointIndex and outsideSet will be set in Quickhull algorithm
57 std::vector<uint_fast64_t> outsideSet;
58 uint_fast64_t maxOutsidePointIndex;
59 };
60
61 /*
62 * Properly handles the 1D case
63 *
64 */
65 void handle1DPoints(std::vector<EigenVector>& points, bool generateRelevantVerticesAndVertexSets);
66
67 /*
68 * Returns true if the vertices with index of subset and item are affine independent
69 * Note that this filter also works for dimension()+1 many vertices
70 */
71 static bool affineFilter(std::vector<uint_fast64_t> const& subset, uint_fast64_t const& item, std::vector<EigenVector> const& vertices);
72
73 /*
74 * handles degenerated polytopes
75 *
76 */
77 void handleAffineDependentPoints(std::vector<EigenVector>& points, bool generateRelevantVerticesAndVertexSets);
78
86 bool findInitialVertices(std::vector<EigenVector>& points, std::vector<uint_fast64_t>& verticesOfInitialPolytope) const;
87
91 std::vector<Facet> computeInitialFacets(std::vector<EigenVector> const& points, std::vector<uint_fast64_t> const& verticesOfInitialPolytope,
92 EigenVector const& insidePoint) const;
93
94 // Computes the normal vector and the offset of the given facet from the (dimension many) points specified in the facet.
95 // The insidePoint specifies the orientation of the facet.
96 void computeNormalAndOffsetOfFacet(std::vector<EigenVector> const& points, EigenVector const& insidePoint, Facet& facet) const;
97
98 /*
99 * Extends the given mesh using the QuickHull-algorithm
100 * For optimization reasons a point thats inside of the initial polytope but on none of the facets has to be provided.
101
102 */
103 void extendMesh(std::vector<EigenVector>& points, std::vector<Facet>& facets, storm::storage::BitVector& currentFacets, EigenVector& insidePoint) const;
104
112 void getPolytopeFromMesh(std::vector<EigenVector> const& points, std::vector<Facet> const& facets, storm::storage::BitVector const& currentFacets,
113 bool generateRelevantVerticesAndVertexSets);
114
115 /*
116 * Returns the set of facets visible from point starting with the facet with index startIndex and recursively testing all neighbors
117 */
118 std::set<uint_fast64_t> getVisibleSet(std::vector<Facet> const& facets, uint_fast64_t const& startIndex, EigenVector const& point) const;
119
120 /*
121 * Sets neighborhood for all facets with index >= firstNewFacet in facets
122 */
123 void setNeighborhoodOfNewFacets(std::vector<Facet>& facets, uint_fast64_t firstNewFacet, uint_fast64_t dimension) const;
124
125 /*
126 * replaces oldFacet by newFacet in the neighborhood of neighbor
127 */
128 void replaceFacetNeighbor(std::vector<Facet>& facets, uint_fast64_t oldFacetIndex, uint_fast64_t newFacetIndex, uint_fast64_t neighborIndex) const;
129
130 /*
131 * computes the outside set of the given facet
132 */
133 void computeOutsideSetOfFacet(Facet& facet, storm::storage::BitVector& currentOutsidePoints, std::vector<EigenVector> const& points) const;
134
135 /*
136 * returns common points of lhs and rhs
137 */
138 std::vector<uint_fast64_t> getCommonPoints(Facet const& lhs, Facet const& rhs) const;
139
140 /*
141 * computes all neighbors that are not in the visibleSet
142 */
143 std::set<uint_fast64_t> getInvisibleNeighbors(std::vector<Facet>& facets, std::set<uint_fast64_t> const& visibleSet) const;
144
145 EigenMatrix resultMatrix;
146 EigenVector resultVector;
147 std::vector<EigenVector> relevantVertices;
148 std::vector<std::vector<uint_fast64_t>> vertexSets;
149};
150} // namespace geometry
151} // namespace storage
152} // namespace storm
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
Eigen::Matrix< ValueType, Eigen::Dynamic, Eigen::Dynamic > EigenMatrix
Definition QuickHull.h:15
std::vector< EigenVector > & getRelevantVertices()
Returns the set of vertices which are not redundant.
Definition QuickHull.cpp:65
Eigen::Matrix< ValueType, Eigen::Dynamic, 1 > EigenVector
Definition QuickHull.h:16
void generateHalfspacesFromPoints(std::vector< EigenVector > &points, bool generateRelevantVerticesAndVertexSets)
Definition QuickHull.cpp:19
std::vector< std::vector< std::uint_fast64_t > > & getVertexSets()
Returns for each hyperplane the set of vertices that lie on that hyperplane.
Definition QuickHull.cpp:70