aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
structuralConstraintUndiGraph_inl.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
/** @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
StructuralConstraintUndiGraph
::
setGraphAlone
(
const
UndiGraph
&
graph
) {
36
_UndiGraph_graph_
=
graph
;
37
}
38
39
/// checks whether the constraints enable to add edge (x,y)
40
INLINE
bool
StructuralConstraintUndiGraph
::
checkEdgeAdditionAlone
(
NodeId
x
,
NodeId
y
)
const
{
41
return
_UndiGraph_graph_
.
existsNode
(
x
) &&
_UndiGraph_graph_
.
existsNode
(
y
)
42
&& !
_UndiGraph_graph_
.
existsEdge
(
x
,
y
);
43
}
44
45
/// checks whether the constraints enable to remove edge (x,y)
46
INLINE
bool
StructuralConstraintUndiGraph
::
checkEdgeDeletionAlone
(
NodeId
x
,
NodeId
y
)
const
{
47
return
_UndiGraph_graph_
.
existsEdge
(
x
,
y
);
48
}
49
50
/// checks whether the constraints enable to add an edge
51
INLINE
bool
52
StructuralConstraintUndiGraph
::
checkModificationAlone
(
const
EdgeAddition
&
change
)
const
{
53
return
checkEdgeAdditionAlone
(
change
.
node1
(),
change
.
node2
());
54
}
55
56
/// checks whether the constraints enable to remove an edge
57
INLINE
bool
58
StructuralConstraintUndiGraph
::
checkModificationAlone
(
const
EdgeDeletion
&
change
)
const
{
59
return
checkEdgeDeletionAlone
(
change
.
node1
(),
change
.
node2
());
60
}
61
62
/// checks whether the constraints enable to perform a graph change
63
INLINE
bool
64
StructuralConstraintUndiGraph
::
checkModificationAlone
(
const
GraphChange
&
change
)
const
{
65
switch
(
change
.
type
()) {
66
case
GraphChangeType
::
EDGE_ADDITION
:
67
return
checkEdgeAdditionAlone
(
change
.
node1
(),
change
.
node2
());
68
69
case
GraphChangeType
::
EDGE_DELETION
:
70
return
checkEdgeDeletionAlone
(
change
.
node1
(),
change
.
node2
());
71
72
default
:
73
GUM_ERROR
(
OperationNotAllowed
,
74
"arc modifications are not "
75
"supported by StructuralConstraintUndiGraph"
);
76
}
77
}
78
79
/// notify the constraint of a modification of the graph
80
INLINE
void
StructuralConstraintUndiGraph
::
modifyGraphAlone
(
const
EdgeAddition
&
change
) {
81
_UndiGraph_graph_
.
addEdge
(
change
.
node1
(),
change
.
node2
());
82
}
83
84
/// notify the constraint of a modification of the graph
85
INLINE
void
StructuralConstraintUndiGraph
::
modifyGraphAlone
(
const
EdgeDeletion
&
change
) {
86
_UndiGraph_graph_
.
eraseEdge
(
Edge
(
change
.
node1
(),
change
.
node2
()));
87
}
88
89
/// notify the constraint of a modification of the graph
90
INLINE
void
StructuralConstraintUndiGraph
::
modifyGraphAlone
(
const
GraphChange
&
change
) {
91
switch
(
change
.
type
()) {
92
case
GraphChangeType
::
EDGE_ADDITION
:
93
modifyGraphAlone
(
reinterpret_cast
<
const
EdgeAddition
& >(
change
));
94
break
;
95
96
case
GraphChangeType
::
EDGE_DELETION
:
97
modifyGraphAlone
(
reinterpret_cast
<
const
EdgeDeletion
& >(
change
));
98
break
;
99
100
default
:
101
GUM_ERROR
(
OperationNotAllowed
,
102
"arc modifications are not supported "
103
"by StructuralConstraintUndiGraph"
);
104
}
105
}
106
107
/// indicates whether a change will always violate the constraint
108
INLINE
bool
StructuralConstraintUndiGraph
::
isAlwaysInvalidAlone
(
const
GraphChange
&)
const
{
109
return
false
;
110
}
111
112
/// sets a new graph from which we will perform checkings
113
INLINE
void
StructuralConstraintUndiGraph
::
setGraph
(
Size
nb_nodes
) {
114
_UndiGraph_graph_
.
clear
();
115
for
(
NodeId
i
= 0;
i
<
nb_nodes
; ++
i
) {
116
_UndiGraph_graph_
.
addNodeWithId
(
i
);
117
}
118
}
119
120
// include all the methods applicable to the whole class hierarchy
121
#
define
GUM_CONSTRAINT_CLASS_NAME
StructuralConstraintUndiGraph
122
#
include
<
agrum
/
BN
/
learning
/
constraints
/
structuralConstraintPattern4UndiGraphRootInline
.
h
>
123
#
undef
GUM_CONSTRAINT_CLASS_NAME
124
125
}
/* namespace learning */
126
127
}
/* namespace gum */
128
129
#
endif
/* DOXYGEN_SHOULD_SKIP_THIS */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:643
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