aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
structuralConstraintDiGraph_inl.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 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-2025 *
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#pragma once
41
42
49#ifndef DOXYGEN_SHOULD_SKIP_THIS
50
51namespace gum {
52
53 namespace learning {
54
56 INLINE void StructuralConstraintDiGraph::setGraphAlone(const DiGraph& graph) {
57 _DiGraph_graph_ = graph;
58 }
59
62 return _DiGraph_graph_.existsNode(x) && _DiGraph_graph_.existsNode(y)
63 && !_DiGraph_graph_.existsArc(x, y);
64 }
65
68 return _DiGraph_graph_.existsArc(x, y);
69 }
70
73 return _DiGraph_graph_.existsArc(x, y) && !_DiGraph_graph_.existsArc(y, x);
74 }
75
77 INLINE bool
79 return checkArcAdditionAlone(change.node1(), change.node2());
80 }
81
83 INLINE bool
85 return checkArcDeletionAlone(change.node1(), change.node2());
86 }
87
89 INLINE bool
91 return checkArcReversalAlone(change.node1(), change.node2());
92 }
93
95 INLINE bool
97 switch (change.type()) {
99 return checkArcAdditionAlone(change.node1(), change.node2());
100
102 return checkArcDeletionAlone(change.node1(), change.node2());
103
105 return checkArcReversalAlone(change.node1(), change.node2());
106
107 default :
108 GUM_ERROR(OperationNotAllowed,
109 "edge modifications are not "
110 "supported by StructuralConstraintDiGraph");
111 }
112 }
113
116 _DiGraph_graph_.addArc(change.node1(), change.node2());
117 }
118
121 _DiGraph_graph_.eraseArc(Arc(change.node1(), change.node2()));
122 }
123
126 _DiGraph_graph_.eraseArc(Arc(change.node1(), change.node2()));
127 _DiGraph_graph_.addArc(change.node2(), change.node1());
128 }
129
132 switch (change.type()) {
134 modifyGraphAlone(reinterpret_cast< const ArcAddition& >(change));
135 break;
136
138 modifyGraphAlone(reinterpret_cast< const ArcDeletion& >(change));
139 break;
140
142 modifyGraphAlone(reinterpret_cast< const ArcReversal& >(change));
143 break;
144
145 default :
146 GUM_ERROR(OperationNotAllowed,
147 "edge modifications are not supported by digraph constraint")
148 }
149 }
150
153 return false;
154 }
155
157 INLINE void StructuralConstraintDiGraph::setGraph(Size nb_nodes) {
158 _DiGraph_graph_.clear();
159
160 for (NodeId i = 0; i < nb_nodes; ++i) {
161 _DiGraph_graph_.addNodeWithId(i);
162 }
163 }
164
165// include all the methods applicable to the whole class hierarchy
166# define GUM_CONSTRAINT_CLASS_NAME StructuralConstraintDiGraph
168# undef GUM_CONSTRAINT_CLASS_NAME
169
170 } /* namespace learning */
171
172} /* namespace gum */
173
174#endif /* DOXYGEN_SHOULD_SKIP_THIS */
The class for notifying learning algorithms of new arc additions.
The class for notifying learning algorithms of arc removals.
The class for notifying learning algorithms of arc reversals.
bool isAlwaysInvalidAlone(const GraphChange &change) const
indicates whether a change will always violate the constraint
void modifyGraphAlone(const ArcAddition &change)
notify the constraint of a modification of the graph
bool checkArcDeletionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to remove arc (x,y)
DiGraph _DiGraph_graph_
the DiGraph on which we perform checks
bool checkArcReversalAlone(NodeId x, NodeId y) const
checks whether the constraints enable to reverse arc (x,y)
void setGraph(Size nb_nodes)
sets a new empty graph from which we will perform checkings
void setGraphAlone(const DiGraph &graph)
sets a new graph from which we will perform checkings
bool checkArcAdditionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to add arc (x,y)
bool checkModificationAlone(const GraphChange &change) const
checks whether the constraints enable to perform a graph change
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size NodeId
Type for node ids.
include the inlined functions if necessary
Definition CSVParser.h:54
gum is the global namespace for all aGrUM entities
Definition agrum.h:46