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")

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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 algorithm to calculate
#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)

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY