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>
99 return this->getWeightedPrecision() - getWeightedPrecisionBoundedPhase();
100}
101
102template<class SparseMaModelType>
104 if (!this->objectivesWithNoUpperTimeBound.full()) {
105 // If there are time-bounded objectives, we allow most of the approximation error in the bounded phase.
106 // This is because computing time-bounded objectives accurately is likely the largest bottle neck of the computation.
107 return storm::utility::convertNumber<ValueType>(0.99) * this->getWeightedPrecision();
108 }
109 return storm::utility::zero<ValueType>();
110}
111
112template<class SparseMaModelType>
114 return !this->objectivesWithNoUpperTimeBound.full();
115}
116
117template<class SparseMaModelType>
118void StandardMaPcaaWeightVectorChecker<SparseMaModelType>::boundedPhase(Environment const& env, std::vector<ValueType> const& weightVector,
119 std::vector<ValueType>& weightedRewardVector) {
120 // Split the preprocessed model into transitions from/to probabilistic/Markovian states.
121 SubModel MS = createSubModel(true, weightedRewardVector);
122 SubModel PS = createSubModel(false, weightedRewardVector);
123
124 // Apply digitization to Markovian transitions
125 ValueType digitizationConstant = getDigitizationConstant(weightVector);
126 digitize(MS, digitizationConstant);
127
128 // Get for each occurring (digitized) timeBound the indices of the objectives with that bound.
129 TimeBoundMap upperTimeBounds;
130 digitizeTimeBounds(upperTimeBounds, digitizationConstant, weightVector);
131
132 // Check whether there is a cycle in of probabilistic states
133 bool acyclic = !storm::utility::graph::hasCycle(PS.toPS);
134
135 // Initialize a minMaxSolver to compute an optimal scheduler (w.r.t. PS) for each epoch
136 // No EC elimination is necessary as we assume non-zenoness
137 std::unique_ptr<MinMaxSolverData> minMax = initMinMaxSolver(env, PS, acyclic, weightVector);
138
139 // create a linear equation solver for the model induced by the optimal choice vector.
140 // the solver will be updated whenever the optimal choice vector has changed.
141 std::unique_ptr<LinEqSolverData> linEq = initLinEqSolver(env, PS, acyclic);
142
143 // Store the optimal choices of PS as computed by the minMax solver.
144 std::vector<uint_fast64_t> optimalChoicesAtCurrentEpoch(PS.getNumberOfStates(), std::numeric_limits<uint_fast64_t>::max());
145
146 // Stores the objectives for which we need to compute values in the current time epoch.
147 storm::storage::BitVector consideredObjectives = this->objectivesWithNoUpperTimeBound & ~this->lraObjectives;
148
149 auto upperTimeBoundIt = upperTimeBounds.begin();
150 uint_fast64_t currentEpoch = upperTimeBounds.empty() ? 0 : upperTimeBoundIt->first;
152 // Update the objectives that are considered at the current time epoch as well as the (weighted) reward vectors.
153 updateDataToCurrentEpoch(MS, PS, *minMax, consideredObjectives, currentEpoch, weightVector, upperTimeBoundIt, upperTimeBounds);
154
155 // Compute the values that can be obtained at probabilistic states in the current time epoch
156 performPSStep(env, PS, MS, *minMax, *linEq, optimalChoicesAtCurrentEpoch, consideredObjectives, weightVector);
157
158 // Compute values that can be obtained at Markovian states after letting one (digitized) time unit pass.
159 // Only perform such a step if there is time left.
160 if (currentEpoch > 0) {
161 performMSStep(env, MS, PS, consideredObjectives, weightVector);
162 --currentEpoch;
163 } else {
164 break;
165 }
166 }
167 STORM_LOG_WARN_COND(!storm::utility::resources::isTerminate(), "Time-bounded reachability computation aborted.");
168
169 // compose the results from MS and PS
170 storm::utility::vector::setVectorValues(this->weightedResult, MS.states, MS.weightedSolutionVector);
171 storm::utility::vector::setVectorValues(this->weightedResult, PS.states, PS.weightedSolutionVector);
172 for (uint_fast64_t objIndex = 0; objIndex < this->objectives.size(); ++objIndex) {
173 storm::utility::vector::setVectorValues(this->objectiveResults[objIndex], MS.states, MS.objectiveSolutionVectors[objIndex]);
174 storm::utility::vector::setVectorValues(this->objectiveResults[objIndex], PS.states, PS.objectiveSolutionVectors[objIndex]);
175 }
176}
177
178template<class SparseMaModelType>
179typename StandardMaPcaaWeightVectorChecker<SparseMaModelType>::SubModel StandardMaPcaaWeightVectorChecker<SparseMaModelType>::createSubModel(
180 bool createMS, std::vector<ValueType> const& weightedRewardVector) const {
181 SubModel result;
182
183 storm::storage::BitVector probabilisticStates = ~markovianStates;
184 result.states = createMS ? markovianStates : probabilisticStates;
185 result.choices = this->transitionMatrix.getRowFilter(result.states);
186 STORM_LOG_ASSERT(!createMS || result.states.getNumberOfSetBits() == result.choices.getNumberOfSetBits(),
187 "row groups for Markovian states should consist of exactly one row");
188
189 // We need to add diagonal entries for selfloops on Markovian states.
190 result.toMS = this->transitionMatrix.getSubmatrix(true, result.states, markovianStates, createMS);
191 result.toPS = this->transitionMatrix.getSubmatrix(true, result.states, probabilisticStates, false);
192 STORM_LOG_ASSERT(result.getNumberOfStates() == result.states.getNumberOfSetBits() && result.getNumberOfStates() == result.toMS.getRowGroupCount() &&
193 result.getNumberOfStates() == result.toPS.getRowGroupCount(),
194 "Invalid state count for subsystem");
195 STORM_LOG_ASSERT(result.getNumberOfChoices() == result.choices.getNumberOfSetBits() && result.getNumberOfChoices() == result.toMS.getRowCount() &&
196 result.getNumberOfChoices() == result.toPS.getRowCount(),
197 "Invalid choice count for subsystem");
198
199 result.weightedRewardVector.resize(result.getNumberOfChoices());
200 storm::utility::vector::selectVectorValues(result.weightedRewardVector, result.choices, weightedRewardVector);
201 for (uint_fast64_t objIndex = 0; objIndex < this->objectives.size(); ++objIndex) {
202 std::vector<ValueType> const& objRewards = this->actionRewards[objIndex];
203 std::vector<ValueType> subModelObjRewards;
204 subModelObjRewards.reserve(result.getNumberOfChoices());
205 for (auto choice : result.choices) {
206 subModelObjRewards.push_back(objRewards[choice]);
207 }
208 result.objectiveRewardVectors.push_back(std::move(subModelObjRewards));
209 }
210
211 result.weightedSolutionVector.resize(result.getNumberOfStates());
212 storm::utility::vector::selectVectorValues(result.weightedSolutionVector, result.states, this->weightedResult);
213 result.objectiveSolutionVectors.resize(this->objectives.size());
214 for (uint_fast64_t objIndex = 0; objIndex < this->objectives.size(); ++objIndex) {
215 result.objectiveSolutionVectors[objIndex].resize(result.weightedSolutionVector.size());
216 storm::utility::vector::selectVectorValues(result.objectiveSolutionVectors[objIndex], result.states, this->objectiveResults[objIndex]);
217 }
218
219 result.auxChoiceValues.resize(result.getNumberOfChoices());
220
221 return result;
222}
223
224template<class SparseMaModelType>
225template<typename VT, typename std::enable_if<storm::NumberTraits<VT>::SupportsExponential, int>::type>
226VT StandardMaPcaaWeightVectorChecker<SparseMaModelType>::getDigitizationConstant(std::vector<ValueType> const& weightVector) const {
227 STORM_LOG_DEBUG("Retrieving digitization constant");
228 // We need to find a delta such that for each objective it holds that lowerbound/delta , upperbound/delta are natural numbers and
229 // sum_{obj_i} (
230 // If obj_i has a lower and an upper bound:
231 // weightVector_i * (1 - e^(-maxRate lowerbound) * (1 + maxRate delta) ^ (lowerbound / delta) + 1-e^(-maxRate upperbound) * (1 + maxRate delta) ^
232 // (upperbound / delta) + (1-e^(-maxRate delta)))
233 // If there is only an upper bound:
234 // weightVector_i * ( 1-e^(-maxRate upperbound) * (1 + maxRate delta) ^ (upperbound / delta))
235 // ) <= this->maximumLowerUpperDistance
236
237 // Initialize some data for fast and easy access
238 VT const maxRate = storm::utility::vector::max_if(exitRates, markovianStates);
239 std::vector<VT> timeBounds;
240 std::vector<VT> eToPowerOfMinusMaxRateTimesBound;
241 VT smallestNonZeroBound = storm::utility::zero<VT>();
242 for (auto const& obj : this->objectives) {
243 if (obj.formula->getSubformula().isCumulativeRewardFormula()) {
244 timeBounds.push_back(obj.formula->getSubformula().asCumulativeRewardFormula().template getBound<VT>());
245 STORM_LOG_THROW(!storm::utility::isZero(timeBounds.back()), storm::exceptions::InvalidPropertyException,
246 "Got zero-valued upper time bound. This is not suppoted.");
247 eToPowerOfMinusMaxRateTimesBound.push_back(std::exp(-maxRate * timeBounds.back()));
248 smallestNonZeroBound = storm::utility::isZero(smallestNonZeroBound) ? timeBounds.back() : std::min(smallestNonZeroBound, timeBounds.back());
249 } else {
250 timeBounds.push_back(storm::utility::zero<VT>());
251 eToPowerOfMinusMaxRateTimesBound.push_back(storm::utility::zero<VT>());
252 }
253 }
254 if (storm::utility::isZero(smallestNonZeroBound)) {
255 // There are no time bounds. In this case, one is a valid digitization constant.
256 return storm::utility::one<VT>();
257 }
258 VT weightedGoalPrecision = this->getWeightedPrecisionBoundedPhase() * storm::utility::sqrt(storm::utility::vector::dotProduct(weightVector, weightVector));
259
260 // We brute-force a delta, since a direct computation is apparently not easy.
261 // Also note that the number of times this loop runs is a lower bound for the number of minMaxSolver invocations.
262 // Hence, this brute-force approach will most likely not be a bottleneck.
263 storm::storage::BitVector objectivesWithTimeBound = ~this->objectivesWithNoUpperTimeBound;
264 uint_fast64_t smallestStepBound = 1;
265 VT delta = smallestNonZeroBound / smallestStepBound;
266 while (true) {
267 bool deltaValid = true;
268 for (auto objIndex : objectivesWithTimeBound) {
269 auto const& timeBound = timeBounds[objIndex];
270 if (timeBound / delta != std::floor(timeBound / delta)) {
271 deltaValid = false;
272 break;
273 }
274 }
275 if (deltaValid) {
276 VT weightedPrecisionForCurrentDelta = storm::utility::zero<VT>();
277 for (uint_fast64_t objIndex = 0; objIndex < this->objectives.size(); ++objIndex) {
278 VT precisionOfObj = storm::utility::zero<VT>();
279 if (objectivesWithTimeBound.get(objIndex)) {
280 precisionOfObj +=
281 storm::utility::one<VT>() - (eToPowerOfMinusMaxRateTimesBound[objIndex] *
282 storm::utility::pow(storm::utility::one<VT>() + maxRate * delta, timeBounds[objIndex] / delta));
283 }
284 weightedPrecisionForCurrentDelta += weightVector[objIndex] * precisionOfObj;
285 }
286 deltaValid &= weightedPrecisionForCurrentDelta <= weightedGoalPrecision;
287 }
288 if (deltaValid) {
289 break;
290 }
291 ++smallestStepBound;
292 STORM_LOG_ASSERT(delta > smallestNonZeroBound / smallestStepBound, "Digitization constant is expected to become smaller in every iteration");
293 delta = smallestNonZeroBound / smallestStepBound;
294 }
295 STORM_LOG_DEBUG("Found digitization constant: " << delta << ". At least " << smallestStepBound << " digitization steps will be necessarry");
296 return delta;
297}
298
299template<class SparseMaModelType>
300template<typename VT, typename std::enable_if<!storm::NumberTraits<VT>::SupportsExponential, int>::type>
301VT StandardMaPcaaWeightVectorChecker<SparseMaModelType>::getDigitizationConstant(std::vector<ValueType> const& /*weightVector*/) const {
302 STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Computing bounded probabilities of MAs is unsupported for this value type.");
303}
304
305template<class SparseMaModelType>
306template<typename VT, typename std::enable_if<storm::NumberTraits<VT>::SupportsExponential, int>::type>
307void StandardMaPcaaWeightVectorChecker<SparseMaModelType>::digitize(SubModel& MS, VT const& digitizationConstant) const {
308 std::vector<VT> rateVector(MS.getNumberOfChoices());
309 storm::utility::vector::selectVectorValues(rateVector, MS.states, exitRates);
310 for (uint_fast64_t row = 0; row < rateVector.size(); ++row) {
311 VT const eToMinusRateTimesDelta = std::exp(-rateVector[row] * digitizationConstant);
312 for (auto& entry : MS.toMS.getRow(row)) {
313 entry.setValue((storm::utility::one<VT>() - eToMinusRateTimesDelta) * entry.getValue());
314 if (entry.getColumn() == row) {
315 entry.setValue(entry.getValue() + eToMinusRateTimesDelta);
316 }
317 }
318 for (auto& entry : MS.toPS.getRow(row)) {
319 entry.setValue((storm::utility::one<VT>() - eToMinusRateTimesDelta) * entry.getValue());
320 }
321 MS.weightedRewardVector[row] *= storm::utility::one<VT>() - eToMinusRateTimesDelta;
322 for (auto& objVector : MS.objectiveRewardVectors) {
323 objVector[row] *= storm::utility::one<VT>() - eToMinusRateTimesDelta;
324 }
325 }
326}
327
328template<class SparseMaModelType>
329template<typename VT, typename std::enable_if<!storm::NumberTraits<VT>::SupportsExponential, int>::type>
330void StandardMaPcaaWeightVectorChecker<SparseMaModelType>::digitize(SubModel& /*subModel*/, VT const& /*digitizationConstant*/) const {
331 STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Computing bounded probabilities of MAs is unsupported for this value type.");
332}
333
334template<class SparseMaModelType>
335void StandardMaPcaaWeightVectorChecker<SparseMaModelType>::digitizeTimeBounds(TimeBoundMap& upperTimeBounds, ValueType const& digitizationConstant,
336 std::vector<ValueType> const& weightVector) {
338 ValueType const maxRate = storm::utility::vector::max_if(exitRates, markovianStates);
339 for (auto objIndex : ~this->objectivesWithNoUpperTimeBound) {
340 auto const& obj = this->objectives[objIndex];
341 ValueType errorTowardsZero = storm::utility::zero<ValueType>();
342 ValueType errorAwayFromZero = storm::utility::zero<ValueType>();
343 if (obj.formula->getSubformula().isCumulativeRewardFormula()) {
344 ValueType timeBound = obj.formula->getSubformula().asCumulativeRewardFormula().template getBound<ValueType>();
345 uint_fast64_t digitizedBound = storm::utility::convertNumber<uint_fast64_t>(timeBound / digitizationConstant);
346 auto timeBoundIt = upperTimeBounds.insert(std::make_pair(digitizedBound, storm::storage::BitVector(this->objectives.size(), false))).first;
347 timeBoundIt->second.set(objIndex);
348 ValueType digitizationError = storm::utility::one<ValueType>();
349 digitizationError -=
350 std::exp(-maxRate * timeBound) * storm::utility::pow(storm::utility::one<ValueType>() + maxRate * digitizationConstant, digitizedBound);
351 errorAwayFromZero += digitizationError;
352 }
353 if (storm::solver::maximize(obj.formula->getOptimalityType())) {
354 this->offsetsToAchievablePoint[objIndex] = -errorTowardsZero;
355 this->offsetToWeightedSum += weightVector[objIndex] * errorAwayFromZero;
356 } else {
357 this->offsetsToAchievablePoint[objIndex] = errorAwayFromZero;
358 this->offsetToWeightedSum += weightVector[objIndex] * errorTowardsZero;
359 }
360 }
361 } else {
362 STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Computing bounded probabilities of MAs is unsupported for this value type.");
363 }
364}
365
366template<class SparseMaModelType>
367std::unique_ptr<typename StandardMaPcaaWeightVectorChecker<SparseMaModelType>::MinMaxSolverData>
368StandardMaPcaaWeightVectorChecker<SparseMaModelType>::initMinMaxSolver(Environment const& env, SubModel const& PS, bool acyclic,
369 std::vector<ValueType> const& weightVector) const {
370 std::unique_ptr<MinMaxSolverData> result(new MinMaxSolverData());
371 result->env = std::make_unique<storm::Environment>(env);
372 // For acyclic models we switch to the more efficient acyclic solver (Unless the solver / method was explicitly specified)
373 if (acyclic) {
374 result->env->solver().minMax().setMethod(storm::solver::MinMaxMethod::Acyclic);
375 }
377 result->solver = minMaxSolverFactory.create(*result->env, PS.toPS);
378 result->solver->setHasUniqueSolution(true);
379 result->solver->setHasNoEndComponents(true); // Non-zeno MA
380 result->solver->setTrackScheduler(true);
381 result->solver->setCachingEnabled(true);
382 auto req = result->solver->getRequirements(*result->env, storm::solver::OptimizationDirection::Maximize, false);
383 boost::optional<ValueType> lowerBound = this->computeWeightedResultBound(true, weightVector, storm::storage::BitVector(weightVector.size(), true));
384 if (lowerBound) {
385 result->solver->setLowerBound(lowerBound.get());
386 req.clearLowerBounds();
387 }
388 boost::optional<ValueType> upperBound = this->computeWeightedResultBound(false, weightVector, storm::storage::BitVector(weightVector.size(), true));
389 if (upperBound) {
390 result->solver->setUpperBound(upperBound.get());
391 req.clearUpperBounds();
392 }
393 if (acyclic) {
394 req.clearAcyclic();
395 }
396 STORM_LOG_THROW(!req.hasEnabledCriticalRequirement(), storm::exceptions::UncheckedRequirementException,
397 "Solver requirements " + req.getEnabledRequirementsAsString() + " not checked.");
398 result->solver->setRequirementsChecked(true);
399 result->solver->setOptimizationDirection(storm::solver::OptimizationDirection::Maximize);
400
401 result->b.resize(PS.getNumberOfChoices());
402
403 return result;
404}
405
406template<class SparseMaModelType>
407template<typename VT, typename std::enable_if<storm::NumberTraits<VT>::SupportsExponential, int>::type>
408std::unique_ptr<typename StandardMaPcaaWeightVectorChecker<SparseMaModelType>::LinEqSolverData>
410 std::unique_ptr<LinEqSolverData> result(new LinEqSolverData());
411 result->env = std::make_unique<Environment>(env);
412 result->acyclic = acyclic;
413 // For acyclic models we switch to the more efficient acyclic solver (Unless the solver / method was explicitly specified)
414 if (acyclic) {
415 result->env->solver().setLinearEquationSolverType(storm::solver::EquationSolverType::Acyclic);
416 }
417 result->factory = std::make_unique<storm::solver::GeneralLinearEquationSolverFactory<ValueType>>();
418 result->b.resize(PS.getNumberOfStates());
419 return result;
420}
421
422template<class SparseMaModelType>
423template<typename VT, typename std::enable_if<!storm::NumberTraits<VT>::SupportsExponential, int>::type>
424std::unique_ptr<typename StandardMaPcaaWeightVectorChecker<SparseMaModelType>::LinEqSolverData>
425StandardMaPcaaWeightVectorChecker<SparseMaModelType>::initLinEqSolver(Environment const& /*env*/, SubModel const& /*PS*/, bool /*acyclic*/) const {
426 STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Computing bounded probabilities of MAs is unsupported for this value type.");
427}
428
429template<class SparseMaModelType>
430void StandardMaPcaaWeightVectorChecker<SparseMaModelType>::updateDataToCurrentEpoch(
431 SubModel& MS, SubModel& PS, MinMaxSolverData& minMax, storm::storage::BitVector& consideredObjectives, uint_fast64_t const& currentEpoch,
432 std::vector<ValueType> const& weightVector, TimeBoundMap::iterator& upperTimeBoundIt, TimeBoundMap const& upperTimeBounds) {
433 if (upperTimeBoundIt != upperTimeBounds.end() && currentEpoch == upperTimeBoundIt->first) {
434 consideredObjectives |= upperTimeBoundIt->second;
435 for (auto objIndex : upperTimeBoundIt->second) {
436 // This objective now plays a role in the weighted sum
437 ValueType factor =
438 storm::solver::minimize(this->objectives[objIndex].formula->getOptimalityType()) ? -weightVector[objIndex] : weightVector[objIndex];
439 storm::utility::vector::addScaledVector(MS.weightedRewardVector, MS.objectiveRewardVectors[objIndex], factor);
440 storm::utility::vector::addScaledVector(PS.weightedRewardVector, PS.objectiveRewardVectors[objIndex], factor);
441 }
442 ++upperTimeBoundIt;
443 }
444
445 // Update the solver data
446 PS.toMS.multiplyWithVector(MS.weightedSolutionVector, minMax.b);
447 storm::utility::vector::addVectors(minMax.b, PS.weightedRewardVector, minMax.b);
448}
449
450template<class SparseMaModelType>
451void StandardMaPcaaWeightVectorChecker<SparseMaModelType>::performPSStep(Environment const& env, SubModel& PS, SubModel const& MS, MinMaxSolverData& minMax,
452 LinEqSolverData& linEq, std::vector<uint_fast64_t>& optimalChoicesAtCurrentEpoch,
453 storm::storage::BitVector const& consideredObjectives,
454 std::vector<ValueType> const& weightVector) const {
455 // compute a choice vector for the probabilistic states that is optimal w.r.t. the weighted reward vector
456 minMax.solver->solveEquations(*minMax.env, PS.weightedSolutionVector, minMax.b);
457 auto const& newChoices = minMax.solver->getSchedulerChoices();
458 if (consideredObjectives.getNumberOfSetBits() == 1 && storm::utility::isOne(weightVector[*consideredObjectives.begin()])) {
459 // In this case there is no need to perform the computation on the individual objectives
460 optimalChoicesAtCurrentEpoch = newChoices;
461 PS.objectiveSolutionVectors[*consideredObjectives.begin()] = PS.weightedSolutionVector;
462 if (storm::solver::minimize(this->objectives[*consideredObjectives.begin()].formula->getOptimalityType())) {
463 storm::utility::vector::scaleVectorInPlace(PS.objectiveSolutionVectors[*consideredObjectives.begin()], -storm::utility::one<ValueType>());
464 }
465 } else {
466 // check whether the linEqSolver needs to be updated, i.e., whether the scheduler has changed
467 if (linEq.solver == nullptr || newChoices != optimalChoicesAtCurrentEpoch) {
468 optimalChoicesAtCurrentEpoch = newChoices;
469 linEq.solver = nullptr;
470 bool needEquationSystem = linEq.factory->getEquationProblemFormat(*linEq.env) == storm::solver::LinearEquationSolverProblemFormat::EquationSystem;
471 storm::storage::SparseMatrix<ValueType> linEqMatrix = PS.toPS.selectRowsFromRowGroups(optimalChoicesAtCurrentEpoch, needEquationSystem);
472 if (needEquationSystem) {
473 linEqMatrix.convertToEquationSystem();
474 }
475 linEq.solver = linEq.factory->create(*linEq.env, std::move(linEqMatrix));
476 linEq.solver->setCachingEnabled(true);
477 auto req = linEq.solver->getRequirements(*linEq.env);
478 if (linEq.acyclic) {
479 req.clearAcyclic();
480 }
481 STORM_LOG_THROW(!req.hasEnabledCriticalRequirement(), storm::exceptions::UncheckedRequirementException,
482 "Solver requirements " + req.getEnabledRequirementsAsString() + " not checked.");
483 }
484
485 // Get the results for the individual objectives.
486 // 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
487 // pretty close
488 for (auto objIndex : consideredObjectives) {
489 auto const& objectiveRewardVectorPS = PS.objectiveRewardVectors[objIndex];
490 auto const& objectiveSolutionVectorMS = MS.objectiveSolutionVectors[objIndex];
491 // compute rhs of equation system, i.e., PS.toMS * x + Rewards
492 // To safe some time, only do this for the obtained optimal choices
493 auto itGroupIndex = PS.toPS.getRowGroupIndices().begin();
494 auto itChoiceOffset = optimalChoicesAtCurrentEpoch.begin();
495 for (auto& bValue : linEq.b) {
496 uint_fast64_t row = (*itGroupIndex) + (*itChoiceOffset);
497 bValue = objectiveRewardVectorPS[row];
498 for (auto const& entry : PS.toMS.getRow(row)) {
499 bValue += entry.getValue() * objectiveSolutionVectorMS[entry.getColumn()];
500 }
501 ++itGroupIndex;
502 ++itChoiceOffset;
503 }
504 linEq.solver->solveEquations(*linEq.env, PS.objectiveSolutionVectors[objIndex], linEq.b);
505 }
506 }
507}
508
509template<class SparseMaModelType>
510void StandardMaPcaaWeightVectorChecker<SparseMaModelType>::performMSStep(Environment const& env, SubModel& MS, SubModel const& PS,
511 storm::storage::BitVector const& consideredObjectives,
512 std::vector<ValueType> const& weightVector) const {
513 MS.toMS.multiplyWithVector(MS.weightedSolutionVector, MS.auxChoiceValues);
514 storm::utility::vector::addVectors(MS.weightedRewardVector, MS.auxChoiceValues, MS.weightedSolutionVector);
515 MS.toPS.multiplyWithVector(PS.weightedSolutionVector, MS.auxChoiceValues);
516 storm::utility::vector::addVectors(MS.weightedSolutionVector, MS.auxChoiceValues, MS.weightedSolutionVector);
517 if (consideredObjectives.getNumberOfSetBits() == 1 && storm::utility::isOne(weightVector[*consideredObjectives.begin()])) {
518 // In this case there is no need to perform the computation on the individual objectives
519 MS.objectiveSolutionVectors[*consideredObjectives.begin()] = MS.weightedSolutionVector;
520 if (storm::solver::minimize(this->objectives[*consideredObjectives.begin()].formula->getOptimalityType())) {
521 storm::utility::vector::scaleVectorInPlace(MS.objectiveSolutionVectors[*consideredObjectives.begin()], -storm::utility::one<ValueType>());
522 }
523 } else {
524 for (auto objIndex : consideredObjectives) {
525 MS.toMS.multiplyWithVector(MS.objectiveSolutionVectors[objIndex], MS.auxChoiceValues);
526 storm::utility::vector::addVectors(MS.objectiveRewardVectors[objIndex], MS.auxChoiceValues, MS.objectiveSolutionVectors[objIndex]);
527 MS.toPS.multiplyWithVector(PS.objectiveSolutionVectors[objIndex], MS.auxChoiceValues);
528 storm::utility::vector::addVectors(MS.objectiveSolutionVectors[objIndex], MS.auxChoiceValues, MS.objectiveSolutionVectors[objIndex]);
529 }
530 }
531}
532
533template class StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<double>>;
534template double StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<double>>::getDigitizationConstant<double>(
535 std::vector<double> const& direction) const;
536template void StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<double>>::digitize<double>(
537 StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<double>>::SubModel& subModel, double const& digitizationConstant) const;
538template std::unique_ptr<typename StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<double>>::LinEqSolverData>
539StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<double>>::initLinEqSolver<double>(
540 Environment const& env, StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<double>>::SubModel const& PS, bool acyclic) const;
541
542template class StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>>;
543template storm::RationalNumber StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>>::getDigitizationConstant<
544 storm::RationalNumber>(std::vector<storm::RationalNumber> const& direction) const;
545template void StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>>::digitize<storm::RationalNumber>(
546 StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>>::SubModel& subModel,
547 storm::RationalNumber const& digitizationConstant) const;
548template std::unique_ptr<typename StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>>::LinEqSolverData>
549StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>>::initLinEqSolver<storm::RationalNumber>(
550 Environment const& env, StandardMaPcaaWeightVectorChecker<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>>::SubModel const& PS,
551 bool acyclic) const;
552
553} // namespace multiobjective
554} // namespace modelchecker
555} // 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 bool smallPrecisionsAreChallenging() const override
Returns whether achieving precise values (i.e.
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
SFTBDDChecker::ValueType ValueType
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)