97 lines
3.9 KiB

  1. #include "storm-dft/generator/DftNextStateGenerator.h"
  2. #include "storm-dft/storage/dft/DFT.h"
  3. #include "storm-dft/storage/dft/DFTState.h"
  4. #include "storm-dft/storage/dft/FailableElements.h"
  5. #include "storm/utility/random.h"
  6. namespace storm {
  7. namespace dft {
  8. namespace simulator {
  9. /*!
  10. * Simulator for DFTs.
  11. * A step in the simulation corresponds to the failure of one BE (either on its own or triggered by a dependency)
  12. * and the failure propagation through the DFT.
  13. * The simulator also allows to randomly generate a next failure according to the failure rates.
  14. */
  15. template<typename ValueType>
  16. class DFTTraceSimulator {
  17. using DFTStatePointer = std::shared_ptr<storm::storage::DFTState<ValueType>>;
  18. public:
  19. /*!
  20. * Constructor.
  21. *
  22. * @param dft DFT.
  23. * @param stateGenerationInfo Info for state generation.
  24. * @param randomGenerator Random number generator.
  25. */
  26. DFTTraceSimulator(storm::storage::DFT<ValueType> const& dft, storm::storage::DFTStateGenerationInfo const& stateGenerationInfo, boost::mt19937& randomGenerator);
  27. /*!
  28. * Set the random number generator.
  29. *
  30. * @param randomNumberGenerator Random number generator.
  31. */
  32. void setRandomNumberGenerator(boost::mt19937& randomNumberGenerator);
  33. /*!
  34. * Set the current state back to the intial state in order to start a new simulation.
  35. */
  36. void resetToInitial();
  37. /*!
  38. * Get the current DFT state.
  39. *
  40. * @return DFTStatePointer DFT state.
  41. */
  42. DFTStatePointer getCurrentState() const;
  43. /*!
  44. * Perform one simulation step by letting the next element fail.
  45. *
  46. * @param nextFailElement Iterator giving the next element which should fail.
  47. * @return True iff step could be performed successfully.
  48. */
  49. bool step(storm::dft::storage::FailableElements::const_iterator nextFailElement);
  50. /*!
  51. * Perform a random step by using the random number generator.
  52. *
  53. * @return double The time which progessed between the last step and this step.
  54. * Returns -1 if no next step could be created.
  55. */
  56. double randomStep();
  57. /*!
  58. * Perform a complete simulation of a failure trace by using the random number generator.
  59. * The simulation starts in the initial state and tries to reach a state where the top-level event of the DFT has failed.
  60. * If this target state can be reached within the given timebound, the simulation was successful.
  61. *
  62. * @param timebound Time bound in which the system failure should occur.
  63. * @return True iff a system failure occurred for the generated trace within the time bound.
  64. */
  65. bool simulateCompleteTrace(double timebound);
  66. protected:
  67. // The DFT used for the generation of next states.
  68. storm::storage::DFT<ValueType> const& dft;
  69. // General information for the state generation.
  70. storm::storage::DFTStateGenerationInfo const& stateGenerationInfo;
  71. // Generator for creating next state in DFT
  72. storm::generator::DftNextStateGenerator<ValueType> generator;
  73. // Current state
  74. DFTStatePointer state;
  75. // Random number generator
  76. boost::mt19937& randomGenerator;
  77. };
  78. }
  79. }
  80. }