+ 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: net.add_member(v) 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.") net.add_link("A1","A2") net.add_link("A1","A3") net.add_link("A2","A3") print(" Network members: \n --> ", net.member_set) ax = fig.add_subplot(221,projection='3d') # 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: net.add_link(b1,b2) ax2 = fig.add_subplot(222,projection='3d') # 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: net.add_link(c1,c2) ax3 = fig.add_subplot(223,projection='3d') # print(net.member_set) net.visualize_3D_graph(ax3, no_of_points_per_edge=10, title="3", this_figure=fig,) # ----------------------------------------------------- # Let us link group members to the group leader and # plot figure 4 # ----------------------------------------------------- print("\nCheck point 4.\nNow we add links between members to leader. See figure 4.") net.add_link("A1","groupA") net.add_link("A2","groupA") net.add_link("A3","groupA") for b1 in groupB: net.add_link(b1,"groupB") for c1 in groupC: net.add_link(c1,"groupC") ax4 = fig.add_subplot(224,projection='3d') net.visualize_3D_graph(ax4, no_of_points_per_edge=10, title="4", this_figure=fig,) plt.show()

Simulation is done using *kero version: 0.5.1.*