Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
StandardGameSolver.h
Go to the documentation of this file.
1#pragma once
2
8
9namespace storm {
10namespace solver {
11
12template<typename ValueType>
13class StandardGameSolver : public GameSolver<ValueType> {
14 public:
15 // Constructors for when the first player is represented using a matrix.
17 storm::storage::SparseMatrix<ValueType> const& player2Matrix,
18 std::unique_ptr<LinearEquationSolverFactory<ValueType>>&& linearEquationSolverFactory);
21 std::unique_ptr<LinearEquationSolverFactory<ValueType>>&& linearEquationSolverFactory);
22
23 // Constructor for when the first player is represented by a grouping of the player 2 states (row groups).
24 StandardGameSolver(std::vector<uint64_t> const& player1Groups, storm::storage::SparseMatrix<ValueType> const& player2Matrix,
25 std::unique_ptr<LinearEquationSolverFactory<ValueType>>&& linearEquationSolverFactory);
26 StandardGameSolver(std::vector<uint64_t>&& player1Groups, storm::storage::SparseMatrix<ValueType>&& player2Matrix,
27 std::unique_ptr<LinearEquationSolverFactory<ValueType>>&& linearEquationSolverFactory);
28
29 virtual bool solveGame(Environment const& env, OptimizationDirection player1Dir, OptimizationDirection player2Dir, std::vector<ValueType>& x,
30 std::vector<ValueType> const& b, std::vector<uint64_t>* player1Choices = nullptr,
31 std::vector<uint64_t>* player2Choices = nullptr) const override;
32 virtual void repeatedMultiply(Environment const& env, OptimizationDirection player1Dir, OptimizationDirection player2Dir, std::vector<ValueType>& x,
33 std::vector<ValueType> const* b, uint_fast64_t n = 1) const override;
34
35 virtual void clearCache() const override;
36
37 private:
38 GameMethod getMethod(Environment const& env, bool isExactMode) const;
39
40 bool solveGamePolicyIteration(Environment const& env, OptimizationDirection player1Dir, OptimizationDirection player2Dir, std::vector<ValueType>& x,
41 std::vector<ValueType> const& b, std::vector<uint64_t>* player1Choices = nullptr,
42 std::vector<uint64_t>* player2Choices = nullptr) const;
43 bool solveGameValueIteration(Environment const& env, OptimizationDirection player1Dir, OptimizationDirection player2Dir, std::vector<ValueType>& x,
44 std::vector<ValueType> const& b, std::vector<uint64_t>* player1Choices = nullptr,
45 std::vector<uint64_t>* player2Choices = nullptr) const;
46
47 // Computes p2Matrix * x + b, reduces the result w.r.t. player 2 choices, and then reduces the result w.r.t. player 1 choices.
48 void multiplyAndReduce(Environment const& env, OptimizationDirection player1Dir, OptimizationDirection player2Dir, std::vector<ValueType>& x,
49 std::vector<ValueType> const* b, storm::solver::Multiplier<ValueType> const& multiplier,
50 std::vector<ValueType>& player2ReducedResult, std::vector<ValueType>& player1ReducedResult,
51 std::vector<uint64_t>* player1SchedulerChoices = nullptr, std::vector<uint64_t>* player2SchedulerChoices = nullptr) const;
52
53 // Solves the equation system given by the two choice selections
54 void getInducedMatrixVector(std::vector<ValueType>& x, std::vector<ValueType> const& b, std::vector<uint_fast64_t> const& player1Choices,
55 std::vector<uint_fast64_t> const& player2Choices, storm::storage::SparseMatrix<ValueType>& inducedMatrix,
56 std::vector<ValueType>& inducedVector) const;
57
58 // Extracts the choices of the different players for the given solution x.
59 // Returns true iff the newly extracted choices yield "better" values then the given choices for one of the players.
60 bool extractChoices(Environment const& env, OptimizationDirection player1Dir, OptimizationDirection player2Dir, std::vector<ValueType> const& x,
61 std::vector<ValueType> const& b, std::vector<ValueType>& player2ChoiceValues, std::vector<uint_fast64_t>& player1Choices,
62 std::vector<uint_fast64_t>& player2Choices) const;
63
64 bool valueImproved(OptimizationDirection dir, storm::utility::ConstantsComparator<ValueType> const& comparator, ValueType const& value1,
65 ValueType const& value2) const;
66
67 bool player1RepresentedByMatrix() const;
69 std::vector<uint64_t> const& getPlayer1Grouping() const;
70 uint64_t getNumberOfPlayer1States() const;
71 uint64_t getNumberOfPlayer2States() const;
72
73 // possibly cached data
74 mutable std::unique_ptr<storm::solver::Multiplier<ValueType>> multiplierPlayer2Matrix;
75 mutable std::unique_ptr<std::vector<ValueType>> auxiliaryP2RowVector; // player2Matrix.rowCount() entries
76 mutable std::unique_ptr<std::vector<ValueType>> auxiliaryP2RowGroupVector; // player2Matrix.rowGroupCount() entries
77 mutable std::unique_ptr<std::vector<ValueType>> auxiliaryP1RowGroupVector; // player1Matrix.rowGroupCount() entries
78
80 std::unique_ptr<LinearEquationSolverFactory<ValueType>> linearEquationSolverFactory;
81
82 // If the solver takes posession of the matrix, we store the moved matrix in this member, so it gets deleted
83 // when the solver is destructed.
84 std::unique_ptr<std::vector<uint64_t>> localPlayer1Grouping;
85 std::unique_ptr<storm::storage::SparseMatrix<storm::storage::sparse::state_type>> localPlayer1Matrix;
86 std::unique_ptr<storm::storage::SparseMatrix<ValueType>> localPlayer2Matrix;
87
88 // A reference to the original sparse matrix given to this solver. If the solver takes posession of the matrix
89 // the reference refers to localA.
90 std::vector<uint64_t> const* player1Grouping;
92 storm::storage::SparseMatrix<ValueType> const& player2Matrix;
93
96 bool linearEquationSolverIsExact;
97};
98} // namespace solver
99} // namespace storm
A class representing the interface that all game solvers shall implement.
Definition GameSolver.h:30
boost::optional< std::vector< uint_fast64_t > > player1SchedulerChoices
The scheduler choices that induce the optimal values (if they could be successfully generated).
Definition GameSolver.h:139
boost::optional< std::vector< uint_fast64_t > > player2SchedulerChoices
Definition GameSolver.h:140
virtual void clearCache() const override
virtual bool solveGame(Environment const &env, OptimizationDirection player1Dir, OptimizationDirection player2Dir, std::vector< ValueType > &x, std::vector< ValueType > const &b, std::vector< uint64_t > *player1Choices=nullptr, std::vector< uint64_t > *player2Choices=nullptr) const override
Solves the equation system defined by the game matrices.
virtual void repeatedMultiply(Environment const &env, OptimizationDirection player1Dir, OptimizationDirection player2Dir, std::vector< ValueType > &x, std::vector< ValueType > const *b, uint_fast64_t n=1) const override
Performs (repeated) matrix-vector multiplication with the given parameters, i.e.
A class that holds a possibly non-square matrix in the compressed row storage format.
LabParser.cpp.
Definition cli.cpp:18