14template<
typename ValueType>
18 toStream(dft, stream);
22template<
typename ValueType>
27template<
typename ValueType>
33 Json jsonParameters = translateParameters(dft);
34 if (!jsonParameters.empty()) {
35 jsonDft[
"parameters"] = jsonParameters;
39 for (
size_t i = 0; i < dft.
nrElements(); ++i) {
40 jsonNodes.push_back(translateElement(dft.
getElement(i)));
42 jsonDft[
"nodes"] = jsonNodes;
47typename DftJsonExporter<storm::RationalFunction>::Json DftJsonExporter<storm::RationalFunction>::translateParameters(
51 std::stringstream stream;
53 jsonParameters.push_back(stream.str());
55 return jsonParameters;
58template<
typename ValueType>
64template<
typename ValueType>
65typename DftJsonExporter<ValueType>::Json DftJsonExporter<ValueType>::translateElement(DFTElementCPointer element) {
67 nodeData[
"id"] = std::to_string(element->id());
68 nodeData[
"name"] = element->name();
71 std::transform(type.begin(), type.end(), type.begin(), ::tolower);
72 nodeData[
"type"] = type;
73 if (element->isRelevant()) {
74 nodeData[
"relevant"] =
true;
77 if (element->isGate() || element->isRestriction()) {
79 auto elemWithChildren = std::static_pointer_cast<storm::dft::storage::elements::DFTChildren<ValueType>
const>(element);
80 std::vector<std::string> children;
81 for (
auto const& child : elemWithChildren->children()) {
82 children.push_back(std::to_string(child->id()));
84 nodeData[
"children"] = children;
87 switch (element->type()) {
89 nodeData[
"voting"] = std::static_pointer_cast<storm::dft::storage::elements::DFTVot<ValueType>
const>(element)->threshold();
92 nodeData[
"inclusive"] = std::static_pointer_cast<storm::dft::storage::elements::DFTPand<ValueType>
const>(element)->isInclusive();
95 nodeData[
"inclusive"] = std::static_pointer_cast<storm::dft::storage::elements::DFTPor<ValueType>
const>(element)->isInclusive();
106 "Element '" << element->name() <<
"' of type '" << element->type() <<
"' is not supported.");
108 }
else if (element->isDependency()) {
110 auto dependency = std::static_pointer_cast<storm::dft::storage::elements::DFTDependency<ValueType>
const>(element);
111 std::vector<std::string> children;
112 children.push_back(std::to_string(dependency->triggerEvent()->id()));
113 for (
auto const& child : dependency->dependentEvents()) {
114 children.push_back(std::to_string(child->id()));
116 nodeData[
"children"] = children;
117 if (storm::utility::isOne<ValueType>(dependency->probability())) {
118 nodeData[
"type"] =
"fdep";
120 std::stringstream stream;
121 stream << dependency->probability();
122 nodeData[
"probability"] = stream.str();
124 }
else if (element->isBasicElement()) {
125 DFTBECPointer be = std::static_pointer_cast<storm::dft::storage::elements::DFTBE<ValueType>
const>(element);
126 nodeData = translateBE(be, nodeData);
129 "Element '" << element->name() <<
"' of type '" << element->type() <<
"' is not supported.");
133 jsonNode[
"data"] = nodeData;
134 jsonNode[
"group"] =
"nodes";
135 jsonNode[
"classes"] = type;
139template<
typename ValueType>
140typename DftJsonExporter<ValueType>::Json DftJsonExporter<ValueType>::translateBE(DFTBECPointer be, Json nodeData) {
143 std::transform(distributionType.begin(), distributionType.end(), distributionType.begin(), ::tolower);
144 nodeData[
"distribution"] = distributionType;
147 switch (be->beType()) {
149 auto beConst = std::static_pointer_cast<storm::dft::storage::elements::BEConst<ValueType>
const>(be);
150 nodeData[
"failed"] = beConst->failed();
154 auto beProb = std::static_pointer_cast<storm::dft::storage::elements::BEProbability<ValueType>
const>(be);
155 std::stringstream stream;
156 stream << beProb->activeFailureProbability();
157 nodeData[
"prob"] = stream.str();
158 stream.str(std::string());
159 stream << beProb->dormancyFactor();
160 nodeData[
"dorm"] = stream.str();
164 auto beExp = std::static_pointer_cast<storm::dft::storage::elements::BEExponential<ValueType>
const>(be);
165 std::stringstream stream;
166 stream << beExp->activeFailureRate();
167 nodeData[
"rate"] = stream.str();
168 stream.str(std::string());
169 stream << beExp->dormancyFactor();
170 nodeData[
"dorm"] = stream.str();
171 nodeData[
"transient"] = beExp->isTransient();
175 auto beErlang = std::static_pointer_cast<storm::dft::storage::elements::BEErlang<ValueType>
const>(be);
176 std::stringstream stream;
177 stream << beErlang->activeFailureRate();
178 nodeData[
"rate"] = stream.str();
179 nodeData[
"phases"] = beErlang->phases();
180 stream.str(std::string());
181 stream << beErlang->dormancyFactor();
182 nodeData[
"dorm"] = stream.str();
186 auto beWeibull = std::static_pointer_cast<storm::dft::storage::elements::BEWeibull<ValueType>
const>(be);
187 std::stringstream stream;
188 stream << beWeibull->shape();
189 nodeData[
"shape"] = stream.str();
190 stream.str(std::string());
191 stream << beWeibull->rate();
192 nodeData[
"rate"] = stream.str();
196 auto beLogNormal = std::static_pointer_cast<storm::dft::storage::elements::BELogNormal<ValueType>
const>(be);
197 std::stringstream stream;
198 stream << beLogNormal->mean();
199 nodeData[
"mean"] = stream.str();
200 stream.str(std::string());
201 stream << beLogNormal->standardDeviation();
202 nodeData[
"stddev"] = stream.str();
206 STORM_LOG_THROW(
false, storm::exceptions::InvalidArgumentException,
"BE of type '" << be->beType() <<
"' is not known.");
212template class DftJsonExporter<double>;
213template 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.