pyfollower


Namepyfollower JSON
Version 0.1.4 PyPI version JSON
download
home_pageNone
SummaryFollower Crowd Simulation
upload_time2024-11-01 05:41:13
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseApache License 2.0
keywords crowd simulation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Follower Crowd Simulation

[![Pypiversion](https://img.shields.io/pypi/v/pyfollower.svg)](https://pypi.org/project/pyfollower/)
![Document](https://img.shields.io/badge/docs-in_progress-violet)
![Formant](https://img.shields.io/pypi/format/pyfollower.svg)
[![Implementation](https://img.shields.io/pypi/implementation/pyfollower.svg)](https://www.python.org/)
[![License](https://img.shields.io/pypi/l/pyfollower.svg)](https://www.apache.org/licenses/LICENSE-2.0)
![Pyversion](https://img.shields.io/pypi/pyversions/pyfollower.svg)
[![PyPI Downloads](https://img.shields.io/pypi/dm/pyfollower.svg?label=PyPI%20downloads)](https://pypi.org/project/pyfollower/)
[![DOI](https://img.shields.io/badge/DOI-10.48550/arXiv.2407.00674-red)](https://doi.org/10.48550/arXiv.2407.00674)
[![Wheel](https://img.shields.io/pypi/wheel/pyfollower.svg)](https://pypi.org/project/pyfollower/#files)

Follower Crowd Simulation (`Follower`) is a project that simulates the movement of a crowd/robots of comformists with self-organizing characteristic. In `Follower`, [ORCA](https://gamma.cs.unc.edu/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.7+ installed on your system. You can download Python from the [official website](https://www.python.org/), and Follower Crowd Simulation can be installed using pip:

```shell
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](https://pypi.org/project/pyfollower/#files)

```shell
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):

```python
import numpy as np
from pyfollower import FollowerEngine

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

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.0 * dx / dist
        sim.set_agent_pref(agent_id, *prev)
    traj.append(x)
    print(x.T)
    sim.follower_step()

# Plot
import pylab as pl
import matplotlib.cm as cm
fig = pl.figure('Trajectory', facecolor='thistle', figsize=(4, 4))
ax = fig.gca()

traj = np.stack(traj)

pl.xlim(-20, 20)
pl.ylim(-20, 20)
ax.imshow(np.zeros((40, 40), np.bool), extent=(-20, 20, -20, 20), cmap='viridis')\
    .format_cursor_data = lambda data: ""

colors = cm.hsv(np.linspace(0, 1, N))
for i in range(N):
    ax.plot(traj[:, i, 0], traj[:, i, 1], c=colors[i])
ax.scatter(*x.T, c=range(N), s=20, cmap='hsv')
ax.plot(obs[:, 0], obs[:, 1], c='white')

ax.format_coord = lambda x, y: f'({x:^6.1f}, {y:^6.1f})'
[spine.set_color('white') for spine in ax.spines.values()]
ax.tick_params(axis='both', colors='white')

pl.show()
```

### Citation
During installation, due to differences in individual machines, various tricky issues may arise.
If you encounter any difficulties using this simulator, please do not hesitate to send an email to [dejavu.rabbyt@gmail.com]().

If you find our work helpful (or if you are so kind as to offer us some encouragement), please consider citing the paper.

```bibtex
@misc{liao2024emergent,
      title={Emergent Crowd Grouping via Heuristic Self-Organization}, 
      author={Xiao-Cheng Liao and Wei-Neng Chen and Xiang-Ling Chen and Yi Mei},
      year={2024},
      eprint={2407.00674},
      archivePrefix={arXiv},
      primaryClass={cs.MA},
      url={https://arxiv.org/abs/2407.00674}, 
}
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pyfollower",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "Crowd, Simulation",
    "author": null,
    "author_email": "Rabbytr <dejavu.rabbyt@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/41/23/9192df46342498339f6efe78a51914e576d9dbe77435a3870fea866c93c8/pyfollower-0.1.4.tar.gz",
    "platform": null,
    "description": "# Follower Crowd Simulation\r\n\r\n[![Pypiversion](https://img.shields.io/pypi/v/pyfollower.svg)](https://pypi.org/project/pyfollower/)\r\n![Document](https://img.shields.io/badge/docs-in_progress-violet)\r\n![Formant](https://img.shields.io/pypi/format/pyfollower.svg)\r\n[![Implementation](https://img.shields.io/pypi/implementation/pyfollower.svg)](https://www.python.org/)\r\n[![License](https://img.shields.io/pypi/l/pyfollower.svg)](https://www.apache.org/licenses/LICENSE-2.0)\r\n![Pyversion](https://img.shields.io/pypi/pyversions/pyfollower.svg)\r\n[![PyPI Downloads](https://img.shields.io/pypi/dm/pyfollower.svg?label=PyPI%20downloads)](https://pypi.org/project/pyfollower/)\r\n[![DOI](https://img.shields.io/badge/DOI-10.48550/arXiv.2407.00674-red)](https://doi.org/10.48550/arXiv.2407.00674)\r\n[![Wheel](https://img.shields.io/pypi/wheel/pyfollower.svg)](https://pypi.org/project/pyfollower/#files)\r\n\r\nFollower Crowd Simulation (`Follower`) is a project that simulates the movement of a crowd/robots of comformists with self-organizing characteristic. In `Follower`, [ORCA](https://gamma.cs.unc.edu/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.\r\n\r\n### Getting started\r\n\r\nTo get started with Follower Crowd Simulation, you'll need to have Python 3.7+ installed on your system. You can download Python from the [official website](https://www.python.org/), and Follower Crowd Simulation can be installed using pip:\r\n\r\n```shell\r\npip install pyfollower\r\n```\r\n\r\nThe 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](https://pypi.org/project/pyfollower/#files)\r\n\r\n```shell\r\npip install pyfollower-xxx.whl\r\n```\r\n\r\nAfter you have installed it, you can simply use this simulation Engine. As an example(Please make sure the numpy and matplotlib is installed):\r\n\r\n```python\r\nimport numpy as np\r\nfrom pyfollower import FollowerEngine\r\n\r\n# Initial scenario\r\ndest = dict()\r\nN = 50\r\nsim = FollowerEngine(agent_radius=0.5)\r\nsim.pref_velocity_correction(1)\r\n\r\nfor idx, i in enumerate(np.linspace(0, 1, N + 1)):\r\n    if i == 1: break\r\n    theta = i * np.pi * 2\r\n    ox, oy = np.cos(theta), np.sin(theta)\r\n    dx, dy = np.cos(theta + np.pi), np.sin(theta + np.pi)\r\n    t = np.array([ox, oy, dx, dy]) * 20\r\n    agent_id = sim.add_agent(*t)\r\n    dest[agent_id] = t[-2:]\r\n\r\n# Test obstacles\r\nsim.add_obstacles([(5, 5), (-5, 5), (-5, -5), (5, -5)])\r\nsim.process_obstacles()\r\nobs = np.array([(-5, -5), (-5, 5), (5, 5), (5, -5), (-5, -5)])\r\n\r\n# Run simulation --- Main loop\r\ntraj = []\r\nfor i in range(100):\r\n    if not i % 10: print(sim.time)\r\n    x = sim.get_agent_positions()\r\n    for agent_id in range(N):\r\n        dx = dest[agent_id] - x[agent_id, :]\r\n        dist = np.sqrt(np.sum(dx ** 2))\r\n        if dist < 0.5:\r\n            prev = (0, 0)\r\n        else:\r\n            prev = 1.0 * dx / dist\r\n        sim.set_agent_pref(agent_id, *prev)\r\n    traj.append(x)\r\n    print(x.T)\r\n    sim.follower_step()\r\n\r\n# Plot\r\nimport pylab as pl\r\nimport matplotlib.cm as cm\r\nfig = pl.figure('Trajectory', facecolor='thistle', figsize=(4, 4))\r\nax = fig.gca()\r\n\r\ntraj = np.stack(traj)\r\n\r\npl.xlim(-20, 20)\r\npl.ylim(-20, 20)\r\nax.imshow(np.zeros((40, 40), np.bool), extent=(-20, 20, -20, 20), cmap='viridis')\\\r\n    .format_cursor_data = lambda data: \"\"\r\n\r\ncolors = cm.hsv(np.linspace(0, 1, N))\r\nfor i in range(N):\r\n    ax.plot(traj[:, i, 0], traj[:, i, 1], c=colors[i])\r\nax.scatter(*x.T, c=range(N), s=20, cmap='hsv')\r\nax.plot(obs[:, 0], obs[:, 1], c='white')\r\n\r\nax.format_coord = lambda x, y: f'({x:^6.1f}, {y:^6.1f})'\r\n[spine.set_color('white') for spine in ax.spines.values()]\r\nax.tick_params(axis='both', colors='white')\r\n\r\npl.show()\r\n```\r\n\r\n### Citation\r\nDuring installation, due to differences in individual machines, various tricky issues may arise.\r\nIf you encounter any difficulties using this simulator, please do not hesitate to send an email to [dejavu.rabbyt@gmail.com]().\r\n\r\nIf you find our work helpful (or if you are so kind as to offer us some encouragement), please consider citing the paper.\r\n\r\n```bibtex\r\n@misc{liao2024emergent,\r\n      title={Emergent Crowd Grouping via Heuristic Self-Organization}, \r\n      author={Xiao-Cheng Liao and Wei-Neng Chen and Xiang-Ling Chen and Yi Mei},\r\n      year={2024},\r\n      eprint={2407.00674},\r\n      archivePrefix={arXiv},\r\n      primaryClass={cs.MA},\r\n      url={https://arxiv.org/abs/2407.00674}, \r\n}\r\n```\r\n",
    "bugtrack_url": null,
    "license": "Apache License 2.0",
    "summary": "Follower Crowd Simulation",
    "version": "0.1.4",
    "project_urls": null,
    "split_keywords": [
        "crowd",
        " simulation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "30c2da34aeeb9cd89d6f939a2bbec1940ea426a11e02a4bbfbaff4dd02a959ad",
                "md5": "1c099e477caacbb55f2b51de6264cb4a",
                "sha256": "809515a895b52df75efff2061edb7421981f6b5e5fc84930db83e5cde160e94f"
            },
            "downloads": -1,
            "filename": "pyfollower-0.1.4-cp311-cp311-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "1c099e477caacbb55f2b51de6264cb4a",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.7",
            "size": 94600,
            "upload_time": "2024-11-01T05:41:11",
            "upload_time_iso_8601": "2024-11-01T05:41:11.472856Z",
            "url": "https://files.pythonhosted.org/packages/30/c2/da34aeeb9cd89d6f939a2bbec1940ea426a11e02a4bbfbaff4dd02a959ad/pyfollower-0.1.4-cp311-cp311-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "41239192df46342498339f6efe78a51914e576d9dbe77435a3870fea866c93c8",
                "md5": "c3f7be4fdbaab3cf506e5de20240eab2",
                "sha256": "0f60141e01074c8411e378f8dd2623acc9ced291862b9d1cbebd5f038e7f77c8"
            },
            "downloads": -1,
            "filename": "pyfollower-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "c3f7be4fdbaab3cf506e5de20240eab2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 813573,
            "upload_time": "2024-11-01T05:41:13",
            "upload_time_iso_8601": "2024-11-01T05:41:13.880529Z",
            "url": "https://files.pythonhosted.org/packages/41/23/9192df46342498339f6efe78a51914e576d9dbe77435a3870fea866c93c8/pyfollower-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-01 05:41:13",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pyfollower"
}
        
Elapsed time: 1.62710s