aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
abstractLeaf.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 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 abstract Leaf class.
25  *
26  * @author Jean-Christophe MAGNAN
27  */
28 
29 // =========================================================================
30 #ifndef GUM_ABSTRACT_LEAF_H
31 #define GUM_ABSTRACT_LEAF_H
32 // =========================================================================
33 #include <agrum/tools/core/hashTable.h>
34 #include <agrum/tools/core/multiPriorityQueue.h>
35 #include <agrum/tools/core/sequence.h>
36 #include <agrum/tools/core/smallobjectallocator/smallObjectAllocator.h>
37 // =========================================================================
38 #include <agrum/tools/graphs/graphElements.h>
39 // =========================================================================
40 
41 namespace gum {
42 
43  /**
44  * @class AbstractLeaf abstractLeaf.h
45  * <agrum/FMDP/learning/datastructure/leaves/abstractLeaf.h>
46  * @brief Abstract Class implementing a Leaf
47  * @ingroup fmdp_group
48  *
49  */
50 
51 
52  class AbstractLeaf {
53  public:
54  // ==========================================================================
55  /// @name Constructor & destructor.
56  // ==========================================================================
57  /// @{
58 
59  // ###################################################################
60  /// Default constructor
61  // ###################################################################
62  AbstractLeaf(NodeId leafId) : leafId__(leafId) {
63  GUM_CONSTRUCTOR(AbstractLeaf);
64  }
65 
66  // ###################################################################
67  /// Default destructor
68  // ###################################################################
69  virtual ~AbstractLeaf() { GUM_DESTRUCTOR(AbstractLeaf); }
70 
71  // ============================================================================
72  /// Allocators and Deallocators redefinition
73  // ============================================================================
74  void* operator new(size_t s) {
75  return SmallObjectAllocator::instance().allocate(s);
76  }
77  void operator delete(void* p) {
78  SmallObjectAllocator::instance().deallocate(p, sizeof(AbstractLeaf));
79  }
80 
81  /// @}
82 
83  // ###################################################################
84  /// Gaves the leaf effectif for given modality
85  // ###################################################################
86  virtual double effectif(Idx) const = 0;
87  virtual double total() const = 0;
88 
89  // ###################################################################
90  /// Returns true if abstractleaf has leaf in it
91  // ###################################################################
92  virtual bool contains(NodeId testedId) const { return leafId__ == testedId; }
93 
94  NodeId id() { return leafId__; }
95 
96  virtual Idx nbModa() const = 0;
97 
98  virtual std::string toString() = 0;
99 
100  private:
102  };
103 
104 
105 } /* namespace gum */
106 
107 
108 #endif // GUM_ABSTRACT_LEAF_H
virtual bool contains(NodeId testedId) const
Returns true if abstractleaf has leaf in it.
Definition: abstractLeaf.h:92
virtual double effectif(Idx) const =0
Gaves the leaf effectif for given modality.
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
void operator delete(void *p)
Default constructor.
Definition: abstractLeaf.h:77
<agrum/FMDP/learning/datastructure/leaves/abstractLeaf.h>
Definition: abstractLeaf.h:52
virtual std::string toString()=0
virtual Idx nbModa() const =0
void * operator new(size_t s)
Allocators and Deallocators redefinition.
Definition: abstractLeaf.h:74
virtual double total() const =0
virtual ~AbstractLeaf()
Default destructor.
Definition: abstractLeaf.h:69
AbstractLeaf(NodeId leafId)
Default constructor.
Definition: abstractLeaf.h:62