aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
structuralConstraintNoParentNodes.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/structuralConstraintNoParentNodes.h
>
50
52
#ifdef GUM_NO_INLINE
53
# include <
agrum/BN/learning/constraints/structuralConstraintNoParentNodes_inl.h
>
54
#endif
/* GUM_NO_INLINE */
55
56
57
namespace
gum::learning
{
58
60
StructuralConstraintNoParentNodes::StructuralConstraintNoParentNodes
() {
61
GUM_CONSTRUCTOR(
StructuralConstraintNoParentNodes
);
62
}
63
65
StructuralConstraintNoParentNodes::StructuralConstraintNoParentNodes
(
const
DiGraph
&
graph
) {
66
setGraph(
graph
);
67
GUM_CONSTRUCTOR(
StructuralConstraintNoParentNodes
);
68
}
69
71
StructuralConstraintNoParentNodes::StructuralConstraintNoParentNodes
(
72
const
StructuralConstraintNoParentNodes
& from) :
_noParentNodes_
(from.
_noParentNodes_
) {
73
GUM_CONS_CPY(
StructuralConstraintNoParentNodes
);
74
}
75
77
StructuralConstraintNoParentNodes::StructuralConstraintNoParentNodes
(
78
StructuralConstraintNoParentNodes
&& from) :
_noParentNodes_
(
std
::move(from.
_noParentNodes_
)) {
79
GUM_CONS_MOV(
StructuralConstraintNoParentNodes
);
80
}
81
83
StructuralConstraintNoParentNodes::~StructuralConstraintNoParentNodes
() {
84
GUM_DESTRUCTOR(
StructuralConstraintNoParentNodes
);
85
}
86
88
StructuralConstraintNoParentNodes
&
89
StructuralConstraintNoParentNodes::operator=
(
const
StructuralConstraintNoParentNodes
& from) {
90
if
(
this
!= &from) {
_noParentNodes_
= from.
_noParentNodes_
; }
91
return
*
this
;
92
}
93
95
StructuralConstraintNoParentNodes
&
96
StructuralConstraintNoParentNodes::operator=
(
StructuralConstraintNoParentNodes
&& from) {
97
if
(
this
!= &from) {
_noParentNodes_
= std::move(from._noParentNodes_); }
98
return
*
this
;
99
}
100
101
bool
StructuralConstraintNoParentNodes::checkModificationAlone
(
const
GraphChange
& change)
const
{
102
switch
(change.
type
()) {
103
case
GraphChangeType::ARC_ADDITION
:
104
return
checkArcAdditionAlone
(change.
node1
(), change.
node2
());
105
106
case
GraphChangeType::ARC_DELETION
:
107
return
checkArcDeletionAlone
(change.
node1
(), change.
node2
());
108
109
case
GraphChangeType::ARC_REVERSAL
:
110
return
checkArcReversalAlone
(change.
node1
(), change.
node2
());
111
112
case
GraphChangeType::ARC_TRIANGLE_DELETION1
:
113
return
checkArcTriangleDeletion1Alone
(change.
node1
(), change.
node2
(), change.
node3
());
114
115
case
GraphChangeType::ARC_TRIANGLE_DELETION2
:
116
return
checkArcTriangleDeletion2Alone
(change.
node1
(), change.
node2
(), change.
node3
());
117
118
default :
119
GUM_ERROR
(
OperationNotAllowed
,
120
"edge modifications are not "
121
"supported by the No-Parent Nodes structural constraint"
);
122
}
123
}
124
}
// namespace gum::learning
gum::DiGraph
Base class for all oriented graphs.
Definition
diGraph.h:132
OperationNotAllowed
Exception : operation not allowed.
gum::learning::GraphChange
Definition
graphChange.h:101
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::StructuralConstraintNoParentNodes
the structural constraint for forbidding parents for some nodes
Definition
structuralConstraintNoParentNodes.h:61
gum::learning::StructuralConstraintNoParentNodes::_noParentNodes_
NodeSet _noParentNodes_
the ForbiddenArcs on which we perform checks
Definition
structuralConstraintNoParentNodes.h:216
gum::learning::StructuralConstraintNoParentNodes::checkArcDeletionAlone
bool checkArcDeletionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to remove arc (x,y)
gum::learning::StructuralConstraintNoParentNodes::operator=
StructuralConstraintNoParentNodes & operator=(const StructuralConstraintNoParentNodes &from)
copy operator
Definition
structuralConstraintNoParentNodes.cpp:89
gum::learning::StructuralConstraintNoParentNodes::checkArcTriangleDeletion2Alone
bool checkArcTriangleDeletion2Alone(NodeId node1, NodeId node2, NodeId node3) const
checks whether the constraints enable to apply an ArcTriangleDeletion2
gum::learning::StructuralConstraintNoParentNodes::StructuralConstraintNoParentNodes
StructuralConstraintNoParentNodes()
default constructor
Definition
structuralConstraintNoParentNodes.cpp:60
gum::learning::StructuralConstraintNoParentNodes::checkModificationAlone
bool checkModificationAlone(const GraphChange &change) const
checks whether the constraints enable to perform a graph change
Definition
structuralConstraintNoParentNodes.cpp:101
gum::learning::StructuralConstraintNoParentNodes::~StructuralConstraintNoParentNodes
virtual ~StructuralConstraintNoParentNodes()
destructor
Definition
structuralConstraintNoParentNodes.cpp:83
gum::learning::StructuralConstraintNoParentNodes::checkArcTriangleDeletion1Alone
bool checkArcTriangleDeletion1Alone(NodeId node1, NodeId node2, NodeId node3) const
checks whether the constraints enable triangle deletion1
gum::learning::StructuralConstraintNoParentNodes::checkArcReversalAlone
bool checkArcReversalAlone(NodeId x, NodeId y) const
checks whether the constraints enable to reverse arc (x,y)
gum::learning::StructuralConstraintNoParentNodes::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
std
STL namespace.
structuralConstraintNoParentNodes.h
the structural constraint for forbidding parents for some nodes during structure learning
structuralConstraintNoParentNodes_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