Files
263-0007-00L-Advanced-Syste…/variants/variant_float_inlining_SoA_symmetry_ILP_8.cpp
Ahmed Kallala 816626664c Ahmed moreilp
2026-06-17 03:01:19 +02:00

913 lines
41 KiB
C++

// # Changes: Added ILP for j-loop with K = 8
// # Predecessor: variant_float_inlining_SoA_symmetry_ILP_4.cpp
#include "../headers/board_reduced_float.hpp"
#include "../headers/constants_float.hpp"
#include "../headers/pedestrian_reduced_float.hpp"
#include <fstream>
#include <random>
#include <algorithm>
#define SEED 42
#define BOARD_WIDTH 10.0f
#define BOARD_LENGTH 50.0f
#define WALL_EPS 1e-3f
#define BOARD_WIDTH_MINUS_WALL_EPS 9.999f
#ifndef RANDOM_SEED
#define RANDOM_SEED 0
#endif
#ifndef BENCHMARK
#define BENCHMARK 0
#endif
using namespace std;
vector<float> pos_x, pos_y;
vector<float> sb_sq;
vector<float> sb_e_x, sb_e_y;
vector<float> e_x, e_y;
vector<float> curr_vel_x, curr_vel_y;
vector<float> w_x, w_y;
vector<float> desired_v0;
vector<float> v_max;
vector<float> destination_x, destination_y;
vector<int> color;
Pedestrian *init_pedestrians(int n_p) {
#if RANDOM_SEED
random_device rd;
mt19937 gen(rd());
#else
mt19937 gen(SEED);
#endif
normal_distribution<float> velocity_gen(v0_mean, v0_std_dev);
uniform_real_distribution<float> y_gen(0.3, BOARD_WIDTH - 0.3);
uniform_real_distribution<float> x_gen_left(2.0, BOARD_LENGTH / 2.0);
uniform_real_distribution<float> x_gen_right(BOARD_LENGTH / 2.0, BOARD_LENGTH - 2.0);
pos_x.resize(n_p);
pos_y.resize(n_p);
sb_sq.resize(n_p);
sb_e_x.resize(n_p);
sb_e_y.resize(n_p);
e_x.resize(n_p);
e_y.resize(n_p);
curr_vel_x.resize(n_p);
curr_vel_y.resize(n_p);
w_x.resize(n_p);
w_y.resize(n_p);
desired_v0.resize(n_p);
v_max.resize(n_p);
destination_x.resize(n_p);
destination_y.resize(n_p);
color.resize(n_p);
int n_p_half = n_p / 2;
for (int i = 0; i < n_p_half; i++) {
float x = x_gen_left(gen);
float y = y_gen(gen);
float dest_x = BOARD_LENGTH + 30.0;
float dest_y = y;
float init_e_x = dest_x - x;
float init_e_y = dest_y - y;
float init_e_norm = sqrt(init_e_x * init_e_x + init_e_y * init_e_y);
float init_e_unit_x = init_e_x / init_e_norm;
float init_e_unit_y = init_e_y / init_e_norm;
float d_v0;
do {
d_v0 = velocity_gen(gen);
} while (d_v0 <= 0.1);
float v_m = 1.3 * d_v0;
color[i] = 0;
pos_x[i] = x;
pos_y[i] = y;
e_x[i] = init_e_unit_x;
e_y[i] = init_e_unit_y;
v_max[i] = v_m;
desired_v0[i] = d_v0;
destination_x[i] = dest_x;
destination_y[i] = dest_y;
w_x[i] = 0.0f;
w_y[i] = 0.0f;
curr_vel_x[i] = 0.0f;
curr_vel_y[i] = 0.0f;
sb_sq[i] = 0.0f;
sb_e_x[i] = 0.0f;
sb_e_y[i] = 0.0f;
}
for (int i = n_p_half; i < n_p; i++) {
float x = x_gen_right(gen);
float y = y_gen(gen);
float dest_x = -30;
float dest_y = y;
float init_e_x = dest_x - x;
float init_e_y = dest_y - y;
float init_e_norm = sqrt(init_e_x * init_e_x + init_e_y * init_e_y);
float init_e_unit_x = init_e_x / init_e_norm;
float init_e_unit_y = init_e_y / init_e_norm;
float d_v0;
do {
d_v0 = velocity_gen(gen);
} while (d_v0 <= 0.1);
float v_m = 1.3 * d_v0;
color[i] = 1;
pos_x[i] = x;
pos_y[i] = y;
e_x[i] = init_e_unit_x;
e_y[i] = init_e_unit_y;
v_max[i] = v_m;
desired_v0[i] = d_v0;
destination_x[i] = dest_x;
destination_y[i] = dest_y;
w_x[i] = 0.0f;
w_y[i] = 0.0f;
curr_vel_x[i] = 0.0f;
curr_vel_y[i] = 0.0f;
sb_sq[i] = 0.0f;
sb_e_x[i] = 0.0f;
sb_e_y[i] = 0.0f;
}
return nullptr;
}
Board init_board_without_obstacles() { return Board(BOARD_LENGTH, BOARD_WIDTH, 0, nullptr); }
int run_simulation(Pedestrian *pedestrians, Board &board, int n_p, int n_iter, const char *dump_path) {
(void)pedestrians;
#if BENCHMARK
(void)dump_path;
#endif
#if !BENCHMARK
const int dump_interval = 1;
vector<tuple<int, int, float, float, float, float, int>> samples;
if (dump_path) {
samples.reserve(static_cast<size_t>(n_iter / dump_interval + 1) * n_p);
for (int i = 0; i < n_p; i++) {
samples.emplace_back(0, i, pos_x[i], pos_y[i], e_x[i], e_y[i], color[i]);
}
}
#endif
vector<float> r_ab_x_lut(n_p * n_p, 0.0);
vector<float> r_ab_y_lut(n_p * n_p, 0.0);
vector<float> r_ab_norm_lut(n_p * n_p, 0.0);
for (int t = 0; t < n_iter; t++) {
for (int i = 0; i < n_p; i++) {
float desired_velocity_x = e_x[i] * desired_v0[i];
float desired_velocity_y = e_y[i] * desired_v0[i];
float f_alpha_dt_x = (desired_velocity_x - curr_vel_x[i]) * dt_times_tau_alpha_inv;
float f_alpha_dt_y = (desired_velocity_y - curr_vel_y[i]) * dt_times_tau_alpha_inv;
float e_x_i = e_x[i];
float e_y_i = e_y[i];
float pos_x_i = pos_x[i];
float pos_y_i = pos_y[i];
for (int j = i + 1; j < n_p; j++) {
float dx = pos_x_i - pos_x[j];
float dy = pos_y_i - pos_y[j];
float norm = sqrt(dx * dx + dy * dy);
int idx = i * n_p + j;
r_ab_x_lut[idx] = dx;
r_ab_y_lut[idx] = dy;
r_ab_norm_lut[idx] = norm;
}
int j;
float acc_x_0 = 0.0f, acc_x_1 = 0.0f, acc_x_2 = 0.0f, acc_x_3 = 0.0f;
float acc_x_4 = 0.0f, acc_x_5 = 0.0f, acc_x_6 = 0.0f, acc_x_7 = 0.0f;
float acc_y_0 = 0.0f, acc_y_1 = 0.0f, acc_y_2 = 0.0f, acc_y_3 = 0.0f;
float acc_y_4 = 0.0f, acc_y_5 = 0.0f, acc_y_6 = 0.0f, acc_y_7 = 0.0f;
for (j = 0; j + 8 < i; j += 8) {
float r_ab_x_0 = -1 * r_ab_x_lut[j * n_p + i];
float r_ab_x_1 = -1 * r_ab_x_lut[(j + 1) * n_p + i];
float r_ab_x_2 = -1 * r_ab_x_lut[(j + 2) * n_p + i];
float r_ab_x_3 = -1 * r_ab_x_lut[(j + 3) * n_p + i];
float r_ab_x_4 = -1 * r_ab_x_lut[(j + 4) * n_p + i];
float r_ab_x_5 = -1 * r_ab_x_lut[(j + 5) * n_p + i];
float r_ab_x_6 = -1 * r_ab_x_lut[(j + 6) * n_p + i];
float r_ab_x_7 = -1 * r_ab_x_lut[(j + 7) * n_p + i];
float r_ab_y_0 = -1 * r_ab_y_lut[j * n_p + i];
float r_ab_y_1 = -1 * r_ab_y_lut[(j + 1) * n_p + i];
float r_ab_y_2 = -1 * r_ab_y_lut[(j + 2) * n_p + i];
float r_ab_y_3 = -1 * r_ab_y_lut[(j + 3) * n_p + i];
float r_ab_y_4 = -1 * r_ab_y_lut[(j + 4) * n_p + i];
float r_ab_y_5 = -1 * r_ab_y_lut[(j + 5) * n_p + i];
float r_ab_y_6 = -1 * r_ab_y_lut[(j + 6) * n_p + i];
float r_ab_y_7 = -1 * r_ab_y_lut[(j + 7) * n_p + i];
float r_ab_norm_0 = r_ab_norm_lut[j * n_p + i];
float r_ab_norm_1 = r_ab_norm_lut[(j + 1) * n_p + i];
float r_ab_norm_2 = r_ab_norm_lut[(j + 2) * n_p + i];
float r_ab_norm_3 = r_ab_norm_lut[(j + 3) * n_p + i];
float r_ab_norm_4 = r_ab_norm_lut[(j + 4) * n_p + i];
float r_ab_norm_5 = r_ab_norm_lut[(j + 5) * n_p + i];
float r_ab_norm_6 = r_ab_norm_lut[(j + 6) * n_p + i];
float r_ab_norm_7 = r_ab_norm_lut[(j + 7) * n_p + i];
r_ab_norm_0 = r_ab_norm_0 > EPS ? r_ab_norm_0 : EPS;
r_ab_norm_1 = r_ab_norm_1 > EPS ? r_ab_norm_1 : EPS;
r_ab_norm_2 = r_ab_norm_2 > EPS ? r_ab_norm_2 : EPS;
r_ab_norm_3 = r_ab_norm_3 > EPS ? r_ab_norm_3 : EPS;
r_ab_norm_4 = r_ab_norm_4 > EPS ? r_ab_norm_4 : EPS;
r_ab_norm_5 = r_ab_norm_5 > EPS ? r_ab_norm_5 : EPS;
r_ab_norm_6 = r_ab_norm_6 > EPS ? r_ab_norm_6 : EPS;
r_ab_norm_7 = r_ab_norm_7 > EPS ? r_ab_norm_7 : EPS;
float r_ab2_x_0 = r_ab_x_0 - sb_e_x[j];
float r_ab2_x_1 = r_ab_x_1 - sb_e_x[j + 1];
float r_ab2_x_2 = r_ab_x_2 - sb_e_x[j + 2];
float r_ab2_x_3 = r_ab_x_3 - sb_e_x[j + 3];
float r_ab2_x_4 = r_ab_x_4 - sb_e_x[j + 4];
float r_ab2_x_5 = r_ab_x_5 - sb_e_x[j + 5];
float r_ab2_x_6 = r_ab_x_6 - sb_e_x[j + 6];
float r_ab2_x_7 = r_ab_x_7 - sb_e_x[j + 7];
float r_ab2_y_0 = r_ab_y_0 - sb_e_y[j];
float r_ab2_y_1 = r_ab_y_1 - sb_e_y[j + 1];
float r_ab2_y_2 = r_ab_y_2 - sb_e_y[j + 2];
float r_ab2_y_3 = r_ab_y_3 - sb_e_y[j + 3];
float r_ab2_y_4 = r_ab_y_4 - sb_e_y[j + 4];
float r_ab2_y_5 = r_ab_y_5 - sb_e_y[j + 5];
float r_ab2_y_6 = r_ab_y_6 - sb_e_y[j + 6];
float r_ab2_y_7 = r_ab_y_7 - sb_e_y[j + 7];
float r_ab2_norm_0 = sqrt(r_ab2_x_0 * r_ab2_x_0 + r_ab2_y_0 * r_ab2_y_0);
float r_ab2_norm_1 = sqrt(r_ab2_x_1 * r_ab2_x_1 + r_ab2_y_1 * r_ab2_y_1);
float r_ab2_norm_2 = sqrt(r_ab2_x_2 * r_ab2_x_2 + r_ab2_y_2 * r_ab2_y_2);
float r_ab2_norm_3 = sqrt(r_ab2_x_3 * r_ab2_x_3 + r_ab2_y_3 * r_ab2_y_3);
float r_ab2_norm_4 = sqrt(r_ab2_x_4 * r_ab2_x_4 + r_ab2_y_4 * r_ab2_y_4);
float r_ab2_norm_5 = sqrt(r_ab2_x_5 * r_ab2_x_5 + r_ab2_y_5 * r_ab2_y_5);
float r_ab2_norm_6 = sqrt(r_ab2_x_6 * r_ab2_x_6 + r_ab2_y_6 * r_ab2_y_6);
float r_ab2_norm_7 = sqrt(r_ab2_x_7 * r_ab2_x_7 + r_ab2_y_7 * r_ab2_y_7);
r_ab2_norm_0 = r_ab2_norm_0 > EPS ? r_ab2_norm_0 : EPS;
r_ab2_norm_1 = r_ab2_norm_1 > EPS ? r_ab2_norm_1 : EPS;
r_ab2_norm_2 = r_ab2_norm_2 > EPS ? r_ab2_norm_2 : EPS;
r_ab2_norm_3 = r_ab2_norm_3 > EPS ? r_ab2_norm_3 : EPS;
r_ab2_norm_4 = r_ab2_norm_4 > EPS ? r_ab2_norm_4 : EPS;
r_ab2_norm_5 = r_ab2_norm_5 > EPS ? r_ab2_norm_5 : EPS;
r_ab2_norm_6 = r_ab2_norm_6 > EPS ? r_ab2_norm_6 : EPS;
r_ab2_norm_7 = r_ab2_norm_7 > EPS ? r_ab2_norm_7 : EPS;
float r_ab_norm_sum_0 = r_ab_norm_0 + r_ab2_norm_0;
float r_ab_norm_sum_1 = r_ab_norm_1 + r_ab2_norm_1;
float r_ab_norm_sum_2 = r_ab_norm_2 + r_ab2_norm_2;
float r_ab_norm_sum_3 = r_ab_norm_3 + r_ab2_norm_3;
float r_ab_norm_sum_4 = r_ab_norm_4 + r_ab2_norm_4;
float r_ab_norm_sum_5 = r_ab_norm_5 + r_ab2_norm_5;
float r_ab_norm_sum_6 = r_ab_norm_6 + r_ab2_norm_6;
float r_ab_norm_sum_7 = r_ab_norm_7 + r_ab2_norm_7;
float two_b_sq_0 = r_ab_norm_sum_0 * r_ab_norm_sum_0 - sb_sq[j];
float two_b_sq_1 = r_ab_norm_sum_1 * r_ab_norm_sum_1 - sb_sq[j + 1];
float two_b_sq_2 = r_ab_norm_sum_2 * r_ab_norm_sum_2 - sb_sq[j + 2];
float two_b_sq_3 = r_ab_norm_sum_3 * r_ab_norm_sum_3 - sb_sq[j + 3];
float two_b_sq_4 = r_ab_norm_sum_4 * r_ab_norm_sum_4 - sb_sq[j + 4];
float two_b_sq_5 = r_ab_norm_sum_5 * r_ab_norm_sum_5 - sb_sq[j + 5];
float two_b_sq_6 = r_ab_norm_sum_6 * r_ab_norm_sum_6 - sb_sq[j + 6];
float two_b_sq_7 = r_ab_norm_sum_7 * r_ab_norm_sum_7 - sb_sq[j + 7];
two_b_sq_0 = two_b_sq_0 > EPS_SQ ? two_b_sq_0 : EPS_SQ;
two_b_sq_1 = two_b_sq_1 > EPS_SQ ? two_b_sq_1 : EPS_SQ;
two_b_sq_2 = two_b_sq_2 > EPS_SQ ? two_b_sq_2 : EPS_SQ;
two_b_sq_3 = two_b_sq_3 > EPS_SQ ? two_b_sq_3 : EPS_SQ;
two_b_sq_4 = two_b_sq_4 > EPS_SQ ? two_b_sq_4 : EPS_SQ;
two_b_sq_5 = two_b_sq_5 > EPS_SQ ? two_b_sq_5 : EPS_SQ;
two_b_sq_6 = two_b_sq_6 > EPS_SQ ? two_b_sq_6 : EPS_SQ;
two_b_sq_7 = two_b_sq_7 > EPS_SQ ? two_b_sq_7 : EPS_SQ;
float two_b_0 = sqrt(two_b_sq_0);
float two_b_1 = sqrt(two_b_sq_1);
float two_b_2 = sqrt(two_b_sq_2);
float two_b_3 = sqrt(two_b_sq_3);
float two_b_4 = sqrt(two_b_sq_4);
float two_b_5 = sqrt(two_b_sq_5);
float two_b_6 = sqrt(two_b_sq_6);
float two_b_7 = sqrt(two_b_sq_7);
float scalar_mult_common_0 = (r_ab_norm_sum_0 / (two_b_0 * r_ab_norm_0 * r_ab2_norm_0)) * (NEG_V0_AB_div_TWO_SIGMA * exp(two_b_0 * NEG_TWO_SIGMA_INV));
float scalar_mult_common_1 = (r_ab_norm_sum_1 / (two_b_1 * r_ab_norm_1 * r_ab2_norm_1)) * (NEG_V0_AB_div_TWO_SIGMA * exp(two_b_1 * NEG_TWO_SIGMA_INV));
float scalar_mult_common_2 = (r_ab_norm_sum_2 / (two_b_2 * r_ab_norm_2 * r_ab2_norm_2)) * (NEG_V0_AB_div_TWO_SIGMA * exp(two_b_2 * NEG_TWO_SIGMA_INV));
float scalar_mult_common_3 = (r_ab_norm_sum_3 / (two_b_3 * r_ab_norm_3 * r_ab2_norm_3)) * (NEG_V0_AB_div_TWO_SIGMA * exp(two_b_3 * NEG_TWO_SIGMA_INV));
float scalar_mult_common_4 = (r_ab_norm_sum_4 / (two_b_4 * r_ab_norm_4 * r_ab2_norm_4)) * (NEG_V0_AB_div_TWO_SIGMA * exp(two_b_4 * NEG_TWO_SIGMA_INV));
float scalar_mult_common_5 = (r_ab_norm_sum_5 / (two_b_5 * r_ab_norm_5 * r_ab2_norm_5)) * (NEG_V0_AB_div_TWO_SIGMA * exp(two_b_5 * NEG_TWO_SIGMA_INV));
float scalar_mult_common_6 = (r_ab_norm_sum_6 / (two_b_6 * r_ab_norm_6 * r_ab2_norm_6)) * (NEG_V0_AB_div_TWO_SIGMA * exp(two_b_6 * NEG_TWO_SIGMA_INV));
float scalar_mult_common_7 = (r_ab_norm_sum_7 / (two_b_7 * r_ab_norm_7 * r_ab2_norm_7)) * (NEG_V0_AB_div_TWO_SIGMA * exp(two_b_7 * NEG_TWO_SIGMA_INV));
float scalar_mult_r_ab_0 = scalar_mult_common_0 * r_ab2_norm_0;
float scalar_mult_r_ab_1 = scalar_mult_common_1 * r_ab2_norm_1;
float scalar_mult_r_ab_2 = scalar_mult_common_2 * r_ab2_norm_2;
float scalar_mult_r_ab_3 = scalar_mult_common_3 * r_ab2_norm_3;
float scalar_mult_r_ab_4 = scalar_mult_common_4 * r_ab2_norm_4;
float scalar_mult_r_ab_5 = scalar_mult_common_5 * r_ab2_norm_5;
float scalar_mult_r_ab_6 = scalar_mult_common_6 * r_ab2_norm_6;
float scalar_mult_r_ab_7 = scalar_mult_common_7 * r_ab2_norm_7;
float scalar_mult_r_ab2_0 = scalar_mult_common_0 * r_ab_norm_0;
float scalar_mult_r_ab2_1 = scalar_mult_common_1 * r_ab_norm_1;
float scalar_mult_r_ab2_2 = scalar_mult_common_2 * r_ab_norm_2;
float scalar_mult_r_ab2_3 = scalar_mult_common_3 * r_ab_norm_3;
float scalar_mult_r_ab2_4 = scalar_mult_common_4 * r_ab_norm_4;
float scalar_mult_r_ab2_5 = scalar_mult_common_5 * r_ab_norm_5;
float scalar_mult_r_ab2_6 = scalar_mult_common_6 * r_ab_norm_6;
float scalar_mult_r_ab2_7 = scalar_mult_common_7 * r_ab_norm_7;
float f_alpha_beta_neg_x_0 = r_ab_x_0 * scalar_mult_r_ab_0 + r_ab2_x_0 * scalar_mult_r_ab2_0;
float f_alpha_beta_neg_x_1 = r_ab_x_1 * scalar_mult_r_ab_1 + r_ab2_x_1 * scalar_mult_r_ab2_1;
float f_alpha_beta_neg_x_2 = r_ab_x_2 * scalar_mult_r_ab_2 + r_ab2_x_2 * scalar_mult_r_ab2_2;
float f_alpha_beta_neg_x_3 = r_ab_x_3 * scalar_mult_r_ab_3 + r_ab2_x_3 * scalar_mult_r_ab2_3;
float f_alpha_beta_neg_x_4 = r_ab_x_4 * scalar_mult_r_ab_4 + r_ab2_x_4 * scalar_mult_r_ab2_4;
float f_alpha_beta_neg_x_5 = r_ab_x_5 * scalar_mult_r_ab_5 + r_ab2_x_5 * scalar_mult_r_ab2_5;
float f_alpha_beta_neg_x_6 = r_ab_x_6 * scalar_mult_r_ab_6 + r_ab2_x_6 * scalar_mult_r_ab2_6;
float f_alpha_beta_neg_x_7 = r_ab_x_7 * scalar_mult_r_ab_7 + r_ab2_x_7 * scalar_mult_r_ab2_7;
float f_alpha_beta_neg_y_0 = r_ab_y_0 * scalar_mult_r_ab_0 + r_ab2_y_0 * scalar_mult_r_ab2_0;
float f_alpha_beta_neg_y_1 = r_ab_y_1 * scalar_mult_r_ab_1 + r_ab2_y_1 * scalar_mult_r_ab2_1;
float f_alpha_beta_neg_y_2 = r_ab_y_2 * scalar_mult_r_ab_2 + r_ab2_y_2 * scalar_mult_r_ab2_2;
float f_alpha_beta_neg_y_3 = r_ab_y_3 * scalar_mult_r_ab_3 + r_ab2_y_3 * scalar_mult_r_ab2_3;
float f_alpha_beta_neg_y_4 = r_ab_y_4 * scalar_mult_r_ab_4 + r_ab2_y_4 * scalar_mult_r_ab2_4;
float f_alpha_beta_neg_y_5 = r_ab_y_5 * scalar_mult_r_ab_5 + r_ab2_y_5 * scalar_mult_r_ab2_5;
float f_alpha_beta_neg_y_6 = r_ab_y_6 * scalar_mult_r_ab_6 + r_ab2_y_6 * scalar_mult_r_ab2_6;
float f_alpha_beta_neg_y_7 = r_ab_y_7 * scalar_mult_r_ab_7 + r_ab2_y_7 * scalar_mult_r_ab2_7;
float w_val_0, w_val_1, w_val_2, w_val_3, w_val_4, w_val_5, w_val_6, w_val_7;
float f_norm_sq_0 = f_alpha_beta_neg_x_0 * f_alpha_beta_neg_x_0 + f_alpha_beta_neg_y_0 * f_alpha_beta_neg_y_0;
float f_norm_sq_1 = f_alpha_beta_neg_x_1 * f_alpha_beta_neg_x_1 + f_alpha_beta_neg_y_1 * f_alpha_beta_neg_y_1;
float f_norm_sq_2 = f_alpha_beta_neg_x_2 * f_alpha_beta_neg_x_2 + f_alpha_beta_neg_y_2 * f_alpha_beta_neg_y_2;
float f_norm_sq_3 = f_alpha_beta_neg_x_3 * f_alpha_beta_neg_x_3 + f_alpha_beta_neg_y_3 * f_alpha_beta_neg_y_3;
float f_norm_sq_4 = f_alpha_beta_neg_x_4 * f_alpha_beta_neg_x_4 + f_alpha_beta_neg_y_4 * f_alpha_beta_neg_y_4;
float f_norm_sq_5 = f_alpha_beta_neg_x_5 * f_alpha_beta_neg_x_5 + f_alpha_beta_neg_y_5 * f_alpha_beta_neg_y_5;
float f_norm_sq_6 = f_alpha_beta_neg_x_6 * f_alpha_beta_neg_x_6 + f_alpha_beta_neg_y_6 * f_alpha_beta_neg_y_6;
float f_norm_sq_7 = f_alpha_beta_neg_x_7 * f_alpha_beta_neg_x_7 + f_alpha_beta_neg_y_7 * f_alpha_beta_neg_y_7;
float rhs_0 = f_norm_sq_0 * cos_phi_sq;
float rhs_1 = f_norm_sq_1 * cos_phi_sq;
float rhs_2 = f_norm_sq_2 * cos_phi_sq;
float rhs_3 = f_norm_sq_3 * cos_phi_sq;
float rhs_4 = f_norm_sq_4 * cos_phi_sq;
float rhs_5 = f_norm_sq_5 * cos_phi_sq;
float rhs_6 = f_norm_sq_6 * cos_phi_sq;
float rhs_7 = f_norm_sq_7 * cos_phi_sq;
float e_dot_f_0 = e_x_i * f_alpha_beta_neg_x_0 + e_y_i * f_alpha_beta_neg_y_0;
float e_dot_f_1 = e_x_i * f_alpha_beta_neg_x_1 + e_y_i * f_alpha_beta_neg_y_1;
float e_dot_f_2 = e_x_i * f_alpha_beta_neg_x_2 + e_y_i * f_alpha_beta_neg_y_2;
float e_dot_f_3 = e_x_i * f_alpha_beta_neg_x_3 + e_y_i * f_alpha_beta_neg_y_3;
float e_dot_f_4 = e_x_i * f_alpha_beta_neg_x_4 + e_y_i * f_alpha_beta_neg_y_4;
float e_dot_f_5 = e_x_i * f_alpha_beta_neg_x_5 + e_y_i * f_alpha_beta_neg_y_5;
float e_dot_f_6 = e_x_i * f_alpha_beta_neg_x_6 + e_y_i * f_alpha_beta_neg_y_6;
float e_dot_f_7 = e_x_i * f_alpha_beta_neg_x_7 + e_y_i * f_alpha_beta_neg_y_7;
float e_dot_f_sq_0 = e_dot_f_0 * e_dot_f_0;
float e_dot_f_sq_1 = e_dot_f_1 * e_dot_f_1;
float e_dot_f_sq_2 = e_dot_f_2 * e_dot_f_2;
float e_dot_f_sq_3 = e_dot_f_3 * e_dot_f_3;
float e_dot_f_sq_4 = e_dot_f_4 * e_dot_f_4;
float e_dot_f_sq_5 = e_dot_f_5 * e_dot_f_5;
float e_dot_f_sq_6 = e_dot_f_6 * e_dot_f_6;
float e_dot_f_sq_7 = e_dot_f_7 * e_dot_f_7;
if (e_dot_f_0 >= 0.0 || e_dot_f_sq_0 <= rhs_0)
w_val_0 = dt_neg;
else
w_val_0 = c_neg_times_dt;
if (e_dot_f_1 >= 0.0 || e_dot_f_sq_1 <= rhs_1)
w_val_1 = dt_neg;
else
w_val_1 = c_neg_times_dt;
if (e_dot_f_2 >= 0.0 || e_dot_f_sq_2 <= rhs_2)
w_val_2 = dt_neg;
else
w_val_2 = c_neg_times_dt;
if (e_dot_f_3 >= 0.0 || e_dot_f_sq_3 <= rhs_3)
w_val_3 = dt_neg;
else
w_val_3 = c_neg_times_dt;
if (e_dot_f_4 >= 0.0 || e_dot_f_sq_4 <= rhs_4)
w_val_4 = dt_neg;
else
w_val_4 = c_neg_times_dt;
if (e_dot_f_5 >= 0.0 || e_dot_f_sq_5 <= rhs_5)
w_val_5 = dt_neg;
else
w_val_5 = c_neg_times_dt;
if (e_dot_f_6 >= 0.0 || e_dot_f_sq_6 <= rhs_6)
w_val_6 = dt_neg;
else
w_val_6 = c_neg_times_dt;
if (e_dot_f_7 >= 0.0 || e_dot_f_sq_7 <= rhs_7)
w_val_7 = dt_neg;
else
w_val_7 = c_neg_times_dt;
acc_x_0 += f_alpha_beta_neg_x_0 * w_val_0;
acc_x_1 += f_alpha_beta_neg_x_1 * w_val_1;
acc_x_2 += f_alpha_beta_neg_x_2 * w_val_2;
acc_x_3 += f_alpha_beta_neg_x_3 * w_val_3;
acc_x_4 += f_alpha_beta_neg_x_4 * w_val_4;
acc_x_5 += f_alpha_beta_neg_x_5 * w_val_5;
acc_x_6 += f_alpha_beta_neg_x_6 * w_val_6;
acc_x_7 += f_alpha_beta_neg_x_7 * w_val_7;
acc_y_0 += f_alpha_beta_neg_y_0 * w_val_0;
acc_y_1 += f_alpha_beta_neg_y_1 * w_val_1;
acc_y_2 += f_alpha_beta_neg_y_2 * w_val_2;
acc_y_3 += f_alpha_beta_neg_y_3 * w_val_3;
acc_y_4 += f_alpha_beta_neg_y_4 * w_val_4;
acc_y_5 += f_alpha_beta_neg_y_5 * w_val_5;
acc_y_6 += f_alpha_beta_neg_y_6 * w_val_6;
acc_y_7 += f_alpha_beta_neg_y_7 * w_val_7;
}
for (; j < i; j++) {
float r_ab_x = -1 * r_ab_x_lut[j * n_p + i];
float r_ab_y = -1 * r_ab_y_lut[j * n_p + i];
float r_ab_norm = r_ab_norm_lut[j * n_p + i];
r_ab_norm = r_ab_norm > EPS ? r_ab_norm : EPS;
float r_ab2_x = r_ab_x - sb_e_x[j];
float r_ab2_y = r_ab_y - sb_e_y[j];
float r_ab2_norm = sqrt(r_ab2_x * r_ab2_x + r_ab2_y * r_ab2_y);
r_ab2_norm = r_ab2_norm > EPS ? r_ab2_norm : EPS;
float r_ab_norm_sum = r_ab_norm + r_ab2_norm;
float two_b_sq = r_ab_norm_sum * r_ab_norm_sum - sb_sq[j];
two_b_sq = two_b_sq > EPS_SQ ? two_b_sq : EPS_SQ;
float two_b = sqrt(two_b_sq);
float scalar_mult_common = (r_ab_norm_sum / (two_b * r_ab_norm * r_ab2_norm)) * (NEG_V0_AB_div_TWO_SIGMA * exp(two_b * NEG_TWO_SIGMA_INV));
float scalar_mult_r_ab = scalar_mult_common * r_ab2_norm;
float scalar_mult_r_ab2 = scalar_mult_common * r_ab_norm;
float f_alpha_beta_neg_x = r_ab_x * scalar_mult_r_ab + r_ab2_x * scalar_mult_r_ab2;
float f_alpha_beta_neg_y = r_ab_y * scalar_mult_r_ab + r_ab2_y * scalar_mult_r_ab2;
float w_val;
float f_norm_sq = f_alpha_beta_neg_x * f_alpha_beta_neg_x + f_alpha_beta_neg_y * f_alpha_beta_neg_y;
float rhs = f_norm_sq * cos_phi_sq;
float e_dot_f = e_x[i] * f_alpha_beta_neg_x + e_y[i] * f_alpha_beta_neg_y;
float e_dot_f_sq = e_dot_f * e_dot_f;
if (e_dot_f >= 0.0 || e_dot_f_sq <= rhs)
w_val = dt_neg;
else
w_val = c_neg_times_dt;
f_alpha_dt_x += f_alpha_beta_neg_x * w_val;
f_alpha_dt_y += f_alpha_beta_neg_y * w_val;
}
f_alpha_dt_x += acc_x_0 + acc_x_1 + acc_x_2 + acc_x_3 + acc_x_4 + acc_x_5 + acc_x_6 + acc_x_7;
f_alpha_dt_y += acc_y_0 + acc_y_1 + acc_y_2 + acc_y_3 + acc_y_4 + acc_y_5 + acc_y_6 + acc_y_7;
acc_x_0 = 0.0f;
acc_x_1 = 0.0f;
acc_x_2 = 0.0f;
acc_x_3 = 0.0f;
acc_x_4 = 0.0f;
acc_x_5 = 0.0f;
acc_x_6 = 0.0f;
acc_x_7 = 0.0f;
acc_y_0 = 0.0f;
acc_y_1 = 0.0f;
acc_y_2 = 0.0f;
acc_y_3 = 0.0f;
acc_y_4 = 0.0f;
acc_y_5 = 0.0f;
acc_y_6 = 0.0f;
acc_y_7 = 0.0f;
for (j = i + 1; j + 8 < n_p; j += 8) {
float r_ab_x_0 = r_ab_x_lut[i * n_p + j];
float r_ab_x_1 = r_ab_x_lut[i * n_p + j + 1];
float r_ab_x_2 = r_ab_x_lut[i * n_p + j + 2];
float r_ab_x_3 = r_ab_x_lut[i * n_p + j + 3];
float r_ab_x_4 = r_ab_x_lut[i * n_p + j + 4];
float r_ab_x_5 = r_ab_x_lut[i * n_p + j + 5];
float r_ab_x_6 = r_ab_x_lut[i * n_p + j + 6];
float r_ab_x_7 = r_ab_x_lut[i * n_p + j + 7];
float r_ab_y_0 = r_ab_y_lut[i * n_p + j];
float r_ab_y_1 = r_ab_y_lut[i * n_p + j + 1];
float r_ab_y_2 = r_ab_y_lut[i * n_p + j + 2];
float r_ab_y_3 = r_ab_y_lut[i * n_p + j + 3];
float r_ab_y_4 = r_ab_y_lut[i * n_p + j + 4];
float r_ab_y_5 = r_ab_y_lut[i * n_p + j + 5];
float r_ab_y_6 = r_ab_y_lut[i * n_p + j + 6];
float r_ab_y_7 = r_ab_y_lut[i * n_p + j + 7];
float r_ab_norm_0 = r_ab_norm_lut[i * n_p + j];
float r_ab_norm_1 = r_ab_norm_lut[i * n_p + j + 1];
float r_ab_norm_2 = r_ab_norm_lut[i * n_p + j + 2];
float r_ab_norm_3 = r_ab_norm_lut[i * n_p + j + 3];
float r_ab_norm_4 = r_ab_norm_lut[i * n_p + j + 4];
float r_ab_norm_5 = r_ab_norm_lut[i * n_p + j + 5];
float r_ab_norm_6 = r_ab_norm_lut[i * n_p + j + 6];
float r_ab_norm_7 = r_ab_norm_lut[i * n_p + j + 7];
r_ab_norm_0 = r_ab_norm_0 > EPS ? r_ab_norm_0 : EPS;
r_ab_norm_1 = r_ab_norm_1 > EPS ? r_ab_norm_1 : EPS;
r_ab_norm_2 = r_ab_norm_2 > EPS ? r_ab_norm_2 : EPS;
r_ab_norm_3 = r_ab_norm_3 > EPS ? r_ab_norm_3 : EPS;
r_ab_norm_4 = r_ab_norm_4 > EPS ? r_ab_norm_4 : EPS;
r_ab_norm_5 = r_ab_norm_5 > EPS ? r_ab_norm_5 : EPS;
r_ab_norm_6 = r_ab_norm_6 > EPS ? r_ab_norm_6 : EPS;
r_ab_norm_7 = r_ab_norm_7 > EPS ? r_ab_norm_7 : EPS;
float r_ab2_x_0 = r_ab_x_0 - sb_e_x[j];
float r_ab2_x_1 = r_ab_x_1 - sb_e_x[j + 1];
float r_ab2_x_2 = r_ab_x_2 - sb_e_x[j + 2];
float r_ab2_x_3 = r_ab_x_3 - sb_e_x[j + 3];
float r_ab2_x_4 = r_ab_x_4 - sb_e_x[j + 4];
float r_ab2_x_5 = r_ab_x_5 - sb_e_x[j + 5];
float r_ab2_x_6 = r_ab_x_6 - sb_e_x[j + 6];
float r_ab2_x_7 = r_ab_x_7 - sb_e_x[j + 7];
float r_ab2_y_0 = r_ab_y_0 - sb_e_y[j];
float r_ab2_y_1 = r_ab_y_1 - sb_e_y[j + 1];
float r_ab2_y_2 = r_ab_y_2 - sb_e_y[j + 2];
float r_ab2_y_3 = r_ab_y_3 - sb_e_y[j + 3];
float r_ab2_y_4 = r_ab_y_4 - sb_e_y[j + 4];
float r_ab2_y_5 = r_ab_y_5 - sb_e_y[j + 5];
float r_ab2_y_6 = r_ab_y_6 - sb_e_y[j + 6];
float r_ab2_y_7 = r_ab_y_7 - sb_e_y[j + 7];
float r_ab2_norm_0 = sqrt(r_ab2_x_0 * r_ab2_x_0 + r_ab2_y_0 * r_ab2_y_0);
float r_ab2_norm_1 = sqrt(r_ab2_x_1 * r_ab2_x_1 + r_ab2_y_1 * r_ab2_y_1);
float r_ab2_norm_2 = sqrt(r_ab2_x_2 * r_ab2_x_2 + r_ab2_y_2 * r_ab2_y_2);
float r_ab2_norm_3 = sqrt(r_ab2_x_3 * r_ab2_x_3 + r_ab2_y_3 * r_ab2_y_3);
float r_ab2_norm_4 = sqrt(r_ab2_x_4 * r_ab2_x_4 + r_ab2_y_4 * r_ab2_y_4);
float r_ab2_norm_5 = sqrt(r_ab2_x_5 * r_ab2_x_5 + r_ab2_y_5 * r_ab2_y_5);
float r_ab2_norm_6 = sqrt(r_ab2_x_6 * r_ab2_x_6 + r_ab2_y_6 * r_ab2_y_6);
float r_ab2_norm_7 = sqrt(r_ab2_x_7 * r_ab2_x_7 + r_ab2_y_7 * r_ab2_y_7);
r_ab2_norm_0 = r_ab2_norm_0 > EPS ? r_ab2_norm_0 : EPS;
r_ab2_norm_1 = r_ab2_norm_1 > EPS ? r_ab2_norm_1 : EPS;
r_ab2_norm_2 = r_ab2_norm_2 > EPS ? r_ab2_norm_2 : EPS;
r_ab2_norm_3 = r_ab2_norm_3 > EPS ? r_ab2_norm_3 : EPS;
r_ab2_norm_4 = r_ab2_norm_4 > EPS ? r_ab2_norm_4 : EPS;
r_ab2_norm_5 = r_ab2_norm_5 > EPS ? r_ab2_norm_5 : EPS;
r_ab2_norm_6 = r_ab2_norm_6 > EPS ? r_ab2_norm_6 : EPS;
r_ab2_norm_7 = r_ab2_norm_7 > EPS ? r_ab2_norm_7 : EPS;
float r_ab_norm_sum_0 = r_ab_norm_0 + r_ab2_norm_0;
float r_ab_norm_sum_1 = r_ab_norm_1 + r_ab2_norm_1;
float r_ab_norm_sum_2 = r_ab_norm_2 + r_ab2_norm_2;
float r_ab_norm_sum_3 = r_ab_norm_3 + r_ab2_norm_3;
float r_ab_norm_sum_4 = r_ab_norm_4 + r_ab2_norm_4;
float r_ab_norm_sum_5 = r_ab_norm_5 + r_ab2_norm_5;
float r_ab_norm_sum_6 = r_ab_norm_6 + r_ab2_norm_6;
float r_ab_norm_sum_7 = r_ab_norm_7 + r_ab2_norm_7;
float two_b_sq_0 = r_ab_norm_sum_0 * r_ab_norm_sum_0 - sb_sq[j];
float two_b_sq_1 = r_ab_norm_sum_1 * r_ab_norm_sum_1 - sb_sq[j + 1];
float two_b_sq_2 = r_ab_norm_sum_2 * r_ab_norm_sum_2 - sb_sq[j + 2];
float two_b_sq_3 = r_ab_norm_sum_3 * r_ab_norm_sum_3 - sb_sq[j + 3];
float two_b_sq_4 = r_ab_norm_sum_4 * r_ab_norm_sum_4 - sb_sq[j + 4];
float two_b_sq_5 = r_ab_norm_sum_5 * r_ab_norm_sum_5 - sb_sq[j + 5];
float two_b_sq_6 = r_ab_norm_sum_6 * r_ab_norm_sum_6 - sb_sq[j + 6];
float two_b_sq_7 = r_ab_norm_sum_7 * r_ab_norm_sum_7 - sb_sq[j + 7];
two_b_sq_0 = two_b_sq_0 > EPS_SQ ? two_b_sq_0 : EPS_SQ;
two_b_sq_1 = two_b_sq_1 > EPS_SQ ? two_b_sq_1 : EPS_SQ;
two_b_sq_2 = two_b_sq_2 > EPS_SQ ? two_b_sq_2 : EPS_SQ;
two_b_sq_3 = two_b_sq_3 > EPS_SQ ? two_b_sq_3 : EPS_SQ;
two_b_sq_4 = two_b_sq_4 > EPS_SQ ? two_b_sq_4 : EPS_SQ;
two_b_sq_5 = two_b_sq_5 > EPS_SQ ? two_b_sq_5 : EPS_SQ;
two_b_sq_6 = two_b_sq_6 > EPS_SQ ? two_b_sq_6 : EPS_SQ;
two_b_sq_7 = two_b_sq_7 > EPS_SQ ? two_b_sq_7 : EPS_SQ;
float two_b_0 = sqrt(two_b_sq_0);
float two_b_1 = sqrt(two_b_sq_1);
float two_b_2 = sqrt(two_b_sq_2);
float two_b_3 = sqrt(two_b_sq_3);
float two_b_4 = sqrt(two_b_sq_4);
float two_b_5 = sqrt(two_b_sq_5);
float two_b_6 = sqrt(two_b_sq_6);
float two_b_7 = sqrt(two_b_sq_7);
float scalar_mult_common_0 = (r_ab_norm_sum_0 / (two_b_0 * r_ab_norm_0 * r_ab2_norm_0)) * (NEG_V0_AB_div_TWO_SIGMA * exp(two_b_0 * NEG_TWO_SIGMA_INV));
float scalar_mult_common_1 = (r_ab_norm_sum_1 / (two_b_1 * r_ab_norm_1 * r_ab2_norm_1)) * (NEG_V0_AB_div_TWO_SIGMA * exp(two_b_1 * NEG_TWO_SIGMA_INV));
float scalar_mult_common_2 = (r_ab_norm_sum_2 / (two_b_2 * r_ab_norm_2 * r_ab2_norm_2)) * (NEG_V0_AB_div_TWO_SIGMA * exp(two_b_2 * NEG_TWO_SIGMA_INV));
float scalar_mult_common_3 = (r_ab_norm_sum_3 / (two_b_3 * r_ab_norm_3 * r_ab2_norm_3)) * (NEG_V0_AB_div_TWO_SIGMA * exp(two_b_3 * NEG_TWO_SIGMA_INV));
float scalar_mult_common_4 = (r_ab_norm_sum_4 / (two_b_4 * r_ab_norm_4 * r_ab2_norm_4)) * (NEG_V0_AB_div_TWO_SIGMA * exp(two_b_4 * NEG_TWO_SIGMA_INV));
float scalar_mult_common_5 = (r_ab_norm_sum_5 / (two_b_5 * r_ab_norm_5 * r_ab2_norm_5)) * (NEG_V0_AB_div_TWO_SIGMA * exp(two_b_5 * NEG_TWO_SIGMA_INV));
float scalar_mult_common_6 = (r_ab_norm_sum_6 / (two_b_6 * r_ab_norm_6 * r_ab2_norm_6)) * (NEG_V0_AB_div_TWO_SIGMA * exp(two_b_6 * NEG_TWO_SIGMA_INV));
float scalar_mult_common_7 = (r_ab_norm_sum_7 / (two_b_7 * r_ab_norm_7 * r_ab2_norm_7)) * (NEG_V0_AB_div_TWO_SIGMA * exp(two_b_7 * NEG_TWO_SIGMA_INV));
float scalar_mult_r_ab_0 = scalar_mult_common_0 * r_ab2_norm_0;
float scalar_mult_r_ab_1 = scalar_mult_common_1 * r_ab2_norm_1;
float scalar_mult_r_ab_2 = scalar_mult_common_2 * r_ab2_norm_2;
float scalar_mult_r_ab_3 = scalar_mult_common_3 * r_ab2_norm_3;
float scalar_mult_r_ab_4 = scalar_mult_common_4 * r_ab2_norm_4;
float scalar_mult_r_ab_5 = scalar_mult_common_5 * r_ab2_norm_5;
float scalar_mult_r_ab_6 = scalar_mult_common_6 * r_ab2_norm_6;
float scalar_mult_r_ab_7 = scalar_mult_common_7 * r_ab2_norm_7;
float scalar_mult_r_ab2_0 = scalar_mult_common_0 * r_ab_norm_0;
float scalar_mult_r_ab2_1 = scalar_mult_common_1 * r_ab_norm_1;
float scalar_mult_r_ab2_2 = scalar_mult_common_2 * r_ab_norm_2;
float scalar_mult_r_ab2_3 = scalar_mult_common_3 * r_ab_norm_3;
float scalar_mult_r_ab2_4 = scalar_mult_common_4 * r_ab_norm_4;
float scalar_mult_r_ab2_5 = scalar_mult_common_5 * r_ab_norm_5;
float scalar_mult_r_ab2_6 = scalar_mult_common_6 * r_ab_norm_6;
float scalar_mult_r_ab2_7 = scalar_mult_common_7 * r_ab_norm_7;
float f_alpha_beta_neg_x_0 = r_ab_x_0 * scalar_mult_r_ab_0 + r_ab2_x_0 * scalar_mult_r_ab2_0;
float f_alpha_beta_neg_x_1 = r_ab_x_1 * scalar_mult_r_ab_1 + r_ab2_x_1 * scalar_mult_r_ab2_1;
float f_alpha_beta_neg_x_2 = r_ab_x_2 * scalar_mult_r_ab_2 + r_ab2_x_2 * scalar_mult_r_ab2_2;
float f_alpha_beta_neg_x_3 = r_ab_x_3 * scalar_mult_r_ab_3 + r_ab2_x_3 * scalar_mult_r_ab2_3;
float f_alpha_beta_neg_x_4 = r_ab_x_4 * scalar_mult_r_ab_4 + r_ab2_x_4 * scalar_mult_r_ab2_4;
float f_alpha_beta_neg_x_5 = r_ab_x_5 * scalar_mult_r_ab_5 + r_ab2_x_5 * scalar_mult_r_ab2_5;
float f_alpha_beta_neg_x_6 = r_ab_x_6 * scalar_mult_r_ab_6 + r_ab2_x_6 * scalar_mult_r_ab2_6;
float f_alpha_beta_neg_x_7 = r_ab_x_7 * scalar_mult_r_ab_7 + r_ab2_x_7 * scalar_mult_r_ab2_7;
float f_alpha_beta_neg_y_0 = r_ab_y_0 * scalar_mult_r_ab_0 + r_ab2_y_0 * scalar_mult_r_ab2_0;
float f_alpha_beta_neg_y_1 = r_ab_y_1 * scalar_mult_r_ab_1 + r_ab2_y_1 * scalar_mult_r_ab2_1;
float f_alpha_beta_neg_y_2 = r_ab_y_2 * scalar_mult_r_ab_2 + r_ab2_y_2 * scalar_mult_r_ab2_2;
float f_alpha_beta_neg_y_3 = r_ab_y_3 * scalar_mult_r_ab_3 + r_ab2_y_3 * scalar_mult_r_ab2_3;
float f_alpha_beta_neg_y_4 = r_ab_y_4 * scalar_mult_r_ab_4 + r_ab2_y_4 * scalar_mult_r_ab2_4;
float f_alpha_beta_neg_y_5 = r_ab_y_5 * scalar_mult_r_ab_5 + r_ab2_y_5 * scalar_mult_r_ab2_5;
float f_alpha_beta_neg_y_6 = r_ab_y_6 * scalar_mult_r_ab_6 + r_ab2_y_6 * scalar_mult_r_ab2_6;
float f_alpha_beta_neg_y_7 = r_ab_y_7 * scalar_mult_r_ab_7 + r_ab2_y_7 * scalar_mult_r_ab2_7;
float w_val_0, w_val_1, w_val_2, w_val_3, w_val_4, w_val_5, w_val_6, w_val_7;
float f_norm_sq_0 = f_alpha_beta_neg_x_0 * f_alpha_beta_neg_x_0 + f_alpha_beta_neg_y_0 * f_alpha_beta_neg_y_0;
float f_norm_sq_1 = f_alpha_beta_neg_x_1 * f_alpha_beta_neg_x_1 + f_alpha_beta_neg_y_1 * f_alpha_beta_neg_y_1;
float f_norm_sq_2 = f_alpha_beta_neg_x_2 * f_alpha_beta_neg_x_2 + f_alpha_beta_neg_y_2 * f_alpha_beta_neg_y_2;
float f_norm_sq_3 = f_alpha_beta_neg_x_3 * f_alpha_beta_neg_x_3 + f_alpha_beta_neg_y_3 * f_alpha_beta_neg_y_3;
float f_norm_sq_4 = f_alpha_beta_neg_x_4 * f_alpha_beta_neg_x_4 + f_alpha_beta_neg_y_4 * f_alpha_beta_neg_y_4;
float f_norm_sq_5 = f_alpha_beta_neg_x_5 * f_alpha_beta_neg_x_5 + f_alpha_beta_neg_y_5 * f_alpha_beta_neg_y_5;
float f_norm_sq_6 = f_alpha_beta_neg_x_6 * f_alpha_beta_neg_x_6 + f_alpha_beta_neg_y_6 * f_alpha_beta_neg_y_6;
float f_norm_sq_7 = f_alpha_beta_neg_x_7 * f_alpha_beta_neg_x_7 + f_alpha_beta_neg_y_7 * f_alpha_beta_neg_y_7;
float rhs_0 = f_norm_sq_0 * cos_phi_sq;
float rhs_1 = f_norm_sq_1 * cos_phi_sq;
float rhs_2 = f_norm_sq_2 * cos_phi_sq;
float rhs_3 = f_norm_sq_3 * cos_phi_sq;
float rhs_4 = f_norm_sq_4 * cos_phi_sq;
float rhs_5 = f_norm_sq_5 * cos_phi_sq;
float rhs_6 = f_norm_sq_6 * cos_phi_sq;
float rhs_7 = f_norm_sq_7 * cos_phi_sq;
float e_dot_f_0 = e_x_i * f_alpha_beta_neg_x_0 + e_y_i * f_alpha_beta_neg_y_0;
float e_dot_f_1 = e_x_i * f_alpha_beta_neg_x_1 + e_y_i * f_alpha_beta_neg_y_1;
float e_dot_f_2 = e_x_i * f_alpha_beta_neg_x_2 + e_y_i * f_alpha_beta_neg_y_2;
float e_dot_f_3 = e_x_i * f_alpha_beta_neg_x_3 + e_y_i * f_alpha_beta_neg_y_3;
float e_dot_f_4 = e_x_i * f_alpha_beta_neg_x_4 + e_y_i * f_alpha_beta_neg_y_4;
float e_dot_f_5 = e_x_i * f_alpha_beta_neg_x_5 + e_y_i * f_alpha_beta_neg_y_5;
float e_dot_f_6 = e_x_i * f_alpha_beta_neg_x_6 + e_y_i * f_alpha_beta_neg_y_6;
float e_dot_f_7 = e_x_i * f_alpha_beta_neg_x_7 + e_y_i * f_alpha_beta_neg_y_7;
float e_dot_f_sq_0 = e_dot_f_0 * e_dot_f_0;
float e_dot_f_sq_1 = e_dot_f_1 * e_dot_f_1;
float e_dot_f_sq_2 = e_dot_f_2 * e_dot_f_2;
float e_dot_f_sq_3 = e_dot_f_3 * e_dot_f_3;
float e_dot_f_sq_4 = e_dot_f_4 * e_dot_f_4;
float e_dot_f_sq_5 = e_dot_f_5 * e_dot_f_5;
float e_dot_f_sq_6 = e_dot_f_6 * e_dot_f_6;
float e_dot_f_sq_7 = e_dot_f_7 * e_dot_f_7;
if (e_dot_f_0 >= 0.0 || e_dot_f_sq_0 <= rhs_0)
w_val_0 = dt_neg;
else
w_val_0 = c_neg_times_dt;
if (e_dot_f_1 >= 0.0 || e_dot_f_sq_1 <= rhs_1)
w_val_1 = dt_neg;
else
w_val_1 = c_neg_times_dt;
if (e_dot_f_2 >= 0.0 || e_dot_f_sq_2 <= rhs_2)
w_val_2 = dt_neg;
else
w_val_2 = c_neg_times_dt;
if (e_dot_f_3 >= 0.0 || e_dot_f_sq_3 <= rhs_3)
w_val_3 = dt_neg;
else
w_val_3 = c_neg_times_dt;
if (e_dot_f_4 >= 0.0 || e_dot_f_sq_4 <= rhs_4)
w_val_4 = dt_neg;
else
w_val_4 = c_neg_times_dt;
if (e_dot_f_5 >= 0.0 || e_dot_f_sq_5 <= rhs_5)
w_val_5 = dt_neg;
else
w_val_5 = c_neg_times_dt;
if (e_dot_f_6 >= 0.0 || e_dot_f_sq_6 <= rhs_6)
w_val_6 = dt_neg;
else
w_val_6 = c_neg_times_dt;
if (e_dot_f_7 >= 0.0 || e_dot_f_sq_7 <= rhs_7)
w_val_7 = dt_neg;
else
w_val_7 = c_neg_times_dt;
acc_x_0 += f_alpha_beta_neg_x_0 * w_val_0;
acc_x_1 += f_alpha_beta_neg_x_1 * w_val_1;
acc_x_2 += f_alpha_beta_neg_x_2 * w_val_2;
acc_x_3 += f_alpha_beta_neg_x_3 * w_val_3;
acc_x_4 += f_alpha_beta_neg_x_4 * w_val_4;
acc_x_5 += f_alpha_beta_neg_x_5 * w_val_5;
acc_x_6 += f_alpha_beta_neg_x_6 * w_val_6;
acc_x_7 += f_alpha_beta_neg_x_7 * w_val_7;
acc_y_0 += f_alpha_beta_neg_y_0 * w_val_0;
acc_y_1 += f_alpha_beta_neg_y_1 * w_val_1;
acc_y_2 += f_alpha_beta_neg_y_2 * w_val_2;
acc_y_3 += f_alpha_beta_neg_y_3 * w_val_3;
acc_y_4 += f_alpha_beta_neg_y_4 * w_val_4;
acc_y_5 += f_alpha_beta_neg_y_5 * w_val_5;
acc_y_6 += f_alpha_beta_neg_y_6 * w_val_6;
acc_y_7 += f_alpha_beta_neg_y_7 * w_val_7;
}
for (; j < n_p; j++) {
float r_ab_x = r_ab_x_lut[i * n_p + j];
float r_ab_y = r_ab_y_lut[i * n_p + j];
float r_ab_norm = r_ab_norm_lut[i * n_p + j];
r_ab_norm = r_ab_norm > EPS ? r_ab_norm : EPS;
float r_ab2_x = r_ab_x - sb_e_x[j];
float r_ab2_y = r_ab_y - sb_e_y[j];
float r_ab2_norm = sqrt(r_ab2_x * r_ab2_x + r_ab2_y * r_ab2_y);
r_ab2_norm = r_ab2_norm > EPS ? r_ab2_norm : EPS;
float r_ab_norm_sum = r_ab_norm + r_ab2_norm;
float two_b_sq = r_ab_norm_sum * r_ab_norm_sum - sb_sq[j];
two_b_sq = two_b_sq > EPS_SQ ? two_b_sq : EPS_SQ;
float two_b = sqrt(two_b_sq);
float scalar_mult_common = (r_ab_norm_sum / (two_b * r_ab_norm * r_ab2_norm)) * (NEG_V0_AB_div_TWO_SIGMA * exp(two_b * NEG_TWO_SIGMA_INV));
float scalar_mult_r_ab = scalar_mult_common * r_ab2_norm;
float scalar_mult_r_ab2 = scalar_mult_common * r_ab_norm;
float f_alpha_beta_neg_x = r_ab_x * scalar_mult_r_ab + r_ab2_x * scalar_mult_r_ab2;
float f_alpha_beta_neg_y = r_ab_y * scalar_mult_r_ab + r_ab2_y * scalar_mult_r_ab2;
float w_val;
float f_norm_sq = f_alpha_beta_neg_x * f_alpha_beta_neg_x + f_alpha_beta_neg_y * f_alpha_beta_neg_y;
float rhs = f_norm_sq * cos_phi_sq;
float e_dot_f = e_x[i] * f_alpha_beta_neg_x + e_y[i] * f_alpha_beta_neg_y;
float e_dot_f_sq = e_dot_f * e_dot_f;
if (e_dot_f >= 0.0 || e_dot_f_sq <= rhs)
w_val = dt_neg;
else
w_val = c_neg_times_dt;
f_alpha_dt_x += f_alpha_beta_neg_x * w_val;
f_alpha_dt_y += f_alpha_beta_neg_y * w_val;
}
f_alpha_dt_x += acc_x_0 + acc_x_1 + acc_x_2 + acc_x_3 + acc_x_4 + acc_x_5 + acc_x_6 + acc_x_7;
f_alpha_dt_y += acc_y_0 + acc_y_1 + acc_y_2 + acc_y_3 + acc_y_4 + acc_y_5 + acc_y_6 + acc_y_7;
for (int k = 0; k < board.n_obstacles; k++) {
float v1_x = pos_x[i] - board.obstacles[k].start_x;
float v1_y = pos_y[i] - board.obstacles[k].start_y;
float v2_x = board.obstacles[k].obstacle_v_x;
float v2_y = board.obstacles[k].obstacle_v_y;
float projection = (v1_x * v2_x + v1_y * v2_y) * board.obstacles[k].length_sq_inv;
if (projection < 0.0)
projection = 0.0;
else if (projection > 1.0)
projection = 1.0;
float r_aB_x = pos_x[i] - (board.obstacles[k].start_x + board.obstacles[k].obstacle_v_x * projection);
float r_aB_y = pos_y[i] - (board.obstacles[k].start_y + board.obstacles[k].obstacle_v_y * projection);
float r_aB_norm = sqrt(r_aB_x * r_aB_x + r_aB_y * r_aB_y);
r_aB_norm = r_aB_norm > EPS ? r_aB_norm : EPS;
float scalar_mult = (NEG_U0_AB_div_R * exp(r_aB_norm * NEG_R_INV)) / r_aB_norm;
float f_alpha_B_neg_x = r_aB_x * scalar_mult;
float f_alpha_B_neg_y = r_aB_y * scalar_mult;
float w_val;
float e_dot_f = (f_alpha_B_neg_y == 0) ? 0 : (f_alpha_B_neg_y < 0 ? -e_y[i] : e_y[i]);
if (e_dot_f >= cos_phi)
w_val = dt_neg;
else
w_val = c_neg_times_dt;
float f_alpha_B_dt_x = f_alpha_B_neg_x * w_val;
float f_alpha_B_dt_y = f_alpha_B_neg_y * w_val;
f_alpha_dt_x += f_alpha_B_dt_x;
f_alpha_dt_y += f_alpha_B_dt_y;
}
w_x[i] += f_alpha_dt_x;
w_y[i] += f_alpha_dt_y;
}
for (int i = 0; i < n_p; i++) {
float w_norm = sqrt(w_x[i] * w_x[i] + w_y[i] * w_y[i]);
float w_norm2 = w_norm > EPS ? w_norm : EPS;
float correction_factor = min(1.0f, v_max[i] / w_norm2);
curr_vel_x[i] = w_x[i] * correction_factor;
curr_vel_y[i] = w_y[i] * correction_factor;
pos_x[i] = pos_x[i] + curr_vel_x[i] * dt;
pos_y[i] = pos_y[i] + curr_vel_y[i] * dt;
if (color[i] == 0 && pos_x[i] > (BOARD_LENGTH - 1.5)) {
pos_x[i] = 1.0;
destination_y[i] = pos_y[i];
w_x[i] = desired_v0[i];
w_y[i] = 0.0;
curr_vel_x[i] = w_x[i];
curr_vel_y[i] = w_y[i];
}
if (color[i] == 1 && pos_x[i] < 1.5) {
pos_x[i] = BOARD_LENGTH - 1.0;
destination_y[i] = pos_y[i];
w_x[i] = -desired_v0[i];
w_y[i] = 0.0;
curr_vel_x[i] = w_x[i];
curr_vel_y[i] = w_y[i];
}
pos_y[i] = clamp(pos_y[i], WALL_EPS, BOARD_WIDTH_MINUS_WALL_EPS);
float ex = destination_x[i] - pos_x[i];
float ey = destination_y[i] - pos_y[i];
float e_norm = sqrt(ex * ex + ey * ey);
float e_norm2 = e_norm > EPS ? e_norm : EPS;
float e_norm_inv = 1.0 / e_norm2;
e_x[i] = ex * e_norm_inv;
e_y[i] = ey * e_norm_inv;
float velocity_norm_sq = curr_vel_x[i] * curr_vel_x[i] + curr_vel_y[i] * curr_vel_y[i];
float velocity_norm = sqrt(velocity_norm_sq);
sb_sq[i] = velocity_norm_sq * delta_t_sq;
sb_e_x[i] = e_x[i] * (velocity_norm * delta_t);
sb_e_y[i] = e_y[i] * (velocity_norm * delta_t);
#if !BENCHMARK
if (dump_path && (t % dump_interval == 0)) {
samples.emplace_back(t + 1, i, pos_x[i], pos_y[i], e_x[i], e_y[i], color[i]);
}
#endif
}
}
#if !BENCHMARK
if (dump_path) {
ofstream out(dump_path);
out << "time,id,x,y,p.e.x,p.e.y,color\n";
for (auto &[t, id, x, y, e_x, e_y, c] : samples) {
out << t << ',' << id << ',' << x << ',' << y << ',' << e_x << ',' << e_y << ',' << c << '\n';
}
}
#endif
return 0;
}