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