Esempio n. 1
0
 def execute(self):
     tk = world().tk
     while True:
         for person in self.people:
             for ii in 0, 1:
                 if person.position[ii] > 25:
                     person.position[ii] = 0
                 elif person.position[ii] < 0:
                     person.position[ii] = 25
         yield hold, self, 0.1
Esempio n. 2
0
 def execute(self):
     stopwatch = 0.0
     tk = world().tk
     canvas, x_, y_ = tk.canvas, tk.x_, tk.y_
     hand, cx, cy = self.hand, self.cx, self.cy
     while True:
         radians = self.seconds_to_radians(stopwatch)
         canvas.coords(hand, x_(cx), y_(cy),
                       x_(cx + cos(radians) * 4), y_(cy + sin(radians) * 4))
         stopwatch += 1.0
         yield hold, self, 1.0
Esempio n. 3
0
 def execute(self):
     waypoints = self.waypoints
     tk = world().tk
     while True:
         for person in self.people:
             if person.position[1] > 25:
                 start_angle = uniform(0, pi)
                 xx, yy = cos(start_angle) * 25 + 12.5, 21.0 - person.radius * 1.2 - sin(start_angle) * 25
                 person.position = vec3(xx, yy)
                 person.waypoints = waypoints[0:]
         yield hold, self, 0.1
Esempio n. 4
0
def main(testing='two_clumps', cluster_size=20):
    interval = 0.1
    world(width=25, height=25, scale=25)
    initialize()

    xx = 12.5
    people = []

    p = Person(interval)
    p.behaviors = [Arrive(), Separation()]
    p.position = vec3(xx, 4.0)
    p.destination = vec3(xx, 21.0)
    people.append(p)
    activate(p, p.move(), 0.0)

    if testing == 'solo':
        pass

    if testing == 'immovable object':
        p = Person(interval)
        p.behaviors = [Arrive(), Separation()]
        p.position = vec3(xx - 0.08, 14.0)
        p.destination = vec3(xx - 0.08, 14.0)
        people.append(p)
        p.update()
        world().update_boid(p)
        # DON'T activate(p, p.move(), 0.0)

    if testing in ('clump', 'two clumps'):
        random_people(xx, 21.0, xx, 4.0, cluster_size, interval, people)

    if testing == 'two clumps':
        random_people(xx, 4.0, xx, 21.0, cluster_size, interval, people)

    u = Updater(interval)
    activate(u, u.execute(), 0.0)
    simulate(until=240)
Esempio n. 5
0
def main(mode='path'):
    interval = 0.1
    the_world = world(width=25, height=25, scale=25)
    initialize()

    xx = 12.5
    door_width = 3.0
    corner_size = 1

    waypoints = [vec3(xx, 4.0), vec3(xx, 5.0), vec3(xx, 6.0),
                 vec3(xx, 40.0)]

    tk = the_world.tk
    canvas, x_, y_ = tk.canvas, tk.x_, tk.y_
    canvas.create_rectangle(x_(-1), y_(-1), x_(100), y_(100), fill='blue')

    # stairs are added here so the graphics appear below the walls
    if mode == 'stairs':
        steps = 12
        step_length = 0.28
        zone = Stairs(lower_left=vec3(xx - door_width / 2, 7),
                      upper_right=vec3(xx + door_width / 2, 7 + steps * step_length))
        the_world.add_zone(zone)
        zone.draw()
    wall1 = ( (-100, 5.0), (12.5 - door_width / 2 - corner_size, 5.0),
                    (12.5 - door_width / 2, 5.0 + corner_size), (12.5 - door_width / 2, 100) )
    wall2 = ( (12.5 + door_width / 2, 100), (12.5 + door_width / 2, 5.0 + corner_size),
                    (12.5 + door_width / 2 + corner_size, 5.0), (100, 5.0) )
    wall3 = ( (12,10),(13,10),(13,11),(12,11) )
    for wall in ( wall1 , wall2 ,wall3 ):
        points = []
        for point in wall:
            points.append(x_(point[0]))
            points.append(y_(point[1]))
        canvas.create_polygon(points, fill='red', outline='black')
        for ii in range(0, len(wall)-1):
            the_world.add_wall(wall[ii], wall[ii+1])

    pg = PersonGenerator()
    activate(pg, pg.generate(interval, waypoints), 0.0)

    u = Updater(interval)
    activate(u, u.execute(), 0.0)
    SimPy.Simulation.simulate(until=100)
Esempio n. 6
0
 def __init__(self, stopwatch_seconds=60):
     Process.__init__(self)
     self.stopwatch_seconds = stopwatch_seconds
     tk = world().tk
     canvas, x_, y_ = tk.canvas, tk.x_, tk.y_
     cx, cy = 27, 136
     self.cx, self.cy = cx, cy
     canvas.create_oval(x_(cx - 5), y_(cy - 5), x_(cx + 5), y_(cy + 5), fill='white')
     steps = 60
     if stopwatch_seconds == 60:
         steps = 5
     for ii in range(0, stopwatch_seconds, steps):
         inner_radius = 4.2
         if steps == 5 and ii % 15 in (5, 10):
             inner_radius = 4.6
         radians = self.seconds_to_radians(ii)
         canvas.create_line(x_(cx + cos(radians) * inner_radius), y_(cy + sin(radians) * inner_radius),
                            x_(cx + cos(radians) * 5), y_(cy + sin(radians) * 5))
     self.hand = canvas.create_line(0, 0, 1, 1)
Esempio n. 7
0
def main(cluster_size=20):
    interval = 0.1
    the_world = world(width=25, height=25, scale=25)
    initialize()

    xx = 12.5

    p = Person(interval)
    p.behaviors = [Wander(), Separation(), Containment()]
    p.position = vec3(12.5, 12.5)
    p.destination = vec3(-100, 100)
    activate(p, p.move(), 0.0)
    people = [p]

    tk = the_world.tk
    canvas, x_, y_ = tk.canvas, tk.x_, tk.y_
    canvas.create_rectangle(x_(-1), y_(-1), x_(100), y_(100), fill='moccasin')

    for wall in ( ( (-100, 14.5), (10.5, 14.5), (10.5, 100) ),
                  ( (10.5, -100), (10.5, 8.5), (8.5, 10.5), (-100, 10.5) ),
                  ( (14.5, 100), (14.5, 14.5), ( 100, 14.5) ),
                  ( ( 100, 10.5), (16.5, 10.5), (14.5, 8.5), (14.5, -100) ),
                  ):
        points = []
        for point in wall:
            points.append(x_(point[0]))
            points.append(y_(point[1]))
        canvas.create_polygon(points, fill='gray', outline='black')
        for ii in range(0, len(wall)-1):
            the_world.add_wall(wall[ii], wall[ii+1])

    restarter = Restarter(people)
    activate(restarter, restarter.execute(), 0.0)

    u = Updater(interval)
    activate(u, u.execute(), 0.0)
    simulate(until=10000)
Esempio n. 8
0
def main(cluster_size=30):
    interval = 0.1
    the_world = world(width=25, height=25, scale=25)
    initialize()

    xx = 12.5
    door_width = 4
    corner_size = 1
    people = []

    waypoints = [vec3(xx, 21.0), vec3(xx, 22.0), vec3(xx, 23.0),
                 vec3(xx, 40.0)]

    people = random_people(xx, 4.0, waypoints, cluster_size, interval, people)

    tk = the_world.tk
    canvas, x_, y_ = tk.canvas, tk.x_, tk.y_
    canvas.create_rectangle(x_(-1), y_(-1), x_(100), y_(100), fill='moccasin')

    for wall in ( ( (-100, 21.0), (12.5 - door_width / 2 - corner_size, 21.0),
                    (12.5 - door_width / 2, 21.0 + corner_size), (12.5 - door_width / 2, 100) ),
                  ( (12.5 + door_width / 2, 100), (12.5 + door_width / 2, 21.0 + corner_size),
                    (12.5 + door_width / 2 + corner_size, 21.0), (100, 21.0) ), ):
        points = []
        for point in wall:
            points.append(x_(point[0]))
            points.append(y_(point[1]))
        canvas.create_polygon(points, fill='gray', outline='black')
        for ii in range(0, len(wall)-1):
            the_world.add_wall(wall[ii], wall[ii+1])

    restarter = Restarter(people, waypoints)
    activate(restarter, restarter.execute(), 0.0)

    u = Updater(interval)
    activate(u, u.execute(), 0.0)
    simulate(until=10000)
Esempio n. 9
0
    def __init__(self, interval=0.5,roomId=0, L=[]):
        Process.__init__(self)
	self.L = L 
        self.world = world()
        self.interval = interval
        self.manager = None
        self.manager_args = []
        self.waypoints = []
	self.roomId   = roomId 
        self.position = vec3()
        self.velocity = vec3()
        self.localx = vec3(1, 0)
        self.localy = vec3(0, 1)
        self.world.add_boid(self)
        # from Helbing, et al "Self-organizing pedestrian movement"
        self.max_speed = normalvariate(1.36, 0.26)
        self.desired_speed = self.max_speed
        self.radius = normalvariate(self.average_radius, 0.025) / 2
        self.intersection = vec3()
        self.arrived = False
        self.behaviors = []
        self.steering_mind = default_steering_mind
        self.cancelled = 0
	self.endpoint = True
Esempio n. 10
0
 def __init__(self, mode, platform_center_y, doorway_width, prt_station, rail_x, headway):
     Process.__init__(self)
     self.world = world()
     self.mode = mode
     self.platform_center_y = platform_center_y
     self.doorway_width = doorway_width
     self.prt_station = prt_station
     self.rail_x = rail_x
     self.headway = headway
     self.rail_waypoints = []
     self.rail_position = []
     self.rail_destination = []
     self.rows = 3
     self.columns = 2
     self.compactness = 1.2
     if self.rows > 6 or self.columns > 4:
         self.compactness = 0.8
     rx = self.rail_x
     railside_x = rx - Railcar.width / 2
     outside_x = rx + Railcar.width / 2
     top_rail_stop = platform_center_y + Railcar.length / 2 + 0.5
     for kk in (0, 1):
         position = -140 - (Railcar.length + 1) * kk
         destination = top_rail_stop - (Railcar.length + 1) * kk
         self.rail_position.append(position)
         self.rail_destination.append(destination)
         top = destination + Railcar.length / 2
         bottom = destination - Railcar.length / 2
         self.world.add_wall( (railside_x, top), (outside_x, top),
                              (outside_x, bottom), (railside_x, bottom) )
         rail_waypoints = []
         for ii in range(0, len(Railcar.doors)):
             rail_waypoints.append( [vec3(railside_x, top - Railcar.doors[ii]),
                                     vec3(rx - 3.5, top - Railcar.doors[ii])] )
         self.rail_waypoints.append(rail_waypoints)
     print "passegers transferring:", self.rows * self.columns * len(Railcar.doors) * 2
Esempio n. 11
0
def main(mode='straight'):
    the_world = world()
    initialize()

    rx, ry = 35., 0.

    berths = 9
    psm1 = PRTStationManager(berths)
    activate(psm1, psm1.check(), 0.0)

    door_width = 4.0
    stair_width = door_width

    s1 = Straight((20., -30.), (20., 35.0))
    s1.next, last_left, last_right, length = station((20.0, 35.0), PRT.max_speed, 'right', berths, psm1)
    last_left.next = last_right.next = c1 = Straight((20., 35. + length), (20., 10000.))
    #last_left.next = last_right.next = c1 = Curve(0, pi/2, (-10., 35.0 + length), 30.)
    #c1.next = Straight((-10., 35.0 + length + 30.), (-10000., 35.0 + length + 30.))
    psm1.mainline = last_left
    prt_draw(s1, 20.0, -31.0)

    pc = PRTChecker()
    activate(pc, pc.check(c1.members), 0.0)

    pp_ul, pp_lr = prt_platform = s1.next.platform
    prt_platform_center = (pp_ul.y + pp_lr.y) / 2
    psm1.platform = prt_platform

    if mode in ('straight', 'doorway'):
        rail_stop_center = prt_platform_center
    elif mode == 'stair':
        platform_height = 6
        step_height = 0.19
        step_length = 0.28
        steps = platform_height / step_height
        stair_length = steps * step_length
        rail_stop_center = prt_platform_center - stair_length - door_width

    #rail_draw(rx, ry, prt_platform_center_y)
    rail_draw(rx, ry, rail_stop_center)

    rail_headway = 450
    rg = RailcarGenerator(mode, rail_stop_center, door_width, s1.next, rx, rail_headway)
    activate(rg, rg.generate(), 20.0 + 30)

    # prt platform walls, clockwise from top left
    the_world.add_wall( (pp_lr.x, pp_ul.y), (pp_ul.x, pp_ul.y),       # top right and left
                        (pp_ul.x, pp_lr.y), (pp_lr.x, pp_lr.y) )       # bottom left and right

    railside_x = rx - Railcar.width / 2
    r1_top = rg.rail_destination[0] + Railcar.length / 2
    r2_top = rg.rail_destination[1] + Railcar.length / 2
    r1_doors = []
    r2_doors = []
    for door in Railcar.doors:
        r1_doors.append( ((railside_x, r1_top - door + 1), (railside_x, r1_top - door - 1)) )
        r2_doors.append( ((railside_x, r2_top - door + 1), (railside_x, r2_top - door - 1)) )

    railside_x = rx - Railcar.width / 2

    # rail platform walls
    the_world.add_wall( (rx - 5, ry + 155), (railside_x, ry + 155), # top left and right
                        r1_doors[0][0] )                            # first car, top door
    the_world.add_wall( r1_doors[0][1], r1_doors[1][0] )
    the_world.add_wall( r1_doors[1][1], r1_doors[2][0] )
    the_world.add_wall( r1_doors[2][1], r1_doors[3][0] )
    the_world.add_wall( r1_doors[3][1], r2_doors[0][0] )
    the_world.add_wall( r2_doors[0][1], r2_doors[1][0] )
    the_world.add_wall( r2_doors[1][1], r2_doors[2][0] )
    the_world.add_wall( r2_doors[2][1], r2_doors[3][0] )
    the_world.add_wall( r2_doors[3][1],                             # second car, bottom door
                        (railside_x, ry + 45), (rx - 5, ry + 45))   # bottom right and left

    tk = the_world.tk
    canvas, x_, y_, s_ = tk.canvas, tk.x_, tk.y_, tk.s_
    if mode == 'straight':
        the_world.add_wall( (rx - 5, pp_ul.y + 4),                 # prt/rail door top
                            (rx - 5, ry + 155) )                    # top right
        the_world.add_wall( (rx - 5, ry + 45),                      # bottom left
                            (rx - 5, pp_lr.y - 4) )                # prt/rail door bottom

        rg.waypoint_high = vec3(rx - 4, pp_ul.y + 3)
        rg.waypoint_low = vec3(rx - 4, pp_lr.y - 3)

        # between rail and prt platforms
        the_world.add_wall((pp_lr.x, pp_ul.y), (rx - 5, pp_ul.y + 4))
        the_world.add_wall((rx - 5, pp_lr.y - 4), (pp_lr.x, pp_lr.y))

        canvas.create_polygon( ((x_(pp_lr.x), y_(pp_ul.y)), (x_(rx - 5), y_(pp_ul.y + 4)),
                                (x_(rx - 5), y_(pp_lr.y - 4)), (x_(pp_lr.x), y_(pp_lr.y))),
                               fill='#ccc', outline='#ccc')

    elif mode == 'doorway':
        the_world.add_wall( (pp_lr.x, pp_ul.y), (pp_lr.x, prt_platform_center + door_width / 2),
                            (rx - 5, prt_platform_center + door_width / 2),
                            (rx - 5, ry + 155) )
        the_world.add_wall( (rx - 5, ry + 45), (rx - 5, prt_platform_center - door_width / 2),
                            (pp_lr.x, prt_platform_center - door_width / 2),
                            (pp_lr.x, pp_lr.y) )
        rg.waypoint_high = vec3(rx - 4, prt_platform_center + door_width / 3)
        rg.waypoint_low = vec3(rx - 4, prt_platform_center - door_width / 3)
        canvas.create_polygon( ((x_(pp_lr.x), y_(prt_platform_center + door_width / 2)),
                                (x_(rx - 5), y_(prt_platform_center + door_width / 2)),
                                (x_(rx - 5), y_(prt_platform_center - door_width / 2)),
                                (x_(pp_lr.x), y_(prt_platform_center - door_width / 2))),
                               fill='#ccc', outline='#ccc')
    elif mode == 'stair':
        epd = extra_platform_depth = 3
        wall1 = ( (pp_lr.x, pp_ul.y), (pp_lr.x + epd, prt_platform_center + door_width / 2),
                  (pp_lr.x + epd + stair_width, prt_platform_center + door_width / 2),
                  (pp_lr.x + epd + stair_width, prt_platform_center - door_width / 2),
                  (rx - 5, prt_platform_center - door_width / 2 - stair_length), 
                  (rx - 5, ry + 155) )
        wall2 = ( (rx - 5, ry + 45), (rx - 5, prt_platform_center - door_width / 2 - stair_length - door_width),
                  (rx - 5 - door_width, prt_platform_center - door_width / 2 - stair_length - door_width),
                  (rx - 5 - door_width, prt_platform_center - door_width / 2 - stair_length),
                  (pp_lr.x + epd, prt_platform_center - door_width / 2),
                  (pp_lr.x, pp_lr.y) )
        the_world.add_wall( *wall1 )
        the_world.add_wall( *wall2 )
        rg.waypoint_low = vec3(rx - 4, prt_platform_center - stair_length - door_width)
        rg.waypoint_prt_door = vec3(pp_lr.x + door_width / 2, prt_platform_center)
        points = []
        for point in wall1 + wall2:
            points.append(x_(point[0]))
            points.append(y_(point[1]))
        canvas.create_polygon(points, fill='gray')
        
    tg = PRTGenerator()
    # 50% empty to simulate sending extras to the transit station
    activate(tg, tg.generate(s1, interval, percent_empty=0.50), 0.0)

    clock = Clock()
    # "0" time taken from when Railcar called station_manager.doors_open
    activate(clock, clock.execute(), 43.684 + 30)

    u = Updater(interval)
    activate(u, u.execute(), 0.0)

    simulate(until=2000)
Esempio n. 12
0
def main(mode='straight'):
    the_world = world()
    initialize()

    tk = the_world.tk
    canvas, x_, y_, s_ = tk.canvas, tk.x_, tk.y_, tk.s_

    ###
    ### PRT
    ###
    berths = 6
    psm1 = PRTStationManager(berths)
    psm2 = PRTStationManager(berths)
    activate(psm1, psm1.check(), 0.0)
    activate(psm2, psm2.check(), 0.0)

    s1 = Straight((20., -30.), (20., -5.0))
    s1.next, last_left, last_right, length \
        = station((20.0, -5.0), PRT.max_speed, 'right', berths, psm1)
    last_left.next = last_right.next = s2 \
        = Straight((20., -5. + length), (20., -5. + length + 5.))
    psm1.mainline = last_left
    s2.next, last_left, last_right, length \
        = station((20.0, -5.0 + length + 5), PRT.max_speed, 'right', berths, psm2)
    last_left.next = last_right.next \
        = Straight((20.0, 500.), (20., 10000.))
    psm2.mainline = last_left
    prt_draw(s1, 20.0, -31.0)

    pc = PRTChecker()
    activate(pc, pc.check(s2.members), 0.0)

    p1_ul, p1_lr = prt_platform = s1.next.platform
    prt_platform_center = (p1_ul.y + p1_lr.y) / 2
    psm1.platform = prt_platform
    p2_ul, p2_lr = s2.next.platform

    canvas.create_polygon( ((x_(p1_lr.x), y_(p1_ul.y)), (x_(p1_lr.x + 15), y_(p1_ul.y + 4)),
                            (x_(p1_lr.x + 15), y_(p1_lr.y - 4)), (x_(p1_lr.x), y_(p1_lr.y))),
                           fill='#ccc', outline='#ccc')

    canvas.create_polygon( ((x_(p2_lr.x), y_(p2_ul.y)), (x_(p2_lr.x + 15), y_(p2_ul.y + 4)),
                            (x_(p2_lr.x + 15), y_(p2_lr.y - 4)), (x_(p2_lr.x), y_(p2_lr.y))),
                           fill='#ccc', outline='#ccc')

    tg = PRTGenerator()
    # 75% empty to simulate sending extras to the stadium
    activate(tg, tg.generate(s1, interval, percent_empty=0.75), 0.0)

    ###
    ### Rail
    ###
    rx, ry = 80., 0.

    rsm = RailStationManager()
    activate(rsm, rsm.check(), 0.0)

    rail_stop_center = 100

    rail_draw(rx, ry, rail_stop_center)

    rg = RailcarGenerator(rx, rsm)
    rsm.mode = "stadium"
    activate(rg, rg.generate(), 20.0 + 30)

    rg.waypoint_high = vec3(rx - 4, p1_ul.y + 3)
    rg.waypoint_low = vec3(rx - 4, p1_lr.y - 3)

    canvas.create_polygon( ((x_(rx - 20), y_(rail_stop_center + 20)),
                            (x_(rx - 5), y_(rail_stop_center + Railcar.length)),
                            (x_(rx - 5), y_(rail_stop_center - Railcar.length)),
                            (x_(rx - 20), y_(rail_stop_center - 20))),
                           fill='#ccc', outline='#ccc')
        
    ###
    ### People
    ###
    pg = PersonGenerator(rsm, rx - 20, rail_stop_center - Railcar.length + 2,
                         rail_stop_center + Railcar.length - 2,
                         psm1, p1_lr.x + 15, p1_lr.y - 4, p1_ul.y + 4,
                         psm2, p2_lr.x + 15, p2_lr.y - 4, p2_ul.y + 4)
    activate(pg, pg.generate(), 45.0)

    ###
    ###
    ###
    u = Updater(interval)
    activate(u, u.execute(), 0.0)

    simulate(until=2000)