Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SymbolicMinMaxLinearEquationSolver.cpp
Go to the documentation of this file.
2
3#include "storm/dd/Add.h"
4#include "storm/dd/Bdd.h"
13#include "storm/utility/dd.h"
15
16namespace storm {
17namespace solver {
18
19template<storm::dd::DdType DdType, typename ValueType>
24
25template<storm::dd::DdType DdType, typename ValueType>
28 std::set<storm::expressions::Variable> const& rowMetaVariables, std::set<storm::expressions::Variable> const& columnMetaVariables,
29 std::set<storm::expressions::Variable> const& choiceVariables,
30 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs,
32 : SymbolicEquationSolver<DdType, ValueType>(allRows),
33 A(A),
35 illegalMaskAdd(illegalMask.ite(A.getDdManager().getConstant(storm::utility::infinity<ValueType>()), A.getDdManager().template getAddZero<ValueType>())),
41 uniqueSolution(false),
42 requirementsChecked(false) {
43 // Intentionally left empty.
44}
45
46template<storm::dd::DdType DdType, typename ValueType>
47MinMaxMethod SymbolicMinMaxLinearEquationSolver<DdType, ValueType>::getMethod(Environment const& env, bool isExactMode) const {
48 // Adjust the method if none was specified and we are using rational numbers.
49 auto method = env.solver().minMax().getMethod();
50
51 if (isExactMode && method != MinMaxMethod::RationalSearch) {
52 if (env.solver().minMax().isMethodSetFromDefault()) {
54 "Selecting 'rational search' as the solution technique to guarantee exact results. If you want to override this, please explicitly specify a "
55 "different method.");
56 method = MinMaxMethod::RationalSearch;
57 } else {
58 STORM_LOG_WARN("The selected solution method does not guarantee exact results.");
59 }
60 }
61 if (method != MinMaxMethod::ValueIteration && method != MinMaxMethod::PolicyIteration && method != MinMaxMethod::RationalSearch) {
62 STORM_LOG_WARN("Selected method is not supported for this solver, switching to value iteration.");
63 method = MinMaxMethod::ValueIteration;
64 }
65
66 return method;
67}
68
69template<storm::dd::DdType DdType, typename ValueType>
73 storm::dd::Add<DdType, ValueType> const& b) const {
75 "The requirements of the solver have not been marked as checked. Please provide the appropriate check or mark the requirements "
76 "as checked (if applicable).");
77
78 switch (getMethod(env, std::is_same<ValueType, storm::RationalNumber>::value)) {
79 case MinMaxMethod::ValueIteration:
80 return solveEquationsValueIteration(env, dir, x, b);
81 break;
82 case MinMaxMethod::PolicyIteration:
83 return solveEquationsPolicyIteration(env, dir, x, b);
84 break;
85 case MinMaxMethod::RationalSearch:
86 return solveEquationsRationalSearch(env, dir, x, b);
87 break;
88 default:
89 STORM_LOG_THROW(false, storm::exceptions::InvalidEnvironmentException, "The selected min max technique is not supported by this solver.");
90 }
92}
93
94template<storm::dd::DdType DdType, typename ValueType>
95typename SymbolicMinMaxLinearEquationSolver<DdType, ValueType>::ValueIterationResult
96SymbolicMinMaxLinearEquationSolver<DdType, ValueType>::performValueIteration(storm::solver::OptimizationDirection const& dir,
98 storm::dd::Add<DdType, ValueType> const& b, ValueType const& precision,
99 bool relativeTerminationCriterion, uint64_t maximalIterations) const {
100 // Set up local variables.
102 uint64_t iterations = 0;
103
104 // Value iteration loop.
106 while (status == SolverStatus::InProgress && iterations < maximalIterations) {
107 // Compute tmp = A * x + b
108 storm::dd::Add<DdType, ValueType> localXAsColumn = localX.swapVariables(this->rowColumnMetaVariablePairs);
109 storm::dd::Add<DdType, ValueType> tmp = this->A.multiplyMatrix(localXAsColumn, this->columnMetaVariables);
110 tmp += b;
111
112 if (dir == storm::solver::OptimizationDirection::Minimize) {
113 tmp += illegalMaskAdd;
114 tmp = tmp.minAbstract(this->choiceVariables);
115 } else {
116 tmp = tmp.maxAbstract(this->choiceVariables);
117 }
118
119 // Now check if the process already converged within our precision.
120 if (localX.equalModuloPrecision(tmp, precision, relativeTerminationCriterion)) {
122 }
123
124 // Set up next iteration.
125 localX = tmp;
126 ++iterations;
128 status = SolverStatus::Aborted;
129 }
130 }
131
132 if (status == SolverStatus::InProgress && iterations < maximalIterations) {
134 }
135
136 return SymbolicMinMaxLinearEquationSolver<DdType, ValueType>::ValueIterationResult(status, iterations, localX);
137}
138
139template<storm::dd::DdType DdType, typename ValueType>
141 storm::dd::Add<DdType, ValueType> const& b) const {
143 storm::dd::Add<DdType, ValueType> tmp = this->A.multiplyMatrix(xAsColumn, this->columnMetaVariables);
144 tmp += b;
145
146 if (dir == storm::solver::OptimizationDirection::Minimize) {
147 tmp += illegalMaskAdd;
148 tmp = tmp.minAbstract(this->choiceVariables);
149 } else {
150 tmp = tmp.maxAbstract(this->choiceVariables);
151 }
152
153 return x == tmp;
154}
155
156template<storm::dd::DdType DdType, typename ValueType>
157template<typename RationalType, typename ImpreciseType>
158storm::dd::Add<DdType, RationalType> SymbolicMinMaxLinearEquationSolver<DdType, ValueType>::sharpen(
159 OptimizationDirection dir, uint64_t precision, SymbolicMinMaxLinearEquationSolver<DdType, RationalType> const& rationalSolver,
160 storm::dd::Add<DdType, ImpreciseType> const& x, storm::dd::Add<DdType, RationalType> const& rationalB, bool& isSolution) {
162
163 for (uint64_t p = 1; p < precision; ++p) {
164 sharpenedX = x.sharpenKwekMehlhorn(p);
165 isSolution = rationalSolver.isSolution(dir, sharpenedX, rationalB);
166
167 if (isSolution) {
168 break;
169 }
170 }
171
172 return sharpenedX;
173}
174
175template<storm::dd::DdType DdType, typename ValueType>
176template<typename RationalType, typename ImpreciseType>
177storm::dd::Add<DdType, RationalType> SymbolicMinMaxLinearEquationSolver<DdType, ValueType>::solveEquationsRationalSearchHelper(
178 Environment const& env, OptimizationDirection dir, SymbolicMinMaxLinearEquationSolver<DdType, RationalType> const& rationalSolver,
179 SymbolicMinMaxLinearEquationSolver<DdType, ImpreciseType> const& impreciseSolver, storm::dd::Add<DdType, RationalType> const& rationalB,
180 storm::dd::Add<DdType, ImpreciseType> const& x, storm::dd::Add<DdType, ImpreciseType> const& b) const {
181 // Storage for the rational sharpened vector and the power iteration intermediate vector.
182 storm::dd::Add<DdType, RationalType> sharpenedX;
183 storm::dd::Add<DdType, ImpreciseType> currentX = x;
184
185 // The actual rational search.
186 uint64_t overallIterations = 0;
187 uint64_t valueIterationInvocations = 0;
188 ValueType precision = storm::utility::convertNumber<ValueType>(env.solver().minMax().getPrecision());
189 uint64_t maxIter = env.solver().minMax().getMaximalNumberOfIterations();
190 bool relative = env.solver().minMax().getRelativeTerminationCriterion();
192 while (status == SolverStatus::InProgress && overallIterations < maxIter) {
193 typename SymbolicMinMaxLinearEquationSolver<DdType, ImpreciseType>::ValueIterationResult viResult =
194 impreciseSolver.performValueIteration(dir, currentX, b, storm::utility::convertNumber<ImpreciseType, ValueType>(precision), relative, maxIter);
195
196 ++valueIterationInvocations;
197 STORM_LOG_TRACE("Completed " << valueIterationInvocations << " value iteration invocations, the last one with precision " << precision
198 << " completed in " << viResult.iterations << " iterations.");
199
200 // Count the iterations.
201 overallIterations += viResult.iterations;
202
203 // Compute maximal precision until which to sharpen.
204 uint64_t p =
206
207 bool isSolution = false;
208 sharpenedX = sharpen<RationalType, ImpreciseType>(dir, p, rationalSolver, viResult.values, rationalB, isSolution);
209
210 if (isSolution) {
212 } else {
213 currentX = viResult.values;
215 }
217 status = SolverStatus::Aborted;
218 }
219 }
220
221 if (status == SolverStatus::InProgress && overallIterations < maxIter) {
223 }
224
225 if (status == SolverStatus::Converged) {
226 STORM_LOG_INFO("Iterative solver (rational search) converged in " << overallIterations << " iterations.");
227 } else {
228 STORM_LOG_WARN("Iterative solver (rational search) did not converge in " << overallIterations << " iterations.");
229 }
230
231 return sharpenedX;
232}
233
234template<storm::dd::DdType DdType, typename ValueType>
235template<typename ImpreciseType>
236typename std::enable_if<std::is_same<ValueType, ImpreciseType>::value && storm::NumberTraits<ValueType>::IsExact, storm::dd::Add<DdType, ValueType>>::type
237SymbolicMinMaxLinearEquationSolver<DdType, ValueType>::solveEquationsRationalSearchHelper(Environment const& env,
239 storm::dd::Add<DdType, ValueType> const& x,
240 storm::dd::Add<DdType, ValueType> const& b) const {
241 return solveEquationsRationalSearchHelper<ValueType, ValueType>(env, dir, *this, *this, b, this->getLowerBoundsVector(), b);
242}
243
244template<storm::dd::DdType DdType, typename ValueType>
245template<typename ImpreciseType>
246typename std::enable_if<std::is_same<ValueType, ImpreciseType>::value && !storm::NumberTraits<ValueType>::IsExact, storm::dd::Add<DdType, ValueType>>::type
247SymbolicMinMaxLinearEquationSolver<DdType, ValueType>::solveEquationsRationalSearchHelper(Environment const& env,
249 storm::dd::Add<DdType, ValueType> const& x,
250 storm::dd::Add<DdType, ValueType> const& b) const {
251 if constexpr (storm::dd::BackendTraits<DdType>::template supportsValueType<storm::RationalNumber>) {
252 storm::dd::Add<DdType, storm::RationalNumber> rationalB = b.template toValueType<storm::RationalNumber>();
254 this->A.template toValueType<storm::RationalNumber>(), this->allRows, this->illegalMask, this->rowMetaVariables, this->columnMetaVariables,
255 this->choiceVariables, this->rowColumnMetaVariablePairs,
257
258 storm::dd::Add<DdType, storm::RationalNumber> rationalResult = solveEquationsRationalSearchHelper<storm::RationalNumber, ImpreciseType>(
259 env, dir, rationalSolver, *this, rationalB, this->getLowerBoundsVector(), b);
260 return rationalResult.template toValueType<ValueType>();
261 } else {
262 STORM_LOG_THROW_UNCONDITIONALLY(storm::exceptions::NotSupportedException,
263 "Rational search is not supported, as the selected DD library does not support rational numbers.");
264 }
265}
266
267template<storm::dd::DdType DdType, typename ValueType>
268template<typename ImpreciseType>
269typename std::enable_if<!std::is_same<ValueType, ImpreciseType>::value, storm::dd::Add<DdType, ValueType>>::type
270SymbolicMinMaxLinearEquationSolver<DdType, ValueType>::solveEquationsRationalSearchHelper(Environment const& env,
272 storm::dd::Add<DdType, ValueType> const& x,
273 storm::dd::Add<DdType, ValueType> const& b) const {
274 // First try to find a solution using the imprecise value type.
275 storm::dd::Add<DdType, ValueType> rationalResult;
276 storm::dd::Add<DdType, ImpreciseType> impreciseX;
277 try {
278 impreciseX = this->getLowerBoundsVector().template toValueType<ImpreciseType>();
279 storm::dd::Add<DdType, ImpreciseType> impreciseB = b.template toValueType<ImpreciseType>();
281 this->A.template toValueType<ImpreciseType>(), this->allRows, this->illegalMask, this->rowMetaVariables, this->columnMetaVariables,
282 this->choiceVariables, this->rowColumnMetaVariablePairs, std::make_unique<GeneralSymbolicLinearEquationSolverFactory<DdType, ImpreciseType>>());
283
284 rationalResult = solveEquationsRationalSearchHelper<ValueType, ImpreciseType>(env, dir, *this, impreciseSolver, b, impreciseX, impreciseB);
285 } catch (storm::exceptions::PrecisionExceededException const&) {
286 STORM_LOG_WARN("Precision of value type was exceeded, trying to recover by switching to rational arithmetic.");
287
288 // Fall back to precise value type if the precision of the imprecise value type was exceeded.
289 rationalResult = solveEquationsRationalSearchHelper<ValueType, ValueType>(env, dir, *this, *this, b, impreciseX.template toValueType<ValueType>(), b);
290 }
291 return rationalResult.template toValueType<ValueType>();
292}
293
294template<storm::dd::DdType DdType, typename ValueType>
295storm::dd::Add<DdType, ValueType> SymbolicMinMaxLinearEquationSolver<DdType, ValueType>::solveEquationsRationalSearch(
296 Environment const& env, storm::solver::OptimizationDirection const& dir, storm::dd::Add<DdType, ValueType> const& x,
297 storm::dd::Add<DdType, ValueType> const& b) const {
298 return solveEquationsRationalSearchHelper<double>(env, dir, x, b);
299}
300
301template<storm::dd::DdType DdType, typename ValueType>
302storm::dd::Add<DdType, ValueType> SymbolicMinMaxLinearEquationSolver<DdType, ValueType>::solveEquationsValueIteration(
303 Environment const& env, storm::solver::OptimizationDirection const& dir, storm::dd::Add<DdType, ValueType> const& x,
304 storm::dd::Add<DdType, ValueType> const& b) const {
305 // Set up the environment.
306 storm::dd::Add<DdType, ValueType> localX;
307
308 if (this->hasUniqueSolution()) {
309 localX = x;
310 } else {
311 // If we were given an initial scheduler, we take its solution as the starting point.
312 if (this->hasInitialScheduler()) {
313 // The linear equation solver should be at least as precise as this solver
314 std::unique_ptr<storm::Environment> environmentOfSolverStorage;
315 auto precOfSolver = env.solver().getPrecisionOfLinearEquationSolver(env.solver().getLinearEquationSolverType());
317 bool changePrecision = precOfSolver.first && precOfSolver.first.get() > env.solver().minMax().getPrecision();
318 bool changeRelative = precOfSolver.second && !precOfSolver.second.get() && env.solver().minMax().getRelativeTerminationCriterion();
319 if (changePrecision || changeRelative) {
320 environmentOfSolverStorage = std::make_unique<storm::Environment>(env);
321 boost::optional<storm::RationalNumber> newPrecision;
322 boost::optional<bool> newRelative;
323 if (changePrecision) {
324 newPrecision = env.solver().minMax().getPrecision();
325 }
326 if (changeRelative) {
327 newRelative = true;
328 }
329 environmentOfSolverStorage->solver().setLinearEquationSolverPrecision(newPrecision, newRelative);
330 }
331 }
332 storm::Environment const& environmentOfSolver = environmentOfSolverStorage ? *environmentOfSolverStorage : env;
333 localX = solveEquationsWithScheduler(environmentOfSolver, this->getInitialScheduler(), x, b);
334 } else {
335 localX = this->getLowerBoundsVector();
336 }
337 }
338
339 ValueType precision = storm::utility::convertNumber<ValueType>(env.solver().minMax().getPrecision());
340 ValueIterationResult viResult = performValueIteration(dir, localX, b, precision, env.solver().minMax().getRelativeTerminationCriterion(),
341 env.solver().minMax().getMaximalNumberOfIterations());
342
343 if (viResult.status == SolverStatus::Converged) {
344 STORM_LOG_INFO("Iterative solver (value iteration) converged in " << viResult.iterations << " iterations.");
345 } else {
346 STORM_LOG_WARN("Iterative solver (value iteration) did not converge in " << viResult.iterations << " iterations.");
347 }
348
349 return viResult.values;
350}
351
352template<storm::dd::DdType DdType, typename ValueType>
353storm::dd::Add<DdType, ValueType> SymbolicMinMaxLinearEquationSolver<DdType, ValueType>::solveEquationsWithScheduler(
354 Environment const& env, storm::dd::Bdd<DdType> const& scheduler, storm::dd::Add<DdType, ValueType> const& x,
355 storm::dd::Add<DdType, ValueType> const& b) const {
356 std::unique_ptr<SymbolicLinearEquationSolver<DdType, ValueType>> solver =
357 linearEquationSolverFactory->create(env, this->allRows, this->rowMetaVariables, this->columnMetaVariables, this->rowColumnMetaVariablePairs);
358 this->forwardBounds(*solver);
359
360 storm::dd::Add<DdType, ValueType> diagonal =
361 (storm::utility::dd::getRowColumnDiagonal<DdType>(x.getDdManager(), this->rowColumnMetaVariablePairs) && this->allRows).template toAdd<ValueType>();
362 return solveEquationsWithScheduler(env, *solver, scheduler, x, b, diagonal);
363}
364
365template<storm::dd::DdType DdType, typename ValueType>
366storm::dd::Add<DdType, ValueType> SymbolicMinMaxLinearEquationSolver<DdType, ValueType>::solveEquationsWithScheduler(
367 Environment const& env, SymbolicLinearEquationSolver<DdType, ValueType>& solver, storm::dd::Bdd<DdType> const& scheduler,
368 storm::dd::Add<DdType, ValueType> const& x, storm::dd::Add<DdType, ValueType> const& b, storm::dd::Add<DdType, ValueType> const& diagonal) const {
369 // Apply scheduler to the matrix and vector.
370 storm::dd::Add<DdType, ValueType> schedulerA =
371 scheduler.ite(this->A, scheduler.getDdManager().template getAddZero<ValueType>()).sumAbstract(this->choiceVariables);
372 if (solver.getEquationProblemFormat(env) == storm::solver::LinearEquationSolverProblemFormat::EquationSystem) {
373 schedulerA = diagonal - schedulerA;
374 }
375
376 storm::dd::Add<DdType, ValueType> schedulerB =
377 scheduler.ite(b, scheduler.getDdManager().template getAddZero<ValueType>()).sumAbstract(this->choiceVariables);
378
379 // Set the matrix for the solver.
380 solver.setMatrix(schedulerA);
381
382 // Solve for the value of the scheduler.
383 storm::dd::Add<DdType, ValueType> schedulerX = solver.solveEquations(env, x, schedulerB);
384
385 return schedulerX;
386}
387
388template<storm::dd::DdType DdType, typename ValueType>
389storm::dd::Add<DdType, ValueType> SymbolicMinMaxLinearEquationSolver<DdType, ValueType>::solveEquationsPolicyIteration(
390 Environment const& env, storm::solver::OptimizationDirection const& dir, storm::dd::Add<DdType, ValueType> const& x,
391 storm::dd::Add<DdType, ValueType> const& b) const {
392 // Set up the environment.
393 storm::dd::Add<DdType, ValueType> currentSolution = x;
394 storm::dd::Add<DdType, ValueType> diagonal =
395 (storm::utility::dd::getRowColumnDiagonal<DdType>(x.getDdManager(), this->rowColumnMetaVariablePairs) && this->allRows).template toAdd<ValueType>();
396 uint_fast64_t iterations = 0;
397 bool converged = false;
398
399 // Choose initial scheduler.
400 storm::dd::Bdd<DdType> scheduler =
401 this->hasInitialScheduler()
402 ? this->getInitialScheduler()
403 : (this->A.sumAbstract(this->columnMetaVariables).notZero() || b.notZero()).existsAbstractRepresentative(this->choiceVariables);
404
405 // Initialize linear equation solver.
406 // It should be at least as precise as this solver.
407 std::unique_ptr<storm::Environment> environmentOfSolverStorage;
408 auto precOfSolver = env.solver().getPrecisionOfLinearEquationSolver(env.solver().getLinearEquationSolverType());
410 bool changePrecision = precOfSolver.first && precOfSolver.first.get() > env.solver().minMax().getPrecision();
411 bool changeRelative = precOfSolver.second && !precOfSolver.second.get() && env.solver().minMax().getRelativeTerminationCriterion();
412 if (changePrecision || changeRelative) {
413 environmentOfSolverStorage = std::make_unique<storm::Environment>(env);
414 boost::optional<storm::RationalNumber> newPrecision;
415 boost::optional<bool> newRelative;
416 if (changePrecision) {
417 newPrecision = env.solver().minMax().getPrecision();
418 }
419 if (changeRelative) {
420 newRelative = true;
421 }
422 environmentOfSolverStorage->solver().setLinearEquationSolverPrecision(newPrecision, newRelative);
423 }
424 }
425 storm::Environment const& environmentOfSolver = environmentOfSolverStorage ? *environmentOfSolverStorage : env;
426
427 std::unique_ptr<SymbolicLinearEquationSolver<DdType, ValueType>> linearEquationSolver = linearEquationSolverFactory->create(
428 environmentOfSolver, this->allRows, this->rowMetaVariables, this->columnMetaVariables, this->rowColumnMetaVariablePairs);
429 this->forwardBounds(*linearEquationSolver);
430
431 // Iteratively solve and improve the scheduler.
432 uint64_t maxIter = env.solver().minMax().getMaximalNumberOfIterations();
433 while (!converged && iterations < maxIter) {
434 storm::dd::Add<DdType, ValueType> schedulerX =
435 solveEquationsWithScheduler(environmentOfSolver, *linearEquationSolver, scheduler, currentSolution, b, diagonal);
436
437 // Policy improvement step.
438 storm::dd::Add<DdType, ValueType> choiceValues =
439 this->A.multiplyMatrix(schedulerX.swapVariables(this->rowColumnMetaVariablePairs), this->columnMetaVariables) + b;
440
441 storm::dd::Bdd<DdType> nextScheduler;
442 if (dir == storm::solver::OptimizationDirection::Minimize) {
443 choiceValues += illegalMaskAdd;
444
445 storm::dd::Add<DdType, ValueType> newStateValues = choiceValues.minAbstract(this->choiceVariables);
446 storm::dd::Bdd<DdType> improvedStates = newStateValues.less(schedulerX);
447
448 nextScheduler = improvedStates.ite(choiceValues.minAbstractRepresentative(this->choiceVariables), scheduler);
449 } else {
450 storm::dd::Add<DdType, ValueType> newStateValues = choiceValues.maxAbstract(this->choiceVariables);
451 storm::dd::Bdd<DdType> improvedStates = newStateValues.greater(schedulerX);
452
453 nextScheduler = improvedStates.ite(choiceValues.maxAbstractRepresentative(this->choiceVariables), scheduler);
454 }
455
456 // Check for convergence.
457 converged = nextScheduler == scheduler;
458
459 // Set up next iteration.
460 if (!converged) {
461 scheduler = nextScheduler;
462 }
463
464 currentSolution = schedulerX;
465 ++iterations;
466 }
467
468 if (converged) {
469 STORM_LOG_INFO("Iterative solver (policy iteration) converged in " << iterations << " iterations.");
470 } else {
471 STORM_LOG_WARN("Iterative solver (policy iteration) did not converge in " << iterations << " iterations.");
472 }
473
474 return currentSolution;
475}
476
477template<storm::dd::DdType DdType, typename ValueType>
481 uint_fast64_t n) const {
483
484 // Perform matrix-vector multiplication while the bound is met.
485 for (uint_fast64_t i = 0; i < n; ++i) {
486 xCopy = xCopy.swapVariables(this->rowColumnMetaVariablePairs);
487 xCopy = this->A.multiplyMatrix(xCopy, this->columnMetaVariables);
488 if (b != nullptr) {
489 xCopy += *b;
490 }
491
492 if (dir == storm::solver::OptimizationDirection::Minimize) {
493 // This is a hack and only here because of the lack of a suitable minAbstract/maxAbstract function
494 // that can properly deal with a restriction of the choices.
495 xCopy += illegalMaskAdd;
496 xCopy = xCopy.minAbstract(this->choiceVariables);
497 } else {
498 xCopy = xCopy.maxAbstract(this->choiceVariables);
499 }
500 }
501
502 return xCopy;
503}
504
505template<storm::dd::DdType DdType, typename ValueType>
509
510template<storm::dd::DdType DdType, typename ValueType>
514
515template<storm::dd::DdType DdType, typename ValueType>
519
520template<storm::dd::DdType DdType, typename ValueType>
522 Environment const& env, boost::optional<storm::solver::OptimizationDirection> const& direction) const {
524
525 auto method = getMethod(env, std::is_same<ValueType, storm::RationalNumber>::value);
526 if (method == MinMaxMethod::PolicyIteration) {
527 if (!this->hasUniqueSolution()) {
528 requirements.requireValidInitialScheduler();
529 }
530 } else if (method == MinMaxMethod::ValueIteration) {
531 if (!this->hasUniqueSolution()) {
532 if (!direction || direction.get() == storm::solver::OptimizationDirection::Maximize) {
533 requirements.requireLowerBounds();
534 }
535 if (!direction || direction.get() == storm::solver::OptimizationDirection::Minimize) {
536 requirements.requireValidInitialScheduler();
537 }
538 }
539 } else if (method == MinMaxMethod::RationalSearch) {
540 requirements.requireLowerBounds();
541 // RationalSearch guesses and verifies a fixpoint and terminates once a fixpoint is found. To ensure that the guessed fixpoint is the
542 // correct one, we enforce uniqueness.
543 if (!this->hasUniqueSolution()) {
544 requirements.requireUniqueSolution();
545 }
546 } else {
547 STORM_LOG_THROW(false, storm::exceptions::InvalidEnvironmentException, "The selected min max technique is not supported by this solver.");
548 }
549
550 return requirements;
551}
552
553template<storm::dd::DdType DdType, typename ValueType>
557
558template<storm::dd::DdType DdType, typename ValueType>
562
563template<storm::dd::DdType DdType, typename ValueType>
567
568template<storm::dd::DdType DdType, typename ValueType>
572
573template<storm::dd::DdType DdType, typename ValueType>
574void SymbolicMinMaxLinearEquationSolver<DdType, ValueType>::forwardBounds(storm::solver::SymbolicLinearEquationSolver<DdType, ValueType>& solver) const {
575 if (this->hasLowerBound()) {
576 solver.setLowerBound(this->getLowerBound());
577 }
578 if (this->hasLowerBounds()) {
579 solver.setLowerBounds(this->getLowerBounds());
580 }
581 if (this->hasUpperBound()) {
582 solver.setUpperBound(this->getUpperBound());
583 }
584 if (this->hasUpperBounds()) {
585 solver.setUpperBounds(this->getUpperBounds());
586 }
587}
588
589template<storm::dd::DdType DdType, typename ValueType>
591 Environment const& env, bool hasUniqueSolution, boost::optional<storm::solver::OptimizationDirection> const& direction) const {
592 std::unique_ptr<storm::solver::SymbolicMinMaxLinearEquationSolver<DdType, ValueType>> solver = this->create();
593 solver->setHasUniqueSolution(hasUniqueSolution);
594 return solver->getRequirements(env, direction);
595}
596
597template<storm::dd::DdType DdType, typename ValueType>
598std::unique_ptr<storm::solver::SymbolicMinMaxLinearEquationSolver<DdType, ValueType>>
600 storm::dd::Add<DdType, ValueType> const& A, storm::dd::Bdd<DdType> const& allRows, storm::dd::Bdd<DdType> const& illegalMask,
601 std::set<storm::expressions::Variable> const& rowMetaVariables, std::set<storm::expressions::Variable> const& columnMetaVariables,
602 std::set<storm::expressions::Variable> const& choiceVariables,
603 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs) const {
604 return std::make_unique<SymbolicMinMaxLinearEquationSolver<DdType, ValueType>>(
605 A, allRows, illegalMask, rowMetaVariables, columnMetaVariables, choiceVariables, rowColumnMetaVariablePairs,
606 std::make_unique<GeneralSymbolicLinearEquationSolverFactory<DdType, ValueType>>());
607}
608
609template<storm::dd::DdType DdType, typename ValueType>
610std::unique_ptr<storm::solver::SymbolicMinMaxLinearEquationSolver<DdType, ValueType>>
612 return std::make_unique<SymbolicMinMaxLinearEquationSolver<DdType, ValueType>>();
613}
614
615template class SymbolicMinMaxLinearEquationSolver<storm::dd::DdType::CUDD, double>;
616template class SymbolicMinMaxLinearEquationSolver<storm::dd::DdType::Sylvan, double>;
617template class SymbolicMinMaxLinearEquationSolver<storm::dd::DdType::Sylvan, storm::RationalNumber>;
618
619template class GeneralSymbolicMinMaxLinearEquationSolverFactory<storm::dd::DdType::CUDD, double>;
620template class GeneralSymbolicMinMaxLinearEquationSolverFactory<storm::dd::DdType::Sylvan, double>;
621template class GeneralSymbolicMinMaxLinearEquationSolverFactory<storm::dd::DdType::Sylvan, storm::RationalNumber>;
622
623} // namespace solver
624} // namespace storm
SolverEnvironment & solver()
storm::solver::MinMaxMethod const & getMethod() const
MinMaxSolverEnvironment & minMax()
Add< LibraryType, ValueType > swapVariables(std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const &metaVariablePairs) const
Swaps the given pairs of meta variables in the ADD.
Definition Add.cpp:276
Bdd< LibraryType > greater(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are gre...
Definition Add.cpp:109
Add< LibraryType, storm::RationalNumber > sharpenKwekMehlhorn(uint64_t precision) const
Retrieves the function that sharpens all values in the current ADD with the Kwek-Mehlhorn algorithm.
Definition Add.cpp:144
Add< LibraryType, ValueType > maxAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Max-abstracts from the given meta variables.
Definition Add.cpp:182
Bdd< LibraryType > minAbstractRepresentative(std::set< storm::expressions::Variable > const &metaVariables) const
Similar to minAbstract, but does not abstract from the variables but rather picks a valuation of each...
Definition Add.cpp:176
Add< LibraryType, ValueType > minAbstract(std::set< storm::expressions::Variable > const &metaVariables) const
Min-abstracts from the given meta variables.
Definition Add.cpp:169
Add< LibraryType, ValueType > multiplyMatrix(Add< LibraryType, ValueType > const &otherMatrix, std::set< storm::expressions::Variable > const &summationMetaVariables) const
Multiplies the current ADD (representing a matrix) with the given matrix by summing over the given me...
Definition Add.cpp:356
bool equalModuloPrecision(Add< LibraryType, ValueType > const &other, ValueType const &precision, bool relative=true) const
Checks whether the current and the given ADD represent the same function modulo some given precision.
Definition Add.cpp:195
Bdd< LibraryType > maxAbstractRepresentative(std::set< storm::expressions::Variable > const &metaVariables) const
Similar to maxAbstract, but does not abstract from the variables but rather picks a valuation of each...
Definition Add.cpp:189
Bdd< LibraryType > less(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are les...
Definition Add.cpp:99
Bdd< LibraryType > ite(Bdd< LibraryType > const &thenBdd, Bdd< LibraryType > const &elseBdd) const
Performs an if-then-else with the given operands, i.e.
Definition Bdd.cpp:107
DdManager< LibraryType > & getDdManager() const
Retrieves the manager that is responsible for this DD.
Definition Dd.cpp:38
virtual std::unique_ptr< storm::solver::SymbolicMinMaxLinearEquationSolver< DdType, ValueType > > create(storm::dd::Add< DdType, ValueType > const &A, storm::dd::Bdd< DdType > const &allRows, storm::dd::Bdd< DdType > const &illegalMask, std::set< storm::expressions::Variable > const &rowMetaVariables, std::set< storm::expressions::Variable > const &columnMetaVariables, std::set< storm::expressions::Variable > const &choiceVariables, std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const &rowColumnMetaVariablePairs) const override
MinMaxLinearEquationSolverRequirements & requireUniqueSolution(bool critical=true)
MinMaxLinearEquationSolverRequirements & requireLowerBounds(bool critical=true)
MinMaxLinearEquationSolverRequirements & requireValidInitialScheduler(bool critical=true)
virtual void setUpperBound(ValueType const &lowerBound)
virtual void setUpperBounds(storm::dd::Add< DdType, ValueType > const &upperBounds)
An interface that represents an abstract symbolic linear equation solver.
virtual std::unique_ptr< storm::solver::SymbolicMinMaxLinearEquationSolver< DdType, ValueType > > create(storm::dd::Add< DdType, ValueType > const &A, storm::dd::Bdd< DdType > const &allRows, storm::dd::Bdd< DdType > const &illegalMask, std::set< storm::expressions::Variable > const &rowMetaVariables, std::set< storm::expressions::Variable > const &columnMetaVariables, std::set< storm::expressions::Variable > const &choiceVariables, std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const &rowColumnMetaVariablePairs) const =0
MinMaxLinearEquationSolverRequirements getRequirements(Environment const &env, bool hasUniqueSolution=false, boost::optional< storm::solver::OptimizationDirection > const &direction=boost::none) const
Retrieves the requirements of the solver that would be created when calling create() right now.
An interface that represents an abstract symbolic linear equation solver.
bool hasUniqueSolution() const
Retrieves whether the solution to the min max equation system is assumed to be unique.
bool hasInitialScheduler() const
Retrieves whether an initial scheduler was set.
void setHasUniqueSolution(bool value=true)
Sets whether the solution to the min max equation system is known to be unique.
virtual storm::dd::Add< DdType, ValueType > multiply(storm::solver::OptimizationDirection const &dir, storm::dd::Add< DdType, ValueType > const &x, storm::dd::Add< DdType, ValueType > const *b=nullptr, uint_fast64_t n=1) const
Performs repeated matrix-vector multiplication, using x[0] = x and x[i + 1] = A*x[i] + b.
virtual storm::dd::Add< DdType, ValueType > solveEquations(Environment const &env, storm::solver::OptimizationDirection const &dir, storm::dd::Add< DdType, ValueType > const &x, storm::dd::Add< DdType, ValueType > const &b) const
Solves the equation system A*x = b.
bool isSolution(OptimizationDirection dir, storm::dd::Add< DdType, ValueType > const &x, storm::dd::Add< DdType, ValueType > const &b) const
Determines whether the given vector x satisfies x = min/max Ax + b.
void setInitialScheduler(storm::dd::Bdd< DdType > const &scheduler)
Sets an initial scheduler that is required by some solvers (see requirements).
bool isRequirementsCheckedSet() const
Retrieves whether the solver is aware that the requirements were checked.
storm::dd::Bdd< DdType > const & getInitialScheduler() const
Retrieves the initial scheduler (if there is any).
std::unique_ptr< SymbolicLinearEquationSolverFactory< DdType, ValueType > > linearEquationSolverFactory
void setRequirementsChecked(bool value=true)
Notifies the solver that the requirements for solving equations have been checked.
std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > rowColumnMetaVariablePairs
virtual MinMaxLinearEquationSolverRequirements getRequirements(Environment const &env, boost::optional< storm::solver::OptimizationDirection > const &direction=boost::none) const
Retrieves the requirements of the solver.
#define STORM_LOG_INFO(message)
Definition logging.h:34
#define STORM_LOG_WARN(message)
Definition logging.h:35
#define STORM_LOG_TRACE(message)
Definition logging.h:22
#define STORM_LOG_THROW_UNCONDITIONALLY(exception, message)
Definition macros.h:48
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
#define STORM_LOG_WARN_COND_DEBUG(cond, message)
Definition macros.h:16
SFTBDDChecker::ValueType ValueType
storm::dd::Bdd< Type > getRowColumnDiagonal(storm::dd::DdManager< Type > const &ddManager, std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const &rowColumnMetaVariablePairs)
Definition dd.cpp:88
bool isTerminate()
Check whether the program should terminate (due to some abort signal).
ValueType ceil(ValueType const &number)
ValueType one()
Definition constants.cpp:21
ValueType log10(ValueType const &number)
TargetType convertNumber(SourceType const &number)
The contract of a DD backend.
static const bool IsExact