aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
structuralConstraintIndegree_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
50#ifndef DOXYGEN_SHOULD_SKIP_THIS
51
52namespace gum {
53
54 namespace learning {
55
57 INLINE void StructuralConstraintIndegree::setGraphAlone(const DiGraph& graph) {
58 // check that the max_indegree corresponds to the graph
59 for (const auto id: graph) {
60 if (!_Indegree_max_parents_.exists(id)) {
62 }
63 }
64 }
65
68 return (_Indegree_max_parents_[y] > _DiGraph_graph_.parents(y).size());
69 }
70
73 return true;
74 }
75
78 return (_Indegree_max_parents_[x] > _DiGraph_graph_.parents(x).size());
79 }
80
82 INLINE bool
84 return checkArcAdditionAlone(change.node1(), change.node2());
85 }
86
88 INLINE bool
90 return checkArcDeletionAlone(change.node1(), change.node2());
91 }
92
94 INLINE bool
96 return checkArcReversalAlone(change.node1(), change.node2());
97 }
98
100 INLINE bool
102 switch (change.type()) {
104 return checkArcAdditionAlone(change.node1(), change.node2());
105
107 return checkArcDeletionAlone(change.node1(), change.node2());
108
110 return checkArcReversalAlone(change.node1(), change.node2());
111
112 default :
113 GUM_ERROR(OperationNotAllowed,
114 "edge modifications are not "
115 "supported by StructuralConstraintIndegree");
116 }
117 }
118
121
124
127
130
132 INLINE bool
134 if ((change.type() == GraphChangeType::ARC_ADDITION)
135 && (_Indegree_max_parents_[change.node2()] == 0)) {
136 return true;
137 } else if ((change.type() == GraphChangeType::ARC_REVERSAL)
138 && (_Indegree_max_parents_[change.node1()] == 0)) {
139 return true;
140 } else {
141 return false;
142 }
143 }
144
146 INLINE void
148 for (const auto& degree: max_indegree) {
149 _Indegree_max_parents_.set(degree.first, degree.second);
150 }
151 }
152
154 INLINE void StructuralConstraintIndegree::setMaxIndegree(Size max_indegree, bool update_all) {
155 if (update_all) {
156 for (auto& degree: _Indegree_max_parents_) {
157 degree.second = max_indegree;
158 }
159 }
160
161 _Indegree_max_indegree_ = max_indegree;
162 }
163
164// include all the methods applicable to the whole class hierarchy
165# define GUM_CONSTRAINT_CLASS_NAME StructuralConstraintIndegree
167# undef GUM_CONSTRAINT_CLASS_NAME
168
169 } /* namespace learning */
170
171} /* namespace gum */
172
173#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.
Size _Indegree_max_indegree_
a default max indegree to assign for nodes without specified indegree
bool checkModificationAlone(const ArcAddition &change) const
checks whether the constraints enable to add an arc
void setMaxIndegree(Size max_indegree, bool update_all_node=false)
resets the default max indegree and possibly updates the indegree of all nodes
void modifyGraphAlone(const ArcAddition &change)
notify the constraint of a modification of the graph
bool isAlwaysInvalidAlone(const GraphChange &change) const
indicates whether a change will always violate the constraint
bool checkArcDeletionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to remove arc (x,y)
void setIndegree(const NodeProperty< Size > &max_indegree)
sets the default max indegree for all the nodes in the property
void setGraphAlone(const DiGraph &graph)
sets a new graph from which we will perform checkings
bool checkArcReversalAlone(NodeId x, NodeId y) const
checks whether the constraints enable to reverse arc (x,y)
NodeProperty< Size > _Indegree_max_parents_
the max number of parents per node
bool checkArcAdditionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to add arc (x,y)
#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.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
include the inlined functions if necessary
Definition CSVParser.h:54
gum is the global namespace for all aGrUM entities
Definition agrum.h:46