Browse Source

first steps for geometric representations

Former-commit-id: f62794ab24
tempestpy_adaptions
TimQu 9 years ago
parent
commit
a3e0a3c55b
  1. 2
      src/CMakeLists.txt
  2. 1
      src/modelchecker/multiobjective/helper/SparseMdpMultiObjectivePreprocessingHelper.cpp
  3. 51
      src/storage/geometry/Halfspace.h
  4. 18
      src/storage/geometry/Polytope.cpp
  5. 98
      src/storage/geometry/Polytope.h
  6. 29
      src/utility/vector.h

2
src/CMakeLists.txt

@ -47,6 +47,7 @@ file(GLOB STORM_STORAGE_DFT_ELEMENTS_FILES ${PROJECT_SOURCE_DIR}/src/storage/dft
file(GLOB_RECURSE STORM_STORAGE_DD_CUDD_FILES ${PROJECT_SOURCE_DIR}/src/storage/dd/cudd/*.h ${PROJECT_SOURCE_DIR}/src/storage/dd/cudd/*.cpp)
file(GLOB_RECURSE STORM_STORAGE_DD_SYLVAN_FILES ${PROJECT_SOURCE_DIR}/src/storage/dd/sylvan/*.h ${PROJECT_SOURCE_DIR}/src/storage/dd/sylvan/*.cpp)
file(GLOB_RECURSE STORM_STORAGE_EXPRESSIONS_FILES ${PROJECT_SOURCE_DIR}/src/storage/expressions/*.h ${PROJECT_SOURCE_DIR}/src/storage/expressions/*.cpp)
file(GLOB_RECURSE STORM_STORAGE_GEOMETRY_FILES ${PROJECT_SOURCE_DIR}/src/storage/geometry/*.h ${PROJECT_SOURCE_DIR}/src/storage/geometry/*.cpp)
file(GLOB_RECURSE STORM_STORAGE_PRISM_FILES ${PROJECT_SOURCE_DIR}/src/storage/prism/*.h ${PROJECT_SOURCE_DIR}/src/storage/prism/*.cpp)
file(GLOB_RECURSE STORM_STORAGE_SPARSE_FILES ${PROJECT_SOURCE_DIR}/src/storage/sparse/*.h ${PROJECT_SOURCE_DIR}/src/storage/sparse/*.cpp)
file(GLOB_RECURSE STORM_UTILITY_FILES ${PROJECT_SOURCE_DIR}/src/utility/*.h ${PROJECT_SOURCE_DIR}/src/utility/*.cpp)
@ -106,6 +107,7 @@ source_group(storage\\prism FILES ${STORM_STORAGE_PRISM_FILES})
source_group(storage\\sparse FILES ${STORM_STORAGE_SPARSE_FILES})
source_group(storage\\dft FILES ${STORM_STORAGE_DFT_FILES})
source_group(storage\\dft\\elements FILES ${STORM_STORAGE_DFT_ELEMENTS_FILES})
source_group(storage\\geometry FILES ${STORM_STORAGE_GEOMETRY_FILES})
source_group(utility FILES ${STORM_UTILITY_FILES})
# Add custom additional include or link directories

1
src/modelchecker/multiobjective/helper/SparseMdpMultiObjectivePreprocessingHelper.cpp

@ -195,7 +195,6 @@ namespace storm {
if(info.negatedRewardsConsidered){
storm::utility::vector::scaleVectorInPlace(objectiveRewards, -storm::utility::one<ValueType>());
}
std::cout << objectiveRewards.size() << "==" << info.model.getTransitionMatrix().getRowCount() << "!=" << info.model.getNumberOfStates() << std::endl;
info.model.addRewardModel(currentObjective.rewardModelName, RewardModelType(boost::none, objectiveRewards));
}

51
src/storage/geometry/Halfspace.h

@ -0,0 +1,51 @@
#ifndef STORM_STORAGE_GEOMETRY_HALFSPACE_H_
#define STORM_STORAGE_GEOMETRY_HALFSPACE_H_
#include <iostream>
#include "src/utility/vector.h"
namespace storm {
namespace storage {
namespace geometry {
/*
* This class represents a closed Halfspace, i.e., the set { x | a*x<=c } for a normalVector a and an offset c
*/
template <typename ValueType>
struct HalfSpace {
HalfSpace(std::vector<ValueType> const& normalVector, ValueType const& offset) : normalVector(normalVector), offset(offset) {
//Intentionally left empty
}
HalfSpace(std::vector<ValueType>&& normalVector, ValueType&& offset) : normalVector(normalVector), offset(offset) {
//Intentionally left empty
}
bool contains(std::vector<ValueType> const& point) {
return storm::utility::vector::multiplyVectors(point, normalVector) <= offset;
}
std::vector<ValueType> normalVector;
ValueType offset;
std::string toString() {
std::stringstream stream;
stream << "(";
for(auto it = normalVector.begin(); it != normalVector.end(); ++it){
if(it != normalVector.begin()){
stream << ", ";
}
stream << *it;
}
stream << ") * x <= " << offset;
return stream.str();
}
}
}
}
}
#endif /* STORM_STORAGE_GEOMETRY_HALFSPACE_H_ */

18
src/storage/geometry/Polytope.cpp

@ -0,0 +1,18 @@
#ifndef STORM_STORAGE_GEOMETRY_POLYTOPE_H_
#define STORM_STORAGE_GEOMETRY_POLYTOPE_H_
#include <vector>
#include <memory>
namespace storm {
namespace storage {
namespace geometry {
}
}
}
#endif /* STORM_STORAGE_GEOMETRY_POLYTOPE_H_ */

98
src/storage/geometry/Polytope.h

@ -0,0 +1,98 @@
#ifndef STORM_STORAGE_GEOMETRY_POLYTOPE_H_
#define STORM_STORAGE_GEOMETRY_POLYTOPE_H_
#include <vector>
#include <memory>
#include "src/storage/geometry/HalfSpace.h"
namespace storm {
namespace storage {
namespace geometry {
template <typename ValueType>
class Polytope {
public:
typedef std::vector<ValueType> point_t;
typedef HalfSpace<ValueType> halfspace_t;
/*!
* Creates a polytope from the given points (i.e., the convex hull of the points).
* If the vector of points is empty, the resulting polytope be empty.
*/
static std::shared_ptr<Polytope<ValueType>> create(std::vector<point_t> const& points);
/*!
* Creates a polytope from the given halfspaces.
* If the given vector of halfspaces is empty, the resulting polytope is universal (i.e., equals |R^n).
*/
static std::shared_ptr<Polytope<ValueType>> create(std::vector<Halfspace<ValueType>> const& halfspaces);
/*!
* Creates a polytope P from the given points (i.e., the convex hull of the points)
* and returns the downward closure of P, i.e., the set { x | ex. y \in P: x<=y}
* If the vector of points is empty, the resulting polytope be empty.
*/
static std::shared_ptr<Polytope<ValueType>> createDownwardClosure(std::vector<point_t> const& points);
/*!
* Returns the vertices of this polytope.
*/
virtual std::vector<point_t> getVertices();
/*!
* Returns the halfspaces of this polytope.
*/
virtual std::vector<Halfspace<ValueType>> getHalfspaces();
/*!
* Returns true iff the given point is inside of the polytope.
*/
virtual bool contains(point_t const& point) const;
/*!
* Intersects this polytope with rhs and returns the result.
*/
virtual unstd::shared_ptr<Polytope<ValueType>> intersect(std::shared_ptr<Polytope<ValueType>> const& rhs) const;
virtual unstd::shared_ptr<Polytope<ValueType>> intersect(Halfspace<ValueType> const& rhs) const;
/*!
* Returns the convex union of this polytope and rhs.
*/
virtual std::shared_ptr<Polytope<ValueType>> convexUnion(std::shared_ptr<Polytope<ValueType>> const& rhs) const;
virtual std::shared_ptr<Polytope<ValueType>> convexUnion(point_t const& rhs) const;
/*!
* Bloats the polytope
* The resulting polytope is an overapproximation of the minkowski sum of this polytope and the hyperrectangle given by point1
* and point2 but does not introduce new halfspaces.
* In more detail, let P={ x | A*x<=b} be the current polytope and R be the smallest hyperrectangle containing the two points.
* The result is the smallest polytope P' with
* 1. P'={ x | A*x<=b'}
* 2. For each p \in P and r \in R it holds that (p+r) \in P'
*/
virtual std::shared_ptr<Polytope<ValueType>> bloat(point_t const& point1, point_t const& point2) const;
private:
virtual Polytope();
/*!
* Creates a polytope from the given points (i.e., the convex hull of the points).
* If the vector of points is empty, the resulting polytope be empty.
*/
virtual Polytope(std::vector<point_t> const& points);
/*!
* Creates a polytope from the given halfspaces.
* If the given vector of halfspaces is empty, the resulting polytope is universal (i.e., equals |R^n).
*/
virtual Polytope(std::vector<Halfspace<ValueType>> const& halfspaces);
};
}
}
}
#endif /* STORM_STORAGE_GEOMETRY_POLYTOPE_H_ */

29
src/utility/vector.h

@ -346,6 +346,35 @@ namespace storm {
applyPointwise<ValueType1, ValueType2>(target, target, [&] (ValueType1 const& argument) -> ValueType1 { return argument * factor; });
}
/*!
* Converts the numbers in the given vector to the target representation
*
* @param target The target vector in which the resulting numbers are written.
* @param source The source vector whose numbers are converted
*/
template<class SourceType, class TargetType>
void convertVector(std::vector<SourceType> const& source, std::vector<TargetType>& target) {
applyPointwise<SourceType, TargetType>(source, target, [&] (SourceType const& argument) -> TargetType { return convertNumber<TargetType>(argument); });
}
/*!
* Multiplies the two given vectors (scalar product) and returns the result
*
* @param firstOperand The first operand.
* @param secondOperand The second operand
* @return firstOperand*secondOperand
*/
template<class T>
T multiplyVectors(std::vector<T> const& firstOperand, std::vector<T> const& secondOperand) {
T res = storm::utility::zero<T>();
auto it1 = firstOperand.begin();
auto it2 = secondOperand.begin();
for(; it1<firstOperand.end(); ++it1, ++it2){
res += (*it1) * (*it2);
}
return res;
}
/*!
* Retrieves a bit vector containing all the indices for which the value at this position makes the given
* function evaluate to true.

Loading…
Cancel
Save