ahmad reza
ahmad reza

Reputation: 21

How can I generate trips from specific source and destination in sumo

I need to generate like 1000 trips from a specific edge as the source to another specific edge as The destination in Sumo. how can I do that I tried randotrips.py but it has no option to specify source and destination. Or like is there a way to define some number of sources and destinations and only create routes between them?

I attempted to use randotrips.py to generate trips without specifying a start and finish but encountered difficulty in specifying the source and destination.

Upvotes: 0

Views: 211

Answers (1)

Divyansh Gemini
Divyansh Gemini

Reputation: 178

In randomTrips.py, there is not any option to specify the source & destination edges. But after generating trips.trips.xml, you can modify it using a Python script.

You can use the below script for this purpose:

import xml.etree.ElementTree as ET

filename = 'trips.trips.xml'         # xml file generated using randomTrips.py
source = 'sourceEdge'                # name of the edge needs to be source
destination = 'destinationEdge'      # name of the edge needs to be destination

tree = ET.parse(filename)
routes = tree.getroot()

# iterating over each 'trip' element in parent element (routes)
# and changing values of 'from' & 'to' attributes to source & destination
for trip in routes.iter('trip'):
    trip.set('from', source)
    trip.set('to', destination)

tree.write(networkFile)

Upvotes: 1

Related Questions