Skip to content

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.
GatePtrClone()<br>Clones arguments and parameters.
Connectivetype() const
voidtype(Connective type)<br>Changes the logic of the gate.
intmin_number() const
voidmin_number(int number)<br>Sets the min number for this gate.
boolconstant() 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>autoargs() const<br>Provides const access to gate arguments w/o exposing the shared pointers.
boolmark() const<br>Marks are used for linear traversal of graphs.
voidmark(bool flag)<br>Sets the mark of this gate.
intdescendant() const
voiddescendant(int index)<br>Assigns a descendant index of this gate.
intancestor()
voidancestor(int index)<br>Assigns an ancestor index of this gate.
virtual intmin_time() const override
voidmin_time(int time)<br>Sets the queried minimum visit time of the sub-graph.
virtual intmax_time() const override
voidmax_time(int time)<br>Sets the queried maximum visit time of the sub-graph.
boolcoherent() const
voidcoherent(bool flag)<br>Sets a coherence flag for the graph rooted by this gate.
boolmodule() const
voidmodule(bool flag)<br>Sets this gate's module flag.
intGetArgSign(const NodePtr & arg) const<br>Helper function to use the sign of the argument.
NodePtrGetArg(int index) const<br>Helper function for algorithms to get nodes from argument indices.
template <class T > <br>voidAddArg(int index, const std::shared_ptr< T > & arg)<br>Adds an argument node to this gate.
template <class T > <br>voidAddArg(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>voidAddArg(const Arg< T > & arg)<br>Wrapper to add arguments from the containers.
voidTransferArg(int index, const GatePtr & recipient)<br>Transfers this gate's argument to another gate.
voidShareArg(int index, const GatePtr & recipient)<br>Shares this gate's argument with another gate.
voidNegateArgs()<br>Makes all arguments complements of themselves.
voidNegateArg(int existing_arg)<br>Replaces an argument with the complement of it.
voidNegateNonCoherentGateArgs()<br>Turns all non-coherent arguments of type gate (NOT, NAND, etc.) into complement arguments.
voidCoalesceGate(const GatePtr & arg_gate)<br>Adds arguments of an argument gate to this gate.
voidJoinNullGate(int index)<br>Swaps a single argument of a NULL type argument gate.
voidProcessConstantArg(const NodePtr & arg, bool state)<br>Changes the state of a gate or removes a constant argument.
voidEraseArg(int index)<br>Removes an argument from the arguments container.
voidEraseArgs()<br>Clears all the arguments of this gate.
voidMakeConstant(bool state)<br>Sets the logic of this gate to pass-through and clears all its arguments except for a Boolean constant.
voidAddArg(int index, const ConstantPtr & arg)<br>Convenient wrapper to dispatch appropriate constant arg handler.
voidAddArg(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()
intindex() const
intorder() const
voidorder(int val)<br>Sets the order number for this node.
intopti_value() const
voidopti_value(int val)<br>Sets the optimization value for failure propagation.
boolVisit(int time)<br>Registers the visit time for this node upon graph traversal.
intEnterTime() const
intExitTime() const
intLastVisit() const
boolRevisited() const
boolVisited() const
voidClearVisits()<br>Clears all the visit information. Resets the visit times to 0s.
intpos_count() const
intneg_count() const
voidAddCount(bool positive)<br>Increases the count of this node.
voidResetCount()<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

cpp
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

cpp
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

cpp
template <class T >
using scram::core::Gate::ConstArg =  std::pair<int, const T&>;

using ArgMap

cpp
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

cpp
using scram::core::Gate::ArgSet =  boost::container::flat_set<int>;

An ordered set of gate argument indices.

Public Functions Documentation

function Gate

cpp
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

cpp
inline ~Gate()

Destructs parent information from the arguments.

function Clone

cpp
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

cpp
inline Connective type() const

Return: Type of this gate.

function type

cpp
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

cpp
inline int min_number() const

Return: Min number.

Precondition: The min number is relevant to the gate logic.

function min_number

cpp
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

cpp
inline bool constant() const

Return: true if this gate has become constant.

function args

cpp
inline const ArgSet & args() const

Return: The ordered set of argument indices of this gate.

function args

cpp
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

cpp
template <class T >
inline auto args() const

Provides 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

cpp
inline bool mark() const

Marks 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

cpp
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

cpp
inline int descendant() const

Return: Pre-assigned index of one of gate's descendants.

function descendant

cpp
inline void descendant(
    int index
)

Assigns a descendant index of this gate.

Parameters:

  • index Index of the descendant.

function ancestor

cpp
inline int ancestor()

Return: Pre-assigned index of one of the gate's ancestors.

function ancestor

cpp
inline void ancestor(
    int index
)

Assigns an ancestor index of this gate.

Parameters:

  • index Index of the ancestor.

function min_time

cpp
inline virtual int min_time() const override

Return:

  • 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

cpp
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

cpp
inline virtual int max_time() const override

Return:

  • 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

cpp
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

cpp
inline bool coherent() const

Return: true if the whole graph of this gate is marked coherent.

function coherent

cpp
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

cpp
inline bool module() const

Return: true if this gate is set to be a module.

function module

cpp
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

cpp
inline int GetArgSign(
    const NodePtr & arg
) const

Helper 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

cpp
inline NodePtr GetArg(
    int index
) const

Helper 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

cpp
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

cpp
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

cpp
template <class T >
inline void AddArg(
    const Arg< T > & arg
)

Wrapper to add arguments from the containers.

function TransferArg

cpp
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

cpp
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

cpp
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

cpp
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

cpp
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

cpp
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

cpp
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

cpp
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

cpp
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

cpp
void EraseArgs()

Clears all the arguments of this gate.

function MakeConstant

cpp
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

cpp
void AddArg(
    int index,
    const ConstantPtr & arg
)

Convenient wrapper to dispatch appropriate constant arg handler.

function AddArg

cpp
void AddArg(
    int index,
    const ConstantPtr & arg
)

Specialization to handle Boolean constants in arguments.


Updated on 2025-11-11 at 16:51:08 +0000