aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
structuralConstraintNoChildrenNodes.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/structuralConstraintNoChildrenNodes.h
>
50
52
#ifdef GUM_NO_INLINE
53
# include <
agrum/BN/learning/constraints/structuralConstraintNoChildrenNodes_inl.h
>
54
#endif
/* GUM_NO_INLINE */
55
56
namespace
gum::learning
{
57
59
StructuralConstraintNoChildrenNodes::StructuralConstraintNoChildrenNodes
() {
60
GUM_CONSTRUCTOR(
StructuralConstraintNoChildrenNodes
);
61
}
62
64
StructuralConstraintNoChildrenNodes::StructuralConstraintNoChildrenNodes
(
const
DiGraph
&
graph
) {
65
setGraph(
graph
);
66
GUM_CONSTRUCTOR(
StructuralConstraintNoChildrenNodes
);
67
}
68
70
StructuralConstraintNoChildrenNodes::StructuralConstraintNoChildrenNodes
(
71
const
StructuralConstraintNoChildrenNodes
& from) :
_noChildrenNodes_
(from.
_noChildrenNodes_
) {
72
GUM_CONS_CPY(
StructuralConstraintNoChildrenNodes
);
73
}
74
76
StructuralConstraintNoChildrenNodes::StructuralConstraintNoChildrenNodes
(
77
StructuralConstraintNoChildrenNodes
&& from) :
78
_noChildrenNodes_
(
std
::move(from.
_noChildrenNodes_
)) {
79
GUM_CONS_MOV(
StructuralConstraintNoChildrenNodes
);
80
}
81
83
StructuralConstraintNoChildrenNodes::~StructuralConstraintNoChildrenNodes
() {
84
GUM_DESTRUCTOR(
StructuralConstraintNoChildrenNodes
);
85
}
86
88
StructuralConstraintNoChildrenNodes
&
StructuralConstraintNoChildrenNodes::operator=
(
89
const
StructuralConstraintNoChildrenNodes
& from) {
90
if
(
this
!= &from) {
_noChildrenNodes_
= from.
_noChildrenNodes_
; }
91
return
*
this
;
92
}
93
95
StructuralConstraintNoChildrenNodes
&
96
StructuralConstraintNoChildrenNodes::operator=
(
StructuralConstraintNoChildrenNodes
&& from) {
97
if
(
this
!= &from) {
_noChildrenNodes_
= std::move(from._noChildrenNodes_); }
98
return
*
this
;
99
}
100
101
bool
102
StructuralConstraintNoChildrenNodes::checkModificationAlone
(
const
GraphChange
& change)
const
{
103
switch
(change.
type
()) {
104
case
GraphChangeType::ARC_ADDITION
:
105
return
checkArcAdditionAlone
(change.
node1
(), change.
node2
());
106
107
case
GraphChangeType::ARC_DELETION
:
108
return
checkArcDeletionAlone
(change.
node1
(), change.
node2
());
109
110
case
GraphChangeType::ARC_REVERSAL
:
111
return
checkArcReversalAlone
(change.
node1
(), change.
node2
());
112
113
case
GraphChangeType::ARC_TRIANGLE_DELETION1
:
114
return
checkArcTriangleDeletion1Alone
(change.
node1
(), change.
node2
(), change.
node3
());
115
116
case
GraphChangeType::ARC_TRIANGLE_DELETION2
:
117
return
checkArcTriangleDeletion2Alone
(change.
node1
(), change.
node2
(), change.
node3
());
118
119
default :
120
GUM_ERROR
(
OperationNotAllowed
,
121
"edge modifications are not "
122
"supported by the No-Children Nodes structural constraint"
);
123
}
124
}
125
126
bool
StructuralConstraintNoChildrenNodes::isAlwaysInvalidAlone
(
const
GraphChange
& change)
const
{
127
switch
(change.
type
()) {
128
case
GraphChangeType::ARC_ADDITION
:
return
_noChildrenNodes_
.
exists
(change.
node1
());
129
130
case
GraphChangeType::ARC_DELETION
:
return
false
;
131
132
case
GraphChangeType::ARC_REVERSAL
:
return
_noChildrenNodes_
.
exists
(change.
node2
());
133
134
case
GraphChangeType::ARC_TRIANGLE_DELETION1
:
135
return
_noChildrenNodes_
.
exists
(change.
node2
()) ||
_noChildrenNodes_
.
exists
(change.
node3
());
136
137
case
GraphChangeType::ARC_TRIANGLE_DELETION2
:
138
return
_noChildrenNodes_
.
exists
(change.
node1
()) ||
_noChildrenNodes_
.
exists
(change.
node3
());
139
140
default :
141
GUM_ERROR
(
OperationNotAllowed
,
142
"edge modifications are not supported "
143
"by the No-Children Nodes structural constraint"
);
144
}
145
}
146
}
// namespace gum::learning
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::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::StructuralConstraintNoChildrenNodes
the structural constraint for forbidding children for some nodes
Definition
structuralConstraintNoChildrenNodes.h:62
gum::learning::StructuralConstraintNoChildrenNodes::checkArcReversalAlone
bool checkArcReversalAlone(NodeId x, NodeId y) const
checks whether the constraints enable to reverse arc (x,y)
gum::learning::StructuralConstraintNoChildrenNodes::StructuralConstraintNoChildrenNodes
StructuralConstraintNoChildrenNodes()
default constructor
Definition
structuralConstraintNoChildrenNodes.cpp:59
gum::learning::StructuralConstraintNoChildrenNodes::checkArcTriangleDeletion2Alone
bool checkArcTriangleDeletion2Alone(NodeId node1, NodeId node2, NodeId node3) const
checks whether the constraints enable to apply an ArcTriangleDeletion2
gum::learning::StructuralConstraintNoChildrenNodes::_noChildrenNodes_
NodeSet _noChildrenNodes_
the set of w nodes without children on which we perform checks
Definition
structuralConstraintNoChildrenNodes.h:217
gum::learning::StructuralConstraintNoChildrenNodes::operator=
StructuralConstraintNoChildrenNodes & operator=(const StructuralConstraintNoChildrenNodes &from)
copy operator
Definition
structuralConstraintNoChildrenNodes.cpp:88
gum::learning::StructuralConstraintNoChildrenNodes::checkArcTriangleDeletion1Alone
bool checkArcTriangleDeletion1Alone(NodeId node1, NodeId node2, NodeId node3) const
checks whether the constraints enable to apply an ArcTriangleDeletion1
gum::learning::StructuralConstraintNoChildrenNodes::checkArcAdditionAlone
bool checkArcAdditionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to add arc (x,y)
gum::learning::StructuralConstraintNoChildrenNodes::~StructuralConstraintNoChildrenNodes
virtual ~StructuralConstraintNoChildrenNodes()
destructor
Definition
structuralConstraintNoChildrenNodes.cpp:83
gum::learning::StructuralConstraintNoChildrenNodes::isAlwaysInvalidAlone
bool isAlwaysInvalidAlone(const GraphChange &change) const
indicates whether a change will always violate the constraint
Definition
structuralConstraintNoChildrenNodes.cpp:126
gum::learning::StructuralConstraintNoChildrenNodes::checkModificationAlone
bool checkModificationAlone(const GraphChange &change) const
checks whether the constraints enable to perform a graph change
Definition
structuralConstraintNoChildrenNodes.cpp:102
gum::learning::StructuralConstraintNoChildrenNodes::checkArcDeletionAlone
bool checkArcDeletionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to remove 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.
structuralConstraintNoChildrenNodes.h
the structural constraint for forbidding children for some nodes during structure learning
structuralConstraintNoChildrenNodes_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