20template<
typename ValueType>
23 bool orderedMatrixRequired =
false;
24 std::vector<uint64_t> result;
25 result.reserve(numGroups);
28 std::vector<uint64_t> stack;
32 uint64_t startState = numGroups;
33 while (startState > 0) {
36 if (processed.
get(startState)) {
41 stack.push_back(startState);
42 while (!stack.empty()) {
43 uint64_t current = stack.back();
44 if (visited.
get(current)) {
48 if (!processed.
get(current)) {
49 result.push_back(current);
50 processed.
set(current);
55 for (
auto const& entry : matrix.
getRowGroup(current)) {
57 orderedMatrixRequired =
true;
58 STORM_LOG_THROW(!visited.
get(entry.getColumn()), storm::exceptions::UnmetRequirementException,
"The model is not acyclic.");
59 stack.push_back(entry.getColumn());
67 if (orderedMatrixRequired) {
68 std::reverse(result.begin(), result.end());
81template<
typename ValueType>
83 std::vector<uint64_t>
const& newToOrigIndexMap,
84 std::vector<std::pair<uint64_t, std::optional<ValueType>>>& bFactors) {
85 std::vector<uint64_t> origToNewMap(newToOrigIndexMap.size(), std::numeric_limits<uint64_t>::max());
86 for (uint64_t i = 0; i < newToOrigIndexMap.size(); ++i) {
87 origToNewMap[newToOrigIndexMap[i]] = i;
94 for (uint64_t newRowGroup = 0; newRowGroup < newToOrigIndexMap.size(); ++newRowGroup) {
95 auto const& origRowGroup = newToOrigIndexMap[newRowGroup];
100 for (
auto const& entry : matrix.
getRow(origRow)) {
104 if (entry.getColumn() == origRowGroup) {
108 bFactors.emplace_back(newRow, std::nullopt);
111 bFactors.emplace_back(newRow, factor);
114 builder.addNextValue(newRow, origToNewMap[entry.getColumn()], entry.getValue());
121 for (
auto const& bFactor : bFactors) {
122 if (!bFactor.second) {
127 for (
auto& entry : result.getRow(bFactor.first)) {
128 entry.setValue(entry.getValue() * *bFactor.second);
A bit vector that is internally represented as a vector of 64-bit values.
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.
A class that can be used to build a sparse matrix by adding value by value.
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)
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...
storm::storage::SparseMatrix< ValueType > createReorderedMatrix(storm::storage::SparseMatrix< ValueType > const &matrix, std::vector< uint64_t > const &newToOrigIndexMap, std::vector< std::pair< uint64_t, std::optional< ValueType > > > &bFactors)
reorders the row group such that the i'th row of the new matrix corresponds to the order[i]'th row of...
bool isOne(ValueType const &a)
bool isZero(ValueType const &a)