Create a crowd of pedestrians with custom statistics
[1]:
import pprint
from pathlib import Path
import matplotlib.pyplot as plt
from shapely.geometry import Polygon
import configuration.backup.crowd_to_zip_and_reverse as fun_zip
import configuration.utils.constants as cst
import configuration.utils.functions as fun
from configuration.models.crowd import Crowd
from configuration.models.measures import CrowdMeasures
from streamlit_app.plot import plot
%matplotlib inline
# Constants
boundaries = Polygon([(0.0, 0.0), (400.0, 0.0), (400.0, 200.0), (0.0, 200.0)]) # (cm)
NUMBER_AGENTS: int = 40
REPULSION_LENGTH: float = 5.0 # (cm)
DESIRED_DIRECTION: float = 90.0 # (degrees)
VARIABLE_ORIENTATION: bool = True
agent_statistics = cst.CrowdStat.copy()
# Update the agent statistics dictionary with custom values
agent_statistics.update(
{
"male_proportion": 0.3,
"male_bideltoid_breadth_mean": 70.0, # cm
"male_bideltoid_breadth_std_dev": 3.0, # cm
}
)
# Create the packed crowd
crowd_measures = CrowdMeasures(agent_statistics=agent_statistics)
crowd = Crowd(boundaries=boundaries, measures=crowd_measures)
crowd.create_agents(number_agents=NUMBER_AGENTS)
crowd.pack_agents_with_forces(
repulsion_length=REPULSION_LENGTH,
desired_direction=DESIRED_DIRECTION,
variable_orientation=VARIABLE_ORIENTATION,
)
# Visualize results
plot.display_crowd2D(crowd)[0]
plt.show()
# Download the xml configuration files necessary for the simulation to a zip format
output_zip_path = Path.cwd().parent.parent / "data" / "tutorial_configuration_files" / "crowd_custom.zip"
fun_zip.save_crowd_data_to_zip(crowd, output_zip_path)
Get some anthropometric statistics from the created crowd
[2]:
crowd_statistics = crowd.get_crowd_statistics()
# Print the crowd statistics
pprint.pprint(fun.filter_dict_by_not_None_values(crowd_statistics["measures"]))
{'bike_proportion': 0.0,
'female_bideltoid_breadth_max': 47.61662981419438,
'female_bideltoid_breadth_mean': 45.225410385727415,
'female_bideltoid_breadth_min': 41.3409277917306,
'female_bideltoid_breadth_std_dev': 1.708970167778921,
'female_chest_depth_max': 27.477589345886557,
'female_chest_depth_mean': 23.56468885149855,
'female_chest_depth_min': 20.548006518661804,
'female_chest_depth_std_dev': 1.7689686686100825,
'female_height_max': 177.07885549596523,
'female_height_mean': 163.0116436675823,
'female_height_min': 146.96064115397735,
'female_height_std_dev': 8.01898855802242,
'female_weight_max': 87.67215417041635,
'female_weight_mean': 68.0316440102898,
'female_weight_min': 46.61525848540077,
'female_weight_std_dev': 9.541021981646065,
'male_bideltoid_breadth_max': 64.75404229475316,
'male_bideltoid_breadth_mean': 63.671305955846904,
'male_bideltoid_breadth_min': 61.80830903854928,
'male_bideltoid_breadth_std_dev': 0.9977005272243731,
'male_chest_depth_max': 29.385441100095584,
'male_chest_depth_mean': 25.8486646529829,
'male_chest_depth_min': 22.047477404424207,
'male_chest_depth_std_dev': 2.2607301437525193,
'male_height_max': 187.47849763927178,
'male_height_mean': 178.69068860007573,
'male_height_min': 163.5777940655044,
'male_height_std_dev': 7.6506713507410735,
'male_proportion': 0.275,
'male_weight_max': 106.68809267921692,
'male_weight_mean': 79.6101136815683,
'male_weight_min': 48.00553097113679,
'male_weight_std_dev': 20.602974441376922,
'pedestrian_proportion': 1.0}
The lengths are in centimeters, the weight are in kilograms.
[3]:
# Print the numbers observables
pprint.pprint(crowd_statistics["stats_counts"])
{'bike_number': 0, 'male_number': 11, 'pedestrian_number': 40}
[4]:
# Print the detailed distribution of the other observables
pprint.pprint(fun.filter_dict_by_not_None_values(crowd_statistics["stats_lists"]))
{'female_bideltoid_breadth': [45.39075946649399,
41.79279360573726,
43.98011530231502,
46.40364584193339,
44.24706043901661,
43.03618783673906,
42.67570385235518,
45.109386803345856,
44.72168351248202,
44.19407949471273,
44.00134407443143,
44.65604500730132,
45.250627549754455,
47.612568664048126,
46.91518830067598,
46.760383492918436,
45.14003553941164,
47.50773343898157,
46.517633739398384,
46.65595898919475,
46.02186928528243,
43.61128048648516,
47.36311818752667,
46.31220249233223,
44.638824064772365,
41.3409277917306,
45.620521881653254,
46.44259223087103,
47.61662981419438],
'female_chest_depth': [24.169115779687807,
24.548943366798966,
23.116521113347144,
22.95946246976655,
22.073115682099168,
24.98953347001123,
22.887697250095837,
20.548006518661804,
22.280515470510483,
24.479552684041614,
22.333026524261538,
25.351586117827576,
22.835646807128224,
26.17503638851356,
22.618541943156025,
22.740690380785487,
24.25288789957979,
21.990102169763702,
27.477589345886557,
26.59175351554449,
24.139852502181203,
21.430125297695174,
21.140151808747742,
20.69212171496877,
25.094964843394767,
22.081696982398938,
24.656844201411303,
24.505057623367357,
25.215836821824933],
'female_height': [162.65525916790423,
162.99717335318252,
160.698869743553,
160.95545735534049,
170.52048679380638,
161.26207253511356,
164.0026236898999,
161.28264690902316,
155.3057950150664,
166.42239890567737,
169.13823956489998,
148.1660948438864,
175.44787610606494,
177.07885549596523,
170.79576450064474,
152.3784760860045,
163.63894222085833,
175.20297396413068,
154.1424936854684,
146.96064115397735,
155.16143745126885,
172.56845495345442,
161.70585317872613,
167.469613286945,
164.9992683316507,
162.29532640101286,
170.74738104315736,
150.85368604384828,
162.48350457935513],
'female_weight': [71.12087478362184,
80.98046025949729,
73.7094303308985,
62.562378754212375,
71.71589184255774,
56.46948651274341,
69.35022513064915,
75.89136890916689,
68.16071035714681,
67.33541090833656,
73.74548548875919,
75.78613687340311,
59.073323926981814,
68.99187713610262,
85.48732539867157,
64.00244145127361,
68.3964948422275,
55.750152566522814,
52.063238652949124,
64.58035114489222,
87.67215417041635,
77.76991394500598,
46.61525848540077,
69.52357275556744,
54.42118157730897,
63.42921035386915,
73.42502570365691,
69.41868151298111,
65.46961252358308],
'male_bideltoid_breadth': [61.80830903854928,
63.980417968806066,
64.3585227771825,
62.4444536139249,
64.39762403091959,
63.38370672846225,
64.29627243275893,
62.5058510607944,
64.58813567280252,
63.86702989536236,
64.75404229475316],
'male_chest_depth': [22.981303182909084,
26.465375713515556,
27.132286980449752,
29.385441100095584,
26.170635441448425,
28.385942684996774,
22.047477404424207,
25.202872634010344,
23.569145968651817,
27.170082560923998,
25.824747511386338],
'male_height': [186.50990499776952,
173.69591596721673,
173.1599819219259,
163.5777940655044,
187.47849763927178,
183.97180390519557,
178.2575379611094,
169.98867302121454,
184.1920136621992,
181.46179958955338,
183.30365186987274],
'male_weight': [70.21957106107988,
104.91326050059335,
67.12907994967156,
56.85803309757575,
69.84352403027964,
106.68809267921692,
48.00553097113679,
102.95562096470938,
65.9970769619776,
91.44195385293149,
91.65950642807873]}