Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[sumo-user] Add vehicles to simulation

Hi there,

I am trying to randomly place a finite (and specific) set of vehicles in certain parts of a map network in SUMO using Flow along with the Traci simulator but... without using Flow's inflows() objects.
When running the flow.envs.base.reset()  to reset the sim with a new randomized configuration, one of the vehicles added is missing.

Let network_object = flow.networks.Network(....) derived from Flow. I can confirm it has the correct ID list and initial state configuration (ID, lane_ID, position, velocity) in its fields. When calling Flow reset(), running self.k.kernel_api.vehicle.getIDList() confirms there are missing vehicles relative to network_object.vehicles.ids. After detecting this discrepancy, Flow errors out.

The error message form is:

  File "~/", line N, in reset
    return super().reset()
  File "/tmp/ucrl/flow/envs/", line M, in reset
    raise FatalFlowError(msg=msg)
Not enough vehicles have spawned! Bad start?
Missing vehicles / initial state:
- vehicle_X : ('vehicle_type_X', 'custom_road_name', lane_id, position, velocity)
A hack that seems to help is adding the following code inside of the missing vehicles check before returning the observation vector to the simulation environment:

  # check to make sure all vehicles have been spawned
  if len(network_object.initial_ids) > len(self.k.kernel_api.vehicle.getIDList()):
      missing_vehicles = list(set(self.initial_ids) - set(initial_ids))
      for mv in missing_vehicles:
          self.k.kernel_api.vehicle.remove(mv)  # FIXME: hack
          type_id, edge, lane_index, pos, speed = self.initial_state[mv]
          # update the information in each kernel to match the current state

I am not sure why the missing vehicle was not added before reaching this part of the code. Is this a problem that others have seen before? Any suggested fixes if we do not want to use Inflows()?

Thanks as always for your time and your help!


Back to the top