37 auto it =
index_.find(name);
45 auto it =
index_.find(name);
54 throw FaultTreeError(
"cannot set top event to unknown node '" + name +
"'");
65 std::vector<std::string> names;
77 ", not a basic event");
79 if (!(probability >= 0.0 && probability <= 1.0)) {
80 std::ostringstream out;
81 out <<
"probability " << probability <<
" for '" << name
82 <<
"' is outside [0, 1]";
99 std::ostringstream out;
100 out <<
"basic event '" <<
node.
name <<
"' has probability "
108 "' must have exactly one input");
116 std::ostringstream out;
117 out <<
"K/N gate '" <<
node.
name <<
"' has k=" <<
node.
k <<
" with "
131 for (std::size_t i = 0; i <
node.
children.size(); ++i) {
145 for (std::size_t j = 0; j < i; ++j) {
156 enum class Colour { White, Grey, Black };
157 std::vector<Colour> colour(
nodes_.size(), Colour::White);
158 std::vector<std::pair<std::size_t, std::size_t>> stack;
160 for (std::size_t start = 0; start <
nodes_.size(); ++start) {
161 if (colour[start] != Colour::White) {
continue; }
162 stack.emplace_back(start, 0);
163 colour[start] = Colour::Grey;
164 while (!stack.empty()) {
165 auto &[current, next_child] = stack.back();
170 if (colour[child] == Colour::Grey) {
171 throw FaultTreeError(
"the fault tree contains a cycle through '" +
172 nodes_[child].name +
"'");
174 if (colour[child] == Colour::White) {
175 colour[child] = Colour::Grey;
176 stack.emplace_back(child, 0);
179 colour[current] = Colour::Black;
Exception type of the fault tree model, the .fta reader and the quantifier.
const Node & node(const std::string &name) const
Looks a node up by name.
std::vector< Node > nodes_
insertion order
void setBasicEventProbability(const std::string &name, double probability)
const std::string & top() const
Name of the top event.
std::unordered_map< std::string, std::size_t > index_
name to position in nodes_
bool hasNode(const std::string &name) const
Tests whether a node of this name has been added.
std::vector< std::string > basicEventNames() const
void addNode(Node node)
Adds a node at the end of the node list.
Node & mutableNode(const std::string &name)
Non-const lookup. Throws FaultTreeError when the name is unknown.
void setTop(const std::string &name)
Designates the top event.
std::string top_
empty until setTop()
Fault tree model of the faulttree library: FaultTreeError, GateType, Node, and the FaultTree containe...
GateType
Kind of a fault tree node: a basic event or one of four gate types.
@ 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.
std::string name
Identity of the node within a tree. Must be non-empty and unique.
std::vector< std::string > children
inputs by name, in gate input order; empty for basic events
GateType type
Basic event or gate kind. Decides which of the fields below are used.
int k
K/N gates only: threshold, 1 <= k <= number of inputs.
double probability
failure probability in [0, 1]; basic events only