Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
StandardMdpPcaaWeightVectorChecker.cpp
Go to the documentation of this file.
2
10
11namespace storm {
12namespace modelchecker {
13namespace multiobjective {
14
15template<class SparseMdpModelType>
21
22template<class SparseMdpModelType>
24 // set the state action rewards. Also do some sanity checks on the objectives.
25 this->actionRewards.resize(this->objectives.size());
26 for (uint_fast64_t objIndex = 0; objIndex < this->objectives.size(); ++objIndex) {
27 auto const& formula = *this->objectives[objIndex].formula;
28 STORM_LOG_THROW(formula.isRewardOperatorFormula() && formula.asRewardOperatorFormula().hasRewardModelName(), storm::exceptions::UnexpectedException,
29 "Unexpected type of operator formula: " << formula);
30 if (formula.getSubformula().isCumulativeRewardFormula()) {
31 auto const& cumulativeRewardFormula = formula.getSubformula().asCumulativeRewardFormula();
32 STORM_LOG_THROW(!cumulativeRewardFormula.isMultiDimensional() && !cumulativeRewardFormula.getTimeBoundReference().isRewardBound(),
33 storm::exceptions::UnexpectedException, "Unexpected type of sub-formula: " << formula.getSubformula());
34 } else {
35 STORM_LOG_THROW(formula.getSubformula().isTotalRewardFormula() || formula.getSubformula().isLongRunAverageRewardFormula(),
36 storm::exceptions::UnexpectedException, "Unexpected type of sub-formula: " << formula.getSubformula());
37 }
38 typename SparseMdpModelType::RewardModelType const& rewModel = model.getRewardModel(formula.asRewardOperatorFormula().getRewardModelName());
39 STORM_LOG_THROW(!rewModel.hasTransitionRewards(), storm::exceptions::NotSupportedException,
40 "Reward model has transition rewards which is not expected.");
41 this->actionRewards[objIndex] = rewModel.getTotalRewardVector(model.getTransitionMatrix());
42 }
43}
44
45template<class SparseMdpModelType>
51
52template<class SparseMdpModelType>
55 STORM_LOG_ASSERT(transitions.getRowGroupCount() == this->transitionMatrix.getRowGroupCount(), "Unexpected size of given matrix.");
57}
58
59template<class SparseMdpModelType>
60void StandardMdpPcaaWeightVectorChecker<SparseMdpModelType>::boundedPhase(Environment const& env, std::vector<ValueType> const& weightVector,
61 std::vector<ValueType>& weightedRewardVector) {
62 // Allocate some memory so this does not need to happen for each time epoch
63 std::vector<uint_fast64_t> optimalChoicesInCurrentEpoch(this->transitionMatrix.getRowGroupCount());
64 std::vector<ValueType> choiceValues(weightedRewardVector.size());
65 std::vector<ValueType> temporaryResult(this->transitionMatrix.getRowGroupCount());
66 // Get for each occurring timeBound the indices of the objectives with that bound.
67 std::map<uint_fast64_t, storm::storage::BitVector, std::greater<uint_fast64_t>> stepBounds;
68 for (uint_fast64_t objIndex = 0; objIndex < this->objectives.size(); ++objIndex) {
69 if (this->objectives[objIndex].formula->getSubformula().isCumulativeRewardFormula()) {
70 auto const& subformula = this->objectives[objIndex].formula->getSubformula().asCumulativeRewardFormula();
71 uint_fast64_t stepBound = subformula.template getBound<uint_fast64_t>();
72 if (subformula.isBoundStrict()) {
73 --stepBound;
74 }
75 auto stepBoundIt = stepBounds.insert(std::make_pair(stepBound, storm::storage::BitVector(this->objectives.size(), false))).first;
76 stepBoundIt->second.set(objIndex);
77
78 // There is no error for the values of these objectives.
79 this->offsetsToUnderApproximation[objIndex] = storm::utility::zero<ValueType>();
80 this->offsetsToOverApproximation[objIndex] = storm::utility::zero<ValueType>();
81 }
82 }
83
84 // Stores the objectives for which we need to compute values in the current time epoch.
85 storm::storage::BitVector consideredObjectives = this->objectivesWithNoUpperTimeBound & ~this->lraObjectives;
86
87 auto stepBoundIt = stepBounds.begin();
88 uint_fast64_t currentEpoch = stepBounds.empty() ? 0 : stepBoundIt->first;
89
90 while (currentEpoch > 0) {
91 if (stepBoundIt != stepBounds.end() && currentEpoch == stepBoundIt->first) {
92 consideredObjectives |= stepBoundIt->second;
93 for (auto objIndex : stepBoundIt->second) {
94 // This objective now plays a role in the weighted sum
95 ValueType factor =
96 storm::solver::minimize(this->objectives[objIndex].formula->getOptimalityType()) ? -weightVector[objIndex] : weightVector[objIndex];
97 storm::utility::vector::addScaledVector(weightedRewardVector, this->actionRewards[objIndex], factor);
98 }
99 ++stepBoundIt;
100 }
101
102 // Get values and scheduler for weighted sum of objectives
103 this->transitionMatrix.multiplyWithVector(this->weightedResult, choiceValues);
104 storm::utility::vector::addVectors(choiceValues, weightedRewardVector, choiceValues);
105 storm::utility::vector::reduceVectorMax(choiceValues, this->weightedResult, this->transitionMatrix.getRowGroupIndices(), &optimalChoicesInCurrentEpoch);
106
107 // get values for individual objectives
108 for (auto objIndex : consideredObjectives) {
109 std::vector<ValueType>& objectiveResult = this->objectiveResults[objIndex];
110 std::vector<ValueType> const& objectiveRewards = this->actionRewards[objIndex];
111 auto rowGroupIndexIt = this->transitionMatrix.getRowGroupIndices().begin();
112 auto optimalChoiceIt = optimalChoicesInCurrentEpoch.begin();
113 for (ValueType& stateValue : temporaryResult) {
114 uint_fast64_t row = (*rowGroupIndexIt) + (*optimalChoiceIt);
115 ++rowGroupIndexIt;
116 ++optimalChoiceIt;
117 stateValue = objectiveRewards[row];
118 for (auto const& entry : this->transitionMatrix.getRow(row)) {
119 stateValue += entry.getValue() * objectiveResult[entry.getColumn()];
120 }
121 }
122 objectiveResult.swap(temporaryResult);
123 }
124 --currentEpoch;
125 }
126}
127
128template class StandardMdpPcaaWeightVectorChecker<storm::models::sparse::Mdp<double>>;
129template class StandardMdpPcaaWeightVectorChecker<storm::models::sparse::Mdp<storm::RationalNumber>>;
130
131} // namespace multiobjective
132} // namespace modelchecker
133} // namespace storm
Helper class for model checking queries that depend on the long run behavior of the (nondeterministic...
Helper class for model checking queries that depend on the long run behavior of the (nondeterministic...
Helper Class that takes preprocessed Pcaa data and a weight vector and ...
virtual storm::modelchecker::helper::SparseNondeterministicInfiniteHorizonHelper< ValueType > createNondetInfiniteHorizonHelper(storm::storage::SparseMatrix< ValueType > const &transitions) const override
StandardMdpPcaaWeightVectorChecker(preprocessing::SparseMultiObjectivePreprocessorResult< SparseMdpModelType > const &preprocessorResult)
virtual void initializeModelTypeSpecificData(SparseMdpModelType const &model) override
virtual storm::modelchecker::helper::SparseDeterministicInfiniteHorizonHelper< ValueType > createDetInfiniteHorizonHelper(storm::storage::SparseMatrix< ValueType > const &transitions) const override
Helper Class that takes preprocessed Pcaa data and a weight vector and ...
void initialize(preprocessing::SparseMultiObjectivePreprocessorResult< SparseMdpModelType > const &preprocessorResult)
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
const_iterator begin() const
Returns an iterator to the indices of the set bits in the bit vector.
A class that holds a possibly non-square matrix in the compressed row storage format.
index_type getRowGroupCount() const
Returns the number of row groups in the matrix.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
bool constexpr minimize(OptimizationDirection d)
void addVectors(std::vector< InValueType1 > const &firstOperand, std::vector< InValueType2 > const &secondOperand, std::vector< OutValueType > &target)
Adds the two given vectors and writes the result to the target vector.
Definition vector.h:399
void addScaledVector(std::vector< InValueType1 > &firstOperand, std::vector< InValueType2 > const &secondOperand, InValueType3 const &factor)
Computes x:= x + a*y, i.e., adds each element of the first vector and (the corresponding element of t...
Definition vector.h:460
void reduceVectorMax(std::vector< T > const &source, std::vector< T > &target, std::vector< uint_fast64_t > const &rowGrouping, std::vector< uint_fast64_t > *choices=nullptr)
Reduces the given source vector by selecting the largest element out of each row group.
Definition vector.h:696