Update board.hpp, forces.hpp, forces.cpp, main.cpp, pedestrian.hpp: correct some bugs in implementation
This commit is contained in:
@@ -4,12 +4,8 @@
|
||||
#include "pedestrian.hpp"
|
||||
#include "vector2d.hpp"
|
||||
|
||||
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,67 +19,58 @@ 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::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++) {
|
||||
Vector2d start_pos = Vector2d(1, y_gen(gen));
|
||||
Vector2d destination = Vector2d(BOARD_LENGTH - 1, y_gen(gen));
|
||||
double desired_v0 = velocity_gen(gen);
|
||||
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++) {
|
||||
Vector2d start_pos = Vector2d(BOARD_LENGTH - 1, y_gen(gen));
|
||||
Vector2d destination = Vector2d(1, y_gen(gen));
|
||||
double desired_v0 = velocity_gen(gen);
|
||||
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[]) {
|
||||
|
||||
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]);
|
||||
|
||||
Pedestrian *pedestrians = init_pedestrians(n_p);
|
||||
|
||||
for (int t = 0; t < n_iter; t++) {
|
||||
|
||||
for (int i = 0; i < n_p; i++) {
|
||||
|
||||
Pedestrian &p = pedestrians[i];
|
||||
|
||||
p.F_i.reset();
|
||||
p.f_i.reset();
|
||||
|
||||
//
|
||||
// $\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);
|
||||
|
||||
//
|
||||
// $\sum_{\beta} \vec{F}_{\alpha\beta}(\vec{e}_{\alpha}, \vec{r}_{\alpha} - \vec{r}_{\beta})$
|
||||
//
|
||||
compute_repulsive_effects_from_pedestrians(pedestrians, &p, n_p);
|
||||
|
||||
//
|
||||
// $\sum_{B} \vec{F}_{\alpha B}(\vec{e}_{\alpha}, \vec{r}_{\alpha} - \vec{r}_{B})$
|
||||
//
|
||||
compute_repulsive_effects_from_borders(B, &p);
|
||||
compute_repulsive_effects_from_borders(board, &p);
|
||||
|
||||
//
|
||||
// $\vec{w}_i = \vec{v}_i + \vec{F}_idt$
|
||||
//
|
||||
p.w_alpha = p.curr_vel + p.F_i * delta_t;
|
||||
Vector2d w_alpha = p.curr_vel + p.f_i * dt;
|
||||
|
||||
//
|
||||
// $\vec{v}_i^{t+1} = \vec{w}_ig(\frac{v^{max}_i}{\Arrowvert \vec{w}_i \Arrowvert}) $
|
||||
//
|
||||
p.next_vel = p.w_alpha * g(p.v_max, p.w_alpha.norm());
|
||||
p.curr_vel = w_alpha * g(p.v_max, w_alpha.norm());
|
||||
|
||||
//
|
||||
// $\vec{r}_i^{t+1} += \vec{r}^t_i + v^t_idt$
|
||||
//
|
||||
p.curr_pos = p.curr_pos + p.curr_vel * delta_t;
|
||||
}
|
||||
p.curr_pos = p.curr_pos + p.curr_vel * dt;
|
||||
|
||||
for (int i = 0; i < n_p; i++) {
|
||||
pedestrians[i].update();
|
||||
p.e = (p.destination - p.curr_pos) / (p.destination - p.curr_pos).norm();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user