Skip to main content

SUMO Trip Convert

To facilitate user migration from SUMO, we designed to convert trips from SUMO to MOSS Protobuf Trip format. To perform this conversion, you need perform a map convert with Map Converter first.

Load SUMO map file and Convert the map

from mosstool.map.sumo.map import MapConverter
from mosstool.trip.sumo.route import RouteConverter
from mosstool.type import Map, Persons
from mosstool.util.format_converter import dict2pb
s2m = MapConverter(
net_path="data/sumo/shenzhen.net.xml",
)
m = s2m.convert_map()
id2uid = s2m.get_sumo_id_mappings()

id2uid is a dict recording the mapping relationship between the original IDs in SUMO map and the IDs in MOSS map.

Convert the trip file

map_pb = dict2pb(m, Map())
s2r = RouteConverter(
converted_map=map_pb,
sumo_id_mappings=id2uid,
route_path="./data/sumo/trips.xml",
)
r = s2r.convert_route()
pb = dict2pb(r, Persons())
with open("data/temp/sumo_persons.pb", "wb") as f:
f.write(pb.SerializeToString())
  • converted_map is the MOSS map we acquired with MapConverter.
  • route_path is the path of SUMO trip file xml file. Either incomplete trips (trips and flows) or complete trips (routes) conversion are supported.