VIPRA Documentation
Loading...
Searching...
No Matches
behavior_model.hpp
1#pragma once
2
3#include "vipra/macros/module.hpp"
4
5#include "vipra/macros/parameters.hpp"
6#include "vipra/modules/goals.hpp"
7#include "vipra/modules/module.hpp"
8#include "vipra/modules/pedestrians.hpp"
9
10#include "vipra/types/seed.hpp"
11#include "vipra/util/clock.hpp"
12#include "vipra/util/timing.hpp"
13#include "vipra/vipra_behaviors/attributes/attributes.hpp"
14#include "vipra/vipra_behaviors/behavior/human_behavior.hpp"
15#include "vipra/vipra_behaviors/builder/behavior_builder.hpp"
16
17namespace VIPRA {
22class BehaviorModel : public VIPRA::Modules::Module<BehaviorModel> {
23 public:
24 VIPRA_MODULE_NAME("main");
25 VIPRA_MODULE_TYPE(Behavior_model);
26
27 // NOLINTNEXTLINE(misc-unused-parameters)
28 VIPRA_REGISTER_PARAMS(VIPRA_PARAM("behaviors_dir", _behaviorsDir),
29 VIPRA_PARAM("behaviors", _behaviorNames))
30
31 void initialize(Modules::Pedestrians& pedset, Modules::Map& map, Modules::Goals& goals,
32 VIPRA::seed seed)
33 {
34 // TODO(rolland): figure out why it errors when duplicating behaviors
35
36 _behaviors.clear();
37 Behaviors::AttributeHandling::cleanup();
38
39 build_behaviors(map, seed);
40 for ( auto& behavior : _behaviors ) {
41 behavior.initialize(pedset, map, goals);
42 }
43
44 behaviorTimings.start_new();
45 behaviorTimings.pause();
46 }
47
48 void timestep(Modules::Pedestrians& pedset, Modules::Map& map, Modules::Goals& goals,
49 VIPRA::State& state, VIPRA::delta_t deltaT)
50 {
51 behaviorTimings.resume();
52 for ( auto& behavior : _behaviors ) {
53 behavior.timestep(pedset, map, goals, state, deltaT);
54 }
55 behaviorTimings.pause();
56 }
57
58 private:
59 std::string _behaviorsDir;
60 std::vector<std::string> _behaviorNames;
61 std::vector<Behaviors::HumanBehavior> _behaviors;
62
63 static Util::Timings behaviorTimings;
64
65 void build_behaviors(Modules::Map const& map, VIPRA::seed seed)
66 {
68 std::transform(_behaviorNames.begin(), _behaviorNames.end(),
69 std::back_inserter(_behaviors), [&](auto const& name) {
70 auto const filePath = _behaviorsDir + '/' + (name + ".bhvr");
71 return builder.build(name, filePath, map, seed);
72 });
73 }
74
75 public:
76 BehaviorModel() = default;
77 BehaviorModel(BehaviorModel const&) = default;
78 auto operator=(BehaviorModel const&) -> BehaviorModel& = default;
79 BehaviorModel(BehaviorModel&&) noexcept = default;
80 auto operator=(BehaviorModel&&) noexcept -> BehaviorModel& = default;
81 ~BehaviorModel()
82 {
83 Behaviors::AttributeHandling::cleanup();
84 behaviorTimings.stop();
85 behaviorTimings.output_timings();
86 };
87};
88} // namespace VIPRA
Parses Behavior Files and Creates the Runtime Functionality they describe.
Definition behavior_builder.hpp:45
Goals module mixin.
Definition goals.hpp:26
Base Map Module Class.
Definition map.hpp:23
VIPRA Module Base CRTP Class.
Definition module.hpp:36
Base Pedestrians module.
Definition pedestrians.hpp:35
Definition timing.hpp:122
Struct that holds the updated positions and velocities of all pedestrians.
Definition state.hpp:12