Skip to content

Commit

Permalink
supporting random departpos and arrivalpos for persons. refs #15946
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Dec 20, 2024
1 parent 970ff40 commit d20f2d2
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions tools/randomTrips.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,13 +680,19 @@ def generate_origin_destination(trip_generator, options):

def generate_attributes(idx, departureTime, arrivalTime, origin, destination, intermediate, options):
label = "%s%s" % (options.tripprefix, idx)
combined_attrs = options.tripattrs
if options.pedestrians:
combined_attrs = ""
else:
combined_attrs = options.tripattrs
arrivalPos = ""
if options.randomDepartPos:
randomPosition = samplePosition(origin)
combined_attrs += ' departPos="%.2f"' % randomPosition
if options.randomArrivalPos:
randomPosition = samplePosition(destination)
combined_attrs += ' arrivalPos="%.2f"' % randomPosition
arrivalPos = ' arrivalPos="%.2f"' % randomPosition
if not options.pedestrians:
combined_attrs += arrivalPos
if options.fringeattrs and origin.is_fringe(
origin._incoming, checkJunctions=options.fringeJunctions):
combined_attrs += " " + options.fringeattrs
Expand All @@ -706,11 +712,11 @@ def generate_attributes(idx, departureTime, arrivalTime, origin, destination, in
[e.getID() for e in intermediate])
if options.validate:
vias[label] = via
return label, combined_attrs, attrFrom, attrTo, via
return label, combined_attrs, attrFrom, attrTo, via, arrivalPos

def generate_one_plan(combined_attrs, attrFrom, attrTo, intermediate, options):
def generate_one_plan(combined_attrs, attrFrom, attrTo, arrivalPos, intermediate, options):
element = "walk"
attrs = otherattrs
attrs = otherattrs + arrivalPos
if options.fromStops:
fouttrips.write(' <stop%s duration="0"/>\n' % attrFrom)
attrFrom = ''
Expand All @@ -727,10 +733,10 @@ def generate_one_plan(combined_attrs, attrFrom, attrTo, intermediate, options):
else:
fouttrips.write(' <%s%s%s%s/>\n' % (element, attrFrom, attrTo, attrs))

def generate_one_person(label, combined_attrs, attrFrom, attrTo, departureTime, intermediate, options):
def generate_one_person(label, combined_attrs, attrFrom, attrTo, arrivalPos, departureTime, intermediate, options):
fouttrips.write(
' <person id="%s" depart="%.2f"%s>\n' % (label, departureTime, personattrs))
generate_one_plan(combined_attrs, attrFrom, attrTo, intermediate, options)
' <person id="%s" depart="%.2f"%s%s>\n' % (label, departureTime, personattrs, combined_attrs))
generate_one_plan(combined_attrs, attrFrom, attrTo, arrivalPos, intermediate, options)
fouttrips.write(' </person>\n')

def generate_one_flow(label, combined_attrs, departureTime, arrivalTime, period, options, timeIdx):
Expand All @@ -745,20 +751,20 @@ def generate_one_flow(label, combined_attrs, departureTime, arrivalTime, period,
fouttrips.write((' <flow id="%s" begin="%s" end="%s" period="%s"%s/>\n') % (
label, departureTime, arrivalTime, intIfPossible(period * options.flows), combined_attrs))

def generate_one_personflow(label, combined_attrs, attrFrom, attrTo, departureTime, arrivalTime, period, options, timeIdx):
def generate_one_personflow(label, combined_attrs, attrFrom, attrTo, arrivalPos, departureTime, arrivalTime, period, options, timeIdx):
if len(options.period) > 1:
label = label + "#%s" % timeIdx
if options.binomial:
for j in range(options.binomial):
fouttrips.write((' <personFlow id="%s#%s" begin="%s" end="%s" probability="%.2f"%s>\n') % (
label, j, departureTime, arrivalTime, 1.0 / period / options.binomial,
combined_attrs))
generate_one_plan(combined_attrs, attrFrom, attrTo, intermediate, options)
generate_one_plan(combined_attrs, attrFrom, attrTo, arrivalPos, intermediate, options)
fouttrips.write(' </personFlow>\n')
else:
fouttrips.write((' <personFlow id="%s" begin="%s" end="%s" period="%s"%s>\n') % (
label, departureTime, arrivalTime, intIfPossible(period * options.flows), combined_attrs))
generate_one_plan(combined_attrs, attrFrom, attrTo, intermediate, options)
generate_one_plan(combined_attrs, attrFrom, attrTo, arrivalPos, intermediate, options)
fouttrips.write(' </personFlow>\n')

def generate_one_trip(label, combined_attrs, departureTime):
Expand All @@ -767,14 +773,16 @@ def generate_one_trip(label, combined_attrs, departureTime):

def generate_one(idx, departureTime, arrivalTime, period, origin, destination, intermediate, timeIdx=None):
try:
label, combined_attrs, attrFrom, attrTo, via = generate_attributes(
label, combined_attrs, attrFrom, attrTo, via, arrivalPos = generate_attributes(
idx, departureTime, arrivalTime, origin, destination, intermediate, options)

if options.pedestrians:
if options.flows > 0:
generate_one_personflow(label, combined_attrs, attrFrom, attrTo, departureTime, arrivalTime, period, options, timeIdx)
generate_one_personflow(label, combined_attrs, attrFrom, attrTo, arrivalPos,
departureTime, arrivalTime, period, options, timeIdx)
else:
generate_one_person(label, combined_attrs, attrFrom, attrTo, departureTime, intermediate, options)
generate_one_person(label, combined_attrs, attrFrom, attrTo, arrivalPos,
departureTime, intermediate, options)
else:
if options.jtrrouter:
attrTo = ''
Expand Down

0 comments on commit d20f2d2

Please sign in to comment.