Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Smg.cpp
Go to the documentation of this file.
2
7
8namespace storm {
9namespace models {
10namespace sparse {
11
12template<typename ValueType, typename RewardModelType>
14 : NondeterministicModel<ValueType, RewardModelType>(ModelType::Smg, components), statePlayerIndications(components.statePlayerIndications.get()) {
15 if (components.playerNameToIndexMap) {
16 playerNameToIndexMap = components.playerNameToIndexMap.get();
17 }
18 // Otherwise the map remains empty.
19}
20
21template<typename ValueType, typename RewardModelType>
24 statePlayerIndications(std::move(components.statePlayerIndications.get())) {
25 if (components.playerNameToIndexMap) {
26 playerNameToIndexMap = std::move(components.playerNameToIndexMap.get());
27 }
28 // Otherwise the map remains empty.
29}
30
31template<typename ValueType, typename RewardModelType>
32std::vector<storm::storage::PlayerIndex> const& Smg<ValueType, RewardModelType>::getStatePlayerIndications() const {
33 return statePlayerIndications;
34}
35
36template<typename ValueType, typename RewardModelType>
38 STORM_LOG_ASSERT(stateIndex < this->getNumberOfStates(), "Invalid state index: " << stateIndex << ".");
39 return statePlayerIndications[stateIndex];
40}
41
42template<typename ValueType, typename RewardModelType>
44 auto findIt = playerNameToIndexMap.find(playerName);
45 STORM_LOG_THROW(findIt != playerNameToIndexMap.end(), storm::exceptions::InvalidArgumentException, "Unknown player name '" << playerName << "'.");
46 return findIt->second;
47}
48
49template<typename ValueType, typename RewardModelType>
51 // Create a set and a bit vector encoding the coalition for faster access
52 std::set<storm::storage::PlayerIndex> coalitionAsIndexSet;
53 for (auto const& player : coalition.getPlayers()) {
54 if (std::holds_alternative<std::string>(player)) {
55 coalitionAsIndexSet.insert(getPlayerIndex(std::get<std::string>(player)));
56 } else {
57 STORM_LOG_ASSERT(std::holds_alternative<storm::storage::PlayerIndex>(player), "Player identifier has unexpected type.");
58 coalitionAsIndexSet.insert(std::get<storm::storage::PlayerIndex>(player));
59 }
60 }
61 storm::storage::BitVector coalitionAsBitVector(*coalitionAsIndexSet.rbegin() + 1, false);
62 for (auto const& pi : coalitionAsIndexSet) {
63 coalitionAsBitVector.set(pi);
64 }
65
66 // Now create the actual result
67 storm::storage::BitVector result(this->getNumberOfStates(), false);
68 for (uint64_t state = 0; state < this->getNumberOfStates(); ++state) {
69 auto const& pi = statePlayerIndications[state];
70 if (pi < coalitionAsBitVector.size() && coalitionAsBitVector.get(pi)) {
71 result.set(state, true);
72 }
73 }
74
75 return result;
76}
77
78template class Smg<double>;
80template class Smg<storm::RationalNumber>;
81template class Smg<storm::Interval>;
82template class Smg<storm::RationalFunction>;
83
84} // namespace sparse
85} // namespace models
86} // 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:32
storm::storage::PlayerIndex getPlayerOfState(uint64_t stateIndex) const
Definition Smg.cpp:37
storm::storage::BitVector computeStatesOfCoalition(storm::logic::PlayerCoalition const &coalition) const
Definition Smg.cpp:50
Smg(storm::storage::sparse::ModelComponents< ValueType, RewardModelType > const &components)
Constructs a model from the given data.
Definition Smg.cpp:13
storm::storage::PlayerIndex getPlayerIndex(std::string const &playerName) const
Definition Smg.cpp:43
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