15template<
typename ValueType>
19 toStream(dft, stream);
23template<
typename ValueType>
28template<
typename ValueType>
34 Json jsonParameters = translateParameters(dft);
35 if (!jsonParameters.empty()) {
36 jsonDft[
"parameters"] = jsonParameters;
40 for (
size_t i = 0; i < dft.
nrElements(); ++i) {
41 jsonNodes.push_back(translateElement(dft.
getElement(i)));
43 jsonDft[
"nodes"] = jsonNodes;
48typename DftJsonExporter<storm::RationalFunction>::Json DftJsonExporter<storm::RationalFunction>::translateParameters(
52 std::stringstream stream;
54 jsonParameters.push_back(stream.str());
56 return jsonParameters;
59template<
typename ValueType>
65template<
typename ValueType>
66typename DftJsonExporter<ValueType>::Json DftJsonExporter<ValueType>::translateElement(DFTElementCPointer element) {
68 nodeData[
"id"] = std::to_string(element->id());
69 nodeData[
"name"] = element->name();
72 std::transform(type.begin(), type.end(), type.begin(), ::tolower);
73 nodeData[
"type"] = type;
74 if (element->isRelevant()) {
75 nodeData[
"relevant"] =
true;
78 if (element->isGate() || element->isRestriction()) {
80 auto elemWithChildren = std::static_pointer_cast<storm::dft::storage::elements::DFTChildren<ValueType>
const>(element);
81 std::vector<std::string> children;
82 for (
auto const& child : elemWithChildren->children()) {
83 children.push_back(std::to_string(child->id()));
85 nodeData[
"children"] = children;
88 switch (element->type()) {
90 nodeData[
"voting"] = std::static_pointer_cast<storm::dft::storage::elements::DFTVot<ValueType>
const>(element)->threshold();
93 nodeData[
"inclusive"] = std::static_pointer_cast<storm::dft::storage::elements::DFTPand<ValueType>
const>(element)->isInclusive();
96 nodeData[
"inclusive"] = std::static_pointer_cast<storm::dft::storage::elements::DFTPor<ValueType>
const>(element)->isInclusive();
107 "Element '" << element->name() <<
"' of type '" << element->type() <<
"' is not supported.");
109 }
else if (element->isDependency()) {
111 auto dependency = std::static_pointer_cast<storm::dft::storage::elements::DFTDependency<ValueType>
const>(element);
112 std::vector<std::string> children;
113 children.push_back(std::to_string(dependency->triggerEvent()->id()));
114 for (
auto const& child : dependency->dependentEvents()) {
115 children.push_back(std::to_string(child->id()));
117 nodeData[
"children"] = children;
118 if (storm::utility::isOne<ValueType>(dependency->probability())) {
119 nodeData[
"type"] =
"fdep";
121 std::stringstream stream;
122 stream << dependency->probability();
123 nodeData[
"probability"] = stream.str();
125 }
else if (element->isBasicElement()) {
126 DFTBECPointer be = std::static_pointer_cast<storm::dft::storage::elements::DFTBE<ValueType>
const>(element);
127 nodeData = translateBE(be, nodeData);
130 "Element '" << element->name() <<
"' of type '" << element->type() <<
"' is not supported.");
134 jsonNode[
"data"] = nodeData;
135 jsonNode[
"group"] =
"nodes";
136 jsonNode[
"classes"] = type;
140template<
typename ValueType>
141typename DftJsonExporter<ValueType>::Json DftJsonExporter<ValueType>::translateBE(DFTBECPointer be, Json nodeData) {
144 std::transform(distributionType.begin(), distributionType.end(), distributionType.begin(), ::tolower);
145 nodeData[
"distribution"] = distributionType;
148 switch (be->beType()) {
150 auto beConst = std::static_pointer_cast<storm::dft::storage::elements::BEConst<ValueType>
const>(be);
151 nodeData[
"failed"] = beConst->failed();
155 auto beProb = std::static_pointer_cast<storm::dft::storage::elements::BEProbability<ValueType>
const>(be);
156 std::stringstream stream;
157 stream << beProb->activeFailureProbability();
158 nodeData[
"prob"] = stream.str();
159 stream.str(std::string());
160 stream << beProb->dormancyFactor();
161 nodeData[
"dorm"] = stream.str();
165 auto beExp = std::static_pointer_cast<storm::dft::storage::elements::BEExponential<ValueType>
const>(be);
166 std::stringstream stream;
167 stream << beExp->activeFailureRate();
168 nodeData[
"rate"] = stream.str();
169 stream.str(std::string());
170 stream << beExp->dormancyFactor();
171 nodeData[
"dorm"] = stream.str();
172 nodeData[
"transient"] = beExp->isTransient();
176 auto beErlang = std::static_pointer_cast<storm::dft::storage::elements::BEErlang<ValueType>
const>(be);
177 std::stringstream stream;
178 stream << beErlang->activeFailureRate();
179 nodeData[
"rate"] = stream.str();
180 nodeData[
"phases"] = beErlang->phases();
181 stream.str(std::string());
182 stream << beErlang->dormancyFactor();
183 nodeData[
"dorm"] = stream.str();
187 auto beWeibull = std::static_pointer_cast<storm::dft::storage::elements::BEWeibull<ValueType>
const>(be);
188 std::stringstream stream;
189 stream << beWeibull->shape();
190 nodeData[
"shape"] = stream.str();
191 stream.str(std::string());
192 stream << beWeibull->rate();
193 nodeData[
"rate"] = stream.str();
197 auto beLogNormal = std::static_pointer_cast<storm::dft::storage::elements::BELogNormal<ValueType>
const>(be);
198 std::stringstream stream;
199 stream << beLogNormal->mean();
200 nodeData[
"mean"] = stream.str();
201 stream.str(std::string());
202 stream << beLogNormal->standardDeviation();
203 nodeData[
"stddev"] = stream.str();
207 STORM_LOG_THROW(
false, storm::exceptions::InvalidArgumentException,
"BE of type '" << be->beType() <<
"' is not known.");
213template class DftJsonExporter<double>;
214template class DftJsonExporter<storm::RationalFunction>;
Represents a Dynamic Fault Tree.
size_t getTopLevelIndex() const
DFTElementCPointer getElement(size_t index) const
Get a pointer to an element in the DFT.
size_t nrElements() const
Exports a DFT into the JSON format.
static void toFile(storm::dft::storage::DFT< ValueType > const &dft, std::string const &filepath)
Export DFT to given file.
static void toStream(storm::dft::storage::DFT< ValueType > const &dft, std::ostream &os)
Export DFT to given stream.
#define STORM_LOG_THROW(cond, exception, message)
std::string toString(DFTElementType const &type)
std::set< storm::RationalFunctionVariable > getParameters(DFT< storm::RationalFunction > const &dft)
Get all rate/probability parameters occurring in the DFT.
void closeFile(std::ofstream &stream)
Close the given file after writing.
void openFile(std::string const &filepath, std::ofstream &filestream, bool append=false, bool silent=false)
Open the given file for writing.
std::string dumpJson(storm::json< ValueType > const &j, bool compact)
Dumps the given json object, producing a String.