import numpy as np import __basik__ as bk if __name__ == '__main__': bk.VehicleDisplay.speed_up_factor = 10 bk.Vehicle.frames_per_move = 2 np.random.seed(123) bk.Queue.clear() fig,ax = bk.axes_grid(1,1,scale=5) end_time = 20 # Let us create a single lane object lane = bk.Lane(20) lane_display = bk.RoadDisplay(left_lane=lane, right_lane=None, axes=ax[0,0], horizontal=True, square_image=False) # removes some detail and gives a road strip rate = {end_time:bk.Rate(0.5)} source = bk.Source(vehicle_velocity = 16.67, # INITIAL VELOCITY is 60 km/h target_node = lane.IN, rate_schedule=rate) source.setup_arrivals(20) # Let us schedule three obstructions at some node lane.nodes[5].assign_velocity_change(5.55) # change to about 20 km/h lane.nodes[10].assign_velocity_change(27.77) # change to about 100 km/h # Run plt.pause(4)
''' Produces two-way stop street display from Tutorial 3. ''' import numpy as np import __basik__ as bk if __name__ == '__main__': print('Setting up simulation...') np.random.seed(123) fig, ax = bk.axes_grid(3, 1, scale=2.5) end_time = 20 lane_length = 5 bk.Queue.clear() # North: Nlane_in = bk.Lane(lane_length) Nlane_out = bk.Lane(lane_length) NDisplay = bk.RoadDisplay(left_lane=Nlane_out, right_lane=Nlane_in, axes=ax[0, 0], horizontal=False) Nrate = {end_time: bk.Rate(2)} Nsource = bk.Source(vehicle_velocity=16.67, target_node=Nlane_in.IN, rate_schedule=Nrate) print('Scheduling Northern arrivals...') Nsource.setup_arrivals(end_time) print('..done!') Nrecord = bk.Record(Nlane_out.OUT) # South
Runs the display of Tutorial 3. ''' import __basik__ as bk import numpy as np if __name__ == '__main__': np.random.seed(123) print('Setting up simulation...') bk.VehicleDisplay.SHOW = True # We turn on the display bk.VehicleDisplay.speed_up_factor = 10 # make the display attempt to render faster bk.Vehicle.frames_per_move = 2 # the amount of frames per move. Larger = smoother = slower fig,ax = bk.axes_grid(3,3,scale=2.5) # we build a display grid end_time = 20 lane_length = 5 # SMALL: easier to see in the display. bk.Queue.clear() # North: Nlane_in = bk.Lane(lane_length) Nlane_out = bk.Lane(lane_length) NDisplay = bk.RoadDisplay(left_lane=Nlane_out, right_lane=Nlane_in, axes=ax[0,1], horizontal=False) Nrate = {end_time:bk.Rate(0.8)} Nsource = bk.Source(vehicle_velocity = 16.67, target_node = Nlane_in.IN, rate_schedule=Nrate) print('Scheduling Northern arrivals...')