Merge branch 'linus/restored_simulation' into 'main'
Linus/restored simulation See merge request course-asl-fastcode26/team70!8
This commit is contained in:
+240060
-240060
File diff suppressed because it is too large
Load Diff
+19
-14
@@ -184,7 +184,9 @@ Pedestrian *init_pedestrians(int n_p) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
normal_distribution<double> velocity_gen(v0_mean, v0_std_dev);
|
normal_distribution<double> velocity_gen(v0_mean, v0_std_dev);
|
||||||
uniform_real_distribution<double> y_gen(WALL_EPS, BOARD_WIDTH_MINUS_WALL_EPS);
|
uniform_real_distribution<double> y_gen(0.3, BOARD_WIDTH - 0.3);
|
||||||
|
uniform_real_distribution<double> x_gen_left(2.0, BOARD_LENGTH / 2.0);
|
||||||
|
uniform_real_distribution<double> x_gen_right(BOARD_LENGTH / 2.0, BOARD_LENGTH - 2.0);
|
||||||
|
|
||||||
Pedestrian *P = new Pedestrian[n_p];
|
Pedestrian *P = new Pedestrian[n_p];
|
||||||
|
|
||||||
@@ -192,11 +194,11 @@ Pedestrian *init_pedestrians(int n_p) {
|
|||||||
|
|
||||||
// Group of pedestrians walking from left to right.
|
// Group of pedestrians walking from left to right.
|
||||||
for (int i = 0; i < n_p_half; i++) {
|
for (int i = 0; i < n_p_half; i++) {
|
||||||
double x = 0.0;
|
double x = x_gen_left(gen);
|
||||||
double y = y_gen(gen);
|
double y = y_gen(gen);
|
||||||
|
|
||||||
Vector2d start_pos = Vector2d(x, y);
|
Vector2d start_pos = Vector2d(x, y);
|
||||||
Vector2d destination = Vector2d(BOARD_LENGTH, y);
|
Vector2d destination = Vector2d(BOARD_LENGTH + 30.0, y);
|
||||||
|
|
||||||
Vector2d init_e = destination - start_pos;
|
Vector2d init_e = destination - start_pos;
|
||||||
double init_e_norm = init_e.norm();
|
double init_e_norm = init_e.norm();
|
||||||
@@ -217,11 +219,11 @@ Pedestrian *init_pedestrians(int n_p) {
|
|||||||
|
|
||||||
// Group of pedestrians walking from right to left.
|
// Group of pedestrians walking from right to left.
|
||||||
for (int i = n_p_half; i < n_p; i++) {
|
for (int i = n_p_half; i < n_p; i++) {
|
||||||
double x = BOARD_LENGTH;
|
double x = x_gen_right(gen);
|
||||||
double y = y_gen(gen);
|
double y = y_gen(gen);
|
||||||
|
|
||||||
Vector2d start_pos = Vector2d(x, y);
|
Vector2d start_pos = Vector2d(x, y);
|
||||||
Vector2d destination = Vector2d(0.0, y);
|
Vector2d destination = Vector2d(-30.0, y);
|
||||||
|
|
||||||
Vector2d init_e = destination - start_pos;
|
Vector2d init_e = destination - start_pos;
|
||||||
double init_e_norm = init_e.norm();
|
double init_e_norm = init_e.norm();
|
||||||
@@ -316,7 +318,8 @@ int run_simulation(Pedestrian *pedestrians, Board &board, int n_p, int n_iter, c
|
|||||||
|
|
||||||
// # 1 ADD, 2 MULTs, 1 SQRT
|
// # 1 ADD, 2 MULTs, 1 SQRT
|
||||||
double w_norm = p.w.norm();
|
double w_norm = p.w.norm();
|
||||||
double w_norm2 = w_norm > EPS ? w_norm : EPS; // Avoid division by zero.
|
|
||||||
|
double w_norm2 = w_norm > EPS ? w_norm : EPS; // Avoid division by zero.
|
||||||
|
|
||||||
// # 1 DIV
|
// # 1 DIV
|
||||||
double correction_factor = std::min(1.0, p.v_max / w_norm2);
|
double correction_factor = std::min(1.0, p.v_max / w_norm2);
|
||||||
@@ -334,15 +337,17 @@ int run_simulation(Pedestrian *pedestrians, Board &board, int n_p, int n_iter, c
|
|||||||
// to the opposite entrance while keeping the same y-coordinate. This
|
// to the opposite entrance while keeping the same y-coordinate. This
|
||||||
// maintains a constant pedestrian flow and makes lane formation easier to
|
// maintains a constant pedestrian flow and makes lane formation easier to
|
||||||
// observe.
|
// observe.
|
||||||
if (p.color == WHITE && p.curr_pos.x >= BOARD_LENGTH) {
|
if (p.color == WHITE && p.curr_pos.x > (BOARD_LENGTH - 1.5)) {
|
||||||
p.curr_pos.x = 0.0;
|
p.curr_pos.x = 1.0;
|
||||||
p.w = Vector2d();
|
p.destination.y = p.curr_pos.y;
|
||||||
p.curr_vel = Vector2d();
|
p.w = Vector2d(p.desired_v0, 0.0);
|
||||||
|
p.curr_vel = p.w;
|
||||||
}
|
}
|
||||||
if (p.color == BLACK && p.curr_pos.x <= 0.0) {
|
if (p.color == BLACK && p.curr_pos.x < 1.5) {
|
||||||
p.curr_pos.x = BOARD_LENGTH;
|
p.curr_pos.x = BOARD_LENGTH - 1.0;
|
||||||
p.w = Vector2d();
|
p.destination.y = p.curr_pos.y;
|
||||||
p.curr_vel = Vector2d();
|
p.w = Vector2d(-p.desired_v0, 0.0);
|
||||||
|
p.curr_vel = p.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep pedestrians inside the board boundaries.
|
// Keep pedestrians inside the board boundaries.
|
||||||
|
|||||||
Reference in New Issue
Block a user