Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
StochasticTwoPlayerGame.cpp
Go to the documentation of this file.
2
8
9namespace storm {
10namespace models {
11namespace symbolic {
12
13template<storm::dd::DdType Type, typename ValueType>
15 std::shared_ptr<storm::dd::DdManager<Type>> manager, storm::dd::Bdd<Type> reachableStates, storm::dd::Bdd<Type> initialStates,
16 storm::dd::Bdd<Type> deadlockStates, storm::dd::Add<Type, ValueType> transitionMatrix, std::set<storm::expressions::Variable> const& rowVariables,
17 std::shared_ptr<storm::adapters::AddExpressionAdapter<Type, ValueType>> rowExpressionAdapter, std::set<storm::expressions::Variable> const& columnVariables,
18 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs,
19 std::set<storm::expressions::Variable> const& player1Variables, std::set<storm::expressions::Variable> const& player2Variables,
20 std::set<storm::expressions::Variable> const& nondeterminismVariables, std::map<std::string, storm::expressions::Expression> labelToExpressionMap,
21 std::unordered_map<std::string, RewardModelType> const& rewardModels)
22 : NondeterministicModel<Type, ValueType>(storm::models::ModelType::S2pg, manager, reachableStates, initialStates, deadlockStates, transitionMatrix,
23 rowVariables, rowExpressionAdapter, columnVariables, rowColumnMetaVariablePairs, nondeterminismVariables,
24 labelToExpressionMap, rewardModels),
25 player1Variables(player1Variables),
26 player2Variables(player2Variables) {
27 createIllegalMasks();
28}
29
30template<storm::dd::DdType Type, typename ValueType>
32 std::shared_ptr<storm::dd::DdManager<Type>> manager, storm::dd::Bdd<Type> reachableStates, storm::dd::Bdd<Type> initialStates,
33 storm::dd::Bdd<Type> deadlockStates, storm::dd::Add<Type, ValueType> transitionMatrix, std::set<storm::expressions::Variable> const& rowVariables,
34 std::set<storm::expressions::Variable> const& columnVariables,
35 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs,
36 std::set<storm::expressions::Variable> const& player1Variables, std::set<storm::expressions::Variable> const& player2Variables,
37 std::set<storm::expressions::Variable> const& nondeterminismVariables, std::map<std::string, storm::dd::Bdd<Type>> labelToBddMap,
38 std::unordered_map<std::string, RewardModelType> const& rewardModels)
39 : NondeterministicModel<Type, ValueType>(storm::models::ModelType::S2pg, manager, reachableStates, initialStates, deadlockStates, transitionMatrix,
40 rowVariables, columnVariables, rowColumnMetaVariablePairs, nondeterminismVariables, labelToBddMap, rewardModels),
41 player1Variables(player1Variables),
42 player2Variables(player2Variables) {
43 createIllegalMasks();
44}
45
46template<storm::dd::DdType Type, typename ValueType>
48 // Compute legal player 1 mask.
49 this->illegalPlayer1Mask = this->getTransitionMatrix().notZero().existsAbstract(this->getColumnVariables()).existsAbstract(this->getPlayer2Variables());
50
51 // Correct the mask for player 2. This is necessary, because it is not yet restricted to the legal choices of player 1.
52 illegalPlayer2Mask = this->getIllegalMask() && this->illegalPlayer1Mask;
53
54 // Then set the illegal mask for player 1 correctly.
55 this->illegalPlayer1Mask = !illegalPlayer1Mask && this->getReachableStates();
56}
57
58template<storm::dd::DdType Type, typename ValueType>
62
63template<storm::dd::DdType Type, typename ValueType>
67
68template<storm::dd::DdType Type, typename ValueType>
69std::set<storm::expressions::Variable> const& StochasticTwoPlayerGame<Type, ValueType>::getPlayer1Variables() const {
70 return player1Variables;
71}
72
73template<storm::dd::DdType Type, typename ValueType>
74std::set<storm::expressions::Variable> const& StochasticTwoPlayerGame<Type, ValueType>::getPlayer2Variables() const {
75 return player2Variables;
76}
77
78template<storm::dd::DdType Type, typename ValueType>
79template<typename NewValueType>
80std::shared_ptr<StochasticTwoPlayerGame<Type, NewValueType>> StochasticTwoPlayerGame<Type, ValueType>::toValueType() const {
81 typedef typename NondeterministicModel<Type, NewValueType>::RewardModelType NewRewardModelType;
82 std::unordered_map<std::string, NewRewardModelType> newRewardModels;
83
84 for (auto const& e : this->getRewardModels()) {
85 newRewardModels.emplace(e.first, e.second.template toValueType<NewValueType>());
86 }
87
88 auto newLabelToBddMap = this->getLabelToBddMap();
89 newLabelToBddMap.erase("init");
90 newLabelToBddMap.erase("deadlock");
92 return std::make_shared<StochasticTwoPlayerGame<Type, NewValueType>>(
93 this->getManagerAsSharedPointer(), this->getReachableStates(), this->getInitialStates(), this->getDeadlockStates(),
94 this->getTransitionMatrix().template toValueType<NewValueType>(), this->getRowVariables(), this->getColumnVariables(),
95 this->getRowColumnMetaVariablePairs(), this->getPlayer1Variables(), this->getPlayer2Variables(), this->getNondeterminismVariables(), newLabelToBddMap,
96 newRewardModels);
97}
99template<storm::dd::DdType Type, typename ValueType>
101 return this->getQualitativeTransitionMatrix().existsAbstract(this->getColumnVariables()).getNonZeroCount();
102}
103
104// Explicitly instantiate the template class.
106
109template std::shared_ptr<StochasticTwoPlayerGame<storm::dd::DdType::Sylvan, double>>
112
113} // namespace symbolic
114} // namespace models
115} // namespace storm
Base class for all nondeterministic symbolic models.
This class represents a discrete-time stochastic two-player game.
std::shared_ptr< StochasticTwoPlayerGame< Type, NewValueType > > toValueType() const
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.
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