aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
variableNodeMap.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
48#ifndef GUM_VARIABLE_NODE_MAP_H
49#define GUM_VARIABLE_NODE_MAP_H
50
51#include <iostream>
52#include <string>
53
54#include <agrum/agrum.h>
55
59
60namespace gum {
61
69 public:
71
73
76
80
83
86
88
89 // ===========================================================================
91 // ===========================================================================
93
95
96 const DiscreteVariable& get(NodeId id) const;
97
99
100 NodeId get(const DiscreteVariable& var) const;
101
103 bool exists(NodeId id) const;
104
106 bool exists(const DiscreteVariable& var) const;
107
109
115
117
118 void erase(NodeId id);
119
121
122 void erase(const DiscreteVariable& var);
123
125
127 void changeName(NodeId id, const std::string& new_name);
128
130 void clear();
131
133 Size size() const;
134
136 std::string toString() const;
137
144 const std::string& name(NodeId id) const;
145
152 const std::string& name(const DiscreteVariable& var) const;
153
155
156 // ===========================================================================
158 // ===========================================================================
160
162
164
166
168
170
171 // ===========================================================================
173 // ===========================================================================
175
177 NodeId idFromName(const std::string& name) const;
178 const DiscreteVariable& variableFromName(const std::string& name) const;
179
181
182 private:
184 void _copy_(const VariableNodeMap& source);
185
188
191 };
192
194
195 std::ostream& operator<<(std::ostream&, const VariableNodeMap&);
196
197} /* namespace gum */
198
199#ifndef GUM_NO_INLINE
201#endif /* GUM_NO_INLINE */
202
203#endif /* GUM_VARIABLE_NODE_MAP_H*/
Set of pairs of elements with fast search for both elements.
Set of pairs of elements with fast search for both elements.
Definition bijection.h:1594
Base class for discrete random variable.
Container used to map discrete variables with nodes.
const DiscreteVariable & variableFromName(const std::string &name) const
VariableNodeMap & operator=(const VariableNodeMap &source)
Copy operator.
void _copy_(const VariableNodeMap &source)
effectively do the copy (for copy constructor or operator=)
void erase(const DiscreteVariable &var)
Removes a var and it's id of this mapping. The pointer is deleted.
~VariableNodeMap()
Destructor.
const std::string & name(const DiscreteVariable &var) const
Returns the name of a variable.
bool exists(const DiscreteVariable &var) const
Return true if var matches a node.
bool exists(NodeId id) const
Return true if id matches a node.
void erase(NodeId id)
Removes a var and it's id of this mapping. The pointer is deleted.
Bijection< std::string, NodeId > _names2nodes_
HashTable for easely find an id from a name.
NodeId get(const DiscreteVariable &var) const
Returns a node id given it's variable.
const DiscreteVariable & get(NodeId id) const
Returns a discrete variable given it's node id.
const DiscreteVariable & operator[](NodeId id) const
Returns a discrete variable given it's node id.
NodeId idFromName(const std::string &name) const
void clear()
removes all the associations
VariableNodeMap(const VariableNodeMap &source)
Copy constructor Proceed a deep copy: all variables are copied but keep the same node id.
const std::string & name(NodeId id) const
Returns the name of a variable given its id.
Bijection< NodeId, const DiscreteVariable * > _nodes2vars_
Bijection between the node's NodeIds and the variables.
std::string toString() const
friendly displays the content of the VariableNodeMap
NodeId operator[](const DiscreteVariable &var) const
Returns a node id given it's variable.
Size size() const
give the size
void changeName(NodeId id, const std::string &new_name)
we allow the user to change the name of a variable
NodeId insert(NodeId id, const DiscreteVariable &var)
Maps id with var.
VariableNodeMap()
Default constructor.
Base class for discrete random variable.
some utils for topology : NodeId, Edge, Arc and consorts ...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size NodeId
Type for node ids.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
Definition AVLTree.h:913
Inlined implementation of VariableNodeMap.