aGrUM 3.1.1
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-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
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
89
92
94
95 // ===========================================================================
97 // ===========================================================================
99
101
102 const DiscreteVariable& get(NodeId id) const;
103
105
106 NodeId get(const DiscreteVariable& var) const;
107
109 bool exists(NodeId id) const;
110
112 bool exists(const DiscreteVariable& var) const;
113
115 bool exists(std::string_view name) const;
116
118
124
126
127 void erase(NodeId id);
128
130
131 void erase(const DiscreteVariable& var);
132
134
136 void changeName(NodeId id, std::string_view new_name);
137
139 void clear();
140
142 Size size() const;
143
145 std::string toString() const;
146
153 const std::string& name(NodeId id) const;
154
161 const std::string& name(const DiscreteVariable& var) const;
162
164
165 // ===========================================================================
167 // ===========================================================================
169
171
173
175
177
179
180 // ===========================================================================
182 // ===========================================================================
184
186 NodeId idFromName(std::string_view name) const;
187 const DiscreteVariable& variableFromName(std::string_view name) const;
188
190
191 private:
193 void _copy_(const VariableNodeMap& source);
194
197
200 };
201
203
204 std::ostream& operator<<(std::ostream&, const VariableNodeMap&);
205
206} /* namespace gum */
207
208#ifndef GUM_NO_INLINE
210#endif /* GUM_NO_INLINE */
211
212#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:1640
Base class for discrete random variable.
Container used to map discrete variables with nodes.
VariableNodeMap(VariableNodeMap &&source)
Move constructor.
VariableNodeMap & operator=(const VariableNodeMap &source)
Copy operator.
void _copy_(const VariableNodeMap &source)
effectively do the copy (for copy constructor or operator=)
VariableNodeMap & operator=(VariableNodeMap &&source)
Move assignment operator.
void erase(const DiscreteVariable &var)
Removes a var and it's id of this mapping. The pointer is deleted.
void changeName(NodeId id, std::string_view new_name)
we allow the user to change the name of a variable
~VariableNodeMap()
Destructor.
const std::string & name(const DiscreteVariable &var) const
Returns the name of a variable.
const DiscreteVariable & variableFromName(std::string_view name) const
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.
NodeId idFromName(std::string_view name) const
bool exists(std::string_view name) const
Return true if name 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.
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
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
Inlined implementation of VariableNodeMap.