Question: Do you know why my algorithm is not work right? Give a working python logarithm for this problem. The code must print the same result
Do you know why my algorithm is not work right? Give a working python logarithm for this problem. The code must print the same result as the test case example.
Task is next:
Given is a data network with n computers and connections between them. Through each connection, information can be sent from one machine to another at a certain number of bits per second.
Your task is to find out what is the maximum amount of data that can be transferred from a given machine to another in one second.
Implement a Download class with the following methods:
addlink adds a connection from machine a to machine b that transfers x bits per second
calculate calculates the maximum possible transfer amount from machine a to machine b
Implement the class in the file download.py according to the following example.
class Download:
def initself n:
# TRUE
def addlinkself a b x:
# TRUE
def calculateself a b:
# TRUE
if namemain:
d Download
printdcalculate #print must be givn
daddlink
printdcalculate #print must be givn
printdcalculate #print must be givn
printdcalculate #print must be givn
daddlink
daddlink
printdcalculate #print must be givn
printdcalculate #print must be givn
printdcalculate #print must be givn
daddlink
printdcalculate #print must be givn
daddlink
daddlink
daddlink
printdcalculate #print must be givn
printdcalculate #print must be givn
printdcalculate #print must be givn
printdcalculate #print must be givn
printdcalculate #print must be givn
daddlink
printdcalculate #print must be givn
printdcalculate #print must be givn
printdcalculate #print must be givn
daddlink
daddlink
daddlink
printdcalculate #print must be givn
MY ALGORITHM:
class Download:
def initself n:
self.n n
self.graph
for i in range n:
self.graphi
def addlinkself a b capacity:
if b not in self.grapha:
self.graphab
self.graphab capacity
if a not in self.graphb:
self.graphba
def bfsself source, sink, parent:
visited set
queue source
visited.addsource
while queue:
current queue.pop
if current sink:
return True
for adj in self.graphcurrent:
if adj not in visited and self.graphcurrentadj:
queue.appendadj
visited.addadj
parentadj current
if adj sink:
return True
return False
def calculateself source, sink:
parent
maxflow
while self.bfssource sink parent:
pathflow floatInf
s sink
while s source:
pathflow minpathflow, self.graphparentss
s parents
v sink
while v source:
u parentv
self.graphuv pathflow
self.graphvu pathflow
v u
maxflow pathflow
return maxflow
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
