aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
internalNode.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
50#ifndef GUM_MULTI_DIM_FUNCTION_GRAPH_INTERNAL_NODE_H
51#define GUM_MULTI_DIM_FUNCTION_GRAPH_INTERNAL_NODE_H
52
53#include <agrum/agrum.h>
54
58
59namespace gum {
60
61 // clang-format off
69 // clang-format on
70
71 struct Parent {
74
78 Parent(NodeId pi, Idx m);
79
83 Parent(const Parent& src);
84
85 // ============================================================================
87 // ============================================================================
89
93 void* operator new(size_t s);
94
98 void operator delete(void* p);
99
101 // ============================================================================
103 // ============================================================================
105
106 bool operator==(const Parent& comp) const;
107
108 bool operator!=(const Parent& comp) const;
109
110 Parent& operator=(const Parent& src);
112 };
113
114 // clang-format off
122 // clang-format on
123
125 private:
128
145
148
150 void _setNodeVar_(const DiscreteVariable* v);
151
152 public:
153 // ============================================================================
155 // ============================================================================
157
162 InternalNode();
163
170 explicit InternalNode(const DiscreteVariable* v);
171
182 InternalNode(const DiscreteVariable* v, NodeId* sons);
183
189 // ============================================================================
191 // ============================================================================
193
197 void* operator new(size_t s);
198
202 void operator delete(void* p);
203
205 // ============================================================================
207 // ============================================================================
209
217 void setNode(const DiscreteVariable* v, NodeId* sons);
218
220 // ============================================================================
222 // ============================================================================
224
228 void setNodeVar(const DiscreteVariable* v);
229
233 const DiscreteVariable* nodeVar() const;
234
236 // ============================================================================
238 // ============================================================================
240
244 void setSon(Idx modality, NodeId son);
245
249 NodeId son(Idx modality) const;
250
254 Idx nbSons() const;
255
257 // ============================================================================
259 // ============================================================================
261
265 void addParent(NodeId parent, Idx modality);
266
270 void removeParent(NodeId parent, Idx modality);
271
276
280 const Link< Parent >* parents() const;
281
283 // ============================================================================
285 // ============================================================================
287
291 static NodeId* allocateNodeSons(const DiscreteVariable* v);
292
296 static void deallocateNodeSons(const DiscreteVariable* v, NodeId* s);
297
299 };
300
301} // End of namespace gum
302
303#ifndef GUM_NO_INLINE
305#endif /* GUM_NO_INLINE */
306
307#endif /* GUM_MULTI_DIM_FUNCTION_GRAPH_INTERNAL_NODE_H */
Base class for discrete random variable.
InternalNode()
Default Constructor Creates an empty node with no variable attached.
void setNodeVar(const DiscreteVariable *v)
Set the node variable.
void setNode(const DiscreteVariable *v, NodeId *sons)
Allows you to respecify the node, changing its attached variable as well as its son map.
const DiscreteVariable * nodeVar() const
Returns the node variable.
void _setNodeVar_(const DiscreteVariable *v)
Set the node variable.
NodeId * _nodeSons_
Table of sons of the node.
const DiscreteVariable * _nodeVar_
Variable associated to such node.
void addParent(NodeId parent, Idx modality)
Adds a parent.
Idx nbSons() const
Returns the number of sons.
~InternalNode()
Class destructors.
static NodeId * allocateNodeSons(const DiscreteVariable *v)
Allocates a table of nodeid of the size given in parameter.
static void deallocateNodeSons(const DiscreteVariable *v, NodeId *s)
Deallocates a NodeSons table.
NodeId son(Idx modality) const
Returns the son at a given index.
void removeParent(NodeId parent, Idx modality)
Removes a parent.
Link< Parent > * parents()
Returns the list of parents.
void setSon(Idx modality, NodeId son)
Sets the node's son.
LinkedList< Parent > _nodeParents_
The list of the node's parent.
Chain list allocated using the SmallObjectAllocator.
Definition link.h:155
Base class for discrete random variable.
some utils for topology : NodeId, Edge, Arc and consorts ...
Size Idx
Type for indexes.
Definition types.h:79
Size NodeId
Type for node ids.
Inline implementation of the InternalNode class.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
bool operator==(const Parent &comp) const
bool operator!=(const Parent &comp) const
Parent & operator=(const Parent &src)
Parent(NodeId pi, Idx m)
Class constructor.
NodeId parentId