aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
structuralConstraintPossibleEdges_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 structural constraint for forbidding the creation of some arcs
24
* during structure learning
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
StructuralConstraintPossibleEdges
::
setGraphAlone
(
const
DiGraph
&
graph
) {}
37
38
/// checks whether the constraints enable to add arc (x,y)
39
INLINE
bool
40
StructuralConstraintPossibleEdges
::
checkArcAdditionAlone
(
NodeId
x
,
41
NodeId
y
)
const
{
42
auto
res
=
PossibleEdges__possible_edges_
.
empty
()
43
||
PossibleEdges__possible_edges_
.
exists
(
Edge
(
x
,
y
));
44
return
res
;
45
}
46
47
/// checks whether the constraints enable to remove arc (x,y)
48
INLINE
bool
49
StructuralConstraintPossibleEdges
::
checkArcDeletionAlone
(
NodeId
x
,
50
NodeId
y
)
const
{
51
return
true
;
52
}
53
54
/// checks whether the constraints enable to reverse arc (x,y)
55
INLINE
bool
56
StructuralConstraintPossibleEdges
::
checkArcReversalAlone
(
NodeId
x
,
57
NodeId
y
)
const
{
58
return
PossibleEdges__possible_edges_
.
empty
()
59
||
PossibleEdges__possible_edges_
.
exists
(
Edge
(
y
,
x
));
60
}
61
62
/// checks whether the constraints enable to add an arc
63
INLINE
bool
StructuralConstraintPossibleEdges
::
checkModificationAlone
(
64
const
ArcAddition
&
change
)
const
{
65
return
checkArcAdditionAlone
(
change
.
node1
(),
change
.
node2
());
66
}
67
68
/// checks whether the constraints enable to remove an arc
69
INLINE
bool
StructuralConstraintPossibleEdges
::
checkModificationAlone
(
70
const
ArcDeletion
&
change
)
const
{
71
return
checkArcDeletionAlone
(
change
.
node1
(),
change
.
node2
());
72
}
73
74
/// checks whether the constraints enable to reverse an arc
75
INLINE
bool
StructuralConstraintPossibleEdges
::
checkModificationAlone
(
76
const
ArcReversal
&
change
)
const
{
77
return
checkArcReversalAlone
(
change
.
node1
(),
change
.
node2
());
78
}
79
80
/// checks whether the constraints enable to perform a graph change
81
INLINE
bool
StructuralConstraintPossibleEdges
::
checkModificationAlone
(
82
const
GraphChange
&
change
)
const
{
83
switch
(
change
.
type
()) {
84
case
GraphChangeType
::
ARC_ADDITION
:
85
return
checkArcAdditionAlone
(
change
.
node1
(),
change
.
node2
());
86
87
case
GraphChangeType
::
ARC_DELETION
:
88
return
checkArcDeletionAlone
(
change
.
node1
(),
change
.
node2
());
89
90
case
GraphChangeType
::
ARC_REVERSAL
:
91
return
checkArcReversalAlone
(
change
.
node1
(),
change
.
node2
());
92
93
default
:
94
GUM_ERROR
(
OperationNotAllowed
,
95
"edge modifications are not "
96
"supported by StructuralConstraintPossibleEdges"
);
97
}
98
}
99
100
/// notify the constraint of a modification of the graph
101
INLINE
void
StructuralConstraintPossibleEdges
::
modifyGraphAlone
(
102
const
ArcAddition
&
change
) {}
103
104
/// notify the constraint of a modification of the graph
105
INLINE
void
StructuralConstraintPossibleEdges
::
modifyGraphAlone
(
106
const
ArcDeletion
&
change
) {}
107
108
/// notify the constraint of a modification of the graph
109
INLINE
void
StructuralConstraintPossibleEdges
::
modifyGraphAlone
(
110
const
ArcReversal
&
change
) {}
111
112
/// notify the constraint of a modification of the graph
113
INLINE
void
StructuralConstraintPossibleEdges
::
modifyGraphAlone
(
114
const
GraphChange
&
change
) {}
115
116
/// indicates whether a change will always violate the constraint
117
INLINE
bool
StructuralConstraintPossibleEdges
::
isAlwaysInvalidAlone
(
118
const
GraphChange
&
change
)
const
{
119
switch
(
change
.
type
()) {
120
case
GraphChangeType
::
ARC_ADDITION
:
121
return
!
checkArcAdditionAlone
(
change
.
node1
(),
change
.
node2
());
122
123
case
GraphChangeType
::
ARC_DELETION
:
124
return
false
;
125
126
case
GraphChangeType
::
ARC_REVERSAL
:
127
return
!
checkArcAdditionAlone
(
change
.
node2
(),
change
.
node1
());
128
129
default
:
130
GUM_ERROR
(
OperationNotAllowed
,
131
"edge modifications are not supported "
132
"by StructuralConstraintPossibleEdges"
);
133
}
134
}
135
136
/// assign a set of forbidden edge
137
INLINE
void
StructuralConstraintPossibleEdges
::
setEdges
(
const
EdgeSet
&
set
) {
138
PossibleEdges__possible_edges_
=
set
;
139
}
140
141
/// assign a new forbidden edge
142
INLINE
void
StructuralConstraintPossibleEdges
::
addEdge
(
const
Edge
&
edge
) {
143
PossibleEdges__possible_edges_
.
insert
(
edge
);
144
}
145
146
/// remove a forbidden edge
147
INLINE
void
StructuralConstraintPossibleEdges
::
eraseEdge
(
const
Edge
&
edge
) {
148
PossibleEdges__possible_edges_
.
erase
(
edge
);
149
}
150
151
/// returns the set of possible edges
152
INLINE
const
EdgeSet
&
StructuralConstraintPossibleEdges
::
edges
()
const
{
153
return
PossibleEdges__possible_edges_
;
154
}
155
156
// include all the methods applicable to the whole class hierarchy
157
#
define
GUM_CONSTRAINT_CLASS_NAME
StructuralConstraintPossibleEdges
158
#
include
<
agrum
/
BN
/
learning
/
constraints
/
structuralConstraintPatternRootInline
.
h
>
159
#
undef
GUM_CONSTRAINT_CLASS_NAME
160
161
}
/* namespace learning */
162
163
}
/* namespace gum */
164
165
#
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