Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Product.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4
5namespace storm {
6namespace transformer {
7template<typename Model>
8class Product {
9 public:
10 typedef std::shared_ptr<Product<Model>> ptr;
11
13 typedef std::pair<state_type, state_type> product_state_type;
14 typedef std::map<product_state_type, state_type> product_state_to_product_index_map;
15 typedef std::vector<product_state_type> product_index_to_product_state_vector;
16
17 Product(Model&& productModel, std::string&& productStateOfInterestLabel, product_state_to_product_index_map&& productStateToProductIndex,
18 product_index_to_product_state_vector&& productIndexToProductState)
19 : productModel(productModel),
20 productStateOfInterestLabel(productStateOfInterestLabel),
21 productStateToProductIndex(productStateToProductIndex),
22 productIndexToProductState(productIndexToProductState) {}
23
24 Product(Product<Model>&& product) = default;
25 Product& operator=(Product<Model>&& product) = default;
26
27 Model& getProductModel() {
28 return productModel;
29 }
30
31 state_type getModelState(state_type productStateIndex) const {
32 return productIndexToProductState.at(productStateIndex).first;
33 }
34
35 state_type getAutomatonState(state_type productStateIndex) const {
36 return productIndexToProductState.at(productStateIndex).second;
37 }
38
39 state_type getProductStateIndex(state_type modelState, state_type automatonState) const {
40 return productStateToProductIndex.at(product_state_type(modelState, automatonState));
41 }
42
43 bool isValidProductState(state_type modelState, state_type automatonState) const {
44 return (productStateToProductIndex.count(product_state_type(modelState, automatonState)) > 0);
45 }
46
48 state_type n = productModel.getNumberOfStates();
49 storm::storage::BitVector lifted(n, false);
50 for (state_type s = 0; s < n; s++) {
51 if (vector.get(getAutomatonState(s))) {
52 lifted.set(s);
53 }
54 }
55 return lifted;
56 }
57
59 state_type n = productModel.getNumberOfStates();
60 storm::storage::BitVector lifted(n, false);
61 for (state_type s = 0; s < n; s++) {
62 if (vector.get(getModelState(s))) {
63 lifted.set(s);
64 }
65 }
66 return lifted;
67 }
68
69 template<typename ValueType>
70 std::vector<ValueType> projectToOriginalModel(const Model& originalModel, const std::vector<ValueType>& prodValues) {
71 return projectToOriginalModel(originalModel.getNumberOfStates(), prodValues);
72 }
73
74 template<typename ValueType>
75 std::vector<ValueType> projectToOriginalModel(std::size_t numberOfStates, const std::vector<ValueType>& prodValues) {
76 std::vector<ValueType> origValues(numberOfStates);
77 for (state_type productState : productModel.getStateLabeling().getStates(productStateOfInterestLabel)) {
78 state_type originalState = getModelState(productState);
79 origValues.at(originalState) = prodValues.at(productState);
80 }
81 return origValues;
82 }
83
85 return productModel.getStates(productStateOfInterestLabel);
86 }
87
88 void printMapping(std::ostream& out) const {
89 out << "Mapping index -> product state\n";
90 for (std::size_t i = 0; i < productIndexToProductState.size(); i++) {
91 out << " " << i << ": " << productIndexToProductState.at(i).first << "," << productIndexToProductState.at(i).second << "\n";
92 }
93 }
94
95 private:
96 Model productModel;
97 std::string productStateOfInterestLabel;
98 product_state_to_product_index_map productStateToProductIndex;
99 product_index_to_product_state_vector productIndexToProductState;
100};
101} // namespace transformer
102} // namespace storm
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
void set(uint_fast64_t index, bool value=true)
Sets the given truth value at the given index.
bool get(uint_fast64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
state_type getModelState(state_type productStateIndex) const
Definition Product.h:31
std::map< product_state_type, state_type > product_state_to_product_index_map
Definition Product.h:14
state_type getAutomatonState(state_type productStateIndex) const
Definition Product.h:35
storm::storage::BitVector liftFromModel(const storm::storage::BitVector &vector) const
Definition Product.h:58
std::vector< ValueType > projectToOriginalModel(const Model &originalModel, const std::vector< ValueType > &prodValues)
Definition Product.h:70
Product(Product< Model > &&product)=default
state_type getProductStateIndex(state_type modelState, state_type automatonState) const
Definition Product.h:39
std::pair< state_type, state_type > product_state_type
Definition Product.h:13
std::vector< product_state_type > product_index_to_product_state_vector
Definition Product.h:15
storm::storage::sparse::state_type state_type
Definition Product.h:12
std::vector< ValueType > projectToOriginalModel(std::size_t numberOfStates, const std::vector< ValueType > &prodValues)
Definition Product.h:75
const storm::storage::BitVector & getStatesOfInterest() const
Definition Product.h:84
Product(Model &&productModel, std::string &&productStateOfInterestLabel, product_state_to_product_index_map &&productStateToProductIndex, product_index_to_product_state_vector &&productIndexToProductState)
Definition Product.h:17
bool isValidProductState(state_type modelState, state_type automatonState) const
Definition Product.h:43
storm::storage::BitVector liftFromAutomaton(const storm::storage::BitVector &vector) const
Definition Product.h:47
std::shared_ptr< Product< Model > > ptr
Definition Product.h:10
Product & operator=(Product< Model > &&product)=default
void printMapping(std::ostream &out) const
Definition Product.h:88
LabParser.cpp.
Definition cli.cpp:18