Skip to content

Instantly share code, notes, and snippets.

@abyrd
Created August 12, 2009 17:24
Show Gist options
  • Save abyrd/166621 to your computer and use it in GitHub Desktop.
Save abyrd/166621 to your computer and use it in GitHub Desktop.
Tests / demonstrates calculation of an SPT without making a new Graph
from graphserver.core import *
from graphserver.graphdb import GraphDatabase
import time
import random
gdb = GraphDatabase('trimet_13sep2009.linked.gsdb')
g = gdb.incarnate()
t0 = 1253730000
time.ctime(t0)
stations = [v.label for v in g.vertices if v.label[0:3] == 'sta']
vlabels = random.sample(stations, 50)
orig = 'sta-8334' # Pioneer Square MAX Eastbound
ti = time.time()
for vlabel in vlabels :
ret = g.spt_in_place ( orig, vlabel, State(1, t0))
print time.time() - ti
ti = time.time()
for vlabel in vlabels :
spt = g.shortest_path_tree ( orig, vlabel, State(1, t0))
spt.destroy()
print time.time() - ti
from graphserver.core import *
from graphserver.graphdb import GraphDatabase
import time
gdb = GraphDatabase('bart.linked.gsdb')
g = gdb.incarnate()
t0 = 1253730000
time.ctime(t0)
orig = 'sta-SSAN'
dest = 'sta-FRMT'
g.spt_in_place( orig, dest, State(1, t0))
g.path_in_place( dest )
spt = g.shortest_path_tree( orig, dest, State(1, t0))
vertices, edges = spt.path( dest )
for i in range(len(vertices)) :
v = vertices[i]
vp = v.payload
# print "%s %3i %10s %15s" % (time.ctime(vp.time), vp.weight / 60, vp.trip_id, v.label),
print "%15s %011li %3li %10s" % (v.label, vp.time, vp.weight / 60, vp.trip_id),
try:
e = edges[i]
ep = e.payload
print type(ep).__name__
except:
print "ARRIVAL"
print "\nwalked %i meters, %i vehicles." % (vp.dist_walked, vp.num_transfers)
g.spt_in_place( orig, None, State(1, t0))
stations = [v for v in g.vertices if v.label[0:3] == 'sta']
for v in stations :
vp = v.payload
print "%15s %011li %3li" % (v.label, vp.time, vp.weight / 60)
g.destroy()
gdb = GraphDatabase('trimet_13sep2009.linked.gsdb')
g = gdb.incarnate()
ti = time.time()
vlabels = [v.label for v in g.vertices if v.label[0:3] == 'sta']
for vl in vlabels :
tn = time.time()
spt = g.shortest_path_tree(vl, None, State(1, t0))
print vl, "new tree : ", time.time() - tn
spt.destroy()
tn = time.time()
ret = g.spt_in_place(vl, None, State(1, t0))
print vl, "in place : ", time.time() - tn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment