← Documentation
ADS-IDAC Engine 5.0.0
fault_tree.hpp
Go to the documentation of this file.
1#pragma once
11//
12// Fault tree model: a named DAG of gates over basic events.
13//
14// The model deliberately mirrors the semantics the legacy HCL resolver
15// implemented for GeNIe/SMILE `.fta` files (src/HCL/hcl/HCLFTResolver.cpp), so
16// that trees authored against the old stack quantify identically here.
17//
18// Node identity is the `<node name="...">` string, not the XML `id`. A node
19// that appears in several places in the file is defined once and referenced
20// everywhere else, which is what makes repeated (common-cause) basic events
21// shared rather than duplicated.
22//
23#include <stdexcept>
24#include <string>
25#include <unordered_map>
26#include <vector>
27
28namespace faulttree {
29
37class FaultTreeError : public std::runtime_error {
38public:
40 explicit FaultTreeError(const std::string &what) : std::runtime_error(what) {}
41};
42
48enum class GateType {
49 Basic,
50 And,
51 Or,
52 KofN,
53 Not
54};
55
62struct Node {
64 std::string name;
67 double probability = 0.0;
68 int k = 1;
69 std::vector<std::string> children;
70};
71
78class FaultTree {
79public:
89 void addNode(Node node);
90
94 [[nodiscard]] bool hasNode(const std::string &name) const;
95
100 [[nodiscard]] const Node &node(const std::string &name) const;
101
103 [[nodiscard]] const std::vector<Node> &nodes() const { return nodes_; }
104
106 [[nodiscard]] std::size_t size() const { return nodes_.size(); }
107
111 void setTop(const std::string &name);
112
115 [[nodiscard]] const std::string &top() const;
116
119 [[nodiscard]] std::vector<std::string> basicEventNames() const;
120
127 void setBasicEventProbability(const std::string &name, double probability);
128
146 void validate() const;
147
148private:
150 Node &mutableNode(const std::string &name);
151
152 std::vector<Node> nodes_;
153 std::unordered_map<std::string, std::size_t> index_;
154 std::string top_;
155};
156
157} // namespace faulttree
Exception type of the fault tree model, the .fta reader and the quantifier.
Definition: fault_tree.hpp:37
FaultTreeError(const std::string &what)
Definition: fault_tree.hpp:40
A fault tree: nodes keyed by name, plus a designated top event.
Definition: fault_tree.hpp:78
const Node & node(const std::string &name) const
Looks a node up by name.
Definition: fault_tree.cpp:36
std::vector< Node > nodes_
insertion order
Definition: fault_tree.hpp:152
void setBasicEventProbability(const std::string &name, double probability)
Definition: fault_tree.cpp:72
const std::string & top() const
Name of the top event.
Definition: fault_tree.cpp:59
std::unordered_map< std::string, std::size_t > index_
name to position in nodes_
Definition: fault_tree.hpp:153
bool hasNode(const std::string &name) const
Tests whether a node of this name has been added.
Definition: fault_tree.cpp:32
std::vector< std::string > basicEventNames() const
Definition: fault_tree.cpp:64
void validate() const
Definition: fault_tree.cpp:88
std::size_t size() const
Number of nodes (basic events plus gates).
Definition: fault_tree.hpp:106
void addNode(Node node)
Adds a node at the end of the node list.
Definition: fault_tree.cpp:23
Node & mutableNode(const std::string &name)
Non-const lookup. Throws FaultTreeError when the name is unknown.
Definition: fault_tree.cpp:44
void setTop(const std::string &name)
Designates the top event.
Definition: fault_tree.cpp:52
std::string top_
empty until setTop()
Definition: fault_tree.hpp:154
const std::vector< Node > & nodes() const
All nodes, basic events and gates, in the order they were added.
Definition: fault_tree.hpp:103
GateType
Kind of a fault tree node: a basic event or one of four gate types.
Definition: fault_tree.hpp:48
@ Or
fails when any input fails (.fta type 1)
@ KofN
fails when at least k inputs fail (.fta type 6)
@ Basic
basic event, quantified by probability
@ Not
fails when its single input does not (.fta type 7)
@ And
fails when every input fails (.fta type 0)
One fault tree node: a basic event or a gate, identified by name.
Definition: fault_tree.hpp:62
std::string name
Identity of the node within a tree. Must be non-empty and unique.
Definition: fault_tree.hpp:64
std::vector< std::string > children
inputs by name, in gate input order; empty for basic events
Definition: fault_tree.hpp:69
GateType type
Basic event or gate kind. Decides which of the fields below are used.
Definition: fault_tree.hpp:66
int k
K/N gates only: threshold, 1 <= k <= number of inputs.
Definition: fault_tree.hpp:68
double probability
failure probability in [0, 1]; basic events only
Definition: fault_tree.hpp:67