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