Skip to main content

Follower Crowd Simulation

Reason this release was yanked:

no

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

pyfollower-0.1.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.1.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pyfollower-0.1.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.1.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 af4a93da14539584429443d5ed835ab64364ce38637307f214be2d82908fb6f7
MD5 f8f7780417f2a3925511be7bf907b01f
BLAKE2b-256 4c210869d4e2ed2cd70e37bc4ce97619d1928f2782e65010cdf0e4f58c0f32cd

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