Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct setting of parameters in Collision Free Speed Model v2 #1414

Merged
merged 4 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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