Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
StandardMaPcaaWeightVectorChecker.cpp
Go to the documentation of this file.
2
3#include <cmath>
4
19
20namespace storm {
21namespace modelchecker {
22namespace multiobjective {
23
24template<class SparseMaModelType>
30
31template<class SparseMaModelType>
33 markovianStates = model.getMarkovianStates();
34 exitRates = model.getExitRates();
35
36 // Set the (discretized) state action rewards.
37 this->actionRewards.assign(this->objectives.size(), {});
38 this->stateRewards.assign(this->objectives.size(), {});
39 for (uint64_t objIndex = 0; objIndex < this->objectives.size(); ++objIndex) {
40 auto const& formula = *this->objectives[objIndex].formula;
41 STORM_LOG_THROW(formula.isRewardOperatorFormula() && formula.asRewardOperatorFormula().hasRewardModelName(), storm::exceptions::UnexpectedException,
42 "Unexpected type of operator formula: " << formula);
43 typename SparseMaModelType::RewardModelType const& rewModel = model.getRewardModel(formula.asRewardOperatorFormula().getRewardModelName());
44 STORM_LOG_ASSERT(!rewModel.hasTransitionRewards(), "Preprocessed Reward model has transition rewards which is not expected.");
45 this->actionRewards[objIndex] = rewModel.hasStateActionRewards()
46 ? rewModel.getStateActionRewardVector()
47 : std::vector<ValueType>(model.getTransitionMatrix().getRowCount(), storm::utility::zero<ValueType>());
48 if (formula.getSubformula().isTotalRewardFormula()) {
49 if (rewModel.hasStateRewards()) {
50 // Note that state rewards are earned over time and thus play no role for probabilistic states
51 for (auto markovianState : markovianStates) {
52 this->actionRewards[objIndex][model.getTransitionMatrix().getRowGroupIndices()[markovianState]] +=
53 rewModel.getStateReward(markovianState) / exitRates[markovianState];
54 }
55 }
56 } else if (formula.getSubformula().isLongRunAverageRewardFormula()) {
57 // The LRA methods for MA require keeping track of state- and action rewards separately
58 if (rewModel.hasStateRewards()) {
59 this->stateRewards[objIndex] = rewModel.getStateRewardVector();
60 }
61 } else {
62 STORM_LOG_THROW(formula.getSubformula().isCumulativeRewardFormula() &&
63 formula.getSubformula().asCumulativeRewardFormula().getTimeBoundReference().isTimeBound(),
64 storm::exceptions::UnexpectedException, "Unexpected type of sub-formula: " << formula.getSubformula());
65 STORM_LOG_THROW(!rewModel.hasStateRewards(), storm::exceptions::InvalidPropertyException,
66 "Found state rewards for time bounded objective " << this->objectives[objIndex].originalFormula << ". This is not supported.");
68 this->objectives[objIndex].originalFormula->isProbabilityOperatorFormula() &&
69 this->objectives[objIndex].originalFormula->asProbabilityOperatorFormula().getSubformula().isBoundedUntilFormula(),
70 "Objective " << this->objectives[objIndex].originalFormula
71 << " was simplified to a cumulative reward formula. Correctness of the algorithm is unknown for this type of property.");
72 }
73 }
74 // Print some statistics (if requested)
75 if (storm::settings::getModule<storm::settings::modules::CoreSettings>().isShowStatisticsSet()) {
76 STORM_PRINT_AND_LOG("Final preprocessed model has " << markovianStates.getNumberOfSetBits() << " Markovian states.\n");
77 }
78}
79
80template<class SparseMdpModelType>
83 STORM_LOG_ASSERT(transitions.getRowGroupCount() == this->transitionMatrix.getRowGroupCount(), "Unexpected size of given matrix.");
84 return storm::modelchecker::helper::SparseNondeterministicInfiniteHorizonHelper<ValueType>(transitions, this->markovianStates, this->exitRates);
85}
86
87template<class SparseMdpModelType>
90 STORM_LOG_ASSERT(transitions.getRowGroupCount() == this->transitionMatrix.getRowGroupCount(), "Unexpected size of given matrix.");
91 // TODO: Right now, there is no dedicated support for "deterministic" Markov automata so we have to pick the nondeterministic one.
92 auto result = storm::modelchecker::helper::SparseNondeterministicInfiniteHorizonHelper<ValueType>(transitions, this->markovianStates, this->exitRates);
93 result.setOptimizationDirection(storm::solver::OptimizationDirection::Maximize);
94 return result;
95}
96
97template<class SparseMaModelType>
98void StandardMaPcaaWeightVectorChecker<SparseMaModelType>::boundedPhase(Environment const& env, std::vector<ValueType> const& weightVector,
99 std::vector<ValueType>& weightedRewardVector) {
100 // Split the preprocessed model into transitions from/to probabilistic/Markovian states.
101 SubModel MS = createSubModel(true, weightedRewardVector);
102 SubModel PS = createSubModel(false, weightedRewardVector);
103
104 // Apply digitization to Markovian transitions
105 ValueType digitizationConstant = getDigitizationConstant(weightVector);
106 digitize(MS, digitizationConstant);
107
108 // Get for each occurring (digitized) timeBound the indices of the objectives with that bound.
109 TimeBoundMap upperTimeBounds;
110 digitizeTimeBounds(upperTimeBounds, digitizationConstant);
111
112 // Check whether there is a cycle in of probabilistic states
113 bool acyclic = !storm::utility::graph::hasCycle(PS.toPS);
114
115 // Initialize a minMaxSolver to compute an optimal scheduler (w.r.t. PS) for each epoch
116 // No EC elimination is necessary as we assume non-zenoness
117 std::unique_ptr<MinMaxSolverData> minMax = initMinMaxSolver(env, PS, acyclic, weightVector);
118
119 // create a linear equation solver for the model induced by the optimal choice vector.
120 // the solver will be updated whenever the optimal choice vector has changed.
121 std::unique_ptr<LinEqSolverData> linEq = initLinEqSolver(env, PS, acyclic);
122
123 // Store the optimal choices of PS as computed by the minMax solver.
124 std::vector<uint_fast64_t> optimalChoicesAtCurrentEpoch(PS.getNumberOfStates(), std::numeric_limits<uint_fast64_t>::max());
125
126 // Stores the objectives for which we need to compute values in the current time epoch.
127 storm::storage::BitVector consideredObjectives = this->objectivesWithNoUpperTimeBound & ~this->lraObjectives;
128
129 auto upperTimeBoundIt = upperTimeBounds.begin();
130 uint_fast64_t currentEpoch = upperTimeBounds.empty() ? 0 : upperTimeBoundIt->first;
132 // Update the objectives that are considered at the current time epoch as well as the (weighted) reward vectors.
133 updateDataToCurrentEpoch(MS, PS, *minMax, consideredObjectives, currentEpoch, weightVector, upperTimeBoundIt, upperTimeBounds);
134
135 // Compute the values that can be obtained at probabilistic states in the current time epoch
136 performPSStep(env, PS, MS, *minMax, *linEq, optimalChoicesAtCurrentEpoch, consideredObjectives, weightVector);
137
138 // Compute values that can be obtained at Markovian states after letting one (digitized) time unit pass.
139 // Only perform such a step if there is time left.
140 if (currentEpoch > 0) {
141 performMSStep(env, MS, PS, consideredObjectives, weightVector);
142 --currentEpoch;
143 } else {
144 break;
145 }
146 }
147 STORM_LOG_WARN_COND(!storm::utility::resources::isTerminate(), "Time-bounded reachability computation aborted.");
148
149 // compose the results from MS and PS
150 storm::utility::vector::setVectorValues(this->weightedResult, MS.states, MS.weightedSolutionVector);
151 storm::utility::vector::setVectorValues(this->weightedResult, PS.states, PS.weightedSolutionVector);
152 for (uint_fast64_t objIndex = 0; objIndex < this->objectives.size(); ++objIndex) {
153 storm::utility::vector::setVectorValues(this->objectiveResults[objIndex], MS.states, MS.objectiveSolutionVectors[objIndex]);
154 storm::utility::vector::setVectorValues(this->objectiveResults[objIndex], PS.states, PS.objectiveSolutionVectors[objIndex]);
155 }
156}
157
158template<class SparseMaModelType>
159typename StandardMaPcaaWeightVectorChecker<SparseMaModelType>::SubModel StandardMaPcaaWeightVectorChecker<SparseMaModelType>::createSubModel(
160 bool createMS, std::vector<ValueType> const& weightedRewardVector) const {
161 SubModel result;
162
163 storm::storage::BitVector probabilisticStates = ~markovianStates;
164 result.states = createMS ? markovianStates : probabilisticStates;
165 result.choices = this->transitionMatrix.getRowFilter(result.states);
166 STORM_LOG_ASSERT(!createMS || result.states.getNumberOfSetBits() == result.choices.getNumberOfSetBits(),
167 "row groups for Markovian states should consist of exactly one row");
168
169 // We need to add diagonal entries for selfloops on Markovian states.
170 result.toMS = this->transitionMatrix.getSubmatrix(true, result.states, markovianStates, createMS);
171 result.toPS = this->transitionMatrix.getSubmatrix(true, result.states, probabilisticStates, false);
172 STORM_LOG_ASSERT(result.getNumberOfStates() == result.states.getNumberOfSetBits() && result.getNumberOfStates() == result.toMS.getRowGroupCount() &&
173 result.getNumberOfStates() == result.toPS.getRowGroupCount(),
174 "Invalid state count for subsystem");
175 STORM_LOG_ASSERT(result.getNumberOfChoices() == result.choices.getNumberOfSetBits() && result.getNumberOfChoices() == result.toMS.getRowCount() &&
176 result.getNumberOfChoices() == result.toPS.getRowCount(),
177 "Invalid choice count for subsystem");
178
179 result.weightedRewardVector.resize(result.getNumberOfChoices());
180 storm::utility::vector::selectVectorValues(result.weightedRewardVector, result.choices, weightedRewardVector);
181 for (uint_fast64_t objIndex = 0; objIndex < this->objectives.size(); ++objIndex) {
182 std::vector<ValueType> const& objRewards = this->actionRewards[objIndex];
183 std::vector<ValueType> subModelObjRewards;
184 subModelObjRewards.reserve(result.getNumberOfChoices());
185 for (auto choice : result.choices) {
186 subModelObjRewards.push_back(objRewards[choice]);
187 }
188 result.objectiveRewardVectors.push_back(std::move(subModelObjRewards));
189 }
190
191 result.weightedSolutionVector.resize(result.getNumberOfStates());
192 storm::utility::vector::selectVectorValues(result.weightedSolutionVector, result.states, this->weightedResult);
193 result.objectiveSolutionVectors.resize(this->objectives.size());
194 for (uint_fast64_t objIndex = 0; objIndex < this->objectives.size(); ++objIndex) {
195 result.objectiveSolutionVectors[objIndex].resize(result.weightedSolutionVector.size());
196 storm::utility::vector::selectVectorValues(result.objectiveSolutionVectors[objIndex], result.states, this->objectiveResults[objIndex]);
197 }
198
199 result.auxChoiceValues.resize(result.getNumberOfChoices());
200
201 return result;
202}
203
204template<class SparseMaModelType>
205template<typename VT, typename std::enable_if<storm::NumberTraits<VT>::SupportsExponential, int>::type>
206VT StandardMaPcaaWeightVectorChecker<SparseMaModelType>::getDigitizationConstant(std::vector<ValueType> const& weightVector) const {
207 STORM_LOG_DEBUG("Retrieving digitization constant");
208 // We need to find a delta such that for each objective it holds that lowerbound/delta , upperbound/delta are natural numbers and
209 // sum_{obj_i} (
210 // If obj_i has a lower and an upper bound:
211 // weightVector_i * (1 - e^(-maxRate lowerbound) * (1 + maxRate delta) ^ (lowerbound / delta) + 1-e^(-maxRate upperbound) * (1 + maxRate delta) ^
212 // (upperbound / delta) + (1-e^(-maxRate delta)))
213 // If there is only an upper bound:
214 // weightVector_i * ( 1-e^(-maxRate upperbound) * (1 + maxRate delta) ^ (upperbound / delta))
215 // ) <= this->maximumLowerUpperDistance
216
217 // Initialize some data for fast and easy access
218 VT const maxRate = storm::utility::vector::max_if(exitRates, markovianStates);
219 std::vector<VT> timeBounds;
220 std::vector<VT> eToPowerOfMinusMaxRateTimesBound;
221 VT smallestNonZeroBound = storm::utility::zero<VT>();
222 for (auto const& obj : this->objectives) {
223 if (obj.formula->getSubformula().isCumulativeRewardFormula()) {
224 timeBounds.push_back(obj.formula->getSubformula().asCumulativeRewardFormula().template getBound<VT>());
225 STORM_LOG_THROW(!storm::utility::isZero(timeBounds.back()), storm::exceptions::InvalidPropertyException,
226 "Got zero-valued upper time bound. This is not suppoted.");
227 eToPowerOfMinusMaxRateTimesBound.push_back(std::exp(-maxRate * timeBounds.back()));
228 smallestNonZeroBound = storm::utility::isZero(smallestNonZeroBound) ? timeBounds.back() : std::min(smallestNonZeroBound, timeBounds.back());
229 } else {
230 timeBounds.push_back(storm::utility::zero<VT>());
231 eToPowerOfMinusMaxRateTimesBound.push_back(storm::utility::zero<VT>());
232 }
233 }
234 if (storm::utility::isZero(smallestNonZeroBound)) {
235 // There are no time bounds. In this case, one is a valid digitization constant.
236 return storm::utility::one<VT>();
237 }
238 VT goalPrecisionTimesNorm = this->weightedPrecision * storm::utility::sqrt(storm::utility::vector::dotProduct(weightVector, weightVector));
239
240 // We brute-force a delta, since a direct computation is apparently not easy.
241 // Also note that the number of times this loop runs is a lower bound for the number of minMaxSolver invocations.
242 // Hence, this brute-force approach will most likely not be a bottleneck.
243 storm::storage::BitVector objectivesWithTimeBound = ~this->objectivesWithNoUpperTimeBound;
244 uint_fast64_t smallestStepBound = 1;
245 VT delta = smallestNonZeroBound / smallestStepBound;
246 while (true) {
247 bool deltaValid = true;
248 for (auto objIndex : objectivesWithTimeBound) {
249 auto const& timeBound = timeBounds[objIndex];
250 if (timeBound / delta != std::floor(timeBound / delta)) {
251 deltaValid = false;
252 break;
253 }
254 }
255 if (deltaValid) {
256 VT weightedPrecisionForCurrentDelta = storm::utility::zero<VT>();
257 for (uint_fast64_t objIndex = 0; objIndex < this->objectives.size(); ++objIndex) {
258 VT precisionOfObj = storm::utility::zero<VT>();
259 if (objectivesWithTimeBound.get(objIndex)) {
260 precisionOfObj +=
261 storm::utility::one<VT>() - (eToPowerOfMinusMaxRateTimesBound[objIndex] *
262 storm::utility::pow(storm::utility::one<VT>() + maxRate * delta, timeBounds[objIndex] / delta));
263 }
264 weightedPrecisionForCurrentDelta += weightVector[objIndex] * precisionOfObj;
265 }
266 deltaValid &= weightedPrecisionForCurrentDelta <= goalPrecisionTimesNorm;
267 }
268 if (deltaValid) {
269 break;
270 }
271 ++smallestStepBound;
272 STORM_LOG_ASSERT(delta > smallestNonZeroBound / smallestStepBound, "Digitization constant is expected to become smaller in every iteration");
273 delta = smallestNonZeroBound / smallestStepBound;
274 }
275 STORM_LOG_DEBUG("Found digitization constant: " << delta << ". At least " << smallestStepBound << " digitization steps will be necessarry");
276 return delta;
277}
278
279template<class SparseMaModelType>
280template<typename VT, typename std::enable_if<!storm::NumberTraits<VT>::SupportsExponential, int>::type>
281VT StandardMaPcaaWeightVectorChecker<SparseMaModelType>::getDigitizationConstant(std::vector<ValueType> const& /*weightVector*/) const {
282 STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Computing bounded probabilities of MAs is unsupported for this value type.");
283}
284
285template<class SparseMaModelType>
286template<typename VT, typename std::enable_if<storm::NumberTraits<VT>::SupportsExponential, int>::type>
287void StandardMaPcaaWeightVectorChecker<SparseMaModelType>::digitize(SubModel& MS, VT const& digitizationConstant) const {
288 std::vector<VT> rateVector(MS.getNumberOfChoices());
289 storm::utility::vector::selectVectorValues(rateVector, MS.states, exitRates);
290 for (uint_fast64_t row = 0; row < rateVector.size(); ++row) {
291 VT const eToMinusRateTimesDelta = std::exp(-rateVector[row] * digitizationConstant);
292 for (auto& entry : MS.toMS.getRow(row)) {
293 entry.setValue((storm::utility::one<VT>() - eToMinusRateTimesDelta) * entry.getValue());
294 if (entry.getColumn() == row) {
295 entry.setValue(entry.getValue() + eToMinusRateTimesDelta);
296 }
297 }
298 for (auto& entry : MS.toPS.getRow(row)) {
299 entry.setValue((storm::utility::one<VT>() - eToMinusRateTimesDelta) * entry.getValue());
300 }
301 MS.weightedRewardVector[row] *= storm::utility::one<VT>() - eToMinusRateTimesDelta;
302 for (auto& objVector : MS.objectiveRewardVectors) {
303 objVector[row] *= storm::utility::one<VT>() - eToMinusRateTimesDelta;
304 }
305 }
306}
307
308template<class SparseMaModelType>
309template<typename VT, typename std::enable_if<!storm::NumberTraits<VT>::SupportsExponential, int>::type>
310void StandardMaPcaaWeightVectorChecker<SparseMaModelType>::digitize(SubModel& /*subModel*/, VT const& /*digitizationConstant*/) const {
311 STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Computing bounded probabilities of MAs is unsupported for this value type.");
312}
313
314template<class SparseMaModelType>
315template<typename VT, typename std::enable_if<storm::NumberTraits<VT>::SupportsExponential, int>::type>
316void StandardMaPcaaWeightVectorChecker<SparseMaModelType>::digitizeTimeBounds(TimeBoundMap& upperTimeBounds, VT const& digitizationConstant) {
317 VT const maxRate = storm::utility::vector::max_if(exitRates, markovianStates);
318 for (uint_fast64_t objIndex = 0; objIndex < this->objectives.size(); ++objIndex) {
319 auto const& obj = this->objectives[objIndex];
320 VT errorTowardsZero = storm::utility::zero<VT>();
321 VT errorAwayFromZero = storm::utility::zero<VT>();
322 if (obj.formula->getSubformula().isCumulativeRewardFormula()) {
323 VT timeBound = obj.formula->getSubformula().asCumulativeRewardFormula().template getBound<VT>();
324 uint_fast64_t digitizedBound = storm::utility::convertNumber<uint_fast64_t>(timeBound / digitizationConstant);
325 auto timeBoundIt = upperTimeBounds.insert(std::make_pair(digitizedBound, storm::storage::BitVector(this->objectives.size(), false))).first;
326 timeBoundIt->second.set(objIndex);
327 VT digitizationError = storm::utility::one<VT>();
328 digitizationError -=
329 std::exp(-maxRate * timeBound) * storm::utility::pow(storm::utility::one<VT>() + maxRate * digitizationConstant, digitizedBound);
330 errorAwayFromZero += digitizationError;
331 }
332 if (storm::solver::maximize(obj.formula->getOptimalityType())) {
333 this->offsetsToUnderApproximation[objIndex] = -errorTowardsZero;
334 this->offsetsToOverApproximation[objIndex] = errorAwayFromZero;
335 } else {
336 this->offsetsToUnderApproximation[objIndex] = errorAwayFromZero;
337 this->offsetsToOverApproximation[objIndex] = -errorTowardsZero;
338 }
339 }
340}
341
342template<class SparseMaModelType>
343template<typename VT, typename std::enable_if<!storm::NumberTraits<VT>::SupportsExponential, int>::type>
344void StandardMaPcaaWeightVectorChecker<SparseMaModelType>::digitizeTimeBounds(TimeBoundMap& /*upperTimeBounds*/, VT const& /*digitizationConstant*/) {
345 STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Computing bounded probabilities of MAs is unsupported for this value type.");
346}
347
348template<class SparseMaModelType>
349std::unique_ptr<typename StandardMaPcaaWeightVectorChecker<SparseMaModelType>::MinMaxSolverData>
350StandardMaPcaaWeightVectorChecker<SparseMaModelType>::initMinMaxSolver(Environment const& env, SubModel const& PS, bool acyclic,
351 std::vector<ValueType> const& weightVector) const {
352 std::unique_ptr<MinMaxSolverData> result(new MinMaxSolverData());
353 result->env = std::make_unique<storm::Environment>(env);
354 // For acyclic models we switch to the more efficient acyclic solver (Unless the solver / method was explicitly specified)
355 if (acyclic) {
356 result->env->solver().minMax().setMethod(storm::solver::MinMaxMethod::Acyclic);
357 }
359 result->solver = minMaxSolverFactory.create(*result->env, PS.toPS);
360 result->solver->setHasUniqueSolution(true);
361 result->solver->setHasNoEndComponents(true); // Non-zeno MA
362 result->solver->setTrackScheduler(true);
363 result->solver->setCachingEnabled(true);
364 auto req = result->solver->getRequirements(*result->env, storm::solver::OptimizationDirection::Maximize, false);
365 boost::optional<ValueType> lowerBound = this->computeWeightedResultBound(true, weightVector, storm::storage::BitVector(weightVector.size(), true));
366 if (lowerBound) {
367 result->solver->setLowerBound(lowerBound.get());
368 req.clearLowerBounds();
369 }
370 boost::optional<ValueType> upperBound = this->computeWeightedResultBound(false, weightVector, storm::storage::BitVector(weightVector.size(), true));
371 if (upperBound) {
372 result->solver->setUpperBound(upperBound.get());
373 req.clearUpperBounds();
374 }
375 if (acyclic) {
376 req.clearAcyclic();
377 }
378 STORM_LOG_THROW(!req.hasEnabledCriticalRequirement(), storm::exceptions::UncheckedRequirementException,
379 "Solver requirements " + req.getEnabledRequirementsAsString() + " not checked.");
380 result->solver->setRequirementsChecked(true);
381 result->solver->setOptimizationDirection(storm::solver::OptimizationDirection::Maximize);
382
383 result->b.resize(PS.getNumberOfChoices());
384
385 return result;
386}
387
388template<class SparseMaModelType>
389template<typename VT, typename std::enable_if<storm::NumberTraits<VT>::SupportsExponential, int>::type>
390std::unique_ptr<typename StandardMaPcaaWeightVectorChecker<SparseMaModelType>::LinEqSolverData>
392 std::unique_ptr<LinEqSolverData> result(new LinEqSolverData());
393 result->env = std::make_unique<Environment>(env);
394 result->acyclic = acyclic;
395 // For acyclic models we switch to the more efficient acyclic solver (Unless the solver / method was explicitly specified)
396 if (acyclic) {
397 result->env->solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Acyclic);
398 }
399 result->factory = std::make_unique<storm::solver::GeneralLinearEquationSolverFactory<ValueType>>();
400 result->b.resize(PS.getNumberOfStates());
401 return result;
402}
403
404template<class SparseMaModelType>
405template<typename VT, typename std::enable_if<!storm::NumberTraits<VT>::SupportsExponential, int>::type>
406std::unique_ptr<typename StandardMaPcaaWeightVectorChecker<SparseMaModelType>::LinEqSolverData>
407StandardMaPcaaWeightVectorChecker<SparseMaModelType>::initLinEqSolver(Environment const& /*env*/, SubModel const& /*PS*/, bool /*acyclic*/) const {
408 STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Computing bounded probabilities of MAs is unsupported for this value type.");
409}
410
411template<class SparseMaModelType>
412void StandardMaPcaaWeightVectorChecker<SparseMaModelType>::updateDataToCurrentEpoch(
413 SubModel& MS, SubModel& PS, MinMaxSolverData& minMax, storm::storage::BitVector& consideredObjectives, uint_fast64_t const& currentEpoch,
414 std::vector<ValueType> const& weightVector, TimeBoundMap::iterator& upperTimeBoundIt, TimeBoundMap const& upperTimeBounds) {
415 if (upperTimeBoundIt != upperTimeBounds.end() && currentEpoch == upperTimeBoundIt->first) {
416 consideredObjectives |= upperTimeBoundIt->second;
417 for (auto objIndex : upperTimeBoundIt->second) {
418 // This objective now plays a role in the weighted sum
419 ValueType factor =
420 storm::solver::minimize(this->objectives[objIndex].formula->getOptimalityType()) ? -weightVector[objIndex] : weightVector[objIndex];
421 storm::utility::vector::addScaledVector(MS.weightedRewardVector, MS.objectiveRewardVectors[objIndex], factor);
422 storm::utility::vector::addScaledVector(PS.weightedRewardVector, PS.objectiveRewardVectors[objIndex], factor);
423 }
424 ++upperTimeBoundIt;
425 }
426
427 // Update the solver data
428 PS.toMS.multiplyWithVector(MS.weightedSolutionVector, minMax.b);
429 storm::utility::vector::addVectors(minMax.b, PS.weightedRewardVector, minMax.b);
430}
431
432template<class SparseMaModelType>
433void StandardMaPcaaWeightVectorChecker<SparseMaModelType>::performPSStep(Environment const& env, SubModel& PS, SubModel const& MS, MinMaxSolverData& minMax,
434 LinEqSolverData& linEq, std::vector<uint_fast64_t>& optimalChoicesAtCurrentEpoch,
435 storm::storage::BitVector const& consideredObjectives,
436 std::vector<ValueType> const& weightVector) const {
437 // compute a choice vector for the probabilistic states that is optimal w.r.t. the weighted reward vector
438 minMax.solver->solveEquations(*minMax.env, PS.weightedSolutionVector, minMax.b);
439 auto const& newChoices = minMax.solver->getSchedulerChoices();
440 if (consideredObjectives.getNumberOfSetBits() == 1 && storm::utility::isOne(weightVector[*consideredObjectives.begin()])) {
441 // In this case there is no need to perform the computation on the individual objectives
442 optimalChoicesAtCurrentEpoch = newChoices;
443 PS.objectiveSolutionVectors[*consideredObjectives.begin()] = PS.weightedSolutionVector;
444 if (storm::solver::minimize(this->objectives[*consideredObjectives.begin()].formula->getOptimalityType())) {
445 storm::utility::vector::scaleVectorInPlace(PS.objectiveSolutionVectors[*consideredObjectives.begin()], -storm::utility::one<ValueType>());
446 }
447 } else {
448 // check whether the linEqSolver needs to be updated, i.e., whether the scheduler has changed
449 if (linEq.solver == nullptr || newChoices != optimalChoicesAtCurrentEpoch) {
450 optimalChoicesAtCurrentEpoch = newChoices;
451 linEq.solver = nullptr;
452 bool needEquationSystem = linEq.factory->getEquationProblemFormat(*linEq.env) == storm::solver::LinearEquationSolverProblemFormat::EquationSystem;
453 storm::storage::SparseMatrix<ValueType> linEqMatrix = PS.toPS.selectRowsFromRowGroups(optimalChoicesAtCurrentEpoch, needEquationSystem);
454 if (needEquationSystem) {
455 linEqMatrix.convertToEquationSystem();
456 }
457 linEq.solver = linEq.factory->create(*linEq.env, std::move(linEqMatrix));
458 linEq.solver->setCachingEnabled(true);
459 auto req = linEq.solver->getRequirements(*linEq.env);
460 if (linEq.acyclic) {
461 req.clearAcyclic();
462 }
463 STORM_LOG_THROW(!req.hasEnabledCriticalRequirement(), storm::exceptions::UncheckedRequirementException,
464 "Solver requirements " + req.getEnabledRequirementsAsString() + " not checked.");
465 }
466
467 // Get the results for the individual objectives.
468 // Note that we do not consider an estimate for each objective (as done in the unbounded phase) since the results from the previous epoch are already
469 // pretty close
470 for (auto objIndex : consideredObjectives) {
471 auto const& objectiveRewardVectorPS = PS.objectiveRewardVectors[objIndex];
472 auto const& objectiveSolutionVectorMS = MS.objectiveSolutionVectors[objIndex];
473 // compute rhs of equation system, i.e., PS.toMS * x + Rewards
474 // To safe some time, only do this for the obtained optimal choices
475 auto itGroupIndex = PS.toPS.getRowGroupIndices().begin();
476 auto itChoiceOffset = optimalChoicesAtCurrentEpoch.begin();
477 for (auto& bValue : linEq.b) {
478 uint_fast64_t row = (*itGroupIndex) + (*itChoiceOffset);
479 bValue = objectiveRewardVectorPS[row];
480 for (auto const& entry : PS.toMS.getRow(row)) {
481 bValue += entry.getValue() * objectiveSolutionVectorMS[entry.getColumn()];
482 }
483 ++itGroupIndex;
484 ++itChoiceOffset;
485 }
486 linEq.solver->solveEquations(*linEq.env, PS.objectiveSolutionVectors[objIndex], linEq.b);
487 }
488 }
489}
490
491template<class SparseMaModelType>
492void StandardMaPcaaWeightVectorChecker<SparseMaModelType>::performMSStep(Environment const& env, SubModel& MS, SubModel const& PS,
493 storm::storage::BitVector const& consideredObjectives,
494 std::vector<ValueType> const& weightVector) const {
495 MS.toMS.multiplyWithVector(MS.weightedSolutionVector, MS.auxChoiceValues);
496 storm::utility::vector::addVectors(MS.weightedRewardVector, MS.auxChoiceValues, MS.weightedSolutionVector);
497 MS.toPS.multiplyWithVector(PS.weightedSolutionVector, MS.auxChoiceValues);
498 storm::utility::vector::addVectors(MS.weightedSolutionVector, MS.auxChoiceValues, MS.weightedSolutionVector);
499 if (consideredObjectives.getNumberOfSetBits() == 1 && storm::utility::isOne(weightVector[*consideredObjectives.begin()])) {
500 // In this case there is no need to perform the computation on the individual objectives
501 MS.objectiveSolutionVectors[*consideredObjectives.begin()] = MS.weightedSolutionVector;
502 if (storm::solver::minimize(this->objectives[*consideredObjectives.begin()].formula->getOptimalityType())) {
503 storm::utility::vector::scaleVectorInPlace(MS.objectiveSolutionVectors[*consideredObjectives.begin()], -storm::utility::one<ValueType>());
504 }
505 } else {
506 for (auto objIndex : consideredObjectives) {
507 MS.toMS.multiplyWithVector(MS.objectiveSolutionVectors[objIndex], MS.auxChoiceValues);
508 storm::utility::vector::addVectors(MS.objectiveRewardVectors[objIndex], MS.auxChoiceValues, MS.objectiveSolutionVectors[objIndex]);
509 MS.toPS.multiplyWithVector(PS.objectiveSolutionVectors[objIndex], MS.auxChoiceValues);
510 storm::utility::vector::addVectors(MS.objectiveSolutionVectors[objIndex], MS.auxChoiceValues, MS.objectiveSolutionVectors[objIndex]);
511 }
512 }
513}
514
515template class StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<double>>;
516template double StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<double>>::getDigitizationConstant<double>(
517 std::vector<double> const& direction) const;
518template void StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<double>>::digitize<double>(
519 StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<double>>::SubModel& subModel, double const& digitizationConstant) const;
520template void StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<double>>::digitizeTimeBounds<double>(
521 StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<double>>::TimeBoundMap& upperTimeBounds, double const& digitizationConstant);
522template std::unique_ptr<typename StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<double>>::LinEqSolverData>
523StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<double>>::initLinEqSolver<double>(
524 Environment const& env, StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<double>>::SubModel const& PS, bool acyclic) const;
525
526template class StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>>;
527template storm::RationalNumber StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>>::getDigitizationConstant<
528 storm::RationalNumber>(std::vector<storm::RationalNumber> const& direction) const;
529template void StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>>::digitize<storm::RationalNumber>(
530 StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>>::SubModel& subModel,
531 storm::RationalNumber const& digitizationConstant) const;
532template void StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>>::digitizeTimeBounds<storm::RationalNumber>(
533 StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>>::TimeBoundMap& upperTimeBounds,
534 storm::RationalNumber const& digitizationConstant);
535template std::unique_ptr<typename StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>>::LinEqSolverData>
536StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>>::initLinEqSolver<storm::RationalNumber>(
537 Environment const& env, StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>>::SubModel const& PS,
538 bool acyclic) const;
539
540} // namespace multiobjective
541} // namespace modelchecker
542} // namespace storm
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 ...
StandardMaPcaaWeightVectorChecker(preprocessing::SparseMultiObjectivePreprocessorResult< SparseMaModelType > const &preprocessorResult)
virtual void initializeModelTypeSpecificData(SparseMaModelType const &model) override
virtual storm::modelchecker::helper::SparseNondeterministicInfiniteHorizonHelper< ValueType > createNondetInfiniteHorizonHelper(storm::storage::SparseMatrix< ValueType > const &transitions) const override
virtual storm::modelchecker::helper::SparseNondeterministicInfiniteHorizonHelper< 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< SparseMaModelType > const &preprocessorResult)
This class represents a Markov automaton.
virtual std::unique_ptr< MinMaxLinearEquationSolver< ValueType, SolutionType > > create(Environment const &env) const override
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
uint64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
const_iterator begin() const
Returns an iterator to the indices of the set bits in the bit vector.
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 holds a possibly non-square matrix in the compressed row storage format.
void convertToEquationSystem()
Transforms the matrix into an equation system.
SparseMatrix selectRowsFromRowGroups(std::vector< index_type > const &rowGroupToRowIndexMapping, bool insertDiagonalEntries=true) const
Selects exactly one row from each row group of this matrix and returns the resulting matrix.
index_type getRowGroupCount() const
Returns the number of row groups in the matrix.
#define STORM_LOG_DEBUG(message)
Definition logging.h:18
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
#define STORM_LOG_WARN_COND(cond, message)
Definition macros.h:38
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
#define STORM_PRINT_AND_LOG(message)
Definition macros.h:68
bool constexpr maximize(OptimizationDirection d)
bool constexpr minimize(OptimizationDirection d)
bool hasCycle(storm::storage::SparseMatrix< T > const &transitionMatrix, boost::optional< storm::storage::BitVector > const &subsystem)
Returns true if the graph represented by the given matrix has a cycle.
Definition graph.cpp:136
bool isTerminate()
Check whether the program should terminate (due to some abort signal).
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
T dotProduct(std::vector< T > const &firstOperand, std::vector< T > const &secondOperand)
Computes the dot product (aka scalar product) and returns the result.
Definition vector.h:473
VT max_if(std::vector< VT > const &values, storm::storage::BitVector const &filter)
Computes the maximum of the entries from the values that are selected by the (non-empty) filter.
Definition vector.h:568
void setVectorValues(std::vector< T > &vector, storm::storage::BitVector const &positions, std::vector< T > const &values)
Sets the provided values at the provided positions in the given vector.
Definition vector.h:78
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:184
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 scaleVectorInPlace(std::vector< ValueType1 > &target, ValueType2 const &factor)
Multiplies each element of the given vector with the given factor and writes the result into the vect...
Definition vector.h:447
bool isOne(ValueType const &a)
Definition constants.cpp:34
bool isZero(ValueType const &a)
Definition constants.cpp:39
ValueType pow(ValueType const &value, int_fast64_t exponent)
ValueType sqrt(ValueType const &number)