aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
composedLeaf.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_COMPOSED_LEAF_H
31 #define GUM_COMPOSED_LEAF_H
32 // =========================================================================
33 #include <agrum/FMDP/learning/datastructure/leaves/abstractLeaf.h>
34 // =========================================================================
35 
36 namespace gum {
37 
38  /**
39  * @class ComposedLeaf composedLeaf.h
40  * <agrum/FMDP/learning/datastructure/leaves/composedLeaf.h>
41  * @brief A leaf that has leaves inside
42  * @ingroup fmdp_group
43  *
44  */
45 
46 
47  class ComposedLeaf: public AbstractLeaf {
48  public:
49  // ==========================================================================
50  /// @name Constructor & destructor.
51  // ==========================================================================
52  /// @{
53 
54  // ###################################################################
55  /// Default constructor
56  // ###################################################################
57  ComposedLeaf(NodeId leafId, AbstractLeaf* l1, AbstractLeaf* l2) :
59  GUM_CONSTRUCTOR(ComposedLeaf);
60  }
61 
62  // ###################################################################
63  /// Default destructor
64  // ###################################################################
65  ~ComposedLeaf() { GUM_DESTRUCTOR(ComposedLeaf); }
66 
67  // ============================================================================
68  /// Allocators and Deallocators redefinition
69  // ============================================================================
70  void* operator new(size_t s) {
71  return SmallObjectAllocator::instance().allocate(s);
72  }
73  void operator delete(void* p) {
74  SmallObjectAllocator::instance().deallocate(p, sizeof(ComposedLeaf));
75  }
76 
77  /// @}
78 
79  // ###################################################################
80  /// Gaves the leaf effectif for given modality
81  // ###################################################################
82  double effectif(Idx moda) const {
83  return l1__->effectif(moda) + l2__->effectif(moda);
84  }
85  double total() const { return l1__->total() + l2__->total(); }
86 
87  // ###################################################################
88  /// Returns true if abstractleaf has leaf in it
89  // ###################################################################
90  bool contains(NodeId testedId) const {
91  return AbstractLeaf::contains(testedId) || l1__->contains(testedId)
92  || l2__->contains(testedId);
93  }
94 
95  Idx nbModa() const { return l1__->nbModa(); }
96 
97  std::string toString();
98 
99  private:
102  };
103 
104 
105 } /* namespace gum */
106 
107 
108 #endif // GUM_COMPOSED_LEAF_H
Idx nbModa() const
Definition: composedLeaf.h:95
double effectif(Idx moda) const
Gaves the leaf effectif for given modality.
Definition: composedLeaf.h:82
void operator delete(void *p)
Default constructor.
Definition: composedLeaf.h:73
AbstractLeaf * l2__
Definition: composedLeaf.h:101
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
std::string toString()
bool contains(NodeId testedId) const
Returns true if abstractleaf has leaf in it.
Definition: composedLeaf.h:90
~ComposedLeaf()
Default destructor.
Definition: composedLeaf.h:65
double total() const
Definition: composedLeaf.h:85
ComposedLeaf(NodeId leafId, AbstractLeaf *l1, AbstractLeaf *l2)
Default constructor.
Definition: composedLeaf.h:57
void * operator new(size_t s)
Allocators and Deallocators redefinition.
Definition: composedLeaf.h:70
<agrum/FMDP/learning/datastructure/leaves/composedLeaf.h>
Definition: composedLeaf.h:47
AbstractLeaf * l1__
Definition: composedLeaf.h:100