def initialize(traci): os.system("cls") print("Initializing...") preprocess.initialize_nx() preprocess.initialize_edges_for_spawns_and_sinks(traci) target.initialize(traci) env.traci = traci vehicle.initialize() 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 # ~ env.update_vehicle_info = True print("Initialization complete!") return
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
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 initialize(traci): os.system("cls") print("Initializing...") preprocess.initialize_nx() preprocess.initialize_shortest_path_weights() preprocess.initialize_edges_for_spawns_and_sinks(traci) target.initialize(traci) n = 0 total = env.veh_exists_max for i in range(0, env.veh_exists_max): vehicle.add(traci) n += 1 purr.update(n, total, msg="Adding first %d vehicles " % (env.veh_exists_max)) continue if env.method == 'nash': env.dist = distance() print("Initialization complete!") return