aGrUM  0.16.0
statesChecker.cpp
Go to the documentation of this file.
1 
24 
25 
26 namespace gum {
27 
29  __nbVisitedStates(0),
30  __checker(MultiDimFunctionGraph< bool >::getTreeInstance()),
31  __checkerTrueId(0), __checkerFalseId(0) {
32  GUM_CONSTRUCTOR(StatesChecker);
33  }
34 
36  delete __checker;
37  GUM_DESTRUCTOR(StatesChecker);
38  }
39 
40  void StatesChecker::reset(const Instantiation& initialState) {
41  __checker->clear();
43  initialState.variablesSequence().beginSafe();
44  varIter != initialState.variablesSequence().endSafe();
45  ++varIter)
46  __checker->add(**varIter);
47 
51 
52  __insertState(initialState, 0, 0);
53  }
54 
57 
58  NodeId parId = __checker->root();
59  Idx parModa = state.valFromPtr(__checker->node(parId)->nodeVar());
60  while (__checker->node(parId)->son(parModa) != __checkerFalseId) {
61  parId = __checker->node(parId)->son(parModa);
62  parModa = state.valFromPtr(__checker->node(parId)->nodeVar());
63  }
64  __insertState(state, parId, parModa);
65  }
66 
68  NodeId parentId,
69  Idx parentModa) {
70  Idx varIter = 0;
71  if (parentId)
72  varIter =
73  state.variablesSequence().pos(__checker->node(parentId)->nodeVar()) + 1;
74 
75 
76  for (; varIter < state.variablesSequence().size(); ++varIter) {
77  const DiscreteVariable* curVar = state.variablesSequence().atPos(varIter);
78  NodeId varId = __checker->manager()->addInternalNode(curVar);
79  if (parentId)
80  __checker->manager()->setSon(parentId, parentModa, varId);
81  else
82  __checker->manager()->setRootNode(varId);
83  for (Idx moda = 0; moda < curVar->domainSize(); ++moda) {
84  if (moda == state.valFromPtr(curVar))
85  parentModa = moda;
86  else
87  __checker->manager()->setSon(varId, moda, __checkerFalseId);
88  }
89  parentId = varId;
90  }
91  __checker->manager()->setSon(parentId, parentModa, __checkerTrueId);
92  }
93 } // End of namespace gum
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Safe iterators for Sequence.
Definition: sequence.h:1206
void setSon(const NodeId &node, const Idx &modality, const NodeId &sonNode)
Sets nodes son for given modality to designated son node.
Idx valFromPtr(const DiscreteVariable *pvar) const
Returns the current value of a given variable.
void setRootNode(const NodeId &root)
Sets root node of decision diagram.
~StatesChecker()
Default destructor.
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.
NodeId addInternalNode(const DiscreteVariable *var)
Inserts a new non terminal node in graph.
Base class for discrete random variable.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
const Sequence< const DiscreteVariable *> & variablesSequence() const final
Returns the sequence of DiscreteVariable of this instantiation.
void addState(const Instantiation &)
virtual Size domainSize() const =0
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
StatesChecker()
Default constructor.
const NodeId & root() const
Returns the id of the root node from the diagram.
Class implementingting a function graph.
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:83
void reset(const Instantiation &)
NodeId addTerminalNode(const GUM_SCALAR &value)
Adds a value to the MultiDimFunctionGraph.
Size Idx
Type for indexes.
Definition: types.h:53
<agrum/FMDP/simulation/statesChecker.h>
Definition: statesChecker.h:49
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
MultiDimFunctionGraph< bool > * __checker
Definition: statesChecker.h:88
void clear()
Clears the function graph.
void __insertState(const Instantiation &, NodeId, Idx)