From aac0adf1696788f74610cbb1e1e049fc2378a5ef Mon Sep 17 00:00:00 2001 From: hiwis <hiwis@irmb.tu-bs.de> Date: Thu, 11 Apr 2019 14:19:10 +0200 Subject: [PATCH] changed curves from using junctions to using neighbors --- .../StreetPointFinder/JunctionReader.cpp | 27 +++++++++++++++---- .../StreetPointFinder/JunctionReader.h | 9 +++++++ src/Traffic/GPU/TrafficTimestep.cu | 2 +- src/Traffic/TrafficMovement.cpp | 2 +- src/Traffic/TrafficMovementFactory.cpp | 8 +++++- .../apps/LBM/Basel/resources/Junctions.txt | 6 ++--- .../Basel/resources/allStreets/Junctions.txt | 6 ++--- .../Basel/resources/fourStreets/Junctions.txt | 2 +- .../resources/testStreets/Junctions5.txt | 3 +++ .../Basel/resources/testStreets/Sinks5.txt | 3 +++ .../Basel/resources/testStreets/Sources5.txt | 4 +++ .../Basel/resources/testStreets/Streets5.txt | 6 +++++ 12 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 targets/apps/LBM/Basel/resources/testStreets/Junctions5.txt create mode 100644 targets/apps/LBM/Basel/resources/testStreets/Sinks5.txt create mode 100644 targets/apps/LBM/Basel/resources/testStreets/Sources5.txt create mode 100644 targets/apps/LBM/Basel/resources/testStreets/Streets5.txt diff --git a/src/GridGenerator/StreetPointFinder/JunctionReader.cpp b/src/GridGenerator/StreetPointFinder/JunctionReader.cpp index 172a48e05..1ce67fb89 100644 --- a/src/GridGenerator/StreetPointFinder/JunctionReader.cpp +++ b/src/GridGenerator/StreetPointFinder/JunctionReader.cpp @@ -6,7 +6,7 @@ JunctionInReader::JunctionInReader(std::vector<uint> inCells, std::vector<uint> outCells, std::vector<int> carCanNotEnterThisOutCell, uint trafficLightSwitchTime = 0) : - inCells{ inCells }, outCells{ outCells }, carCanNotEnterThisOutCell{ carCanNotEnterThisOutCell }, trafficLightSwitchTime{trafficLightSwitchTime} + inCells{ inCells }, outCells{ outCells }, carCanNotEnterThisOutCell{ carCanNotEnterThisOutCell }, trafficLightSwitchTime{ trafficLightSwitchTime } {} void JunctionReader::readJunctions(std::string filename, StreetPointFinder streetPointFinder) @@ -22,8 +22,9 @@ void JunctionReader::readJunctions(std::string filename, StreetPointFinder stree file >> numberOfJunctions; std::string inOutDummy; - int streetIndex; + int streetIndex = 0; uint trafficLightTime = 0; + bool onlyNeighbors = false; file >> inOutDummy; @@ -32,7 +33,7 @@ void JunctionReader::readJunctions(std::string filename, StreetPointFinder stree std::vector<int> carCanNotEnterThisOutCell; //inCells - file >> inOutDummy; + file >> inOutDummy; while (inOutDummy.compare("out") != 0) { streetIndex = std::stoi(inOutDummy); @@ -44,7 +45,7 @@ void JunctionReader::readJunctions(std::string filename, StreetPointFinder stree //outCells file >> inOutDummy; - while (inOutDummy.compare("in") != 0 && inOutDummy.compare("end") !=0 && inOutDummy.compare("t") != 0) { + while (inOutDummy.compare("in") != 0 && inOutDummy.compare("end") != 0 && inOutDummy.compare("t") != 0 && inOutDummy.compare("c") != 0) { streetIndex = std::stoi(inOutDummy); if (streetIndex >= 0) { @@ -67,8 +68,24 @@ void JunctionReader::readJunctions(std::string filename, StreetPointFinder stree else trafficLightTime = 0; + // only neighbors (used for curves) + if (inOutDummy.compare("c") == 0) { + onlyNeighbors = true; + } + //make Junction - junctions.push_back(JunctionInReader(inCells, outCells, carCanNotEnterThisOutCell, trafficLightTime)); + if (onlyNeighbors) { + if (inCells.size() == outCells.size()) { + specialNeighbors.cells.insert(specialNeighbors.cells.end(), inCells.begin(), inCells.end()); + std::reverse(outCells.begin(), outCells.end()); + specialNeighbors.neighbors.insert(specialNeighbors.neighbors.end(), outCells.begin(), outCells.end()); + onlyNeighbors = false; + } + else std::cerr << "can't add curve" << std::endl; continue; + } + else + junctions.push_back(JunctionInReader(inCells, outCells, carCanNotEnterThisOutCell, trafficLightTime)); + } } diff --git a/src/GridGenerator/StreetPointFinder/JunctionReader.h b/src/GridGenerator/StreetPointFinder/JunctionReader.h index 93c09bcc5..b57bf3bc5 100644 --- a/src/GridGenerator/StreetPointFinder/JunctionReader.h +++ b/src/GridGenerator/StreetPointFinder/JunctionReader.h @@ -21,9 +21,18 @@ struct VF_PUBLIC JunctionInReader }; +struct VF_PUBLIC Neighbors +{ + std::vector<int> cells; + std::vector<int> neighbors; +}; + + + struct VF_PUBLIC JunctionReader { std::vector<JunctionInReader> junctions; + Neighbors specialNeighbors; StreetPointFinder streetPointFinder; void readJunctions(std::string filename, StreetPointFinder streetPointFinder); diff --git a/src/Traffic/GPU/TrafficTimestep.cu b/src/Traffic/GPU/TrafficTimestep.cu index f6775ef3e..58cddc7de 100644 --- a/src/Traffic/GPU/TrafficTimestep.cu +++ b/src/Traffic/GPU/TrafficTimestep.cu @@ -325,7 +325,7 @@ __global__ void trafficTimestepKernel(int* roadCurrent, int* roadNext, int* neig //////// brake car ///////////////////////////////////////////////////////////////////////// //getGapAfterCar - uint gap = maxVelocity; + uint gap = speed; uint idx = 0; int neighbor = neighbors[index]; uint currentCell = index; diff --git a/src/Traffic/TrafficMovement.cpp b/src/Traffic/TrafficMovement.cpp index 2873b34cc..f3b0e0a3d 100644 --- a/src/Traffic/TrafficMovement.cpp +++ b/src/Traffic/TrafficMovement.cpp @@ -213,7 +213,7 @@ void TrafficMovement::calculateTimestep(uint step) //if (useGPU) dispCurrentConcFromGPU(); //else if (concWriter != nullptr) concWriter->dispCurrentConcentrations(); - //currentStep += 1; + currentStep += 1; } diff --git a/src/Traffic/TrafficMovementFactory.cpp b/src/Traffic/TrafficMovementFactory.cpp index 36d824857..69c6c1f5d 100644 --- a/src/Traffic/TrafficMovementFactory.cpp +++ b/src/Traffic/TrafficMovementFactory.cpp @@ -34,7 +34,7 @@ void TrafficMovementFactory::initTrafficMovement(std::string path, real * pConcA real dawdlePossibility = (real) 0.2; //typical value: 0.2 real slowToStartPossibility = (real) 0.3; - bool useGPU = true; + bool useGPU = false; bool useSlowToStart = true; useLogger = true; @@ -115,6 +115,12 @@ void TrafficMovementFactory::initTrafficMovement(std::string path, real * pConcA roadNetwork->setJunctions(move(junctions)); + //set neighbors for curves + for (uint i = 0; i < junctionReader.specialNeighbors.cells.size(); i++) { + roadNetwork->setNeighbor(junctionReader.specialNeighbors.cells[i], junctionReader.specialNeighbors.neighbors[i]); + } + + //init TrafficMovement this->simulator = std::make_shared<TrafficMovement>(move(roadNetwork), dawdlePossibility); simulator->setMaxAcceleration(maxAcceleration); diff --git a/targets/apps/LBM/Basel/resources/Junctions.txt b/targets/apps/LBM/Basel/resources/Junctions.txt index ac0fcf41d..414c35fa9 100644 --- a/targets/apps/LBM/Basel/resources/Junctions.txt +++ b/targets/apps/LBM/Basel/resources/Junctions.txt @@ -6,7 +6,7 @@ in 48 58 45 out 47 46 44 in 33 15 3 out 31 4 16 t 46 in 43 31 32 out 42 33 29 in 34 28 29 38 out 35 32 30 36 -in 30 27 out 28 26 +in 30 27 out 28 26 c in 16 12 18 2 out 3 21 6 13 t 55 in 26 113 13 1 out 27 114 2 19 t 31 in 105 19 0 out 106 1 20 t 35 @@ -27,6 +27,6 @@ in 56 54 51 out 55 52 53 in 53 60 17 6 out 51 59 7 18 t 30 in 59 66 62 63 out 60 65 61 64 in 67 73 72 69 out 68 74 70 71 -in 65 68 out 66 67 -in 118 71 out 117 72 +in 65 68 out 66 67 c +in 118 71 out 117 72 c end \ No newline at end of file diff --git a/targets/apps/LBM/Basel/resources/allStreets/Junctions.txt b/targets/apps/LBM/Basel/resources/allStreets/Junctions.txt index ac0fcf41d..414c35fa9 100644 --- a/targets/apps/LBM/Basel/resources/allStreets/Junctions.txt +++ b/targets/apps/LBM/Basel/resources/allStreets/Junctions.txt @@ -6,7 +6,7 @@ in 48 58 45 out 47 46 44 in 33 15 3 out 31 4 16 t 46 in 43 31 32 out 42 33 29 in 34 28 29 38 out 35 32 30 36 -in 30 27 out 28 26 +in 30 27 out 28 26 c in 16 12 18 2 out 3 21 6 13 t 55 in 26 113 13 1 out 27 114 2 19 t 31 in 105 19 0 out 106 1 20 t 35 @@ -27,6 +27,6 @@ in 56 54 51 out 55 52 53 in 53 60 17 6 out 51 59 7 18 t 30 in 59 66 62 63 out 60 65 61 64 in 67 73 72 69 out 68 74 70 71 -in 65 68 out 66 67 -in 118 71 out 117 72 +in 65 68 out 66 67 c +in 118 71 out 117 72 c end \ No newline at end of file diff --git a/targets/apps/LBM/Basel/resources/fourStreets/Junctions.txt b/targets/apps/LBM/Basel/resources/fourStreets/Junctions.txt index 311a023cd..fca1e6e71 100644 --- a/targets/apps/LBM/Basel/resources/fourStreets/Junctions.txt +++ b/targets/apps/LBM/Basel/resources/fourStreets/Junctions.txt @@ -1,4 +1,4 @@ 2 in 1 7 6 4 out 5 3 2 9 t 45 -in 0 5 out 8 1 t 0 +in 0 5 out 8 1 c end \ No newline at end of file diff --git a/targets/apps/LBM/Basel/resources/testStreets/Junctions5.txt b/targets/apps/LBM/Basel/resources/testStreets/Junctions5.txt new file mode 100644 index 000000000..505c5fca9 --- /dev/null +++ b/targets/apps/LBM/Basel/resources/testStreets/Junctions5.txt @@ -0,0 +1,3 @@ +1 +in 4 3 1 out -2 2 0 t 30 +end \ No newline at end of file diff --git a/targets/apps/LBM/Basel/resources/testStreets/Sinks5.txt b/targets/apps/LBM/Basel/resources/testStreets/Sinks5.txt new file mode 100644 index 000000000..963602302 --- /dev/null +++ b/targets/apps/LBM/Basel/resources/testStreets/Sinks5.txt @@ -0,0 +1,3 @@ +2 +0 0.5 +2 0.5 diff --git a/targets/apps/LBM/Basel/resources/testStreets/Sources5.txt b/targets/apps/LBM/Basel/resources/testStreets/Sources5.txt new file mode 100644 index 000000000..6ff2b74df --- /dev/null +++ b/targets/apps/LBM/Basel/resources/testStreets/Sources5.txt @@ -0,0 +1,4 @@ +3 +1 0.4 +3 0.4 +4 0.4 \ No newline at end of file diff --git a/targets/apps/LBM/Basel/resources/testStreets/Streets5.txt b/targets/apps/LBM/Basel/resources/testStreets/Streets5.txt new file mode 100644 index 000000000..64aa5c46a --- /dev/null +++ b/targets/apps/LBM/Basel/resources/testStreets/Streets5.txt @@ -0,0 +1,6 @@ +5 + 0 0 256 0 1 + 256 5 0 5 1 + 0 5 0 256 1 + -5 256 -5 5 1 + -256 0 -5 0 1 -- GitLab