diff --git a/libjupedsim/src/collision_free_speed_model_v2.cpp b/libjupedsim/src/collision_free_speed_model_v2.cpp index 2cc28c6cf..0c2e64b1e 100644 --- a/libjupedsim/src/collision_free_speed_model_v2.cpp +++ b/libjupedsim/src/collision_free_speed_model_v2.cpp @@ -69,7 +69,7 @@ void JPS_CollisionFreeSpeedModelV2State_SetStrengthNeighborRepulsion( { assert(handle); auto state = reinterpret_cast(handle); - state->strengthGeometryRepulsion = strengthNeighborRepulsion; + state->strengthNeighborRepulsion = strengthNeighborRepulsion; } double JPS_CollisionFreeSpeedModelV2State_GetRangeNeighborRepulsion( diff --git a/python_modules/jupedsim/jupedsim/models/social_force.py b/python_modules/jupedsim/jupedsim/models/social_force.py index 05318e9a7..c9a7989ad 100644 --- a/python_modules/jupedsim/jupedsim/models/social_force.py +++ b/python_modules/jupedsim/jupedsim/models/social_force.py @@ -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 diff --git a/systemtest/test_model_properties.py b/systemtest/test_model_properties.py index 0725ff5b4..afdd75b2d 100644 --- a/systemtest/test_model_properties.py +++ b/systemtest/test_model_properties.py @@ -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)], ) @@ -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) @@ -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