6#include <unordered_map>
9#include <boost/iterator/counting_iterator.hpp>
36template<
typename ValueType>
40 if (a->rank() == 0 && b->rank() == 0) {
41 return a->isConstant();
43 return a->rank() < b->rank();
51template<
typename ValueType>
53 using DFTElementPointer = std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType>>;
54 using DFTElementCPointer = std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType>
const>;
55 using DFTElementVector = std::vector<DFTElementPointer>;
56 using DFTGatePointer = std::shared_ptr<storm::dft::storage::elements::DFTGate<ValueType>>;
57 using DFTGateVector = std::vector<DFTGatePointer>;
58 using DFTStatePointer = std::shared_ptr<storm::dft::storage::DFTState<ValueType>>;
61 DFTElementVector mElements;
64 size_t mNrRepresentatives;
65 size_t mTopLevelIndex;
66 size_t mStateVectorSize;
67 size_t mMaxSpareChildCount;
68 std::map<size_t, storm::dft::storage::DftModule> mModules;
69 std::vector<size_t> mDependencies;
70 std::map<size_t, size_t> mRepresentants;
71 std::map<size_t, DFTLayoutInfo> mLayoutInfo;
72 mutable std::vector<size_t> mRelevantEvents;
73 std::map<size_t, bool> mDependencyInConflict;
76 DFT(DFTElementVector
const& elements, DFTElementPointer
const& tle);
83 size_t stateIndex)
const;
91 return (mStateVectorSize / 64 + (mStateVectorSize % 64 != 0)) * 64;
95 return mElements.size();
107 return mTopLevelIndex;
115 return mMaxSpareChildCount;
119 std::vector<size_t> indices;
120 for (
auto const& elem : mElements) {
121 if (elem->isSpareGate()) {
122 indices.push_back(elem->id());
129 STORM_LOG_ASSERT(mModules.count(representativeId) > 0,
"Representative not found.");
130 return mModules.at(representativeId);
134 std::vector<storm::dft::storage::DftModule> spareModules;
135 for (
auto const& pair : mModules) {
136 if (pair.first != mTopLevelIndex) {
137 spareModules.push_back(pair.second);
145 return mDependencyInConflict.at(
id);
150 mDependencyInConflict.at(
id) =
false;
154 return mDependencies;
158 std::vector<size_t> result;
159 for (DFTElementPointer elem : mElements) {
160 if (elem->isBasicElement()) {
161 std::shared_ptr<storm::dft::storage::elements::DFTBE<ValueType>> be =
162 std::static_pointer_cast<storm::dft::storage::elements::DFTBE<ValueType>>(elem);
164 switch (be->beType()) {
166 result.push_back(be->id());
169 auto beExp = std::static_pointer_cast<storm::dft::storage::elements::BEExponential<ValueType>>(be);
170 if (!beExp->isColdBasicElement()) {
171 result.push_back(be->id());
176 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"BE type '" << be->beType() <<
"' is not supported.");
190 return mElements[index];
209 std::shared_ptr<storm::dft::storage::elements::DFTBE<ValueType>
const>
getBasicElement(
size_t index)
const {
211 return std::static_pointer_cast<storm::dft::storage::elements::DFTBE<ValueType>
const>(mElements[index]);
218 std::shared_ptr<storm::dft::storage::elements::DFTGate<ValueType>
const>
getGate(
size_t index)
const {
220 return std::static_pointer_cast<storm::dft::storage::elements::DFTGate<ValueType>
const>(mElements[index]);
223 std::shared_ptr<storm::dft::storage::elements::DFTDependency<ValueType>
const>
getDependency(
size_t index)
const {
225 return std::static_pointer_cast<storm::dft::storage::elements::DFTDependency<ValueType>
const>(mElements[index]);
228 std::shared_ptr<storm::dft::storage::elements::DFTRestriction<ValueType>
const>
getRestriction(
size_t index)
const {
230 return std::static_pointer_cast<storm::dft::storage::elements::DFTRestriction<ValueType>
const>(mElements[index]);
233 std::vector<std::shared_ptr<storm::dft::storage::elements::DFTBE<ValueType>>>
getBasicElements()
const {
234 std::vector<std::shared_ptr<storm::dft::storage::elements::DFTBE<ValueType>>> elements;
235 for (DFTElementPointer elem : mElements) {
236 if (elem->isBasicElement()) {
250 for (
auto const& parent :
getElement(
id)->parents()) {
251 if (parent->isSpareGate()) {
259 return mRepresentants.find(
id) != mRepresentants.end();
264 return mRepresentants.find(
id)->second;
268 return state->hasFailed(mTopLevelIndex);
276 return state->isFailsafe(mTopLevelIndex);
301 size_t getChild(
size_t spareId,
size_t nrUsedChild)
const;
303 size_t getNrChild(
size_t spareId,
size_t childId)
const;
322 mLayoutInfo[id] = layoutInfo;
326 return mLayoutInfo.at(
id);
342 bool existsName(std::string
const& name)
const;
349 size_t getIndex(std::string
const& name)
const;
371 bool elementIndicesCorrect()
const {
372 for (
size_t i = 0; i < mElements.size(); ++i) {
373 if (mElements[i]->
id() != i)
385std::set<storm::RationalFunctionVariable>
getParameters(DFT<storm::RationalFunction>
const& dft);
Represents a Dynamic Fault Tree.
size_t nrBasicElements() const
bool hasFailed(DFTStatePointer const &state) const
std::vector< size_t > nonColdBEs() const
size_t getTopLevelIndex() const
bool isRepresentative(size_t id) const
std::string getRelevantEventsString() const
Get a string containing the list of all relevant events.
std::shared_ptr< storm::dft::storage::elements::DFTDependency< ValueType > const > getDependency(size_t index) const
void setRelevantEvents(storm::dft::utility::RelevantEvents const &relevantEvents, bool const allowDCForRelevant) const
Set the relevance flag for all elements according to the given relevant events.
std::shared_ptr< storm::dft::storage::elements::DFTBE< ValueType > const > getBasicElement(size_t index) const
size_t nrDynamicElements() const
size_t getNrChild(size_t spareId, size_t childId) const
DFTLayoutInfo const & getElementLayoutInfo(size_t id) const
std::string getModulesString() const
std::set< size_t > getAllIds() const
Get Ids of all elements.
bool hasRepresentant(size_t id) const
std::vector< size_t > findModularisationRewrite() const
void setDependencyNotInConflict(size_t id)
DFTElementCPointer getElement(size_t index) const
Get a pointer to an element in the DFT.
void setElementLayoutInfo(size_t id, DFTLayoutInfo const &layoutInfo)
void writeStatsToStream(std::ostream &stream) const
storm::dft::storage::elements::DFTElementType getTopLevelType() const
std::string getElementsWithStateString(DFTStatePointer const &state) const
DFTElementCPointer getTopLevelElement() const
std::vector< size_t > const & getDependencies() const
bool existsName(std::string const &name) const
Check whether an element with the given name exists.
size_t nrElements() const
std::shared_ptr< storm::dft::storage::elements::DFTGate< ValueType > const > getGate(size_t index) const
std::string getStateString(DFTStatePointer const &state) const
size_t stateBitVectorSize() const
size_t uses(storm::storage::BitVector const &state, DFTStateGenerationInfo const &stateGenerationInfo, size_t id) const
Return id of used child for a given spare gate.
std::string getInfoString() const
std::vector< std::shared_ptr< storm::dft::storage::elements::DFTBE< ValueType > > > getBasicElements() const
bool isDependencyInConflict(size_t id) const
size_t getRepresentant(size_t id) const
size_t generateStateInfo(DFTStateGenerationInfo &generationInfo, size_t id, storm::storage::BitVector &visited, size_t stateIndex) const
bool isDependency(size_t index) const
DFTStateGenerationInfo buildStateGenerationInfo(storm::dft::storage::DftSymmetries const &symmetries) const
bool isGate(size_t index) const
std::shared_ptr< storm::dft::storage::elements::DFTRestriction< ValueType > const > getRestriction(size_t index) const
size_t nrStaticElements() const
bool hasFailed(storm::storage::BitVector const &state, DFTStateGenerationInfo const &stateGenerationInfo) const
std::vector< size_t > const & getRelevantEvents() const
Get all relevant events.
size_t getIndex(std::string const &name) const
Get id for the given element name.
std::vector< size_t > getSpareIndices() const
bool isRestriction(size_t index) const
size_t performStateGenerationInfoDFS(DFTStateGenerationInfo &generationInfo, std::queue< size_t > &visitQueue, storm::storage::BitVector &visited, size_t stateIndex) const
bool isFailsafe(storm::storage::BitVector const &state, DFTStateGenerationInfo const &stateGenerationInfo) const
void copyElements(std::vector< size_t > elements, storm::dft::builder::DFTBuilder< ValueType > builder) const
bool canHaveNondeterminism() const
size_t getMaxSpareChildCount() const
std::vector< size_t > immediateFailureCauses(size_t index) const
size_t getChild(size_t spareId, size_t nrUsedChild) const
std::vector< storm::dft::storage::DftModule > getSpareModules() const
std::string getElementsString() const
storm::dft::storage::DftModule const & module(size_t representativeId) const
std::vector< DFT< ValueType > > topModularisation() const
DFT< ValueType > optimize() const
bool isFailsafe(DFTStatePointer const &state) const
bool isBasicElement(size_t index) const
size_t getStateIndex(size_t id) const
bool hasFailed(size_t id) const
bool isFailsafe(size_t id) const
static uint_fast64_t usesIndex(storm::storage::BitVector const &state, DFTStateGenerationInfo const &stateGenerationInfo, size_t id)
Returns the index of the used child for a spare gate.
Represents a module/subtree in a DFT.
Abstract base class for basic events (BEs) in DFTs.
Abstract base class for DFT elements.
A bit vector that is internally represented as a vector of 64-bit values.
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
DFTElementType
Element types in a DFT.
std::set< storm::RationalFunctionVariable > getParameters(DFT< storm::RationalFunction > const &dft)
Get all rate/probability parameters occurring in the DFT.
bool operator()(std::shared_ptr< storm::dft::storage::elements::DFTElement< ValueType > > const &a, std::shared_ptr< storm::dft::storage::elements::DFTElement< ValueType > > const &b) const