The Gaudi Framework  v29r0 (ff2e7097)
concurrency::recursive_CF::DecisionNode Class Reference

#include <src/ControlFlowGraph.h>

Inheritance diagram for concurrency::recursive_CF::DecisionNode:
Collaboration diagram for concurrency::recursive_CF::DecisionNode:

Public Member Functions

 DecisionNode (ControlFlowGraph &graph, unsigned int nodeIndex, const std::string &name, bool modeConcurrent, bool modePromptDecision, bool modeOR, bool allPass)
 Constructor. More...
 
 ~DecisionNode () override
 Destructor. More...
 
void initialize (const std::unordered_map< std::string, unsigned int > &algname_index_map) override
 Initialize. More...
 
int updateState (AlgsExecutionStates &states, std::vector< int > &node_decisions) const override
 Method to set algos to CONTROLREADY, if possible. More...
 
void addDaughterNode (ControlFlowNode *node)
 Add a daughter node. More...
 
const std::vector< ControlFlowNode * > & getDaughters () const
 
void printState (std::stringstream &output, AlgsExecutionStates &states, const std::vector< int > &node_decisions, const unsigned int &recursionLevel) const override
 Print a string representing the control flow state. More...
 
- Public Member Functions inherited from concurrency::recursive_CF::ControlFlowNode
 ControlFlowNode (ControlFlowGraph &graph, unsigned int nodeIndex, const std::string &name)
 Constructor. More...
 
virtual ~ControlFlowNode ()
 Destructor. More...
 
const unsigned int & getNodeIndex () const
 Get node index. More...
 
const std::stringgetNodeName () const
 Get node name. More...
 

Public Attributes

bool m_modeConcurrent
 Whether all daughters will be evaluated concurrently or sequentially. More...
 
bool m_modePromptDecision
 Whether to evaluate the hub decision ASA its child decisions allow to do that. More...
 
bool m_modeOR
 Whether acting as "and" (false) or "or" node (true) More...
 
bool m_allPass
 Whether always passing regardless of daughter results. More...
 
- Public Attributes inherited from concurrency::recursive_CF::ControlFlowNode
ControlFlowGraphm_graph
 

Private Attributes

std::vector< ControlFlowNode * > m_children
 All direct daughter nodes in the tree. More...
 

Additional Inherited Members

- Protected Member Functions inherited from concurrency::recursive_CF::ControlFlowNode
std::string stateToString (const int &stateId) const
 Translation between state id and name. More...
 
- Protected Attributes inherited from concurrency::recursive_CF::ControlFlowNode
unsigned int m_nodeIndex
 
std::string m_nodeName
 

Detailed Description

Definition at line 57 of file ControlFlowGraph.h.

Constructor & Destructor Documentation

concurrency::recursive_CF::DecisionNode::DecisionNode ( ControlFlowGraph graph,
unsigned int  nodeIndex,
const std::string name,
bool  modeConcurrent,
bool  modePromptDecision,
bool  modeOR,
bool  allPass 
)
inline

Constructor.

Definition at line 61 of file ControlFlowGraph.h.

63  : ControlFlowNode( graph, nodeIndex, name )
64  , m_modeConcurrent( modeConcurrent )
65  , m_modePromptDecision( modePromptDecision )
66  , m_modeOR( modeOR )
67  , m_allPass( allPass )
68  , m_children()
69  {
70  }
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
bool m_allPass
Whether always passing regardless of daughter results.
ControlFlowNode(ControlFlowGraph &graph, unsigned int nodeIndex, const std::string &name)
Constructor.
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
bool m_modeConcurrent
Whether all daughters will be evaluated concurrently or sequentially.
concurrency::recursive_CF::DecisionNode::~DecisionNode ( )
override

Destructor.

Definition at line 23 of file ControlFlowGraph.cpp.

24  {
25 
26  for ( auto node : m_children ) delete node;
27  }
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.

Member Function Documentation

void concurrency::recursive_CF::DecisionNode::addDaughterNode ( ControlFlowNode node)

Add a daughter node.

Definition at line 37 of file ControlFlowGraph.cpp.

38  {
39 
40  if ( std::find( m_children.begin(), m_children.end(), node ) == m_children.end() ) m_children.push_back( node );
41  }
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
T find(T...args)
const std::vector<ControlFlowNode*>& concurrency::recursive_CF::DecisionNode::getDaughters ( ) const
inline

Definition at line 80 of file ControlFlowGraph.h.

80 { return m_children; }
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
void concurrency::recursive_CF::DecisionNode::initialize ( const std::unordered_map< std::string, unsigned int > &  algname_index_map)
overridevirtual

Initialize.

Implements concurrency::recursive_CF::ControlFlowNode.

Definition at line 30 of file ControlFlowGraph.cpp.

31  {
32 
33  for ( auto daughter : m_children ) daughter->initialize( algname_index_map );
34  }
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
void concurrency::recursive_CF::DecisionNode::printState ( std::stringstream output,
AlgsExecutionStates states,
const std::vector< int > &  node_decisions,
const unsigned int &  recursionLevel 
) const
overridevirtual

Print a string representing the control flow state.

Implements concurrency::recursive_CF::ControlFlowNode.

Definition at line 44 of file ControlFlowGraph.cpp.

46  {
47 
48  output << std::string( recursionLevel, ' ' ) << m_nodeName << " (" << m_nodeIndex << ")"
49  << ", w/ decision: " << stateToString( node_decisions[m_nodeIndex] ) << "(" << node_decisions[m_nodeIndex]
50  << ")" << std::endl;
51  for ( auto daughter : m_children ) {
52  daughter->printState( output, states, node_decisions, recursionLevel + 2 );
53  }
54  }
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
std::string stateToString(const int &stateId) const
Translation between state id and name.
T endl(T...args)
STL class.
int concurrency::recursive_CF::DecisionNode::updateState ( AlgsExecutionStates states,
std::vector< int > &  node_decisions 
) const
overridevirtual

Method to set algos to CONTROLREADY, if possible.

Implements concurrency::recursive_CF::ControlFlowNode.

Definition at line 57 of file ControlFlowGraph.cpp.

58  {
59  // check whether we already had a result earlier
60  // if (-1 != node_decisions[m_nodeIndex] ) { return node_decisions[m_nodeIndex]; }
61  int decision = ( ( m_allPass && m_modePromptDecision ) ? 1 : -1 );
62  bool hasUndecidedChild = false;
63  for ( auto daughter : m_children ) {
64  if ( m_modePromptDecision && ( -1 != decision || hasUndecidedChild ) ) {
65  node_decisions[m_nodeIndex] = decision;
66  return decision;
67  } // if prompt decision, return once result is known already or we can't
68  // fully evaluate right now because one daugther decision is missing still
69  auto res = daughter->updateState( states, node_decisions );
70  if ( -1 == res ) {
71  hasUndecidedChild = true;
72  } else if ( false == m_modeOR && res == 0 ) {
73  decision = 0;
74  } // "and"-mode (once first result false, the overall decision is false)
75  else if ( true == m_modeOR && res == 1 ) {
76  decision = 1;
77  } // "or"-mode (once first result true, the overall decision is true)
78  }
79  // what to do with yet undefined answers depends on whether AND or OR mode applies
80  if ( !hasUndecidedChild && -1 == decision ) {
81  // OR mode: all results known, and none true -> reject
82  if ( true == m_modeOR ) {
83  decision = 0;
84  }
85  // AND mode: all results known, and no false -> accept
86  else {
87  decision = 1;
88  }
89  }
90  // in all other cases I stay with previous decisions
91  node_decisions[m_nodeIndex] = decision;
92  if ( m_allPass ) decision = 1;
93  return decision;
94  }
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
bool m_allPass
Whether always passing regardless of daughter results.
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)

Member Data Documentation

bool concurrency::recursive_CF::DecisionNode::m_allPass

Whether always passing regardless of daughter results.

Definition at line 94 of file ControlFlowGraph.h.

std::vector<ControlFlowNode*> concurrency::recursive_CF::DecisionNode::m_children
private

All direct daughter nodes in the tree.

Definition at line 98 of file ControlFlowGraph.h.

bool concurrency::recursive_CF::DecisionNode::m_modeConcurrent

Whether all daughters will be evaluated concurrently or sequentially.

Definition at line 87 of file ControlFlowGraph.h.

bool concurrency::recursive_CF::DecisionNode::m_modeOR

Whether acting as "and" (false) or "or" node (true)

Definition at line 92 of file ControlFlowGraph.h.

bool concurrency::recursive_CF::DecisionNode::m_modePromptDecision

Whether to evaluate the hub decision ASA its child decisions allow to do that.

Applicable to both concurrent and sequential cases.

Definition at line 90 of file ControlFlowGraph.h.


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