aGrUM  0.14.2
statesChecker.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}@lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
22 
23 
24 namespace gum {
25 
27  __nbVisitedStates(0),
28  __checker(MultiDimFunctionGraph< bool >::getTreeInstance()),
29  __checkerTrueId(0), __checkerFalseId(0) {
30  GUM_CONSTRUCTOR(StatesChecker);
31  }
32 
34  delete __checker;
35  GUM_DESTRUCTOR(StatesChecker);
36  }
37 
38  void StatesChecker::reset(const Instantiation& initialState) {
39  __checker->clear();
41  initialState.variablesSequence().beginSafe();
42  varIter != initialState.variablesSequence().endSafe();
43  ++varIter)
44  __checker->add(**varIter);
45 
49 
50  __insertState(initialState, 0, 0);
51  }
52 
55 
56  NodeId parId = __checker->root();
57  Idx parModa = state.valFromPtr(__checker->node(parId)->nodeVar());
58  while (__checker->node(parId)->son(parModa) != __checkerFalseId) {
59  parId = __checker->node(parId)->son(parModa);
60  parModa = state.valFromPtr(__checker->node(parId)->nodeVar());
61  }
62  __insertState(state, parId, parModa);
63  }
64 
66  NodeId parentId,
67  Idx parentModa) {
68  Idx varIter = 0;
69  if (parentId)
70  varIter =
71  state.variablesSequence().pos(__checker->node(parentId)->nodeVar()) + 1;
72 
73 
74  for (; varIter < state.variablesSequence().size(); ++varIter) {
75  const DiscreteVariable* curVar = state.variablesSequence().atPos(varIter);
76  NodeId varId = __checker->manager()->addInternalNode(curVar);
77  if (parentId)
78  __checker->manager()->setSon(parentId, parentModa, varId);
79  else
80  __checker->manager()->setRootNode(varId);
81  for (Idx moda = 0; moda < curVar->domainSize(); ++moda) {
82  if (moda == state.valFromPtr(curVar))
83  parentModa = moda;
84  else
85  __checker->manager()->setSon(varId, moda, __checkerFalseId);
86  }
87  parentId = varId;
88  }
89  __checker->manager()->setSon(parentId, parentModa, __checkerTrueId);
90  }
91 } // End of namespace gum
Headers of the States Checker class.
Safe iterators for Sequence.
Definition: sequence.h:1203
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.
gum is the global namespace for all aGrUM entities
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:80
void reset(const Instantiation &)
NodeId addTerminalNode(const GUM_SCALAR &value)
Adds a value to the MultiDimFunctionGraph.
Size Idx
Type for indexes.
Definition: types.h:50
<agrum/FMDP/simulation/statesChecker.h>
Definition: statesChecker.h:46
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
MultiDimFunctionGraph< bool > * __checker
Definition: statesChecker.h:85
void clear()
Clears the function graph.
void __insertState(const Instantiation &, NodeId, Idx)