1 /**
2  *
3  *   Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(_at_LIP6) & Christophe GONZALES(_at_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(_at_LIP6) and Jean-Christophe MAGNAN and Christophe
27  * GONZALES(_at_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    */
51   class StatesCounter: public IVisitableGraphLearner {
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     // ==========================================================================
root()92     NodeId root() const { return _counter_->root(); }
93 
94     // ==========================================================================
95     ///
96     // ==========================================================================
isTerminal(NodeId ni)97     bool isTerminal(NodeId ni) const { return _counter_->isTerminalNode(ni); }
98 
99     // ==========================================================================
100     ///
101     // ==========================================================================
nodeVar(NodeId ni)102     const DiscreteVariable* nodeVar(NodeId ni) const { return _counter_->node(ni)->nodeVar(); }
103 
104     // ==========================================================================
105     ///
106     // ==========================================================================
nodeSon(NodeId ni,Idx modality)107     NodeId nodeSon(NodeId ni, Idx modality) const { return _counter_->node(ni)->son(modality); }
108 
109     // ==========================================================================
110     ///
111     // ==========================================================================
nodeNbObservation(NodeId ni)112     Idx nodeNbObservation(NodeId ni) const { return _counter_->nodeValue(ni); }
113 
insertSetOfVars(MultiDimFunctionGraph<double> * ret)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 
128     MultiDimFunctionGraph< Size >* _counter_;
129 
130     Set< Instantiation* > _visitedStates_;
131   };
132 } /* namespace gum */
133 
134 #endif   // GUM_STATES_COUNTER_H
135