Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
GameSolver.h
Go to the documentation of this file.
1#pragma once
2
3#include <boost/optional.hpp>
4#include <memory>
5#include <vector>
6
12
14
15namespace storm {
16
17class Environment;
18
19namespace storage {
20template<typename T>
21class SparseMatrix;
22}
23
24namespace solver {
25
29template<class ValueType>
30class GameSolver : public AbstractEquationSolver<ValueType> {
31 public:
32 virtual ~GameSolver() = default;
33
47 virtual bool solveGame(Environment const& env, OptimizationDirection player1Dir, OptimizationDirection player2Dir, std::vector<ValueType>& x,
48 std::vector<ValueType> const& b, std::vector<uint64_t>* player1Choices = nullptr,
49 std::vector<uint64_t>* player2Choices = nullptr) const = 0;
50
65 virtual void repeatedMultiply(Environment const& env, OptimizationDirection player1Dir, OptimizationDirection player2Dir, std::vector<ValueType>& x,
66 std::vector<ValueType> const* b, uint_fast64_t n = 1) const = 0;
67
72 void setTrackSchedulers(bool value = true);
73
77 bool isTrackSchedulersSet() const;
78
82 bool hasSchedulers() const;
83
89
93 std::vector<uint_fast64_t> const& getPlayer1SchedulerChoices() const;
94 std::vector<uint_fast64_t> const& getPlayer2SchedulerChoices() const;
95
99 void setSchedulerHints(std::vector<uint_fast64_t>&& player1Choices, std::vector<uint_fast64_t>&& player2Choices);
100
104 bool hasSchedulerHints() const;
105
110 void setCachingEnabled(bool value);
111
115 bool isCachingEnabled() const;
116
117 /*
118 * Clears the currently cached data that has been stored during previous calls of the solver.
119 */
120 virtual void clearCache() const;
121
125 void setHasUniqueSolution(bool value = true);
126
130 bool hasUniqueSolution() const;
131
132 protected:
133 GameSolver();
134
137
139 mutable boost::optional<std::vector<uint_fast64_t>> player1SchedulerChoices;
140 mutable boost::optional<std::vector<uint_fast64_t>> player2SchedulerChoices;
141
142 // scheduler choices that might be considered by the solver as an initial guess
143 boost::optional<std::vector<uint_fast64_t>> player1ChoicesHint;
144 boost::optional<std::vector<uint_fast64_t>> player2ChoicesHint;
145
146 private:
148 bool uniqueSolution;
149
151 bool cachingEnabled;
152};
153
154template<typename ValueType>
156 public:
158 virtual ~GameSolverFactory() = default;
159
160 virtual std::unique_ptr<GameSolver<ValueType>> create(Environment const& env,
162 storm::storage::SparseMatrix<ValueType> const& player2Matrix) const;
163 virtual std::unique_ptr<GameSolver<ValueType>> create(Environment const& env,
165 storm::storage::SparseMatrix<ValueType>&& player2Matrix) const;
166
167 virtual std::unique_ptr<GameSolver<ValueType>> create(Environment const& env, std::vector<uint64_t> const& player1Grouping,
168 storm::storage::SparseMatrix<ValueType> const& player2Matrix) const;
169 virtual std::unique_ptr<GameSolver<ValueType>> create(Environment const& env, std::vector<uint64_t>&& player1Grouping,
170 storm::storage::SparseMatrix<ValueType>&& player2Matrix) const;
171};
172
173} // namespace solver
174} // namespace storm
virtual std::unique_ptr< GameSolver< ValueType > > create(Environment const &env, storm::storage::SparseMatrix< storm::storage::sparse::state_type > const &player1Matrix, storm::storage::SparseMatrix< ValueType > const &player2Matrix) const
virtual ~GameSolverFactory()=default
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 > > player1ChoicesHint
Definition GameSolver.h:143
bool hasUniqueSolution() const
Retrieves whether the solution to the min max equation system is assumed to be unique.
boost::optional< std::vector< uint_fast64_t > > player2SchedulerChoices
Definition GameSolver.h:140
storm::storage::Scheduler< ValueType > computePlayer2Scheduler() const
std::vector< uint_fast64_t > const & getPlayer2SchedulerChoices() const
storm::storage::Scheduler< ValueType > computePlayer1Scheduler() const
Retrieves the generated scheduler.
void setCachingEnabled(bool value)
Sets whether some of the generated data during solver calls should be cached.
bool trackSchedulers
Whether we generate schedulers during solving.
Definition GameSolver.h:136
std::vector< uint_fast64_t > const & getPlayer1SchedulerChoices() const
Retrieves the generated (deterministic) choices of the optimal scheduler.
void setTrackSchedulers(bool value=true)
Sets whether schedulers are generated when solving equation systems.
bool hasSchedulers() const
Retrieves whether the solver generated a scheduler.
virtual void clearCache() const
virtual ~GameSolver()=default
bool hasSchedulerHints() const
Returns whether Scheduler hints are available.
bool isTrackSchedulersSet() const
Retrieves whether this solver is set to generate schedulers.
void setSchedulerHints(std::vector< uint_fast64_t > &&player1Choices, std::vector< uint_fast64_t > &&player2Choices)
Sets scheduler hints that might be considered by the solver as an initial guess.
void setHasUniqueSolution(bool value=true)
Sets whether the solution to the min max equation system is known to be unique.
boost::optional< std::vector< uint_fast64_t > > player2ChoicesHint
Definition GameSolver.h:144
bool isCachingEnabled() const
Retrieves whether some of the generated data during solver calls should be cached.
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 =0
Performs (repeated) matrix-vector multiplication with the given parameters, i.e.
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 =0
Solves the equation system defined by the game matrices.
This class defines which action is chosen in a particular state of a non-deterministic model.
Definition Scheduler.h:18
A class that holds a possibly non-square matrix in the compressed row storage format.
LabParser.cpp.
Definition cli.cpp:18