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