Storm 1.11.1.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>
53 // Create a set and a bit vector encoding the coalition for faster access
54 std::set<storm::storage::PlayerIndex> coalitionAsIndexSet;
55 for (auto const& player : coalition.getPlayers()) {
56 if (std::holds_alternative<std::string>(player)) {
57 coalitionAsIndexSet.insert(getPlayerIndex(std::get<std::string>(player)));
58 } else {
59 STORM_LOG_ASSERT(std::holds_alternative<storm::storage::PlayerIndex>(player), "Player identifier has unexpected type.");
60 coalitionAsIndexSet.insert(std::get<storm::storage::PlayerIndex>(player));
61 }
62 }
63 storm::storage::BitVector coalitionAsBitVector(*coalitionAsIndexSet.rbegin() + 1, false);
64 for (auto const& pi : coalitionAsIndexSet) {
65 coalitionAsBitVector.set(pi);
66 }
67
68 // Now create the actual result
69 storm::storage::BitVector result(this->getNumberOfStates(), false);
70 for (uint64_t state = 0; state < this->getNumberOfStates(); ++state) {
71 auto const& pi = statePlayerIndications[state];
72 if (pi < coalitionAsBitVector.size() && coalitionAsBitVector.get(pi)) {
73 result.set(state, true);
74 }
75 }
76
77 return result;
78}
79
80template class Smg<double>;
82template class Smg<storm::RationalNumber>;
83template class Smg<storm::Interval>;
84template class Smg<storm::RationalFunction>;
85
86} // namespace sparse
87} // namespace models
88} // namespace storm
std::vector< std::variant< std::string, storm::storage::PlayerIndex > > const & getPlayers() const
CRewardModelType RewardModelType
Definition Model.h:35
The base class of sparse nondeterministic models.
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: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
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