echo.models.base.optimisation_graph module
- class echo.models.base.optimisation_graph.OptimisationGraph(nodes: dict[str, Node] = NOTHING, edges: dict[tuple[str, str], Edge] = NOTHING, paths: dict[tuple, Path] = NOTHING)
Bases:
object- apply_path_constraints(model: EchoConcreteModel) None
Applies path tracing constraints to model
- connect_ports_and_create_edge(port1: Port, port2: Port, edge_name: str | None = None) None
Creates an edge between port1 and port2 and adds it to the graph
- convert_to_nx() Graph
Converts the OptimisationGraph to a networkx graph, where nx nodes are echo node names and nx edges are nx node pairs
- create_path_objects(sources: list[Node] | list[str], sinks: list[Node] | list[str], path_unit: Units = Units.KW, regularise: bool = False) None
Creates path objects according to source/sink lists provided.
- delete_edge(edge_nodes: tuple[str, str]) None
- delete_node(node_name: str) None
- draw_on_axes(axes: Axes, with_labels: bool = False, labels: dict[str, str] | None = None, **kwargs) None
Draws the network on a matplotlib plot
- Parameters:
axes (matplotlib.axes.Axes) – The (sub-)plot on which to draw the network
with_labels (bool) – Set to True to draw labels on the nodes. Defaults to False. Uses the node’s names as the label.
labels (dict) – Optional way of supplying node labels as a dictionary of labels (strings) keyed by node. Default = None.
**kwargs – Optional keyword arguments for customising the drawing of the network. See networkx.drawing.nx_pylab.draw_networkx documentation for more information.
Examples
The following example shows how to draw an already created OptimisationGraph with the name network
>>> import matplotlib.pyplot as plt >>> network_figure = plt.figure() >>> network_axes = network_figure.add_subplot() >>> network.draw_on_axes(axes=network_axes, with_labels=True) >>> plt.show()
- edge_list() list[str]
- get_edge(nodes: tuple[str, str]) Edge | None
Retrieves the edge that connects a tuple of nodes, if an edge exists.
- get_path(path_vertices: list[Node] | list[str]) Path
Looks up a path using a list of path vertices (nodes, or node names).
- get_port_names_from_edges() set[str]
- get_port_names_from_nodes(skip_dangling_ports: bool = False) set[str]
- get_ports_on_edge_from_nodes(node1: str, node2: str) tuple[Port, Port] | None
Returns the ports that are on the edge from node1 to node2.
- inject_data_into_ev(node_name: str, available: ndarray | list | str | None = None, usage: ndarray | list | str | None = None, initial_state_of_charge: float | None = None, interval_duration: int | None = None) None
Injects stateful data into an EV node in an OptimisationGraph.
This is a convenience method to be used for networks constructed by MESNetwork.to_echo(). It will update all data in the relevant node and edges through re-initialisation of nodes, and delete and recreated of the edge.
- Parameters:
node_name – The node_name of the EV to have stateful data injected.
available – The avability data of the EV to be injected.
usage – The usage data of the EV to be injected.
initial_state_of_charge – The initial state of charge of the EV to be injected.
interval_duration – The interval duration of the EV to be injected.
- Returns:
None
- lookup_node_names_from_port(port: Port) str
Returns node name of the node that a specified port belongs to, if the port belongs to a node.
- node_name_list() list[str]
- print_port_names() None
Prints port name-uid pairs, useful for debugging infeasible optimisation
- rebuild_all_edges() None
Deletes and rebuilds all edges. Deprecated and replaced with a pass (i.e. no operation)
To be used after stateful data has been injected into ports. Injecting stateful data into ports alters the port. The new altered port correctly remains associated with the node, but does not remain associated with any edges this port may be associated with. This method builds new edges for each old edge based on the port name associated with each end of the edge. The original edge is deleted.
- Returns:
None
- split_graph_on_edge(node1: str, node2: str) tuple[OptimisationGraph, OptimisationGraph]
Splits a graph between node1 and node 2, and returns two echo optimisation graphs. The ports on the split edge are kept in the two new graphs.
- to_cytoscape_json() str
Converts the optimisation graph to json that can be read by cytoscape (https://js.cytoscape.org/)
- update_node(node_name: str, **kwargs) None
- verify_graph() None
Checks that the graph is connected (all nodes have at least one edge), and warns if there are unconnected ports
- verify_paths() None
Verifies that our paths meet the assumptions required to correctly do flow tracing.