Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[sumo-user] Efficient way to count #vehicles within a distance of junction

Hi SUMO community,

I'm using TraCI to control traffic lights and would like the traffic light to know the number of cars approaching it. Also, I'm only interested in counting vehicles that are close enough, i.e. within 20 meters.

My current implementation is to get the ID of vehicles on a lane and calculate the distance to the junction. Code is shown as follows. But is there a more efficient way fo doing so?

Thanks,
Shuyi

def numberv(lane):
    nb = 0
    for k in traci.lane.getLastStepVehicleIDs(lane):
        if traci.vehicle.getLanePosition(k) < X-100:
             nb += 1
    return nb


Back to the top