Vote count:
0
is there a way of altering the python implementation of the FF algorithm (from wikipedia) so that the required details are obtained from a text file?
For example, if I have a text file which stores an adjacency matrix such as:
0, 1, 2
1, 0, 3
2, 3, 0
How would I go about editing the code to obtain these values from the next file rather than hardcoding them, as in the example below?
g=FlowNetwork()
map(g.add_vertex, ['a','b','c'])
g.add_edge('a','b',1)
g.add_edge('a','c',2)
g.add_edge('b','c',3)
print g.max_flow('a','c')
I have split the file 'example.txt' using the below code, to obtain the individual entries but I can't figure out how to use this.
def createNetworkTable():
with open("example.txt", "r") as txtfile:
numberOfNodes = 0
network = []
for line in txtfile:
numberOfNodes += 1
line = line.replace("\n","")
line = line.replace("\r","")
chars = line.split(",")
ints = []
for char in chars:
ints.append(int(char))
network.append(ints)
txtfile.closed
return network
Any advice would be helpful
Thanks
asked 33 secs ago
Aucun commentaire:
Enregistrer un commentaire