VIPRA Documentation
Loading...
Searching...
No Matches
human_behavior.hpp
1#pragma once
2
3#include <algorithm>
4#include <vector>
5#include "vipra/geometry/polygon.hpp"
6#include "vipra/geometry/rectangle.hpp"
7#include "vipra/modules/goals.hpp"
8#include "vipra/modules/map.hpp"
9#include "vipra/modules/pedestrians.hpp"
10#include "vipra/vipra_behaviors/actions/action.hpp"
11#include "vipra/vipra_behaviors/definitions/behavior_context.hpp"
12#include "vipra/vipra_behaviors/definitions/sim_pack.hpp"
13#include "vipra/vipra_behaviors/events/event.hpp"
14#include "vipra/vipra_behaviors/locations/location.hpp"
15#include "vipra/vipra_behaviors/selectors/selector.hpp"
16#include "vipra/vipra_behaviors/targets/target.hpp"
17
18namespace VIPRA::Behaviors {
22class HumanBehavior {
23 DEFAULT_CONSTRUCTIBLE(HumanBehavior)
24 COPYABLE(HumanBehavior)
25 MOVEABLE(HumanBehavior)
26
27 public:
28 explicit HumanBehavior(std::string behaviorName)
29 : _name(std::move(behaviorName)), _context()
30 {
31 }
32
33 void initialize(Modules::Pedestrians const& pedset, Modules::Map const& map,
34 Modules::Goals& goals);
36 VIPRA::State& state, VIPRA::delta_t deltaT);
37
38 void set_all_ped_types(Ptype types)
39 {
40 _selector.set_all_types(types);
41 _actions.resize(types.type_count() + 1);
42 }
43 void add_sub_selector(auto const& subSelector)
44 {
45 _selector.add_sub_selector(subSelector);
46 }
47 void add_action(typeUID type, auto const& action)
48 {
49 _actions[type].emplace_back(action);
50 }
51 auto add_event(Event const& evnt) -> VIPRA::idx
52 {
53 _context.events.push_back(evnt);
54 return _context.events.size() - 1;
55 }
56 auto add_location(Location const& loc) -> VIPRA::idx
57 {
58 _context.locations.emplace_back(loc);
59 return _context.locations.size() - 1;
60 }
61
62 void add_objectives(std::string const& name,
63 std::vector<Geometry::Polygon> const& locations)
64 {
65 std::vector<Geometry::Rectangle> locs(locations.size());
66
67 std::transform(
68 locations.begin(), locations.end(), locs.begin(),
69 [](auto const& poly) { return Geometry::Rectangle{poly.bounding_box()}; });
70
71 _context.objectives[name] = std::move(locs);
72 }
73
74 [[nodiscard]] auto get_name() const noexcept -> std::string const& { return _name; }
75 [[nodiscard]] auto event_count() const noexcept -> VIPRA::size
76 {
77 return _context.events.size();
78 }
79 [[nodiscard]] auto location_count() const noexcept -> VIPRA::size
80 {
81 return _context.locations.size();
82 }
83 [[nodiscard]] auto selector_count() noexcept -> VIPRA::size
84 {
85 return _selector.selector_count();
86 }
87 [[nodiscard]] auto action_count() const noexcept -> VIPRA::size
88 {
89 return std::accumulate(
90 _actions.begin(), _actions.end(), 0,
91 [](VIPRA::size sum, auto const& group) { return sum + group.size(); });
92 }
93
94 void set_seed(VIPRA::seed seed) { _seedNum = seed; }
95
96 private:
97 VIPRA::seed _seedNum{};
98
99 std::string _name;
100 BehaviorContext _context;
101
102 Selector _selector;
103 std::vector<std::vector<Action>> _actions;
104 std::vector<bool> _conditionMet;
105 std::vector<Target> _targets;
106
107 void evaluate_events(Modules::Pedestrians& pedset, Modules::Map& map,
108 Modules::Goals& goals, VIPRA::delta_t deltaT);
109 void apply_actions(Modules::Pedestrians& pedset, Modules::Map& map,
110 Modules::Goals& goals, VIPRA::State& state, VIPRA::delta_t deltaT);
111};
112
113} // namespace VIPRA::Behaviors
An Event is something that occurs during a simulation, when an event starts it notifies it's subscrib...
Definition event.hpp:19
void initialize(Modules::Pedestrians const &pedset, Modules::Map const &map, Modules::Goals &goals)
initializes behavior selector
Definition human_behavior.cpp:13
void timestep(Modules::Pedestrians &pedset, Modules::Map &map, Modules::Goals &goals, VIPRA::State &state, VIPRA::delta_t deltaT)
Evaluates behavior events, and performs actions of pedestrians.
Definition human_behavior.cpp:51
Pedestrian Type, used as a composite of typeUIDs.
Definition pedestrian_types.hpp:23
constexpr auto type_count() const -> VIPRA::size
Returns the number of different types, excluding the base type (0)
Definition pedestrian_types.hpp:38
Combines/Organizes SubSelectors to select pedestrians for types.
Definition selector.hpp:16
Goals module mixin.
Definition goals.hpp:26
Base Map Module Class.
Definition map.hpp:23
Base Pedestrians module.
Definition pedestrians.hpp:35
The context in which a simulation is run. This includes the elapsed time, the random number generator...
Definition behavior_context.hpp:24
Struct that holds the updated positions and velocities of all pedestrians.
Definition state.hpp:12