Browse Source

added player related helpers

tempestpy_adaptions
Stefan Pranger 4 years ago
parent
commit
6b715792aa
  1. 15
      src/storm/generator/Choice.cpp
  2. 22
      src/storm/generator/Choice.h
  3. 6
      src/storm/storage/prism/Player.cpp
  4. 10
      src/storm/storage/prism/Player.h
  5. 11
      src/storm/storage/prism/Program.cpp
  6. 35
      src/storm/storage/prism/Program.h

15
src/storm/generator/Choice.cpp

@ -92,6 +92,21 @@ namespace storm {
return labels.get();
}
template<typename ValueType, typename StateType>
void Choice<ValueType, StateType>::setPlayerIndex(uint_fast32_t playerIndex) {
this->playerIndex = playerIndex;
}
template<typename ValueType, typename StateType>
bool Choice<ValueType, StateType>::hasPlayerIndex() const {
return playerIndex.is_initialized();
}
template<typename ValueType, typename StateType>
uint_fast32_t const& Choice<ValueType, StateType>::getPlayerIndex() const {
return playerIndex.get();
}
template<typename ValueType, typename StateType>
void Choice<ValueType, StateType>::addOriginData(boost::any const& data) {
if (!this->originData || this->originData->empty()) {

22
src/storm/generator/Choice.h

@ -91,6 +91,25 @@ namespace storm {
*/
std::set<std::string> const& getLabels() const;
/*!
* Sets the players index
*
* @param The player index associated with this choice.
*/
void setPlayerIndex(uint_fast32_t playerIndex);
/*!
* Returns whether there is an index for the player defined for this choice.
*/
bool hasPlayerIndex() const;
/*!
* Retrieves the players index associated with this choice
*
* @return The player index associated with this choice.
*/
uint_fast32_t const& getPlayerIndex() const;
/*!
* Adds the given data that specifies the origin of this choice w.r.t. the model specification
*/
@ -176,6 +195,9 @@ namespace storm {
// The labels of this choice
boost::optional<std::set<std::string>> labels;
// The playerIndex of this choice
boost::optional<uint_fast32_t> playerIndex = boost::none;
};
template<typename ValueType, typename StateType>

6
src/storm/storage/prism/Player.cpp

@ -2,7 +2,7 @@
namespace storm {
namespace prism {
Player::Player(std::string const& playerName, std::map<std::string, uint_fast64_t> const& controlledModules, std::map<std::string, uint_fast64_t> const& controlledCommands, std::string const& filename, uint_fast64_t lineNumber) : LocatedInformation(filename, lineNumber), playerName(playerName), controlledModules(controlledModules), controlledCommands(controlledCommands) {
Player::Player(std::string const& playerName, std::map<std::string, uint_fast32_t> const& controlledModules, std::map<std::string, uint_fast32_t> const& controlledCommands, std::string const& filename, uint_fast32_t lineNumber) : LocatedInformation(filename, lineNumber), playerName(playerName), controlledModules(controlledModules), controlledCommands(controlledCommands) {
// Nothing to do here.
}
@ -10,11 +10,11 @@ namespace storm {
return this->playerName;
}
std::map<std::string, uint_fast64_t> const& Player::getModules() const {
std::map<std::string, uint_fast32_t> const& Player::getModules() const {
return this->controlledModules;
}
std::map<std::string, uint_fast64_t> const& Player::getCommands() const {
std::map<std::string, uint_fast32_t> const& Player::getCommands() const {
return this->controlledCommands;
}

10
src/storm/storage/prism/Player.h

@ -24,7 +24,7 @@ namespace storm {
* @param filename The filename in which the player is defined.
* @param lineNumber The line number in which the player is defined.
*/
Player(std::string const& playerName, std::map<std::string, uint_fast64_t> const& controlledModules, std::map<std::string, uint_fast64_t> const& controlledCommands, std::string const& filename = "", uint_fast64_t lineNumber = 0);
Player(std::string const& playerName, std::map<std::string, uint_fast32_t> const& controlledModules, std::map<std::string, uint_fast32_t> const& controlledCommands, std::string const& filename = "", uint_fast32_t lineNumber = 0);
// Create default implementations of constructors/assignment.
Player() = default;
@ -45,14 +45,14 @@ namespace storm {
*
* @return The modules controlled by the player.
*/
std::map<std::string, uint_fast64_t> const& getModules() const; // TODO
std::map<std::string, uint_fast32_t> const& getModules() const; // TODO
/*!
* Retrieves all controlled Commands of the player.
*
* @return The commands controlled by the player.
*/
std::map<std::string, uint_fast64_t> const& getCommands() const;
std::map<std::string, uint_fast32_t> const& getCommands() const;
friend std::ostream& operator<<(std::ostream& stream, Player const& player);
private:
@ -60,10 +60,10 @@ namespace storm {
std::string playerName;
// The modules associated with this player.
std::map<std::string, uint_fast64_t> controlledModules;
std::map<std::string, uint_fast32_t> controlledModules;
// The commands associated with this player.
std::map<std::string, uint_fast64_t> controlledCommands;
std::map<std::string, uint_fast32_t> controlledCommands;
};
} // namespace prism

11
src/storm/storage/prism/Program.cpp

@ -491,6 +491,10 @@ namespace storm {
return this->getModules().size();
}
std::size_t Program::getNumberOfPlayers() const {
return this->getPlayers().size();
}
storm::prism::Module const& Program::getModule(uint_fast64_t index) const {
return this->modules[index];
}
@ -509,6 +513,10 @@ namespace storm {
return this->modules;
}
uint_fast32_t const& Program::getIndexOfPlayer(std::string playerName) const {
return this->playerToIndexMap.at(playerName);
}
std::map<std::string, uint_fast64_t> const& Program::getActionNameToIndexMapping() const {
return actionToIndexMap;
}
@ -805,6 +813,9 @@ namespace storm {
for (uint_fast64_t moduleIndex = 0; moduleIndex < this->getNumberOfModules(); ++moduleIndex) {
this->moduleToIndexMap[this->getModules()[moduleIndex].getName()] = moduleIndex;
}
for (uint_fast64_t playerIndex = 0; playerIndex < this->getNumberOfPlayers(); ++playerIndex) {
this->playerToIndexMap[this->getPlayers()[playerIndex].getName()] = playerIndex;
}
for (uint_fast64_t rewardModelIndex = 0; rewardModelIndex < this->getNumberOfRewardModels(); ++rewardModelIndex) {
this->rewardModelToIndexMap[this->getRewardModels()[rewardModelIndex].getName()] = rewardModelIndex;
}

35
src/storm/storage/prism/Program.h

@ -275,13 +275,6 @@ namespace storm {
*/
std::vector<Formula> const& getFormulas() const;
/*!
* Retrieves the players of the program.
*
* @return The players of the program.
*/
std::vector<Player> const& getPlayers() const;
/*!
* Retrieves the number of formulas in the program.
*
@ -326,6 +319,27 @@ namespace storm {
*/
std::vector<Module> const& getModules() const;
/*!
* Retrieves the players of the program.
*
* @return The players of the program.
*/
std::vector<Player> const& getPlayers() const;
/*!
* Retrieves the number of players in the program.
*
* @return The number of players in the program.
*/
std::size_t getNumberOfPlayers() const;
/*!
* Retrieves the index of the player in the program.
*
* @return The index of the player in the program.
*/
uint_fast32_t const& getIndexOfPlayer(std::string playerName) const;
/*!
* Retrieves the mapping of action names to their indices.
*
@ -746,11 +760,14 @@ namespace storm {
// The modules associated with the program.
std::vector<Module> modules;
// A mapping of module names to their indices.
std::map<std::string, uint_fast64_t> moduleToIndexMap;
// The players associated with the program.
std::vector<Player> players;
// A mapping of module names to their indices.
std::map<std::string, uint_fast64_t> moduleToIndexMap;
// A mapping of player names to their indices.
std::map<std::string, uint_fast64_t> playerToIndexMap;
// The reward models associated with the program.
std::vector<RewardModel> rewardModels;

Loading…
Cancel
Save