Пример #1
0
    def generate(self):
        while True:
            start = uniform(1, 199)

            if not prts_only:
                p = Person(interval=interval)
                p.behaviors = [Seek(), Separation()]
                p.position = vec3(0.0, start)
                platform_position = start * 54 / 199 - 27
                p.destination = vec3(28, 100 + platform_position)
                p.manager = self.rail_station.person_at_platform
                activate(p, p.move(), 0.0)

            p = Person(interval=interval)
            p.behaviors = [Seek(), Separation()]
            p.position = vec3(100.0, start)
            platform_position = start * 8 / 199
            if start < 100:
                p.destination = self.destination1.copy()
                p.manager = self.station1.person_at_station
                p.manager_args = []
            else:
                p.destination = self.destination2.copy()
                p.manager = self.station2.person_at_station
                p.manager_args = []
            activate(p, p.move(), 0.0)

            yield hold, self, 7
Пример #2
0
    def generate(self):
        """
        creates a Person at the same time and same relative place on each
        of the PRT and LRT lines.
        """
        prt_platform_length = self.p1_y2 - self.p1_y1
        rail_platform_length = self.r_y2 - self.r_y1
        people = 0
        # http://findarticles.com/p/articles/mi_m1215/is_9_204/ai_108788436
        event_max = 5000
        while people < event_max:
            people += 1
            if (people % 100) == 0:
                print "people: ", people

            start = uniform(0, 100)

            if start < 33.33:
                p = Person(interval=interval)
                p.behaviors = [Seek(), Separation()]
                p.manager_args = []
                if start < 16.66:
                    p_start = self.p1_y1 + start * 6 * prt_platform_length / 100
                    p.position = vec3(self.p1_x, p_start)
                    platform_position = (p_start - self.p1_y1) * 0.7
                    p.destination = vec3(28., self.p1_y1 + 4 + platform_position)
                    p.manager = self.prt_station1.person_at_station
                else:
                    p_start = self.p2_y1 + (start - 16.66) * 6 * prt_platform_length / 100
                    p.position = vec3(self.p2_x, p_start)
                    platform_position = (p_start - self.p2_y1) * 0.7
                    p.destination = vec3(28., self.p2_y1 + 4 + platform_position)
                    p.manager = self.prt_station2.person_at_station
                activate(p, p.move(), 0.0)

            p = Person(interval=interval)
            p.behaviors = [Seek(), Separation()]
            p.position = vec3(self.r_x, self.r_y1 + 12 + start * 0.6 * rail_platform_length / 100)
            platform_position = start * (self.r_y2 - self.r_y1) / 100
            p.destination = vec3(78., self.r_y1 + platform_position)
            p.manager = self.rail_station.person_at_platform
            p.manager_args = []
            activate(p, p.move(), 0.0)

            yield hold, self, 0.25

        yield passivate, self
Пример #3
0
    def generate(self):
        while True:
            start = uniform(5, 40)

            p = Person(interval=interval)
            p.behaviors = [Seek(), Separation()]
            p.position = vec3(100.0, start)
            platform_position = start * 8 / 199
            p.destination = self.destination1.copy()
            p.manager = self.station1.person_at_station
            p.manager_args = []
            activate(p, p.move(), 0.0)

            yield hold, self, 3.5
Пример #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)
Пример #5
0
 def execute(self):
     station = self.station
     platform = station.platform
     while True:
         for berth in range(0, len(station.berth_queues)):
             queue = station.berth_queues[berth]
             if len(queue) is 0:
                 p = Person(interval=interval)
                 p.behaviors = [Arrive()]
                 p.position = vec3(platform[0].x + 2,
                                   platform[0].y - PRT.berth_length / 2 - berth * PRT.berth_length)
                 p.destination = vec3(platform[0].x + 0.5,
                                   platform[0].y - PRT.berth_length / 2 - berth * PRT.berth_length)
                 p.velocity = vec3(-0.1, 0.0)
                 activate(p, p.move(), 0.0)
                 queue.append(p)
         yield hold, self, 0.01
Пример #6
0
def random_people(cx, cy, dstx, dsty, cluster_size, interval, people):
    def random_position():
        range = cluster_size * (pi * Person.radius**2 + 0.2)
        offset = range / 2
        return random() * range - offset
    for ii in range(0, cluster_size):
        p = Person(interval)
        p.behaviors = [Arrive(), Separation()]
        try_again = True
        while try_again:
            px, py = cx + random_position(),  cy + random_position()
            try_again = False
            for person in people:
                jx, jy, unused_z = person.position
                if sqrt((jx-px)**2 + (jy-py)**2) < Person.radius*2.5:
                    try_again = True
        p.position = vec3(px, py)
        p.destination = vec3(dstx, dsty)
        activate(p, p.move(), 0.0)
        people.append(p)
Пример #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)