Example #1
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)
Example #2
0
 def person(self, railcar, yy, railcar_waypoints):
     columns = self.columns
     compactness = self.compactness
     for ii in range(0, columns):
         xx = self.rail_x + (ii - (float(columns) - 1.0) / 2.0) * (Person.average_radius * 2.0 * compactness)
         p = Person(interval=interval)
         p.behaviors = [Containment(), Separation(), FollowWaypoints(), InterpenetrationConstraint()]
         p.steering_mind = queue_steering_mind
         p.position = vec3(xx, yy)
         p.waypoints = railcar_waypoints[0:]
         if self.mode == 'straight':
             if p.waypoints[0].y - self.waypoint_high.y > 3:
                 p.waypoints.append(self.waypoint_high)
             if self.waypoint_low.y - p.waypoints[0].y > 3:
                 p.waypoints.append(self.waypoint_low)
         elif self.mode == 'doorway':
             if p.waypoints[0].y > self.platform_center_y:
                 p.waypoints.append(self.waypoint_high)
             if p.waypoints[0].y <= self.platform_center_y:
                 p.waypoints.append(self.waypoint_low)
             p.waypoints.append(vec3(p.waypoints[-1]))
             p.waypoints[-1].x -= 7.0
         elif self.mode == 'stair':
             p.waypoints.append(self.waypoint_low)
             p.waypoints.append(vec3(self.waypoint_low))
             p.waypoints[-1].x -= self.doorway_width * 0.75
             p.waypoints.append(self.waypoint_prt_door)
             p.waypoints.append(vec3(self.waypoint_prt_door))
             p.waypoints[-1].x -= 1.0
         p.manager = self.prt_station.person_at_station
         railcar.departing.append(p)
Example #3
0
    def generate(self, interval, waypoints):
        people = []
        rate = 0.5
        #while True:
	for k in range(10):
            start = uniform(0, 5)

            p = Person(interval=interval)
	    #p.destination= vec3(12.5,uniform(2,20))
            p.behaviors = [Containment(), Separation(), Queuing(), FollowWaypoints(), InterpenetrationConstraint()]
 	    #p.behaviors = [FollowWaypoints(),InterpenetrationConstraint()]
 	    #p.behaviors = [Seek(),InterpenetrationConstraint()]
            p.steering_mind = queue_steering_mind
            p.position = vec3(start, 0.0)
            p.waypoints = waypoints[0:]
            activate(p, p.move(), 0.0)
            people.append(p)

            count = 0
            for p in people:
                if p.position[1] > 25:
                    self.cancel(p)
                    p.world.remove_boid(p)
                    people.remove(p)
                if p.position[1] < 7:
                    count += 1

            if count > 30:
                rate = 1.5
            elif count < 20:
                rate = 0.5

            yield hold, self, rate
Example #4
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)
Example #5
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
Example #6
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
Example #7
0
def random_people(cx, cy, waypoints, cluster_size, interval, people):
    def random_position():
        range = cluster_size * (pi * Person.average_radius**2 + 0.2)
        offset = range / 2
        return uniform(0.0, range) - offset
    for ii in range(0, cluster_size):
        p = Person(interval)
        p.behaviors = [Containment(), Separation(), Queuing(), FollowWaypoints()]
        p.steering_mind = queue_steering_mind
        try_again = True
        while try_again:
            px, py = cx + random_position(),  cy + random_position()
            if py > (21.0 - Person.radius):
                continue
            try_again = False
            for person in people:
                jx, jy, unused_z = person.position
                if sqrt((jx-px)**2 + (jy-py)**2) < Person.average_radius*2.5:
                    try_again = True
        p.position = vec3(px, py)
        p.waypoints = waypoints[0:]
        activate(p, p.move(), 0.0)
        people.append(p)
    return people
Example #8
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
Example #9
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)
Example #10
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