aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
structuralConstraintUndiGraph_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 StructuralConstraintUndiGraph::setGraphAlone(const UndiGraph& graph) {
57 _UndiGraph_graph_ = graph;
58 }
59
62 return _UndiGraph_graph_.existsNode(x) && _UndiGraph_graph_.existsNode(y)
63 && !_UndiGraph_graph_.existsEdge(x, y);
64 }
65
68 return _UndiGraph_graph_.existsEdge(x, y);
69 }
70
72 INLINE bool
74 return checkEdgeAdditionAlone(change.node1(), change.node2());
75 }
76
78 INLINE bool
80 return checkEdgeDeletionAlone(change.node1(), change.node2());
81 }
82
84 INLINE bool
86 switch (change.type()) {
88 return checkEdgeAdditionAlone(change.node1(), change.node2());
89
91 return checkEdgeDeletionAlone(change.node1(), change.node2());
92
93 default :
94 GUM_ERROR(OperationNotAllowed,
95 "arc modifications are not "
96 "supported by StructuralConstraintUndiGraph");
97 }
98 }
99
102 _UndiGraph_graph_.addEdge(change.node1(), change.node2());
103 }
104
107 _UndiGraph_graph_.eraseEdge(Edge(change.node1(), change.node2()));
108 }
109
112 switch (change.type()) {
114 modifyGraphAlone(reinterpret_cast< const EdgeAddition& >(change));
115 break;
116
118 modifyGraphAlone(reinterpret_cast< const EdgeDeletion& >(change));
119 break;
120
121 default :
122 GUM_ERROR(OperationNotAllowed,
123 "arc modifications are not supported "
124 "by StructuralConstraintUndiGraph");
125 }
126 }
127
130 return false;
131 }
132
134 INLINE void StructuralConstraintUndiGraph::setGraph(Size nb_nodes) {
135 _UndiGraph_graph_.clear();
136 for (NodeId i = 0; i < nb_nodes; ++i) {
137 _UndiGraph_graph_.addNodeWithId(i);
138 }
139 }
140
141// include all the methods applicable to the whole class hierarchy
142# define GUM_CONSTRAINT_CLASS_NAME StructuralConstraintUndiGraph
144# undef GUM_CONSTRAINT_CLASS_NAME
145
146 } /* namespace learning */
147
148} /* namespace gum */
149
150#endif /* DOXYGEN_SHOULD_SKIP_THIS */
The class for notifying learning algorithms of new edge additions.
The class for notifying learning algorithms of edge removals.
bool checkEdgeDeletionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to remove edge (x,y)
UndiGraph _UndiGraph_graph_
the UndiGraph on which we perform checks
void setGraphAlone(const UndiGraph &graph)
sets a new graph from which we will perform checkings
void modifyGraphAlone(const EdgeAddition &change)
notify the constraint of a modification of the graph
bool checkEdgeAdditionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to add edge (x,y)
void setGraph(Size nb_nodes)
sets a new empty graph from which we will perform checkings
bool isAlwaysInvalidAlone(const GraphChange &change) const
indicates whether a change will always violate the constraint
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