-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetPath.py
33 lines (33 loc) · 2.03 KB
/
getPath.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def find_all_paths(graph, start, end, path=[]):
path = path + [start]
if start == end:
return [path]
if not graph.has_key(start):
return []
- paths = []
- for node in graph[start]:
- if node not in path:
- newpaths = find_all_paths(graph, node, end, path)
- for newpath in newpaths:
- paths.append(newpath)
- return paths
-
-
-keys = G.keys()
-start = [None,0]
-
-for k in keys:
- before = len(G[k])
- if before > start[1]:
- start = [k,before]
-
-
-print datetime.datetime.now()
-maxPath = []
-for k in range(len(keys)):
- newPaths = find_all_paths(G,start[0],keys[k])
- for path in newPaths:
- if( len(path) >= len(maxPath)):
- maxPath = path
-print maxPath
-print len(maxPath)