Add unit tests, refactor simulation code, improve Makefile, and add documentation

This commit is contained in:
Ahmed Kallala
2026-05-12 22:16:46 +02:00
committed by salijagic
parent ae1c64af05
commit 5713ad7e19
16 changed files with 2486 additions and 825 deletions
+31 -13
View File
@@ -2,10 +2,10 @@
#include "constants.hpp"
#include "vector2d.hpp"
// For visual simulation.
// Black pedestrians move from left to right;
// White pedestrians move from right to left.
enum Color { BLACK, WHITE };
// Needed for visual simulation, in order to distinguish two groups of pedestrians:
// - White pedestrians move from left to right
// - Black pedestrians move from right to left
enum Color { WHITE, BLACK};
struct Pedestrian {
@@ -31,17 +31,35 @@ struct Pedestrian {
// $\vec{r}^0_\alpha$
Vector2d destination;
// social force
Vector2d f_i;
// $s_\beta^2 = (v_\beta \Delta t)^2$
double s_b_sq;
// $s_\beta \vec{e}_\beta$
Vector2d s_b_e;
// $s_\beta \vec{e}_\beta = v_{\beta} \Delta t \vec{e}_{\beta}$
Vector2d s_b_e_b;
// Default constructor: initializes a pedestrian with color WHITE and all vector/scalar fields set to zero.
Pedestrian() : color(WHITE), curr_vel(0.0, 0.0), w(0.0, 0.0), curr_pos(0.0, 0.0), e(0.0, 0.0), v_max(0.0), desired_v0(0.0), destination(0.0, 0.0), s_b_sq(0.0), s_b_e(0.0, 0.0) {}
Pedestrian() : color(WHITE), curr_vel(0.0, 0.0), w(0.0, 0.0), curr_pos(0.0, 0.0), e(0.0, 0.0), v_max(0.0), desired_v0(0.0), destination(0.0, 0.0), f_i(0.0, 0.0), s_b_sq(0.0), s_b_e_b(0.0, 0.0) {}
Pedestrian(Color clr, Vector2d c_v, Vector2d c_p, Vector2d e, double v_max, double desired_v0, Vector2d d, Vector2d f) : color(clr), curr_vel(c_v), w(c_v), curr_pos(c_p), e(e), v_max(v_max), desired_v0(desired_v0), destination(d), f_i(f), s_b_sq(c_v.dot(c_v) * DELTA_T_SQ), s_b_e_b(e * c_v.norm() * DELTA_T) {}
// Constructs a pedestrian with the given initial state and precomputes the
// quantities used in the pedestrian-pedestrian repulsion term.
//
// The preferred velocity w is initialized to the current velocity c_v. The
// cached quantities s_b_sq and s_b_e correspond to the predicted step of this
// pedestrian over $\Delta t$:
//
// s_b = ||c_v|| * dt
// s_b_sq = s_b^2
// s_b_e = e * s_b
//
// These values are used when another pedestrian computes the elliptical
// interaction term involving this pedestrian.
//
// @param clr The display/color category of the pedestrian.
// @param c_v The initial current velocity.
// @param c_p The initial current position.
// @param e The initial desired direction of motion.
// @param v_max The maximum speed that the pedestrian can reach.
// @param desired_v0 The desired walking speed.
// @param d The pedestrian's target destination point.
//
Pedestrian(Color clr, Vector2d c_v, Vector2d c_p, Vector2d e, double v_max, double desired_v0, Vector2d d) : color(clr), curr_vel(c_v), w(c_v), curr_pos(c_p), e(e), v_max(v_max), desired_v0(desired_v0), destination(d), s_b_sq(c_v.dot(c_v) * delta_t_sq), s_b_e(e * c_v.norm() * delta_t) {}
};