added back formula

This commit is contained in:
smail alijagic
2026-04-27 10:48:43 +02:00
parent a83aa654df
commit 2fe93b5c94
11 changed files with 1000154 additions and 1000002 deletions
Vendored
BIN
View File
Binary file not shown.
+18
View File
@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "macos-clang-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "macos-clang-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}
+13
View File
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "lldb",
"request": "launch",
"args": [],
"cwd": "/Users/smailalijagic/Desktop/Universität/26FS/Advanced Systems Lab/team70",
"program": "/Users/smailalijagic/Desktop/Universität/26FS/Advanced Systems Lab/team70/build/Debug/outDebug"
}
]
}
+59
View File
@@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "clang",
"C_Cpp_Runner.cppCompilerPath": "clang++",
"C_Cpp_Runner.debuggerPath": "lldb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}
+34 -1
View File
@@ -18,15 +18,23 @@ double g(double v_max_alpha, double w_alpha_norm) {
} }
// # 8 flops // # 8 flops
//
// $\vec{F}_\alpha(\vec{v}_\alpha, v^0_\alpha \vec{e}_\alpha) \vec{e}_\alpha(t) = \frac{1}{\tau_\alpha}(v^0_\alpha \vec{e}_\alpha - \vec{v}_\alpha)$
//
void compute_acceleration_term(Pedestrian *p) { void compute_acceleration_term(Pedestrian *p) {
// # 2 flops // # 2 flops
// $v_{\alpha}^{0}\vec{e}_{\alpha}$
Vector2d desired_velocity = p->e * p->desired_v0; Vector2d desired_velocity = p->e * p->desired_v0;
// $\vec{v}_{\alpha}(t)$
Vector2d actual_velocity = p->curr_vel; Vector2d actual_velocity = p->curr_vel;
// # 6 flops = 4 ADDs, 2 DIVs // # 6 flops = 4 ADDs, 2 DIVs
p->f_i += (desired_velocity - actual_velocity) / tau_alpha; p->f_i += (desired_velocity - actual_velocity) / tau_alpha;
} }
// # 55(N - 1) = 55N - 55 flops // # 55(N - 1) = 55N - 55 flops
//
// $\sum_{\beta} \vec{F}_{\alpha\beta}(\vec{e}_{\alpha}, \vec{r}_{\alpha} - \vec{r}_{\beta})$
//
void compute_repulsive_effects_from_pedestrians(Pedestrian *pedestrians, Pedestrian *p, int N) { void compute_repulsive_effects_from_pedestrians(Pedestrian *pedestrians, Pedestrian *p, int N) {
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
@@ -41,32 +49,50 @@ void compute_repulsive_effects_from_pedestrians(Pedestrian *pedestrians, Pedestr
// } // }
// # 2 ADDs // # 2 ADDs
// $\vec{r}_{\alpha\beta}$
Vector2d r_ab = p->curr_pos - pedestrians[i].curr_pos; Vector2d r_ab = p->curr_pos - pedestrians[i].curr_pos;
// # 4 flops = 1 SQRT, 2 MULTs, 1 ADD // # 4 flops = 1 SQRT, 2 MULTs, 1 ADD
// $\Arrowvert \vec{r}_{\alpha \beta} \Arrowvert$
double r_ab_norm = r_ab.norm(); double r_ab_norm = r_ab.norm();
// $\vec{e}_{\beta}$
Vector2d e_b = pedestrians[i].e; Vector2d e_b = pedestrians[i].e;
// # 2 MULTs // # 2 MULTs
double s_b = pedestrians[i].desired_v0 * delta_t; // $v_\beta \Delta t$
double s_b = pedestrians[i].curr_vel.norm() * delta_t;
// # 4 flops = 2 ADDs, 2 MULTs // # 4 flops = 2 ADDs, 2 MULTs
// $\vec{r}_{\alpha\beta} - \vec{v}_{\beta}\varDelta_{t}\vec{e}_{\beta}$
Vector2d r_ab2 = r_ab - (e_b * s_b); Vector2d r_ab2 = r_ab - (e_b * s_b);
// # 4 flops = 1 SQRT, 2 MULTs, 1 ADD // # 4 flops = 1 SQRT, 2 MULTs, 1 ADD
// $\Arrowvert \vec{r}_{\alpha \beta} - v_\beta \Delta t \vec{e}_\beta \Arrowvert$
double r_ab2_norm = r_ab2.norm(); double r_ab2_norm = r_ab2.norm();
// # 7 flops = 1 SQRT, 3 ADDs, 2 MULTs, 1 DIV // # 7 flops = 1 SQRT, 3 ADDs, 2 MULTs, 1 DIV
//
// $(4):2b = \sqrt{(\Arrowvert \vec{r}_{\alpha \beta} \Arrowvert + \Arrowvert \vec{r}_{\alpha \beta} - v_\beta \Delta t \vec{e}_\beta \Arrowvert)^2 - (v_\beta \Delta t)^2}$
//
double b = sqrt((r_ab_norm + r_ab2_norm) * (r_ab_norm + r_ab2_norm) - s_b * s_b) / 2; double b = sqrt((r_ab_norm + r_ab2_norm) * (r_ab_norm + r_ab2_norm) - s_b * s_b) / 2;
// # 12 flops = 6 DIVs, 3 ADDs, 3 MULTs // # 12 flops = 6 DIVs, 3 ADDs, 3 MULTs
//
// $(7):\grad_{\vec{r}_{\alpha \beta}}b = \frac{(\Arrowvert \vec{r}_{\alpha \beta} \Arrowvert + \Arrowvert \vec{r}_{\alpha \beta} - v_\beta \Delta t \vec{e}_\beta \Arrowvert) (\frac{\vec{r}_{\alpha \beta}}{\Arrowvert \vec{r}_{\alpha \beta} \Arrowvert} + \frac{\vec{r}_{\alpha \beta} - v_\beta \Delta t \vec{e}_\beta}{\Arrowvert \vec{r}_{\alpha \beta} - v_\beta \Delta t \vec{e}_\beta \Arrowvert})}{4b}$
//
Vector2d b_grad = (r_ab / r_ab_norm + r_ab2 / r_ab2_norm) * (r_ab_norm + r_ab2_norm) / (4 * b); Vector2d b_grad = (r_ab / r_ab_norm + r_ab2 / r_ab2_norm) * (r_ab_norm + r_ab2_norm) / (4 * b);
// # 6 flops = 3 MULTs, 2 DIVs, 1 EXP // # 6 flops = 3 MULTs, 2 DIVs, 1 EXP
//
// $(5):\vec{f}_{\alpha \beta}(\vec{r}_{\alpha \beta}) = \frac{V^0_{\alpha \beta}}{\sigma}e^{-b / \sigma} \grad_{\vec{r}_{\alpha \beta}}b$
//
Vector2d f_ped = b_grad * ((V0_AB / SIGMA) * (exp(-b / SIGMA))); Vector2d f_ped = b_grad * ((V0_AB / SIGMA) * (exp(-b / SIGMA)));
// # 14 flops: 9 MULTs, 4 ADDs, 1 SQRT // # 14 flops: 9 MULTs, 4 ADDs, 1 SQRT
//
// $(11):\vec{F}_{\alpha\beta}(\vec{e}_{\alpha}, \vec{r}_{\alpha} - \vec{r}_{\beta}) = w(\vec{e}_{\alpha}, -\vec{f}_{\alpha\beta})\vec{f}_{\alpha\beta}(\vec{r}_{\alpha} - \vec{r}_{\beta})$
//
p->f_i += f_ped * w(p->e, f_ped * -1); p->f_i += f_ped * w(p->e, f_ped * -1);
} }
} }
@@ -83,9 +109,13 @@ void compute_repulsive_effects_from_borders(Board &board, Pedestrian *p) {
Obstacle obstacle = obstacles[i]; Obstacle obstacle = obstacles[i];
// # 17 flops // # 17 flops
// $\vec{r}_{\alpha B}$
Vector2d r_aB = p->curr_pos - obstacle.find_nearest_obstacle_point(p->curr_pos); Vector2d r_aB = p->curr_pos - obstacle.find_nearest_obstacle_point(p->curr_pos);
// # 17 flops = 2 DIVs, 1 SQRT, 2 MULTs, 1 ADD, 2 MULTs, 1 DIV, 2 MULTs, 1 EXP, 1 SQRT, 2 MULTs, 1 ADD, 1 DIV // # 17 flops = 2 DIVs, 1 SQRT, 2 MULTs, 1 ADD, 2 MULTs, 1 DIV, 2 MULTs, 1 EXP, 1 SQRT, 2 MULTs, 1 ADD, 1 DIV
//
// $\vec{F}_{\alpha B}(\vec{r}_{\alpha B}) = \frac{U^0_{\alpha B}}{R} e^{- \Arrowvert \vec{r}_{\alpha B} \Arrowvert / R} \frac{\vec{r}_{\alpha B}}{\Arrowvert \vec{r}_{\alpha B} \Arrowvert}$
//
Vector2d f_obst = (r_aB / r_aB.norm()) * (U0_AB / R) * std::exp(-r_aB.norm() / R); Vector2d f_obst = (r_aB / r_aB.norm()) * (U0_AB / R) * std::exp(-r_aB.norm() / R);
// # 2 ADDs // # 2 ADDs
@@ -95,6 +125,9 @@ void compute_repulsive_effects_from_borders(Board &board, Pedestrian *p) {
// However, the formulas above for attractive and repulsive effects only hold for situations that are perceived in the desired direction e_alpha(t) of motion. // However, the formulas above for attractive and repulsive effects only hold for situations that are perceived in the desired direction e_alpha(t) of motion.
// I assumed that with formulas above its also meant for equation 8 (even though not explicitly mentioned their) // I assumed that with formulas above its also meant for equation 8 (even though not explicitly mentioned their)
// # 14 flops: 9 MULTs, 4 ADDS, 1 SQRT // # 14 flops: 9 MULTs, 4 ADDS, 1 SQRT
//
// $(12):\vec{F}_{\alpha B}(\vec{e}_{\alpha}, \vec{r}_{\alpha} - \vec{r}_{ B}) = w(\vec{e}_{\alpha}, -\vec{F}_{\alpha B})\vec{F}_{\alpha B}(\vec{r}_{\alpha} - \vec{r}_{ B})$
//
p->f_i += f_obst * w(p->e, f_obst * -1); p->f_i += f_obst * w(p->e, f_obst * -1);
} }
} }
+10 -1
View File
@@ -3,25 +3,34 @@
#include "pedestrian.hpp" #include "pedestrian.hpp"
#include <cmath> #include <cmath>
// $\tau_{\alpha}$
const double tau_alpha = 0.5; const double tau_alpha = 0.5;
// $V^0_{\alpha \beta}$
const double V0_AB = 2.1; const double V0_AB = 2.1;
// $\sigma$
const double SIGMA = 0.3; const double SIGMA = 0.3;
// $U^0_{\alpha B}$
const double U0_AB = 10.0; const double U0_AB = 10.0;
// $R$
const double R = 0.2; const double R = 0.2;
// $c$
const double c = 0.5; const double c = 0.5;
// $\varphi$
const double phi = 100.0 / 180.0 * M_PI; const double phi = 100.0 / 180.0 * M_PI;
const double cos_phi = cos(phi); const double cos_phi = cos(phi);
// $\varDelta_{t}$
// step size = 0.2 seconds
const double delta_t = 2; const double delta_t = 2;
const double dt = 0.01; const double dt = 0.001;
// # Optional (forces.cpp: compute_repulsive_effects_from_pedestrians) // # Optional (forces.cpp: compute_repulsive_effects_from_pedestrians)
// const double DISTANCE = 2.0; // const double DISTANCE = 2.0;
+13 -1
View File
@@ -67,7 +67,7 @@ int main(int argc, const char *argv[]) {
int n_iter = atoi(argv[2]); int n_iter = atoi(argv[2]);
// Logic to get/dump the simulation data // Logic to get/dump the simulation data
const int dump_interval = 5; // dump every 5 iterations -> 20 fps (since dt = 0.01) const int dump_interval = 50; // dump every 5 iterations -> 20 fps (since dt = 0.01)
const char *dump_path = (argc >= 4) ? argv[3] : nullptr; const char *dump_path = (argc >= 4) ? argv[3] : nullptr;
std::vector<std::tuple<int, int, double, double, int>> samples; // t, id, x, y, color std::vector<std::tuple<int, int, double, double, int>> samples; // t, id, x, y, color
@@ -89,12 +89,21 @@ int main(int argc, const char *argv[]) {
p.f_i.reset(); p.f_i.reset();
// # 8 flops // # 8 flops
//
// $\vec{F}_\alpha(\vec{v}_\alpha, v^0_\alpha \vec{e}_\alpha) \vec{e}_\alpha(t) = \frac{1}{\tau_\alpha}(v^0_\alpha \vec{e}_\alpha - \vec{v}_\alpha)$
//
compute_acceleration_term(&p); compute_acceleration_term(&p);
// # 55N - 55 flops // # 55N - 55 flops
//
// $\sum_{\beta} \vec{F}_{\alpha\beta}(\vec{e}_{\alpha}, \vec{r}_{\alpha} - \vec{r}_{\beta})$
//
compute_repulsive_effects_from_pedestrians(pedestrians, &p, n_p); compute_repulsive_effects_from_pedestrians(pedestrians, &p, n_p);
// # 192 flops // # 192 flops
//
// $\sum_{B} \vec{F}_{\alpha B}(\vec{e}_{\alpha}, \vec{r}_{\alpha} - \vec{r}_{B})$
//
compute_repulsive_effects_from_borders(board, &p); compute_repulsive_effects_from_borders(board, &p);
} }
// Pass2: integrate the forces and update the current state // Pass2: integrate the forces and update the current state
@@ -109,6 +118,9 @@ int main(int argc, const char *argv[]) {
p.curr_vel = p.w * g(p.v_max, p.w.norm()); p.curr_vel = p.w * g(p.v_max, p.w.norm());
// # 4 flops = 2 ADDs, 2 MULTs // # 4 flops = 2 ADDs, 2 MULTs
//
// $\vec{r}_i^{t+1} += \vec{r}^t_i + v^t_idt$
//
p.curr_pos = p.curr_pos + p.curr_vel * dt; p.curr_pos = p.curr_pos + p.curr_vel * dt;
// how to handle if a pedestrian reached the end of our simulation/end of the hallway // how to handle if a pedestrian reached the end of our simulation/end of the hallway
Regular → Executable
BIN
View File
Binary file not shown.
+8
View File
@@ -7,13 +7,21 @@ enum Color { BLACK, WHITE };
struct Pedestrian { struct Pedestrian {
Color color; Color color;
// $\vec{v}_{\alpha}(t)$
Vector2d curr_vel; // v_alpha (actual, ≤ v_max) Vector2d curr_vel; // v_alpha (actual, ≤ v_max)
// $\vec{w}_{\alpha}$
Vector2d w; // w_alpha (preferred, integrates force) Vector2d w; // w_alpha (preferred, integrates force)
// $\vec{r}_\alpha(t)$
Vector2d curr_pos; Vector2d curr_pos;
// $\vec{e}_{\alpha}(t)$
Vector2d e; Vector2d e;
// $v_{\alpha}^{max} = 1.3 v^{0}_{\alpha}$
double v_max; double v_max;
// $v_\alpha^0$
double desired_v0; double desired_v0;
// $\vec{r}^0_\alpha$
Vector2d destination; Vector2d destination;
// social force
Vector2d f_i; Vector2d f_i;
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) {} 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) {}
+999999 -999999
View File
File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.