Skip to content

Commit

Permalink
Add example using CFSMV2
Browse files Browse the repository at this point in the history
  • Loading branch information
schroedtert committed Mar 15, 2024
1 parent 8e0374f commit 8a31a90
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions examples/example6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#! /usr/bin/env python3

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

import pathlib
import sys

import shapely

import jupedsim as jps


def main():
geometry = shapely.GeometryCollection(shapely.box(0, -2.5, 50, 2.5))
exit_polygon = shapely.box(48, -2.5, 50, 2.5)

trajectory_file = "example_6.sqlite"
simulation = jps.Simulation(
model=jps.CollisionFreeSpeedModelV2(),
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)

motivated_start_positions = jps.distribute_by_number(
polygon=shapely.box(0, -2.5, 5, 2.5),
number_of_agents=30,
distance_to_agents=0.3,
distance_to_polygon=0.2,
)

for position in motivated_start_positions:
simulation.add_agent(
jps.CollisionFreeSpeedModelV2AgentParameters(
journey_id=journey_id,
stage_id=exit_id,
position=position,
radius=0.12,
strength_neighbor_repulsion=8,
range_neighbor_repulsion=0.1,
strength_geometry_repulsion=5,
range_geometry_repulsion=0.1,
)
)

slow_start_positions = jps.distribute_by_number(
polygon=shapely.box(15, -2.5, 20, 2.5),
number_of_agents=30,
distance_to_agents=0.3,
distance_to_polygon=0.2,
)

for position in slow_start_positions:
simulation.add_agent(
jps.CollisionFreeSpeedModelV2AgentParameters(
journey_id=journey_id,
stage_id=exit_id,
position=position,
radius=0.12,
strength_neighbor_repulsion=30,
range_neighbor_repulsion=0.1,
strength_geometry_repulsion=15,
range_geometry_repulsion=0.1,
v0=0.3,
)
)

while simulation.agent_count() > 0:
try:
simulation.iterate()
except KeyboardInterrupt:
print("CTRL-C Recieved! Shuting down")
sys.exit(1)
print(
f"Simulation completed after {simulation.iteration_count()} iterations"
)


if __name__ == "__main__":
main()

0 comments on commit 8a31a90

Please sign in to comment.