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): # 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
def initialize(traci): os.system("cls") print("Initializing...") env.traci = traci preprocess.initialize_nx() preprocess.initialize_edges_and_nodes() point.validate() vehicle.initialize() target.initialize(traci) spm.generate_tar2dest() env.dist = distance.distance() n = 0 total = env.veh_exists_max for i in range(0, env.veh_exists_max): vehicle.add() n += 1 purr.update(n, total, msg="Adding first %d vehicles " % (env.veh_exists_max)) continue print() vehicle.update() spm.update_veh2tar() env.nash_assigner = ss2.nashAssigner(N=len(env.vPd), M=len(env.tP), R=env.R, tau=env.tau, dist=env.dist) if env.method == "greedy": vehicle.set_route(env.nash_assigner.greedyAssignments()) else: vehicle.set_route(env.nash_assigner.getAssignments()) # ~ env.update_vehicle_info = True print("Initialization complete!") return
def update(derby): return new(vehicle.update(vehicle.wander(v)) for v in derby)