Construct version 5.4.3
An agent based modeling framework
GraphManager Class Reference

Manages all graphs in Construct. More...

Collaboration diagram for GraphManager:

Classes

struct  set_of_generators
 Class that contains the set of all generators Construct can use on a Graph. More...
 

Public Member Functions

bool is_imported (Typeless_Graph *graph)
 Returns true if the submitted graph was imported before model loading.
 
Graph_Intermediary load_required (const std::string &name, const Nodeset *src, const Nodeset *trg, const Nodeset *slc=nullptr) const
 Finds a loaded Graph and returns it via a proxy class. More...
 
Graph_Intermediary load_required (const std::string &name, const Nodeset &src, const Nodeset &trg)
 
Graph_Intermediary load_required (const std::string &name, const Nodeset &src, const Nodeset &trg, const Nodeset &slc)
 
Graph_Intermediary load_required (const std::string &name, const std::string &source_nodeset, const std::string &target_nodeset, const std::string &slice_nodeset="") const
 Similar to GraphManager::load_required(const std::string&, const Nodeset*, const Nodeset*, const Nodeset*). More...
 
Graph_Intermediary load_required (const std::string &name, const std::string &source_nodeset, const std::string &target_nodeset, const std::string &slice_nodeset="")
 
Graph_Intermediary load_optional (const std::string &name, const Nodeset *src, const Nodeset *trg, const Nodeset *slc=nullptr) const
 Finds a Graph if its loaded and returns it via a proxy class. More...
 
Graph_Intermediary load_optional (const std::string &name, const Nodeset &src, const Nodeset &trg)
 
Graph_Intermediary load_optional (const std::string &name, const Nodeset &src, const Nodeset &trg, const Nodeset &slc)
 
Graph_Intermediary load_optional (const std::string &name, const std::string &source_nodeset, const std::string &target_nodeset, const std::string &slice_nodeset="") const
 Similar to GraphManager::load_optional(const std::string&, const Nodeset*, const Nodeset*, const Nodeset*). More...
 
Graph_Intermediary load_optional (const std::string &name, const std::string &source_nodeset, const std::string &target_nodeset, const std::string &slice_nodeset="")
 
template<typename T >
Graph_Intermediary load_optional (const std::string &name, const T &vals, const Nodeset *src, bool row_dense, const Nodeset *trg, bool col_dense, const Nodeset *slc=nullptr)
 Finds a Graph, creates a new Graph if it can't be found, and returns it via a proxy class. More...
 
template<typename T >
Graph_Intermediary load_optional (const std::string &name, const T &vals, const Nodeset &src, bool row_dense, const Nodeset &trg, bool col_dense)
 
template<typename T >
Graph_Intermediary load_optional (const std::string &name, const T &vals, const Nodeset &src, bool row_dense, const Nodeset &trg, bool col_dense, const Nodeset &slc)
 
template<typename T >
Graph_Intermediary load_optional (const std::string &name, const T &vals, const std::string &source_nodeset, bool row_dense, const std::string &target_nodeset, bool col_dense, const std::string &slice_nodeset="")
 Similar to GraphManager::load_optional(const std::string&, const T&, const Nodeset*, bool, const Nodeset*, bool, const Nodeset*). More...
 
Typeless_Graphget_network (const std::string &name) noexcept
 Finds the parent class pointer for the requested Graph. More...
 
void import_network (Typeless_Graph *graph)
 Causes this manager to take ownership of the graph. More...
 
void export_network (Typeless_Graph *graph) noexcept
 Causes this manager to relieve its ownership of the graph. More...
 

Public Attributes

std::set< Typeless_Graph * > imported_graphs
 The set of graphs imported before model loading.
 
set_of_generators generators
 

Detailed Description

Manages all graphs in Construct.

Graphs are the primary data storage class for information connecting more than one node. Ex. which agents can interact with which other agent, which agent has which knowledge, which knowledge can be used on a communication medium. Construct when parsing an input xml file will create a graph and add data to based on the input. This included adding the specified links and applying any generators in the associated XML element.

The graph manager allows developers to require that a graph be created before a model is constructed or that it be optional. Using load_required will search for the specified graph and ensure that its dimension's match the developers specifications and data type. Exceptions are thrown any if any of these steps fail. By contrast, load_optional will performs similar checks on the dimensions and data type, but returns a null pointer if the graph isn't found. An overload of load_optional will create a graph if the graph is not found using the submitted dimensions, representation, and default value. Both functions return a Graph_Intermediary wrapping the returned Typeless_Graph. When cast, this object will automatically convert the wrapped pointer to either a Graph pointer or reference assuming the Typless_Graph::edge_type matches the conversion type.

Graphs that are loaded by xml file parsing are added to the imported_graphs member. In addition, any graph that is imported via import_network is added to the same member. Any Graph can be exported from the GraphManager. Graphs that are exported will not be deallocated by the GraphManager when itself is deallocated. Conversly, any Graph that is imported will be deallocated by the GraphManager if it is not exported before deallocation. Graphs that are exported are no longer contained in the GraphManager and can no

Member Function Documentation

◆ export_network()

void GraphManager::export_network ( Typeless_Graph graph)
noexcept

Causes this manager to relieve its ownership of the graph.

This Typeless_Graph is removed from the container and will not be deallocated when this manager is deallocated. This can be used to save the Typeless_Graph for a future Construct instance without copying the old contents.

Parameters
graphThe Typeless_Graph that this manager is relieving its owership of.

Exception Safety

No-throw guarantee: this member function never throws exceptions.

◆ get_network()

Typeless_Graph * GraphManager::get_network ( const std::string &  name)
noexcept

Finds the parent class pointer for the requested Graph.

Parameters
nameName of the requested Graph.
Returns
The pointer to the requested Graph, or a NULL pointer if the Graph was not found.

Example

std::cout << "knowledge network is currently available." << std::endl;
}
Typeless_Graph * get_network(const std::string &name) noexcept
Finds the parent class pointer for the requested Graph.
Definition: GraphManager.cpp:946
const std::string knowledge
Definition: GraphManager.h:99
GraphManager graph_manager
The manager that holds all graphs/networks.
Definition: Construct.h:107

Output:

knowledge network is currently available. 

Complexity

Constant.

Exception Safety

Strong Guarantee: This function never throws exceptions.

Here is the caller graph for this function:

◆ import_network()

void GraphManager::import_network ( Typeless_Graph graph)

Causes this manager to take ownership of the graph.

This Typeless_Graph is added to the container and it is deallocated when this manager is deallocated. This can be used to import a Typeless_Graph from a previous Construct instance without copying the old contents.

Parameters
graphThe Typeless_Graph that this manager is taking owership of.

Exception Safety

A dynet::already_exists exception is thrown if a Typeless_Graph with the same name already exists.

◆ load_optional() [1/4]

Graph_Intermediary GraphManager::load_optional ( const std::string &  name,
const Nodeset src,
const Nodeset trg,
const Nodeset slc = nullptr 
) const

Finds a Graph if its loaded and returns it via a proxy class.

Graphs are identified by their name. Once the graph has been identified, its row and column nodeset dimensions are compared with the submitted nodesets. This ensures an imported graph's dimensions are correct. Exceptions are raised if it's dimensions do not match. If the Graph is not found, the returned proxy class will hold a null pointer.

The returned object is a wrapper for the graph. This object can be automatically converted to a graph of the correct template type. If Graph::edge_type does not correspond to the requested type, an exception is raised. Additionally this object is converted to a pointer or reference automatically. An exception is raised if the proxy holding a null pointer is converted to a reference.

Parameters
nameName of the graph being requested.
srcThe source nodeset that the requested graph must match.
trgThe target nodeset that the requested graph must match.
slcThe slice nodeset that the requested graph must match. Two dimensional graph's do not require a slice nodeset.
Returns
A Graph_Intermediary that wraps a Typless_Graph pointer. This object automatically converts to either a Graph pointer or reference.

Example

const Nodeset* my_ns_1 = construct.ns_manager.get_nodeset("my nodeset 1");
const Nodeset* my_ns_2 = construct.ns_manager.get_nodeset("my nodeset 2");
Graph<bool>* bool_graph_ptr = construct.graph_manager.load_optional("my_graph_1", my_ns_1, my_ns_1);
// unsafe assignment, it should be guarenteed that the graph already exists in the graph_manager
const Graph<float>& float_graph_ref = construct.graph_manager.load_optional("my_graph_2", my_ns_1, my_ns_2);
const Graph<std::vector<bool> >* bool_3dgraph_ptr = construct.graph_manager.load_optional("my_graph_3", my_ns_1, my_ns_1, my_ns_2);
// also an unsafe assignment
Graph<std::map<unsigned int, int> >& int_3dgraph_ref = construct.graph_manager.load_optional("my_graph_4", my_ns_1, my_ns_2, my_ns_2);
Graph_Intermediary load_optional(const std::string &name, const Nodeset *src, const Nodeset *trg, const Nodeset *slc=nullptr) const
Finds a Graph if its loaded and returns it via a proxy class.
Definition: GraphManager.cpp:907
A container for nodes.
Definition: NodesetManager.h:192
const Nodeset & get_nodeset(const std::string &name) const
Finds the specified nodeset.
Definition: NodesetManager.cpp:112
NodesetManager ns_manager
The manager that holds all nodesets.
Definition: Construct.h:103

Complexity

Constant.

Exception Safety If the graph can not be found, a null pointer is returned. Otherwise, if either input source, target, or slice nodeset pointers do not equal the respective pointers in the requested graph, or the requested graph's edge_type does not match the corresponding dynet::get_edge_type for the template instantiation, a dynet::construct_exception is thrown.

Here is the caller graph for this function:

◆ load_optional() [2/4]

Graph_Intermediary GraphManager::load_optional ( const std::string &  name,
const std::string &  source_nodeset,
const std::string &  target_nodeset,
const std::string &  slice_nodeset = "" 
) const

Similar to GraphManager::load_optional(const std::string&, const Nodeset*, const Nodeset*, const Nodeset*).

For each nodeset name string submitted, a Nodeset pointer is queried from the NodesetManager. These are then submitted to the overload function compliment of this function.

Here is the call graph for this function:

◆ load_optional() [3/4]

template<typename T >
Graph_Intermediary GraphManager::load_optional ( const std::string &  name,
const T &  vals,
const Nodeset src,
bool  row_dense,
const Nodeset trg,
bool  col_dense,
const Nodeset slc = nullptr 
)

Finds a Graph, creates a new Graph if it can't be found, and returns it via a proxy class.

Graphs are identified by their name. Once the graph has been identified, its row and column nodeset dimensions are compared with the submitted nodesets. This ensures an imported graph's dimensions are correct. Exceptions are raised if it's dimensions do not match. If the Graph is not found, a Graph is created with default values, dimensions, and represenations based on inputs.

The returned object is a wrapper for the graph. This object can be automatically converted to a graph of the correct template type. If Graph::edge_type does not correspond to the requested type, an exception is raised. Additionally this object is converted to a pointer or reference automatically. An exception is raised if the proxy holding a null pointer is converted to a reference.

Parameters
nameName of the graph being requested.
valsIf a graph is made, this parameter sets its default value.
srcThe source nodeset that the requested graph must match.
row_denseIf a graph is made, the graph's source dimension (rows) will be dense if parameter is set to true, otherwise the dimension will be sparse.
trgThe target nodeset that the requested graph must match.
Parameters
col_denseIf a graph is made, the graph's target dimension (columns) will be dense if parameter is set to true, otherwise the dimension will be sparse.
slcThe slice nodeset that the requested graph must match. Two dimensional graph's do not require a slice nodeset.
Returns
A Graph_Intermediary that wraps a Typless_Graph pointer. This object automatically converts to either a Graph pointer or reference.

Example

const Nodeset* my_ns_1 = construct.ns_manager.get_nodeset("my nodeset 1");
const Nodeset* my_ns_2 = construct.ns_manager.get_nodeset("my nodeset 2");
Graph<bool>* bool_graph_ptr = construct.graph_manager.load_optional(
"my_graph_1", true, my_ns_1, true, my_ns_1, false);
// safe assignment as if the requested graph isn't found, a graph is created.
const Graph<float>& float_graph_ref = construct.graph_manager.load_optional(
"my_graph_2", 0.0f, my_ns_1, false, my_ns_2, true);
const Graph<std::vector<bool> >* bool_3dgraph_ptr = construct.graph_manager.load_optional(
"my_graph_3", std::vector<bool>(my_ns_2->size(), true), my_ns_1, false, my_ns_1, false, my_ns_2);
// safe assignment
"my_graph_4", std::map<unsigned int, int>(), my_ns_1, true, my_ns_2, true, my_ns_2);
unsigned int size(void) const
Returns the number of nodes in the nodeset
Definition: NodesetManager.cpp:10

Complexity

Constant.

Exception Safety If a graph already exists and either input source, target, or slice nodeset pointers do not equal the respective pointers in the requested graph, or the requested graph's edge_type does not match the corresponding dynet::get_edge_type for the template instantiation, a dynet::construct_exception is thrown.

Here is the call graph for this function:

◆ load_optional() [4/4]

template<typename T >
Graph_Intermediary GraphManager::load_optional ( const std::string &  name,
const T &  vals,
const std::string &  source_nodeset,
bool  row_dense,
const std::string &  target_nodeset,
bool  col_dense,
const std::string &  slice_nodeset = "" 
)

Similar to GraphManager::load_optional(const std::string&, const T&, const Nodeset*, bool, const Nodeset*, bool, const Nodeset*).

For each nodeset name string submitted, a Nodeset pointer is queried from the NodesetManager. These are then submitted to the overload function compliment of this function.

Here is the call graph for this function:

◆ load_required() [1/2]

Graph_Intermediary GraphManager::load_required ( const std::string &  name,
const Nodeset src,
const Nodeset trg,
const Nodeset slc = nullptr 
) const

Finds a loaded Graph and returns it via a proxy class.

Graphs are identified by their name. Once the graph has been identified, its row and column nodeset dimensions are compared with the submitted nodesets. This ensures an imported graph's dimensions are correct. Exceptions are raised if the graph can't be found or if it's dimensions do not match.

The returned object is a wrapper for the graph. This object can be automatically converted to a graph of the correct template type. If Graph::edge_type does not correspond to the requested type, an exception is raised. Additionally this object is converted to a pointer or reference automatically.

Parameters
nameName of the graph being requested.
srcThe source nodeset that the requested graph must match.
trgThe target nodeset that the requested graph must match.
slcThe slice nodeset that the requested graph must match. Two dimensional graph's do not require a slice nodeset.
Returns
A Graph_Intermediary that wraps a Typless_Graph pointer. This object automatically converts to either a Graph pointer or reference.

Example

const Nodeset* my_ns_1 = construct.ns_manager.get_nodeset("my nodeset 1");
const Nodeset* my_ns_2 = construct.ns_manager.get_nodeset("my nodeset 2");
Graph<bool>* bool_graph_ptr = construct.graph_manager.load_required("my_graph_1", my_ns_1, my_ns_1);
const Graph<float>& float_graph_ref = construct.graph_manager.load_required("my_graph_2", my_ns_1, my_ns_2);
const Graph<std::vector<bool> >* bool_3dgraph_ptr = construct.graph_manager.load_required("my_graph_3", my_ns_1, my_ns_1, my_ns_2);
Graph<std::map<unsigned int, int> >& int_3dgraph_ref = construct.graph_manager.load_required("my_graph_4", my_ns_1, my_ns_2, my_ns_2);
Graph_Intermediary load_required(const std::string &name, const Nodeset *src, const Nodeset *trg, const Nodeset *slc=nullptr) const
Finds a loaded Graph and returns it via a proxy class.
Definition: GraphManager.cpp:876

Complexity

Constant.

Exception Safety

If either input source, target, or slice nodeset pointers do not equal the respective pointers in the requested graph, or the requested graph's edge_type does not match the corresponding dynet::get_edge_type for the template instantiation a dynet::construct_exception is thrown. If the graph can not be found, a dynet::could_not_find_network is thrown.

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

◆ load_required() [2/2]

Graph_Intermediary GraphManager::load_required ( const std::string &  name,
const std::string &  source_nodeset,
const std::string &  target_nodeset,
const std::string &  slice_nodeset = "" 
) const

Similar to GraphManager::load_required(const std::string&, const Nodeset*, const Nodeset*, const Nodeset*).

For each nodeset name string submitted, a Nodeset pointer is queried from the NodesetManager. These are then submitted to the overload function compliment of this function.

Here is the call graph for this function: