def timestep(traci, n_step): # Take samples if neccesary for vid in traci.vehicle.getIDList(): if vehicle.is_veh_at_target(vid): vehicle.sample(vid, n_step) if env.method == "smart" and env.recalculate_nash: env.recalculate_nash = False vehicle.update() spm.update_veh2tar() vehicle.set_route(env.nash_assigner.getAssignments()) # End of Simulation condition if (traci.vehicle.getIDCount() <= 0) and (env.veh_id_counter >= (env.veh_total - 1)): print("All vehicles have arrived at their destinations.") return False # Add another vehicle condition elif traci.vehicle.getIDCount( ) < env.veh_exists_max and env.veh_id_counter < env.veh_total: print("\nAdding another vehicle.", env.veh_id_counter, env.veh_total) vehicle.add() return True
def timestep(traci, n_step): env.traci = traci env.vids_active = traci.vehicle.getIDList() if env.method == 'nash': if env.recalculate_nash: nash.recalculate() # Check the position of each vehicle for vid in env.vids_active: if vehicle.is_veh_at_target(traci, vid): vehicle.sample(vid, n_step) # Simulation is ending if len(env.vids_active) == 0 and env.veh_id_counter >= env.veh_total: print("\nSimulation complete. Finalizing...") return False # Create more vehicles if neccesary elif len(env.vids_active ) < env.veh_exists_max and env.veh_id_counter < env.veh_total: print("\nAdding vehicle %d/%d." % (env.veh_id_counter + 1, env.veh_total)) vehicle.add(traci) return True
def timestep(traci, n_step): # Take samples if neccesary for vid in traci.vehicle.getIDList(): if vehicle.is_veh_at_target(vid): vehicle.sample(vid, n_step) # We will wait until all vehicles spawn before assigning new routes. This may take 2-3 steps if env.first_update and (traci.vehicle.getIDCount() == env.veh_exists_max): env.first_update = False env.baseline_assign = True env.recalculate_nash = True env.update_vehicle_info = True # Update vehicle info if needed if (env.update_vehicle_info): vehicle.update() spm.update_veh2tar() # Set baseline assignments if env.method == 'baseline' and env.baseline_assign: env.baseline_assign = False baseline.assign() # Set Nash asignments if env.method == 'nash' and env.recalculate_nash: env.recalculate_nash = False nash.get_assignments() # End of Simulation condition if (traci.vehicle.getIDCount() <= 0) and (env.veh_id_counter >= (env.veh_total - 1)): print("All vehicles have arrived at their destinations.") return False # Add another vehicle condition elif traci.vehicle.getIDCount( ) < env.veh_exists_max and env.veh_id_counter < env.veh_total: print("\nAdding another vehicle.", env.veh_id_counter, env.veh_total) vehicle.add() return True