Skip to content

Commit

Permalink
Revised the notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
JetteSchumann authored and Ozaq committed Oct 16, 2023
1 parent 815855f commit 6d30c53
Show file tree
Hide file tree
Showing 5 changed files with 1,681 additions and 202 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

# -- Automatic execution of jupyter notebooks --------------------------------
nb_execution_excludepatterns = []
nb_execution_timeout = 120
nb_execution_timeout = 900
myst_enable_extensions = [
"amsmath",
"colon_fence",
Expand Down
17 changes: 9 additions & 8 deletions docs/source/notebooks/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ Notebooks
.. toctree::
:maxdepth: 1

Simple Bottleneck Simulation <bottleneck>
Simple Corner Simulation <corner>
Double bottleneck <double-bottleneck>
How to work with Journeys <journey>
Modelling Motivation <motivation>
How routing can influence evacuation times <routing>
Single file movement <single-file>
Lane Formation <lane-formation>
bottleneck
corner
double-bottleneck
journey
lane-formation
motivation
queues_waiting
routing
single-file
202 changes: 134 additions & 68 deletions notebooks/corner.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
"cell_type": "markdown",
"id": "ae798e28-45c8-401a-891d-fdfa71c6516a",
"metadata": {
"editable": true,
"pycharm": {
"name": "#%% md\n"
}
},
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"# Simple Corner Simulation\n",
"# Movement around Corners\n",
"\n",
"In the following we'll investigate the movement of pedestrians around corners. When pedestrians walk around corners they are expected to slow down and take a path that is close to the corner. According to RiMEA Test 6 **[TODO REF]** a scenario is configured where **20 agents** move towards a **corner** at which they should turn to the left.\n",
"In the following we'll investigate the movement of pedestrians around corners. When pedestrians walk around corners they are expected to slow down and take a path that is close to the corner. According to RiMEA Test 6 [1] a scenario is configured where **20 agents** move towards a **corner** at which they should turn to the left.\n",
"\n",
"Let's begin by importing the required packages for our simulation:"
]
Expand Down Expand Up @@ -41,12 +46,8 @@
"import pedpy\n",
"import pandas as pd\n",
"import numpy as np\n",
"import plotly # visualise trajectories\n",
"import plotly.express as px\n",
"import plotly.graph_objects as go\n",
"from plotly.graph_objs import Figure\n",
"import sqlite3\n",
"from numpy.random import normal # normal distribution of free movement speed"
"from numpy.random import normal # normal distribution of free movement speed\n",
"import matplotlib.pyplot as plt"
]
},
{
Expand All @@ -60,7 +61,7 @@
"source": [
"## Setting up the Geometry\n",
"\n",
"We define a corridor with a width of 2 meters and a corner on halfway:"
"According to the RiMEA Test we define a corridor with a width of 2 meters and a corner on halfway:"
]
},
{
Expand All @@ -82,80 +83,149 @@
"outputs": [],
"source": [
"area = Polygon([(0, 0), (12, 0), (12, 12), (10, 12), (10, 2), (0, 2)])\n",
"area"
"walkable_area = pedpy.WalkableArea(area)\n",
"pedpy.plot_walkable_area(walkable_area=walkable_area).set_aspect(\"equal\")"
]
},
{
"cell_type": "markdown",
"id": "269d95ac",
"id": "6acd2af2-b811-4779-b3b3-46684ac9a281",
"metadata": {
"editable": true,
"pycharm": {
"name": "#%% md\n"
}
},
"raw_mimetype": "",
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"## Definition of Start Positions and Exit\n",
"\n",
"Now we'll calculate the position of 20 agents in the lower left part of the geometry within an rectangle of 6 x 2 meters. To calculate the positions we use a library function from JuPedSim. We assume an agent size of 0.3 m and set the distance parameters accordingly. The exit is defined in the upper right of the geometry."
"Now we'll calculate the position of 20 agents in the lower left part of the geometry within an rectangle of 6 x 2 meters. For this purpose, we use a library function from JuPedSim that calclulates positions in a given polygon. We assume an agent size of 0.4 m (diameter) and set the distance parameters accordingly. The exit is defined in the upper right of the geometry."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fccaffe5-2f29-44a9-82f4-e6f220ffe8c8",
"metadata": {
"editable": true,
"pycharm": {
"name": "#%%\n"
}
},
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"spawning_area = Polygon([(0, 0), (6, 0), (6, 2), (0, 2)])\n",
"num_agents = 20\n",
"positions = jps.distributions.distribute_by_number(\n",
"pos_in_spawning_area = jps.distributions.distribute_by_number(\n",
" polygon=spawning_area,\n",
" number_of_agents=num_agents,\n",
" distance_to_agents=0.4,\n",
" distance_to_polygon=0.15,\n",
" distance_to_polygon=0.2,\n",
" seed=1,\n",
")\n",
"exit_area = Polygon([(10, 11), (12, 11), (12, 12), (10, 12)])"
]
},
{
"cell_type": "markdown",
"id": "40bee00b-7b0d-46d7-914d-d88bea7bc39d",
"id": "badcdfb6-ffd5-4a78-a3cf-fedc137f5732",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"Let's have a look at the basic simulation setup. The spawning area is shown in grey, the agents in blue and the exit area in red:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "073c2dab-542e-4ad7-9a94-7988ffa1b15f",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"def plot_simulation_configuration(\n",
" walkable_area, spawning_area, starting_positions, exit_area\n",
"):\n",
" axes = pedpy.plot_walkable_area(walkable_area=walkable_area)\n",
" axes.fill(*spawning_area.exterior.xy, color=\"lightgrey\")\n",
" axes.fill(*exit_area.exterior.xy, color=\"indianred\")\n",
" axes.scatter(*zip(*starting_positions))\n",
" axes.set_xlabel(\"x/m\")\n",
" axes.set_ylabel(\"y/m\")\n",
" axes.set_aspect(\"equal\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a840a3be-8759-4058-9e37-3b2cc483f0c3",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"**TODO: plot config setup - geo + start positions + exit**"
"plot_simulation_configuration(\n",
" walkable_area, spawning_area, pos_in_spawning_area, exit_area\n",
")"
]
},
{
"cell_type": "markdown",
"id": "f2f206a3",
"metadata": {
"editable": true,
"pycharm": {
"name": "#%% md\n"
}
},
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"## Setting up the Simulation and Routing Details\n",
"\n",
"As a next step we create a simulation object, set the configuration for the operational model (collision-free speed model) and define the routes for the agents. For this scenario only one journey is created as all agents should follow the same route."
"As a next step we create a simulation object, set the configuration for the operational model (collision-free speed model) and define the routes for the agents. Default values for the model parameters are set implicitly. For this scenario, only one journey is created as all agents should follow the same route."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "36627194",
"metadata": {
"editable": true,
"pycharm": {
"name": "#%%\n"
}
},
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
Expand All @@ -174,9 +244,14 @@
"execution_count": null,
"id": "c1cfdadc",
"metadata": {
"editable": true,
"pycharm": {
"name": "#%%\n"
}
},
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
Expand All @@ -194,54 +269,33 @@
}
},
"source": [
"## Specifying Agent Parameters\n",
"\n",
"As a next step we define the model-specific parameters for the agents. They share the same journey and model parameters except for the free movement speed which is normally distributed. "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bad06382",
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"v_distribution = normal(1.34, 0.2, num_agents)"
]
},
{
"cell_type": "markdown",
"id": "569d86fe",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"## Executing the Simulation\n",
"## Agent Parameters and Executing the Simulation\n",
"\n",
"Now we can specifiy the indiviual starting positions and speeds and add the agents to the simulation. After that the simulation is started and iterates until all agents have reached the exit."
"As a next step we define the agent parameters and add them to the simulation. They share the same journey and model parameters except for the starting position and free movement speed which is normally distributed. After adding the agents, the simulation is started and iterates until all agents have reached the exit."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2a413666",
"metadata": {
"editable": true,
"pycharm": {
"name": "#%%\n"
}
},
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"for position, v0 in zip(positions, v_distribution):\n",
"v_distribution = normal(1.34, 0.05, num_agents)\n",
"\n",
"for pos, v0 in zip(pos_in_spawning_area, v_distribution):\n",
" simulation.add_agent(\n",
" jps.CollisionFreeSpeedModelAgentParameters(\n",
" journey_id=journey_id, stage_id=exit_id, position=position, v0=v0\n",
" journey_id=journey_id, stage_id=exit_id, position=pos, v0=v0\n",
" )\n",
" )\n",
"\n",
Expand All @@ -264,18 +318,25 @@
{
"cell_type": "code",
"execution_count": null,
"id": "8ac7d6d7",
"id": "5379718a-4af8-470b-8cf0-b4a6dd6f7193",
"metadata": {
"editable": true,
"pycharm": {
"name": "#%%\n"
}
},
"slideshow": {
"slide_type": ""
},
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"from jupedsim.internal.notebook_utils import animate, read_sqlite_file\n",
"\n",
"trajectory_data, walkable_area = read_sqlite_file(trajectory_file)\n",
"animate(trajectory_data, walkable_area)"
"animate(trajectory_data, walkable_area, every_nth_frame=5)"
]
},
{
Expand All @@ -287,27 +348,32 @@
}
},
"source": [
"**TODO add colorbar for speed to plot**\n",
"\n",
"As expected the agents choose the shortest path and approach the corner in a funnel-shaped formation. Agents moving closer to the corner become slower than agents at the edge of the crowd who choose a longer path around the corner."
]
},
{
"cell_type": "markdown",
"id": "a4c85934",
"metadata": {
"editable": true,
"pycharm": {
"name": "#%% md\n"
}
},
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"## References & Further Exploration\n",
"\n",
"**TODO RiMEA reference**\n",
"[1] RiMEA, 'Guideline for Microscopic Evacuation Analysis'(2016), URL: https://rimea.de/ \n",
"\n",
"Another RiMEA test regarding the movement in bottlenecks can be found in **TODO Link double-bottleneck**.\n",
"\n",
"The chosen model here is based on the collision-free speed model. JuPedSim also incorporates another model known as GCFM. For more details on GCFM, refer to another notebook **(TODO: Link to the GCFM notebook)**.\n",
"This examples shows the basic behaviour of agents when moving around corners. A more advanced simulation and analysis can be found in **TODO ref to Mohcine's notebook**.\n",
"\n",
"The demonstration employed a straightforward journey with a singular exit. For a more intricate journey featuring multiple intermediate stops and waiting zones, see the upcoming section **(TODO: Link to the advanced journey section)**."
"The demonstration employed a straightforward journey with a singular exit. For a more intricate journey featuring multiple intermediate stops and waiting zones, see the upcoming section **TODO: Link to the advanced journey section)**."
]
}
],
Expand Down
Loading

0 comments on commit 6d30c53

Please sign in to comment.