Storm 1.13.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 statePlayerIndications(std::move(components.statePlayerIndications.get())) {
27 if (components.playerNameToIndexMap) {
28 playerNameToIndexMap = std::move(components.playerNameToIndexMap.get());
29 }
30 // Otherwise the map remains empty.
31}
32
33template<typename ValueType, typename RewardModelType>
34std::vector<storm::storage::PlayerIndex> const& Smg<ValueType, RewardModelType>::getStatePlayerIndications() const {
35 return statePlayerIndications;
36}
37
38template<typename ValueType, typename RewardModelType>
40 STORM_LOG_ASSERT(stateIndex < this->getNumberOfStates(), "Invalid state index: " << stateIndex << ".");
41 return statePlayerIndications[stateIndex];
42}
43
44template<typename ValueType, typename RewardModelType>
46 auto findIt = playerNameToIndexMap.find(playerName);
47 STORM_LOG_THROW(findIt != playerNameToIndexMap.end(), storm::exceptions::InvalidArgumentException, "Unknown player name '" << playerName << "'.");
48 return findIt->second;
49}
50
51template<typename ValueType, typename RewardModelType>
52std::map<std::string, storm::storage::PlayerIndex> const& Smg<ValueType, RewardModelType>::getPlayerNamesToIndex() const {
53 return playerNameToIndexMap;
54}
55
56template<typename ValueType, typename RewardModelType>
58 return playerNameToIndexMap.size();
59}
60
61template<typename ValueType, typename RewardModelType>
63 // Create a set and a bit vector encoding the coalition for faster access
64 std::set<storm::storage::PlayerIndex> coalitionAsIndexSet;
65 for (auto const& player : coalition.getPlayers()) {
66 if (std::holds_alternative<std::string>(player)) {
67 coalitionAsIndexSet.insert(getPlayerIndex(std::get<std::string>(player)));
68 } else {
69 STORM_LOG_ASSERT(std::holds_alternative<storm::storage::PlayerIndex>(player), "Player identifier has unexpected type.");
70 coalitionAsIndexSet.insert(std::get<storm::storage::PlayerIndex>(player));
71 }
72 }
73 storm::storage::BitVector coalitionAsBitVector(*coalitionAsIndexSet.rbegin() + 1, false);
74 for (auto const& pi : coalitionAsIndexSet) {
75 coalitionAsBitVector.set(pi);
76 }
77
78 // Now create the actual result
79 storm::storage::BitVector result(this->getNumberOfStates(), false);
80 for (uint64_t state = 0; state < this->getNumberOfStates(); ++state) {
81 auto const& pi = statePlayerIndications[state];
82 if (pi < coalitionAsBitVector.size() && coalitionAsBitVector.get(pi)) {
83 result.set(state, true);
84 }
85 }
86
87 return result;
88}
89
90template class Smg<double>;
92template class Smg<storm::RationalNumber>;
94template class Smg<storm::Interval>;
95template class Smg<storm::RationalInterval>;
96template class Smg<storm::RationalFunction>;
97
98} // namespace sparse
99} // namespace models
100} // 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:34
storm::storage::PlayerIndex getPlayerOfState(uint64_t stateIndex) const
Definition Smg.cpp:39
storm::storage::BitVector computeStatesOfCoalition(storm::logic::PlayerCoalition const &coalition) const
Definition Smg.cpp:62
std::map< std::string, storm::storage::PlayerIndex > const & getPlayerNamesToIndex() const
Definition Smg.cpp:52
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:45
uint64_t getNumberOfPlayers() const
Definition Smg.cpp:57
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:11
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
uint64_t PlayerIndex
Definition PlayerIndex.h:7
boost::optional< std::map< std::string, storm::storage::PlayerIndex > > playerNameToIndexMap