aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
structuralConstraintUndiGraph_inl.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
/** @file
23
* @brief the base class for structural constraints used by learning algorithms
24
* that learn an undirected graph structure
25
*
26
* @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27
*/
28
#
ifndef
DOXYGEN_SHOULD_SKIP_THIS
29
30
namespace
gum
{
31
32
namespace
learning
{
33
34
/// sets a new graph from which we will perform checkings
35
INLINE
void
36
StructuralConstraintUndiGraph
::
setGraphAlone
(
const
UndiGraph
&
graph
) {
37
UndiGraph__graph_
=
graph
;
38
}
39
40
/// checks whether the constraints enable to add edge (x,y)
41
INLINE
bool
42
StructuralConstraintUndiGraph
::
checkEdgeAdditionAlone
(
NodeId
x
,
43
NodeId
y
)
const
{
44
return
UndiGraph__graph_
.
existsNode
(
x
) &&
UndiGraph__graph_
.
existsNode
(
y
)
45
&& !
UndiGraph__graph_
.
existsEdge
(
x
,
y
);
46
}
47
48
/// checks whether the constraints enable to remove edge (x,y)
49
INLINE
bool
50
StructuralConstraintUndiGraph
::
checkEdgeDeletionAlone
(
NodeId
x
,
51
NodeId
y
)
const
{
52
return
UndiGraph__graph_
.
existsEdge
(
x
,
y
);
53
}
54
55
/// checks whether the constraints enable to add an edge
56
INLINE
bool
StructuralConstraintUndiGraph
::
checkModificationAlone
(
57
const
EdgeAddition
&
change
)
const
{
58
return
checkEdgeAdditionAlone
(
change
.
node1
(),
change
.
node2
());
59
}
60
61
/// checks whether the constraints enable to remove an edge
62
INLINE
bool
StructuralConstraintUndiGraph
::
checkModificationAlone
(
63
const
EdgeDeletion
&
change
)
const
{
64
return
checkEdgeDeletionAlone
(
change
.
node1
(),
change
.
node2
());
65
}
66
67
/// checks whether the constraints enable to perform a graph change
68
INLINE
bool
StructuralConstraintUndiGraph
::
checkModificationAlone
(
69
const
GraphChange
&
change
)
const
{
70
switch
(
change
.
type
()) {
71
case
GraphChangeType
::
EDGE_ADDITION
:
72
return
checkEdgeAdditionAlone
(
change
.
node1
(),
change
.
node2
());
73
74
case
GraphChangeType
::
EDGE_DELETION
:
75
return
checkEdgeDeletionAlone
(
change
.
node1
(),
change
.
node2
());
76
77
default
:
78
GUM_ERROR
(
OperationNotAllowed
,
79
"arc modifications are not "
80
"supported by StructuralConstraintUndiGraph"
);
81
}
82
}
83
84
/// notify the constraint of a modification of the graph
85
INLINE
void
StructuralConstraintUndiGraph
::
modifyGraphAlone
(
86
const
EdgeAddition
&
change
) {
87
UndiGraph__graph_
.
addEdge
(
change
.
node1
(),
change
.
node2
());
88
}
89
90
/// notify the constraint of a modification of the graph
91
INLINE
void
StructuralConstraintUndiGraph
::
modifyGraphAlone
(
92
const
EdgeDeletion
&
change
) {
93
UndiGraph__graph_
.
eraseEdge
(
Edge
(
change
.
node1
(),
change
.
node2
()));
94
}
95
96
/// notify the constraint of a modification of the graph
97
INLINE
void
98
StructuralConstraintUndiGraph
::
modifyGraphAlone
(
const
GraphChange
&
change
) {
99
switch
(
change
.
type
()) {
100
case
GraphChangeType
::
EDGE_ADDITION
:
101
modifyGraphAlone
(
reinterpret_cast
<
const
EdgeAddition
& >(
change
));
102
break
;
103
104
case
GraphChangeType
::
EDGE_DELETION
:
105
modifyGraphAlone
(
reinterpret_cast
<
const
EdgeDeletion
& >(
change
));
106
break
;
107
108
default
:
109
GUM_ERROR
(
OperationNotAllowed
,
110
"arc modifications are not supported "
111
"by StructuralConstraintUndiGraph"
);
112
}
113
}
114
115
/// indicates whether a change will always violate the constraint
116
INLINE
bool
StructuralConstraintUndiGraph
::
isAlwaysInvalidAlone
(
117
const
GraphChange
&)
const
{
118
return
false
;
119
}
120
121
/// sets a new graph from which we will perform checkings
122
INLINE
void
StructuralConstraintUndiGraph
::
setGraph
(
Size
nb_nodes
) {
123
UndiGraph__graph_
.
clear
();
124
for
(
NodeId
i
= 0;
i
<
nb_nodes
; ++
i
) {
125
UndiGraph__graph_
.
addNodeWithId
(
i
);
126
}
127
}
128
129
// include all the methods applicable to the whole class hierarchy
130
#
define
GUM_CONSTRAINT_CLASS_NAME
StructuralConstraintUndiGraph
131
#
include
<
agrum
/
BN
/
learning
/
constraints
/
structuralConstraintPattern4UndiGraphRootInline
.
h
>
132
#
undef
GUM_CONSTRAINT_CLASS_NAME
133
134
}
/* namespace learning */
135
136
}
/* namespace gum */
137
138
#
endif
/* DOXYGEN_SHOULD_SKIP_THIS */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:669
gum::learning::genericBNLearner::Database::Database
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
Definition:
genericBNLearner_tpl.h:31