← Documentation
ADS-IDAC Engine 5.0.0
quantifier.hpp
Go to the documentation of this file.
1#pragma once
11//
12// Exact fault tree quantification by compilation to a Bayesian network.
13//
14// Every fault tree node becomes a binary variable with states
15// {"Failed", "Working"} (state index 0 is Failed, matching the crew BBN's
16// convention that index 0 is the failure state). Basic events get the prior
17// {p, 1-p}; gates get a deterministic conditional table over their inputs.
18// BNCore then compiles a junction tree and returns the exact marginal.
19//
20// Going through the BN rather than multiplying gate probabilities directly is
21// what makes repeated events correct: a basic event feeding several gates is
22// one variable with several children, so the shared dependence is accounted
23// for instead of being double counted.
24//
26#include <cstddef>
27#include <memory>
28#include <string>
29#include <unordered_map>
30#include <vector>
31
32namespace bncore {
33class Graph;
34class JunctionTree;
35class BatchExecutionEngine;
36} // namespace bncore
37
38namespace faulttree {
39
44inline constexpr std::size_t kMaxGateInputs = 20;
45
58public:
65 explicit Quantifier(const FaultTree &tree);
67
68 Quantifier(const Quantifier &) = delete;
69 Quantifier &operator=(const Quantifier &) = delete;
70
73 [[nodiscard]] double topEventProbability() const;
74
83 [[nodiscard]] double probabilityOf(const std::string &name) const;
84
96 void setBasicEventProbability(const std::string &name, double probability);
97
99 [[nodiscard]] std::vector<std::string> basicEventNames() const;
100
103 [[nodiscard]] bool isDefined(const std::string &name) const;
104
105private:
108 void build();
109
111 std::unique_ptr<bncore::Graph> graph_;
112 std::unique_ptr<bncore::JunctionTree> junction_tree_;
113 std::unique_ptr<bncore::BatchExecutionEngine> engine_;
114 std::unordered_map<std::string, std::size_t> var_of_node_;
115};
116
117} // namespace faulttree
A fault tree: nodes keyed by name, plus a designated top event.
Definition: fault_tree.hpp:78
Exact fault tree quantifier backed by a BNCore junction tree.
Definition: quantifier.hpp:57
bool isDefined(const std::string &name) const
Definition: quantifier.cpp:131
double probabilityOf(const std::string &name) const
Definition: quantifier.cpp:99
Quantifier(const Quantifier &)=delete
std::unordered_map< std::string, std::size_t > var_of_node_
node name to BNCore variable id
Definition: quantifier.hpp:114
std::vector< std::string > basicEventNames() const
Names of the basic events, in definition order.
Definition: quantifier.cpp:127
std::unique_ptr< bncore::Graph > graph_
one binary variable per node
Definition: quantifier.hpp:111
std::unique_ptr< bncore::BatchExecutionEngine > engine_
refers to junction_tree_
Definition: quantifier.hpp:113
FaultTree tree_
validated private copy of the model
Definition: quantifier.hpp:110
void setBasicEventProbability(const std::string &name, double probability)
Definition: quantifier.cpp:116
std::unique_ptr< bncore::JunctionTree > junction_tree_
points at graph_
Definition: quantifier.hpp:112
Quantifier(const FaultTree &tree)
Definition: quantifier.cpp:34
double topEventProbability() const
Definition: quantifier.cpp:112
Quantifier & operator=(const Quantifier &)=delete
Fault tree model of the faulttree library: FaultTreeError, GateType, Node, and the FaultTree containe...
constexpr std::size_t kMaxGateInputs
Largest number of inputs a single gate may have.
Definition: quantifier.hpp:44