![]() |
Construct version 5.4.1
An agent based modeling framework
|
A container for nodes. More...
Public Types | |
using | iterator = std::vector< Node >::const_iterator |
Public Member Functions | |||||
Nodeset (const std::string &_name) | |||||
~Nodeset () | |||||
Deallocates the attribute pointers of all nodes it contains. | |||||
iterator | begin (void) const | ||||
Returns an iterator pointing the beginning of the vector of nodes. More... | |||||
iterator | end (void) const | ||||
Returns an iterator pointing the beyond the last node in the vector of nodes. More... | |||||
unsigned int | size (void) const | ||||
Returns the number of nodes in the nodeset More... | |||||
void | add_node (const dynet::ParameterMap &attributes) | ||||
Adds a node to the Nodeset. More... | |||||
void | add_node (const std::string &node_name, const dynet::ParameterMap &attributes, bool verbose_initialization=false) | ||||
Similar to Nodeset::add_node(const dynet::ParameterMap), but allows for the specification of the node's name. | |||||
void | add_nodes (unsigned int count, const dynet::ParameterMap &attributes, bool verbose_initialization=false) | ||||
Calls Nodeset::add_node(const dynet::ParameterMap) a number of times equal to count. | |||||
const Node * | get_node_by_index (unsigned int index) const | ||||
Finds a node using the node's index. More... | |||||
const Node * | get_node_by_name (const std::string &name) const noexcept | ||||
Finds a node using the node's name. More... | |||||
template<typename T > | |||||
void | check_attributes (std::string attribute, T min, T max) const | ||||
Checks that all nodes in the nodeset for the specified attribute. More... | |||||
template<typename T > | |||||
void | check_attributes (std::string attribute) const | ||||
Checks that all nodes in the nodeset for the specified attribute. More... | |||||
void | turn_to_const () noexcept | ||||
Modifies the nodeset such that is findable by the NodesetManager and can no longer have nodes added to it. More... | |||||
void | import_dynetml (const std::string &fname, const std::string &dynetml_ns_name) | ||||
Imports information from a DyNetML style xml file into the nodeset.
Exception Safety More... | |||||
void | import_csv (const std::string &fname) | ||||
Imports information from a CSV files. The header should contain the names of all attributes with the first element being blank. Each row should start with the node's name and the contents of that row corresponding to attribute values. | |||||
bool | is_const () const noexcept | ||||
Returns true if the nodeset can no longer be modified. | |||||
template<> | |||||
void | check_attributes (std::string attribute) const | ||||
template<> | |||||
void | check_attributes (std::string attribute) const | ||||
template<> | |||||
void | check_attributes (std::string attribute) const | ||||
template<> | |||||
void | check_attributes (std::string attribute) const | ||||
Public Attributes | |
const std::string | name |
A container for nodes.
A nodeset is a container for Nodes. This includes basic functions for accessing and interacting with the nodes in the nodeset.
Nodesets are created by the NodesetManager. It is not expected that other classes in Construct would create a nodeset. Rather a pointer to an existing nodeset to find a node is the primary way a nodeset is used.
void Nodeset::add_node | ( | const dynet::ParameterMap & | attributes | ) |
Adds a node to the Nodeset.
Nodes are added to the nodeset with index equal to the previous nodeset size. The nodes name is created using the nodeset's name plus the node's index.
attributes | The attributes to be saved to the new node. The values in "attributes" are copied into the new node. |
Example
Output:
node 0 and node 1 use the same attributes pointer node 0 does not have the same attributes pointer as my_attributes node 0 and node 2 have the same attributes pointer node 0 and node 3 do not have the same attributes pointer
Complexity
Constant
Iterator validity
If a reallocation happens, all iterators, pointers and references related to the container are invalidated. Otherwise, only the end iterator is invalidated, and all iterators, pointers and references to elements are guaranteed to keep referring to the same elements they were referring to before the call.
Exception Safety
An assertion is raised if the nodeset has been turned to a constant nodeset. A dynet::already_exists is thrown if the created node name (nodeset name + "_" + index) matches any previous node name.
Nodeset::iterator Nodeset::begin | ( | void | ) | const |
Returns an iterator pointing the beginning of the vector of nodes.
Example
Output:
This nodeset contains: Mary John Joe
Complexity
Constant
Iterator validity
No changes
Exception Safety
No-throw guarantee: this member function never throws exceptions.
void Nodeset::check_attributes | ( | std::string | attribute | ) | const |
Checks that all nodes in the nodeset for the specified attribute.
The attribute values are converted to the data type dictated the explicit instantiation of the template.
attribute | Name of the attribute that each node should have. |
Example
Output:
Error: Could not convert value to unsigned int for attribute "attribute2" for node "node1".
Complexity
Linear in number of nodes in the specified nodeset.
Iterator validity
No changes.
Exception Safety
A dynet::missing_node_attribute is thrown if a node is missing the attribute. A dynet::could_not_convert_attribute is thrown if the attribute could not be converted to the data type of the template instantiation.
void Nodeset::check_attributes | ( | std::string | attribute, |
T | min, | ||
T | max | ||
) | const |
Checks that all nodes in the nodeset for the specified attribute.
These attributes are converted to the type determined by the submitted parameters. The converted values are then checked to ensure the it lies between the submitted bounds for that attribute. The only template instantiations available are int, unsigned int, float.
attribute | Name of the attribute that each node should have. |
min | The minimum value the attribute can have. Any attribute value that is smaller than min will cause a dynet::out_of_range exception to be thrown. |
max | The maximum value the attribute can have. Any attribute value that is greater than max will cause a dynet::out_of_range exception to be thrown. |
Example
Output:
Error: "attribute2" for node "node1" is out of range [0,1].
Complexity
Linear in number of nodes in the specified nodeset.
Iterator validity
No changes.
Exception Safety
A dynet::missing_node_attribute is thrown if a node is missing the attribute. A dynet::could_not_convert_attribute is thrown if the attribute could not be converted to the template specialization. A dynet::out_of_range is thrown if the converted attribute value is greater than max or less than min.
Nodeset::iterator Nodeset::end | ( | void | ) | const |
Returns an iterator pointing the beyond the last node in the vector of nodes.
Example
Output:
This nodeset contains: Mary John Joe
Complexity
Constant
Iterator validity
No changes
Exception Safety
No-throw guarantee: this member function never throws exceptions.
const Node * Nodeset::get_node_by_index | ( | unsigned int | index | ) | const |
Finds a node using the node's index.
This function provides drastic speed up compared to get_node_by_name as this function references a vector while the former references a binary tree.
index | The node's index in the nodeset. |
Example
Output:
Node at index 0 is Mary
Complexity
Constant
Iterator validity
No changes
Exception Safety
An assertion is raised if index is out of bounds for the nodeset.
|
noexcept |
Finds a node using the node's name.
This function uses a binary tree to find a node, making its speed slower than get_node_by_index.
name | The node's name in the nodeset. |
Example
Output:
Node Mary is at index 0
Complexity
Logarithmic in size of nodeset. Underlying function uses map::find
Iterator validity
No changes
Exception Safety
No-throw guarantee: this member function never throws exceptions. If the node was not found, a null pointer is returned.
void Nodeset::import_dynetml | ( | const std::string & | fname, |
const std::string & | dynetml_ns_name | ||
) |
Imports information from a DyNetML style xml file into the nodeset.
fname | The file name with either an absolute or relative directory path. |
dynetml_ns_name | The name of nodeset stored in the DyNetML file that is to be imported. |
Exception Safety
Various exceptions can be raised if the DyNetML file is not formatted correctly or if information is missing.
unsigned int Nodeset::size | ( | void | ) | const |
Returns the number of nodes in the nodeset
Example
Output:
The number of nodes in this nodeset: 3
Complexity
Constant
Iterator validity
No changes
Exception Safety
No-throw guarantee: this member function never throws exceptions.
|
noexcept |
Modifies the nodeset such that is findable by the NodesetManager and can no longer have nodes added to it.
Once a nodeset has all the nodes that one wishes to add to this nodeset, this function should be called. If this function has been called, Nodeset::add_node will raise an assertion when called. If this function has not been called, a dynet::could_not_find_nodeset exception will be thrown when querying the NodesetManager for this nodeset.
nodeset | Pointer to the nodeset that should be converted. |
Example
Output:
my_nodeset was loaded
Complexity
Constant
Exception Safety
No-throw guarantee: this member function never throws exceptions.
const std::string Nodeset::name |