echo OptimisationGraph
The optimisation graph holds all the nodes and edges in the model. It is both a representation of a physical network, as well as an object on which we can perform optimisation and analysis.
Mathematically, the optimisation graph is a graph \(G=(N,E)\), where \(N\) is the set of nodes in the graph, and \(E\) is the set of edges. Each node contains a list of ports that belong to the node:
\(n=(p_0, p_1, ..., p_m)\) where there are \(m\) ports belonging to the node.
Each edge is a node pair, and since nodes are a set of ports, edges are also a corresponding pair of ports.
Creating and Modifying the Graph
The optimisation graph is instantiated as shown below:
system = OptimisationGraph()
Once the graph has been created, we can create some nodes and add them to the graph, as shown below:
grid = FlexNode(node_name='grid', port_name='grid', port_unit=Units.KW) # creates a node with one flexible port called 'grid'
load = Load(node_name='load',
port_name='load',
port_unit=Units.KW,
profile=[2]*24) # creates a node with one fixed demand port called 'load'
system.add_nodes([grid, battery])
To connect nodes together via ports, we need to retrieve the port objects as well as the node names. We can then create an edge using the .connect_ports_and_create_edge method, as shown below:
grid_port = grid.get_port('grid')
load_port = load.get_port('load')
system.connect_ports_and_create_edge(grid_port, load_port)
Note
Any nodes that are part of an edge must be added to the graph first, before edges can be created.
Path tracing
Warning
Path tracing is an experimental feature. There is often no unique solution to the path tracing problem, although a regularisation term can be added to produce a unique solution. If path tracing is being used in order to use path tariffs, it is recommended to convert the tariffs to port tariffs where possible. This is because echo may alter the path flows to minimise cost in a way that is not physically meaningful or representative of how flows behave in real networks.
Echo can calculate path flows within the network. A path is a sequence of distinct nodes. Usually a path begins at a node that is a source of some commodity, and terminates at a node that is a sink for the same commodity.
Path tracing currently ignores different commodities. Echo will calculate paths in a network based on user-specified source and sink nodes. Source nodes are nodes that can be the start of a path (i.e., they can generate a commodity), and sink nodes are nodes nodes that can be the end of a path (i.e., they can sink a commodity). If it is not known whether nodes are sources or sinks, they can be entered as both.
Note
Any Tellegen nodes, or interconnecting should NOT be included as either a source or sink. This will raise an error. Echo will assume that any node that isn’t a source or sink is a tellegen node.
Source/sink nodes should have only one port.
Enabling Path Tracing
To use path tracing, the full network model should be built first. Then, paths can be generated using the .create_path_objects() method as shown below.
system.create_path_objects(sources=[grid], sinks=[load])
This will create all paths in the network, according to the sources and sinks provided. These path objects can be accessed using
the .get_path() method, which takes as an input the list of node objects that form the vertices of the desired path.
You should only access path objects if you want to apply a path tariff.
Note
Paths only represent flow in one direction. Therefore, there will be separate path objects for path A->B->C and C->B->A.
Path Flow Constraints
Each path object has a variable, \(f\). This is a non-negative variable that represents the flow along the path.
Let \(f_N^{start}\) and \(f_N^{end}\) represent the sum of path flow variables that start at node N and end at node N respectively. Then, for each source or sink node \(N\), with associated port \(p_N\), the constraint is:
\(f_N^{end} - f_N^{start} = p_N\)
This constraint enforces that if \(f_N^{end} > f_N^{start}\), \(p_N\) will be positive and importing, which is correct since there are more flows in than out. Conversely, if \(f_N^{end} < f_N^{start}\), \(p_N\) will be negative and exporting, which is correct since there are more flows out than in.
Because sources and sinks either import or export at a given time, it does not make sense for there to be simultaneous flows in and out. Therefore, we add the following pair of big M constraints to enforce that when there are flows in, the sum of flows out must equal zero, and vice versa. To achieve this we introduce a binary node variable, \(N^{inflow}\). For each source or sink node \(N\), with associated port \(p_N\), the constraints are:
\(f_N^{end} <= N^{inflow} \cdot M\)
\(f_N^{start} <= (1 - N^{inflow}) \cdot M\)
Note
A similar constraint could be achieved by splitting each port variable \(p_N\) into positive and negative components, and instead of the two constraints above, using:
\(f_N^{end} = p_N^+\)
\(f_N^{start} = p_N^-\)
However, both formulations require introducing a binary variable and two big M constraints, so it is unlikely there would be a significant difference in performance.