【问题标题】:How to change a vehicle route before it enters the map如何在进入地图之前更改车辆路线
【发布时间】:2022-01-13 02:53:23
【问题描述】:

我目前正在Bologna Acosta map 上进行一些实验,用 Python 计算替代路线,并根据一些启发式方法更改输入车辆的路线,并监控 SUMO 指标的变化。

为了了解哪些车辆刚刚进入地图,我这样做了:

vehiclesInside = set()
while step < constants.HORIZON:
    traci.simulationStep(step)

    vehicles = set(traci.vehicle.getIDList())

    newVehicles = vehicles.difference(vehiclesInside)

    for vehicleId in newVehicles:
        route = traci.vehicle.getRoute(vehicleId)
        origin = route[0]
        destination = route[-1]
        newRoute = computeNewRoute(origin, destination)
        traci.vehicle.setRoute(vehicleId, newRoute)

    vehiclesInside = vehicles
    step += constants.TRACI_STEP

问题在于,通过这种方式,车辆会在最适合它们到达原始路线的车道上的入口点弹出,而当我随后更改路线时,所有车辆都在“错误”上导致 DepartDelay 指标增加的车道(车辆因道路空间不足而延误的平均时间)。

Traci 中是否有办法在车辆路线在地图中生成之前更新它们?

【问题讨论】:

  • 为了帮助您,请提供一个最小的可重现问题集,其中包含样本输入、预期输出、实际输出以及重现问题所需的所有相关代码。你所提供的没有达到这个目标。详情请见Minimal Reproducible Example
  • 对不起。我已经更新了原始问题。我的问题不是关于为什么 DepartDelay 会增加(我已经发现了问题以及如何解决它),而是关于如何在车辆实际进入地图之前使用 Traci 更新路线。

标签: python sumo


【解决方案1】:

您可以通过traci.simulation.getLoadedIDshttps://sumo.dlr.de/pydoc/traci._simulation.html#SimulationDomain-getLoadedIDList获取已装载但可能尚未离开的车辆列表。您可以为这些车辆设置一条新路线,就像为离开的车辆设置一条新路线。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-27
    • 2014-04-12
    • 2021-05-15
    • 2020-08-04
    相关资源
    最近更新 更多