models
agents
Defines a class Agent to store physical attributes and geometry of agents.
- class configuration.models.agents.Agent(agent_type, measures)[source]
Bases:
objectClass representing an agent with physical attributes and geometry.
- Parameters:
agent_type (AgentTypes) -- The type of the agent.
measures (dict[str, float | Sex] | AgentMeasures) -- The measures associated with the agent. Can be a dictionary with measure names as keys and float values or Sex (Literal["male","female"]), or an AgentMeasures object.
- property agent_type: AgentTypes
Get the agent type.
- Returns:
The current agent type from the enumeration AgentTypes.
- Return type:
AgentType
- property measures: AgentMeasures
Access the agent's physical measurement data.
- Returns:
Dataclass object holding all measurement parameters.
- Return type:
- property shapes2D: Shapes2D
Access the agent's 2D representation.
- Returns:
Dataclass object holding all 2D shapes defining the agent's spatial boundaries.
- Return type:
- property shapes3D: Shapes3D | None
Access the agent's 3D geometric representations.
- Returns:
Dataclass object holding all 3D shapes defining the agent's 3D features, if available. None if not set.
- Return type:
Shapes3D | None
- translate(dx, dy)[source]
Translate all 2D shapes by the specified offsets in x and y directions.
- Parameters:
- Return type:
Notes
Does not affect 3D shapes.
- rotate(angle)[source]
Rotate all 2D shapes around the agent position (defined by its centroid) by the specified angle.
- Parameters:
angle (float) -- Rotation angle in degrees (positive for counter-clockwise).
- Return type:
Notes
Does not affect 3D shapes.
- get_position()[source]
Calculate the agent's position based on 2D shape geometry.
- Returns:
The mean of the centroids of all composite shapes of the 2D representation of the agent.
- Return type:
- translate_body3D(dx, dy, dz)[source]
Translate 3D shapes along all spatial axes with height adjustment.
- Parameters:
- Raises:
ValueError -- If shapes3D is None.
- Return type:
- rotate_body3D(angle)[source]
Rotate all 3D shapes on XY plane around Z-axis.
- Parameters:
angle (float) -- Rotation angle in degrees (positive counter-clockwise).
- Raises:
ValueError -- If shapes3D is None.
- Return type:
- get_centroid_body3D()[source]
Calculate the centroid of the agent's 3D body.
- Returns:
The centroid of the agent's 3D body, calculated as the mean of the centroid of each 3D body layer.
- Return type:
- Raises:
ValueError -- If shapes3D is None.
crowd
Module containing the Crowd class, which represents a crowd of pedestrians in a room.
- class configuration.models.crowd.Crowd(measures=None, agents=None, boundaries=None)[source]
Bases:
objectClass representing a crowd of pedestrians in a room.
- Parameters:
measures (dict[str, float] | CrowdMeasures | None) --
- Crowd measures data. Can be:
A dictionary of agent statistics (str keys, float values)
A CrowdMeasures instance
None (default) when agents are provided instead
agents (list[Agent] | None) -- List of Agent instances. If None, measures must be provided. When agents are provided, crowd statistics will be calculated from them.
boundaries (Polygon | None) -- A shapely Polygon instance defining the boundaries. If None, a default large square boundary is created.
- property measures: CrowdMeasures
Get the measures of the crowd.
- Returns:
A CrowdMeasures object containing the measures of the crowd.
- Return type:
- property boundaries: Polygon
Get the boundaries of the room.
- Returns:
The boundaries of the room as a shapely Polygon object.
- Return type:
- get_number_agents()[source]
Get the number of agents in the crowd.
- Returns:
The number of agents in the crowd.
- Return type:
- add_one_agent()[source]
Add a new agent to the crowd using available measures data.
The agent creation follows this priority: 1. Uses agent statistics if available 2. Uses the default ANSURII database
- Return type:
- create_agents(number_agents=4)[source]
Create multiple agents in the crowd from the given CrowdMeasures (ANSURII database by default).
- calculate_interpenetration()[source]
Compute the total interpenetration area between pedestrians and between pedestrians and boundaries.
- Returns:
The total interpenetration area between pedestrians and between pedestrians and boundaries.
- Return type:
- calculate_covered_area()[source]
Calculate the total area covered by all 2D agents in the crowd.
- Returns:
The total area covered by all 2D agents.
- Return type:
- static calculate_contact_force(agent_centroid, other_centroid)[source]
Compute the repulsive force between two centroids.
- Parameters:
- Returns:
The normalized direction of the repulsive force as a 1D NumPy array of floats. If the centroids coincide, a small random force is returned.
- Return type:
NDArray[np.float64]
- static calculate_repulsive_force(agent_centroid, other_centroid, repulsion_length)[source]
Compute the repulsive force between two centroids, exponentially decreasing with distance.
- Parameters:
agent_centroid (Point) -- The centroid of the agent.
other_centroid (Point) -- The centroid of the other agent.
repulsion_length (float) -- Coefficient used to compute the magnitude of the repulsive force between agents. The force decreases exponentially with distance divided by this repulsion_length.
- Returns:
A 1D NumPy array representing the repulsive force vector. If the centroids coincide, a small random force is returned.
- Return type:
NDArray[np.float64]
- calculate_boundary_forces(current_geo, temperature)[source]
Compute boundary interaction forces for an agent near environment edges.
- Parameters:
- Returns:
Updated force vector with boundary interactions.
- Return type:
NDArray[np.float64]
Notes
Forces are only applied when the agent is outside the boundaries or touching boundary edges.
- Force calculations:
Contact force: Linear repulsion from nearest boundary point.
Rotational force: Temperature-scaled random torque.
- static check_validity_parameters_agents_packing(repulsion_length, desired_direction, variable_orientation)[source]
Validate the input parameters for agent packing.
- update_shapes3D_based_on_shapes2D()[source]
Update the position and orientation of 3D shapes of all agents based on their 2D shapes.
This method iterates through each agent in the crowd and updates its 3D shapes position and orientation based on the corresponding 2D shapes.
- Return type:
- pack_agents_with_forces(repulsion_length=5.0, desired_direction=0.0, variable_orientation=False)[source]
Simulate crowd dynamics using physics-based forces to resolve agent overlaps.
Iteratively calculates repulsive forces between agents and boundary constraints, while applying rotational adjustments. Implements a temperature-based cooling system to gradually reduce movement intensity over iterations.
- Parameters:
repulsion_length (float) -- Exponential decay coefficient for repulsive forces between agents. Higher values increase the effective range of repulsion.
desired_direction (float) -- Initial orientation angle in degrees for all agents.
variable_orientation (bool) -- Whether to apply rotational forces during packing. When True, enables random angular adjustments based on collision forces.
- Return type:
Notes
- Boundary handling:
Uses Shapely Polygon objects for boundary constraints
Agents cannot move outside boundary polygons
Boundaries are treated as static
- Force calculations:
Agent-agent repulsion (exponential decay with distance)
Contact forces for overlapping agents
Boundary repulsion for agents near edges
Rotational forces (only when variable_orientation=True)
- pack_agents_on_grid(grid_size_x=31.0, grid_size_y=60.0)[source]
Arrange the agents on a square 2D grid with specified cell sizes, ensuring that the smallest x and y coordinates are at (0, 0).
- get_crowd_statistics()[source]
Measure the statistics of the crowd.
- Returns:
- A dictionary whose keys and values are:
stats_counts: A dictionary with counts of agents by type.
stats_lists: A dictionary with lists of measurements for each agent type.
measures: A dictionary of computed statistics for the crowd.
- Return type:
dict[str, dict[str, int] | dict[str, list[float | None]] | dict[str, float | int | None]]
Notes
- The dictionary containing the computed statistics for the crowd has keys formatted as follows:
"{kind}_proportion": Count of agents (e.g., "male_proportion" or "bike_proportion" or "pedestrian_proportion")
"{part}_mean": Mean value for each body/bike part measurement
"{part}_std_dev": Sample standard deviation for each part
"{part}_min": Minimum observed value for each part
"{part}_max": Maximum observed value for each part
- The dictionary containing the counts of agents by type has keys formatted as follows:
"pedestrian_number": Total number of pedestrians
"male_number": Total number of males
"bike_number": Total number of bikes
- The dictionary containing the lists of measurements for each agent type has keys formatted as follows:
"bike_weight": List of weights for all bikes
"male_bideltoid_breadth": List of bideltoid breadths for all male pedestrians
"male_chest_depth": List of chest depths for all male pedestrians
"male_height": List of heights for all male pedestrians
"male_weight": List of weights for all male pedestrians
"female_bideltoid_breadth": List of bideltoid breadths for all female pedestrians
"female_chest_depth": List of chest depths for all female pedestrians
"female_height": List of heights for all female pedestrians
"female_weight": List of weights for all female pedestrians
"wheel_width": List of wheel widths for all bikes
"total_length": List of total lengths for all bikes
"handlebar_length": List of handlebar lengths for all bikes
"top_tube_length": List of top tube lengths for all bikes
- configuration.models.crowd.create_agents_from_dynamic_static_geometry_parameters(static_dict, dynamic_dict, geometry_dict)[source]
Create agents from dynamic and static geometry parameters.
- Parameters:
static_dict (StaticCrowdDataType) -- Dictionary containing static crowd data.
dynamic_dict (DynamicCrowdDataType) -- Dictionary containing dynamic crowd data.
geometry_dict (GeometryDataType) -- Dictionary containing geometry data.
- Returns:
A Crowd object containing the created agents and the scene boundaries.
- Return type:
initial_agents
Module defining the InitialPedestrian and InitialBike classes.
- class configuration.models.initial_agents.InitialPedestrian(sex)[source]
Bases:
objectClass representing the initial pedestrian state including its 2D shape data and basic measurements.
- Parameters:
sex (Sex) -- Biological sex of the pedestrian, must be either "male" or "female".
- property sex: Literal['male', 'female']
Get the biological sex of the pedestrian.
- Returns:
The biological sex of the pedestrian as either "male" or "female".
- Return type:
- Raises:
ValueError -- If provided value is not "male" or "female"
TypeError -- If non-string value is provided
- property agent_type: AgentTypes
Get the type of the agent.
- Returns:
Enum member representing the agent's type classification (either "pedestrian", "bike" or "custom").
- Return type:
- property shapes2D: dict[str, dict[str, Literal['disk', 'rectangle', 'polygon'] | Literal['concrete', 'human_naked', 'human_clothes'] | float]] | dict[str, dict[str, Literal['disk', 'rectangle', 'polygon'] | Literal['concrete', 'human_naked', 'human_clothes'] | float | Polygon | MultiPolygon]]
Get the 2D geometric representation of the pedestrian's body components.
- Returns:
- Dictionary containing circular disk representations of body parts with:
Keys: Format "disk{N}" where N ranges 0-4 (e.g., "disk0", "disk1")
- Values: Dictionaries with properties:
type: "disk" (str from ShapeTypes enum name)
radius: Disk radius (cm)
material: Material name (str from MaterialNames enum)
x: x-coordinate (cm)
y: y-coordinate (cm)
- Return type:
ShapeDataType
- property measures: dict[str, float | Literal['male', 'female'] | None]
Get the measures of the pedestrian.
- property shapes3D: dict[float, MultiPolygon]
Get the 3D body representation of the pedestrian.
- Returns:
- A dictionary where:
Keys are float representing the height of each pedestrian slice.
Values are "MultiPolygon" objects representing the 2D geometry of each layer or slice.
- Return type:
- get_position()[source]
Get the centroid position of the pedestrian based on their 2D shapes.
- Returns:
A Point object representing the centroid of the pedestrian's geometry.
- Return type:
- get_disk_centers()[source]
Retrieve the center coordinates of all disks of the agent physical shape.
- get_reference_multipolygon()[source]
Get the reference multipolygon of the agent i.e. the one at torso height.
- Returns:
The reference multipolygon of the agent.
- Return type:
- get_bideltoid_breadth()[source]
Compute the bideltoid breadth of the agent (that has not rotated) in cm.
- Returns:
The bideltoid breadth of the agent (cm).
- Return type:
- class configuration.models.initial_agents.InitialBike[source]
Bases:
objectClass representing the initial state of a bike, including its 2D shape data and derived measurements.
- property agent_type: AgentTypes
Get the type of the agent.
- Returns:
Enum member representing the agent's type classification (either "pedestrian", "bike" or "custom").
- Return type:
- property shapes2D: dict[str, dict[str, Literal['disk', 'rectangle', 'polygon'] | Literal['concrete', 'human_naked', 'human_clothes'] | float]] | dict[str, dict[str, Literal['disk', 'rectangle', 'polygon'] | Literal['concrete', 'human_naked', 'human_clothes'] | float | Polygon | MultiPolygon]]
Get the 2D shapes of the agent.
- Returns:
An object containing the 2D shapes of the agent.
- Return type:
ShapeDataType
- get_position()[source]
Compute the centroid position of the agent based on all 2D shapes.
- Returns:
A Point object representing the centroid of the agent's geometry.
- Return type:
- Raises:
ValueError -- If no valid shapes are found in self.shapes2D.
measures
Module containing the AgentMeasures and CrowdMeasures dataclass to store body measures and crowd desired measures.
- class configuration.models.measures.AgentMeasures(agent_type, measures=<factory>)[source]
Bases:
objectClass to store body characteristics based on agent type.
- Parameters:
agent_type (AgentTypes)
-
agent_type:
AgentTypes
- class configuration.models.measures.CrowdMeasures(default_database=<factory>, agent_statistics=<factory>)[source]
Bases:
objectCollection of dictionaries (databases and statistics) representing the characteristics of the crowd, used to create agents.
- configuration.models.measures.draw_agent_measures(agent_type, crowd_measures)[source]
Draw randomly a set of agent measures based on the agent type.
- Parameters:
agent_type (AgentTypes) -- The type of agent for which to draw measures. Must be either AgentTypes.pedestrian or AgentTypes.bike.
crowd_measures (CrowdMeasures) -- An object containing statistical measures for the crowd, including both pedestrian and bike-specific measurements.
- Returns:
An object containing the randomly drawn measures for the specified agent type.
- Return type:
- configuration.models.measures.draw_agent_type(crowd_measures)[source]
Draw a random agent type using tower sampling algorithm.
- Parameters:
crowd_measures (CrowdMeasures) -- An instance of CrowdMeasures containing the statistics of different agent types in the crowd.
- Returns:
The randomly selected agent type (pedestrian or bike) based on the given proportions.
- Return type:
- Raises:
ValueError -- If the sum of pedestrian and bike proportions is not equal to 1.
- configuration.models.measures.create_pedestrian_measures(agent_data)[source]
Create pedestrian-specific AgentMeasures object.
- Parameters:
agent_data (dict[str, float]) --
- A dictionary containing pedestrian measurements. Expected keys are:
"sex": The sex of the pedestrian (either "male" or "female").
"bideltoid breadth [cm]": Shoulder width in centimeters.
"chest depth [cm]": Depth of the chest in centimeters.
"height [cm]": Height of the pedestrian in centimeters.
"weight [kg]": Weight of the pedestrian in kilograms.
- Returns:
An AgentMeasures object.
- Return type:
- configuration.models.measures.create_bike_measures(agent_data)[source]
Create bike-specific AgentMeasures object.
- Parameters:
agent_data (dict[str, float]) --
- A dictionary containing bike measurements. Expected keys are:
"wheel width [cm]": Width of the bike's wheel in centimeters.
"total length [cm]": Total length of the bike in centimeters.
"handlebar length [cm]": Length of the bike's handlebar in centimeters.
"top tube length [cm]": Length of the bike's top tube in centimeters.
- Returns:
- An AgentMeasures object with the following attributes:
agent_type: Set to AgentTypes.bike
measures: A dictionary mapping bike parts to their measurements
- Return type:
shapes2D
Class to store body shapes based on agent type.
- class configuration.models.shapes2D.Shapes2D(agent_type, shapes=<factory>)[source]
Bases:
objectClass to store body shapes based on agent type.
This class allows you to manage shapes in two ways:
Provide a dictionary of pre-defined Shapely shapes as input
Specify the type of shape and its characteristics to create it
- Parameters:
agent_type (AgentTypes)
shapes (dict[str, dict[str, Literal['disk', 'rectangle', 'polygon'] | ~typing.Literal['concrete', 'human_naked', 'human_clothes'] | float]] | dict[str, dict[str, ~typing.Literal['disk', 'rectangle', 'polygon'] | ~typing.Literal['concrete', 'human_naked', 'human_clothes'] | float | ~shapely.geometry.polygon.Polygon | ~shapely.geometry.multipolygon.MultiPolygon]])
-
agent_type:
AgentTypes
-
shapes:
dict[str,dict[str,Union[Literal['disk','rectangle','polygon'],Literal['concrete','human_naked','human_clothes'],float]]] |dict[str,dict[str,Union[Literal['disk','rectangle','polygon'],Literal['concrete','human_naked','human_clothes'],float,Polygon,MultiPolygon]]]
- add_shape(name, shape_type, material, **kwargs)[source]
Create a shape and add it to the shapes dictionary.
- Parameters:
name (str) -- The name of the shape.
shape_type (ShapeType) -- The type of the shape. Must be one of the following: {'disk', 'rectangle', 'polygon'}.
material (MaterialType) -- The material of the shape.
**kwargs (Any) --
Additional keyword arguments specific to the shape type:
Disk:
x (float): The x-coordinate of the disk's center.
y (float): The y-coordinate of the disk's center.
radius (float): The radius of the disk.
material (str): The material of the disk.
Rectangle:
min_x (float): The minimum x-coordinate of the rectangle.
min_y (float): The minimum y-coordinate of the rectangle.
max_x (float): The maximum x-coordinate of the rectangle.
max_y (float): The maximum y-coordinate of the rectangle.
material (str): The material of the rectangle.
Polygon:
- points (list of tuple[float, float]): A list of (x, y) coordinates representing
the vertices of the polygon. Must contain at least 3 points, and the first and last points must match to close the polygon.
material (str): The material of the polygon.
- Raises:
ValueError -- If the shape type is unsupported or if required keyword arguments are missing or invalid.
- Return type:
Notes
This method validates that all required parameters are provided and ensures that shapes are correctly formatted before adding them to the dictionary.
- get_additional_parameters()[source]
Retrieve the parameters for each stored shape.
- Returns:
A dictionary where each key is the name of a shape, and the corresponding value is a dictionary containing the parameters for that shape. The structure of the parameter dictionary depends on the type of shape:
Disk:
type (str): The type of the shape (always 'disk').
radius (float): The radius of the disk.
material (str): The material of the disk's interior.
x (float): The x-coordinate of the disk's center.
y (float): The y-coordinate of the disk's center.
Rectangle:
type (str): The type of the shape (always 'rectangle').
material (str): The material of the rectangle's interior.
min_x (float): The x-coordinate of the rectangle's minimum bound.
min_y (float): The y-coordinate of the rectangle's minimum bound.
max_x (float): The x-coordinate of the rectangle's maximum bound.
max_y (float): The y-coordinate of the rectangle's maximum bound.
Polygon:
type (str): The type of the shape (always 'polygon').
material (str): The material of the polygon's interior.
- points (list of tuple[float, float]): A list of (x, y) coordinates representing
the vertices of the polygon.
- Return type:
ShapeDataType
Notes
This method assumes that all shapes are stored with their respective parameters in a consistent format.
- number_of_shapes()[source]
Return the total number of stored shapes.
- Returns:
The total number of shapes stored in the shapes attribute.
- Return type:
- create_pedestrian_shapes(measurements)[source]
Create the shapes of a pedestrian based on the provided measures.
This method generates the shapes of a pedestrian agent by scaling initial disk centers and radii according to the provided measurements. To find the correct scalings, it uses an optimization algorithm to minimize the difference between the desired and actual chest depth and bideltoid breadth.
- Parameters:
measurements (AgentMeasures) -- An object containing the measurements of the pedestrian agent.
- Raises:
ValueError -- If the agent type is not 'pedestrian'.
- Return type:
- create_bike_shapes(measurements)[source]
Create and scale 2D shapes for a bike and its rider based on provided measurements.
This method uses an optimization process to generate bike and rider shapes that best match the provided measurements. It scales initial shapes to minimize the difference between desired and actual dimensions.
- Parameters:
measurements (AgentMeasures) -- An object containing the target measurements for various bike parts and rider dimensions.
- Raises:
ValueError -- If the agent type is not 'bike'.
- Return type:
- get_geometric_shapes()[source]
Return the geometric shapes that constitute a pedestrian physical shape.
- get_geometric_shape()[source]
Return the geometric union of all shapes that constitute a pedestrian physical shape.
- Returns:
The union of all stored shapes as a single Polygon object.
- Return type:
- get_area()[source]
Compute the area of the agent 2D representation.
- Returns:
The area of the agent 2D representation (cm²).
- Return type:
- get_chest_depth()[source]
Compute the chest depth (anterior-posterior diameter) of a pedestrian agent in centimeters.
The chest depth is defined as twice the radius of 'disk2', converted from meters to centimeters.
- Returns:
The chest depth of the agent in centimeters.
- Return type:
- Raises:
ValueError -- If the agent is not a pedestrian or required parameters are missing.
- get_bideltoid_breadth()[source]
Compute the bideltoid breadth (shoulder width) of a pedestrian agent in centimeters.
- Returns:
The bideltoid breadth of the agent in centimeters.
- Return type:
- Raises:
ValueError -- If the agent is not a pedestrian or required parameters are missing.
shapes3D
Class to store body shapes dynamically based on agent type.
- class configuration.models.shapes3D.Shapes3D(agent_type, shapes=<factory>)[source]
Bases:
objectStore and manage 3D body shapes for different agent types.
- Parameters:
agent_type (AgentTypes)
shapes (dict[str, dict[str, Literal['disk', 'rectangle', 'polygon'] | ~typing.Literal['concrete', 'human_naked', 'human_clothes'] | float]] | dict[str, dict[str, ~typing.Literal['disk', 'rectangle', 'polygon'] | ~typing.Literal['concrete', 'human_naked', 'human_clothes'] | float | ~shapely.geometry.polygon.Polygon | ~shapely.geometry.multipolygon.MultiPolygon]])
-
agent_type:
AgentTypes
-
shapes:
dict[str,dict[str,Union[Literal['disk','rectangle','polygon'],Literal['concrete','human_naked','human_clothes'],float]]] |dict[str,dict[str,Union[Literal['disk','rectangle','polygon'],Literal['concrete','human_naked','human_clothes'],float,Polygon,MultiPolygon]]]
- create_pedestrian3D(measurements)[source]
Create a 3D representation of a pedestrian based on provided measurements.
- Parameters:
measurements (AgentMeasures) -- An object containing the target measurements of the pedestrian, including sex, bideltoid breadth, chest depth, and height.
- Raises:
ValueError -- If the provided sex in "measurements" is not "male" or "female".
- Return type:
Notes
The method uses an initial pedestrian representation based on the provided sex.
Scaling factors are calculated for each dimension (x, y, z) based on the ratio of target measurements to initial measurements.
- get_height()[source]
Compute the height of the agent in meters.
- Returns:
The height of the agent in meters.
- Return type:
- get_reference_multipolygon()[source]
Get the reference multipolygon of the agent i.e. the one at torso height.
- Returns:
The reference multipolygon of the agent.
- Return type: