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