コード例 #1
0
def run_simulation(city, num_peds):
    print("Generating {} random pedestrians".format(num_peds))
    pedestrians = Pedestrian.generate_random_pedestrians(num_peds, city)

    """
    We create a count of how many times a node (CityLocation object) appears in 
    the shortest simple paths of pedestrians, indicating a "hot spot" in the grid. We also
    examine the number of times that a node is occupied by a pedestrian
    on a path at the "same time," i.e. in the same index position in a pathway, as another
    node. This indicates frequent "collisions" of pedestrians at the same place at same time.
    We exclude start and destination nodes from this count.
    """

    intersect_dict = {}

    for ped in pedestrians:
        shortest_path = ped.shortest_path
        node_position = 1
        for short_path_node in shortest_path[1:-1]:
            count = intersect_dict.get(short_path_node, 0)
            intersect_dict[short_path_node] = count + 1
            node_position += 1

    return sorted(intersect_dict.items(), key=lambda x: x[1], reverse=True)
コード例 #2
0
from city import City
from pedestrian import Pedestrian

city = City.generate_random_city(10, 10)
#city.print(True, True)
pedestrians = Pedestrian.generate_random_pedestrians(50, city)