Skip to content

A JAX based implementation of the Social Force Model in Python to simulate realistic human motion.

License

Notifications You must be signed in to change notification settings

TommasoVandermeer/JSFM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSFM (JAX Social Force Model)

A JAX based implementation of the Headed Social Force Model in Python.

circular_crossing_sfm

Description

This repository contains an implementation of the Social Force Model to simulate human motion in Python. Following the current programming trend, the code is based on the well-known JAX Python library that allows fast computations thanks to vectorization, parallelization and accelerated linear algebra.

The main contribution of this repo is the step() method which takes in input the current state, goals and parameters of all humans and returns the updated state using a given sampling time dt. Moreover, the repo includes methods to generate humans' initial conditions, parameters, and goals with a few lines of code.

Finally, some examples are included to show how the model can be used in practice and how humans move following the HSFM.

Note that this implementation of the SFM differs from the original one in [1]. It implements a modification proposed in [2] to introduce a sliding component in the repulsive forces.

Table of contents

Installation

This code has only been tested in Python 3.10 but it might also work with other interpreters. Hereafter, a simple step-by-step guide for installation is presented.

Step-by-step installation guide

First of all, creating a Python virtual environment is a good practice when starting new projects. You can do that with the well-known virtualenv package (pip install virtualenv):

virtualenv jsfm

Now that the virtualenv has been created using your default Python interpreter, you can activate the environment:

source jsfm/bin/activate

After that, its time to clone this repo:

git clone https://github.com/TommasoVandermeer/JSFM.git

Finally, you need to install the requirements and then you can install the package:

cd JSFM
python3 setup.py install

You have successfully installed the package. Whenever you are done using this code, remember to deactivate your virtualenv:

deactivate

Getting started

As previously mentioned, the repository includes three examples the can be run to learn the implementation details.

Example one

Example 1 simulates the circular crossing scenario, a scenario widely employed in the reasearch community. Each human is positioned (randomly or evenly spaced) in the boundary of a circle and its goal is to reach the point diametrically opposite to its initial position. To run it use:

python3 example1.py

circular_crossing_sfm

Example two

Example 2 simulates a scenario in which several pedestrians need to go through a narrow passage (e.g., a door). To run it use:

python3 example2.py

go_through_door_sfm

Example three

Example 3 simulates a scenario in which humans flow in a large corridor all in the same direction to reach the othe end. To run it use:

python3 example3.py

parallel_traffic

References

[1] Helbing, D., Farkas, I., & Vicsek, T. (2000). Simulating dynamical features of escape panic. Nature, 407(6803), 487-490.

[2] Guo, Ren-Yong. "Simulation of spatial and temporal separation of pedestrian counter flow through a bottleneck." Physica A: Statistical Mechanics and its Applications 415 (2014): 428-439.

About

A JAX based implementation of the Social Force Model in Python to simulate realistic human motion.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages