← Documentation
ADS-IDAC Engine 5.0.0
faulttree::FaultTree Class Reference

A fault tree: nodes keyed by name, plus a designated top event. More...

#include <fault_tree.hpp>

Public Member Functions

void addNode (Node node)
 Adds a node at the end of the node list. More...
 
bool hasNode (const std::string &name) const
 Tests whether a node of this name has been added. More...
 
const Node & node (const std::string &name) const
 Looks a node up by name. More...
 
const std::vector< Node > & nodes () const
 All nodes, basic events and gates, in the order they were added. More...
 
std::size_t size () const
 Number of nodes (basic events plus gates). More...
 
void setTop (const std::string &name)
 Designates the top event. More...
 
const std::string & top () const
 Name of the top event. More...
 
std::vector< std::string > basicEventNames () const
 
void setBasicEventProbability (const std::string &name, double probability)
 
void validate () const
 

Private Member Functions

Node & mutableNode (const std::string &name)
 Non-const lookup. Throws FaultTreeError when the name is unknown. More...
 

Private Attributes

std::vector< Node > nodes_
 insertion order More...
 
std::unordered_map< std::string, std::size_t > index_
 name to position in nodes_ More...
 
std::string top_
 empty until setTop() More...
 

Detailed Description

A fault tree: nodes keyed by name, plus a designated top event.

Nodes are stored in the order they are added, and that order is what nodes() and basicEventNames() report. addNode() and setTop() check only the name. All structural rules are checked by validate(), which the .fta reader and the Quantifier constructor both call.

Definition at line 78 of file fault_tree.hpp.

Member Function Documentation

◆ addNode()

void faulttree::FaultTree::addNode ( Node  node)

Adds a node at the end of the node list.

The inputs named in node.children do not have to exist yet.

Parameters
nodeNode to store. node.name must be non-empty.
Exceptions
FaultTreeErrorif the name is empty or a node of that name already exists.
Note
Node references returned earlier by node(), and iterators into nodes(), can be invalidated, because the nodes live in one std::vector.

Definition at line 23 of file fault_tree.cpp.

References index_, faulttree::Node::name, node(), and nodes_.

Here is the call graph for this function:

◆ basicEventNames()

std::vector< std::string > faulttree::FaultTree::basicEventNames ( ) const

Names of every basic event, in definition order (the order of the addNode() calls).

Definition at line 64 of file fault_tree.cpp.

References faulttree::Basic, faulttree::Node::name, node(), nodes_, and faulttree::Node::type.

Referenced by faulttree::Quantifier::basicEventNames().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasNode()

bool faulttree::FaultTree::hasNode ( const std::string &  name) const

Tests whether a node of this name has been added.

Parameters
nameNode name, compared exactly.
Returns
True when the tree holds a node of that name.

Definition at line 32 of file fault_tree.cpp.

References index_.

Referenced by faulttree::Quantifier::isDefined(), setTop(), and validate().

Here is the caller graph for this function:

◆ mutableNode()

Node & faulttree::FaultTree::mutableNode ( const std::string &  name)
private

Non-const lookup. Throws FaultTreeError when the name is unknown.

Definition at line 44 of file fault_tree.cpp.

References index_, and nodes_.

Referenced by setBasicEventProbability().

Here is the caller graph for this function:

◆ node()

const Node & faulttree::FaultTree::node ( const std::string &  name) const

Looks a node up by name.

Parameters
nameNode name, compared exactly.
Returns
The stored node.
Exceptions
FaultTreeErrorif no node of that name exists.

Definition at line 36 of file fault_tree.cpp.

References index_, and nodes_.

Referenced by addNode(), basicEventNames(), and validate().

Here is the caller graph for this function:

◆ nodes()

const std::vector< Node > & faulttree::FaultTree::nodes ( ) const
inline

All nodes, basic events and gates, in the order they were added.

Definition at line 103 of file fault_tree.hpp.

References nodes_.

Referenced by faulttree::Quantifier::build().

Here is the caller graph for this function:

◆ setBasicEventProbability()

void faulttree::FaultTree::setBasicEventProbability ( const std::string &  name,
double  probability 
)

Overrides a basic event's probability (the fixEvent operation the engine performs when a component failure is observed).

Parameters
nameName of a basic event.
probabilityNew failure probability, in [0, 1].
Exceptions
FaultTreeErrorif the node is missing, is not a basic event, or the probability is outside [0, 1] (NaN is rejected too).

Definition at line 72 of file fault_tree.cpp.

References faulttree::Basic, mutableNode(), faulttree::Node::probability, and faulttree::Node::type.

Referenced by faulttree::Quantifier::setBasicEventProbability().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTop()

void faulttree::FaultTree::setTop ( const std::string &  name)

Designates the top event.

Parameters
nameName of a node that has already been added.
Exceptions
FaultTreeErrorif no node of that name exists.

Definition at line 52 of file fault_tree.cpp.

References hasNode(), and top_.

Here is the call graph for this function:

◆ size()

std::size_t faulttree::FaultTree::size ( ) const
inline

Number of nodes (basic events plus gates).

Definition at line 106 of file fault_tree.hpp.

References nodes_.

Referenced by faulttree::Quantifier::probabilityOf().

Here is the caller graph for this function:

◆ top()

const std::string & faulttree::FaultTree::top ( ) const

Name of the top event.

Exceptions
FaultTreeErrorif setTop() has not been called.

Definition at line 59 of file fault_tree.cpp.

References top_.

Referenced by faulttree::Quantifier::topEventProbability().

Here is the caller graph for this function:

◆ validate()

void faulttree::FaultTree::validate ( ) const

Structural check: every child resolves, no cycles, gates have the inputs their type requires, probabilities are in [0, 1], k is within range. Throws FaultTreeError describing the first problem found.

The checks, in order:

  • the tree is not empty and has a top event;
  • for each node in insertion order: a basic event has no inputs and a probability in [0, 1]; a NOT gate has exactly one input; AND, OR and K/N gates have at least one input; a K/N gate has 1 <= k <= number of inputs; every input names an existing node, is not the node itself, and is listed at most once in that gate;
  • the input graph has no cycle (iterative depth-first search, so deep trees do not grow the call stack).

An event that feeds several gates is valid. Nodes that cannot be reached from the top event are not reported.

Exceptions
FaultTreeErrorfor the first violated rule.

Definition at line 88 of file fault_tree.cpp.

References faulttree::And, faulttree::Basic, faulttree::Node::children, hasNode(), index_, faulttree::Node::k, faulttree::KofN, faulttree::Node::name, node(), nodes_, faulttree::Not, faulttree::Or, faulttree::Node::probability, top_, and faulttree::Node::type.

Referenced by faulttree::Quantifier::Quantifier().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ index_

std::unordered_map<std::string, std::size_t> faulttree::FaultTree::index_
private

name to position in nodes_

Definition at line 153 of file fault_tree.hpp.

Referenced by addNode(), hasNode(), mutableNode(), node(), and validate().

◆ nodes_

std::vector<Node> faulttree::FaultTree::nodes_
private

insertion order

Definition at line 152 of file fault_tree.hpp.

Referenced by addNode(), basicEventNames(), mutableNode(), node(), nodes(), size(), and validate().

◆ top_

std::string faulttree::FaultTree::top_
private

empty until setTop()

Definition at line 154 of file fault_tree.hpp.

Referenced by setTop(), top(), and validate().


The documentation for this class was generated from the following files: