Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
AcyclicLinearEquationSolver.cpp
Go to the documentation of this file.
2
5
7
8namespace storm {
9namespace solver {
10
11template<typename ValueType>
15
16template<typename ValueType>
20
21template<typename ValueType>
25
26template<typename ValueType>
28 localA.reset();
29 this->A = &A;
30 clearCache();
31}
32
33template<typename ValueType>
35 localA = std::make_unique<storm::storage::SparseMatrix<ValueType>>(std::move(A));
36 this->A = localA.get();
37 clearCache();
38}
39
40template<typename ValueType>
42 return this->A->getRowCount();
43}
44
45template<typename ValueType>
46uint64_t AcyclicLinearEquationSolver<ValueType>::getMatrixColumnCount() const {
47 return this->A->getColumnCount();
48}
49
50template<typename ValueType>
51bool AcyclicLinearEquationSolver<ValueType>::internalSolveEquations(Environment const& env, std::vector<ValueType>& x, std::vector<ValueType> const& b) const {
52 STORM_LOG_ASSERT(x.size() == this->A->getRowGroupCount(), "Provided x-vector has invalid size.");
53 STORM_LOG_ASSERT(b.size() == this->A->getRowCount(), "Provided b-vector has invalid size.");
54
55 if (!multiplier) {
56 // We have not allocated cache memory, yet
57 rowOrdering = helper::computeTopologicalGroupOrdering(*this->A);
58 if (!rowOrdering) {
59 // It is not required to reorder the elements.
60 this->multiplier = storm::solver::MultiplierFactory<ValueType>().create(env, *this->A);
61 } else {
62 bFactors.clear();
63 orderedMatrix = helper::createReorderedMatrix(*this->A, *rowOrdering, bFactors);
64 this->multiplier = storm::solver::MultiplierFactory<ValueType>().create(env, *orderedMatrix);
65 }
66 auxiliaryRowVector = std::vector<ValueType>(this->A->getRowCount());
67 auxiliaryRowVector2 = std::vector<ValueType>(this->A->getRowCount());
68 }
69
70 std::vector<ValueType>* xPtr = &x;
71 std::vector<ValueType> const* bPtr = &b;
72 if (rowOrdering) {
73 STORM_LOG_ASSERT(rowOrdering->size() == b.size(), "b-vector has unexpected size.");
74 auxiliaryRowVector->resize(b.size());
75 storm::utility::vector::selectVectorValues(*auxiliaryRowVector, *rowOrdering, b);
76 for (auto const& bFactor : bFactors) {
77 (*auxiliaryRowVector)[bFactor.first] *= bFactor.second;
78 }
79 bPtr = &auxiliaryRowVector.get();
80 xPtr = &auxiliaryRowVector2.get();
81 }
82
83 this->multiplier->multiplyGaussSeidel(env, *xPtr, bPtr, true);
84
85 if (rowOrdering) {
86 for (uint64_t newRow = 0; newRow < x.size(); ++newRow) {
87 x[(*rowOrdering)[newRow]] = (*xPtr)[newRow];
88 }
89 }
90
91 if (!this->isCachingEnabled()) {
92 this->clearCache();
93 }
94 return true;
95}
96
97template<typename ValueType>
101
102template<typename ValueType>
104 // Return the requirements of the underlying solver
106 requirements.requireAcyclic();
107 return requirements;
108}
109
110template<typename ValueType>
112 multiplier.reset();
113 orderedMatrix = boost::none;
114 rowOrdering = boost::none;
115 auxiliaryRowVector = boost::none;
116 auxiliaryRowVector2 = boost::none;
117 bFactors.clear();
118}
119
120// Explicitly instantiate the min max linear equation solver.
122
123#ifdef STORM_HAVE_CARL
126#endif
127} // namespace solver
128} // namespace storm
This solver can be used on equation systems that are known to be acyclic.
virtual LinearEquationSolverProblemFormat getEquationProblemFormat(storm::Environment const &env) const override
Retrieves the format in which this solver expects to solve equations.
virtual bool internalSolveEquations(storm::Environment const &env, std::vector< ValueType > &x, std::vector< ValueType > const &b) const override
virtual void setMatrix(storm::storage::SparseMatrix< ValueType > const &A) override
virtual LinearEquationSolverRequirements getRequirements(Environment const &env) const override
Retrieves the requirements of the solver under the current settings.
LinearEquationSolverRequirements & requireAcyclic(bool critical=true)
std::unique_ptr< Multiplier< ValueType > > create(Environment const &env, storm::storage::SparseMatrix< ValueType > const &matrix)
A class that holds a possibly non-square matrix in the compressed row storage format.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
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...
void selectVectorValues(std::vector< T > &vector, storm::storage::BitVector const &positions, std::vector< T > const &values)
Selects the elements from a vector at the specified positions and writes them consecutively into anot...
Definition vector.h:189
LabParser.cpp.
Definition cli.cpp:18