How to clear vehicle's route in SUMO using TraCI/Python

68 Views Asked by At

I'm managing a SUMO simulation using the lib TraCI in python. I want to simulate refueling events in my simulation, but unfortunately, SUMO can't simulate this, so i'm doing it myself. Basically, i can track a vehicle's fuel consumption and store it in a variable. I set a tank volume variable and decrease the fuel consumption of this variable each time step. When the vehicle's fuel is low, i set a route for a parking area and there i "refuel" the vehicle.

I'm trying to simulate a usual behavior that is: A car travel from a point A (it's home) to a point B (it's work). When arrive the point B, travel to point A, and continue doing this process until the fuel is low. When fuel is low, go to a parking area to refuel and then, come back to this route between point A and B.

I can do all of this, but i have a BIG problem. When i arrive the point B, for example, and try do set a route to point A, SUMO concatenate the edges between point B and A in the actual route, instead of setting a new route. This made the vehicles route increase each time i set a new route, what is making my simulation run slower the more time passes. With this performance problem, i can't run simulations longer enough.

When a vehicle arrive the last edge of it's route, i use traci.simulation.findRoute(pointA, PointB).edges to find a route between between these points. Then i set this new route using traci.vehicle.setRoute(veh_id, new_route), but instead of create a new route, sumo concatenate the actual route with the edges of the new route.

I already tried to set a empty route using traci.vehicle.setRoute(veh_id, "") when the vehicle is in the last edge of it's route, but it return error.

I also tried to remove the vehicle and then add a vehicle with the same id, but I can't do this at the same time step, and if i try to remove a vehicle in a time step, in the next time step sumo automatically creates a vehicle before i add my vehicle.

0

There are 0 best solutions below