scram::core::Gate
An indexed gate for use in a PDAG. More...
#include <pdag.h>
Inherits from scram::core::Node, std::enable_shared_from_this< Gate >, scram::core::NodeParentManager
Public Types
| Name | |
|---|---|
| template <class T > <br>using std::pair< int, std::shared_ptr< T > > | Arg <br>An argument entry type in the gate's argument containers. |
| template <class T > <br>using std::pair< int, const T & > | ConstArg |
| template <class T > <br>using ext::linear_map< int, std::shared_ptr< T >, ext::MoveEraser > | ArgMap <br>An associative container type to store the gate arguments. |
| using boost::container::flat_set< int > | ArgSet <br>An ordered set of gate argument indices. |
Public Functions
| Name | |
|---|---|
| Gate(Connective type, Pdag * graph)<br>Creates an indexed gate with its unique index. | |
| ~Gate()<br>Destructs parent information from the arguments. | |
| GatePtr | Clone()<br>Clones arguments and parameters. |
| Connective | type() const |
| void | type(Connective type)<br>Changes the logic of the gate. |
| int | min_number() const |
| void | min_number(int number)<br>Sets the min number for this gate. |
| bool | constant() const |
| const ArgSet & | args() const |
| template <class T > <br>const ArgMap< T > & | args()<br>Generic accessor to the gate argument containers. |
| template <class T > <br>auto | args() const<br>Provides const access to gate arguments w/o exposing the shared pointers. |
| bool | mark() const<br>Marks are used for linear traversal of graphs. |
| void | mark(bool flag)<br>Sets the mark of this gate. |
| int | descendant() const |
| void | descendant(int index)<br>Assigns a descendant index of this gate. |
| int | ancestor() |
| void | ancestor(int index)<br>Assigns an ancestor index of this gate. |
| virtual int | min_time() const override |
| void | min_time(int time)<br>Sets the queried minimum visit time of the sub-graph. |
| virtual int | max_time() const override |
| void | max_time(int time)<br>Sets the queried maximum visit time of the sub-graph. |
| bool | coherent() const |
| void | coherent(bool flag)<br>Sets a coherence flag for the graph rooted by this gate. |
| bool | module() const |
| void | module(bool flag)<br>Sets this gate's module flag. |
| int | GetArgSign(const NodePtr & arg) const<br>Helper function to use the sign of the argument. |
| NodePtr | GetArg(int index) const<br>Helper function for algorithms to get nodes from argument indices. |
| template <class T > <br>void | AddArg(int index, const std::shared_ptr< T > & arg)<br>Adds an argument node to this gate. |
| template <class T > <br>void | AddArg(const std::shared_ptr< T > & arg, bool complement =false)<br>Wrapper to add gate arguments with index retrieval from the arg. |
| template <class T > <br>void | AddArg(const Arg< T > & arg)<br>Wrapper to add arguments from the containers. |
| void | TransferArg(int index, const GatePtr & recipient)<br>Transfers this gate's argument to another gate. |
| void | ShareArg(int index, const GatePtr & recipient)<br>Shares this gate's argument with another gate. |
| void | NegateArgs()<br>Makes all arguments complements of themselves. |
| void | NegateArg(int existing_arg)<br>Replaces an argument with the complement of it. |
| void | NegateNonCoherentGateArgs()<br>Turns all non-coherent arguments of type gate (NOT, NAND, etc.) into complement arguments. |
| void | CoalesceGate(const GatePtr & arg_gate)<br>Adds arguments of an argument gate to this gate. |
| void | JoinNullGate(int index)<br>Swaps a single argument of a NULL type argument gate. |
| void | ProcessConstantArg(const NodePtr & arg, bool state)<br>Changes the state of a gate or removes a constant argument. |
| void | EraseArg(int index)<br>Removes an argument from the arguments container. |
| void | EraseArgs()<br>Clears all the arguments of this gate. |
| void | MakeConstant(bool state)<br>Sets the logic of this gate to pass-through and clears all its arguments except for a Boolean constant. |
| void | AddArg(int index, const ConstantPtr & arg)<br>Convenient wrapper to dispatch appropriate constant arg handler. |
| void | AddArg(int index, const ConstantPtr & arg)<br>Specialization to handle Boolean constants in arguments. |
Additional inherited members
Public Functions inherited from scram::core::Node
| Name | |
|---|---|
| Node(Pdag * graph)<br>Creates a unique graph node as a member of a PDAG. | |
| virtual | ~Node() =0<br>Abstract class. |
| Pdag & | graph() |
| int | index() const |
| int | order() const |
| void | order(int val)<br>Sets the order number for this node. |
| int | opti_value() const |
| void | opti_value(int val)<br>Sets the optimization value for failure propagation. |
| bool | Visit(int time)<br>Registers the visit time for this node upon graph traversal. |
| int | EnterTime() const |
| int | ExitTime() const |
| int | LastVisit() const |
| bool | Revisited() const |
| bool | Visited() const |
| void | ClearVisits()<br>Clears all the visit information. Resets the visit times to 0s. |
| int | pos_count() const |
| int | neg_count() const |
| void | AddCount(bool positive)<br>Increases the count of this node. |
| void | ResetCount()<br>Resets positive and negative counts of this node. |
Public Types inherited from scram::core::NodeParentManager
| Name | |
|---|---|
| using std::pair< int, GateWeakPtr > | Parent <br>Parent index and ptr. |
| using ext::linear_map< int, GateWeakPtr, ext::MoveEraser > | ParentMap <br>A map type of parent gate positive indices and weak pointers to them. |
Public Functions inherited from scram::core::NodeParentManager
| Name | |
|---|---|
| const ParentMap & | parents() const |
Protected Functions inherited from scram::core::NodeParentManager
| Name | |
|---|---|
| ~NodeParentManager() =default |
Detailed Description
class scram::core::Gate;An indexed gate for use in a PDAG.
Initially this gate can represent any type of gate or logic; however, this gate can be only of OR and AND type at the end of all simplifications and processing. This gate class helps process the fault tree before any complex analysis is done.
Public Types Documentation
using Arg
template <class T >
using scram::core::Gate::Arg = std::pair<int, std::shared_ptr<T> >;An argument entry type in the gate's argument containers.
Template Parameters:
- T The type of the argument node.
The entry contains the positive or negative index (indicating a complement) and the pointer to the argument node.
The constant version is to simulate transitive const so that the reference count of the argument cannot be changed.
using ConstArg
template <class T >
using scram::core::Gate::ConstArg = std::pair<int, const T&>;using ArgMap
template <class T >
using scram::core::Gate::ArgMap = ext::linear_map<int, std::shared_ptr<T>, ext::MoveEraser>;An associative container type to store the gate arguments.
Template Parameters:
- T The type of the argument node.
This container type maps the index of the argument to the pointer to it.
using ArgSet
using scram::core::Gate::ArgSet = boost::container::flat_set<int>;An ordered set of gate argument indices.
Public Functions Documentation
function Gate
Gate(
Connective type,
Pdag * graph
)Creates an indexed gate with its unique index.
Parameters:
- type The type of this gate.
- graph The host PDAG.
It is assumed that smart pointers are used to manage the graph, and one shared pointer exists for this gate to manage parent-child hierarchy.
function ~Gate
inline ~Gate()Destructs parent information from the arguments.
function Clone
GatePtr Clone()Clones arguments and parameters.
Return: Shared pointer to a newly created gate.
Warning: This function does not destroy modules. If cloning destroys modules, module(false) member function must be called.
The semantics of the gate is cloned, not the gate data like index and parents.
function type
inline Connective type() constReturn: Type of this gate.
function type
void type(
Connective type
)Changes the logic of the gate.
Parameters:
- type A new type for this gate.
Precondition:
- The new logic is compatible with the existing arguments and preserves the gate invariants.
- The previous type is not equal to the new one.
Depending on the original and new type of the gate, the graph or gate properties may be changed or recorded.
function min_number
inline int min_number() constReturn: Min number.
Precondition: The min number is relevant to the gate logic.
function min_number
inline void min_number(
int number
)Sets the min number for this gate.
Parameters:
- number The min number of ATLEAST gate.
Precondition: The min number is appropriate for the gate logic and arguments.
This function is used for K/N gates.
function constant
inline bool constant() constReturn: true if this gate has become constant.
function args
inline const ArgSet & args() constReturn: The ordered set of argument indices of this gate.
function args
template <class T >
inline const ArgMap< T > & args()Generic accessor to the gate argument containers.
Template Parameters:
- T The type of the argument nodes.
Return: The map container of the gate arguments with the given type.
function args
template <class T >
inline auto args() constProvides const access to gate arguments w/o exposing the shared pointers.
Template Parameters:
- The type of the arguments.
Return: Forward-iterable range with ConstArg value type.
The arguments are provided by reference.
function mark
inline bool mark() constMarks are used for linear traversal of graphs.
Return: The mark of this gate.
This can be an alternative to visit information provided by the base Node class.
function mark
inline void mark(
bool flag
)Sets the mark of this gate.
Parameters:
- flag Marking with the meaning for the marker.
Precondition:
- The marks are assigned in a top-down traversal.
- The marks are continuous.
function descendant
inline int descendant() constReturn: Pre-assigned index of one of gate's descendants.
function descendant
inline void descendant(
int index
)Assigns a descendant index of this gate.
Parameters:
- index Index of the descendant.
function ancestor
inline int ancestor()Return: Pre-assigned index of one of the gate's ancestors.
function ancestor
inline void ancestor(
int index
)Assigns an ancestor index of this gate.
Parameters:
- index Index of the ancestor.
function min_time
inline virtual int min_time() const overrideReturn:
- The minimum time of visits of the gate's sub-graph.
- 0 if no time assignment was performed.
Reimplements: scram::core::Node::min_time
function min_time
inline void min_time(
int time
)Sets the queried minimum visit time of the sub-graph.
Parameters:
- time The positive min time of this gate's sub-graph.
function max_time
inline virtual int max_time() const overrideReturn:
- The maximum time of the visits of the gate's sub-graph.
- 0 if no time assignment was performed.
Reimplements: scram::core::Node::max_time
function max_time
inline void max_time(
int time
)Sets the queried maximum visit time of the sub-graph.
Parameters:
- time The positive max time of this gate's sub-graph.
function coherent
inline bool coherent() constReturn: true if the whole graph of this gate is marked coherent.
function coherent
inline void coherent(
bool flag
)Sets a coherence flag for the graph rooted by this gate.
Parameters:
- flag true if the whole graph is coherent.
function module
inline bool module() constReturn: true if this gate is set to be a module.
function module
inline void module(
bool flag
)Sets this gate's module flag.
Parameters:
- flag true for modular gates.
Precondition: The gate has already been marked with an opposite flag.
function GetArgSign
inline int GetArgSign(
const NodePtr & arg
) constHelper function to use the sign of the argument.
Parameters:
- arg One of the arguments of this gate.
Return:
- 1 if the argument is positive.
- -1 if the argument is negative (complement).
Warning: The function assumes that the argument exists. If it doesn't, the return value is invalid.
function GetArg
inline NodePtr GetArg(
int index
) constHelper function for algorithms to get nodes from argument indices.
Parameters:
- index Positive or negative index of the existing argument.
Return: Pointer to the argument node of this gate.
Warning:
- The function assumes that the argument exists. If it doesn't, the behavior is undefined.
- Never try to use dynamic casts to find the type of the node. There are other gate's helper functions that will avoid any need for the RTTI or other hacks.
function AddArg
template <class T >
inline void AddArg(
int index,
const std::shared_ptr< T > & arg
)Adds an argument node to this gate.
Parameters:
- index A positive or negative index of an argument.
- arg A pointer to the argument node.
Template Parameters:
- T The type of the argument node.
Warning:
- The function does not indicate invalid state. For example, a second argument for NOT or NULL type gates is not going to be reported in any way.
- This function does not indicate error for future additions in case the state is nulled or becomes unity.
- Duplicate arguments may change the type and state of the gate. Depending on the logic of the gate, new gates may be introduced instead of the existing arguments.
- Complex logic gates like ATLEAST and XOR are handled specially if the argument is duplicate. The caller must be very cautious of the side effects of the manipulations.
Before adding the argument, the existing arguments are checked for complements and duplicates. If there is a complement, the gate may change its state (erasing its arguments) or type.
The duplicates are handled according to the logic of the gate. The caller must be aware of possible changes due to the logic of the gate.
function AddArg
template <class T >
inline void AddArg(
const std::shared_ptr< T > & arg,
bool complement =false
)Wrapper to add gate arguments with index retrieval from the arg.
function AddArg
template <class T >
inline void AddArg(
const Arg< T > & arg
)Wrapper to add arguments from the containers.
function TransferArg
void TransferArg(
int index,
const GatePtr & recipient
)Transfers this gate's argument to another gate.
Parameters:
- index Positive or negative index of the argument.
- recipient A new parent for the argument.
Precondition: No constant arguments are present.
function ShareArg
void ShareArg(
int index,
const GatePtr & recipient
)Shares this gate's argument with another gate.
Parameters:
- index Positive or negative index of the argument.
- recipient Another parent for the argument.
Precondition: No constant arguments are present.
function NegateArgs
void NegateArgs()Makes all arguments complements of themselves.
Precondition: No constant arguments are present.
This is a helper function to propagate a complement gate and apply the De Morgan's Law.
function NegateArg
void NegateArg(
int existing_arg
)Replaces an argument with the complement of it.
Parameters:
- existing_arg Positive or negative index of the argument.
Precondition: No constant arguments are present.
This is a helper function to propagate a complement gate and apply the De Morgan's Law.
function NegateNonCoherentGateArgs
inline void NegateNonCoherentGateArgs()Turns all non-coherent arguments of type gate (NOT, NAND, etc.) into complement arguments.
This is a helper function for gate normalization to efficiently normalize non-coherent gates.
function CoalesceGate
void CoalesceGate(
const GatePtr & arg_gate
)Adds arguments of an argument gate to this gate.
Parameters:
- arg_gate The gate which arguments to be added to this gate.
Warning: This function does not test if the parent and argument logics are correct for coalescing.
Precondition: No constant arguments are present.
This is a helper function for gate coalescing. The argument gate of the same logic is removed from the arguments list. The sign of the argument gate is expected to be positive.
function JoinNullGate
void JoinNullGate(
int index
)Swaps a single argument of a NULL type argument gate.
Parameters:
- index Positive or negative index of the argument gate.
This is separate from other coalescing functions because this function takes into account the sign of the argument.
function ProcessConstantArg
void ProcessConstantArg(
const NodePtr & arg,
bool state
)Changes the state of a gate or removes a constant argument.
Parameters:
- arg The pointer the argument of this gate.
- state False or True constant state of the argument.
Note:
- This is a helper function that propagates constants.
- This function takes into account the sign of the index to properly assess the Boolean constant argument.
- This function may change the state of the gate.
- This function may change type and parameters of the gate.
The function determines its actions depending on the type of the gate and state of an argument.
function EraseArg
void EraseArg(
int index
)Removes an argument from the arguments container.
Parameters:
- index The positive or negative index of the existing argument.
Warning: The parent gate may become empty or one-argument gate, which must be handled by the caller.
The passed argument index must be in this gate's arguments container and initialized.
function EraseArgs
void EraseArgs()Clears all the arguments of this gate.
function MakeConstant
void MakeConstant(
bool state
)Sets the logic of this gate to pass-through and clears all its arguments except for a Boolean constant.
Parameters:
- state The value for the Boolean constant.
This function is expected to be used only once.
function AddArg
void AddArg(
int index,
const ConstantPtr & arg
)Convenient wrapper to dispatch appropriate constant arg handler.
function AddArg
void AddArg(
int index,
const ConstantPtr & arg
)Specialization to handle Boolean constants in arguments.
Updated on 2025-11-11 at 16:51:08 +0000
