Ejemplo n.º 1
0
 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
 Slane_in = bk.Lane(lane_length)
 Slane_out = bk.Lane(lane_length)
 SDisplay = bk.RoadDisplay(left_lane=Slane_in,
                           right_lane=Slane_out,
                           axes=ax[2, 0],
                           horizontal=False)
 Srate = {end_time: bk.Rate(2)}
 Ssource = bk.Source(vehicle_velocity=16.67,
                     target_node=Slane_in.IN,
'''
Produces the type 1 obstruction crossing from Tutorial 7.
'''

import numpy as np
import __basik__ as bk

if __name__ == '__main__':

    end_time = 20
    np.random.seed(123)
    fig, ax = plt.subplots(1, 1)
    # Let us create a single lane object
    lane = bk.Lane(10)
    lane_display = bk.RoadDisplay(left_lane=lane,
                                  right_lane=None,
                                  axes=ax,
                                  horizontal=True)
    rate = {end_time: bk.Rate(0.3)}
    source = bk.Source(vehicle_velocity=16.67,
                       target_node=lane.IN,
                       rate_schedule=rate)
    source.setup_arrivals(20)
    # Let us schedule three obstructions at some node
    lane.nodes[4].schedule_obstructions(start_times=[0, 20], durations=[9, 5])
    # Run

    bk.Queue.run(end_time)
Ejemplo n.º 3
0
 print('Setting up simulation...')
 np.random.seed(123)
 fig,ax = bk.axes_grid(3,3,scale=2.5)  
 end_time = 21
 lane_length = 5 
 bk.Queue.clear()
 # East 
 Elane_in = bk.Lane(lane_length) 
 Elane_out = bk.Lane(lane_length) 
 EDisplay = bk.RoadDisplay(left_lane=Elane_out,
                           right_lane=Elane_in,
                           axes=ax[1,2],
                           horizontal=True)
 Erate = {end_time:bk.Rate(0.3)} 
 Esource = bk.Source(vehicle_velocity = 16.67,  
                     target_node = Elane_in.IN,
                     rate_schedule=Erate)
 print('Scheduling Eastern arrivals...')
 Esource.setup_arrivals(end_time)
 print('..done!')
 Erecord = bk.Record(Elane_out.OUT)   
 # West
 Wlane_in = bk.Lane(lane_length) 
 Wlane_out = bk.Lane(lane_length)
 WDisplay = bk.RoadDisplay(left_lane=Wlane_in,
                           right_lane=Wlane_out,
                           axes=ax[1,0],
                           horizontal=True)
 Wrate = {end_time:bk.Rate(0.5)} 
 Wsource = bk.Source(vehicle_velocity = 16.67,  # 60 km/h
                     target_node = Wlane_in.IN,
Ejemplo n.º 4
0
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)
    bk.Queue.run(end_time)