aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::VariableNodeMap Class Reference

Container used to map discrete variables with nodes. More...

#include <variableNodeMap.h>

Collaboration diagram for gum::VariableNodeMap:

Public Member Functions

Constructors / Destructors
 VariableNodeMap ()
 Default constructor.
 VariableNodeMap (const VariableNodeMap &source)
 Copy constructor Proceed a deep copy: all variables are copied but keep the same node id.
 ~VariableNodeMap ()
 Destructor.
VariableNodeMapoperator= (const VariableNodeMap &source)
 Copy operator.
Getters and setters.
const DiscreteVariableget (NodeId id) const
 Returns a discrete variable given it's node id.
NodeId get (const DiscreteVariable &var) const
 Returns a node id given it's variable.
bool exists (NodeId id) const
 Return true if id matches a node.
bool exists (const DiscreteVariable &var) const
 Return true if var matches a node.
NodeId insert (NodeId id, const DiscreteVariable &var)
 Maps id with var.
void erase (NodeId id)
 Removes a var and it's id of this mapping. The pointer is deleted.
void erase (const DiscreteVariable &var)
 Removes a var and it's id of this mapping. The pointer is deleted.
void changeName (NodeId id, const std::string &new_name)
 we allow the user to change the name of a variable
void clear ()
 removes all the associations
Size size () const
 give the size
std::string toString () const
 friendly displays the content of the VariableNodeMap
const std::string & name (NodeId id) const
 Returns the name of a variable given its id.
const std::string & name (const DiscreteVariable &var) const
 Returns the name of a variable.
Operators.
const DiscreteVariableoperator[] (NodeId id) const
 Returns a discrete variable given it's node id.
NodeId operator[] (const DiscreteVariable &var) const
 Returns a node id given it's variable.
Accessor by name
NodeId idFromName (const std::string &name) const
const DiscreteVariablevariableFromName (const std::string &name) const

Private Member Functions

void _copy_ (const VariableNodeMap &source)
 effectively do the copy (for copy constructor or operator=)

Private Attributes

Bijection< NodeId, const DiscreteVariable * > _nodes2vars_
 Bijection between the node's NodeIds and the variables.
Bijection< std::string, NodeId_names2nodes_
 HashTable for easely find an id from a name.

Detailed Description

Container used to map discrete variables with nodes.

Warning
VariableNodeMap ensures that every name of variable is unique in the container.

Definition at line 68 of file variableNodeMap.h.

Constructor & Destructor Documentation

◆ VariableNodeMap() [1/2]

gum::VariableNodeMap::VariableNodeMap ( )

Default constructor.

Referenced by VariableNodeMap(), _copy_(), and operator=().

Here is the caller graph for this function:

◆ VariableNodeMap() [2/2]

gum::VariableNodeMap::VariableNodeMap ( const VariableNodeMap & source)

Copy constructor Proceed a deep copy: all variables are copied but keep the same node id.

References VariableNodeMap().

Here is the call graph for this function:

◆ ~VariableNodeMap()

gum::VariableNodeMap::~VariableNodeMap ( )

Destructor.

Member Function Documentation

◆ _copy_()

void gum::VariableNodeMap::_copy_ ( const VariableNodeMap & source)
private

effectively do the copy (for copy constructor or operator=)

References VariableNodeMap().

Here is the call graph for this function:

◆ changeName()

void gum::VariableNodeMap::changeName ( NodeId id,
const std::string & new_name )

we allow the user to change the name of a variable

Exceptions
DuplicateLabelif this name already exists
NotFoundRaised if no nodes matches id.

◆ clear()

void gum::VariableNodeMap::clear ( )

removes all the associations

◆ erase() [1/2]

void gum::VariableNodeMap::erase ( const DiscreteVariable & var)

Removes a var and it's id of this mapping. The pointer is deleted.

Exceptions
NotFoundRaised if no nodes matches id.

◆ erase() [2/2]

void gum::VariableNodeMap::erase ( NodeId id)

Removes a var and it's id of this mapping. The pointer is deleted.

Exceptions
NotFoundRaised if no nodes matches id.

◆ exists() [1/2]

bool gum::VariableNodeMap::exists ( const DiscreteVariable & var) const

Return true if var matches a node.

◆ exists() [2/2]

bool gum::VariableNodeMap::exists ( NodeId id) const

Return true if id matches a node.

◆ get() [1/2]

NodeId gum::VariableNodeMap::get ( const DiscreteVariable & var) const

Returns a node id given it's variable.

Exceptions
NotFoundRaised if no nodes matches var.

◆ get() [2/2]

const DiscreteVariable & gum::VariableNodeMap::get ( NodeId id) const

Returns a discrete variable given it's node id.

Exceptions
NotFoundRaised if no nodes matches id.

Referenced by gum::learning::DAG2BNLearner::createBNwithEM(), and gum::GraphicalModel::variables().

Here is the caller graph for this function:

◆ idFromName()

NodeId gum::VariableNodeMap::idFromName ( const std::string & name) const
Exceptions
NotFoundif no such name exists in the graph.

References name().

Here is the call graph for this function:

◆ insert()

NodeId gum::VariableNodeMap::insert ( NodeId id,
const DiscreteVariable & var )

Maps id with var.

Warning
Var is added by copy.
Exceptions
DuplicateLabelif this name already exists
DuplicateElementif this id already exists
Returns
Returns id (useful in some case);

◆ name() [1/2]

const std::string & gum::VariableNodeMap::name ( const DiscreteVariable & var) const

Returns the name of a variable.

Parameters
varThe variable.
Returns
var's name.
Exceptions
NotFoundRaised if var is not in this VariableNodeMap.

◆ name() [2/2]

const std::string & gum::VariableNodeMap::name ( NodeId id) const

Returns the name of a variable given its id.

Parameters
idThe variable's id.
Returns
id's name.
Exceptions
NotFoundRaised if no variable matches id.

Referenced by gum::IBayesNet< double >::empty(), idFromName(), and variableFromName().

Here is the caller graph for this function:

◆ operator=()

VariableNodeMap & gum::VariableNodeMap::operator= ( const VariableNodeMap & source)

Copy operator.

References VariableNodeMap().

Here is the call graph for this function:

◆ operator[]() [1/2]

NodeId gum::VariableNodeMap::operator[] ( const DiscreteVariable & var) const

Returns a node id given it's variable.

Exceptions
NotFoundRaised if no nodes matches var.

◆ operator[]() [2/2]

const DiscreteVariable & gum::VariableNodeMap::operator[] ( NodeId id) const

Returns a discrete variable given it's node id.

Exceptions
NotFoundRaised if no nodes matches id.

◆ size()

Size gum::VariableNodeMap::size ( ) const

give the size

◆ toString()

std::string gum::VariableNodeMap::toString ( ) const

friendly displays the content of the VariableNodeMap

◆ variableFromName()

const DiscreteVariable & gum::VariableNodeMap::variableFromName ( const std::string & name) const
Exceptions
NotFoundif no such name exists in the graph.

References name().

Referenced by gum::IBayesNet< double >::ids().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _names2nodes_

Bijection< std::string, NodeId > gum::VariableNodeMap::_names2nodes_
private

HashTable for easely find an id from a name.

Definition at line 190 of file variableNodeMap.h.

◆ _nodes2vars_

Bijection< NodeId, const DiscreteVariable* > gum::VariableNodeMap::_nodes2vars_
private

Bijection between the node's NodeIds and the variables.

Definition at line 187 of file variableNodeMap.h.


The documentation for this class was generated from the following file: