aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
o4DGContext.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 Class used to manipulate o4DGContext in Function Graph Operations
25  *
26  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27  * @author Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and Christophe
28  * GONZALES(@AMU)
29  */
30 
31 #ifndef O4DGCONTEXT_H
32 #define O4DGCONTEXT_H
33 
34 #include <agrum/agrum.h>
35 #include <agrum/tools/core/math/math_utils.h>
36 #include <agrum/tools/multidim/implementations/multiDimFunctionGraph.h>
37 
38 namespace gum {
39 
40  // clang-format off
41  /**
42  * @class O4DGContext
43  * @headerfile o4DGContext.h <agrum/tools/multidim/FunctionGraphUtilities/o4DGContext.h>
44  * @ingroup multidim_group
45  *
46  * @brief Class used to manipulate context during Function Graph Operations
47  */
48  // clang-format on
49  class O4DGContext {
50  public:
51  // ============================================================================
52  /// @name Constructors, Destructors.
53  // ============================================================================
54  /// @{
55 
56  /**
57  * @brief Default constructor.
58  */
59  O4DGContext(Idx*, Idx);
60 
61  /**
62  * @brief Default destructor.
63  */
64  ~O4DGContext();
65 
66  /**
67  * @brief Operator new overload to use the SmallObjectAllocator
68  */
69  void* operator new(size_t s);
70 
71  /**
72  * @brief Operator delete overload to use the SmallObjectAllocator
73  */
74  void operator delete(void* p);
75  /// @}
76 
77  // ============================================================================
78  /// @name Diagrams current nodes setters & getters.
79  // ============================================================================
80 
81  /// @{
82  /// Set DG1 diagram current explored Node
83  void setDG1Node(const NodeId&);
84 
85  /// Get DG1 diagram current explored Node
86  const NodeId& DG1Node() const { return _DG1ExploredNode_; }
87 
88  /// Set DG2 diagram current explored Node
89  void setDG2Node(const NodeId&);
90 
91  /// Get DG2 diagram current explored Node
92  const NodeId& DG2Node() const { return _DG2ExploredNode_; }
93  /// @}
94 
95  // ============================================================================
96  /// @name Variables modalities handlers
97  // ============================================================================
98  /// @{
99 
100  /// Changes given variable modality
101  void chgVarModality(Idx, Idx);
102 
103  /// Changes given variable modality
105 
106  /// @}
107  // ============================================================================
108  /// @name O4DG Handling methods
109  // ============================================================================
110  /// @{
111 
112  /// Returns o4DGContext key
113  const double& key(short int* instNeeded);
114 
115  /// @}
116 
117  private:
118  /// DG1 Diagram current explored node
120 
121  /// DG2 Diagram current explored node
123 
124  /// Vector containing for each retrograde variable its current modality
125  /// 0 meaning no instantiation done => there's an offset
128 
129  /// The key use to store the context as a key in the hashtable
130  double _key_;
131 
132  /// Table containing the log2 of prime numbers
133  static const double _logPrime_[];
135  };
136 } // namespace gum
137 
138 #ifndef GUM_NO_INLINE
139 # include <agrum/tools/multidim/utils/FunctionGraphUtilities/operators/o4DGContext_inl.h>
140 #endif /* GUM_NO_INLINE */
141 
142 #endif // O4DGCONTEXT_H
const NodeId & DG2Node() const
Get DG2 diagram current explored Node.
Definition: o4DGContext.h:92
void * operator new(size_t s)
Operator new overload to use the SmallObjectAllocator.
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
const double & key(short int *instNeeded)
Returns o4DGContext key.
void chgVarModality(Idx, Idx)
Changes given variable modality.
NodeId _DG2ExploredNode_
DG2 Diagram current explored node.
Definition: o4DGContext.h:122
const NodeId & DG1Node() const
Get DG1 diagram current explored Node.
Definition: o4DGContext.h:86
void setDG1Node(const NodeId &)
Set DG1 diagram current explored Node.
static const Idx _offsetv_
Definition: o4DGContext.h:134
O4DGContext(Idx *, Idx)
Default constructor.
Definition: o4DGContext.cpp:68
void operator delete(void *p)
Operator delete overload to use the SmallObjectAllocator.
NodeId _DG1ExploredNode_
DG1 Diagram current explored node.
Definition: o4DGContext.h:119
Idx * _varInstantiation_
Vector containing for each retrograde variable its current modality 0 meaning no instantiation done =...
Definition: o4DGContext.h:126
static const double _logPrime_[]
Table containing the log2 of prime numbers.
Definition: o4DGContext.h:133
static const Idx _offset1_
Definition: o4DGContext.h:134
void setDG2Node(const NodeId &)
Set DG2 diagram current explored Node.
~O4DGContext()
Default destructor.
Definition: o4DGContext.cpp:76
double _key_
The key use to store the context as a key in the hashtable.
Definition: o4DGContext.h:130
static const Idx _nbLogPrime_
Definition: o4DGContext.h:134
Class used to manipulate context during Function Graph Operations.
Definition: o4DGContext.h:49
static const Idx _offset2_
Definition: o4DGContext.h:134
Idx varModality(Idx)
Changes given variable modality.