Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Smg.cpp
Go to the documentation of this file.
2
9
10namespace storm {
11namespace models {
12namespace sparse {
13
14template<typename ValueType, typename RewardModelType>
16 : NondeterministicModel<ValueType, RewardModelType>(ModelType::Smg, components), statePlayerIndications(components.statePlayerIndications.get()) {
17 if (components.playerNameToIndexMap) {
18 playerNameToIndexMap = components.playerNameToIndexMap.get();
19 }
20 // Otherwise the map remains empty.
21}
22
23template<typename ValueType, typename RewardModelType>
26 // NOLINTBEGIN(bugprone-use-after-move) The base constructor only consumes the base-relevant fields of components.
27 statePlayerIndications(std::move(components.statePlayerIndications.get())) {
28 if (components.playerNameToIndexMap) {
29 playerNameToIndexMap = std::move(components.playerNameToIndexMap.get());
30 }
31 // Otherwise the map remains empty.
32 // NOLINTEND(bugprone-use-after-move)
33}
34
35template<typename ValueType, typename RewardModelType>
36std::vector<storm::storage::PlayerIndex> const& Smg<ValueType, RewardModelType>::getStatePlayerIndications() const {
37 return statePlayerIndications;
38}
39
40template<typename ValueType, typename RewardModelType>
42 STORM_LOG_ASSERT(stateIndex < this->getNumberOfStates(), "Invalid state index: " << stateIndex << ".");
43 return statePlayerIndications[stateIndex];
44}
45
46template<typename ValueType, typename RewardModelType>
48 auto findIt = playerNameToIndexMap.find(playerName);
49 STORM_LOG_THROW(findIt != playerNameToIndexMap.end(), storm::exceptions::InvalidArgumentException, "Unknown player name '" << playerName << "'.");
50 return findIt->second;
51}
52
53template<typename ValueType, typename RewardModelType>
54std::map<std::string, storm::storage::PlayerIndex> const& Smg<ValueType, RewardModelType>::getPlayerNamesToIndex() const {
55 return playerNameToIndexMap;
56}
57
58template<typename ValueType, typename RewardModelType>
60 return playerNameToIndexMap.size();
61}
62
63template<typename ValueType, typename RewardModelType>
65 // Create a set and a bit vector encoding the coalition for faster access
66 std::set<storm::storage::PlayerIndex> coalitionAsIndexSet;
67 for (auto const& player : coalition.getPlayers()) {
68 if (std::holds_alternative<std::string>(player)) {
69 coalitionAsIndexSet.insert(getPlayerIndex(std::get<std::string>(player)));
70 } else {
71 STORM_LOG_ASSERT(std::holds_alternative<storm::storage::PlayerIndex>(player), "Player identifier has unexpected type.");
72 coalitionAsIndexSet.insert(std::get<storm::storage::PlayerIndex>(player));
73 }
74 }
75 storm::storage::BitVector coalitionAsBitVector(*coalitionAsIndexSet.rbegin() + 1, false);
76 for (auto const& pi : coalitionAsIndexSet) {
77 coalitionAsBitVector.set(pi);
78 }
79
80 // Now create the actual result
81 storm::storage::BitVector result(this->getNumberOfStates(), false);
82 for (uint64_t state = 0; state < this->getNumberOfStates(); ++state) {
83 auto const& pi = statePlayerIndications[state];
84 if (pi < coalitionAsBitVector.size() && coalitionAsBitVector.get(pi)) {
85 result.set(state, true);
86 }
87 }
88
89 return result;
90}
91
92template class Smg<double>;
94template class Smg<storm::RationalNumber>;
96template class Smg<storm::Interval>;
97template class Smg<storm::RationalInterval>;
98template class Smg<storm::RationalFunction>;
99
100} // namespace sparse
101} // namespace models
102} // namespace storm
std::vector< std::variant< std::string, storm::storage::PlayerIndex > > const & getPlayers() const
CRewardModelType RewardModelType
Definition Model.h:33
virtual uint_fast64_t getNumberOfStates() const override
Returns the number of states of the model.
Definition Model.cpp:163
NondeterministicModel(ModelType modelType, storm::storage::sparse::ModelComponents< ValueType, RewardModelType > const &components)
Constructs a model from the given data.
This class represents a stochastic multiplayer game.
Definition Smg.h:16
std::vector< storm::storage::PlayerIndex > const & getStatePlayerIndications() const
Definition Smg.cpp:36
storm::storage::PlayerIndex getPlayerOfState(uint64_t stateIndex) const
Definition Smg.cpp:41
storm::storage::BitVector computeStatesOfCoalition(storm::logic::PlayerCoalition const &coalition) const
Definition Smg.cpp:64
std::map< std::string, storm::storage::PlayerIndex > const & getPlayerNamesToIndex() const
Definition Smg.cpp:54
Smg(storm::storage::sparse::ModelComponents< ValueType, RewardModelType > const &components)
Constructs a model from the given data.
Definition Smg.cpp:15
storm::storage::PlayerIndex getPlayerIndex(std::string const &playerName) const
Definition Smg.cpp:47
uint64_t getNumberOfPlayers() const
Definition Smg.cpp:59
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
void set(uint64_t index, bool value=true)
Sets the given truth value at the given index.
size_t size() const
Retrieves the number of bits this bit vector can store.
bool get(uint64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28
uint64_t PlayerIndex
Definition PlayerIndex.h:7
boost::optional< std::map< std::string, storm::storage::PlayerIndex > > playerNameToIndexMap