aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
structuralConstraintTabuList_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 class imposing a N-sized tabu list as a structural constraints for
24
* learning algorithms
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 the size of the tabu list
35
INLINE
36
void
StructuralConstraintTabuList
::
setTabuListSize
(
Size
new_size
) {
37
if
(
new_size
==
TabuList__changes_
.
size
())
return
;
38
39
if
(
TabuList__changes_
.
size
() >
new_size
) {
40
// remove the oldest elements, so that only newsize elements remain
41
while
(
TabuList__changes_
.
size
() >
new_size
) {
42
TabuList__changes_
.
eraseSecond
(
TabuList__offset_
);
43
++
TabuList__offset_
;
44
}
45
}
else
{
46
// add dummy elements
47
while
(
TabuList__changes_
.
size
() <
new_size
) {
48
--
TabuList__offset_
;
49
TabuList__changes_
.
insert
(
50
ArcAddition
(
std
::
numeric_limits
<
NodeId
>::
max
() -
TabuList__offset_
,
51
std
::
numeric_limits
<
NodeId
>::
max
()),
52
TabuList__offset_
);
53
}
54
}
55
}
56
57
/// sets a new graph from which we will perform checkings
58
INLINE
void
StructuralConstraintTabuList
::
setGraphAlone
(
const
DiGraph
&
graph
) {
59
}
60
61
/// checks whether the constraints enable to add arc (x,y)
62
INLINE
bool
63
StructuralConstraintTabuList
::
checkArcAdditionAlone
(
NodeId
x
,
64
NodeId
y
)
const
{
65
return
!
TabuList__changes_
.
existsFirst
(
ArcDeletion
(
x
,
y
))
66
&& !
TabuList__changes_
.
existsFirst
(
ArcAddition
(
x
,
y
));
67
}
68
69
/// checks whether the constraints enable to remove arc (x,y)
70
INLINE
bool
71
StructuralConstraintTabuList
::
checkArcDeletionAlone
(
NodeId
x
,
72
NodeId
y
)
const
{
73
return
!
TabuList__changes_
.
existsFirst
(
ArcAddition
(
x
,
y
))
74
&& !
TabuList__changes_
.
existsFirst
(
ArcDeletion
(
x
,
y
));
75
}
76
77
/// checks whether the constraints enable to reverse arc (x,y)
78
INLINE
bool
79
StructuralConstraintTabuList
::
checkArcReversalAlone
(
NodeId
x
,
80
NodeId
y
)
const
{
81
return
!
TabuList__changes_
.
existsFirst
(
ArcReversal
(
y
,
x
))
82
&& !
TabuList__changes_
.
existsFirst
(
ArcReversal
(
x
,
y
));
83
}
84
85
/// checks whether the constraints enable to add an arc
86
INLINE
bool
StructuralConstraintTabuList
::
checkModificationAlone
(
87
const
ArcAddition
&
change
)
const
{
88
return
checkArcAdditionAlone
(
change
.
node1
(),
change
.
node2
());
89
}
90
91
/// checks whether the constraints enable to remove an arc
92
INLINE
bool
StructuralConstraintTabuList
::
checkModificationAlone
(
93
const
ArcDeletion
&
change
)
const
{
94
return
checkArcDeletionAlone
(
change
.
node1
(),
change
.
node2
());
95
}
96
97
/// checks whether the constraints enable to reverse an arc
98
INLINE
bool
StructuralConstraintTabuList
::
checkModificationAlone
(
99
const
ArcReversal
&
change
)
const
{
100
return
checkArcReversalAlone
(
change
.
node1
(),
change
.
node2
());
101
}
102
103
/// checks whether the constraints enable to perform a graph change
104
INLINE
bool
StructuralConstraintTabuList
::
checkModificationAlone
(
105
const
GraphChange
&
change
)
const
{
106
switch
(
change
.
type
()) {
107
case
GraphChangeType
::
ARC_ADDITION
:
108
return
checkArcAdditionAlone
(
change
.
node1
(),
change
.
node2
());
109
110
case
GraphChangeType
::
ARC_DELETION
:
111
return
checkArcDeletionAlone
(
change
.
node1
(),
change
.
node2
());
112
113
case
GraphChangeType
::
ARC_REVERSAL
:
114
return
checkArcReversalAlone
(
change
.
node1
(),
change
.
node2
());
115
116
default
:
117
GUM_ERROR
(
OperationNotAllowed
,
118
"edge modifications are not "
119
"supported by StructuralConstraintTabuList"
);
120
}
121
}
122
123
/// notify the constraint of a modification of the graph
124
INLINE
void
125
StructuralConstraintTabuList
::
modifyGraphAlone
(
const
ArcAddition
&
change
) {
126
TabuList__changes_
.
eraseSecond
(
TabuList__offset_
);
127
++
TabuList__offset_
;
128
TabuList__changes_
.
insert
(
129
change
,
130
NodeId
(
TabuList__offset_
+
TabuList__changes_
.
size
()));
131
}
132
133
/// notify the constraint of a modification of the graph
134
INLINE
void
135
StructuralConstraintTabuList
::
modifyGraphAlone
(
const
ArcDeletion
&
change
) {
136
TabuList__changes_
.
eraseSecond
(
TabuList__offset_
);
137
++
TabuList__offset_
;
138
TabuList__changes_
.
insert
(
change
,
139
TabuList__offset_
140
+
NodeId
(
TabuList__changes_
.
size
()));
141
}
142
143
/// notify the constraint of a modification of the graph
144
INLINE
void
145
StructuralConstraintTabuList
::
modifyGraphAlone
(
const
ArcReversal
&
change
) {
146
TabuList__changes_
.
eraseSecond
(
TabuList__offset_
);
147
++
TabuList__offset_
;
148
TabuList__changes_
.
insert
(
change
,
149
TabuList__offset_
150
+
NodeId
(
TabuList__changes_
.
size
()));
151
}
152
153
/// notify the constraint of a modification of the graph
154
INLINE
void
155
StructuralConstraintTabuList
::
modifyGraphAlone
(
const
GraphChange
&
change
) {
156
switch
(
change
.
type
()) {
157
case
GraphChangeType
::
ARC_ADDITION
:
158
modifyGraphAlone
(
static_cast
<
const
ArcAddition
& >(
change
));
159
break
;
160
161
case
GraphChangeType
::
ARC_DELETION
:
162
modifyGraphAlone
(
static_cast
<
const
ArcDeletion
& >(
change
));
163
break
;
164
165
case
GraphChangeType
::
ARC_REVERSAL
:
166
modifyGraphAlone
(
static_cast
<
const
ArcReversal
& >(
change
));
167
break
;
168
169
default
:
170
GUM_ERROR
(
OperationNotAllowed
,
171
"edge modifications are not supported by digraph constraint"
);
172
}
173
}
174
175
/// indicates whether a change will always violate the constraint
176
INLINE
bool
StructuralConstraintTabuList
::
isAlwaysInvalidAlone
(
177
const
GraphChange
&)
const
{
178
return
false
;
179
}
180
181
// include all the methods applicable to the whole class hierarchy
182
#
define
GUM_CONSTRAINT_CLASS_NAME
StructuralConstraintTabuList
183
#
include
<
agrum
/
BN
/
learning
/
constraints
/
structuralConstraintPatternRootInline
.
h
>
184
#
undef
GUM_CONSTRAINT_CLASS_NAME
185
186
}
/* namespace learning */
187
188
}
/* namespace gum */
189
190
#
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