Construct version 5.4.4
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. | |||||
operator const Nodeset * () const | |||||
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 & | operator[] (unsigned int index) const noexcept | ||||
Returns the node at the specified index. More... | |||||
const Node & | operator[] (const std::string &name) const | ||||
Returns the node with the specified name. More... | |||||
const Node * | get_node_by_index (unsigned int index) const | ||||
Returns the node at the specified index. More... | |||||
const Node * | get_node_by_name (const std::string &name) const noexcept | ||||
Returns the node with the specified 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 | 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. | |||||
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 |
Returns the node at the specified index.
index | The index of the node being queried. |
Example
Output:
Mary Joe
Complexity
Constant
Iterator validity
No changes
Exception Safety
An assertion is raised if the index is equal to or larger than the size of the nodeset.
|
noexcept |
Returns the node with the specified name.
name | The name of the node being queried. |
Example
Output:
0 2
Complexity
Constant
Iterator validity
No changes
Exception Safety
An exception is thrown if no node exists with the queried name.
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.
|
inline |
Returns the node with the specified name.
name | The name of the node being queried. |
Example
Output:
0 2
Complexity
Constant
Iterator validity
No changes
Exception Safety
An exception is thrown if no node exists with the queried name.
|
inlinenoexcept |
Returns the node at the specified index.
index | The index of the node being queried. |
Example
Output:
Mary Joe
Complexity
Constant
Iterator validity
No changes
Exception Safety
An assertion is raised if the index is equal to or larger than the size of the nodeset.
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.
const std::string Nodeset::name |
summary>