This code tries to simulate a pedestrian flow in two crossing streets.
The rules of the pedestrian behaviour are encoded into the following equations of motion:
$$ \frac{d \boldsymbol{v}i}{dt} = f{tot} (t) / m $$
with
Where
This code base is using the Julia Language and DrWatson to make a reproducible scientific project named
PedestFlow
It is authored by Ehsan Irani.
To (locally) reproduce this project, do the following:
- Download this code base. Notice that raw data are typically not included in the git-history and may need to be downloaded independently.
- Open a Julia console and do:
julia> using Pkg julia> Pkg.add("DrWatson") # install globally, for using `quickactivate` julia> Pkg.activate("path/to/this/project") julia> Pkg.instantiate()
This will install all necessary packages for you to be able to run the scripts and everything should work out of the box, including correctly finding local paths.
First include the main code by
julia> include(srcdir("ehsan.jl"))
Then define the pedestrian-flow model by
julia> model = initialize_model(n_persons = 1, ϕ=1.0, dt=0.005, σ=0.5, γ=0.0, m=1, θ = 3π/4, Rv=4, β=0.0, seed=11)
here ϕ
is the rate of adding new people, Rv
is the visual board of pedestrians.
After defining the model, one can run the simulation by
julia> adf, _ = run!(model, agent_step!, model_step!, Int(120 ÷ model.dt);
agents_first = false,
adata = [:pos, :vel])
with adf
is a dataframe containing the position and velocity informations of agents. One can save it by
julia> using CSV
julia> CSV.write(datadir(savename("agents", "csv")), adf)
Using the following command one can record an animation of the simulation to animation.mp4
:
julia> abmvideo(
plotsdir("animation.mp4"), model, agent_step!, model_step!;
ac=ac,
framerate = 120, spf=6, frames = 2000,
title = "Pedestrian flow", static_preplot!
)
Here the population size of the simulations at different flow rates is plotted.