25#include <unordered_map>
40 explicit FaultTreeError(
const std::string &what) : std::runtime_error(what) {}
94 [[nodiscard]]
bool hasNode(
const std::string &name)
const;
100 [[nodiscard]]
const Node &
node(
const std::string &name)
const;
103 [[nodiscard]]
const std::vector<Node> &
nodes()
const {
return nodes_; }
106 [[nodiscard]] std::size_t
size()
const {
return nodes_.size(); }
111 void setTop(
const std::string &name);
115 [[nodiscard]]
const std::string &
top()
const;
153 std::unordered_map<std::string, std::size_t>
index_;
Exception type of the fault tree model, the .fta reader and the quantifier.
FaultTreeError(const std::string &what)
A fault tree: nodes keyed by name, plus a designated top event.
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
std::size_t size() const
Number of nodes (basic events plus gates).
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()
const std::vector< Node > & nodes() const
All nodes, basic events and gates, in the order they were added.
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