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->offsetsToAchievablePoint[objIndex] = storm::utility::zero<ValueType>();
80 }
81 }
82
83 // Stores the objectives for which we need to compute values in the current time epoch.
84 storm::storage::BitVector consideredObjectives = this->objectivesWithNoUpperTimeBound & ~this->lraObjectives;
85
86 auto stepBoundIt = stepBounds.begin();
87 uint_fast64_t currentEpoch = stepBounds.empty() ? 0 : stepBoundIt->first;
88
89 while (currentEpoch > 0) {
90 if (stepBoundIt != stepBounds.end() && currentEpoch == stepBoundIt->first) {
91 consideredObjectives |= stepBoundIt->second;
92 for (auto objIndex : stepBoundIt->second) {
93 // This objective now plays a role in the weighted sum
94 ValueType factor =
95 storm::solver::minimize(this->objectives[objIndex].formula->getOptimalityType()) ? -weightVector[objIndex] : weightVector[objIndex];
96 storm::utility::vector::addScaledVector(weightedRewardVector, this->actionRewards[objIndex], factor);
97 }
98 ++stepBoundIt;
99 }
100
101 // Get values and scheduler for weighted sum of objectives
102 this->transitionMatrix.multiplyWithVector(this->weightedResult, choiceValues);
103 storm::utility::vector::addVectors(choiceValues, weightedRewardVector, choiceValues);
104 storm::utility::vector::reduceVectorMax(choiceValues, this->weightedResult, this->transitionMatrix.getRowGroupIndices(), &optimalChoicesInCurrentEpoch);
105
106 // get values for individual objectives
107 for (auto objIndex : consideredObjectives) {
108 std::vector<ValueType>& objectiveResult = this->objectiveResults[objIndex];
109 std::vector<ValueType> const& objectiveRewards = this->actionRewards[objIndex];
110 auto rowGroupIndexIt = this->transitionMatrix.getRowGroupIndices().begin();
111 auto optimalChoiceIt = optimalChoicesInCurrentEpoch.begin();
112 for (ValueType& stateValue : temporaryResult) {
113 uint_fast64_t row = (*rowGroupIndexIt) + (*optimalChoiceIt);
114 ++rowGroupIndexIt;
115 ++optimalChoiceIt;
116 stateValue = objectiveRewards[row];
117 for (auto const& entry : this->transitionMatrix.getRow(row)) {
118 stateValue += entry.getValue() * objectiveResult[entry.getColumn()];
119 }
120 }
121 objectiveResult.swap(temporaryResult);
122 }
123 --currentEpoch;
124 }
125}
126
127template<class SparseMdpModelType>
129 return this->getWeightedPrecision(); // No approx. error in bounded phase.
130}
131
132template<class SparseMdpModelType>
134 return storm::utility::zero<ValueType>(); // No approx. error in bounded phase.
135}
136
139
140} // namespace multiobjective
141} // namespace modelchecker
142} // 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