VIPRA Documentation
Loading...
Searching...
No Matches
calm_model.hpp
1#pragma once
2
3#include "vipra/modules/map.hpp"
4#include "vipra/modules/model.hpp"
5
6#include "vipra/macros/model.hpp"
7#include "vipra/macros/module.hpp"
8#include "vipra/macros/parameters.hpp"
9#include "vipra/macros/performance.hpp"
10
11#include "calm_collision.hpp"
12#include "calm_model_types.hpp"
13#include "vipra/types/float.hpp"
14
15namespace Model {
17 public:
18 VIPRA_MODULE_NAME("Calm")
19 VIPRA_MODULE_TYPE(Model)
20
21 VIPRA_REGISTER_PARAMS(VIPRA_PARAM("meanMass", _config.meanMass),
22 VIPRA_PARAM("massStdDev", _config.massStdDev),
23 VIPRA_PARAM("meanMass", _config.meanMass),
24 VIPRA_PARAM("massStdDev", _config.massStdDev),
25 VIPRA_PARAM("meanReactionTime", _config.meanReactionTime),
26 VIPRA_PARAM("reactionTimeStdDev", _config.reactionTimeStdDev),
27 VIPRA_PARAM("meanMaxSpeed", _config.meanMaxSpeed),
28 VIPRA_PARAM("maxSpeedStdDev", _config.maxSpeedStdDev),
29 VIPRA_PARAM("meanShoulderLen", _config.meanShoulderLen),
30 VIPRA_PARAM("shoulderLenStdDev", _config.shoulderLenStdDev),
31 VIPRA_PARAM("collisionRange", _config.collisionRange),
32 VIPRA_PARAM("friction", _config.frictionCoef))
33
34 VIPRA_MODEL_RESET {}
35
36 // NOLINTNEXTLINE(misc-unused-parameters)
37 VIPRA_MODEL_INIT_STEP
38 {
39 _peds.resize(pedset.num_pedestrians());
40 _collision.initialize(_config.collisionRange, pedset);
41
42 _peds.masses = VIPRA::Random::make_distribution(
43 std::normal_distribution<VIPRA::f_pnt>{_config.meanMass, _config.massStdDev},
44 _peds.size(), engine);
45 _peds.reactionTimes = VIPRA::Random::make_distribution<>(
46 std::normal_distribution<VIPRA::f_pnt>{_config.meanReactionTime,
47 _config.reactionTimeStdDev},
48 _peds.size(), engine);
49 _peds.maxSpeeds = VIPRA::Random::make_distribution<>(
50 std::normal_distribution<VIPRA::f_pnt>{_config.meanMaxSpeed,
51 _config.maxSpeedStdDev},
52 _peds.size(), engine);
53 _peds.shoulderLens = VIPRA::Random::make_distribution<>(
54 std::normal_distribution<VIPRA::f_pnt>{_config.meanShoulderLen,
55 _config.shoulderLenStdDev},
56 _peds.size(), engine);
57 }
58
59 // NOLINTNEXTLINE(bugprone-easily-swappable-parameters, misc-unused-parameters)
60 VIPRA_MODEL_TIMESTEP
61 {
62 calc_shoulders(pedset.all_coords(), goals.current_goals());
63 calc_neighbors(pedset, goals, map);
64 calc_betas();
65 if ( timestep % 100 == 0 ) _collision.race_detection(pedset, goals, _peds);
66
67 update_state(pedset, goals, state, deltaT);
68 }
69
70 private:
71 CALM::ModelData _peds;
72 CALM::ConfigData _config{};
73 CALM::CollisionDetection _collision;
74
75 void calc_neighbors(VIPRA::Modules::Pedestrians const& pedset,
76 VIPRA::Modules::Goals const& goals, VIPRA::Modules::Map const& map);
77 void update_state(VIPRA::Modules::Pedestrians const& pedset,
78 VIPRA::Modules::Goals const& goals, VIPRA::State& state,
79 VIPRA::delta_t deltaT);
80 auto is_path_blocked(VIPRA::idx pedIdx, VIPRA::f3d veloc, VIPRA::f_pnt maxDist,
81 VIPRA::Modules::Map const& map) -> VIPRA::f_pnt;
82
83 void calc_shoulders(VIPRA::f3dVec const&, VIPRA::f3dVec const&);
84 static auto obj_spatial_test(const VIPRA::Geometry::Rectangle&, VIPRA::f3d,
85 VIPRA::f3d) -> bool;
86 static auto obj_direction_test(VIPRA::f3d, VIPRA::f3d, VIPRA::f3d) -> bool;
87 static auto is_ped_toward_goal(VIPRA::f3d, VIPRA::f3d, VIPRA::f3d) -> bool;
88
89 auto rect_from_shoulders(VIPRA::idx, VIPRA::f3d,
91
92 void calc_betas();
93 VIPRA_INLINE static constexpr auto calc_beta(VIPRA::f_pnt distance) -> VIPRA::f_pnt
94 {
95 constexpr VIPRA::f_pnt VAL_A = -2.11;
96 constexpr VIPRA::f_pnt VAL_B = 0.366;
97 constexpr VIPRA::f_pnt VAL_C = 0.966;
98 return (VAL_C - std::exp(VAL_A * (distance - VAL_B)));
99 }
100};
101} // namespace Model
Definition calm_collision.hpp:24
Definition calm_model.hpp:16
Definition rectangle.hpp:20
Goals module mixin.
Definition goals.hpp:26
Base Map Module Class.
Definition map.hpp:23
Base Model module.
Definition model.hpp:16
VIPRA Module Base CRTP Class.
Definition module.hpp:36
Base Pedestrians module.
Definition pedestrians.hpp:35
Definition calm_model_types.hpp:10
Definition calm_model_types.hpp:24
Struct that holds the updated positions and velocities of all pedestrians.
Definition state.hpp:12
Definition f3d.hpp:27