Skip to main content

Follower Crowd Simulation

Project description

Follower Crowd Simulation

Follower Crowd Simulation (Follower) is a project that simulates the movement of a crowd of comformists with self-organizing characteristic. In Follower, ORCA is adapted as the basic collision avoidance model. This project is writen in C++ and built using CMake. pyfollower is the python interfaces for Follower with many easy-to-use APIs.

Getting started

To get started with Follower Crowd Simulation, you'll need to have Python 3.6+ installed on your system. You can download Python from the official website, and Follower Crowd Simulation can be installed using pip:

pip install pyfollower

The installation process of this project requires Cmake and C++ compilation environment, so if you are a Windows user, it is a better choice to use a compiled wheel file

pip install pyfollower-xxx.whl

After you have installed it, you can simply use this simulation Engine. As an example(Please make sure the numpy and matplotlib is installed):

import numpy as np
from pyfollower import FollowerEngine

# Initial scenario
dest = dict()
N = 50
sim = FollowerEngine(agent_radius=0.5)

for idx, i in enumerate(np.linspace(0, 1, N + 1)):
    if i == 1: break
    theta = i * np.pi * 2
    ox, oy = np.cos(theta), np.sin(theta)
    dx, dy = np.cos(theta + np.pi), np.sin(theta + np.pi)
    t = np.array([ox, oy, dx, dy]) * 20
    agent_id = sim.add_agent(*t)
    dest[agent_id] = t[-2:]

# Test obstacles
sim.add_obstacles([(5, 5), (-5, 5), (-5, -5), (5, -5)])
sim.process_obstacles()
obs = np.array([(-5, -5), (-5, 5), (5, 5), (5, -5), (-5, -5)])


# Run simulation --- Main loop
traj = []
for i in range(100):
    if not i % 10: print(sim.time)
    x = sim.get_agent_positions()
    for agent_id in range(N):
        dx = dest[agent_id] - x[agent_id, :]
        dist = np.sqrt(np.sum(dx ** 2))
        if dist < 0.5:
            prev = (0, 0)
        else:
            prev = 1.3 * dx / dist
        sim.set_agent_pref(agent_id, *prev)
    traj.append(x)
    print(x.T)
    sim.follower_step()


# Plot
import pylab as pl

traj = np.stack(traj)

pl.xlim(-20, 20)
pl.ylim(-20, 20)
pl.imshow(np.zeros((40, 40), float), extent=(-20, 20, -20, 20))

import matplotlib.cm as cm

colors = cm.hsv(np.linspace(0, 1, N))
for i in range(N):
    pl.plot(traj[:, i, 0], traj[:, i, 1], c=colors[i])

pl.scatter(*x.T, c=range(N), s=20, cmap='hsv')

pl.plot(obs[:, 0], obs[:, 1], c='white')
pl.show()

Contributing

If you'd like to contribute to Follower Crowd Simulation, feel free to submit a pull request. Please make sure that your code follows the PEP 8 style guide and that any new features are thoroughly tested.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfollower-0.1.2.tar.gz (190.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyfollower-0.1.2-cp38-cp38-win_amd64.whl (78.3 kB view details)

Uploaded CPython 3.8Windows x86-64

File details

Details for the file pyfollower-0.1.2.tar.gz.

File metadata

  • Download URL: pyfollower-0.1.2.tar.gz
  • Upload date:
  • Size: 190.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.6rc1

File hashes

Hashes for pyfollower-0.1.2.tar.gz
Algorithm Hash digest
SHA256 803bfe7745ad1d2fcc30b715c1938bc8e9b8d200aa1958c5c569750dad8fd028
MD5 fd7a58fa64440a1dc38c5c4d8106b814
BLAKE2b-256 b50e778822e99b1c278e21132a9917a4531090aebee66df98093f7163b0bfe21

See more details on using hashes here.

File details

Details for the file pyfollower-0.1.2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pyfollower-0.1.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 78.3 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.6rc1

File hashes

Hashes for pyfollower-0.1.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 e17776a0f690cadbc4ab16e977a4792a36b67fab6acfae15ebeff9df441c7dd2
MD5 53dfafa5aa1ddda1121078fa45fba64e
BLAKE2b-256 ea9308f783c5b2f9bdcc5a824cd0ef9cb9415f91b7ac11333b01c5fa997babd3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page