Skip to content

Class cowboys::GraphNode

ClassList > cowboys > GraphNode

A node in a decision graph. More...

  • #include <GraphNode.hpp>

Inherits the following classes: std::enable_shared_from_this< GraphNode >

Public Functions

Type Name
void AddInput (std::shared_ptr< GraphNode > node)
Add an input node to this node.
void AddInputs (const std::vector< std::shared_ptr< GraphNode > > & nodes)
Append nodes in a vector to this node's list of inputs.
double GetDefaultOutput () const
Get the default output of this node.
std::vector< double > GetInputValues () const
Get the output values of the inputs of this node.
std::optional< std::vector< double > > GetInputValues (const std::array< size_t, N > & indices) const
Get the output values of the inputs of this node given an array of indices.
double GetOutput () const
Get the output of this node. Performs caching.
GraphNode () = default
GraphNode (double default_value)
TODO: Check guidelines for this.
GraphNode (NodeFunction function)
GraphNode (InnerFunction function)
bool IsCacheValid () const
Check if the cached output is valid.
void SetDefaultOutput (double value)
Set the default output of this node.
void SetFunctionPointer (NodeFunction function)
Set the function pointer of this node.
void SetFunctionPointer (InnerFunction inner_function)
Set the function pointer of this node.
void SetInputs (std::vector< std::shared_ptr< GraphNode > > nodes)
Set the input nodes of this node.
~GraphNode () = default

Protected Attributes

Type Name
double cached_output = {0}
The cached output of this node.
bool cached_output_valid = {false}
Flag indicating whether the cached output is valid.
double default_output = {0}
The default output of this node.
NodeFunction function_pointer
The function that operates on the outputs from a node's input nodes.
std::vector< std::shared_ptr< GraphNode > > inputs
The input nodes to this node.
std::vector< GraphNode * > outputs
The nodes connected to this node's output.

Protected Functions

Type Name
void AddOutput (GraphNode * node)
Add an output node to this node. Used for cache invalidation.
void RecursiveInvalidateCache () const
Invalidates this node's cache and the caches of all nodes that depend on this node.

Detailed Description

Note:

This should always be a shared pointer. Caching will not work otherwise.

Public Functions Documentation

function AddInput

Add an input node to this node.

inline void cowboys::GraphNode::AddInput (
    std::shared_ptr< GraphNode > node
) 

Parameters:

  • node The node to add as an input.

function AddInputs

Append nodes in a vector to this node's list of inputs.

inline void cowboys::GraphNode::AddInputs (
    const std::vector< std::shared_ptr< GraphNode > > & nodes
) 

Parameters:

  • nodes The nodes to add as inputs.

function GetDefaultOutput

Get the default output of this node.

inline double cowboys::GraphNode::GetDefaultOutput () const

Returns:

The default output.

function GetInputValues [1/2]

Get the output values of the inputs of this node.

inline std::vector< double > cowboys::GraphNode::GetInputValues () const

Returns:

A vector of doubles representing the input values.

function GetInputValues [2/2]

Get the output values of the inputs of this node given an array of indices.

template<size_t N>
inline std::optional< std::vector< double > > cowboys::GraphNode::GetInputValues (
    const std::array< size_t, N > & indices
) const

Template parameters:

  • N The size of the indices array.

Parameters:

  • indices The indices of the inputs to get the output values of.

Returns:

A vector of doubles representing the input values in the same order of the indices.

function GetOutput

Get the output of this node. Performs caching.

inline double cowboys::GraphNode::GetOutput () const

Returns:

The output of this node.

function GraphNode [1/4]

cowboys::GraphNode::GraphNode () = default

function GraphNode [2/4]

inline cowboys::GraphNode::GraphNode (
    double default_value
) 

function GraphNode [3/4]

inline cowboys::GraphNode::GraphNode (
    NodeFunction function
) 

function GraphNode [4/4]

inline cowboys::GraphNode::GraphNode (
    InnerFunction function
) 

function IsCacheValid

Check if the cached output is valid.

inline bool cowboys::GraphNode::IsCacheValid () const

Returns:

True if the cached output is valid, false otherwise.

function SetDefaultOutput

Set the default output of this node.

inline void cowboys::GraphNode::SetDefaultOutput (
    double value
) 

Parameters:

  • value The new default output.

function SetFunctionPointer [1/2]

Set the function pointer of this node.

inline void cowboys::GraphNode::SetFunctionPointer (
    NodeFunction function
) 

Parameters:

  • function The function for this node to use.

function SetFunctionPointer [2/2]

Set the function pointer of this node.

inline void cowboys::GraphNode::SetFunctionPointer (
    InnerFunction inner_function
) 

Parameters:

  • inner_function The inner function for this node to use. Will be wrapped in a NodeFunction.

function SetInputs

Set the input nodes of this node.

inline void cowboys::GraphNode::SetInputs (
    std::vector< std::shared_ptr< GraphNode > > nodes
) 

Parameters:

  • nodes

function ~GraphNode

cowboys::GraphNode::~GraphNode () = default

Protected Attributes Documentation

variable cached_output

double cached_output;

variable cached_output_valid

bool cached_output_valid;

variable default_output

double default_output;

variable function_pointer

NodeFunction function_pointer;

variable inputs

std::vector<std::shared_ptr<GraphNode> > inputs;

variable outputs

std::vector<GraphNode *> outputs;

Protected Functions Documentation

function AddOutput

Add an output node to this node. Used for cache invalidation.

inline void cowboys::GraphNode::AddOutput (
    GraphNode * node
) 

Parameters:

  • node The node to add as an output.

function RecursiveInvalidateCache

inline void cowboys::GraphNode::RecursiveInvalidateCache () const

The documentation for this class was generated from the following file source/Agents/GP/GraphNode.hpp