Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
GameSolver.cpp
Go to the documentation of this file.
2
8
9namespace storm {
10namespace solver {
11
12template<typename ValueType>
13GameSolver<ValueType>::GameSolver() : trackSchedulers(false), uniqueSolution(false), cachingEnabled(false) {
14 // Intentionally left empty
15}
16
17template<typename ValueType>
19 trackSchedulers = value;
20 if (!trackSchedulers) {
21 player1SchedulerChoices = boost::none;
22 player2SchedulerChoices = boost::none;
23 }
24}
25
26template<typename ValueType>
28 return trackSchedulers;
29}
30
31template<typename ValueType>
33 return player1SchedulerChoices.is_initialized() && player2SchedulerChoices.is_initialized();
34}
35
36template<typename ValueType>
38 STORM_LOG_THROW(hasSchedulers(), storm::exceptions::IllegalFunctionCallException, "Cannot retrieve player 1 scheduler, because none was generated.");
39 storm::storage::Scheduler<ValueType> result(player1SchedulerChoices->size());
40 uint_fast64_t state = 0;
41 for (auto const& schedulerChoice : player1SchedulerChoices.get()) {
42 result.setChoice(schedulerChoice, state);
43 ++state;
44 }
45 return result;
46}
47
48template<typename ValueType>
50 STORM_LOG_THROW(hasSchedulers(), storm::exceptions::IllegalFunctionCallException, "Cannot retrieve player 2 scheduler, because none was generated.");
51 storm::storage::Scheduler<ValueType> result(player2SchedulerChoices->size());
52 uint_fast64_t state = 0;
53 for (auto const& schedulerChoice : player2SchedulerChoices.get()) {
54 result.setChoice(schedulerChoice, state);
55 ++state;
56 }
57 return result;
58}
59
60template<typename ValueType>
61std::vector<uint_fast64_t> const& GameSolver<ValueType>::getPlayer1SchedulerChoices() const {
62 STORM_LOG_THROW(hasSchedulers(), storm::exceptions::IllegalFunctionCallException,
63 "Cannot retrieve player 1 scheduler choices, because they were not generated.");
64 return player1SchedulerChoices.get();
65}
66
67template<typename ValueType>
68std::vector<uint_fast64_t> const& GameSolver<ValueType>::getPlayer2SchedulerChoices() const {
69 STORM_LOG_THROW(hasSchedulers(), storm::exceptions::IllegalFunctionCallException,
70 "Cannot retrieve player 2 scheduler choices, because they were not generated.");
71 return player2SchedulerChoices.get();
72}
73
74template<typename ValueType>
75void GameSolver<ValueType>::setSchedulerHints(std::vector<uint_fast64_t>&& player1Choices, std::vector<uint_fast64_t>&& player2Choices) {
76 this->player1ChoicesHint = std::move(player1Choices);
77 this->player2ChoicesHint = std::move(player2Choices);
78}
79
80template<typename ValueType>
82 return player1ChoicesHint.is_initialized() && player2ChoicesHint.is_initialized();
83}
84
85template<typename ValueType>
87 if (cachingEnabled && !value) {
88 // caching will be turned off. Hence we clear the cache at this point
89 clearCache();
90 }
91 cachingEnabled = value;
92}
93
94template<typename ValueType>
96 return cachingEnabled;
97}
98
99template<typename ValueType>
101 // Intentionally left empty.
102}
103
104template<typename ValueType>
106 this->uniqueSolution = value;
107}
108
109template<typename ValueType>
111 return this->uniqueSolution;
112}
113
114template<typename ValueType>
116 // Intentionally left empty.
117}
118
119template<typename ValueType>
120std::unique_ptr<GameSolver<ValueType>> GameSolverFactory<ValueType>::create(
122 storm::storage::SparseMatrix<ValueType> const& player2Matrix) const {
123 return std::make_unique<StandardGameSolver<ValueType>>(player1Matrix, player2Matrix, std::make_unique<GeneralLinearEquationSolverFactory<ValueType>>());
124}
125
126template<typename ValueType>
127std::unique_ptr<GameSolver<ValueType>> GameSolverFactory<ValueType>::create(Environment const& env,
129 storm::storage::SparseMatrix<ValueType>&& player2Matrix) const {
130 return std::make_unique<StandardGameSolver<ValueType>>(std::move(player1Matrix), std::move(player2Matrix),
131 std::make_unique<GeneralLinearEquationSolverFactory<ValueType>>());
132}
133
134template<typename ValueType>
135std::unique_ptr<GameSolver<ValueType>> GameSolverFactory<ValueType>::create(Environment const& env, std::vector<uint64_t> const& player1Grouping,
136 storm::storage::SparseMatrix<ValueType> const& player2Matrix) const {
137 return std::make_unique<StandardGameSolver<ValueType>>(player1Grouping, player2Matrix, std::make_unique<GeneralLinearEquationSolverFactory<ValueType>>());
138}
139
140template<typename ValueType>
141std::unique_ptr<GameSolver<ValueType>> GameSolverFactory<ValueType>::create(Environment const& env, std::vector<uint64_t>&& player1Grouping,
142 storm::storage::SparseMatrix<ValueType>&& player2Matrix) const {
143 return std::make_unique<StandardGameSolver<ValueType>>(std::move(player1Grouping), std::move(player2Matrix),
144 std::make_unique<GeneralLinearEquationSolverFactory<ValueType>>());
145}
146
147template class GameSolver<double>;
149
150template class GameSolverFactory<double>;
152} // namespace solver
153} // 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:38
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