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

Anticipation Velocity Model (AVM) #1432

Open
wants to merge 52 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
46c0bd8
Change version of jupedsim
chraibi Dec 30, 2024
09001fb
First version compiles
chraibi Dec 31, 2024
778523f
Running CollisionFreeSpeedModelV3.
chraibi Jan 1, 2025
6e65c65
update example
chraibi Jan 1, 2025
0e1838e
Rename model CollisionFreeSpeedModelV3 to AVM
chraibi Jan 3, 2025
f2344d9
remove unused imports
chraibi Jan 3, 2025
b7e4218
Implement direction of agents
chraibi Jan 6, 2025
9c6b365
Implement boundaryRepulsion
chraibi Jan 6, 2025
ec801e4
Update the direction according to eq 7
chraibi Jan 6, 2025
de57a2e
validate parameters of the model
chraibi Jan 6, 2025
42bb1db
Update functionality for walls behind walls
chraibi Jan 7, 2025
681b518
Add anticipation and reaction times to C-API
chraibi Jan 7, 2025
732f1a6
Fix bug in wall calculation
chraibi Jan 7, 2025
7dfffef
rename get reaction time
chraibi Jan 7, 2025
407bae0
Add two parameters and remove unused parameter from AVM API
chraibi Jan 7, 2025
f79dd6f
python bindings for AVM
chraibi Jan 7, 2025
efb7ca7
Add test can construct AVM
chraibi Jan 7, 2025
f83fbfa
Init new parameters in libjupedsim simulation
chraibi Jan 7, 2025
b7147a6
Add headon examples
chraibi Jan 7, 2025
c8df214
Wrong sign for wall influence
chraibi Jan 7, 2025
df7041f
Update velocity of agents
chraibi Jan 8, 2025
21bcc41
Fix bug: Apply Update velocity of agents
chraibi Jan 9, 2025
23305ae
Fix missmatch of neighbor and geometry parameters
chraibi Jan 9, 2025
f8a5ca1
Implement sliding walls
chraibi Jan 10, 2025
269b608
Refactor sliding walls
chraibi Jan 14, 2025
bdd9299
Add notebook to compare all models
chraibi Jan 14, 2025
e6cf0e0
Update models for anticipation velocity model
chraibi Jan 14, 2025
6f41508
Update notebook with time plots
chraibi Jan 14, 2025
9cc1865
Add documentation for AVM
chraibi Jan 14, 2025
f2d88a7
link notebook to documentation
chraibi Jan 14, 2025
920259f
Update model notebook
chraibi Jan 14, 2025
3ca16f1
Add requirement for notebook
chraibi Jan 14, 2025
6d37d3b
rename notebook and add it to index
chraibi Jan 14, 2025
8fbc35d
Add more explanatory context to the notebook
chraibi Jan 15, 2025
354da4b
Add tests for AVM and update AVM-parameters contraints
chraibi Jan 15, 2025
9092048
merge two cells in the notebook
chraibi Jan 15, 2025
bf8d459
Add test default parameters of AVM
chraibi Jan 15, 2025
0b9352f
update AVM default parameters
chraibi Jan 15, 2025
5e124cf
update clang format
chraibi Jan 15, 2025
264c09b
clang-format my code
chraibi Jan 15, 2025
42da8e2
clangformating
chraibi Jan 15, 2025
c615170
clang-formating a bunch
chraibi Jan 15, 2025
5710c4c
clang formatting
chraibi Jan 15, 2025
e339d71
sorting imports and ruffing
chraibi Jan 15, 2025
0045715
use clang-format 18
chraibi Jan 15, 2025
7db6421
clang format
chraibi Jan 15, 2025
35da307
Fixed python formatting
Ozaq Jan 15, 2025
9dfd0a4
Format cpp code to match newer clang-format version
Ozaq Jan 15, 2025
7320f23
Fix formatting
Ozaq Jan 15, 2025
d19228b
set version to 1.3.0
chraibi Jan 15, 2025
2444f89
update example 7
chraibi Jan 15, 2025
9fbb00d
reformatting and restructuring the comparison-models notebook
chraibi Jan 15, 2025
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 CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Project setup
################################################################################
cmake_minimum_required(VERSION 3.22 FATAL_ERROR)
project(JuPedSim VERSION 1.3.0 LANGUAGES CXX)
project(JuPedSim VERSION 1.3.1 LANGUAGES CXX)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the version bump, 1.3.0 is still unreleased

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
Expand Down
81 changes: 81 additions & 0 deletions examples/example7_avm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#! /usr/bin/env python3

# Copyright © 2012-2024 Forschungszentrum Jülich GmbH
# SPDX-License-Identifier: LGPL-3.0-or-later

import pathlib
import sys

import jupedsim as jps
import shapely
from shapely import Polygon


def main():
room1 = Polygon([(0, 0), (10, 0), (10, 10), (0, 10)]) # Room 1 (10m x 10m)
room2 = Polygon(
[(15, 0), (25, 0), (25, 10), (15, 10)]
) # Room 2 (10m x 10m)
width = 0.8
num_agents = 10
corridor = Polygon(
[
(10, 5 - width / 2),
(15, 5 - width / 2),
(15, 5 + width / 2),
(10, 5 + width / 2),
]
)
geometry = room1.union(room2).union(corridor)
# geometry = shapely.GeometryCollection(shapely.box(0, -2.5, 50, 2.5))
# exit_polygon = shapely.box(48, -2.5, 50, 2.5) #
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented out code

exit_polygon = Polygon([(24, 4.5), (25, 4.5), (25, 5.5), (24, 5.5)])
trajectory_file = "example_7.sqlite"
simulation = jps.Simulation(
model=jps.AnticipationVelocityModel(),
geometry=geometry,
trajectory_writer=jps.SqliteTrajectoryWriter(
output_file=pathlib.Path(trajectory_file)
),
)

exit_id = simulation.add_exit_stage(exit_polygon)
journey = jps.JourneyDescription([exit_id])
journey_id = simulation.add_journey(journey)

start_positions = jps.distribute_by_number(
polygon=Polygon([(0, 0), (5, 0), (5, 10), (0, 10)]),
# shapely.box(0, -2.5, 5, 2.5),
number_of_agents=num_agents,
distance_to_agents=0.5,
distance_to_polygon=0.2,
)

for position in start_positions:
simulation.add_agent(
jps.AnticipationVelocityModelAgentParameters(
journey_id=journey_id,
stage_id=exit_id,
position=position,
radius=0.2,
# strength_neighbor_repulsion=8,
# range_neighbor_repulsion=0.1,
# strength_geometry_repulsion=5,
# range_geometry_repulsion=0.1,
)
)

while simulation.agent_count() > 0 and simulation.iteration_count() < 3000:
try:
simulation.iterate()
except KeyboardInterrupt:
print("CTRL-C Received! Shutting down")
sys.exit(1)
print(
f"Simulation completed after {simulation.iteration_count()} iterations ({simulation.elapsed_time()} s)"
)
print(f"{trajectory_file = }")


if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions libjupedsim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add_library(jupedsim_obj OBJECT
src/build_info.cpp
src/collision_free_speed_model.cpp
src/collision_free_speed_model_v2.cpp
src/anticipation_velocity_model.cpp
src/error.cpp
src/generalized_centrifugal_force_model.cpp
src/geometry.cpp
Expand Down Expand Up @@ -112,6 +113,7 @@ install(
${header_dest}/build_info.h
${header_dest}/collision_free_speed_model.h
${header_dest}/collision_free_speed_model_v2.h
${header_dest}/anticipation_velocity_model.h
${header_dest}/error.h
${header_dest}/export.h
${header_dest}/generalized_centrifugal_force_model.h
Expand Down
12 changes: 12 additions & 0 deletions libjupedsim/include/jupedsim/agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "collision_free_speed_model.h"
#include "collision_free_speed_model_v2.h"
#include "anticipation_velocity_model.h"
#include "error.h"
#include "export.h"
#include "generalized_centrifugal_force_model.h"
Expand Down Expand Up @@ -116,6 +117,17 @@ JPS_Agent_GetSocialForceModelState(JPS_Agent handle, JPS_ErrorMessage* errorMess
JUPEDSIM_API JPS_CollisionFreeSpeedModelV2State
JPS_Agent_GetCollisionFreeSpeedModelV2State(JPS_Agent handle, JPS_ErrorMessage* errorMessage);

/**
* Access Anticipation Velocity Model state.
* Precondition: Agent needs to use Anticipation Velocity Model
* @param handle of the agent to access.
* @param[out] errorMessage if not NULL: will be set to a JPS_ErrorMessage in case of an error.
* @return state or NULL on error
*/
JUPEDSIM_API JPS_AnticipationVelocityModelState
JPS_Agent_GetAnticipationVelocityModelState(JPS_Agent handle, JPS_ErrorMessage* errorMessage);


/**
* Opaque type of an iterator over agents
*/
Expand Down
253 changes: 253 additions & 0 deletions libjupedsim/include/jupedsim/anticipation_velocity_model.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
/* Copyright © 2012-2024 Forschungszentrum Jülich GmbH */
/* SPDX-License-Identifier: LGPL-3.0-or-later */
#pragma once

#include "error.h"
#include "export.h"
#include "operational_model.h"
#include "types.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* Opaque type for a Anticipation Velocity Model Builder
*/
typedef struct JPS_AnticipationVelocityModelBuilder_t* JPS_AnticipationVelocityModelBuilder;

/**
* Creates a Anticipation Velocity Model builder.
* @return the builder
*/
JUPEDSIM_API JPS_AnticipationVelocityModelBuilder JPS_AnticipationVelocityModelBuilder_Create();

/**
* Creates a JPS_OperationalModel of type Anticipation Velocity Model from the
* JPS_AnticipationVelocityModelBuilder.
* @param handle the builder to operate on
* @param[out] errorMessage if not NULL: will be set to a JPS_ErrorMessage in case of an error
* @return a JPS_AnticipationVelocityModel or NULL if an error occured.
*/
JUPEDSIM_API JPS_OperationalModel JPS_AnticipationVelocityModelBuilder_Build(
JPS_AnticipationVelocityModelBuilder handle,
JPS_ErrorMessage* errorMessage);

/**
* Frees a JPS_AnticipationVelocityModelBuilder
* @param handle to the JPS_AnticipationVelocityModelBuilder to free.
*/
JUPEDSIM_API void
JPS_AnticipationVelocityModelBuilder_Free(JPS_AnticipationVelocityModelBuilder handle);

/**
* Opaque type of Anticipation Velocity Model state
*/
typedef struct JPS_AnticipationVelocityModelState_t* JPS_AnticipationVelocityModelState;

/**
* Read strength neighbor repulsion of this agent.
* @param handle of the Agent to access.
* @return strength neighbor repulsion of this agent
*/
JUPEDSIM_API double JPS_AnticipationVelocityModelState_GetStrengthNeighborRepulsion(
JPS_AnticipationVelocityModelState handle);

/**
* Write strength neighbor repulsion of this agent.
* @param handle of the Agent to access.
* @param strengthNeighborRepulsion of this agent.
*/
JUPEDSIM_API void JPS_AnticipationVelocityModelState_SetStrengthNeighborRepulsion(
JPS_AnticipationVelocityModelState handle,
double strengthNeighborRepulsion);

/**
* Read range neighbor repulsion of this agent.
* @param handle of the Agent to access.
* @return range neighbor repulsion of this agent
*/
JUPEDSIM_API double JPS_AnticipationVelocityModelState_GetRangeNeighborRepulsion(
JPS_AnticipationVelocityModelState handle);

/**
* Write range neighbor repulsion of this agent.
* @param handle of the Agent to access.
* @param rangeNeighborRepulsion of this agent.
*/
JUPEDSIM_API void JPS_AnticipationVelocityModelState_SetRangeNeighborRepulsion(
JPS_AnticipationVelocityModelState handle,
double rangeNeighborRepulsion);

/**
* Read strength geometry repulsion of this agent.
* @param handle of the Agent to access.
* @return strength geometry repulsion of this agent
*/
JUPEDSIM_API double JPS_AnticipationVelocityModelState_GetStrengthGeometryRepulsion(
JPS_AnticipationVelocityModelState handle);

/**
* Write strength geometry repulsion of this agent.
* @param handle of the Agent to access.
* @param strengthGeometryRepulsion of this agent.
*/
JUPEDSIM_API void JPS_AnticipationVelocityModelState_SetStrengthGeometryRepulsion(
JPS_AnticipationVelocityModelState handle,
double strengthGeometryRepulsion);

/**
* Read range geometry repulsion of this agent.
* @param handle of the Agent to access.
* @return range geometry repulsion of this agent
*/
JUPEDSIM_API double JPS_AnticipationVelocityModelState_GetRangeGeometryRepulsion(
JPS_AnticipationVelocityModelState handle);

/**
* Write strength neighbor repulsion of this agent.
* @param handle of the Agent to access.
* @param rangeGeometryRepulsion of this agent.
*/
JUPEDSIM_API void JPS_AnticipationVelocityModelState_SetRangeGeometryRepulsion(
JPS_AnticipationVelocityModelState handle,
double rangeGeometryRepulsion);

/**
* Read e0 of this agent.
* @param handle of the Agent to access.
* @return e0 of this agent
*/
JUPEDSIM_API JPS_Point
JPS_AnticipationVelocityModelState_GetE0(JPS_AnticipationVelocityModelState handle);

/**
* Write e0 of this agent.
* @param handle of the Agent to access.
* @param e0 of this agent.
*/
JUPEDSIM_API void
JPS_AnticipationVelocityModelState_SetE0(JPS_AnticipationVelocityModelState handle, JPS_Point e0);

/**
* Read time gap of this agent.
* @param handle of the Agent to access.
* @return time gap of this agent
*/
JUPEDSIM_API double
JPS_AnticipationVelocityModelState_GetTimeGap(JPS_AnticipationVelocityModelState handle);

/**
* Write time gap of this agent.
* @param handle of the Agent to access.
* @param time_gap of this agent.
*/
JUPEDSIM_API void JPS_AnticipationVelocityModelState_SetTimeGap(
JPS_AnticipationVelocityModelState handle,
double time_gap);

/**
* Read tau of this agent.
* @param handle of the Agent to access.
* @return tau of this agent
*/
JUPEDSIM_API double
JPS_AnticipationVelocityModelState_GetTau(JPS_AnticipationVelocityModelState handle);

/**
* Write tau of this agent.
* @param handle of the Agent to access.
* @param tau of this agent.
*/
JUPEDSIM_API void
JPS_AnticipationVelocityModelState_SetTau(JPS_AnticipationVelocityModelState handle, double tau);

/**
* Read v0 of this agent.
* @param handle of the Agent to access.
* @return v0 of this agent
*/
JUPEDSIM_API double
JPS_AnticipationVelocityModelState_GetV0(JPS_AnticipationVelocityModelState handle);

/**
* Write v0 of this agent.
* @param handle of the Agent to access.
* @param v0 of this agent.
*/
JUPEDSIM_API void
JPS_AnticipationVelocityModelState_SetV0(JPS_AnticipationVelocityModelState handle, double v0);

/**
* Read radius of this agent.
* @param handle of the Agent to access.
* @return radius of this agent
*/
JUPEDSIM_API double
JPS_AnticipationVelocityModelState_GetRadius(JPS_AnticipationVelocityModelState handle);

/**
* Write radius of this agent in meters.
* @param handle of the Agent to access.
* @param radius (m) of this agent.
*/
JUPEDSIM_API void JPS_AnticipationVelocityModelState_SetRadius(
JPS_AnticipationVelocityModelState handle,
double radius);

/**
* Describes parameters of an Agent in Anticipation Velocity Model
*/
typedef struct JPS_AnticipationVelocityModelAgentParameters {
/**
* Position of the agent.
* The position needs to inside the accessible area.
*/
JPS_Point position{0, 0};
/**
* Defines the journey this agent will take use
*/
JPS_JourneyId journeyId = 0;
/**
* Defines the current stage of its journey
*/
JPS_StageId stageId = 0;

/**
* @param time_gap of the agents using this profile (T in the OV-function)
*/
double time_gap = 1.;
/**
*@param v0 of the agents using this profile(desired speed) double radius;
*/
double v0 = 1.2;
/**
*@param radius of the agent in 'meters'
*/
double radius = 0.2;

/**
* Strength of the repulsion from neighbors
*/
double strengthNeighborRepulsion{8.0};

/**
* Range of the repulsion from neighbors
*/
double rangeNeighborRepulsion{0.1};

/**
* Strength of the repulsion from geometry boundaries
*/
double strengthGeometryRepulsion{5.0};

/**
* Range of the repulsion from geometry boundaries
*/
double rangeGeometryRepulsion{0.02};

} JPS_AnticipationVelocityModelAgentParameters;

#ifdef __cplusplus
}
#endif
1 change: 1 addition & 0 deletions libjupedsim/include/jupedsim/jupedsim.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "build_info.h"
#include "collision_free_speed_model.h"
#include "collision_free_speed_model_v2.h"
#include "anticipation_velocity_model.h"
#include "error.h"
#include "export.h"
#include "generalized_centrifugal_force_model.h"
Expand Down
Loading
Loading