aGrUM 3.3.2
a C++ library for (probabilistic) graphical models
gum::StatesChecker Class Reference

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

#include <statesChecker.h>

Collaboration diagram for gum::StatesChecker:
[legend]

Public Member Functions

Constructor & destructor.
 StatesChecker ()
 Default constructor.
 ~StatesChecker ()
 Default destructor.
Miscelleanous methods
bool checkState (const Instantiation &state)
void addState (const Instantiation &)
Idx nbVisitedStates ()
void reset (const Instantiation &)

Private Member Functions

void _insertState_ (const Instantiation &, NodeId, Idx)

Private Attributes

Idx _nbVisitedStates_
MultiDimFunctionGraph< bool > * _checker_
NodeId _checkerTrueId_
NodeId _checkerFalseId_
Set< Instantiation * > _visitedStates_

Detailed Description

<agrum/FMDP/simulation/statesChecker.h>

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

Definition at line 69 of file statesChecker.h.

Constructor & Destructor Documentation

◆ StatesChecker()

gum::StatesChecker::StatesChecker ( )

Default constructor.

Definition at line 50 of file statesChecker.cpp.

50 :
53 GUM_CONSTRUCTOR(StatesChecker);
54 }
static MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * getTreeInstance()
Returns an arborescent instance.
MultiDimFunctionGraph< bool > * _checker_
StatesChecker()
Default constructor.

References StatesChecker(), _checker_, _checkerFalseId_, _checkerTrueId_, and _nbVisitedStates_.

Referenced by StatesChecker(), and ~StatesChecker().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~StatesChecker()

gum::StatesChecker::~StatesChecker ( )

Default destructor.

Definition at line 56 of file statesChecker.cpp.

56 {
57 delete _checker_;
58 GUM_DESTRUCTOR(StatesChecker);
59 }

References StatesChecker(), and _checker_.

Here is the call graph for this function:

Member Function Documentation

◆ _insertState_()

void gum::StatesChecker::_insertState_ ( const Instantiation & state,
NodeId parentId,
Idx parentModa )
private

Definition at line 88 of file statesChecker.cpp.

88 {
89 Idx varIter = 0;
90 if (parentId) varIter = state.variablesSequence().pos(_checker_->node(parentId)->nodeVar()) + 1;
91
92
93 for (; varIter < state.variablesSequence().size(); ++varIter) {
94 const DiscreteVariable* curVar = state.variablesSequence().atPos(varIter);
95 NodeId varId = _checker_->manager()->addInternalNode(curVar);
96 if (parentId) _checker_->manager()->setSon(parentId, parentModa, varId);
97 else _checker_->manager()->setRootNode(varId);
98 for (Idx moda = 0; moda < curVar->domainSize(); ++moda) {
99 if (moda == state.valFromPtr(curVar)) parentModa = moda;
100 else _checker_->manager()->setSon(varId, moda, _checkerFalseId_);
101 }
102 parentId = varId;
103 }
104 _checker_->manager()->setSon(parentId, parentModa, _checkerTrueId_);
105 }
const DiscreteVariable * nodeVar() const
Returns the node variable.
NodeId addInternalNode(const DiscreteVariable *var)
Inserts a new non terminal node in graph.
void setRootNode(const NodeId &root)
Sets root node of decision diagram.
void setSon(const NodeId &node, const Idx &modality, const NodeId &sonNode)
Sets nodes son for given modality to designated son node.
const InternalNode * node(NodeId n) const
Returns internalNode structure associated to that nodeId.
MultiDimFunctionGraphManager< GUM_ELEMENT, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
Size Idx
Type for indexes.
Definition types.h:79
Size NodeId
Type for node ids.

References _checker_, _checkerFalseId_, _checkerTrueId_, gum::MultiDimFunctionGraphManager< GUM_ELEMENT, TerminalNodePolicy >::addInternalNode(), gum::DiscreteVariable::domainSize(), gum::MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy >::manager(), gum::MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy >::node(), gum::InternalNode::nodeVar(), gum::MultiDimFunctionGraphManager< GUM_ELEMENT, TerminalNodePolicy >::setRootNode(), gum::MultiDimFunctionGraphManager< GUM_ELEMENT, TerminalNodePolicy >::setSon(), gum::Instantiation::valFromPtr(), and gum::Instantiation::variablesSequence().

Referenced by addState(), and reset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addState()

void gum::StatesChecker::addState ( const Instantiation & state)

Definition at line 76 of file statesChecker.cpp.

76 {
78
79 NodeId parId = _checker_->root();
80 Idx parModa = state.valFromPtr(_checker_->node(parId)->nodeVar());
81 while (_checker_->node(parId)->son(parModa) != _checkerFalseId_) {
82 parId = _checker_->node(parId)->son(parModa);
83 parModa = state.valFromPtr(_checker_->node(parId)->nodeVar());
84 }
85 _insertState_(state, parId, parModa);
86 }
NodeId son(Idx modality) const
Returns the son at a given index.
const NodeId & root() const
Returns the id of the root node from the diagram.
void _insertState_(const Instantiation &, NodeId, Idx)

References _checker_, _checkerFalseId_, _insertState_(), _nbVisitedStates_, gum::MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy >::node(), gum::InternalNode::nodeVar(), gum::MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy >::root(), gum::InternalNode::son(), and gum::Instantiation::valFromPtr().

Referenced by gum::E_GreedyDecider::checkState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkState()

INLINE bool gum::StatesChecker::checkState ( const Instantiation & state)

Definition at line 48 of file statesChecker_inl.h.

48 {
49 return _checker_->get(state);
50 }
GUM_ELEMENT get(const Instantiation &i) const override
Returns the value pointed by i.

References _checker_, and gum::MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy >::get().

Referenced by gum::E_GreedyDecider::checkState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nbVisitedStates()

INLINE Idx gum::StatesChecker::nbVisitedStates ( )

Definition at line 52 of file statesChecker_inl.h.

52{ return _nbVisitedStates_; }

References _nbVisitedStates_.

Referenced by gum::E_GreedyDecider::checkState(), and gum::E_GreedyDecider::stateOptimalPolicy().

Here is the caller graph for this function:

◆ reset()

void gum::StatesChecker::reset ( const Instantiation & initialState)

Definition at line 61 of file statesChecker.cpp.

61 {
63 for (SequenceIteratorSafe< const DiscreteVariable* > varIter
64 = initialState.variablesSequence().beginSafe();
65 varIter != initialState.variablesSequence().endSafe();
66 ++varIter)
67 _checker_->add(**varIter);
68
72
73 _insertState_(initialState, 0, 0);
74 }
NodeId addTerminalNode(const GUM_ELEMENT &value)
Adds a value to the MultiDimFunctionGraph.
void clear()
Clears the function graph.
void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.

References _checker_, _checkerFalseId_, _checkerTrueId_, _insertState_(), _nbVisitedStates_, gum::MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy >::add(), gum::MultiDimFunctionGraphManager< GUM_ELEMENT, TerminalNodePolicy >::addTerminalNode(), gum::MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy >::clear(), gum::MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy >::manager(), and gum::Instantiation::variablesSequence().

Referenced by gum::E_GreedyDecider::checkState().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _checker_

MultiDimFunctionGraph< bool >* gum::StatesChecker::_checker_
private

◆ _checkerFalseId_

NodeId gum::StatesChecker::_checkerFalseId_
private

Definition at line 109 of file statesChecker.h.

Referenced by StatesChecker(), _insertState_(), addState(), and reset().

◆ _checkerTrueId_

NodeId gum::StatesChecker::_checkerTrueId_
private

Definition at line 109 of file statesChecker.h.

Referenced by StatesChecker(), _insertState_(), and reset().

◆ _nbVisitedStates_

Idx gum::StatesChecker::_nbVisitedStates_
private

Definition at line 106 of file statesChecker.h.

Referenced by StatesChecker(), addState(), nbVisitedStates(), and reset().

◆ _visitedStates_

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

Definition at line 111 of file statesChecker.h.


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