Update file main.cpp

This commit is contained in:
Nguyen Quy Anh
2026-03-13 15:39:52 +01:00
parent 145f25b87c
commit 5d43ef05bc
+77 -79
View File
@@ -6,102 +6,100 @@ using namespace std;
struct Vector2d { struct Vector2d {
double x, y; double x, y;
Vector2d(double a, double b) : x(a), y(b) {} Vector2d(double a, double b) : x(a), y(b) {}
Vector2d() : x(.0), y(.0) {} Vector2d() : x(.0), y(.0) {}
Vector2d operator+(Vector2d v) const { return Vector2d(v.x + x, v.y + y); } Vector2d operator+(Vector2d v) const { return Vector2d(v.x + x, v.y + y); }
Vector2d operator-(Vector2d v) const { return Vector2d(x - v.x, y - v.y); } Vector2d operator-(Vector2d v) const { return Vector2d(x - v.x, y - v.y); }
Vector2d operator-(double a) const { return Vector2d(x - a, y - a); } Vector2d operator-(double a) const { return Vector2d(x - a, y - a); }
Vector2d operator+(double a) const { return Vector2d(x + a, y + a); } Vector2d operator+(double a) const { return Vector2d(x + a, y + a); }
Vector2d operator/(double a) const { return Vector2d(x / a, y / a); } Vector2d operator/(double a) const { return Vector2d(x / a, y / a); }
Vector2d operator*(double a) const { return Vector2d(x * a, y * a); } Vector2d operator*(double a) const { return Vector2d(x * a, y * a); }
Vector2d operator+=(const Vector2d &v) { Vector2d operator+=(const Vector2d &v) {
*this = *this + v; *this = *this + v;
return *this; return *this;
} }
double norm() { return sqrt(x * x + y * y); } double norm() { return sqrt(x * x + y * y); }
double dot(Vector2d v) { return x * v.x + y * v.y; } double dot(Vector2d v) { return x * v.x + y * v.y; }
void reset() { void reset() {
x = 0; x = 0;
y = 0; y = 0;
} }
}; };
// Numer of pedestrians // Numer of pedestrians
// $n_p$ // $n_p$
const int n_p = 100; const int n_p = 100;
// Number of iterations // Number of iterations
// $n_{iter}$ // $n_{iter}$
const int n_iter = 100; const int n_iter = 100;
// TODO: Change this // TODO: Change this
// $\tau$ // $\tau$
const double tau = 0.12345; const double tau = 0.12345;
void compute_acceleration_term(Vector2d *F_i) {} void compute_acceleration_term(Vector2d *F_i) {}
void compute_repulsive_effects_from_pedestrians(Vector2d *F_i) {} void compute_repulsive_effects_from_pedestrians(Vector2d *F_i) {}
void compute_repulsive_effects_from_borders(Vector2d *F_i) {} void compute_repulsive_effects_from_borders(Vector2d *F_i) {}
// Return an array of doubles // Return an array of doubles
double *w(Vector2d e, Vector2d f) { double *w(Vector2d e, Vector2d f) {
// TODO: // TODO:
// $cos(60\degree)$ // $cos(60\degree)$
// if (e * f > f.norm() * (0.5)) { // if (e * f > f.norm() * (0.5)) {
// } // }
// return 0; // return 0;
} }
int main() { int main() {
// ! DONT TOUCH // ! DONT TOUCH
// $\vec{v}^0_i$ // $\vec{v}^0_i$
// Velocity at iteration $t$ for pedestrian $i$ // Velocity at iteration $t$ for pedestrian $i$
double v[n_iter][n_p]; double v[n_iter][n_p];
// $\vec{r}^0_i$ // $\vec{r}^0_i$
// Intended destination at iteration $t$ for pedestrian $i$ // Intended destination at iteration $t$ for pedestrian $i$
Vector2d r[n_iter][n_p]; Vector2d r[n_iter][n_p];
// $\vec{e}_i$ // $\vec{e}_i$
// Desired direction to the next way point at iteration $t$ for pedestrian $i$ // Desired direction to the next way point at iteration $t$ for pedestrian $i$
Vector2d e[n_iter][n_p]; Vector2d e[n_iter][n_p];
// $v_i^{max}$ // $v_i^{max}$
// Maximum allowed speed for pedestrian $i$ // Maximum allowed speed for pedestrian $i$
double v_max[n_p]; double v_max[n_p];
// $v_i^{0}$ // $v_i^{0}$
// Desired speed for pedestrian $i$ // Desired speed for pedestrian $i$
double v_0[n_p]; double v_0[n_p];
// $\vec{F}_i$ // $\vec{F}_i$
// Total social force for pedestrian $i$ // Total social force for pedestrian $i$
Vector2d F[n_p][n_p]; Vector2d F[n_p][n_p];
// $\vec{r}_0$ // $\vec{r}_0$
// Desired destination of pedestrian $n_p$ // Desired destination of pedestrian $n_p$
Vector2d r_0[n_p]; Vector2d r_0[n_p];
for (int t = 0; t < n_iter; t++) { for (int t = 0; t < n_iter; t++) {
for (int i = 0; i < n_p; i++) { for (int i = 0; i < n_p; i++) {
for (int itr = 0; itr < n_p; itr++) { for (int itr = 0; itr < n_p; itr++) {
F[i][itr].reset(); F[i][itr].reset();
} }
compute_acceleration_term(F[i]); compute_acceleration_term(F[i]);
compute_repulsive_effects_from_pedestrians(F[i]); compute_repulsive_effects_from_pedestrians(F[i]);
compute_repulsive_effects_from_borders(F[i]); compute_repulsive_effects_from_borders(F[i]);
// TODO: Update $\vec{w}_i$ // TODO: Update $\vec{w}_i$
// TODO: Update $\vec{v}_i^{t+1}$ // TODO: Update $\vec{v}_i^{t+1}$
// TODO: pdate $\vec{r}_i^{t+1}$
}
}
return 0;
}
// TODO: pdate $\vec{r}_i^{t+1}$
}
}
return 0;
}