Skip to content

Commit

Permalink
filtering duplicate mapping deviations, limit representatives #46
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Jan 9, 2023
1 parent ece765c commit 1587e47
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
12 changes: 7 additions & 5 deletions get_trips.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def write_background_trips(conn, trip_table, limit, tripfile, params):
return command


def write_all_pairs(conn, vType, depart, limit, tripfile, params, seed, mode=MODE.car):
def write_all_pairs(conn, vType, depart, limit, tripfile, params, seed, mode=MODE.car, bbox=None):
random.seed(seed)
fieldnames = TH.KEEP_COLUMNS + [THX.depart_second]
template = list(fieldnames)
Expand All @@ -196,10 +196,12 @@ def write_all_pairs(conn, vType, depart, limit, tripfile, params, seed, mode=MOD
num_samples = 5
reps = collections.defaultdict(list)
cursor = conn.cursor()
command = """SELECT taz_num_id, id, st_X(representative_coordinate), st_Y(representative_coordinate)
FROM core.%s r, core.%s t WHERE r.taz_id = t.taz_id ORDER BY taz_num_id, id""" % (
params[SP.representatives], params[SP.taz_table])
cursor.execute(command)
command = """SELECT taz_num_id, id, st_X(representative_coordinate) AS X, st_Y(representative_coordinate) AS Y
FROM core.%s r, core.%s t WHERE r.taz_id = t.taz_id""" % (
params[SP.representatives], params[SP.taz_table])
if bbox:
command += " AND X > %s AND Y > %s AND X < %s AND Y < %s" % tuple(bbox.split(","))
cursor.execute(command + " ORDER BY taz_num_id, id")
for row in cursor:
reps[row[0]].append(row[1:])
keys = sorted(reps.keys())
Expand Down
7 changes: 7 additions & 0 deletions t2s.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def fillOptions(argParser):
argParser.add_argument("--subnet-file", help="specifying the subnet to use to rerun a subnet assignment")
argParser.add_argument("--resume", action="store_true", default=False,
help="reuse existing files instead of overwriting them")
argParser.add_argument("-b", "--representatives-bbox",
help="bounding box to limit valid taz represantives (west,south,east,north)")


def getSumoTripfileName(trips_dir, tapas_trips):
Expand Down Expand Up @@ -370,6 +372,10 @@ def map_trips(trip_sequence, vTypes, max_radius):


def checkDeviations(tazMap, deviations, xycoord, taz, map_result, uid, log):
key = (xycoord, taz)
if key in deviations.reported:
return
deviations.reported.add(key)
minDist, minEdge, minInTazEdge, minInTazDist = map_result
if minEdge is not None and minDist is not None:
if taz and (taz not in tazMap or minEdge not in tazMap[taz]):
Expand Down Expand Up @@ -424,6 +430,7 @@ def map_to_edges(options, parallel=False):
deviations = Statistics("Mapping deviations")
deviations.unmapped = 0
deviations.noTazEdge = 0
deviations.reported = set()

with open(options.mapped_log, 'w') as logfile:
if os.name == "nt":
Expand Down
6 changes: 4 additions & 2 deletions tsc_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ def run_all_pairs(options, conn, sim_key, params, final_routes, final_weights):
trips_file = None
if not os.path.exists(options.tapas_trips) or not options.resume:
trips_file = options.tapas_trips
get_trips.write_all_pairs(conn, vType, begin_second, options.limit, trips_file, params, options.seed)
get_trips.write_all_pairs(conn, vType, begin_second, options.limit, trips_file, params, options.seed,
bbox=options.representatives_bbox)
write_status('>>> starting all pairs t2s using tripfile %s' %
options.tapas_trips, sim_key, params, conn)
conn.close()
Expand All @@ -308,7 +309,8 @@ def run_all_pairs(options, conn, sim_key, params, final_routes, final_weights):
write_status('>>> starting all pairs for public transport', sim_key, params, conn)
if params[SP.representatives]:
options.tapas_trips = get_trips.tripfile_name("%s_public" % (get_trips.ALL_PAIRS), target_dir=options.trips_dir)
get_trips.write_all_pairs(conn, "public", 31 * 3600, options.limit, options.tapas_trips, params, options.seed, MODE.public)
get_trips.write_all_pairs(conn, "public", 31 * 3600, options.limit, options.tapas_trips, params,
options.seed, MODE.public, bbox=options.representatives_bbox)
write_status('>>> starting all pairs t2s using tripfile %s' % options.tapas_trips, sim_key, params, conn)
conn.close()
rou_file, _ = t2s.main(options)
Expand Down

0 comments on commit 1587e47

Please sign in to comment.