19template<
typename ValueType>
22 bool orderedMatrixRequired =
false;
23 std::vector<uint64_t> result;
24 result.reserve(numGroups);
27 std::vector<uint64_t> stack;
31 uint64_t startState = numGroups;
32 while (startState > 0) {
35 if (processed.
get(startState))
39 stack.push_back(startState);
40 while (!stack.empty()) {
41 uint64_t current = stack.back();
42 if (visited.
get(current)) {
46 if (!processed.
get(current)) {
47 result.push_back(current);
48 processed.
set(current);
53 for (
auto const& entry : matrix.
getRowGroup(current)) {
55 orderedMatrixRequired =
true;
56 STORM_LOG_THROW(!visited.
get(entry.getColumn()), storm::exceptions::UnmetRequirementException,
"The model is not acyclic.");
57 stack.push_back(entry.getColumn());
65 if (orderedMatrixRequired) {
66 std::reverse(result.begin(), result.end());
76template<
typename ValueType>
78 std::vector<uint64_t>
const& newToOrigIndexMap,
79 std::vector<std::pair<uint64_t, ValueType>>& bFactors) {
80 std::vector<uint64_t> origToNewMap(newToOrigIndexMap.size(), std::numeric_limits<uint64_t>::max());
81 for (uint64_t i = 0; i < newToOrigIndexMap.size(); ++i) {
82 origToNewMap[newToOrigIndexMap[i]] = i;
89 for (uint64_t newRowGroup = 0; newRowGroup < newToOrigIndexMap.size(); ++newRowGroup) {
90 auto const& origRowGroup = newToOrigIndexMap[newRowGroup];
95 for (
auto const& entry : matrix.
getRow(origRow)) {
99 if (entry.getColumn() == origRowGroup) {
103 bFactors.emplace_back(newRow, storm::utility::infinity<ValueType>());
105 ValueType factor = storm::utility::one<ValueType>() / (storm::utility::one<ValueType>() - entry.getValue());
106 bFactors.emplace_back(newRow, factor);
108 builder.
addNextValue(newRow, origToNewMap[entry.getColumn()], entry.getValue());
115 for (
auto const& bFactor : bFactors) {
117 "The input matrix does not seem to be probabilistic.");
118 for (
auto& entry : result.getRow(bFactor.first)) {
119 entry.setValue(entry.getValue() * bFactor.second);
A bit vector that is internally represented as a vector of 64-bit values.
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.
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.
void newRowGroup(index_type startingRow)
Starts a new row group in the matrix.
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.
const_rows getRowGroup(index_type rowGroup) const
Returns an object representing the given row group.
index_type getRowGroupCount() const
Returns the number of row groups in the matrix.
std::string getDimensionsAsString() const
Returns a string describing the dimensions of the matrix.
index_type getColumnCount() const
Returns the number of columns of the matrix.
bool hasTrivialRowGrouping() const
Retrieves whether the matrix has a trivial row grouping.
std::vector< index_type > const & getRowGroupIndices() const
Returns the grouping of rows of this matrix.
index_type getRowCount() const
Returns the number of rows of the matrix.
index_type getNonzeroEntryCount() const
Returns the cached number of nonzero entries in the matrix.
#define STORM_LOG_DEBUG(message)
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
storm::storage::SparseMatrix< ValueType > createReorderedMatrix(storm::storage::SparseMatrix< ValueType > const &matrix, std::vector< uint64_t > const &newToOrigIndexMap, std::vector< std::pair< uint64_t, ValueType > > &bFactors)
reorders the row group such that the i'th row of the new matrix corresponds to the order[i]'th row of...
boost::optional< std::vector< uint64_t > > computeTopologicalGroupOrdering(storm::storage::SparseMatrix< ValueType > const &matrix)
Returns a reordering of the matrix row(groups) and columns such that we can solve the (minmax or line...
bool isOne(ValueType const &a)
bool isZero(ValueType const &a)
bool isInfinity(ValueType const &a)