Revert "Merge branch 'smail' into lbaumberger"

This reverts commit 1cf29bfdd8, reversing
changes made to 1b79bd15f4.
This commit is contained in:
lbaumberger
2026-04-27 14:36:20 +02:00
parent d7a8154bbe
commit 5e738642fd
4 changed files with 58 additions and 25 deletions
+7 -8
View File
@@ -1,10 +1,11 @@
#include "forces.hpp"
#include <math.h>
// # Done
// # 8 flops = 5 MULTs, 2 ADD, 1 SQRT
double w(Vector2d e, Vector2d f) {
if (e.dot(f) >= f.norm() * cos_phi)
return 1.0;
else
return c;
}
@@ -26,10 +27,8 @@ void compute_acceleration_term(Pedestrian *p) {
Vector2d desired_velocity = p->e * p->desired_v0;
// $\vec{v}_{\alpha}(t)$
Vector2d actual_velocity = p->curr_vel;
double tau_alpha_inv = 1 / tau_alpha;
p->F_i += (desired_velocity - actual_velocity) * tau_alpha_inv;
// # 6 flops = 4 ADDs, 2 DIVs
p->f_i += (desired_velocity - actual_velocity) / tau_alpha;
}
// # 55(N - 1) = 55N - 55 flops
@@ -102,12 +101,12 @@ void compute_repulsive_effects_from_pedestrians(Pedestrian *pedestrians, Pedestr
// # 48 n_obstacles flops = 192 flops
void compute_repulsive_effects_from_borders(Board &board, Pedestrian *p) {
Vector2d *borders = B.borders;
int n_borders = B.n_borders;
Obstacle *obstacles = board.obstacles;
int n_borders = board.n_obstacles;
for (int i = 0; i < n_borders; i++) {
Vector2d border = borders[i];
Obstacle obstacle = obstacles[i];
// # 17 flops
// $\vec{r}_{\alpha B}$
+2
View File
@@ -37,6 +37,8 @@ const double dt = 0.001;
double w(Vector2d e, Vector2d f);
double g(double v_max_alpha, double w_alpha_norm);
void compute_acceleration_term(Pedestrian *p);
void compute_repulsive_effects_from_pedestrians(Pedestrian *P, Pedestrian *p, int N);
+45 -16
View File
@@ -2,14 +2,15 @@
#include "forces.hpp"
#include "math.h"
#include "pedestrian.hpp"
#include "tsc_x86.h"
#include "vector2d.hpp"
#include <fstream>
#include <iostream>
#include <tuple>
#include <vector>
double g(double v_max_alpha, double w_alpha_norm) {
if (w_alpha_norm <= v_max_alpha) {
return 1;
}
return v_max_alpha / w_alpha_norm;
}
#define BOARD_WIDTH 10.0
#define BOARD_LENGTH 50.0
using namespace std;
@@ -23,20 +24,44 @@ using namespace std;
Pedestrian *init_pedestrians(int n_p) {
Pedestrian *P = new Pedestrian[n_p];
for (int i = 0; i < n_p; i++) {
P[i] = Pedestrian();
std::random_device rd; // use for truly random simulation
// std::mt19937 gen(rd()); // use rd instead of 42 as seed for real randomness
std::mt19937 gen(42); // use fixed seed for reproducibility
std::normal_distribution<double> velocity_gen(1.34, 0.26); // 1.34 and 0.26 are the mean and stdrd deviation used in paper
std::uniform_real_distribution<double> x_gen(2, BOARD_LENGTH - 2);
std::uniform_real_distribution<double> y_gen(2, BOARD_WIDTH - 2);
for (int i = 0; i < n_p / 2; i++) {
double y = y_gen(gen);
Vector2d start_pos = Vector2d(x_gen(gen), y);
Vector2d destination = Vector2d(BOARD_LENGTH + 300, BOARD_WIDTH / 2);
// double desired_v0 = velocity_gen(gen);
double desired_v0;
do {
desired_v0 = velocity_gen(gen);
} while (desired_v0 <= 0.1); // to avoid small values (Way below the social force -> that would make the walk backwards) (we discovered some weird stuff in the simulation)
double v_max = 1.3 * desired_v0;
P[i] = Pedestrian(WHITE, (destination - start_pos) / (destination - start_pos).norm() * desired_v0, start_pos, (destination - start_pos) / (destination - start_pos).norm(), v_max, desired_v0, destination, Vector2d());
}
for (int i = n_p / 2; i < n_p; i++) {
double y = y_gen(gen);
Vector2d start_pos = Vector2d(x_gen(gen), y);
Vector2d destination = Vector2d(-300, BOARD_WIDTH / 2);
// double desired_v0 = velocity_gen(gen);
double desired_v0;
do {
desired_v0 = velocity_gen(gen);
} while (desired_v0 <= 0.1);
double v_max = 1.3 * desired_v0;
P[i] = Pedestrian(BLACK, (destination - start_pos) / (destination - start_pos).norm() * desired_v0, start_pos, (destination - start_pos) / (destination - start_pos).norm(), v_max, desired_v0, destination, Vector2d(0, 0));
}
return P;
}
Board init_board(int width, int length) {
Vector2d obs[] = {Vector2d(2.0, 1.0), Vector2d(4.0, 1.0), Vector2d(6.0, 2.0), Vector2d(6.0, 4.0)};
return Board(width, length, 4, obs);
}
int main(int argc, const char *argv[]) {
Board B = init_board(10, 15);
Obstacle obs[] = {};
Board board = Board(BOARD_LENGTH, BOARD_WIDTH, 0, obs);
int n_p = atoi(argv[1]);
int n_iter = atoi(argv[2]);
@@ -51,13 +76,17 @@ int main(int argc, const char *argv[]) {
Pedestrian *pedestrians = init_pedestrians(n_p);
for (int t = 0; t < n_iter; t++) {
// # Start here or right after function signature
uint64_t start = start_tsc();
// # (8 + 55N - 55 + 192 + 4 + 8 + 4 + 10)*n_p*n_iter
for (int t = 0; t < n_iter; t++) {
// Pass1: conmpute all forces from the current state
for (int i = 0; i < n_p; i++) {
Pedestrian &p = pedestrians[i];
p.F_i.reset();
p.f_i.reset();
// # 8 flops
//
+3
View File
@@ -2,6 +2,9 @@
#include "random"
#include "vector2d.hpp"
// For visual simulation
enum Color { BLACK, WHITE };
struct Pedestrian {
Color color;
// $\vec{v}_{\alpha}(t)$