Browse Source

reward parameters

tempestpy_adaptions
Sebastian Junges 8 years ago
parent
commit
1f82fa27e8
  1. 11
      src/storm/models/sparse/Model.cpp
  2. 1
      src/storm/models/sparse/Model.h
  3. 17
      src/storm/models/sparse/StandardRewardModel.cpp
  4. 8
      src/storm/models/sparse/StandardRewardModel.h
  5. 9
      src/storm/utility/vector.h

11
src/storm/models/sparse/Model.cpp

@ -360,6 +360,17 @@ namespace storm {
std::set<storm::RationalFunctionVariable> getProbabilityParameters(Model<storm::RationalFunction> const& model) {
return storm::storage::getVariables(model.getTransitionMatrix());
}
std::set<storm::RationalFunctionVariable> getRewardParameters(Model<storm::RationalFunction> const& model) {
std::set<storm::RationalFunctionVariable> result;
for(auto rewModel : model.getRewardModels()) {
std::set<storm::RationalFunctionVariable> tmp = getRewardModelParameters(rewModel.second);
result.insert(tmp.begin(), tmp.end());
}
return result;
}
#endif
template class Model<double>;

1
src/storm/models/sparse/Model.h

@ -374,6 +374,7 @@ namespace storm {
#ifdef STORM_HAVE_CARL
std::set<storm::RationalFunctionVariable> getProbabilityParameters(Model<storm::RationalFunction> const& model);
std::set<storm::RationalFunctionVariable> getRewardParameters(Model<storm::RationalFunction> const& model);
#endif
} // namespace sparse
} // namespace models

17
src/storm/models/sparse/StandardRewardModel.cpp

@ -299,6 +299,23 @@ namespace storm {
return out;
}
std::set<storm::RationalFunctionVariable> getRewardModelParameters(StandardRewardModel<storm::RationalFunction> const& rewModel) {
std::set<storm::RationalFunctionVariable> vars;
if (rewModel.hasTransitionRewards()) {
vars = storm::storage::getVariables(rewModel.getTransitionRewardMatrix());
}
if (rewModel.hasStateActionRewards()) {
std::set<storm::RationalFunctionVariable> tmp = storm::utility::vector::getVariables(rewModel.getStateActionRewardVector());
vars.insert(tmp.begin(), tmp.end());
}
if (rewModel.hasStateRewards()) {
std::set<storm::RationalFunctionVariable> tmp = storm::utility::vector::getVariables(rewModel.getStateRewardVector());
vars.insert(tmp.begin(), tmp.end());
}
return vars;
}
// Explicitly instantiate the class.
template std::vector<double> StandardRewardModel<double>::getTotalRewardVector(storm::storage::SparseMatrix<double> const& transitionMatrix) const;
template std::vector<double> StandardRewardModel<double>::getTotalRewardVector(uint_fast64_t numberOfRows, storm::storage::SparseMatrix<double> const& transitionMatrix, storm::storage::BitVector const& filter) const;

8
src/storm/models/sparse/StandardRewardModel.h

@ -1,11 +1,11 @@
#ifndef STORM_MODELS_SPARSE_STANDARDREWARDMODEL_H_
#define STORM_MODELS_SPARSE_STANDARDREWARDMODEL_H_
#pragma once
#include <vector>
#include <boost/optional.hpp>
#include "storm/storage/SparseMatrix.h"
#include "storm/utility/OsDetection.h"
#include "storm/adapters/CarlAdapter.h"
namespace storm {
namespace models {
@ -296,8 +296,8 @@ namespace storm {
template <typename ValueType>
std::ostream& operator<<(std::ostream& out, StandardRewardModel<ValueType> const& rewardModel);
std::set<storm::RationalFunctionVariable> getRewardModelParameters(StandardRewardModel<storm::RationalFunction> const& rewModel);
}
}
}
#endif /* STORM_MODELS_SPARSE_STANDARDREWARDMODEL_H_ */

9
src/storm/utility/vector.h

@ -10,6 +10,7 @@
#include <algorithm>
#include <functional>
#include <numeric>
#include <storm/adapters/CarlAdapter.h>
#include "storm/storage/BitVector.h"
#include "storm/utility/constants.h"
@ -822,6 +823,14 @@ namespace storm {
return std::any_of(v.begin(), v.end(), [](T value){return !storm::utility::isZero(value);});
}
inline std::set<storm::RationalFunctionVariable> getVariables(std::vector<storm::RationalFunction> const& vector) {
std::set<storm::RationalFunctionVariable> result;
for(auto const& entry : vector) {
entry.gatherVariables(result);
}
return result;
}
/*!
* Output vector as string.
*

Loading…
Cancel
Save