# Building Network

```+ Tutorial 4:
1. Building Network
2. Building Network 2```

We demonstrate the use of kero.multib to build an arbitrary network in the form of un-directed graphs. The explanations should be self explanatory and embedded as comments in the code below. The code will plot figure 1 to 4 in sequence.

```import kero.multib.nDnet as nd
import matplotlib.pyplot as plt

fig = plt.figure()
net = nd.Network()

# -------------------------------------
# Create network members
# -------------------------------------
groupA=["A1","A2","A3"]
groupB=["B"+str(i) for i in range(5)]
groupC=["C"+str(i) for i in range(5)]
member_set = groupA + groupB + groupC + ["groupA","groupB","groupC"]
for v in member_set:
print("Check point 1. Network members: \n --> ", net.member_set)

# --------------------------------------------
# Give each members a spatial coordinates
# -------------------------------------=======
grid_lattice_points={
"A1": [0,0,0],
"A2": [0,1,0],
"A3": [1,0,0],
"groupA": [0,0,4] ,
"groupB": [2,0,4],
"groupC": [4,0,4]
}
groupB_coord = [[2,0,0],[2,1,0],[2,-1,0],[3,0.5,0],[3,-0.5,0]]
for i in range(len(groupB)):
grid_lattice_points[groupB[i]] = groupB_coord[i]

groupC_coord = [[4,0,0],[4,1,0],[4,-1,0],[5,0,1],[5,0,-1]]
for i in range(len(groupC)):
grid_lattice_points[groupC[i]] = groupC_coord[i]
net.grid_lattice_points = grid_lattice_points

# -----------------------------------------------------
# Let us link members of group A and plot figure 1
# -----------------------------------------------------
print("\nCheck point 2.\nNow we add links between members of group A. See figure 1.")
print(" Network members: \n --> ", net.member_set)

# print(net.member_set)
net.visualize_3D_graph(ax,
title="1",
this_figure=fig,)

# -----------------------------------------------------
# Let us link members of group B and plot figure 2
# -----------------------------------------------------
print("\nCheck point 3.\nNow we add links between members of group B. See figure 2.")
for b1 in groupB:
for b2 in groupB:
if b1 is not b2:
# print(net.member_set)
net.visualize_3D_graph(ax2,
no_of_points_per_edge=12,
title="2",
this_figure=fig,)

# -----------------------------------------------------
# Let us link members of group C and plot figure 3
# -----------------------------------------------------
print("\nCheck point 4.\nNow we add links between members of group C. See figure 3.")
for c1 in groupC:
for c2 in groupC:
if c1 is not c2:
# print(net.member_set)
net.visualize_3D_graph(ax3,
no_of_points_per_edge=10,
title="3",
this_figure=fig,)

# -----------------------------------------------------
# plot figure 4
# -----------------------------------------------------