15constexpr char const* NotAffine =
16 "SCP requires an affine pMDP (every transition probability, and every state-action reward for reward properties, must have total degree <= 1 in the "
21 std::set<storm::RationalFunctionVariable> occurring;
26 for (
auto const& var : occurring) {
32 for (
auto const& var : occurring) {
34 STORM_LOG_ASSERT(
derivative.isConstant(),
"Derivative of an affine function w.r.t. one of its own parameters must be constant.");
38 parameters.insert(occurring.begin(), occurring.end());
45 auto const& rowGroupIndices = matrix.getRowGroupIndices();
46 auto stateOfRow = [&](uint64_t row) {
return std::upper_bound(rowGroupIndices.begin(), rowGroupIndices.end(), row) - rowGroupIndices.begin() - 1; };
48 rows.reserve(matrix.getRowCount());
49 for (uint64_t row = 0; row < matrix.getRowCount(); ++row) {
50 std::vector<UnpackedTransition> unpackedRow;
51 unpackedRow.reserve(matrix.getRow(row).getNumberOfEntries());
53 for (
auto const& entry : matrix.getRow(row)) {
55 NotAffine <<
"the transition from state " << stateOfRow(row) <<
" (row " << row <<
") to state " << entry.getColumn() <<
" is '"
56 << entry.getValue() <<
"', which is not affine.");
62 unpackedRow.push_back(std::move(unpacked));
64 rows.push_back(std::move(unpackedRow));
67 if (rewardModel !=
nullptr) {
69 rewardRows.reserve(rewardVector.size());
70 for (uint64_t row = 0; row < rewardVector.size(); ++row) {
73 NotAffine <<
"the reward of state " << stateOfRow(row) <<
" (row " << row <<
") is '" << rewardVector[row] <<
"', which is not affine.");
74 rewardRows.push_back(decomposeAffine(rewardVector[row]));
88 return rewardRows.at(row);
Base class for all sparse models.
storm::storage::SparseMatrix< ValueType > const & getTransitionMatrix() const
Retrieves the matrix representing the transitions of the model.
std::vector< ValueType > getTotalRewardVector(storm::storage::SparseMatrix< MatrixValueType > const &transitionMatrix) const
Creates a vector representing the complete reward vector based on the state-, state-action- and trans...
AffinePMdpDecomposition(storm::models::sparse::Model< storm::RationalFunction > const &model, storm::models::sparse::StandardRewardModel< storm::RationalFunction > const *rewardModel=nullptr)
std::set< storm::RationalFunctionVariable > const & getParameters() const
All parameters occurring anywhere in the model's transition matrix, or (if a reward model was given t...
uint64_t getNumberOfRows() const
The number of rows (matrix rows, i.e. choices) that were decomposed.
std::vector< UnpackedTransition > const & getRow(uint64_t row) const
The unpacked transitions of the given matrix row (a state for a DTMC, or a single state-action choice...
UnpackedValue const & getReward(uint64_t row) const
The affine decomposition of the reward accrued by taking the given matrix row, from the reward model ...
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
bool isLinear(FunctionType const &function)
Checks whether the function is linear (in one parameter).
std::map< typename VariableType< FunctionType >::type, typename CoefficientType< FunctionType >::type > Valuation
void gatherOccurringVariables(FunctionType const &function, std::set< typename VariableType< FunctionType >::type > &variableSet)
Add all variables that occur in the given function to the the given set.
double evaluate(storm::RationalFunction const &function, Valuation< storm::RationalFunction > const &valuation)
TargetType convertNumber(SourceType const &number)
carl::RationalFunction< Polynomial, true > RationalFunction
The affine part of a single transition (row, successor): UnpackedValue plus which successor state it ...
std::vector< std::pair< storm::RationalFunctionVariable, double > > parameterCoefficients
The affine decomposition of a single scalar quantity, so that everything downstream only ever touches...
std::vector< std::pair< storm::RationalFunctionVariable, double > > parameterCoefficients