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.0.1.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.0.1-cp38-cp38-win_amd64.whl (78.3 kB view details)

Uploaded CPython 3.8Windows x86-64

File details

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

File metadata

  • Download URL: pyfollower-0.0.1.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.0.1.tar.gz
Algorithm Hash digest
SHA256 cb77f24585c3db63a36108d686a15da21350ca8787892a6203322f649b482b0c
MD5 0cfe98cba4158500b0d5a1606298e3d4
BLAKE2b-256 087aa2d6e58be1b86fe35653a6d8d687e2ce8fd29239ef3b83b588abe5a20200

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyfollower-0.0.1-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.0.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 83c2ca15fc704c7612cee723accd6a0e5cd641f83efd2bfc50ad4da141ad5522
MD5 95077d3b7c425ca57675e7450206ef6e
BLAKE2b-256 31ce0d355405b112dde6670fe96586d504821737ab9682a45f61eabbbb4caf8f

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