aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
statesCounter.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Headers of the States Counter class.
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and Christophe
27  * GONZALES(@AMU)
28  */
29 
30 // =========================================================================
31 #ifndef GUM_STATES_COUNTER_H
32 #define GUM_STATES_COUNTER_H
33 // =========================================================================
34 #include <agrum/tools/core/sequence.h>
35 // =========================================================================
36 #include <agrum/FMDP/learning/datastructure/IVisitableGraphLearner.h>
37 // =========================================================================
38 #include <agrum/tools/multidim/implementations/multiDimFunctionGraph.h>
39 // =========================================================================
40 
41 namespace gum {
42 
43 
44  /**
45  * @class StatesCounter statesCounter.h
46  * <agrum/FMDP/simulation/statesCounter.h>
47  * @brief Provides the necessary to check whether or not states have been
48  * already visited.
49  * @ingroup fmdp_group
50  */
52  public:
53  // ==========================================================================
54  /// @name Constructor & destructor.
55  // ==========================================================================
56  /// @{
57 
58  /**
59  * Default constructor
60  */
61  StatesCounter();
62 
63  /**
64  * Default destructor
65  */
66  ~StatesCounter();
67 
68  /// @}
69 
70  // ==========================================================================
71  /// @name Miscelleanous methods
72  // ==========================================================================
73  /// @{
74 
75  void incState(const Instantiation&);
76 
77  void reset(const Instantiation&);
78 
79  const MultiDimFunctionGraph< int >* counter();
80 
81  /// @}
82 
83 
84  // ###################################################################
85  /// @name Visit Methods
86  // ###################################################################
87  /// @{
88  public:
89  // ==========================================================================
90  ///
91  // ==========================================================================
92  NodeId root() const { return _counter_->root(); }
93 
94  // ==========================================================================
95  ///
96  // ==========================================================================
97  bool isTerminal(NodeId ni) const { return _counter_->isTerminalNode(ni); }
98 
99  // ==========================================================================
100  ///
101  // ==========================================================================
102  const DiscreteVariable* nodeVar(NodeId ni) const { return _counter_->node(ni)->nodeVar(); }
103 
104  // ==========================================================================
105  ///
106  // ==========================================================================
107  NodeId nodeSon(NodeId ni, Idx modality) const { return _counter_->node(ni)->son(modality); }
108 
109  // ==========================================================================
110  ///
111  // ==========================================================================
112  Idx nodeNbObservation(NodeId ni) const { return _counter_->nodeValue(ni); }
113 
114  void insertSetOfVars(MultiDimFunctionGraph< double >* ret) const {
115  for (SequenceIteratorSafe< const DiscreteVariable* > varIter
116  = _counter_->variablesSequence().beginSafe();
117  varIter != _counter_->variablesSequence().endSafe();
118  ++varIter)
119  ret->add(**varIter);
120  }
121 
122 
123  /// @}
124 
125  private:
126  void _incState_(const Instantiation&, NodeId, Idx, Size);
127 
129 
131  };
132 } /* namespace gum */
133 
134 #endif // GUM_STATES_COUNTER_H
NodeId root() const
Definition: statesCounter.h:92
<agrum/FMDP/simulation/statesCounter.h>
Definition: statesCounter.h:51
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
void insertSetOfVars(MultiDimFunctionGraph< double > *ret) const
const MultiDimFunctionGraph< int > * counter()
Idx nodeNbObservation(NodeId ni) const
Set< Instantiation *> _visitedStates_
MultiDimFunctionGraph< Size > * _counter_
const DiscreteVariable * nodeVar(NodeId ni) const
~StatesCounter()
Default destructor.
void reset(const Instantiation &)
NodeId nodeSon(NodeId ni, Idx modality) const
void incState(const Instantiation &)
StatesCounter()
Default constructor.
void _incState_(const Instantiation &, NodeId, Idx, Size)
bool isTerminal(NodeId ni) const
Definition: statesCounter.h:97