graph_utilities

List of utilities for the Network class

add_time_to_pipes(net, fluid)[source]

Add time attribute to edges.

assign_line(net)[source]

Assign a line - either supply or return - to pipes. It assumes that the endpoint of the first Producer is in the supply line.

Parameters:

net (Network) – Instance of Network class.

compute_linegraph(G, edge_label=None)[source]

Creates a linegraph of the input graph G preserving coordinates and labels. Node and edge features are carried over. New node positions are computed as the centroid of the corresponding edge in the original graph.

Parameters:
  • G (DiGraph) – Directed graph of the network.

  • edge_label (str, optional) – If specified, nodes are relabeled with the specified label. The default is None.

Returns:

linegraph – Linegraph of G.

Return type:

DiGraph

compute_linegraph_net(net, edge_label=None)[source]

Creates a linegraph of the input graph G preserving coordinates and labels.

Parameters:

net (instance of Network class)

connect_pairs(net, verbose=False)[source]

For each node and edge in the supply line identifies the correspective twin in the return line and vice-versa. Twin elements are stored as attributes called “adjacent_node” and “adjacent_edge” respectively.

Parameters:
  • net (instance of Network class)

  • verbose (if True prints a)

find_path_with_edge(G, source, target, edge, node_path=True)[source]

Find a path between two nodes that contains a certain edge in a directed graph. If such a path does not exist, return None.

Parameters:
  • G (DiGraph) – Directed graph of the network.

  • source (str) – Source node.

  • target (str) – Target node.

  • edge (tuple) – Edge to be included in the path.

  • node_path (bool) – If true, returns a list of nodes. If false, returns a list of edges.

Returns:

path – List of nodes (or edges) forming the path.

Return type:

list

get_edges_attribute_array(net, attribute, fill_missing=None, dtype=None)[source]

Returns an array containing the value of the specified attribute in each edge of the network graph. From Python 3.7 the order of attributes follows the insertion order of edges.

Parameters:
  • net (instance of Network class)

  • attribute (the name of the desired attribute)

  • fill_missing (default value when the node does not have the desired) – attribute. (optional)

  • dtype (specific dtype of the array items. (optional))

get_furthest_consumers(net)[source]

Return a dict of {producer: furthest consumer}.

get_longest_paths(net)[source]

Return a list of directed graphs from each producer to furthest consumer.

get_nodes_attribute_array(net, attribute, fill_missing=None, dtype=None)[source]

Returns an array containing the value of the specified attribute in each node of the network graph. From Python 3.7 the order of attributes follows the insertion order of nodes.

Parameters:
  • net (instance of Network class)

  • attribute (the name of the desired attribute)

  • fill_missing (default value when the node does not have the desired) – attribute. (optional)

  • dtype (specific dtype of the array items. (optional))

get_pipes_to_consumers_dict(net)[source]

Returns a list with the indices of all the pipes entering in a consumer edge.

get_supply_time(net, fluid=None)[source]

Return timedelta to reach the furthest consumer.

run_sanity_checks(net, verbose=1, check_isomorphism=True)[source]

Runs sanity checks on the Network class against common mistakes.

Parameters:
  • net (Network) – Instance of Network class.

  • verbose (Bool, optional) – Defines the level of verbosity. The default is 1.

Returns:

errors – Dictionary with the results of the sanity check. A True value means that an error was found during that test.

Return type:

Dict