aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::StatesCounter Class Reference

<agrum/FMDP/simulation/statesCounter.h> More...

#include <statesCounter.h>

+ Inheritance diagram for gum::StatesCounter:
+ Collaboration diagram for gum::StatesCounter:

Public Member Functions

Constructor & destructor.
 StatesCounter ()
 Default constructor. More...
 
 ~StatesCounter ()
 Default destructor. More...
 
Miscelleanous methods
void incState (const Instantiation &)
 
void reset (const Instantiation &)
 
const MultiDimFunctionGraph< int > * counter ()
 
Visit Methods
NodeId root () const
 
bool isTerminal (NodeId ni) const
 
const DiscreteVariablenodeVar (NodeId ni) const
 
NodeId nodeSon (NodeId ni, Idx modality) const
 
Idx nodeNbObservation (NodeId ni) const
 
void insertSetOfVars (MultiDimFunctionGraph< double > *ret) const
 

Detailed Description

<agrum/FMDP/simulation/statesCounter.h>

Provides the necessary to check whether or not states have been already visited.

Definition at line 51 of file statesCounter.h.

Constructor & Destructor Documentation

◆ StatesCounter()

gum::StatesCounter::StatesCounter ( )

Default constructor.

Definition at line 31 of file statesCounter.cpp.

References gum::Set< Key, Alloc >::emplace().

32  GUM_CONSTRUCTOR(StatesCounter);
33  }
MultiDimFunctionGraph< Size > * _counter_
static MultiDimFunctionGraph< Size, ExactTerminalNodePolicy > * getTreeInstance()
Returns an arborescent instance.
StatesCounter()
Default constructor.
+ Here is the call graph for this function:

◆ ~StatesCounter()

gum::StatesCounter::~StatesCounter ( )

Default destructor.

Definition at line 39 of file statesCounter.cpp.

References gum::Set< Key, Alloc >::emplace().

39  {
40  delete _counter_;
41  GUM_DESTRUCTOR(StatesCounter);
42  }
MultiDimFunctionGraph< Size > * _counter_
StatesCounter()
Default constructor.
+ Here is the call graph for this function:

Member Function Documentation

◆ _incState_()

void gum::StatesCounter::_incState_ ( const Instantiation state,
NodeId  parentId,
Idx  parentModa,
Size  nbVisits 
)
private

Definition at line 81 of file statesCounter.cpp.

References gum::Set< Key, Alloc >::emplace().

84  {
85  Idx varIter = 0;
86  if (parentId) varIter = state.variablesSequence().pos(_counter_->node(parentId)->nodeVar()) + 1;
87 
88 
89  for (; varIter < state.variablesSequence().size(); ++varIter) {
90  const DiscreteVariable* curVar = state.variablesSequence().atPos(varIter);
91  NodeId varId = _counter_->manager()->addInternalNode(curVar);
92  if (parentId)
93  _counter_->manager()->setSon(parentId, parentModa, varId);
94  else
95  _counter_->manager()->setRootNode(varId);
96  for (Idx moda = 0; moda < curVar->domainSize(); ++moda) {
97  if (moda == state.valFromPtr(curVar))
98  parentModa = moda;
99  else
100  _counter_->manager()->setSon(varId, moda, _counter_->terminalNodeId(nbVisits));
101  }
102  parentId = varId;
103  }
104  _counter_->manager()->setSon(parentId,
105  parentModa,
106  _counter_->manager()->addTerminalNode(nbVisits + 1));
107  }
void setSon(const NodeId &node, const Idx &modality, const NodeId &sonNode)
Sets nodes son for given modality to designated son node.
void setRootNode(const NodeId &root)
Sets root node of decision diagram.
const InternalNode * node(NodeId n) const
Returns internalNode structure associated to that nodeId.
const DiscreteVariable * nodeVar() const
Returns the node variable.
const NodeId & terminalNodeId(const GUM_SCALAR &v) const
Returns the id of the terminal node that has the given value.
NodeId addInternalNode(const DiscreteVariable *var)
Inserts a new non terminal node in graph.
MultiDimFunctionGraph< Size > * _counter_
NodeId addTerminalNode(const GUM_SCALAR &value)
Adds a value to the MultiDimFunctionGraph.
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ counter()

const MultiDimFunctionGraph< int >* gum::StatesCounter::counter ( )

◆ incState()

void gum::StatesCounter::incState ( const Instantiation state)

Definition at line 65 of file statesCounter.cpp.

References gum::Set< Key, Alloc >::emplace().

65  {
66  Idx nbVisits = _counter_->get(state);
67 
68  NodeId parId = _counter_->root();
69  Idx parModa = state.valFromPtr(_counter_->node(parId)->nodeVar());
70  while (!_counter_->isTerminalNode(_counter_->node(parId)->son(parModa))) {
71  parId = _counter_->node(parId)->son(parModa);
72  parModa = state.valFromPtr(_counter_->node(parId)->nodeVar());
73  }
74  _incState_(state, parId, parModa, nbVisits);
75  }
bool isTerminalNode(const NodeId &node) const
Indicates if given node is terminal or not.
const InternalNode * node(NodeId n) const
Returns internalNode structure associated to that nodeId.
const DiscreteVariable * nodeVar() const
Returns the node variable.
NodeId son(Idx modality) const
Returns the son at a given index.
MultiDimFunctionGraph< Size > * _counter_
const NodeId & root() const
Returns the id of the root node from the diagram.
virtual GUM_SCALAR get(const Instantiation &i) const
Returns the value pointed by i.
void _incState_(const Instantiation &, NodeId, Idx, Size)
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ insertSetOfVars()

void gum::StatesCounter::insertSetOfVars ( MultiDimFunctionGraph< double > *  ret) const
inlinevirtual

Implements gum::IVisitableGraphLearner.

Definition at line 114 of file statesCounter.h.

114  {
115  for (SequenceIteratorSafe< const DiscreteVariable* > varIter
116  = _counter_->variablesSequence().beginSafe();
117  varIter != _counter_->variablesSequence().endSafe();
118  ++varIter)
119  ret->add(**varIter);
120  }
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
MultiDimFunctionGraph< Size > * _counter_
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.

◆ isTerminal()

bool gum::StatesCounter::isTerminal ( NodeId  ni) const
inlinevirtual

Implements gum::IVisitableGraphLearner.

Definition at line 97 of file statesCounter.h.

97 { return _counter_->isTerminalNode(ni); }
bool isTerminalNode(const NodeId &node) const
Indicates if given node is terminal or not.
MultiDimFunctionGraph< Size > * _counter_

◆ nodeNbObservation()

Idx gum::StatesCounter::nodeNbObservation ( NodeId  ni) const
inlinevirtual

Implements gum::IVisitableGraphLearner.

Definition at line 112 of file statesCounter.h.

112 { return _counter_->nodeValue(ni); }
const GUM_SCALAR & nodeValue(NodeId n) const
Returns value associated to given node.
MultiDimFunctionGraph< Size > * _counter_

◆ nodeSon()

NodeId gum::StatesCounter::nodeSon ( NodeId  ni,
Idx  modality 
) const
inlinevirtual

Implements gum::IVisitableGraphLearner.

Definition at line 107 of file statesCounter.h.

107 { return _counter_->node(ni)->son(modality); }
const InternalNode * node(NodeId n) const
Returns internalNode structure associated to that nodeId.
NodeId son(Idx modality) const
Returns the son at a given index.
MultiDimFunctionGraph< Size > * _counter_

◆ nodeVar()

const DiscreteVariable* gum::StatesCounter::nodeVar ( NodeId  ni) const
inlinevirtual

Implements gum::IVisitableGraphLearner.

Definition at line 102 of file statesCounter.h.

102 { return _counter_->node(ni)->nodeVar(); }
const InternalNode * node(NodeId n) const
Returns internalNode structure associated to that nodeId.
const DiscreteVariable * nodeVar() const
Returns the node variable.
MultiDimFunctionGraph< Size > * _counter_

◆ reset()

void gum::StatesCounter::reset ( const Instantiation initialState)

Definition at line 48 of file statesCounter.cpp.

References gum::Set< Key, Alloc >::emplace().

48  {
49  _counter_->clear();
50  for (SequenceIteratorSafe< const DiscreteVariable* > varIter
51  = initialState.variablesSequence().beginSafe();
52  varIter != initialState.variablesSequence().endSafe();
53  ++varIter)
54  _counter_->add(**varIter);
55 
57 
58  _incState_(initialState, 0, 0, 0);
59  }
void setRootNode(const NodeId &root)
Sets root node of decision diagram.
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
MultiDimFunctionGraph< Size > * _counter_
NodeId addTerminalNode(const GUM_SCALAR &value)
Adds a value to the MultiDimFunctionGraph.
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
void _incState_(const Instantiation &, NodeId, Idx, Size)
void clear()
Clears the function graph.
+ Here is the call graph for this function:

◆ root()

NodeId gum::StatesCounter::root ( ) const
inlinevirtual

Implements gum::IVisitableGraphLearner.

Definition at line 92 of file statesCounter.h.

92 { return _counter_->root(); }
MultiDimFunctionGraph< Size > * _counter_
const NodeId & root() const
Returns the id of the root node from the diagram.

Member Data Documentation

◆ _counter_

MultiDimFunctionGraph< Size >* gum::StatesCounter::_counter_
private

Definition at line 128 of file statesCounter.h.

◆ _visitedStates_

Set< Instantiation* > gum::StatesCounter::_visitedStates_
private

Definition at line 130 of file statesCounter.h.


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