Multiple Hubs

This notebook demonstrates how to connect Energy Hub models together by adding network links. This allows us to model microgrids, district heating networks and any other type of energy sharing. One of the benefits of PyEHub over other energy hub model implementations is the ease with which we can nest hubs.

[ ]:
from pyehub.multiple_hubs import multiple_hubs

Example

Here we load a case with four hubs and four possible links, shown schematically below. Links between (2 - 0) and (1 - 3) are in fact shorter than the others.

Hub layout

Input files

We can use a pattern for naming mutiple hub input files, where we pass in the stem (in this case hub__) and the number of hubs (here n=4). This means the files to be read are hub__1.xlsx, hub__2.xlsx, etc. These use 1 as the first index.

[ ]:
input_file = "hub__"
n = 4

We also need the file network.xlsx which defines the links between the different hubs. The main tab in this file lists the network links, giving: + Network link ID + Start node ID + End node ID + Type + Length + Capacity

The start and end node IDs refer to the numbers of the hubs. Type, length, capacity and various other properties can be used in formulating the network constraints.

[ ]:
network = "network.xlsx"

Solving the Models

Here we run the multiple_hubs function, which: + combines the individual hub models into one big hub + adds network constraints to allow energy to be exchanged + solves the resulting hub model The stdout is very long, so we capture it to a variable sol_output.

[ ]:
%%capture sol_output
sol = multiple_hubs(input_files=input_file, n=n, network_excel=network)

Results

Results are returned for all four hubs, but all the network link capacities are the same by definition, so we can just take the values from the first hub.

[ ]:
hub = sol[0]

We can examine the network links that are installed:

[ ]:
hub["is_link_installed"]

And the capacity of the links:

[ ]:
for i in range(4):
    id = "capacity" + str(i)
    print("Link", i, "has capacity", hub[id])