Commit 31c777ea authored by dagal's avatar dagal

Successful new gen

parent a5aed23a
#!/bin/bash
USER=postgres
PW=postgres
DB=trippydb
PGPASSWORD=$PW psql -h localhost -U $USER -d $DB -q -f schema.sql
PGPASSWORD=$PW psql -h localhost -U $USER -d $DB -q -f emt_stops.sql
PGPASSWORD=$PW psql -h localhost -U $USER -d $DB -q -f emt_lines.sql
PGPASSWORD=$PW psql -h localhost -U $USER -d $DB -q -f emt_linestops.sql
PGPASSWORD=$PW psql -h localhost -U $USER -d $DB -q -f emt_journeys.sql
unzip -p emt_stages.zip | PGPASSWORD=$PW psql -h localhost -U $USER -d $DB -q
...@@ -114,22 +114,24 @@ class Network(): ...@@ -114,22 +114,24 @@ class Network():
fls = open(prefix + "_linestops.sql", "w") fls = open(prefix + "_linestops.sql", "w")
for trip in self.trips.values(): for trip in self.trips.values():
stops = [s for (_,_,s) in trip.stops]
if len(set(stops)) < len(stops):
sys.stderr.write("Skipping line %s trip %s\n" % (trip.get_line(), trip.id))
continue
if prefix: if prefix:
line = trip.get_line() line = trip.get_line()
stops = [s for (_,_,s) in trip.stops]
if line in lineStops: if line in lineStops:
if lineStops[line] != stops: if len(lineStops[line]) != len(stops):
sys.stderr.write(line + ": " + lineStops[line] + " vs " + stops + "\n") sys.stderr.write(line + ": " + lineStops[line] + " vs " + stops + "\n")
else: else:
lineStops[line] = stops lineStops[line] = stops
if len(set(stops)) == len(stops): for i,s in enumerate(stops):
for i,s in enumerate(stops): mystr = "INSERT INTO line_stop (line_id, stop_id, seq) VALUES ('%s', '%s', %d);\n" % (line, s, i+1)
mystr = "INSERT INTO line_stop (line_id, stop_id, seq) VALUES ('%s', '%s', %d);\n" % (line, s, i+1) fls.write(mystr.encode("utf-8"))
fls.write(mystr.encode("utf-8"))
else:
sys.stderr.write("Skipping line " + line + "\n")
for day in [d[0] for d in enumerate(trip.days) if d[1]]: for day in [d[0] for d in enumerate(trip.days) if d[1]]:
for _,end_time,stop in trip.stops: for _,end_time,stop in trip.stops:
...@@ -369,10 +371,10 @@ def main(argv): ...@@ -369,10 +371,10 @@ def main(argv):
#prefix = None #prefix = None
prefix = "emt" prefix = "emt"
n_traj = 0 #n_traj = 0
#n_traj = 10 #n_traj = 10
#n_traj = 100000 #n_traj = 100000
#n_traj = 10000000 n_traj = 10000000
#change_probs = [0.50, 0.90, 0.95, 0.98, 1.0] #change_probs = [0.50, 0.90, 0.95, 0.98, 1.0]
#change_probs = [0.98, 0.98, 0.99, 1.0] #change_probs = [0.98, 0.98, 0.99, 1.0]
switch_weights = [10, 10, 5, 1] switch_weights = [10, 10, 5, 1]
...@@ -417,6 +419,9 @@ def main(argv): ...@@ -417,6 +419,9 @@ def main(argv):
n_switch = [x*n_traj/sum(switch_weights) for x in switch_weights] n_switch = [x*n_traj/sum(switch_weights) for x in switch_weights]
n_switch[0] += n_traj - sum(n_switch) n_switch[0] += n_traj - sum(n_switch)
if prefix:
ft = open(prefix + "_stages.sql", "w")
while i < n_traj: while i < n_traj:
current_day = getRandomDay() current_day = getRandomDay()
origin = network.stops[random.choice(tripsByStop[current_day.val() % 7].keys())] origin = network.stops[random.choice(tripsByStop[current_day.val() % 7].keys())]
...@@ -503,11 +508,19 @@ def main(argv): ...@@ -503,11 +508,19 @@ def main(argv):
lengths.update([len(trajectory)]) lengths.update([len(trajectory)])
unused_stops.difference_update(trajectory) unused_stops.difference_update(trajectory)
if prefix:
for j in xrange(len(trajectory)/2):
ft.write("INSERT INTO stage (trip_id, num_stage, line_id, journey_id, board_stop, alight_stop) ")
ft.write("VALUES (%d, %d, '%s', %d, '%s', '%s');\n" % (i, j, lines[j*2], times[j*2], trajectory[j*2], trajectory[j*2+1]))
sys.stdout.write(",".join(map(lambda (l,s,t): "%s:%s:%s" % (l,str(stops_dict[s]),str(t)), zip(lines, trajectory, times)))) sys.stdout.write(",".join(map(lambda (l,s,t): "%s:%s:%s" % (l,str(stops_dict[s]),str(t)), zip(lines, trajectory, times))))
sys.stdout.write("\n") sys.stdout.write("\n")
i+=1 i+=1
if prefix:
ft.close()
if unused_stops: if unused_stops:
sys.stderr.write("\nWARNING: " + str(len(unused_stops)) + " Unused stops\n") sys.stderr.write("\nWARNING: " + str(len(unused_stops)) + " Unused stops\n")
...@@ -519,6 +532,8 @@ def main(argv): ...@@ -519,6 +532,8 @@ def main(argv):
sys.stderr.write("\nLENGTHS: " + str(lengths) + "\n") sys.stderr.write("\nLENGTHS: " + str(lengths) + "\n")
sys.stderr.write("\nCHANGES: " + str(changes) + "\n") sys.stderr.write("\nCHANGES: " + str(changes) + "\n")
for k,v in changes.iteritems(): for k,v in changes.iteritems():
sys.stderr.write(str(k) + " " + str(float(v)/n_traj) + "\n") sys.stderr.write(str(k) + " " + str(float(v)/n_traj) + "\n")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment