1
2 '''
3 Created on Aug 12, 2010
4
5 @author: dwmclary
6 '''
7 import sys
8 import re
9
11 - def __init__(self, nID=None, distance=None, adj=None, path=None):
12 if nID != None:
13 self.nID = nID
14 self.distance = distance
15 self.adj = adj
16 self.path = path
17
19 s = str(self.nID)+ " "+ " ".join(map(str,self.adj)) +\
20 " d: "+str(self.distance) + " path: " + " ".join(map(str,self.path))
21 return s
22
25
26
28 for line in file:
29 line = line.rstrip()
30 if line[0] != comment:
31 entry = line.split(sep)
32 nid = entry[0]
33 if "d:" in entry:
34 d_index = entry.index("d:")
35 distance = float(entry[d_index+1])
36 p_index = entry.index("path:")
37 path = entry[p_index+1:]
38 adj = entry[1:d_index]
39 else:
40 distance = float('inf')
41 path = []
42 adj = entry[1:]
43
44 node = BFSNode(nid,distance,adj, path)
45 yield node
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
72 data = read_adjacency(sys.stdin)
73 for node in data:
74 if node.nID == n:
75 node.distance = 0.0
76 print n + " pathlen: 0.0" + " path: "
77 d = node.distance
78
79 print node
80
81 for m in node.adj:
82 path = [node.nID] + node.path
83 print m + " pathlen: " + str(d+1) + " path: " + ",".join(path)
84
85
86
87
88
89 if __name__ == "__main__":
90 try:
91 import psyco
92 psyco.full()
93 except:
94 pass
95 source = open("pbfs_source").readlines()
96 source = source[0].strip()
97 main(source)
98