-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.py
67 lines (50 loc) · 1.75 KB
/
example.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sys
sys.path.pop(0)
import fastpath as fp
import fastpathz as fz
f = open("edges.txt", "r")
#--------------------------------------------------------------------#
# write edges to the graph
#--------------------------------------------------------------------#
for line in f:
edge = tuple(line.rstrip().split("\t"))
ret = fz.add_edge(edge)
ret = fp.add_edge(line)
#--------------------------------------------------------------------#
# find the best path from a source node to a target node
#--------------------------------------------------------------------#
print("\nfastpath", "fastpathz", sep="\t")
for node in zip(fp.get_path(source="A", target="Z"),fz.get_path(source="A", target="Z")):
print(node[0], node[1], sep="\t\t")
# reset everything
fz.empty_graph()
f.seek(0)
#--------------------------------------------------------------------#
# fastpathz only works on integers, so multiply to keep decimal accuracy
#--------------------------------------------------------------------#
#scale = lambda a : (a[0], a[1], str(float(a[2])*1000))
fz.scaling = 4
for line in f:
edge = tuple(line.rstrip().split("\t"))
ret = fz.add_edge(edge)
print("\nfastpathz (scaled)")
for node in fz.get_path(source="A", target="Z"):
print(node, sep="\t\t")
print()
# reset everything
fz.empty_graph()
f.seek(0)
#--------------------------------------------------------------------#
# Writing edges are tab delimited strings is still supported
#--------------------------------------------------------------------#
print("\nfastpath tab delimited")
for line in f:
ret = fz.add_edge(line)
for node in fz.get_path(source="A", target="Z"):
print(node)
f.close()
exit()
# read edges in graph
print("The edges written to graph")
for edge in fz.get_edges():
print(edge)