Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
StochasticTwoPlayerGame.cpp
Go to the documentation of this file.
2
6
8
9#include "storm-config.h"
11
12namespace storm {
13namespace models {
14namespace symbolic {
15
16template<storm::dd::DdType Type, typename ValueType>
18 std::shared_ptr<storm::dd::DdManager<Type>> manager, storm::dd::Bdd<Type> reachableStates, storm::dd::Bdd<Type> initialStates,
19 storm::dd::Bdd<Type> deadlockStates, storm::dd::Add<Type, ValueType> transitionMatrix, std::set<storm::expressions::Variable> const& rowVariables,
20 std::shared_ptr<storm::adapters::AddExpressionAdapter<Type, ValueType>> rowExpressionAdapter, std::set<storm::expressions::Variable> const& columnVariables,
21 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs,
22 std::set<storm::expressions::Variable> const& player1Variables, std::set<storm::expressions::Variable> const& player2Variables,
23 std::set<storm::expressions::Variable> const& nondeterminismVariables, std::map<std::string, storm::expressions::Expression> labelToExpressionMap,
24 std::unordered_map<std::string, RewardModelType> const& rewardModels)
25 : NondeterministicModel<Type, ValueType>(storm::models::ModelType::S2pg, manager, reachableStates, initialStates, deadlockStates, transitionMatrix,
26 rowVariables, rowExpressionAdapter, columnVariables, rowColumnMetaVariablePairs, nondeterminismVariables,
27 labelToExpressionMap, rewardModels),
28 player1Variables(player1Variables),
29 player2Variables(player2Variables) {
30 createIllegalMasks();
31}
32
33template<storm::dd::DdType Type, typename ValueType>
35 std::shared_ptr<storm::dd::DdManager<Type>> manager, storm::dd::Bdd<Type> reachableStates, storm::dd::Bdd<Type> initialStates,
36 storm::dd::Bdd<Type> deadlockStates, storm::dd::Add<Type, ValueType> transitionMatrix, std::set<storm::expressions::Variable> const& rowVariables,
37 std::set<storm::expressions::Variable> const& columnVariables,
38 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs,
39 std::set<storm::expressions::Variable> const& player1Variables, std::set<storm::expressions::Variable> const& player2Variables,
40 std::set<storm::expressions::Variable> const& nondeterminismVariables, std::map<std::string, storm::dd::Bdd<Type>> labelToBddMap,
41 std::unordered_map<std::string, RewardModelType> const& rewardModels)
42 : NondeterministicModel<Type, ValueType>(storm::models::ModelType::S2pg, manager, reachableStates, initialStates, deadlockStates, transitionMatrix,
43 rowVariables, columnVariables, rowColumnMetaVariablePairs, nondeterminismVariables, labelToBddMap, rewardModels),
44 player1Variables(player1Variables),
45 player2Variables(player2Variables) {
46 createIllegalMasks();
47}
48
49template<storm::dd::DdType Type, typename ValueType>
51 // Compute legal player 1 mask.
52 this->illegalPlayer1Mask = this->getTransitionMatrix().notZero().existsAbstract(this->getColumnVariables()).existsAbstract(this->getPlayer2Variables());
53
54 // Correct the mask for player 2. This is necessary, because it is not yet restricted to the legal choices of player 1.
55 illegalPlayer2Mask = this->getIllegalMask() && this->illegalPlayer1Mask;
56
57 // Then set the illegal mask for player 1 correctly.
58 this->illegalPlayer1Mask = !illegalPlayer1Mask && this->getReachableStates();
59}
60
61template<storm::dd::DdType Type, typename ValueType>
65
66template<storm::dd::DdType Type, typename ValueType>
70
71template<storm::dd::DdType Type, typename ValueType>
72std::set<storm::expressions::Variable> const& StochasticTwoPlayerGame<Type, ValueType>::getPlayer1Variables() const {
73 return player1Variables;
75
76template<storm::dd::DdType Type, typename ValueType>
77std::set<storm::expressions::Variable> const& StochasticTwoPlayerGame<Type, ValueType>::getPlayer2Variables() const {
78 return player2Variables;
79}
80
81template<storm::dd::DdType Type, typename ValueType>
82template<typename NewValueType>
83std::shared_ptr<StochasticTwoPlayerGame<Type, NewValueType>> StochasticTwoPlayerGame<Type, ValueType>::toValueType() const {
84 typedef typename NondeterministicModel<Type, NewValueType>::RewardModelType NewRewardModelType;
85 std::unordered_map<std::string, NewRewardModelType> newRewardModels;
86
87 for (auto const& e : this->getRewardModels()) {
88 newRewardModels.emplace(e.first, e.second.template toValueType<NewValueType>());
89 }
90
91 auto newLabelToBddMap = this->getLabelToBddMap();
92 newLabelToBddMap.erase("init");
93 newLabelToBddMap.erase("deadlock");
94
95 return std::make_shared<StochasticTwoPlayerGame<Type, NewValueType>>(
96 this->getManagerAsSharedPointer(), this->getReachableStates(), this->getInitialStates(), this->getDeadlockStates(),
97 this->getTransitionMatrix().template toValueType<NewValueType>(), this->getRowVariables(), this->getColumnVariables(),
98 this->getRowColumnMetaVariablePairs(), this->getPlayer1Variables(), this->getPlayer2Variables(), this->getNondeterminismVariables(), newLabelToBddMap,
99 newRewardModels);
100}
101
102template<storm::dd::DdType Type, typename ValueType>
104 return this->getQualitativeTransitionMatrix().existsAbstract(this->getColumnVariables()).getNonZeroCount();
105}
106
107// Explicitly instantiate the template class.
110#ifdef STORM_HAVE_CARL
112template std::shared_ptr<StochasticTwoPlayerGame<storm::dd::DdType::Sylvan, double>>
115#endif
116
117} // namespace symbolic
118} // namespace models
119} // namespace storm
Base class for all nondeterministic symbolic models.
This class represents a discrete-time stochastic two-player game.
std::set< storm::expressions::Variable > const & getPlayer1Variables() const
Retrieeves the set of meta variables used to encode the nondeterministic choices of player 1.
std::set< storm::expressions::Variable > const & getPlayer2Variables() const
Retrieeves the set of meta variables used to encode the nondeterministic choices of player 2.
storm::dd::Bdd< Type > getIllegalPlayer1Mask() const
Retrieves a BDD characterizing all illegal player 1 choice encodings in the model.
std::shared_ptr< StochasticTwoPlayerGame< Type, NewValueType > > toValueType() const
uint64_t getNumberOfPlayer2States() const
Retrieves the number of player 2 states in the game.
storm::dd::Bdd< Type > getIllegalPlayer2Mask() const
Retrieves a BDD characterizing all illegal player 2 choice encodings in the model.
StochasticTwoPlayerGame(StochasticTwoPlayerGame< Type, ValueType > const &other)=default
LabParser.cpp.
Definition cli.cpp:18