Skip to content

Commit

Permalink
Make 'pushout_stregth' configurable in AVM
Browse files Browse the repository at this point in the history
  • Loading branch information
Ozaq committed Jan 22, 2025
1 parent 2617aa9 commit e7579f8
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 17 deletions.
4 changes: 3 additions & 1 deletion libjupedsim/include/jupedsim/anticipation_velocity_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ typedef struct JPS_AnticipationVelocityModelBuilder_t* JPS_AnticipationVelocityM

/**
* Creates a Anticipation Velocity Model builder.
* @param pushoutStrength strength of repulsive force of walls.
* @param rng_seed Seed value for random number generator.
* @return the builder
*/
JUPEDSIM_API JPS_AnticipationVelocityModelBuilder
JPS_AnticipationVelocityModelBuilder_Create(uint64_t rng_seed);
JPS_AnticipationVelocityModelBuilder_Create(double pushoutStrength, uint64_t rng_seed);

/**
* Creates a JPS_OperationalModel of type Anticipation Velocity Model from the
Expand Down
4 changes: 2 additions & 2 deletions libjupedsim/src/anticipation_velocity_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
/// Anticipation Velocity Model Builder
////////////////////////////////////////////////////////////////////////////////////////////////////
JUPEDSIM_API JPS_AnticipationVelocityModelBuilder
JPS_AnticipationVelocityModelBuilder_Create(uint64_t rng_seed)
JPS_AnticipationVelocityModelBuilder_Create(double pushoutStrength, uint64_t rng_seed)
{
return reinterpret_cast<JPS_AnticipationVelocityModelBuilder>(
new AnticipationVelocityModelBuilder(rng_seed));
new AnticipationVelocityModelBuilder(pushoutStrength, rng_seed));
}

JUPEDSIM_API JPS_OperationalModel JPS_AnticipationVelocityModelBuilder_Build(
Expand Down
4 changes: 1 addition & 3 deletions libjupedsim/test/TestJupedsim.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright © 2012-2024 Forschungszentrum Jülich GmbH
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "AgentIterator.hpp"
#include "Point.hpp"
#include "jupedsim/anticipation_velocity_model.h"
#include "gtest/gtest.h"
#include <ErrorMessage.hpp>
Expand Down Expand Up @@ -48,7 +46,7 @@ TEST(OperationalModel, DefaultsOfCollisionFreeSpeedModelAgentParameters)
TEST(OperationalModel, CanConstructAnticipationVelocityModel)
{
JPS_ErrorMessage errorMsg{};
auto builder = JPS_AnticipationVelocityModelBuilder_Create(0);
auto builder = JPS_AnticipationVelocityModelBuilder_Create(0.3, 0);
auto model = JPS_AnticipationVelocityModelBuilder_Build(builder, &errorMsg);
EXPECT_NE(model, nullptr);
EXPECT_EQ(errorMsg, nullptr);
Expand Down
5 changes: 2 additions & 3 deletions libsimulator/src/AnticipationVelocityModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#include <numeric>
#include <vector>

AnticipationVelocityModel::AnticipationVelocityModel(uint64_t rng_seed) : gen(rng_seed)
AnticipationVelocityModel::AnticipationVelocityModel(double pushoutStrength, uint64_t rng_seed)
: pushoutStrength(pushoutStrength), gen(rng_seed)
{
}

Expand Down Expand Up @@ -327,8 +328,6 @@ Point AnticipationVelocityModel::HandleWallAvoidance(
// Get parallel component of current direction
const auto parallelComponent = wallDirection * direction.ScalarProduct(wallDirection);

// Add a small outward component to maintain minimum distance
const double pushoutStrength = 0.3; // TODO(@mchraibi): This is random.
const auto newDirection =
parallelComponent + directionAwayFromBoundary * pushoutStrength;
return newDirection.Normalized();
Expand Down
4 changes: 3 additions & 1 deletion libsimulator/src/AnticipationVelocityModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ class AnticipationVelocityModel : public OperationalModel

private:
double _cutOffRadius{3};
/// Add a small outward component to maintain minimum distance from walls.
double pushoutStrength = 0.3;
mutable std::mt19937 gen;

public:
AnticipationVelocityModel(uint64_t rng_seed);
AnticipationVelocityModel(double pushoutStrength, uint64_t rng_seed);
~AnticipationVelocityModel() override = default;
OperationalModelType Type() const override;
OperationalModelUpdate ComputeNewPosition(
Expand Down
8 changes: 5 additions & 3 deletions libsimulator/src/AnticipationVelocityModelBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "AnticipationVelocityModelBuilder.hpp"

AnticipationVelocityModelBuilder::AnticipationVelocityModelBuilder(uint64_t rng_seed)
: rng_seed(rng_seed)
AnticipationVelocityModelBuilder::AnticipationVelocityModelBuilder(
double pushoutStrength,
uint64_t rng_seed)
: pushoutStrength(pushoutStrength), rng_seed(rng_seed)
{
}

AnticipationVelocityModel AnticipationVelocityModelBuilder::Build()
{
return AnticipationVelocityModel(rng_seed);
return AnticipationVelocityModel(pushoutStrength, rng_seed);
}
3 changes: 2 additions & 1 deletion libsimulator/src/AnticipationVelocityModelBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
class AnticipationVelocityModelBuilder
{
public:
AnticipationVelocityModelBuilder(uint64_t rng_seed);
AnticipationVelocityModelBuilder(double pushoutStrength, uint64_t rng_seed);
AnticipationVelocityModel Build();

private:
double pushoutStrength{};
uint64_t rng_seed{};
};
5 changes: 3 additions & 2 deletions python_bindings_jupedsim/anticipation_velocity_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ void init_anticipation_velocity_model(py::module_& m)
});
py::class_<JPS_AnticipationVelocityModelBuilder_Wrapper>(m, "AnticipationVelocityModelBuilder")
.def(
py::init([](uint64_t rng_seed) {
py::init([](double pushoutStrength, uint64_t rng_seed) {
return std::make_unique<JPS_AnticipationVelocityModelBuilder_Wrapper>(
JPS_AnticipationVelocityModelBuilder_Create(rng_seed));
JPS_AnticipationVelocityModelBuilder_Create(pushoutStrength, rng_seed));
}),
py::kw_only(),
py::arg("pushout_strength"),
py::arg("rng_seed"))
.def("build", [](JPS_AnticipationVelocityModelBuilder_Wrapper& w) {
JPS_ErrorMessage errorMsg{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ class AnticipationVelocityModel:
https://doi.org/10.1016/j.trc.2021.103464
Attributes:
pushout_strength: TODO(@mchraibi): ADD DOC :)
rng_seed: seed value of internally used rng. If not explicitly set this
value will be choosen randomly.
"""

pushout_strength: float = 0.3
rng_seed: int = randint(0, 2**64 - 1)


Expand Down
2 changes: 1 addition & 1 deletion python_modules/jupedsim/jupedsim/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(
py_jps_model = model_builder.build()
elif isinstance(model, AnticipationVelocityModel):
model_builder = py_jps.AnticipationVelocityModelBuilder(
rng_seed=model.rng_seed
pushout_strength=model.pushout_strength, rng_seed=model.rng_seed
)
py_jps_model = model_builder.build()
elif isinstance(model, GeneralizedCentrifugalForceModel):
Expand Down

0 comments on commit e7579f8

Please sign in to comment.