i get the executable source code of my program as a python .py file. #Here the nodes in the given network is added network=[] print('Enter Number of Vertices') V=int(input()) def addnode(u,v,w): network.append([u,v,w]) #to give the nodes the variables as in the network provided nodes=['U','V','W','X','Y','Z'] #this function is used for showing the output of the routing table generated def printTable(dist,pred): print("Vertex Shortest Distance from Source")
Can i get the executable source code of my program as a python .py file.
#Here the nodes in the given network is added
network=[]
print('Enter Number of Vertices')
V=int(input())
def addnode(u,v,w):
network.append([u,v,w])
#to give the nodes the variables as in the network provided
nodes=['U','V','W','X','Y','Z']
#this function is used for showing the output of the routing table generated
def printTable(dist,pred):
print("Vertex Shortest Distance from Source")
for i in range(V):
print(nodes[i]+" "+ str( dist[i]))
print("Vertex Predecessor")
for i in range(V):
print(nodes[i] + " " + str(pred[i]))
print("Vertex Number of hops from Source Node")
for i in range(V):
count = 0
m=i
while(pred[m]is not 0):
count += 1
m=pred[m]
print(nodes[i]+" "+str(count))
#this function uses the Bellman Ford
#the shortest path of the source node to each of it's neighbour nodes
def BellmanFord(srcNode):
dist=[float('Inf')]*V
pred=['']*V
dist[srcNode]=0
pred[0]=0
print('Node Neighbour Distance')
for i in range(V-1): #as it needs to be iterated V-1 times
print("ITERATION-"+str(i+1))
for u,v,w in network:
if(dist[u]+w < dist[v]):
dist[v]=dist[u]+w
pred[v]=u
for i in range(V):
print(nodes[i] + " " + str(dist[i]))
for u,v,w in network:
if dist[u]!=float('Inf') and dist[u]+w < dist[v]:
print('Negative weight cycle is present in the network')
return
printTable(dist,pred)
#Each node is added as provided in the network
addnode(0, 1, 3)
addnode(0, 2, 7)
addnode(0, 3, 1)
addnode(1, 2, 1)
addnode(1, 3, 1)
addnode(2, 3, 4)
addnode(2, 4, 5)
addnode(2, 5, 6)
addnode(3, 4, 2)
addnode(3, 1, 1)
addnode(4, 5, 3)
Step by step
Solved in 2 steps