route = ['road 3', 'exit 2'] cf_p = [35, 1.3, 2, 1.1, 1.5] lc_p = [-8, -20, .6, .1, 0, .2, .1, 20, 20] kwargs = {'route': route, 'maxspeed': cf_p[0]-1e-6, 'relax_parameters':8.7, 'shift_parameters': [-2, 2], 'hdbounds':(cf_p[2]+1e-6, 1e4)} self.newveh = hs.Vehicle(vehid, self, cf_p, lc_p, **kwargs) return mainroad_newveh # boundary conditions increment_inflow = {'method': 'seql2', 'kwargs':{'c':.8, 'eql_speed':True, 'transition':19}} mainroad_inflow = lambda *args: .65 road1.set_upstream(increment_inflow=increment_inflow, get_inflow={'time_series': mainroad_inflow}, new_vehicle=newveh_wrapper(.95), self_indices=[0]) road1.set_upstream(increment_inflow=increment_inflow, get_inflow={'time_series': mainroad_inflow}, new_vehicle=newveh_wrapper(.5), self_indices=[1]) road1.set_upstream(increment_inflow=increment_inflow, get_inflow={'time_series': mainroad_inflow}, new_vehicle=newveh_wrapper(.05), self_indices=[2]) # Make simulation simulation = hs.Simulation(roads=[road1, road2, road3], dt = .25) #%% timesteps=10000 start = time.time() simulation.simulate(timesteps) end = time.time() all_vehicles = simulation.prev_vehicles.copy() all_vehicles.extend(simulation.vehicles) print('simulation time is '+str(end-start)+' over '+str(sum([timesteps - veh.start+1 if veh.end is None else veh.end - veh.start+1 for veh in all_vehicles]))+' timesteps') #%% # laneinds = {road1[0]:0, road1[1]:1, road1[2]:2, road2[0]:3, road2[1]:4, road3[0]:5, road3[1]:6} # sim, siminfo = hp.plot_format(all_vehicles, laneinds) # hp.platoonplot(sim, None, siminfo, lane = 5, opacity = 0, colorcode=False)
}, { 'event': 'exit', 'pos': mainroadlen }] lane2.events = [{ 'event': 'update lr', 'left': 'add', 'left anchor': 0, 'right': None, 'pos': startmerge }] #make simulation merge_lanes = [lane1, lane2] inflow_lanes = [lane0, lane1, lane2] simulation = hs.Simulation(inflow_lanes, merge_lanes, dt=.25) #call timesteps = 480 * 30 start = time.time() simulation.simulate(timesteps) end = time.time() all_vehicles = simulation.prev_vehicles.copy() all_vehicles.extend(simulation.vehicles) print('simulation time is ' + str(end - start) + ' over ' + str( sum([ timesteps - veh.starttime + 1 if veh.endtime is None else veh.endtime - veh.starttime + 1 for veh in all_vehicles ])) + ' timesteps')
main_road.set_downstream(downstream1) main_road.set_upstream(increment_inflow=increment_inflow, get_inflow=get_inflow2, new_vehicle=mainroad_newveh) downstream2 = { 'method': 'free merge', 'self_lane': onramp_road[0], 'stopping': 'car following' } onramp_road.set_downstream(downstream2) onramp_road.set_upstream(increment_inflow=increment_inflow_ramp, get_inflow=get_inflow1, new_vehicle=onramp_newveh) # Make simulation simulation = hs.Simulation(roads=[main_road, onramp_road], dt=.25) #call timesteps = 10000 start = time.time() simulation.simulate(timesteps) end = time.time() all_vehicles = simulation.prev_vehicles.copy() all_vehicles.extend(simulation.vehicles) print('simulation time is ' + str(end - start) + ' over ' + str( sum([ timesteps - veh.start + 1 if veh.end is None else veh.end - veh.start + 1 for veh in all_vehicles ])) + ' timesteps')
return hs.Vehicle(vehid, mainroad[0], cf_p, lc_p, **kwargs) vehicles = set() eql_hd = tempveh.get_eql(eql_speed) curpos = 1e5 prev_veh = None for i in range(nveh): veh = newveh(i) veh.lead = prev_veh veh.initialize(curpos, eql_speed, eql_hd, 0) vehicles.add(veh) curpos += -veh.len - eql_hd prev_veh = veh simulation = hs.Simulation(vehicles=vehicles, dt=dt) start = time.time() simulation.simulate(nt) # number of timesteps end = time.time() all_vehicles = simulation.vehicles print('simulation time is ' + str(end - start) + ' over ' + str( sum([ nt - veh.start + 1 if veh.end is None else veh.end - veh.start + 1 for veh in all_vehicles ])) + ' timesteps') #%% basic plotting laneinds = {mainroad[0]: 0} sim, siminfo = hp.plot_format(all_vehicles, laneinds) hp.platoonplot(sim, None, siminfo, lane=0, opacity=0)