aGrUM 3.1.1
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-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#pragma once
42
43
51#ifndef DOXYGEN_SHOULD_SKIP_THIS
52
53namespace gum {
54
55 namespace learning {
56
58 INLINE void StructuralConstraintUndiGraph::setGraphAlone(const UndiGraph& graph) {
59 _UndiGraph_graph_ = graph;
60 }
61
64 return _UndiGraph_graph_.existsNode(x) && _UndiGraph_graph_.existsNode(y)
65 && !_UndiGraph_graph_.existsEdge(x, y);
66 }
67
70 return _UndiGraph_graph_.existsEdge(x, y);
71 }
72
74 INLINE bool
76 return checkEdgeAdditionAlone(change.node1(), change.node2());
77 }
78
80 INLINE bool
82 return checkEdgeDeletionAlone(change.node1(), change.node2());
83 }
84
86 INLINE bool
88 switch (change.type()) {
90 return checkEdgeAdditionAlone(change.node1(), change.node2());
91
93 return checkEdgeDeletionAlone(change.node1(), change.node2());
94
95 default :
96 GUM_ERROR(OperationNotAllowed,
97 "arc modifications are not "
98 "supported by StructuralConstraintUndiGraph");
99 }
100 }
101
104 _UndiGraph_graph_.addEdge(change.node1(), change.node2());
105 }
106
109 _UndiGraph_graph_.eraseEdge(Edge(change.node1(), change.node2()));
110 }
111
114 switch (change.type()) {
116 modifyGraphAlone(reinterpret_cast< const EdgeAddition& >(change));
117 break;
118
120 modifyGraphAlone(reinterpret_cast< const EdgeDeletion& >(change));
121 break;
122
123 default :
124 GUM_ERROR(OperationNotAllowed,
125 "arc modifications are not supported "
126 "by StructuralConstraintUndiGraph");
127 }
128 }
129
132 return false;
133 }
134
136 INLINE void StructuralConstraintUndiGraph::setGraph(Size nb_nodes) {
137 _UndiGraph_graph_.clear();
138 for (NodeId i = 0; i < nb_nodes; ++i) {
139 _UndiGraph_graph_.addNodeWithId(i);
140 }
141 }
142
143// include all the methods applicable to the whole class hierarchy
144# define GUM_CONSTRAINT_CLASS_NAME StructuralConstraintUndiGraph
146# undef GUM_CONSTRAINT_CLASS_NAME
147
148 } /* namespace learning */
149
150} /* namespace gum */
151
152#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:76
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:55
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
the base class for structural constraints used by learning algorithms that learn an undirected graph ...