Browse Source

Added getter routines, so we can retrieve the reward models

main
gereon 12 years ago
parent
commit
2005eb7e73
  1. 12
      src/ir/Program.cpp
  2. 13
      src/ir/Program.h
  3. 8
      src/ir/RewardModel.cpp
  4. 12
      src/ir/RewardModel.h
  5. 7
      src/ir/StateReward.cpp
  6. 8
      src/ir/StateReward.h
  7. 8
      src/ir/TransitionReward.cpp
  8. 6
      src/ir/TransitionReward.h

12
src/ir/Program.cpp

@ -98,6 +98,18 @@ std::shared_ptr<std::set<uint_fast64_t>> const Program::getModulesByAction(std::
}
}
storm::ir::RewardModel Program::getRewardModel(std::string const & name) const {
auto it = this->rewards.find(name);
if (it == this->rewards.end()) {
// throw some exception here...
} else {
return it->second;
}
}
std::map<std::string, std::shared_ptr<storm::ir::expressions::BaseExpression>> Program::getLabels() const {
return this->labels;
}
} // namespace ir

13
src/ir/Program.h

@ -93,6 +93,19 @@ public:
*/
std::shared_ptr<std::set<uint_fast64_t>> const getModulesByAction(std::string const& action) const;
/*!
* Retrieve reward model with given name.
* @param name Name of the reward model.
* @return Reward model with given name.
*/
storm::ir::RewardModel getRewardModel(std::string const & name) const;
/*!
* Retrieves all labels.
* @return All labels.
*/
std::map<std::string, std::shared_ptr<storm::ir::expressions::BaseExpression>> getLabels() const;
private:
// The type of the model.
ModelType modelType;

8
src/ir/RewardModel.cpp

@ -37,6 +37,14 @@ std::string RewardModel::toString() const {
return result.str();
}
std::vector<storm::ir::StateReward> RewardModel::getStateRewards() const {
return this->stateRewards;
}
std::vector<storm::ir::TransitionReward> RewardModel::getTransitionRewards() const {
return this->transitionRewards;
}
} // namespace ir
} // namespace storm

12
src/ir/RewardModel.h

@ -42,6 +42,18 @@ public:
*/
std::string toString() const;
/*!
* Retrieve state rewards.
* @return State rewards.
*/
std::vector<storm::ir::StateReward> getStateRewards() const;
/*!
* Retrieve transition rewards.
* @return Transition rewards.
*/
std::vector<storm::ir::TransitionReward> getTransitionRewards() const;
private:
// The name of the reward model.
std::string rewardModelName;

7
src/ir/StateReward.cpp

@ -30,6 +30,13 @@ std::string StateReward::toString() const {
return result.str();
}
double StateReward::getReward(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const * state) const {
if (this->statePredicate->getValueAsBool(state)) {
return this->rewardValue->getValueAsDouble(state);
}
return 0;
}
} // namespace ir
} // namespace storm

8
src/ir/StateReward.h

@ -42,6 +42,14 @@ public:
*/
std::string toString() const;
/*!
* Returns the reward for the given state.
* It the state fulfills the predicate, the reward value is returned, zero otherwise.
* @param state State object.
* @return Reward for given state.
*/
double getReward(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const * state) const;
private:
// The predicate that characterizes the states that obtain this reward.
std::shared_ptr<storm::ir::expressions::BaseExpression> statePredicate;

8
src/ir/TransitionReward.cpp

@ -30,6 +30,14 @@ std::string TransitionReward::toString() const {
return result.str();
}
double TransitionReward::getReward(std::string const & label, std::pair<std::vector<bool>, std::vector<int_fast64_t>> const * state) const {
if (this->commandName != label) return 0;
if (this->statePredicate->getValueAsBool(state)) {
return this->rewardValue->getValueAsDouble(state);
}
return 0;
}
} // namespace ir
} // namespace storm

6
src/ir/TransitionReward.h

@ -43,6 +43,12 @@ public:
*/
std::string toString() const;
/*!
* Retrieves reward for given transition.
* Returns reward value if source state fulfills predicate and the transition is labeled correctly, zero otherwise.
*/
double getReward(std::string const & label, std::pair<std::vector<bool>, std::vector<int_fast64_t>> const * state) const;
private:
// The name of the command this transition-based reward is attached to.
std::string commandName;

Loading…
Cancel
Save