aGrUM
3.3.2
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
structuralConstraintTotalOrder.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
47
48
#include <
agrum/BN/learning/constraints/structuralConstraintTotalOrder.h
>
49
51
#ifdef GUM_NO_INLINE
52
# include <
agrum/BN/learning/constraints/structuralConstraintTotalOrder_inl.h
>
53
#endif
/* GUM_NO_INLINE */
54
55
namespace
gum
{
56
57
namespace
learning
{
58
60
StructuralConstraintTotalOrder::StructuralConstraintTotalOrder
() {
61
GUM_CONSTRUCTOR(
StructuralConstraintTotalOrder
);
62
}
63
65
StructuralConstraintTotalOrder::StructuralConstraintTotalOrder
(
66
const
Sequence< NodeId >
& order) :
_total_order_
(order) {
67
GUM_CONSTRUCTOR(
StructuralConstraintTotalOrder
);
68
}
69
71
StructuralConstraintTotalOrder::StructuralConstraintTotalOrder
(
72
const
DiGraph
&
graph
,
73
const
Sequence< NodeId >
& order) :
_total_order_
(order) {
74
GUM_CONSTRUCTOR(
StructuralConstraintTotalOrder
);
75
}
76
78
StructuralConstraintTotalOrder::StructuralConstraintTotalOrder
(
79
const
StructuralConstraintTotalOrder
& from) :
_total_order_
(from.
_total_order_
) {
80
GUM_CONS_CPY(
StructuralConstraintTotalOrder
);
81
}
82
84
StructuralConstraintTotalOrder::StructuralConstraintTotalOrder
(
85
StructuralConstraintTotalOrder
&& from) :
_total_order_
(
std
::move(from.
_total_order_
)) {
86
GUM_CONS_MOV(
StructuralConstraintTotalOrder
);
87
}
88
90
StructuralConstraintTotalOrder::~StructuralConstraintTotalOrder
() {
91
GUM_DESTRUCTOR(
StructuralConstraintTotalOrder
);
92
}
93
95
StructuralConstraintTotalOrder
&
96
StructuralConstraintTotalOrder::operator=
(
const
StructuralConstraintTotalOrder
& from) {
97
if
(
this
!= &from) {
_total_order_
= from.
_total_order_
; }
98
return
*
this
;
99
}
100
102
StructuralConstraintTotalOrder
&
103
StructuralConstraintTotalOrder::operator=
(
StructuralConstraintTotalOrder
&& from) {
104
if
(
this
!= &from) {
_total_order_
= std::move(from._total_order_); }
105
return
*
this
;
106
}
107
108
bool
StructuralConstraintTotalOrder::isAlwaysInvalidAlone
(
const
GraphChange
& change)
const
{
109
switch
(change.
type
()) {
110
case
GraphChangeType::ARC_ADDITION
:
111
return
!
checkArcAdditionAlone
(change.
node1
(), change.
node2
());
112
113
case
GraphChangeType::ARC_DELETION
:
return
false
;
114
115
case
GraphChangeType::ARC_REVERSAL
:
116
return
!
checkArcAdditionAlone
(change.
node2
(), change.
node1
());
117
118
case
GraphChangeType::ARC_TRIANGLE_DELETION1
:
119
return
!
checkArcTriangleDeletion1Alone
(change.
node1
(), change.
node2
(), change.
node3
());
120
121
case
GraphChangeType::ARC_TRIANGLE_DELETION2
:
122
return
!
checkArcTriangleDeletion2Alone
(change.
node1
(), change.
node2
(), change.
node3
());
123
124
default :
125
GUM_ERROR
(
OperationNotAllowed
,
126
"Graph change operation "
127
<< change.
typeAsString
()
128
<<
" is not supported by the Total Order structural constraint"
);
129
}
130
}
131
132
bool
StructuralConstraintTotalOrder::checkModificationAlone
(
const
GraphChange
& change)
const
{
133
switch
(change.
type
()) {
134
case
GraphChangeType::ARC_ADDITION
:
135
return
checkArcAdditionAlone
(change.
node1
(), change.
node2
());
136
137
case
GraphChangeType::ARC_DELETION
:
138
return
checkArcDeletionAlone
(change.
node1
(), change.
node2
());
139
140
case
GraphChangeType::ARC_REVERSAL
:
141
return
checkArcReversalAlone
(change.
node1
(), change.
node2
());
142
143
case
GraphChangeType::ARC_TRIANGLE_DELETION1
:
144
return
checkArcTriangleDeletion1Alone
(change.
node1
(), change.
node2
(), change.
node3
());
145
146
case
GraphChangeType::ARC_TRIANGLE_DELETION2
:
147
return
checkArcTriangleDeletion2Alone
(change.
node1
(), change.
node2
(), change.
node3
());
148
149
default :
150
GUM_ERROR
(
OperationNotAllowed
,
151
"edge modifications are not "
152
"supported by the Total Order structural constraint"
);
153
}
154
}
155
}
/* namespace learning */
156
157
}
/* namespace gum */
gum::DiGraph
Base class for all oriented graphs.
Definition
diGraph.h:136
OperationNotAllowed
Exception : operation not allowed.
gum::Sequence< NodeId >
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::StructuralConstraintTotalOrder
the structural constraint imposing a total order over some nodes
Definition
structuralConstraintTotalOrder.h:67
gum::learning::StructuralConstraintTotalOrder::StructuralConstraintTotalOrder
StructuralConstraintTotalOrder()
default constructor
Definition
structuralConstraintTotalOrder.cpp:60
gum::learning::StructuralConstraintTotalOrder::_total_order_
Sequence< NodeId > _total_order_
the total ordering over the nodes
Definition
structuralConstraintTotalOrder.h:259
gum::learning::StructuralConstraintTotalOrder::isAlwaysInvalidAlone
bool isAlwaysInvalidAlone(const GraphChange &change) const
indicates whether a change will always violate the constraint
Definition
structuralConstraintTotalOrder.cpp:108
gum::learning::StructuralConstraintTotalOrder::checkArcTriangleDeletion2Alone
bool checkArcTriangleDeletion2Alone(NodeId node1, NodeId node2, NodeId node3) const
checks whether the constraints enable to apply an ArcTriangleDeletion2
gum::learning::StructuralConstraintTotalOrder::checkModificationAlone
bool checkModificationAlone(const ArcAddition &change) const
checks whether the constraints enable to add an arc
gum::learning::StructuralConstraintTotalOrder::checkArcAdditionAlone
bool checkArcAdditionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to add arc (x,y)
gum::learning::StructuralConstraintTotalOrder::~StructuralConstraintTotalOrder
virtual ~StructuralConstraintTotalOrder()
destructor
Definition
structuralConstraintTotalOrder.cpp:90
gum::learning::StructuralConstraintTotalOrder::checkArcTriangleDeletion1Alone
bool checkArcTriangleDeletion1Alone(NodeId node1, NodeId node2, NodeId node3) const
checks whether the constraints enable to apply an ArcTriangleDeletion1
gum::learning::StructuralConstraintTotalOrder::operator=
StructuralConstraintTotalOrder & operator=(const StructuralConstraintTotalOrder &from)
copy operator
Definition
structuralConstraintTotalOrder.cpp:96
gum::learning::StructuralConstraintTotalOrder::checkArcReversalAlone
bool checkArcReversalAlone(NodeId x, NodeId y) const
checks whether the constraints enable to reverse arc (x,y)
gum::learning::StructuralConstraintTotalOrder::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
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
std
STL namespace.
structuralConstraintTotalOrder.h
the structural constraint imposing a total ordering over some nodes
structuralConstraintTotalOrder_inl.h
the structural constraint imposing a total order over some nodes
aGrUM
3.3.2
© PHW&CG&others - 2022
DoXyGeN 1.18.0