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