Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

looking at changes #38

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e8ca9ab
Update README.md
Xuan-1998 Dec 10, 2022
a7b4bbc
Putting speed into person data
Xuan-1998 Dec 10, 2022
e31342f
adding speed, edges and travel time
Xuan-1998 Dec 10, 2022
4696952
updating outputs
Xuan-1998 Dec 10, 2022
c253d1c
fix bugs in person data
Xuan-1998 Dec 10, 2022
fa27d9b
calculate speed for each hour
Xuan-1998 Dec 10, 2022
2f09fed
adding columns
Xuan-1998 Dec 11, 2022
dc1b62c
updating output and checking currentTime
Xuan-1998 Dec 11, 2022
5d8a22f
fix bugs of printing
Xuan-1998 Dec 11, 2022
f7394b3
adding right " to fix bug
Xuan-1998 Dec 11, 2022
b29a4d3
dismissing debugger
Xuan-1998 Dec 11, 2022
f3e06cc
pringting even if there is no next
Xuan-1998 Dec 11, 2022
207ba73
speed correction
Xuan-1998 Dec 11, 2022
f8fe533
using dynamic routing
Xuan-1998 Dec 11, 2022
c038ac3
Update command_line_options.ini
Xuan-1998 Dec 11, 2022
cc6832e
Update command_line_options.ini
Xuan-1998 Dec 11, 2022
1244be3
fix bug for dynamic routing
Xuan-1998 Dec 11, 2022
a1f97ec
fixing dynamic routing bugs
Xuan-1998 Dec 11, 2022
965ec47
fix edge number bugs
Xuan-1998 Dec 11, 2022
b21e41e
get rid of illegal memory access
Xuan-1998 Dec 11, 2022
0912432
Update command_line_options.ini
Xuan-1998 Dec 11, 2022
4867960
dynamic planning bugs
Xuan-1998 Dec 11, 2022
c354a42
Update command_line_options.ini
Xuan-1998 Dec 11, 2022
eb95b71
Update command_line_options.ini
Xuan-1998 Dec 11, 2022
cb4c39e
Update command_line_options.ini
Xuan-1998 Dec 11, 2022
f53f698
Update command_line_options.ini
Xuan-1998 Dec 11, 2022
c8de540
reset
Xuan-1998 Dec 11, 2022
39594c6
Update command_line_options.ini
Xuan-1998 Dec 11, 2022
55aaabb
Update b18CUDA_trafficSimulator.cu
Xuan-1998 Dec 11, 2022
81a37c0
2 timestep
Xuan-1998 Dec 11, 2022
613a0fe
solving runtime error for rerouting
Xuan-1998 Dec 22, 2022
ca42771
finish adding speed, time on the edge, travel time
Jan 30, 2023
1237737
fix bugs
Jan 30, 2023
c80b4ee
comparison
Xuan-1998 Jan 31, 2023
8eacf14
Update b18TrafficSimulator.cpp
Xuan-1998 Jan 31, 2023
e8d6f52
Update b18CUDA_trafficSimulator.cu
Xuan-1998 Jan 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added LivingCity/.DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions LivingCity/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ build/
obj/
x64/


# Vim swap files
*.swp
*.info
.csv

102 changes: 102 additions & 0 deletions LivingCity/traffic/b18CUDA_trafficSimulator.cu
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "b18TrafficPerson.h"
#include "b18EdgeData.h"
#include <vector>
#include <thrust/device_vector.h>
#include <iostream>

#include "../../src/benchmarker.h"
Expand Down Expand Up @@ -520,6 +521,30 @@ __global__ void kernel_trafficSimulation(

assert(trafficPersonVec[p].indexPathCurr < indexPathVec_d_size);
if (indexPathVec[trafficPersonVec[p].indexPathCurr] == END_OF_PATH) {
float elapsed_s = (trafficPersonVec[p].end_time_on_prev_edge - trafficPersonVec[p].start_time_on_prev_edge); //multiply by delta_time to get seconds elapsed (not half seconds)

// We filter whenever elapsed_s == 0, which means the time granularity was not enough to measure the speed
// We also filter whenever 0 > elapsed_s > 5, because it causes manual_v to turn extraordinarily high
assert(trafficPersonVec[p].prevEdge < edgesData_d_size);
if (trafficPersonVec[p].window_flag < 100) {

if (trafficPersonVec[p].window_flag == 0) {
// trafficPersonVec[p].avg_speed[trafficPersonVec[p].window_flag] = edgesData[trafficPersonVec[p].prevEdge].length / elapsed_s;
// trafficPersonVec[p].prevEdge_array[trafficPersonVec[p].window_flag] = trafficPersonVec[p].prevEdge;
trafficPersonVec[p].travel_time[trafficPersonVec[p].window_flag] = elapsed_s;
// trafficPersonVec[p].end_time_on_prev_edge_array[trafficPersonVec[p].window_flag] = trafficPersonVec[p].end_time_on_prev_edge;
// printf("%f", trafficPersonVec[p].travel_time[trafficPersonVec[p].window_flag]);
trafficPersonVec[p].window_flag++;
} else {
if (trafficPersonVec[p].travel_time[trafficPersonVec[p].window_flag - 1] != elapsed_s) {
// trafficPersonVec[p].avg_speed[trafficPersonVec[p].window_flag] = edgesData[trafficPersonVec[p].prevEdge].length / elapsed_s;
// trafficPersonVec[p].prevEdge_array[trafficPersonVec[p].window_flag] = trafficPersonVec[p].prevEdge;
trafficPersonVec[p].travel_time[trafficPersonVec[p].window_flag] = elapsed_s;
// trafficPersonVec[p].end_time_on_prev_edge_array[trafficPersonVec[p].window_flag] = trafficPersonVec[p].end_time_on_prev_edge;
trafficPersonVec[p].window_flag++;
}
}
}
trafficPersonVec[p].active = 2; //finished
return;
}
Expand All @@ -536,6 +561,30 @@ __global__ void kernel_trafficSimulation(
trafficPersonVec[p].last_time_simulated = currentTime;

if (firstEdge == END_OF_PATH) {
float elapsed_s = (trafficPersonVec[p].end_time_on_prev_edge - trafficPersonVec[p].start_time_on_prev_edge); //multiply by delta_time to get seconds elapsed (not half seconds)

// We filter whenever elapsed_s == 0, which means the time granularity was not enough to measure the speed
// We also filter whenever 0 > elapsed_s > 5, because it causes manual_v to turn extraordinarily high
assert(trafficPersonVec[p].prevEdge < edgesData_d_size);
if (trafficPersonVec[p].window_flag < 100) {

if (trafficPersonVec[p].window_flag == 0) {
// trafficPersonVec[p].avg_speed[trafficPersonVec[p].window_flag] = edgesData[trafficPersonVec[p].prevEdge].length / elapsed_s;
// trafficPersonVec[p].prevEdge_array[trafficPersonVec[p].window_flag] = trafficPersonVec[p].prevEdge;
trafficPersonVec[p].travel_time[trafficPersonVec[p].window_flag] = elapsed_s;
// trafficPersonVec[p].end_time_on_prev_edge_array[trafficPersonVec[p].window_flag] = trafficPersonVec[p].end_time_on_prev_edge;
// printf("%f", trafficPersonVec[p].travel_time[trafficPersonVec[p].window_flag]);
trafficPersonVec[p].window_flag++;
} else {
if (trafficPersonVec[p].travel_time[trafficPersonVec[p].window_flag - 1] != elapsed_s) {
// trafficPersonVec[p].avg_speed[trafficPersonVec[p].window_flag] = edgesData[trafficPersonVec[p].prevEdge].length / elapsed_s;
// trafficPersonVec[p].prevEdge_array[trafficPersonVec[p].window_flag] = trafficPersonVec[p].prevEdge;
trafficPersonVec[p].travel_time[trafficPersonVec[p].window_flag] = elapsed_s;
// trafficPersonVec[p].end_time_on_prev_edge_array[trafficPersonVec[p].window_flag] = trafficPersonVec[p].end_time_on_prev_edge;
trafficPersonVec[p].window_flag++;
}
}
}
trafficPersonVec[p].active = 2;
return;
}
Expand Down Expand Up @@ -625,22 +674,51 @@ __global__ void kernel_trafficSimulation(
//2.1 try to move
float numMToMove;
bool nextVehicleIsATrafficLight = false;




//when we're on a new edge for the first time
if (currentEdge == trafficPersonVec[p].nextEdge) {




trafficPersonVec[p].end_time_on_prev_edge = currentTime - deltaTime;
float elapsed_s = (trafficPersonVec[p].end_time_on_prev_edge - trafficPersonVec[p].start_time_on_prev_edge); //multiply by delta_time to get seconds elapsed (not half seconds)

// We filter whenever elapsed_s == 0, which means the time granularity was not enough to measure the speed
// We also filter whenever 0 > elapsed_s > 5, because it causes manual_v to turn extraordinarily high
assert(trafficPersonVec[p].prevEdge < edgesData_d_size);
if (trafficPersonVec[p].window_flag < 100) {

if (trafficPersonVec[p].window_flag == 0) {
// trafficPersonVec[p].avg_speed[trafficPersonVec[p].window_flag] = edgesData[trafficPersonVec[p].prevEdge].length / elapsed_s;
// trafficPersonVec[p].prevEdge_array[trafficPersonVec[p].window_flag] = trafficPersonVec[p].prevEdge;
trafficPersonVec[p].travel_time[trafficPersonVec[p].window_flag] = elapsed_s;
// trafficPersonVec[p].end_time_on_prev_edge_array[trafficPersonVec[p].window_flag] = trafficPersonVec[p].end_time_on_prev_edge;
// printf("%f", trafficPersonVec[p].travel_time[trafficPersonVec[p].window_flag]);
trafficPersonVec[p].window_flag++;
} else {
if (trafficPersonVec[p].travel_time[trafficPersonVec[p].window_flag] != elapsed_s) {
// trafficPersonVec[p].avg_speed[trafficPersonVec[p].window_flag] = edgesData[trafficPersonVec[p].prevEdge].length / elapsed_s;
// trafficPersonVec[p].prevEdge_array[trafficPersonVec[p].window_flag] = trafficPersonVec[p].prevEdge;
trafficPersonVec[p].travel_time[trafficPersonVec[p].window_flag] = elapsed_s;
// trafficPersonVec[p].end_time_on_prev_edge_array[trafficPersonVec[p].window_flag] = trafficPersonVec[p].end_time_on_prev_edge;
trafficPersonVec[p].window_flag++;
}
}
}



if (elapsed_s > MINIMUM_NUMBER_OF_CARS_TO_MEASURE_SPEED) {
trafficPersonVec[p].manual_v = edgesData[trafficPersonVec[p].prevEdge].length / elapsed_s;
edgesData[trafficPersonVec[p].prevEdge].curr_iter_num_cars += 1;
edgesData[trafficPersonVec[p].prevEdge].curr_cum_vel += trafficPersonVec[p].manual_v;
}


trafficPersonVec[p].start_time_on_prev_edge = currentTime;
trafficPersonVec[p].prevEdge = currentEdge;
}
Expand Down Expand Up @@ -806,6 +884,30 @@ __global__ void kernel_trafficSimulation(
trafficPersonVec[p].LC_initOKLanes = 0xFF;
trafficPersonVec[p].LC_endOKLanes = 0xFF;
} else {
float elapsed_s = (trafficPersonVec[p].end_time_on_prev_edge - trafficPersonVec[p].start_time_on_prev_edge); //multiply by delta_time to get seconds elapsed (not half seconds)

// We filter whenever elapsed_s == 0, which means the time granularity was not enough to measure the speed
// We also filter whenever 0 > elapsed_s > 5, because it causes manual_v to turn extraordinarily high
assert(trafficPersonVec[p].prevEdge < edgesData_d_size);
if (trafficPersonVec[p].window_flag < 100) {

if (trafficPersonVec[p].window_flag == 0) {
// trafficPersonVec[p].avg_speed[trafficPersonVec[p].window_flag] = edgesData[trafficPersonVec[p].prevEdge].length / elapsed_s;
// trafficPersonVec[p].prevEdge_array[trafficPersonVec[p].window_flag] = trafficPersonVec[p].prevEdge;
trafficPersonVec[p].travel_time[trafficPersonVec[p].window_flag] = elapsed_s;
// trafficPersonVec[p].end_time_on_prev_edge_array[trafficPersonVec[p].window_flag] = trafficPersonVec[p].end_time_on_prev_edge;
// printf("%f", trafficPersonVec[p].travel_time[trafficPersonVec[p].window_flag]);
trafficPersonVec[p].window_flag++;
} else {
if (trafficPersonVec[p].travel_time[trafficPersonVec[p].window_flag - 1] != elapsed_s) {
// trafficPersonVec[p].avg_speed[trafficPersonVec[p].window_flag] = edgesData[trafficPersonVec[p].prevEdge].length / elapsed_s;
// trafficPersonVec[p].prevEdge_array[trafficPersonVec[p].window_flag] = trafficPersonVec[p].prevEdge;
trafficPersonVec[p].travel_time[trafficPersonVec[p].window_flag] = elapsed_s;
// trafficPersonVec[p].end_time_on_prev_edge_array[trafficPersonVec[p].window_flag] = trafficPersonVec[p].end_time_on_prev_edge;
trafficPersonVec[p].window_flag++;
}
}
}
trafficPersonVec[p].active == 2;
}
trafficPersonVec[p].indexPathCurr++;
Expand Down
9 changes: 8 additions & 1 deletion LivingCity/traffic/b18TrafficPerson.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
* @author igaciad
*
************************************************************************************************/

using namespace std;
#include <vector>
#include <thrust/device_vector.h>
#ifndef LC_B18_TRAFFIC_PERSON_H
#define LC_B18_TRAFFIC_PERSON_H

Expand All @@ -16,9 +18,14 @@ namespace LC {
struct B18TrafficPerson {
unsigned int init_intersection;
unsigned int end_intersection;
unsigned int window_flag = 0;
float time_departure;
float dist_traveled = 0;
float last_time_simulated = 0;
float avg_speed[100];
unsigned int prevEdge_array[100];
float travel_time[100];
float end_time_on_prev_edge_array[100];

unsigned short active;//0 inactive 1 active 2 finished
unsigned short numOfLaneInEdge;//number of lane in that edge
Expand Down
58 changes: 45 additions & 13 deletions LivingCity/traffic/b18TrafficSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void B18TrafficSimulator::updateEdgeImpedances(
float new_impedance;
if (edgesData.at(ind).curr_cum_vel != 0) {
avg_edge_vel[index] = edgesData.at(ind).curr_cum_vel / edgesData.at(ind).curr_iter_num_cars;// * 2.23694;
new_impedance = edgesData.at(ind).length / avg_edge_vel[index];
new_impedance = edgesData.at(ind).length / avg_edge_vel[index];
auto cum_vel = edgesData.at(ind).curr_cum_vel;
auto num_cars = edgesData.at(ind).curr_iter_num_cars;
auto avg_edge_vel_index = avg_edge_vel[index];
Expand Down Expand Up @@ -375,16 +375,16 @@ void B18TrafficSimulator::simulateInGPU(const int numOfPasses, const float start
b18GetSampleTrafficCUDA(accSpeedPerLinePerTimeInterval,
numVehPerLinePerTimeInterval);

for (int i = 0; i < trafficPersonVec.size(); i++) {
if ((trafficPersonVec[i].time_departure < currentBatchEndTimeSecs && trafficPersonVec[i].active == 0) ||
(isgreaterequal(trafficPersonVec[i].time_departure, currentBatchEndTimeSecs) && trafficPersonVec[i].active != 0)) {
std::string errorMessage =
"Person " + std::to_string(i) + " has active state " +
std::to_string(trafficPersonVec[i].active) + " and dep time " +
std::to_string(trafficPersonVec[i].time_departure);
throw std::runtime_error(errorMessage);
}
}
// for (int i = 0; i < trafficPersonVec.size(); i++) {
// if ((trafficPersonVec[i].time_departure < currentBatchEndTimeSecs && trafficPersonVec[i].active == 0) ||
// (isgreaterequal(trafficPersonVec[i].time_departure, currentBatchEndTimeSecs) && trafficPersonVec[i].active != 0)) {
// std::string errorMessage =
// "Person " + std::to_string(i) + " has active state " +
// std::to_string(trafficPersonVec[i].active) + " and dep time " +
// std::to_string(trafficPersonVec[i].time_departure);
// throw std::runtime_error(errorMessage);
// }
// }

printFullProgressBar();

Expand Down Expand Up @@ -2469,19 +2469,51 @@ void writePeopleFile(
int start_time, int end_time,
const std::vector<B18TrafficPerson> &trafficPersonVec,
float deltaTime){

QFile peopleFile(QString::number(numOfPass) + "_people" + QString::number(start_time) + "to" + QString::number(end_time) + ".csv");
if (peopleFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
std::cout << "> Saving People file... (size " << trafficPersonVec.size() << ")" << std::endl;
QTextStream streamP(&peopleFile);
streamP << "p,init_intersection,end_intersection,time_departure,num_steps,co,gas,distance,a,b,T,avg_v(mph),active,last_time_simulated,path_length_cpu,path_length_gpu\n";

// streamP << "p,init_intersection,end_intersection,time_departure,num_steps,co,avg_speed,prevEdge,travel_time,endtimeonprevEdge,gas,distance,a,b,T,avg_v(mph),active,last_time_simulated,path_length_cpu,path_length_gpu\n";
streamP << "p,init_intersection,end_intersection,time_departure,num_steps,co,travel_time,gas,distance,a,b,T,avg_v(mph),active,last_time_simulated,path_length_cpu,path_length_gpu\n";
for (int p = 0; p < trafficPersonVec.size(); p++) {
// int n = sizeof(trafficPersonVec[p].avg_speed)/sizeof(trafficPersonVec[p].avg_speed[0]);
// QString str = "";
// for (int i = 0; i < n; i++) {
// str += QString::fromStdString(to_string(trafficPersonVec[p].avg_speed[i])) + QString::fromStdString(" ");
// }
// int n1 = sizeof(trafficPersonVec[p].prevEdge_array)/sizeof(trafficPersonVec[p].prevEdge_array[0]);
// QString str1 = "";
// for (int i = 0; i < n1; i++) {
// str1 += QString::fromStdString(to_string(trafficPersonVec[p].prevEdge_array[i])) + QString::fromStdString(" ");
// }
int n2 = sizeof(trafficPersonVec[p].travel_time)/sizeof(trafficPersonVec[p].travel_time[0]);

QString str2 = "";
for (int i = 0; i < n2; i++) {
str2 += QString::fromStdString(to_string(trafficPersonVec[p].travel_time[i])) + QString::fromStdString(" ");
}
// int n3 = sizeof(trafficPersonVec[p].end_time_on_prev_edge_array)/sizeof(trafficPersonVec[p].end_time_on_prev_edge_array[0]);

// QString str3 = "";
// for (int i = 0; i < n3; i++) {
// str3 += QString::fromStdString(to_string(trafficPersonVec[p].end_time_on_prev_edge_array[i])) + QString::fromStdString(" ");
// }
streamP << p;
streamP << "," << graph_->nodeIndex_to_osmid_[trafficPersonVec[p].init_intersection];
streamP << "," << graph_->nodeIndex_to_osmid_[trafficPersonVec[p].end_intersection];
streamP << "," << trafficPersonVec[p].time_departure;
streamP << "," << trafficPersonVec[p].num_steps * deltaTime;
streamP << "," << trafficPersonVec[p].co;
// streamP << "," << str;
// streamP << "," << str1;
streamP << "," << str2;
// streamP << "," << str3;





streamP << "," << trafficPersonVec[p].gas;
streamP << "," << trafficPersonVec[p].dist_traveled;
streamP << "," << trafficPersonVec[p].a;
Expand Down
6 changes: 6 additions & 0 deletions LivingCity/traffic/cudaTrafficPerson.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ struct CUDATrafficPerson {
unsigned short init_intersection;
unsigned short end_intersection;
float time_departure;

unsigned int window_flag = 0;
float avg_speed[100];
unsigned int prevEdge_array[100];
float travel_time[100];
float end_time_on_prev_edge_array[100];

unsigned short active;//0 inactive 1 active 2 finished
//unsigned short curEdgeLane;// edge number
Expand Down
Loading