aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
classDependencyGraph_tpl.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 Inline implementation of ClassDependencyGraph.
25
*
26
* @author Lionel TORTI and Pierre-Henri WUILLEMIN(@LIP6)
27
*/
28
#
include
<
agrum
/
PRM
/
classDependencyGraph
.
h
>
29
30
namespace
gum
{
31
namespace
prm
{
32
33
// Destructor.
34
template
<
typename
GUM_SCALAR
>
35
ClassDependencyGraph
<
GUM_SCALAR
>::~
ClassDependencyGraph
() {
36
GUM_DESTRUCTOR
(
ClassDependencyGraph
);
37
38
for
(
const
auto
&
elt
:
node_map__
)
39
delete
elt
.
second
;
40
41
for
(
const
auto
&
elt
:
elt_map__
)
42
delete
elt
.
second
;
43
}
44
45
// Build the class dependency graph.
46
template
<
typename
GUM_SCALAR
>
47
void
ClassDependencyGraph
<
GUM_SCALAR
>::
buildGraph__
(
48
const
PRM
<
GUM_SCALAR
>&
prm
) {
49
// First we add all nodes
50
for
(
const
auto
ci
:
prm
.
classes
()) {
51
node_map__
.
insert
(
52
ci
,
53
new
HashTable
<
const
PRMClassElement
<
GUM_SCALAR
>*,
NodeId
>());
54
55
for
(
const
auto
node
:
ci
->
containerDag
().
nodes
())
56
addNode__
(
ci
,
ci
->
get
(
node
));
57
}
58
59
for
(
const
auto
ii
:
prm
.
interfaces
()) {
60
node_map__
.
insert
(
61
ii
,
62
new
HashTable
<
const
PRMClassElement
<
GUM_SCALAR
>*,
NodeId
>());
63
64
for
(
const
auto
node
:
ii
->
containerDag
().
nodes
()) {
65
addNode__
(
ii
,
ii
->
get
(
node
));
66
}
67
}
68
69
// Then we add the arcs
70
for
(
const
auto
cc
:
prm
.
classes
())
71
for
(
const
auto
node
:
cc
->
containerDag
().
nodes
())
72
addArcs__
(*
cc
,
node
, *(
node_map__
[
cc
]));
73
}
74
75
// Add arcs in graph__.
76
template
<
typename
GUM_SCALAR
>
77
void
ClassDependencyGraph
<
GUM_SCALAR
>::
addArcs__
(
78
const
PRMClassElementContainer
<
GUM_SCALAR
>&
c
,
79
NodeId
node
,
80
HashTable
<
const
PRMClassElement
<
GUM_SCALAR
>*,
NodeId
>&
map
) {
81
switch
(
c
.
get
(
node
).
elt_type
()) {
82
case
PRMClassElement
<
GUM_SCALAR
>::
prm_slotchain
: {
83
const
PRMSlotChain
<
GUM_SCALAR
>&
sc
84
=
static_cast
<
const
PRMSlotChain
<
GUM_SCALAR
>& >(
c
.
get
(
node
));
85
86
for
(
const
auto
chi
:
c
.
containerDag
().
children
(
node
))
87
graph__
.
addArc
((*(
node_map__
[&(
sc
.
end
())]))[&(
88
sc
.
end
().
get
(
sc
.
lastElt
().
safeName
()))],
89
map
[&(
c
.
get
(
chi
))]);
90
91
break
;
92
}
93
94
case
PRMClassElement
<
GUM_SCALAR
>::
prm_aggregate
:
95
case
PRMClassElement
<
GUM_SCALAR
>::
prm_attribute
: {
96
for
(
const
auto
chi
:
c
.
containerDag
().
children
(
node
))
97
graph__
.
addArc
(
map
[&(
c
.
get
(
node
))],
map
[&(
c
.
get
(
chi
))]);
98
99
break
;
100
}
101
102
default
: {
/* do nothing */
103
break
;
104
}
105
}
106
}
107
108
template
<
typename
GUM_SCALAR
>
109
INLINE
ClassDependencyGraph
<
GUM_SCALAR
>::
ClassDependencyGraph
(
110
const
PRM
<
GUM_SCALAR
>&
prm
) {
111
GUM_CONSTRUCTOR
(
ClassDependencyGraph
);
112
buildGraph__
(
prm
);
113
}
114
115
template
<
typename
GUM_SCALAR
>
116
INLINE
ClassDependencyGraph
<
GUM_SCALAR
>::
ClassDependencyGraph
(
117
const
ClassDependencyGraph
<
GUM_SCALAR
>&
source
) :
118
graph__
(
source
.
graph__
),
119
modalitites__
(
source
.
modalitites__
),
elt_map__
(
source
.
elt_map__
) {
120
GUM_CONS_CPY
(
ClassDependencyGraph
);
121
122
for
(
const
auto
elt
:
source
.
node_map__
) {
123
node_map__
.
insert
(
124
elt
.
first
,
125
new
HashTable
<
const
PRMClassElement
<
GUM_SCALAR
>*,
NodeId
>(
126
*
elt
.
second
));
127
}
128
}
129
130
template
<
typename
GUM_SCALAR
>
131
INLINE
const
DAG
&
ClassDependencyGraph
<
GUM_SCALAR
>::
dag
()
const
{
132
return
graph__
;
133
}
134
135
template
<
typename
GUM_SCALAR
>
136
INLINE
const
typename
ClassDependencyGraph
<
GUM_SCALAR
>::
EltPair
&
137
ClassDependencyGraph
<
GUM_SCALAR
>::
get
(
NodeId
id
)
const
{
138
return
*(
elt_map__
[
id
]);
139
}
140
141
template
<
typename
GUM_SCALAR
>
142
INLINE
NodeId
ClassDependencyGraph
<
GUM_SCALAR
>::
get
(
143
const
PRMClassElementContainer
<
GUM_SCALAR
>&
c
,
144
const
PRMClassElement
<
GUM_SCALAR
>&
elt
)
const
{
145
return
(*(
node_map__
[&
c
]))[&
elt
];
146
}
147
148
template
<
typename
GUM_SCALAR
>
149
INLINE
const
NodeProperty
<
Size
>&
150
ClassDependencyGraph
<
GUM_SCALAR
>::
modalities
()
const
{
151
return
modalitites__
;
152
}
153
154
template
<
typename
GUM_SCALAR
>
155
INLINE
void
ClassDependencyGraph
<
GUM_SCALAR
>::
addNode__
(
156
const
PRMClassElementContainer
<
GUM_SCALAR
>*
c
,
157
const
PRMClassElement
<
GUM_SCALAR
>&
elt
) {
158
switch
(
elt
.
elt_type
()) {
159
case
PRMClassElement
<
GUM_SCALAR
>::
prm_attribute
:
160
case
PRMClassElement
<
GUM_SCALAR
>::
prm_aggregate
: {
161
NodeId
id
=
graph__
.
addNode
();
162
elt_map__
.
insert
(
163
id
,
164
new
ClassDependencyGraph
<
GUM_SCALAR
>::
EltPair
(
c
, &
elt
));
165
node_map__
[
c
]->
insert
(&
elt
,
id
);
166
modalitites__
.
insert
(
id
,
elt
.
type
().
variable
().
domainSize
());
167
break
;
168
}
169
170
default
: {
/* do nothing */
171
break
;
172
}
173
}
174
}
175
176
}
/* namespace prm */
177
}
/* namespace gum */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:669
gum::prm::ParamScopeData::ParamScopeData
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)
Definition:
PRMClass_tpl.h:1101