aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
internalNode.cpp
Go to the documentation of this file.
1
/****************************************************************************
2
* This file is part of the aGrUM/pyAgrum library. *
3
* *
4
* Copyright (c) 2005-2026 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-2026 *
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
51
#include <
agrum/base/multidim/utils/FunctionGraphUtilities/internalNode.h
>
52
53
#define ALLOCATE(x) SmallObjectAllocator::instance().allocate(x)
54
#define DEALLOCATE(x, y) SmallObjectAllocator::instance().deallocate(x, y)
55
56
namespace
gum
{
57
58
// ============================================================================
59
// Constructors
60
// ============================================================================
61
InternalNode::InternalNode
() {
62
GUM_CONSTRUCTOR(
InternalNode
);
63
_nodeVar_
=
nullptr
;
64
}
65
66
InternalNode::InternalNode
(
const
DiscreteVariable
* v) {
67
GUM_CONSTRUCTOR(
InternalNode
);
68
_setNodeVar_
(v);
69
}
70
71
InternalNode::InternalNode
(
const
DiscreteVariable
* v,
NodeId
* sons) {
72
GUM_CONSTRUCTOR(
InternalNode
);
73
_nodeVar_
= v;
74
_nodeSons_
= sons;
75
}
76
77
// ============================================================================
78
// Destructors
79
// ============================================================================
80
InternalNode::~InternalNode
() {
81
GUM_DESTRUCTOR(
InternalNode
);
82
if
(
_nodeVar_
!=
nullptr
)
deallocateNodeSons
(
_nodeVar_
,
_nodeSons_
);
83
}
84
85
// ============================================================================
86
// Allocates a table of nodeid of the size given in parameter
87
// ============================================================================
88
NodeId
*
InternalNode::allocateNodeSons
(
const
DiscreteVariable
* v) {
89
NodeId
* sons =
static_cast<
NodeId
*
>
(
ALLOCATE
(
sizeof
(
NodeId
) * v->
domainSize
()));
90
for
(
gum::Idx
i = 0; i < v->
domainSize
(); ++i)
91
sons[i] = 0;
92
return
sons;
93
}
94
95
// ============================================================================
96
// Deallocates a NodeSons table
97
// ============================================================================
98
void
InternalNode::deallocateNodeSons
(
const
DiscreteVariable
* v,
NodeId
* s) {
99
DEALLOCATE
(s,
sizeof
(
NodeId
) * v->
domainSize
());
100
}
101
102
// ============================================================================
103
// Node handlers
104
// ============================================================================
105
void
InternalNode::setNode
(
const
DiscreteVariable
* v,
NodeId
* sons) {
106
if
(
_nodeVar_
!=
nullptr
)
deallocateNodeSons
(
_nodeVar_
,
_nodeSons_
);
107
_nodeVar_
= v;
108
_nodeSons_
= sons;
109
}
110
111
// ============================================================================
112
// Var handlers
113
// ============================================================================
114
void
InternalNode::setNodeVar
(
const
DiscreteVariable
* v) {
115
if
(
_nodeVar_
!=
nullptr
)
deallocateNodeSons
(
_nodeVar_
,
_nodeSons_
);
116
_setNodeVar_
(v);
117
}
118
119
void
InternalNode::_setNodeVar_
(
const
DiscreteVariable
* v) {
120
_nodeVar_
= v;
121
_nodeSons_
=
allocateNodeSons
(v);
122
}
123
124
// ============================================================================
125
// Parent handlers
126
// ============================================================================
127
void
InternalNode::addParent
(
NodeId
parent,
Idx
modality) {
128
_nodeParents_
.addLink(
Parent
(parent, modality));
129
}
130
131
void
InternalNode::removeParent
(
NodeId
parent,
Idx
modality) {
132
_nodeParents_
.searchAndRemoveLink(
Parent
(parent, modality));
133
}
134
135
}
// namespace gum
136
137
#ifdef GUM_NO_INLINE
138
# include <
agrum/base/multidim/utils/FunctionGraphUtilities/internalNode_inl.h
>
139
#endif
/* GUM_NO_INLINE */
gum::DiscreteVariable
Base class for discrete random variable.
Definition
discreteVariable.h:80
gum::DiscreteVariable::domainSize
virtual Size domainSize() const =0
gum::InternalNode::InternalNode
InternalNode()
Default Constructor Creates an empty node with no variable attached.
Definition
internalNode.cpp:61
gum::InternalNode::setNodeVar
void setNodeVar(const DiscreteVariable *v)
Set the node variable.
Definition
internalNode.cpp:114
gum::InternalNode::setNode
void setNode(const DiscreteVariable *v, NodeId *sons)
Allows you to respecify the node, changing its attached variable as well as its son map.
Definition
internalNode.cpp:105
gum::InternalNode::_setNodeVar_
void _setNodeVar_(const DiscreteVariable *v)
Set the node variable.
Definition
internalNode.cpp:119
gum::InternalNode::_nodeSons_
NodeId * _nodeSons_
Table of sons of the node.
Definition
internalNode.h:143
gum::InternalNode::_nodeVar_
const DiscreteVariable * _nodeVar_
Variable associated to such node.
Definition
internalNode.h:126
gum::InternalNode::addParent
void addParent(NodeId parent, Idx modality)
Adds a parent.
Definition
internalNode.cpp:127
gum::InternalNode::~InternalNode
~InternalNode()
Class destructors.
Definition
internalNode.cpp:80
gum::InternalNode::allocateNodeSons
static NodeId * allocateNodeSons(const DiscreteVariable *v)
Allocates a table of nodeid of the size given in parameter.
Definition
internalNode.cpp:88
gum::InternalNode::deallocateNodeSons
static void deallocateNodeSons(const DiscreteVariable *v, NodeId *s)
Deallocates a NodeSons table.
Definition
internalNode.cpp:98
gum::InternalNode::removeParent
void removeParent(NodeId parent, Idx modality)
Removes a parent.
Definition
internalNode.cpp:131
gum::InternalNode::_nodeParents_
LinkedList< Parent > _nodeParents_
The list of the node's parent.
Definition
internalNode.h:146
gum::Idx
Size Idx
Type for indexes.
Definition
types.h:79
gum::NodeId
Size NodeId
Type for node ids.
Definition
graphElements.h:117
DEALLOCATE
#define DEALLOCATE(x, y)
Definition
internalNode.cpp:54
ALLOCATE
#define ALLOCATE(x)
Definition
internalNode.cpp:53
internalNode.h
Headers of the InternalNode class.
internalNode_inl.h
Inline implementation of the InternalNode class.
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
gum::Parent::Parent
Parent(NodeId pi, Idx m)
Class constructor.
Definition
internalNode_inl.h:58
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0