aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
structuralConstraintForbiddenArcs.cpp
Go to the documentation of this file.
1
/****************************************************************************
2
* This file is part of the aGrUM/pyAgrum library. *
3
* *
4
* Copyright (c) 2005-2026 by *
5
* - Pierre-Henri WUILLEMIN(_at_LIP6) *
6
* - Christophe GONZALES(_at_AMU) *
7
* *
8
* The aGrUM/pyAgrum library is free software; you can redistribute it *
9
* and/or modify it under the terms of either : *
10
* *
11
* - the GNU Lesser General Public License as published by *
12
* the Free Software Foundation, either version 3 of the License, *
13
* or (at your option) any later version, *
14
* - the MIT license (MIT), *
15
* - or both in dual license, as here. *
16
* *
17
* (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18
* *
19
* This aGrUM/pyAgrum library is distributed in the hope that it will be *
20
* useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26
* OTHER DEALINGS IN THE SOFTWARE. *
27
* *
28
* See LICENCES for more details. *
29
* *
30
* SPDX-FileCopyrightText: Copyright 2005-2026 *
31
* - Pierre-Henri WUILLEMIN(_at_LIP6) *
32
* - Christophe GONZALES(_at_AMU) *
33
* SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34
* *
35
* Contact : info_at_agrum_dot_org *
36
* homepage : http://agrum.gitlab.io *
37
* gitlab : https://gitlab.com/agrumery/agrum *
38
* *
39
****************************************************************************/
40
41
48
49
#include <
agrum/BN/learning/constraints/structuralConstraintForbiddenArcs.h
>
50
52
#ifdef GUM_NO_INLINE
53
# include <
agrum/BN/learning/constraints/structuralConstraintForbiddenArcs_inl.h
>
54
#endif
/* GUM_NO_INLINE */
55
56
namespace
gum
{
57
58
namespace
learning
{
59
61
StructuralConstraintForbiddenArcs::StructuralConstraintForbiddenArcs
() {
62
GUM_CONSTRUCTOR(
StructuralConstraintForbiddenArcs
);
63
}
64
66
StructuralConstraintForbiddenArcs::StructuralConstraintForbiddenArcs
(
const
DiGraph
&
graph
) {
67
setGraph(
graph
);
68
GUM_CONSTRUCTOR(
StructuralConstraintForbiddenArcs
);
69
}
70
72
StructuralConstraintForbiddenArcs::StructuralConstraintForbiddenArcs
(
73
const
StructuralConstraintForbiddenArcs
& from) :
_forbidden_arcs_
(from.
_forbidden_arcs_
) {
74
GUM_CONS_CPY(
StructuralConstraintForbiddenArcs
);
75
}
76
78
StructuralConstraintForbiddenArcs::StructuralConstraintForbiddenArcs
(
79
StructuralConstraintForbiddenArcs
&& from) :
80
_forbidden_arcs_
(
std
::move(from.
_forbidden_arcs_
)) {
81
GUM_CONS_MOV(
StructuralConstraintForbiddenArcs
);
82
}
83
85
StructuralConstraintForbiddenArcs::~StructuralConstraintForbiddenArcs
() {
86
GUM_DESTRUCTOR(
StructuralConstraintForbiddenArcs
);
87
}
88
90
StructuralConstraintForbiddenArcs
&
StructuralConstraintForbiddenArcs::operator=
(
91
const
StructuralConstraintForbiddenArcs
& from) {
92
if
(
this
!= &from) {
_forbidden_arcs_
= from.
_forbidden_arcs_
; }
93
return
*
this
;
94
}
95
97
StructuralConstraintForbiddenArcs
&
98
StructuralConstraintForbiddenArcs::operator=
(
StructuralConstraintForbiddenArcs
&& from) {
99
if
(
this
!= &from) {
_forbidden_arcs_
= std::move(from._forbidden_arcs_); }
100
return
*
this
;
101
}
102
103
bool
104
StructuralConstraintForbiddenArcs::checkModificationAlone
(
const
GraphChange
& change)
const
{
105
switch
(change.
type
()) {
106
case
GraphChangeType::ARC_ADDITION
:
107
return
checkArcAdditionAlone
(change.
node1
(), change.
node2
());
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
case
GraphChangeType::ARC_TRIANGLE_DELETION1
:
116
return
checkArcTriangleDeletion1Alone
(change.
node1
(), change.
node2
(), change.
node3
());
117
118
case
GraphChangeType::ARC_TRIANGLE_DELETION2
:
119
return
checkArcTriangleDeletion2Alone
(change.
node1
(), change.
node2
(), change.
node3
());
120
121
default :
122
GUM_ERROR
(
OperationNotAllowed
,
123
"Graph change operation "
124
<< change.
typeAsString
()
125
<<
" is not supported by the Forbidden Arcs structural constraint"
);
126
}
127
}
128
129
bool
StructuralConstraintForbiddenArcs::isAlwaysInvalidAlone
(
const
GraphChange
& change)
const
{
130
switch
(change.
type
()) {
131
case
GraphChangeType::ARC_ADDITION
:
132
return
_forbidden_arcs_
.
exists
(
Arc
(change.
node1
(), change.
node2
()));
133
134
case
GraphChangeType::ARC_DELETION
:
return
false
;
135
136
case
GraphChangeType::ARC_REVERSAL
:
137
return
_forbidden_arcs_
.
exists
(
Arc
(change.
node2
(), change.
node1
()));
138
139
case
GraphChangeType::ARC_TRIANGLE_DELETION1
:
140
return
!
checkArcTriangleDeletion1Alone
(change.
node1
(), change.
node2
(), change.
node3
());
141
142
case
GraphChangeType::ARC_TRIANGLE_DELETION2
:
143
return
!
checkArcTriangleDeletion2Alone
(change.
node1
(), change.
node2
(), change.
node3
());
144
145
default :
146
GUM_ERROR
(
OperationNotAllowed
,
147
"Graph change operation "
148
<< change.
typeAsString
()
149
<<
" is not supported by the Forbidden Arcs structural constraint"
);
150
}
151
}
152
}
/* namespace learning */
153
154
}
/* namespace gum */
gum::Arc::Arc
Arc(NodeId tail, NodeId head)
basic constructor. Creates tail -> head.
gum::DiGraph
Base class for all oriented graphs.
Definition
diGraph.h:132
OperationNotAllowed
Exception : operation not allowed.
gum::Set::exists
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
Definition
set_tpl.h:504
gum::learning::GraphChange
Definition
graphChange.h:101
gum::learning::GraphChange::typeAsString
std::string typeAsString() const
returns a string corresponding to the type of the change
Definition
graphChange.cpp:302
gum::learning::GraphChange::node1
NodeId node1() const noexcept
returns the first node involved in the modification
gum::learning::GraphChange::type
GraphChangeType type() const noexcept
returns the type of the operation
gum::learning::GraphChange::node2
NodeId node2() const noexcept
returns the second node involved in the modification
gum::learning::GraphChange::node3
NodeId node3() const
returns the third node involved in the modification (if any)
gum::learning::StructuralConstraintForbiddenArcs
the structural constraint for forbidding the creation of some arcs during structure learning
Definition
structuralConstraintForbiddenArcs.h:65
gum::learning::StructuralConstraintForbiddenArcs::checkModificationAlone
bool checkModificationAlone(const GraphChange &change) const
checks whether the constraints enable to perform a graph change
Definition
structuralConstraintForbiddenArcs.cpp:104
gum::learning::StructuralConstraintForbiddenArcs::~StructuralConstraintForbiddenArcs
virtual ~StructuralConstraintForbiddenArcs()
destructor
Definition
structuralConstraintForbiddenArcs.cpp:85
gum::learning::StructuralConstraintForbiddenArcs::checkArcTriangleDeletion2Alone
bool checkArcTriangleDeletion2Alone(NodeId node1, NodeId node2, NodeId node3) const
checks whether the constraints enable to apply an ArcTriangleDeletion2
gum::learning::StructuralConstraintForbiddenArcs::_forbidden_arcs_
ArcSet _forbidden_arcs_
the ForbiddenArcs on which we perform checks
Definition
structuralConstraintForbiddenArcs.h:249
gum::learning::StructuralConstraintForbiddenArcs::operator=
StructuralConstraintForbiddenArcs & operator=(const StructuralConstraintForbiddenArcs &from)
copy operator
Definition
structuralConstraintForbiddenArcs.cpp:90
gum::learning::StructuralConstraintForbiddenArcs::checkArcReversalAlone
bool checkArcReversalAlone(NodeId x, NodeId y) const
checks whether the constraints enable to reverse arc (x,y)
gum::learning::StructuralConstraintForbiddenArcs::checkArcTriangleDeletion1Alone
bool checkArcTriangleDeletion1Alone(NodeId node1, NodeId node2, NodeId node3) const
checks whether the constraints enable to apply an ArcTriangleDeletion1
gum::learning::StructuralConstraintForbiddenArcs::isAlwaysInvalidAlone
bool isAlwaysInvalidAlone(const GraphChange &change) const
indicates whether a change will always violate the constraint
Definition
structuralConstraintForbiddenArcs.cpp:129
gum::learning::StructuralConstraintForbiddenArcs::checkArcDeletionAlone
bool checkArcDeletionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to remove arc (x,y)
gum::learning::StructuralConstraintForbiddenArcs::StructuralConstraintForbiddenArcs
StructuralConstraintForbiddenArcs()
default constructor
Definition
structuralConstraintForbiddenArcs.cpp:61
gum::learning::StructuralConstraintForbiddenArcs::checkArcAdditionAlone
bool checkArcAdditionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to add arc (x,y)
GUM_ERROR
#define GUM_ERROR(type, msg)
Definition
exceptions.h:76
gum::graph
Definition
bayesBall.h:79
gum::learning
include the inlined functions if necessary
Definition
CSVParser.h:55
gum::learning::GraphChangeType::ARC_DELETION
@ ARC_DELETION
Definition
graphChange.h:76
gum::learning::GraphChangeType::ARC_REVERSAL
@ ARC_REVERSAL
Definition
graphChange.h:77
gum::learning::GraphChangeType::ARC_ADDITION
@ ARC_ADDITION
Definition
graphChange.h:75
gum::learning::GraphChangeType::ARC_TRIANGLE_DELETION1
@ ARC_TRIANGLE_DELETION1
Definition
graphChange.h:78
gum::learning::GraphChangeType::ARC_TRIANGLE_DELETION2
@ ARC_TRIANGLE_DELETION2
Definition
graphChange.h:79
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
std
STL namespace.
structuralConstraintForbiddenArcs.h
the structural constraint for forbidding the creation of some arcs during structure learning
structuralConstraintForbiddenArcs_inl.h
the structural constraint for forbidding the creation of some arcs during structure learning
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0