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