diff --git a/main.cpp b/main.cpp index 248d4f6..0d22f7e 100644 --- a/main.cpp +++ b/main.cpp @@ -26,6 +26,16 @@ struct Vector2d { } }; +struct Sidewalk{ + int row, col; + double length, width; + Sidewalk(int r, int c, double l, double w) : row(r), col(c), length(l), width(w) {} +}; + +struct Cell{ + // TODO: cell stores information such as next neighbor +}; + // Numer of pedestrians // $n_p$ const int n_p = 100; @@ -38,9 +48,58 @@ const int n_iter = 100; // $\tau$ const double tau = 0.12345; -void compute_acceleration_term(Vector2d *F_i) {} -void compute_repulsive_effects_from_pedestrians(Vector2d *F_i) {} -void compute_repulsive_effects_from_borders(Vector2d *F_i) {} +// F_i is the current position resp. direction vector of pedestrian p in time i? +void compute_acceleration_term(Vector2d *F_i, Vector2d curr, Vector2d next) { + // get curr pos --> probably no needed, can be read in F_i + + // get next pos --> call shortest path --> how to encode map? + + // get desired velocity + // desired speed * desired direction + + // get actual velocity + // actual speed * actual direction + + // TODO: how to get next node? + + // acceleration * desired speed + double v_desired = 0.0; + + double v_actual = 0.0; + + double res = (1 / tau) * (v_desired - v_actual); + + +} + +Vector2d get_next_node(Vector2d curr_pos, Vector2d map[]) { + // dummy element + return Vector2d(curr_pos.x + 1.0, curr_pos.y + 1.0); +} + +// return the direction between two nodes along the shortest path +Vector2d get_direction(Vector2d curr_pos, Vector2d next_pos) { + double x, y, x1, x2, y1, y2; + + x1 = curr_pos.x; + x2 = next_pos.x; + y1 = curr_pos.y; + y2 = next_pos.y; + + x = (x2 - x1) / abs(x2 - x1); + y = (y2 - y1) / abs(y2 - y1); + + return Vector2d(x, y); +} + + +void compute_repulsive_effects_from_pedestrians(Vector2d *F_i) { + +} + +void compute_repulsive_effects_from_borders(Vector2d *F_i) { + +} // Return an array of doubles double *w(Vector2d e, Vector2d f) { diff --git a/tsc_x86.h b/tsc_x86.h new file mode 100644 index 0000000..4e4baf4 --- /dev/null +++ b/tsc_x86.h @@ -0,0 +1,94 @@ +/* ==================== GNU C and possibly other UNIX compilers ===================== */ + #ifndef _WIN32 + + #if defined(__GNUC__) || defined(__linux__) + #define VOLATILE __volatile__ + #define ASM __asm__ + #else + /* if we're neither compiling with gcc or under linux, we can hope + * the following lines work, they probably won't */ + #define ASM asm + #define VOLATILE + #endif + + #define myInt64 unsigned long long + #define INT32 unsigned int + +/* ======================== WIN32 ======================= */ +#else + + #define myInt64 signed __int64 + #define INT32 unsigned __int32 + +#endif + +/* This is the RDTSC timer. + * RDTSC is an instruction on several Intel and compatible CPUs that Reads the + * Time Stamp Counter. The Intel manuals contain more information. + */ + + +#define COUNTER_LO(a) ((a).int32.lo) +#define COUNTER_HI(a) ((a).int32.hi) +#define COUNTER_VAL(a) ((a).int64) + +#define COUNTER(a) \ + ((unsigned long long)COUNTER_VAL(a)) + +#define COUNTER_DIFF(a,b) \ + (COUNTER(a)-COUNTER(b)) + +/* ==================== GNU C and possibly other UNIX compilers ===================== */ +#ifndef _WIN32 + + typedef union + { myInt64 int64; + struct {INT32 lo, hi;} int32; + } tsc_counter; + + #define RDTSC(cpu_c) \ + ASM VOLATILE ("rdtsc" : "=a" ((cpu_c).int32.lo), "=d"((cpu_c).int32.hi)) + #define CPUID() \ + ASM VOLATILE ("cpuid" : : "a" (0) : "bx", "cx", "dx" ) + +/* ======================== WIN32 ======================= */ +#else + + typedef union + { myInt64 int64; + struct {INT32 lo, hi;} int32; + } tsc_counter; + + #define RDTSC(cpu_c) \ + { __asm rdtsc \ + __asm mov (cpu_c).int32.lo,eax \ + __asm mov (cpu_c).int32.hi,edx \ + } + + #define CPUID() \ + { \ + __asm mov eax, 0 \ + __asm cpuid \ + } + +#endif + + +static void init_tsc() { + ; // no need to initialize anything for x86 +} + +static myInt64 start_tsc(void) { + tsc_counter start; + CPUID(); + RDTSC(start); + return COUNTER_VAL(start); +} + +static myInt64 stop_tsc(myInt64 start) { + tsc_counter end; + RDTSC(end); + CPUID(); + return COUNTER_VAL(end) - start; +} +