Skip to content

Commit 1059649

Browse files
committed
refined verbose output #16326
1 parent 7ec687f commit 1059649

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

tools/import/gtfs/gtfs2pt.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,10 @@ def traceMap(options, typedNets, fixedStops, stopLookup, invEdgeMap, radius=150)
213213
if options.verbose:
214214
print("mapping", mode)
215215
net = sumolib.net.readNet(os.path.join(options.network_split, mode + ".net.xml"))
216+
mode_edges = set([e.getID() for e in net.getEdges()])
216217
netBox = net.getBBoxXY()
217218
numTraces = 0
219+
numRoutes = 0
218220
filePath = os.path.join(options.fcd, mode + ".fcd.xml")
219221
if not os.path.exists(filePath):
220222
return []
@@ -229,7 +231,8 @@ def traceMap(options, typedNets, fixedStops, stopLookup, invEdgeMap, radius=150)
229231
for idx, xy in enumerate(trace):
230232
candidates = stopLookup.getCandidates(xy)
231233
if candidates:
232-
vias[idx] = [invEdgeMap[lane2edge(stop.lane)] for stop in candidates]
234+
all_edges = [invEdgeMap[lane2edge(stop.lane)] for stop in candidates]
235+
vias[idx] = [e for e in all_edges if e in mode_edges]
233236
for idx in range(len(trace)):
234237
fixed = fixedStops.get("%s.%s" % (tid, idx))
235238
if fixed:
@@ -238,9 +241,10 @@ def traceMap(options, typedNets, fixedStops, stopLookup, invEdgeMap, radius=150)
238241
fillGaps=options.fill_gaps, gapPenalty=5000., vias=vias,
239242
reversalPenalty=1000.)
240243
if mappedRoute:
244+
numRoutes += 1
241245
routes[tid] = [e.getID() for e in mappedRoute]
242246
if options.verbose:
243-
print("mapped", numTraces, "traces to", len(routes), "routes.")
247+
print("mapped", numTraces, "traces to", numRoutes, "routes.")
244248
return routes
245249

246250

tools/sumolib/route.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,30 @@ def mapTrace(trace, net, delta, verbose=False, airDistFactor=2, fillGaps=0, gapP
9494
result = ()
9595
paths = {} # maps a path stub to a pair of current cost and the last mapping position on the last edge
9696
lastPos = None
97+
nPathCalls = 0
98+
nNoCandidates = 0
9799
if verbose:
98-
print("mapping trace with %s points" % len(trace))
100+
print("mapping trace with %s points ... " % len(trace), end="", flush=True)
99101
for idx, pos in enumerate(trace):
102+
x, y = pos
100103
newPaths = {}
101104
if vias and idx in vias:
102105
candidates = []
103106
for edgeID in vias[idx]:
104107
if net.hasEdge(edgeID):
105108
candidates.append((net.getEdge(edgeID), 0.))
106109
else:
107-
print("Unknown via edge %s for %s,%s" % (edgeID, pos[0], pos[1]))
110+
print("Unknown via edge %s for %s,%s" % (edgeID, x, y))
108111
else:
109-
candidates = net.getNeighboringEdges(pos[0], pos[1], delta, not net.hasInternal)
112+
candidates = net.getNeighboringEdges(x, y, delta, not net.hasInternal)
110113
if debug:
111-
print("\n\npos:%s, %s" % (pos[0], pos[1]))
114+
print("\n\npos:%s, %s" % (x, y))
112115
print("candidates:%s\n" % [(e.getID(), c) for e, c in candidates])
113116
if verbose and not candidates:
114-
print("Found no candidate edges for %s,%s" % pos)
117+
if nNoCandidates == 0:
118+
print()
119+
print(" Found no candidate edges for %s,%s (index %s) " % (x, y, idx))
120+
nNoCandidates += 1
115121

116122
for edge, d in candidates:
117123
if vClass is not None and not edge.allows(vClass):
@@ -139,6 +145,7 @@ def mapTrace(trace, net, delta, verbose=False, airDistFactor=2, fillGaps=0, gapP
139145
extension, cost = net.getOptimalPath(path[-1], edge, maxCost=maxGap,
140146
reversalPenalty=reversalPenalty,
141147
fromPos=lastBase, toPos=base)
148+
nPathCalls += 1
142149
if extension is None:
143150
airLineDist = euclidean(
144151
path[-1].getToNode().getCoord(),
@@ -176,6 +183,10 @@ def mapTrace(trace, net, delta, verbose=False, airDistFactor=2, fillGaps=0, gapP
176183
result += minPath
177184
paths = newPaths
178185
lastPos = pos
186+
if verbose:
187+
if nNoCandidates > 0:
188+
print("%s Points had no candidates. " % nNoCandidates, end="")
189+
print("(%s router calls)" % nPathCalls)
179190
if paths:
180191
if debug:
181192
print("**************** result:")

0 commit comments

Comments
 (0)