Utopia  2
Framework for studying models of complex & adaptive systems.
state.hh
Go to the documentation of this file.
1 #ifndef UTOPIA_MODELS_SIMPLEFLOCKING_STATE_HH
2 #define UTOPIA_MODELS_SIMPLEFLOCKING_STATE_HH
3 
4 #include <cmath>
5 #include <random>
6 
7 #include <utopia/core/types.hh>
8 
9 #include "utils.hh"
10 
11 
13 
15 class AgentState {
17  double speed;
18 
20 
23  double orientation;
24 
27 
28 public:
31  :
32  speed(0.)
33  , orientation(0.)
34  , displacement({0., 0.})
35  {}
36 
38  template<typename RNGType>
39  AgentState(const Config& cfg, const std::shared_ptr<RNGType>& rng)
40  :
41  speed(get_as<double>("speed", cfg, 0.))
43  , displacement({0., 0.})
44  {
46  }
47 
48  // .. Getters .............................................................
49 
51  auto get_speed () const {
52  return speed;
53  }
54 
56 
59  auto get_orientation () const {
60  return orientation;
61  }
62 
64  const auto& get_displacement () const {
65  return displacement;
66  }
67 
68  // .. Setters .............................................................
69 
71  auto set_speed (double new_speed) {
72  speed = new_speed;
74  }
75 
77 
79  auto set_orientation (double new_orientation) {
80  orientation = constrain_angle(new_orientation);
82  }
83 
84 protected:
85  // .. Helpers .............................................................
86 
89  displacement[0] = speed * std::cos(orientation);
90  displacement[1] = speed * std::sin(orientation);
91  }
92 };
93 
94 
95 } // namespace Utopia::Models::SimpleFlocking
96 
97 #endif // UTOPIA_MODELS_SIMPLEFLOCKING_STATE_HH
An agent's state.
Definition: state.hh:15
auto get_speed() const
Returns the current speed of this agent.
Definition: state.hh:51
auto get_orientation() const
Returns the current orientation in radians, [-π, +π)
Definition: state.hh:59
SpaceVecType< 2 > displacement
The current displacement vector, updated upon any changes.
Definition: state.hh:26
double orientation
Orientation in radians, [-π, +π)
Definition: state.hh:23
void update_displacement()
Updates the displacement vector using current speed and orientation.
Definition: state.hh:88
double speed
Agent speed.
Definition: state.hh:17
AgentState(const Config &cfg, const std::shared_ptr< RNGType > &rng)
Constructor with config node and RNG.
Definition: state.hh:39
AgentState()
Default constructor with zero-initialized members.
Definition: state.hh:30
auto set_orientation(double new_orientation)
Sets the orientation and subsequently updates the displacement vector.
Definition: state.hh:79
const auto & get_displacement() const
The current value of the displacement vector.
Definition: state.hh:64
auto set_speed(double new_speed)
Sets the speed and subsequently updates the displacement vector.
Definition: state.hh:71
ReturnType get_as(const std::string &key, const DataIO::Config &node)
This function is a wrapper around the yaml-cpp YAML::Node::as function.
Definition: cfg_utils.hh:158
std::mt19937 rng
– Type definitions ----------------------------------------------------—
Definition: test_revision.cc:17
Definition: SimpleFlocking.hh:15
T random_angle(const std::shared_ptr< RNG > &rng)
Returns a uniformly random angle value in [-π, +π)
Definition: utils.hh:26
T constrain_angle(T angle)
Constrains an angle value to interval [-π, +π)
Definition: utils.hh:32
DataIO::Config Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition: types.hh:80
arma::Col< double >::fixed< dim > SpaceVecType
Type for vector-like data that is associated with a physical space.
Definition: types.hh:61