Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
IntervalEndComponentPreserver.cpp
Go to the documentation of this file.
1
12namespace storm {
13namespace transformer {
14
18
19std::optional<storage::SparseMatrix<Interval>> IntervalEndComponentPreserver::eliminateMECs(storm::storage::SparseMatrix<Interval> const& originalMatrix,
20 std::vector<Interval> const& originalVector) {
21 storage::RobustMaximalEndComponentDecomposition<Interval> decomposition(originalMatrix, originalMatrix.transpose(), originalVector);
22
23 bool hasNonTrivialMEC = false;
24 for (auto const& group : decomposition) {
25 if (!group.isTrivial()) {
26 hasNonTrivialMEC = true;
27 // std::cout << "Non-trivial MEC: ";
28 // for (auto const& state : group) {
29 // std::cout << state << " ";
30 // }
31 // std::cout << std::endl;
32 }
33 }
34
35 if (!hasNonTrivialMEC) {
36 return std::nullopt;
37 }
38
39 auto const& indexMap = decomposition.computeStateToSccIndexMap(originalMatrix.getRowCount());
40
41 storm::storage::SparseMatrixBuilder<Interval> builder(originalMatrix.getRowCount() + 1, originalMatrix.getColumnCount() + 1, 0, true, false);
42
43 uint64_t sinkState = originalMatrix.getRowCount();
44
45 for (uint64_t row = 0; row < originalMatrix.getRowCount(); row++) {
46 if (indexMap.at(row) >= decomposition.size() || decomposition.getBlock(indexMap.at(row)).isTrivial()) {
47 // Group is trivial: Copy the row
48 for (auto const& entry : originalMatrix.getRow(row)) {
49 // We want to route this transition to a state in the group
50 builder.addNextValue(row, entry.getColumn(), entry.getValue());
51 }
52 } else {
53 auto const& group = decomposition.getBlock(indexMap.at(row));
54 // Group is non-trivial: Check whether state is the smallest in the group
55 uint64_t smallestInGroup = *group.begin();
56 if (row != smallestInGroup) {
57 // Add a one transition that points to the smallest state in the group
58 builder.addNextValue(row, smallestInGroup, utility::one<Interval>());
59 continue;
60 }
61 // Collect all states outside of the group that states inside of the group go to
62 boost::container::flat_set<uint64_t> groupSet;
63 for (auto const& state : group) {
64 for (auto const& entry : originalMatrix.getRow(state)) {
65 if (group.getStates().contains(entry.getColumn()) || utility::isZero(entry.getValue())) {
66 continue;
67 }
68 // We want to route this transition to the state representing the group
69 uint64_t groupIndex = indexMap.at(entry.getColumn());
70 uint64_t stateRepresentingGroup = groupIndex >= decomposition.size() ? entry.getColumn() : *decomposition.getBlock(groupIndex).begin();
71 groupSet.insert(stateRepresentingGroup);
72 }
73 }
74 STORM_LOG_DEBUG("Transformed group of size " << groupSet.size() << " for state " << row);
75 // Insert interval [0, 1] to all of these states
76 for (auto const& state : groupSet) {
77 builder.addNextValue(row, state, Interval(0, 1));
78 }
79 builder.addNextValue(row, sinkState, Interval(0, 1));
80 }
81 }
82
83 return builder.build();
84}
85
86} // namespace transformer
87} // namespace storm
block_type const & getBlock(uint_fast64_t index) const
Retrieves the block with the given index.
std::size_t size() const
Retrieves the number of blocks of this decomposition.
This class represents the decomposition of a nondeterministic model into its maximal end components.
std::vector< uint64_t > computeStateToSccIndexMap(uint64_t numberOfStates) const
Computes a vector that for each state has the index of the scc of that state in it.
A class that can be used to build a sparse matrix by adding value by value.
void addNextValue(index_type row, index_type column, value_type const &value)
Sets the matrix entry at the given row and column to the given value.
SparseMatrix< value_type > build(index_type overriddenRowCount=0, index_type overriddenColumnCount=0, index_type overriddenRowGroupCount=0)
A class that holds a possibly non-square matrix in the compressed row storage format.
const_rows getRow(index_type row) const
Returns an object representing the given row.
index_type getColumnCount() const
Returns the number of columns of the matrix.
storm::storage::SparseMatrix< value_type > transpose(bool joinGroups=false, bool keepZeros=false) const
Transposes the matrix.
index_type getRowCount() const
Returns the number of rows of the matrix.
iterator begin()
Returns an iterator to the states in this SCC.
Definition StateBlock.cpp:5
bool isTrivial() const
Retrieves whether this SCC is trivial.
std::optional< storage::SparseMatrix< Interval > > eliminateMECs(storm::storage::SparseMatrix< Interval > const &matrix, std::vector< Interval > const &vector)
#define STORM_LOG_DEBUG(message)
Definition logging.h:18
bool isZero(ValueType const &a)
Definition constants.cpp:42
LabParser.cpp.
carl::Interval< double > Interval
Interval type.