Browse Source

add random step functionality to simulator

tempestpy_adaptions
Sebastian Junges 4 years ago
parent
commit
5fa667b847
  1. 9
      src/storm/simulator/DiscreteTimeSparseModelSimulator.cpp
  2. 1
      src/storm/simulator/DiscreteTimeSparseModelSimulator.h
  3. 4
      src/storm/utility/random.cpp
  4. 2
      src/storm/utility/random.h

9
src/storm/simulator/DiscreteTimeSparseModelSimulator.cpp

@ -21,6 +21,15 @@ namespace storm {
generator = storm::utility::RandomProbabilityGenerator<double>(seed);
}
template<typename ValueType, typename RewardModelType>
bool DiscreteTimeSparseModelSimulator<ValueType,RewardModelType>::randomStep() {
// TODO random_uint is slow
if (model.getTransitionMatrix().getRowGroupSize(currentState) == 0) {
return false;
}
return step(generator.random_uint(0, model.getTransitionMatrix().getRowGroupSize(currentState) - 1));
}
template<typename ValueType, typename RewardModelType>
bool DiscreteTimeSparseModelSimulator<ValueType,RewardModelType>::step(uint64_t action) {
// TODO lots of optimization potential.

1
src/storm/simulator/DiscreteTimeSparseModelSimulator.h

@ -19,6 +19,7 @@ namespace storm {
DiscreteTimeSparseModelSimulator(storm::models::sparse::Model<ValueType, RewardModelType> const& model);
void setSeed(uint64_t);
bool step(uint64_t action);
bool randomStep();
std::vector<ValueType> const& getLastRewards() const;
uint64_t getCurrentState() const;
bool resetToInitial();

4
src/storm/utility/random.cpp

@ -19,6 +19,10 @@ namespace storm {
return distribution(engine);
}
uint64_t RandomProbabilityGenerator<double>::random_uint(uint64_t min, uint64_t max) {
return std::uniform_int_distribution<uint64_t>(min, max)(engine);
}
}
}

2
src/storm/utility/random.h

@ -8,6 +8,7 @@ namespace storm {
RandomProbabilityGenerator();
RandomProbabilityGenerator(uint64_t seed);
ValueType random() const;
uint64_t random_uint(uint64_t min, uint64_t max);
};
@ -17,6 +18,7 @@ namespace storm {
RandomProbabilityGenerator();
RandomProbabilityGenerator(uint64_t seed);
double random();
uint64_t random_uint(uint64_t min, uint64_t max);
private:
std::uniform_real_distribution<double> distribution;
std::mt19937 engine;

Loading…
Cancel
Save