aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
multiDimFunctionGraphManager.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
41
51#ifndef GUM_MULTI_DIM_FUNCTION_GRAPH_MANAGER_H
52# define GUM_MULTI_DIM_FUNCTION_GRAPH_MANAGER_H
53
54# include <agrum/agrum.h>
55
58
59namespace gum {
60
61 template < typename GUM_SCALAR, template < typename > class TerminalNodePolicy >
63
96 template < typename GUM_SCALAR, template < typename > class TerminalNodePolicy >
98 // =========================================================================
100 // =========================================================================
102
111
118
119 protected:
122
123 public:
128
130 // =========================================================================
132 // =========================================================================
134
139 void setRootNode(const NodeId& root);
140
150
164 virtual NodeId addInternalNode(const DiscreteVariable* var, NodeId* sons) = 0;
165
166 protected:
174
175 public:
189
200 NodeId addTerminalNode(const GUM_SCALAR& value);
201
212 void eraseNode(NodeId id, NodeId replacingId = 0, bool updateParents = true);
213
215 // =========================================================================
217 // =========================================================================
219
226 void setSon(const NodeId& node, const Idx& modality, const NodeId& sonNode);
227
228
232 void minimizeSize();
233
239 void moveTo(const DiscreteVariable* x, Idx desiredPos);
240
241 private:
252 void _adjacentSwap_(const DiscreteVariable* x, const DiscreteVariable* y);
253
254 protected:
262 void migrateNode_(const NodeId& x, const NodeId& y);
263
265 // =========================================================================
267 // =========================================================================
269
270 protected:
285
286 private:
300
310 bool _isRedundant_(const DiscreteVariable* var, NodeId* sons);
311
312 public:
316 virtual void reduce() = 0;
317
318 protected:
322 void reduce_();
323
325
326 public:
330 void clean();
331
332 private:
335 };
336
337 // ===========================================================================
338 // MultiDimFunctionGraphTreeManager
339 // ===========================================================================
340
356 template < typename GUM_SCALAR, template < typename > class TerminalNodePolicy >
358 public MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > {
363
364 // ========================================================================
366 // ========================================================================
368
373
374 public:
379
381 // ========================================================================
383 // ========================================================================
385 virtual NodeId addInternalNode(const DiscreteVariable* var, NodeId* sons);
386
387 virtual void reduce();
389 };
390
391 // ===========================================================================
392 // MultiDimFunctionGraphROManager
393 // ===========================================================================
394
410 template < typename GUM_SCALAR, template < typename > class TerminalNodePolicy >
412 public MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > {
417
418 // ========================================================================
420 // ========================================================================
423
424 public:
426
428 // ========================================================================
430 // ========================================================================
432
433 virtual NodeId addInternalNode(const DiscreteVariable* var, NodeId* sons);
434
435 virtual void reduce();
436
438 };
439
440} // namespace gum
441
442// ============================================================================
444// ============================================================================
445#endif // GUM_MULTI_DIM_FUNCTION_GRAPH_MANAGER_H
446// ============================================================================
Base class for discrete random variable.
void eraseNode(NodeId id, NodeId replacingId=0, bool updateParents=true)
Erases a node from the diagram.
bool _isRedundant_(const DiscreteVariable *var, NodeId *sons)
Checks if node has the same child for every variable value.
NodeId addInternalNode_(const DiscreteVariable *var, NodeId *sons)
Adds an internal node.
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _functionGraph_
The multidimdecisiongraph supposed to be edited.
void _adjacentSwap_(const DiscreteVariable *x, const DiscreteVariable *y)
Swap two adjacent variable.
void reduce_()
Ensures that every isomorphic subgraphs are merged together.
void migrateNode_(const NodeId &x, const NodeId &y)
Remaps all arcs going to ou going from the first given node to the second node, then delete first nod...
void moveTo(const DiscreteVariable *x, Idx desiredPos)
Changes var position in variable sequence.
void clean()
Removes var without nodes in the diagram.
void setRootNode(const NodeId &root)
Sets root node of decision diagram.
void minimizeSize()
Performs a sifting in search of a(local) minimal size.
NodeId addTerminalNode(const GUM_SCALAR &value)
Adds a value to the MultiDimFunctionGraph.
virtual NodeId addInternalNode(const DiscreteVariable *var, NodeId *sons)=0
Inserts a new non terminal node in graph.
virtual void reduce()=0
Ensures that every isomorphic subgraphs are merged together.
MultiDimFunctionGraphManager(MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *master)
Default constructor.
NodeId addInternalNode(const DiscreteVariable *var)
Inserts a new non terminal node in graph.
NodeId _checkIsomorphism_(const DiscreteVariable *var, NodeId *sons)
Checks if a similar node does not already exists in the graph.
void setSon(const NodeId &node, const Idx &modality, const NodeId &sonNode)
Sets nodes son for given modality to designated son node.
NodeId nodeRedundancyCheck_(const DiscreteVariable *var, NodeId *sonsMap)
Check for redundancy.
MultiDimFunctionGraphROManager(MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *master)
virtual void reduce()
Ensures that every isomorphic subgraphs are merged together.
virtual NodeId addInternalNode(const DiscreteVariable *var, NodeId *sons)
Inserts a new non terminal node in graph.
MultiDimFunctionGraphTreeManager(MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *master)
Class constructor.
virtual NodeId addInternalNode(const DiscreteVariable *var, NodeId *sons)
Inserts a new non terminal node in graph.
virtual void reduce()
Ensures that every isomorphic subgraphs are merged together.
Class implementingting a function graph.
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
Size Idx
Type for indexes.
Definition types.h:79
Size NodeId
Type for node ids.
Headers of the InternalNode class.
Template methods of gum::MultiDimFunctionGraphManager.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Base node set class for graphs.