Construct version 5.4.4
An agent based modeling framework
Node Struct Reference

Nodes are any type of entity with or without attributes. More...

Collaboration diagram for Node:

Public Member Functions

 Node (const std::string &_name, unsigned int _index, const dynet::ParameterMap &atts)
 Constructor stores but does not take ownership of attribute pointers. More...
 
const std::string & get_attribute (const std::string &attribute_name) const
 Searches for a node attribute. More...
 
const std::string & operator[] (const std::string &attribute_name) const
 

Public Attributes

const dynet::ParameterMapattributes
 Each attribute value is stored in the parameter map at the appropriate attribute key.
 
const std::string name
 Name of the node
 
const unsigned int index
 Node index of the node
 

Detailed Description

Nodes are any type of entity with or without attributes.

Nodes are created to be linked up via networks. Nodes can have attributes which affect the dynamics of a model. Nodes are not expected to be created outside of the NodesetManager. Rather, pointers and iterators to already existing nodes are utilized.

Constructor & Destructor Documentation

◆ Node()

Node::Node ( const std::string &  _name,
unsigned int  _index,
const dynet::ParameterMap atts 
)
inline

Constructor stores but does not take ownership of attribute pointers.

Member Function Documentation

◆ get_attribute()

const std::string & Node::get_attribute ( const std::string &  attribute_name) const

Searches for a node attribute.

Uses the unordered_set::find function to find an attribute. If the attribute is not found, an empty string is returned.

Parameters
attribute_nameName of the attribute to search for.
Returns
A string corresponding to the value found for an attribute. If no attribute is found an empty string is returned.

Example

//nodeset has been preloaded with some agents; Mary, John, and Joe.
//these nodes all have the "type" attributes of person and
//"gender" attribute of "female", "male", and "male" respectively
const Nodeset* agents = construct.ns_manager.get_nodeset(nodeset_names::agent);
const Node* joe = agents->get_node_by_name("Joe");
std::string gender = joe->get_attribute("gender");
if (gender!="") std::cout << "This node's gender is " << gender << std::endl;
else std::cout << "This node has no gender" << std::endl;
A container for nodes.
Definition: NodesetManager.h:192
const std::string agents
Definition: NodesetManager.h:14
Nodes are any type of entity with or without attributes.
Definition: NodesetManager.h:109
const std::string & get_attribute(const std::string &attribute_name) const
Searches for a node attribute.
Definition: NodesetManager.cpp:4

Output:

This node's gender is male 

Complexity

Same complexity as unordered_set::find

Iterator validity

No changes

Exception Safety

If the attribute name is not found in a node's attributes a dynet::missing_node_attribute is thrown.

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

◆ operator[]()

const std::string & Node::operator[] ( const std::string &  attribute_name) const
inline

Operator is identical to Node::get_attribute.

Here is the call graph for this function: