Skip to content

Kinetic evacuation of a network of rooms

The kinetic system of the evacuation of a building whose rooms form a network.

  • Class: EvacuationSystem
  • Import: from skcomplex.systems.social.crowds import EvacuationSystem
  • Field: social/crowds
  • Topics: crowds, evacuation, kinetic, network, distribution
  • References:
    • Bellomo et al. 2017 §3.4
    • Bellomo and Gibelli 2015

Use this system

The block imports the class and simulates the system with its default parameters and its tuned run settings.

from skcomplex.systems.social.crowds import EvacuationSystem

trajectory = EvacuationSystem().prepare().simulate()

Parameters

The model parameters take these defaults, and set_params changes them.

Parameter Default
branching 2
depth 2
speeds 3
mobility 0.5
crowding 2.0
recovery 0.5
solver 'auto'
backend 'auto'

Tags

The system with its default parameters has these capability tags, which solvers and analyses check.

Tag Values
Time continuous
Space lattice
Laws rate
Randomness deterministic
Domains real
Structure fixed

Class

The source of the class shows how it builds its components from its model parameters.

class EvacuationSystem(BaseSystem):
    """The kinetic system of the evacuation of a building whose rooms form a network.

    The crowd is a distribution over pairs of a room and a speed class, held by a site group on a two-dimensional
    lattice indexed by room and speed, with one last row of sites for the outside. The rooms form a balanced tree with
    the exit in the root room, and the walking encounters read its doors, so pedestrians walk to the next room on the
    way out at a rate proportional to their speed. Encounters within a room slow pedestrians down, and the exit signs
    speed them up again, so the crowd queues in the rooms near the exit and the evacuated fraction grows along an
    S-shaped curve.

    The rooms are the nodes and the speed classes the discrete activity of the kinetic structure for a network of
    Bellomo et al. (2017, sections 3.4 and 3.4.1), and the slowing and guiding encounters follow the behavioural crowd
    of Bellomo and Gibelli (2015). The crowd of chapter 6 of Bellomo et al. (2017), which moves in continuous space
    around walls and obstacles, is a different model. The system has the crowd `crowd`, the exit signs `signs`, and the
    interactions `walking`, `crowding`, and `guidance`. Its standard observables are the evacuated fraction and the mean
    walking speed.

    Args:
        branching:
            The number of rooms behind every door of the building.

        depth:
            The number of doors between the exit room and the rooms furthest from it.

        speeds:
            The number of speed classes.

        mobility:
            The rate at which pedestrians at the free speed leave a room.

        crowding:
            The rate of the encounters within a room that slow pedestrians down.

        recovery:
            The rate at which pedestrians speed up again.

        label:
            The label of the system, which names it when it is nested in another one.

        solver:
            The solver of the problem, or `'auto'` for the one the system chooses.

        backend:
            The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.

    Examples:
        >>> from skcomplex.systems.social.crowds import EvacuationSystem
        >>> EvacuationSystem().prepare().system_.elements[0].x.size
        24
    """

    field = 'social/crowds'
    topics = ('crowds', 'evacuation', 'kinetic', 'network', 'distribution')
    references = EVACUATION_REFERENCES
    until = 40
    dt = 0.5

    @staticmethod
    def _get_sizes_of(system: System) -> tuple[int, int]:
        """Return the number of rooms and of speed classes of a system.

        They are read from its crowding interaction.
        """
        crowding = next(item for item in system.interactions if isinstance(item, CrowdingInteraction))
        return int(crowding.rooms), int(crowding.speeds)

    def __init__(
        self,
        branching: int = 2,
        depth: int = 2,
        speeds: int = 3,
        *,
        mobility: float = 0.5,
        crowding: float = 2.0,
        recovery: float = 0.5,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.branching = branching
        self.depth = depth
        self.speeds = speeds
        self.mobility = mobility
        self.crowding = crowding
        self.recovery = recovery

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set `system_` to the components built from the model parameters."""
        super()._prepare(context)
        rooms = building_of(self.branching, self.depth).number_of_nodes()
        initial = np.zeros((rooms + 1, self.speeds))
        initial[:rooms, self.speeds // 2] = 1.0 / rooms
        crowd_space = LatticeSpace((rooms + 1, self.speeds), boundary='fixed')
        self.system_ = System(
            self.label,
            elements=[
                ActivityDensityElement('crowd', x=initial.ravel(), space=crowd_space),
                ActivityDensityElement('signs', x=[1.0], size=1),
            ],
            interactions=[
                WalkingInteraction(
                    'walking',
                    candidate='crowd',
                    field='signs',
                    branching=self.branching,
                    depth=self.depth,
                    speeds=self.speeds,
                    mobility=self.mobility,
                ),
                CrowdingInteraction(
                    'crowding',
                    candidate='crowd',
                    field='crowd',
                    rooms=rooms,
                    speeds=self.speeds,
                    crowding=self.crowding,
                ),
                GuidanceInteraction(
                    'guidance',
                    candidate='crowd',
                    field='signs',
                    rooms=rooms,
                    speeds=self.speeds,
                    recovery=self.recovery,
                ),
            ],
            space=crowd_space,
        )
        if not self.observables_:
            self.observables_ = tuple(evacuation_observables(*EvacuationSystem._get_sizes_of(self.system_)))

Components

The system uses these element and interaction classes, each with its nearest class of the core.

Elements:

Interactions:

class ActivityDensityElement(NonnegativeElement):
    """Value `x` of the density of active particles at one activity class.

    In the kinetic theory of active particles of Bellomo et al., a population is this element on a lattice of activity
    classes, with one value per class, and conservative, proliferative, and destructive encounters change it. The
    element has no laws of its own.

    Args:
        label:
            The label of the element, unique among the components of its system.

        x:
            The initial density, a nonnegative number.

        size:
            The number of members, or `None` for one.

        space:
            The space with one member per site, such as a lattice of classes, or `None` for none.

    Examples:
        >>> from skcomplex.core.components.spaces import LatticeSpace
        >>> from skcomplex.systems.social.common.kinetics import ActivityDensityElement
        >>> classes = LatticeSpace(5, boundary='fixed')
        >>> ActivityDensityElement('opinions', x=[0.2] * 5, space=classes).x
        [0.2, 0.2, 0.2, 0.2, 0.2]
    """

    def __init__(
        self,
        label: str,
        *,
        x: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
        size: int | None = None,
        space: BaseSpace | None = None,
    ) -> None:
        super().__init__(label, x=x, size=size, space=space)

class WalkingInteraction(EncounterInteraction):
    """Walking of pedestrians to the next room on the way out.

    It is an encounter with the exit signs.

    Args:
        label:
            The label of the interaction.

        candidate:
            The path of the crowd, a distribution over rooms and speed classes.

        field:
            The path of the group of one member whose fixed density is the guidance of the exit signs.

        branching:
            The number of rooms behind every door of the building, a balanced tree of rooms with the exit in room 0.

        depth:
            The number of doors between the exit room and the rooms furthest from it.

        speeds:
            The number of speed classes.

        mobility:
            The rate at which pedestrians at the free speed leave a room.

    Examples:
        >>> from skcomplex.systems.social.crowds import WalkingInteraction
        >>> WalkingInteraction('walking', candidate='crowd', field='signs').mobility
        0.5
    """

    def __init__(
        self,
        label: str,
        *,
        candidate: Role,
        field: Role,
        branching: Annotated[int, RealSet.open(0, oo)] = 2,
        depth: Annotated[int, RealSet.open(0, oo)] = 2,
        speeds: Annotated[int, RealSet.open(0, oo)] = 3,
        mobility: Annotated[float, RealSet.closed_open(0, oo)] = 0.5,
    ) -> None:
        super().__init__(label, candidate=candidate, field=field, rate=self._get_rate, kernel=self._get_kernel)
        self.branching = branching
        self.depth = depth
        self.speeds = speeds
        self.mobility = mobility

    def _get_rate(self, s: SimpleNamespace) -> object:
        """Return the rate at which every speed class of every room leaves it."""
        building = building_of(int(self.branching), int(self.depth))
        return walking_table(building, 0, int(self.speeds))[0] * s.mobility

    def _get_kernel(self, s: SimpleNamespace) -> object:
        """Return the table that moves a walker to the next room on the way out."""
        building = building_of(int(self.branching), int(self.depth))
        return walking_table(building, 0, int(self.speeds))[1]

class CrowdingInteraction(EncounterInteraction):
    """Encounters that slow pedestrians down in crowded rooms.

    It is an `EncounterInteraction` of the crowd with itself. Two pedestrians in the same room meet at the rate
    `crowding`, and the candidate slows down one speed class. Pedestrians outside keep their speed.

    Args:
        label:
            The label of the interaction.

        candidate:
            The path of the crowd, a distribution over rooms and speed classes.

        field:
            The path of the crowd that the candidates meet, the crowd again.

        rooms:
            The number of rooms.

        speeds:
            The number of speed classes.

        crowding:
            The rate of the encounters within a room that slow pedestrians down.

    Examples:
        >>> from skcomplex.systems.social.crowds import CrowdingInteraction
        >>> CrowdingInteraction('crowding', candidate='crowd', field='crowd').crowding
        2.0
    """

    def __init__(
        self,
        label: str,
        *,
        candidate: Role,
        field: Role,
        rooms: Annotated[int, RealSet.open(0, oo)] = 7,
        speeds: Annotated[int, RealSet.open(0, oo)] = 3,
        crowding: Annotated[float, RealSet.closed_open(0, oo)] = 2.0,
    ) -> None:
        super().__init__(label, candidate=candidate, field=field, rate=self._get_rate, kernel=self._get_kernel)
        self.rooms = rooms
        self.speeds = speeds
        self.crowding = crowding

    def _get_rate(self, s: SimpleNamespace) -> object:
        """Return the rate of the slowing encounters of every pair of classes.

        The encounters happen within a room.
        """
        return crowding_table(int(self.rooms), int(self.speeds), -1)[0] * s.crowding

    def _get_kernel(self, s: SimpleNamespace) -> object:
        """Return the table that moves a pedestrian down one speed class."""
        return crowding_table(int(self.rooms), int(self.speeds), -1)[1]

class GuidanceInteraction(EncounterInteraction):
    """Encounters with the exit signs that speed pedestrians up again.

    It is an `EncounterInteraction` of the crowd with the exit signs. A pedestrian meets the exit signs at the rate
    `recovery` and speeds up one class. Pedestrians outside keep their speed.

    Args:
        label:
            The label of the interaction.

        candidate:
            The path of the crowd, a distribution over rooms and speed classes.

        field:
            The path of the group of one member whose fixed density is the guidance of the exit signs.

        rooms:
            The number of rooms.

        speeds:
            The number of speed classes.

        recovery:
            The rate at which pedestrians speed up again.

    Examples:
        >>> from skcomplex.systems.social.crowds import GuidanceInteraction
        >>> GuidanceInteraction('guidance', candidate='crowd', field='signs').recovery
        0.5
    """

    def __init__(
        self,
        label: str,
        *,
        candidate: Role,
        field: Role,
        rooms: Annotated[int, RealSet.open(0, oo)] = 7,
        speeds: Annotated[int, RealSet.open(0, oo)] = 3,
        recovery: Annotated[float, RealSet.closed_open(0, oo)] = 0.5,
    ) -> None:
        super().__init__(label, candidate=candidate, field=field, rate=self._get_rate, kernel=self._get_kernel)
        self.rooms = rooms
        self.speeds = speeds
        self.recovery = recovery

    def _get_rate(self, s: SimpleNamespace) -> object:
        """Return the rate of the encounters of every class with the exit signs."""
        return crowding_table(int(self.rooms), int(self.speeds), 1)[0] * s.recovery

    def _get_kernel(self, s: SimpleNamespace) -> object:
        """Return the table that moves a pedestrian up one speed class."""
        return crowding_table(int(self.rooms), int(self.speeds), 1)[1]