Skip to main content

Crate rustsim_crowd

Crate rustsim_crowd 

Source
Expand description

Microscopic crowd locomotion models for rustsim.

This crate implements the five microscopic pedestrian models catalogued at https://pedestriandynamics.org/models/ in pure 2-D continuous space plus a layered 2.5-D extension in the threed module for multi-storey environments (stations, airports, stadiums, malls).

It is called rustsim-crowd rather than rustsim-pedestrian because the same physics apply equally to cyclists, evacuees, queue-formers, and generic self-propelled agents.

ModuleModelClassPrimary references
social_forceSocial ForceForce-based, 2nd orderHelbing & Molnár 1995; Helbing, Farkas & Vicsek 2000
collision_free_speedCollision-Free SpeedVelocity-based, 1st orderTordeux, Chraibi & Seyfried 2016
generalized_centrifugal_forceGeneralized Centrifugal ForceForce-based, 2nd orderChraibi, Seyfried & Schadschneider 2010
optimal_stepsOptimal StepsDiscrete-step utilitySeitz & Köster 2012
anticipation_velocityAnticipation VelocityVelocity-based, 1st orderXu, Chraibi & Seyfried 2021
threedLayered 2.5-D Social ForcePer-floor 2-D physics + vertical connectorsIndustry standard (JuPedSim, MassMotion, Legion)

§API shape

Every 2-D model shares the same three-type contract defined by the PedestrianModel trait:

  • Pedestrian — the shared per-agent state (position, velocity, radius, desired speed, destination).
  • WallSegment — a 2-D line segment describing a static obstacle.
  • Params — a model-specific parameter bundle living inside each module.

Each model exposes:

  • a Params struct with stable literature/engineering defaults.
  • explicit calibration helpers for deployments that must enforce a published speed-density envelope such as Weidmann (1993).
  • a unit struct implementing PedestrianModel so callers can swap models behind a trait object or generic bound.
  • a free step(peds, walls, params, dt) function (deprecated since 0.0.3; O(n²) reference path retained for parity tests). Production callers use step_scratch (zero-alloc) or step_with_grid (broadphase) instead.
use rustsim_crowd::prelude::*;

let mut peds = vec![Pedestrian::new(
    [0.0, 0.0],
    [0.0, 0.0],
    0.25,
    1.34,
    [10.0, 0.0],
)];
let walls: Vec<WallSegment> = Vec::new();
let params = social_force::Params::default();
// Production hot path: zero-alloc, broadphase-accelerated.
let mut scratch = Scratch::new(recommended_cell_size(
    social_force::neighbor_cutoff(&params),
));
social_force::step_scratch(&mut peds, &walls, &params, 0.05, &mut scratch);

§Design constraints

  • Pure f64, SoA-friendly internals, no interior mutability.
  • step_scratch(peds, walls, params, dt, &mut scratch) is the zero-alloc hot path: allocate one broadphase::Scratch per simulation and reuse it tick-after-tick. step_with_grid takes a caller-owned NeighborGrid and allocates one Vec<[f64; 2]> per tick; step is the O(n²) reference path with no broadphase.
  • Determinism: every step_* variant is a deterministic function of its inputs.

Re-exports§

pub use broadphase::recommended_cell_size;
pub use broadphase::NeighborGrid;
pub use broadphase::Scratch;
pub use calibration::apply_weidmann_speed_cap;
pub use calibration::apply_weidmann_speed_target;
pub use calibration::density_for_area;
pub use calibration::mean_speed;
pub use calibration::CalibrationPoint;
pub use calibration::CalibrationReport;
pub use calibration::WeidmannCurve;
pub use common::Pedestrian;
pub use common::PedestrianModel;
pub use common::WallSegment;
pub use error::CrowdError;
pub use integration::pack_columns_from;
pub use integration::step_columns_f64;
pub use integration::step_scratch_store;
pub use integration::step_scratch_store_observed;
pub use integration::unpack_columns_into;
pub use integration::AnticipationVelocityModel;
pub use integration::CollisionFreeSpeedModel;
pub use integration::CrowdAgent;
pub use integration::CrowdObserver;
pub use integration::CrowdStep;
pub use integration::GeneralizedCentrifugalForceModel;
pub use integration::OptimalStepsModel;
pub use integration::SocialForceModel;
pub use threed::LayeredObserver;
pub use threed::LayeredScratch;
pub use threed::Pedestrian3D;
pub use threed::WallPolygon3D;

Modules§

anticipation_velocity
Anticipation Velocity Model (Xu, Chraibi & Seyfried 2021).
broadphase
Broadphase acceleration for crowd models.
calibration
Scientific calibration helpers for pedestrian fundamental diagrams.
collision_free_speed
Collision-Free Speed Model (Tordeux, Chraibi & Seyfried 2016).
common
Shared types and trait for all pedestrian models in this crate.
error
Parameter and runtime errors for rustsim-crowd.
generalized_centrifugal_force
Generalized Centrifugal Force Model (Chraibi, Seyfried & Schadschneider 2010).
integration
rustsim-core integration for the crowd models.
optimal_steps
Optimal Steps Model (Seitz & Köster 2012).
prelude
Convenience re-exports for the common consumer path.
social_force
Social Force Model (Helbing & Molnár 1995; Helbing, Farkas & Vicsek 2000).
threed
Layered 2.5-D crowd locomotion for multi-storey environments.