Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
GameSolver.cpp
Go to the documentation of this file.
2
6
9
10namespace storm {
11namespace solver {
12
13template<typename ValueType>
14GameSolver<ValueType>::GameSolver() : trackSchedulers(false), uniqueSolution(false), cachingEnabled(false) {
15 // Intentionally left empty
16}
17
18template<typename ValueType>
20 trackSchedulers = value;
21 if (!trackSchedulers) {
22 player1SchedulerChoices = boost::none;
23 player2SchedulerChoices = boost::none;
24 }
25}
26
27template<typename ValueType>
29 return trackSchedulers;
30}
31
32template<typename ValueType>
34 return player1SchedulerChoices.is_initialized() && player2SchedulerChoices.is_initialized();
35}
36
37template<typename ValueType>
39 STORM_LOG_THROW(hasSchedulers(), storm::exceptions::IllegalFunctionCallException, "Cannot retrieve player 1 scheduler, because none was generated.");
40 storm::storage::Scheduler<ValueType> result(player1SchedulerChoices->size());
41 uint_fast64_t state = 0;
42 for (auto const& schedulerChoice : player1SchedulerChoices.get()) {
43 result.setChoice(schedulerChoice, state);
44 ++state;
45 }
46 return result;
47}
48
49template<typename ValueType>
51 STORM_LOG_THROW(hasSchedulers(), storm::exceptions::IllegalFunctionCallException, "Cannot retrieve player 2 scheduler, because none was generated.");
52 storm::storage::Scheduler<ValueType> result(player2SchedulerChoices->size());
53 uint_fast64_t state = 0;
54 for (auto const& schedulerChoice : player2SchedulerChoices.get()) {
55 result.setChoice(schedulerChoice, state);
56 ++state;
57 }
58 return result;
59}
60
61template<typename ValueType>
62std::vector<uint_fast64_t> const& GameSolver<ValueType>::getPlayer1SchedulerChoices() const {
63 STORM_LOG_THROW(hasSchedulers(), storm::exceptions::IllegalFunctionCallException,
64 "Cannot retrieve player 1 scheduler choices, because they were not generated.");
65 return player1SchedulerChoices.get();
66}
67
68template<typename ValueType>
69std::vector<uint_fast64_t> const& GameSolver<ValueType>::getPlayer2SchedulerChoices() const {
70 STORM_LOG_THROW(hasSchedulers(), storm::exceptions::IllegalFunctionCallException,
71 "Cannot retrieve player 2 scheduler choices, because they were not generated.");
72 return player2SchedulerChoices.get();
73}
74
75template<typename ValueType>
76void GameSolver<ValueType>::setSchedulerHints(std::vector<uint_fast64_t>&& player1Choices, std::vector<uint_fast64_t>&& player2Choices) {
77 this->player1ChoicesHint = std::move(player1Choices);
78 this->player2ChoicesHint = std::move(player2Choices);
79}
80
81template<typename ValueType>
83 return player1ChoicesHint.is_initialized() && player2ChoicesHint.is_initialized();
84}
85
86template<typename ValueType>
88 if (cachingEnabled && !value) {
89 // caching will be turned off. Hence we clear the cache at this point
90 clearCache();
91 }
92 cachingEnabled = value;
93}
94
95template<typename ValueType>
97 return cachingEnabled;
98}
99
100template<typename ValueType>
102 // Intentionally left empty.
103}
104
105template<typename ValueType>
107 this->uniqueSolution = value;
108}
109
110template<typename ValueType>
112 return this->uniqueSolution;
113}
114
115template<typename ValueType>
117 // Intentionally left empty.
118}
119
120template<typename ValueType>
121std::unique_ptr<GameSolver<ValueType>> GameSolverFactory<ValueType>::create(
123 storm::storage::SparseMatrix<ValueType> const& player2Matrix) const {
124 return std::make_unique<StandardGameSolver<ValueType>>(player1Matrix, player2Matrix, std::make_unique<GeneralLinearEquationSolverFactory<ValueType>>());
125}
126
127template<typename ValueType>
128std::unique_ptr<GameSolver<ValueType>> GameSolverFactory<ValueType>::create(Environment const& env,
130 storm::storage::SparseMatrix<ValueType>&& player2Matrix) const {
131 return std::make_unique<StandardGameSolver<ValueType>>(std::move(player1Matrix), std::move(player2Matrix),
132 std::make_unique<GeneralLinearEquationSolverFactory<ValueType>>());
133}
134
135template<typename ValueType>
136std::unique_ptr<GameSolver<ValueType>> GameSolverFactory<ValueType>::create(Environment const& env, std::vector<uint64_t> const& player1Grouping,
137 storm::storage::SparseMatrix<ValueType> const& player2Matrix) const {
138 return std::make_unique<StandardGameSolver<ValueType>>(player1Grouping, player2Matrix, std::make_unique<GeneralLinearEquationSolverFactory<ValueType>>());
139}
140
141template<typename ValueType>
142std::unique_ptr<GameSolver<ValueType>> GameSolverFactory<ValueType>::create(Environment const& env, std::vector<uint64_t>&& player1Grouping,
143 storm::storage::SparseMatrix<ValueType>&& player2Matrix) const {
144 return std::make_unique<StandardGameSolver<ValueType>>(std::move(player1Grouping), std::move(player2Matrix),
145 std::make_unique<GeneralLinearEquationSolverFactory<ValueType>>());
146}
147
148template class GameSolver<double>;
150
151template class GameSolverFactory<double>;
153} // namespace solver
154} // 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
A class representing the interface that all game solvers shall implement.
Definition GameSolver.h:30
bool hasUniqueSolution() const
Retrieves whether the solution to the min max equation system is assumed to be unique.
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.
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
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.
bool isCachingEnabled() const
Retrieves whether some of the generated data during solver calls should be cached.
This class defines which action is chosen in a particular state of a non-deterministic model.
Definition Scheduler.h:18
void setChoice(SchedulerChoice< ValueType > const &choice, uint_fast64_t modelState, uint_fast64_t memoryState=0)
Sets the choice defined by the scheduler for the given state.
Definition Scheduler.cpp:37
A class that holds a possibly non-square matrix in the compressed row storage format.
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
LabParser.cpp.
Definition cli.cpp:18