Problem 3.2#
Integrated Energy Grids
Problem 3.2
Consider the simplified network plotted in the figure, which represents Denmark and its neighbouring countries. Let us assume the following convention names for the regions Germany=0, DK1=1, DK2=2, Norway=3, and Sweden=4.

a) Create a list of the nodes and links. Sort the nodes and links in ascending order. Link (0,1) before (1,2), before (1,3) etc.
We will use the package numpy to operate with matrices.
import numpy as np
import numpy.linalg
List of nodes and links
nodes = [0,1,2,3,4]
links = [(0,1), (1,2), (1,3), (1,4), (2,4)]
b) Calculate the degree of each node \(k_i\) and the average degree of the network 〈k〉.
Degree of each node and average degree of the network
\(k_1\)= 1, \(k_1\)=4, \(k_2\)=2, \(k_3\)=1, \(k_4\)=2
Average degree of the network
k=(1+4+2+1+2)/5
print(k)
2.0
c) Create the degree matrix \(D_{ij}\). Create the adjacency matrix \(A_{ij}\) and check that it is symmetric.
Degree matrix
D = np.zeros((len(nodes), len(nodes)))
for node in nodes:
D[node, node] = sum([1 if node in link else 0 for link in links])
D
array([[1., 0., 0., 0., 0.],
[0., 4., 0., 0., 0.],
[0., 0., 2., 0., 0.],
[0., 0., 0., 1., 0.],
[0., 0., 0., 0., 2.]])
Adjacency matrix
A = np.zeros((len(nodes), len(nodes)))
for node_a, node_b in links:
A[node_a, node_b] = 1
A[node_b, node_a] = 1
A
array([[0., 1., 0., 0., 0.],
[1., 0., 1., 1., 1.],
[0., 1., 0., 0., 1.],
[0., 1., 0., 0., 0.],
[0., 1., 1., 0., 0.]])
We can check that matrix A is symmetric by checking that its transpose is equal to the original matrix
A-A.T
array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]])
d) Create the incidence matrix \(K_{ij}\), assuming that the links are always directed from low-number node to high-number node.
K = np.zeros((len(nodes),len(links)))
for i, (node_a, node_b) in enumerate(links):
K[node_a,i] = 1
K[node_b,i] = -1
K
array([[ 1., 0., 0., 0., 0.],
[-1., 1., 1., 1., 0.],
[ 0., -1., 0., 0., 1.],
[ 0., 0., -1., 0., 0.],
[ 0., 0., 0., -1., -1.]])
e) Create the Laplacian matrix \(L_{ij}\) using the degree and adjacency matrices. Create the Laplacian matrix using the incidence matrix. Check that the two definitions agree.
a) using the adjacency matrix
L = D - A
L
array([[ 1., -1., 0., 0., 0.],
[-1., 4., -1., -1., -1.],
[ 0., -1., 2., 0., -1.],
[ 0., -1., 0., 1., 0.],
[ 0., -1., -1., 0., 2.]])
b) using the incidence matrix
L=K.dot(K.T)
L
array([[ 1., -1., 0., 0., 0.],
[-1., 4., -1., -1., -1.],
[ 0., -1., 2., 0., -1.],
[ 0., -1., 0., 1., 0.],
[ 0., -1., -1., 0., 2.]])