Skip to content

Building Dataclass

Module containing building representation for the AMR Hub ABM simulation.

This module defines the Building class, which represents a building in the AMR Hub ABM simulation. The Building class contains a list of Floor objects and provides methods for plotting the building layout and sorting/numbering buildings by name.

Building dataclass

Representation of a building in the AMR Hub ABM simulation.

Parameters:

Name Type Description Default
name str

The name of the building.

required
floors list[Floor]

The list of floors in the building.

required
Source code in src/amr_hub_abm/spatial/building.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@dataclass
class Building:
    """
    Representation of a building in the AMR Hub ABM simulation.

    Parameters
    ----------
    name : str
        The name of the building.
    floors : list[Floor]
        The list of floors in the building.

    """

    idx: int = field(init=False, repr=False)
    name: str
    floors: list[Floor]

    def plot_building(
        self,
        axes: list[Axes],
        agents: list[Agent] | None = None,
        *,
        trajectory: bool = False,
    ) -> None:
        """
        Plot the building layout.

        Parameters
        ----------
        axes : list[Axes]
            The list of matplotlib axes to plot on.
        agents : list[Agent] | None, optional
            The list of agents to plot. Defaults to None.
        trajectory : bool, optional
            Whether to plot the trajectory of the agents. Defaults to False.

        """
        for floor, ax in zip(self.floors, axes, strict=True):
            floor.plot(ax=ax, agents=agents, trajectory=trajectory)

    @staticmethod
    def sort_and_number_buildings(buildings: list[Building]) -> list[Building]:
        """
        Sort and number buildings by name.

        Parameters
        ----------
        buildings : list[Building]
            The list of buildings to sort and number.

        Returns
        -------
        list[Building]
            The sorted and numbered list of buildings.

        """
        sorted_buildings = sorted(buildings, key=lambda b: b.name)
        for i, building in enumerate(sorted_buildings):
            building.idx = i
        return sorted_buildings

plot_building(axes, agents=None, *, trajectory=False)

Plot the building layout.

Parameters:

Name Type Description Default
axes list[Axes]

The list of matplotlib axes to plot on.

required
agents list[Agent] | None

The list of agents to plot. Defaults to None.

None
trajectory bool

Whether to plot the trajectory of the agents. Defaults to False.

False
Source code in src/amr_hub_abm/spatial/building.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def plot_building(
    self,
    axes: list[Axes],
    agents: list[Agent] | None = None,
    *,
    trajectory: bool = False,
) -> None:
    """
    Plot the building layout.

    Parameters
    ----------
    axes : list[Axes]
        The list of matplotlib axes to plot on.
    agents : list[Agent] | None, optional
        The list of agents to plot. Defaults to None.
    trajectory : bool, optional
        Whether to plot the trajectory of the agents. Defaults to False.

    """
    for floor, ax in zip(self.floors, axes, strict=True):
        floor.plot(ax=ax, agents=agents, trajectory=trajectory)

sort_and_number_buildings(buildings) staticmethod

Sort and number buildings by name.

Parameters:

Name Type Description Default
buildings list[Building]

The list of buildings to sort and number.

required

Returns:

Type Description
list[Building]

The sorted and numbered list of buildings.

Source code in src/amr_hub_abm/spatial/building.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@staticmethod
def sort_and_number_buildings(buildings: list[Building]) -> list[Building]:
    """
    Sort and number buildings by name.

    Parameters
    ----------
    buildings : list[Building]
        The list of buildings to sort and number.

    Returns
    -------
    list[Building]
        The sorted and numbered list of buildings.

    """
    sorted_buildings = sorted(buildings, key=lambda b: b.name)
    for i, building in enumerate(sorted_buildings):
        building.idx = i
    return sorted_buildings