aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
abstractLeaf.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 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) { GUM_CONSTRUCTOR(AbstractLeaf); }
63 
64  // ###################################################################
65  /// Default destructor
66  // ###################################################################
67  virtual ~AbstractLeaf() {
68  GUM_DESTRUCTOR(AbstractLeaf);
69  ;
70  }
71 
72  // ============================================================================
73  /// Allocators and Deallocators redefinition
74  // ============================================================================
75  void* operator new(size_t s) { return SmallObjectAllocator::instance().allocate(s); }
76  void operator delete(void* p) {
77  SmallObjectAllocator::instance().deallocate(p, sizeof(AbstractLeaf));
78  }
79 
80  /// @}
81 
82  // ###################################################################
83  /// Gaves the leaf effectif for given modality
84  // ###################################################################
85  virtual double effectif(Idx) const = 0;
86  virtual double total() const = 0;
87 
88  // ###################################################################
89  /// Returns true if abstractleaf has leaf in it
90  // ###################################################################
91  virtual bool contains(NodeId testedId) const { return _leafId_ == testedId; }
92 
93  NodeId id() { return _leafId_; }
94 
95  virtual Idx nbModa() const = 0;
96 
97  virtual std::string toString() = 0;
98 
99  private:
101  };
102 
103 
104 } /* namespace gum */
105 
106 
107 #endif // GUM_ABSTRACT_LEAF_H
virtual bool contains(NodeId testedId) const
Returns true if abstractleaf has leaf in it.
Definition: abstractLeaf.h:91
virtual double effectif(Idx) const =0
Gaves the leaf effectif for given modality.
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
void operator delete(void *p)
Default constructor.
Definition: abstractLeaf.h:76
<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:75
virtual double total() const =0
virtual ~AbstractLeaf()
Default destructor.
Definition: abstractLeaf.h:67
AbstractLeaf(NodeId leafId)
Default constructor.
Definition: abstractLeaf.h:62