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