Skip to content

Commit

Permalink
Split models.py per implemented model
Browse files Browse the repository at this point in the history
  • Loading branch information
Ozaq committed Dec 5, 2023
1 parent 275ea9e commit 77382fa
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 104 deletions.
4 changes: 3 additions & 1 deletion python_modules/jupedsim/jupedsim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
set_info_callback,
set_warning_callback,
)
from jupedsim.models import (
from jupedsim.models.collision_free_speed import (
CollisionFreeSpeedModel,
CollisionFreeSpeedModelAgentParameters,
CollisionFreeSpeedModelState,
)
from jupedsim.models.generalized_centrifugal_force import (
GeneralizedCentrifugalForceModel,
GeneralizedCentrifugalForceModelAgentParameters,
GeneralizedCentrifugalForceModelState,
Expand Down
4 changes: 2 additions & 2 deletions python_modules/jupedsim/jupedsim/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# SPDX-License-Identifier: LGPL-3.0-or-later

import jupedsim.native as py_jps
from jupedsim.models import (
CollisionFreeSpeedModelState,
from jupedsim.models.collision_free_speed import CollisionFreeSpeedModelState
from jupedsim.models.generalized_centrifugal_force import (
GeneralizedCentrifugalForceModelState,
)

Expand Down
106 changes: 106 additions & 0 deletions python_modules/jupedsim/jupedsim/models/collision_free_speed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Copyright © 2012-2023 Forschungszentrum Jülich GmbH
# SPDX-License-Identifier: LGPL-3.0-or-later

from dataclasses import dataclass

import jupedsim.native as py_jps


@dataclass(kw_only=True)
class CollisionFreeSpeedModel:
"""Parameters for Collision Free Speed Model
All attributes are initialized with reasonably good defaults.
Attributes:
strength_neighbor_repulsion: Strength of the repulsion from neighbors
range_neighbor_repulsion: Range of the repulsion from neighbors
strength_geometry_repulsion: Strength of the repulsion from geometry boundaries
range_geometry_repulsion: Range of the repulsion from geometry boundaries
"""

strength_neighbor_repulsion: float = 8.0
range_neighbor_repulsion: float = 0.1
strength_geometry_repulsion: float = 5.0
range_geometry_repulsion: float = 0.02


@dataclass(kw_only=True)
class CollisionFreeSpeedModelAgentParameters:
"""
Agent parameters for Collision Free Speed Model.
See the scientific publication for more details about this model
https://arxiv.org/abs/1512.05597
.. note::
Instances of this type are copied when creating the agent, you can safely
create one instance of this type and modify it between calls to `add_agent`
E.g.:
.. code:: python
positions = [...] # List of initial agent positions
params = CollisionFreeSpeedModelAgentParameters(speed=0.9) # all agents are slower
for p in positions:
params.position = p
sim.add_agent(params)
Attributes:
position: Position of the agent.
time_gap: Time constant that describe how fast pedestrian close gaps.
v0: Maximum speed of the agent.
radius: Radius of the agent.
journey_id: Id of the journey the agent follows.
stage_id: Id of the stage the agent targets.
"""

position: tuple[float, float] = (0.0, 0.0)
time_gap: float = 1.0
v0: float = 1.2
radius: float = 0.2
journey_id: int = 0
stage_id: int = 0

def as_native(self) -> py_jps.CollisionFreeSpeedModelAgentParameters:
return py_jps.CollisionFreeSpeedModelAgentParameters(
position=self.position,
time_gap=self.time_gap,
v0=self.v0,
radius=self.radius,
journey_id=self.journey_id,
stage_id=self.stage_id,
)


class CollisionFreeSpeedModelState:
def __init__(self, backing):
self._obj = backing

@property
def time_gap(self) -> float:
return self._obj.time_gap

@time_gap.setter
def time_gap(self, time_gap):
self._obj.time_gap = time_gap

@property
def v0(self) -> float:
"""Maximum speed of this agent."""
return self._obj.v0

@v0.setter
def v0(self, v0):
self._obj.v0 = v0

@property
def radius(self) -> float:
"""Radius of this agent."""
return self._obj.radius

@radius.setter
def radius(self, radius):
self._obj.radius = radius
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,6 @@
import jupedsim.native as py_jps


@dataclass(kw_only=True)
class CollisionFreeSpeedModel:
"""Parameters for Collision Free Speed Model
All attributes are initialized with reasonably good defaults.
Attributes:
strength_neighbor_repulsion: Strength of the repulsion from neighbors
range_neighbor_repulsion: Range of the repulsion from neighbors
strength_geometry_repulsion: Strength of the repulsion from geometry boundaries
range_geometry_repulsion: Range of the repulsion from geometry boundaries
"""

strength_neighbor_repulsion: float = 8.0
range_neighbor_repulsion: float = 0.1
strength_geometry_repulsion: float = 5.0
range_geometry_repulsion: float = 0.02


@dataclass(kw_only=True)
class GeneralizedCentrifugalForceModel:
"""Parameters for Generalized Centrifugal Force Model
Expand Down Expand Up @@ -125,56 +106,6 @@ def as_native(
)


@dataclass(kw_only=True)
class CollisionFreeSpeedModelAgentParameters:
"""
Agent parameters for Collision Free Speed Model.
See the scientific publication for more details about this model
https://arxiv.org/abs/1512.05597
.. note::
Instances of this type are copied when creating the agent, you can safely
create one instance of this type and modify it between calls to `add_agent`
E.g.:
.. code:: python
positions = [...] # List of initial agent positions
params = CollisionFreeSpeedModelAgentParameters(speed=0.9) # all agents are slower
for p in positions:
params.position = p
sim.add_agent(params)
Attributes:
position: Position of the agent.
time_gap: Time constant that describe how fast pedestrian close gaps.
v0: Maximum speed of the agent.
radius: Radius of the agent.
journey_id: Id of the journey the agent follows.
stage_id: Id of the stage the agent targets.
"""

position: tuple[float, float] = (0.0, 0.0)
time_gap: float = 1.0
v0: float = 1.2
radius: float = 0.2
journey_id: int = 0
stage_id: int = 0

def as_native(self) -> py_jps.CollisionFreeSpeedModelAgentParameters:
return py_jps.CollisionFreeSpeedModelAgentParameters(
position=self.position,
time_gap=self.time_gap,
v0=self.v0,
radius=self.radius,
journey_id=self.journey_id,
stage_id=self.stage_id,
)


class GeneralizedCentrifugalForceModelState:
def __init__(self, backing) -> None:
self._obj = backing
Expand Down Expand Up @@ -249,34 +180,3 @@ def b_max(self) -> float:
@b_max.setter
def b_max(self, b_max):
self._obj.b_max = b_max


class CollisionFreeSpeedModelState:
def __init__(self, backing):
self._obj = backing

@property
def time_gap(self) -> float:
return self._obj.time_gap

@time_gap.setter
def time_gap(self, time_gap):
self._obj.time_gap = time_gap

@property
def v0(self) -> float:
"""Maximum speed of this agent."""
return self._obj.v0

@v0.setter
def v0(self, v0):
self._obj.v0 = v0

@property
def radius(self) -> float:
"""Radius of this agent."""
return self._obj.radius

@radius.setter
def radius(self, radius):
self._obj.radius = radius
4 changes: 3 additions & 1 deletion python_modules/jupedsim/jupedsim/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
from jupedsim.geometry import Geometry
from jupedsim.geometry_utils import build_geometry
from jupedsim.journey import JourneyDescription
from jupedsim.models import (
from jupedsim.models.collision_free_speed import (
CollisionFreeSpeedModel,
CollisionFreeSpeedModelAgentParameters,
)
from jupedsim.models.generalized_centrifugal_force import (
GeneralizedCentrifugalForceModel,
GeneralizedCentrifugalForceModelAgentParameters,
)
Expand Down

0 comments on commit 77382fa

Please sign in to comment.