Skip to content
Draft
3 changes: 3 additions & 0 deletions doc/developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ The following contains some general guidelines for developers.
#include ...
```

### File structure
- Test files in `src/test/` end with the suffix `*Test.cpp`.

### Output
- We provide custom macros for output and logging.
The use of `std::cout` should be avoided and instead, macros such as `STORM_LOG_DEBUG`, `STORM_LOG_INFO` or `STORM_PRINT_AND_LOG` should be used.
Expand Down
16 changes: 7 additions & 9 deletions src/storm-dft/simulator/DFTTraceSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ namespace simulator {

template<typename ValueType>
DFTTraceSimulator<ValueType>::DFTTraceSimulator(storm::dft::storage::DFT<ValueType> const& dft,
storm::dft::storage::DFTStateGenerationInfo const& stateGenerationInfo, boost::mt19937& randomGenerator)
storm::dft::storage::DFTStateGenerationInfo const& stateGenerationInfo,
storm::utility::RandomProbabilityGenerator<ValueType> randomGenerator)
: dft(dft), stateGenerationInfo(stateGenerationInfo), generator(dft, stateGenerationInfo), randomGenerator(randomGenerator) {
// Set initial state
resetToInitial();
}

template<typename ValueType>
void DFTTraceSimulator<ValueType>::setRandomNumberGenerator(boost::mt19937& randomNumberGenerator) {
this->randomGenerator = randomNumberGenerator;
void DFTTraceSimulator<ValueType>::setRandomGenerator(storm::utility::RandomProbabilityGenerator<ValueType> randomGenerator) {
this->randomGenerator = randomGenerator;
}

template<typename ValueType>
Expand Down Expand Up @@ -65,8 +66,7 @@ std::tuple<storm::dft::storage::FailableElements::const_iterator, double, bool>
bool successful = true;
if (!dependency->isFDEP()) {
// Flip a coin whether the PDEP is successful
storm::utility::BernoulliDistributionGenerator probGenerator(dependency->probability());
successful = probGenerator.random(randomGenerator);
successful = randomGenerator.randomProbability() <= dependency->probability();
}
STORM_LOG_TRACE("Let dependency " << *dependency << " " << (successful ? "successfully" : "unsuccessfully") << " fail");
return std::make_tuple(iterFailable, 0, successful);
Expand All @@ -75,15 +75,13 @@ std::tuple<storm::dft::storage::FailableElements::const_iterator, double, bool>
// Initialize with first BE
storm::dft::storage::FailableElements::const_iterator nextFail = iterFailable;
double rate = state->getBERate(nextFail.asBE(dft)->id());
storm::utility::ExponentialDistributionGenerator rateGenerator(rate);
double smallestTimebound = rateGenerator.random(randomGenerator);
double smallestTimebound = randomGenerator.randomExponential(rate);
++iterFailable;

// Consider all other BEs and find the one which fails first
for (; iterFailable != state->getFailableElements().end(); ++iterFailable) {
rate = state->getBERate(iterFailable.asBE(dft)->id());
rateGenerator = storm::utility::ExponentialDistributionGenerator(rate);
double timebound = rateGenerator.random(randomGenerator);
double timebound = randomGenerator.randomExponential(rate);
if (timebound < smallestTimebound) {
// BE fails earlier -> use as nextFail
nextFail = iterFailable;
Expand Down
11 changes: 5 additions & 6 deletions src/storm-dft/simulator/DFTTraceSimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "storm-dft/storage/DFT.h"
#include "storm-dft/storage/DFTState.h"
#include "storm-dft/storage/FailableElements.h"

#include "storm/utility/random.h"

namespace storm::dft {
Expand Down Expand Up @@ -41,14 +40,14 @@ class DFTTraceSimulator {
* @param randomGenerator Random number generator.
*/
DFTTraceSimulator(storm::dft::storage::DFT<ValueType> const& dft, storm::dft::storage::DFTStateGenerationInfo const& stateGenerationInfo,
boost::mt19937& randomGenerator);
storm::utility::RandomProbabilityGenerator<ValueType> randomGenerator);

/*!
* Set the random number generator.
*
* @param randomNumberGenerator Random number generator.
* @param randomGenerator Random number generator.
*/
void setRandomNumberGenerator(boost::mt19937& randomNumberGenerator);
void setRandomGenerator(storm::utility::RandomProbabilityGenerator<ValueType> randomGenerator);

/*!
* Set the current state back to the initial state in order to start a new simulation.
Expand Down Expand Up @@ -144,8 +143,8 @@ class DFTTraceSimulator {
// Currently elapsed time
double time;

// Random number generator
boost::mt19937& randomGenerator;
// Random generator
storm::utility::RandomProbabilityGenerator<ValueType> randomGenerator;
};

} // namespace simulator
Expand Down
98 changes: 0 additions & 98 deletions src/storm/simulator/DiscreteTimeSparseModelSimulator.cpp

This file was deleted.

35 changes: 0 additions & 35 deletions src/storm/simulator/DiscreteTimeSparseModelSimulator.h

This file was deleted.

61 changes: 61 additions & 0 deletions src/storm/simulator/ModelSimulator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "storm/simulator/ModelSimulator.h"

#include "storm/utility/constants.h"
#include "storm/utility/macros.h"

namespace storm {
namespace simulator {

template<typename ValueType>
ModelSimulator<ValueType>::ModelSimulator() : currentTime(storm::utility::zero<ValueType>()), randomGenerator() {
// Intentionally left empty
}

template<typename ValueType>
void ModelSimulator<ValueType>::setSeed(uint64_t newSeed) {
randomGenerator = storm::utility::RandomProbabilityGenerator<ValueType>(newSeed);
}

template<typename ValueType>
bool ModelSimulator<ValueType>::randomStep() {
if (isContinuousTimeModel()) {
// First choose time when to leave the state
randomTime();
}

if (isCurrentStateDeadlock()) {
return false;
}
if (getCurrentNumberOfChoices() == 1) {
return step(0);
}
// Select action by uniform distribution
return step(this->randomGenerator.randomSelect(0, getCurrentNumberOfChoices() - 1));
}

template<typename ValueType>
void ModelSimulator<ValueType>::randomTime() {
STORM_LOG_ASSERT(isContinuousTimeModel(), "Model must be continuous-time model");
ValueType exitRate = getCurrentExitRate();
if (!storm::utility::isZero(exitRate)) {
STORM_LOG_ASSERT(getCurrentNumberOfChoices() == 1, "Markovian state should have a trivial row group.");
ValueType time = this->randomGenerator.randomExponential(exitRate);
this->currentTime += time;
}
}

template<typename ValueType>
ValueType ModelSimulator<ValueType>::getCurrentTime() const {
return currentTime;
}

template<typename ValueType>
std::vector<ValueType> const& ModelSimulator<ValueType>::getCurrentRewards() const {
return currentRewards;
}

template class ModelSimulator<double>;
template class ModelSimulator<storm::RationalNumber>;

} // namespace simulator
} // namespace storm
Loading
Loading