Skip to content

Commit

Permalink
Correct setting of parameters in Collision Free Speed Model v2 (Pedes…
Browse files Browse the repository at this point in the history
…trianDynamics#1414)

* Fix parameter assignement

In CollisionFreeSpeedModelV2 setting strengthNeighborRepulsion was
modifiying strengthGeometryRepulsion.

* Add tests for setting agent parameters of collision free speed model

* Add tests for setting agent parameters of generalized centrifugal force model

* Add tests for setting agent parameters of social force model

---------

Co-authored-by: Ozaq <[email protected]>
  • Loading branch information
schroedtert and Ozaq authored May 20, 2024
1 parent 262111c commit 121b109
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libjupedsim/src/collision_free_speed_model_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void JPS_CollisionFreeSpeedModelV2State_SetStrengthNeighborRepulsion(
{
assert(handle);
auto state = reinterpret_cast<CollisionFreeSpeedModelV2Data*>(handle);
state->strengthGeometryRepulsion = strengthNeighborRepulsion;
state->strengthNeighborRepulsion = strengthNeighborRepulsion;
}

double JPS_CollisionFreeSpeedModelV2State_GetRangeNeighborRepulsion(
Expand Down
2 changes: 1 addition & 1 deletion python_modules/jupedsim/jupedsim/models/social_force.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(self, backing) -> None:
self._obj = backing

@property
def velocity(self) -> float:
def velocity(self) -> tuple[float, float]:
"""velocity of this agent."""
return self._obj.test_value

Expand Down
174 changes: 172 additions & 2 deletions systemtest/test_model_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@pytest.fixture
def corridor():
return jps.Simulation(
model=jps.CollisionFreeSpeedModel(),
model=jps.CollisionFreeSpeedModelV2(),
geometry=[(0, 0), (10, 0), (10, 2), (0, 2)],
)

Expand All @@ -19,7 +19,7 @@ def test_set_v0(corridor):
wp = sim.add_waypoint_stage((10, 1), 0.5)
journey_id = sim.add_journey(jps.JourneyDescription([wp]))

agent = jps.CollisionFreeSpeedModelAgentParameters(
agent = jps.CollisionFreeSpeedModelV2AgentParameters(
journey_id=journey_id, stage_id=wp, position=(1, 1), v0=1
)
agent_id = sim.add_agent(agent)
Expand All @@ -37,3 +37,173 @@ def test_set_v0(corridor):
for _ in range(0, 100):
sim.iterate()
assert math.isclose(sim.agent(agent_id).position[0], 7)


@pytest.fixture
def simulation_with_collision_free_speed_model_v2():
return jps.Simulation(
model=jps.CollisionFreeSpeedModelV2(),
geometry=[(0, 0), (10, 0), (10, 10), (0, 10)],
)


def test_set_model_parameters_collision_free_speed_model_v2(
simulation_with_collision_free_speed_model_v2,
):
sim = simulation_with_collision_free_speed_model_v2
wp = sim.add_waypoint_stage((10, 1), 0.5)
journey_id = sim.add_journey(jps.JourneyDescription([wp]))

agent = jps.CollisionFreeSpeedModelV2AgentParameters(
journey_id=journey_id,
stage_id=wp,
position=(1, 1),
)
agent_id = sim.add_agent(agent)

sim.agent(agent_id).model.v0 = 2.0
assert sim.agent(agent_id).model.v0 == 2.0

sim.agent(agent_id).model.time_gap = 3.0
assert sim.agent(agent_id).model.time_gap == 3.0

sim.agent(agent_id).model.radius = 4.0
assert sim.agent(agent_id).model.radius == 4.0

sim.agent(agent_id).model.strength_neighbor_repulsion = 5.0
assert sim.agent(agent_id).model.strength_neighbor_repulsion == 5.0

sim.agent(agent_id).model.range_neighbor_repulsion = 6.0
assert sim.agent(agent_id).model.range_neighbor_repulsion == 6.0

sim.agent(agent_id).model.range_geometry_repulsion = 7.0
assert sim.agent(agent_id).model.range_geometry_repulsion == 7.0

sim.agent(agent_id).model.range_geometry_repulsion = 8.0
assert sim.agent(agent_id).model.range_geometry_repulsion == 8.0


@pytest.fixture
def simulation_with_collision_free_speed_model():
return jps.Simulation(
model=jps.CollisionFreeSpeedModel(),
geometry=[(0, 0), (10, 0), (10, 10), (0, 10)],
)


def test_set_model_parameters_collision_free_speed_model(
simulation_with_collision_free_speed_model,
):
sim = simulation_with_collision_free_speed_model
wp = sim.add_waypoint_stage((10, 1), 0.5)
journey_id = sim.add_journey(jps.JourneyDescription([wp]))

agent = jps.CollisionFreeSpeedModelAgentParameters(
journey_id=journey_id,
stage_id=wp,
position=(1, 1),
)
agent_id = sim.add_agent(agent)

sim.agent(agent_id).model.v0 = 2.0
assert sim.agent(agent_id).model.v0 == 2.0

sim.agent(agent_id).model.time_gap = 3.0
assert sim.agent(agent_id).model.time_gap == 3.0

sim.agent(agent_id).model.radius = 4.0
assert sim.agent(agent_id).model.radius == 4.0


@pytest.fixture
def simulation_with_generalized_centrifugal_force_model():
return jps.Simulation(
model=jps.GeneralizedCentrifugalForceModel(),
geometry=[(0, 0), (10, 0), (10, 10), (0, 10)],
)


def test_set_model_parameters_generalized_centrifugal_force_model(
simulation_with_generalized_centrifugal_force_model,
):
sim = simulation_with_generalized_centrifugal_force_model
wp = sim.add_waypoint_stage((10, 1), 0.5)
journey_id = sim.add_journey(jps.JourneyDescription([wp]))

agent = jps.GeneralizedCentrifugalForceModelAgentParameters(
journey_id=journey_id,
stage_id=wp,
position=(1, 1),
)
agent_id = sim.add_agent(agent)

sim.agent(agent_id).model.speed = 2.0
assert sim.agent(agent_id).model.speed == 2.0

sim.agent(agent_id).model.e0 = (3.0, -3.0)
assert sim.agent(agent_id).model.e0 == (3.0, -3.0)

sim.agent(agent_id).model.tau = 4.0
assert sim.agent(agent_id).model.tau == 4.0

sim.agent(agent_id).model.v0 = 5.0
assert sim.agent(agent_id).model.v0 == 5.0

sim.agent(agent_id).model.a_v = 6.0
assert sim.agent(agent_id).model.a_v == 6.0

sim.agent(agent_id).model.a_min = 7.0
assert sim.agent(agent_id).model.a_min == 7.0

sim.agent(agent_id).model.b_min = 8.0
assert sim.agent(agent_id).model.b_min == 8.0

sim.agent(agent_id).model.b_max = 9.0
assert sim.agent(agent_id).model.b_max == 9.0


@pytest.fixture
def simulation_with_social_force_model():
return jps.Simulation(
model=jps.SocialForceModel(),
geometry=[(0, 0), (10, 0), (10, 10), (0, 10)],
)


def test_set_model_parameters_social_force_model(
simulation_with_social_force_model,
):
sim = simulation_with_social_force_model
wp = sim.add_waypoint_stage((10, 1), 0.5)
journey_id = sim.add_journey(jps.JourneyDescription([wp]))

agent = jps.SocialForceModelAgentParameters(
journey_id=journey_id,
stage_id=wp,
position=(1, 1),
)
agent_id = sim.add_agent(agent)

sim.agent(agent_id).model.velocity = (2.0, -2.0)
assert sim.agent(agent_id).model.velocity == (2.0, -2.0)

sim.agent(agent_id).model.mass = 3.0
assert sim.agent(agent_id).model.mass == 3.0

sim.agent(agent_id).model.desiredSpeed = 4.0
assert sim.agent(agent_id).model.desiredSpeed == 4.0

sim.agent(agent_id).model.reactionTime = 5.0
assert sim.agent(agent_id).model.reactionTime == 5.0

sim.agent(agent_id).model.agentScale = 6.0
assert sim.agent(agent_id).model.agentScale == 6.0

sim.agent(agent_id).model.obstacleScale = 7.0
assert sim.agent(agent_id).model.obstacleScale == 7.0

sim.agent(agent_id).model.ForceDistance = 8.0
assert sim.agent(agent_id).model.ForceDistance == 8.0

sim.agent(agent_id).model.radius = 9.0
assert sim.agent(agent_id).model.radius == 9.0

0 comments on commit 121b109

Please sign in to comment.