From b9e91363e9c148c5472c13bbf5b72a097e596420 Mon Sep 17 00:00:00 2001 From: hiwis <hiwis@irmb.tu-bs.de> Date: Mon, 15 Apr 2019 10:37:12 +0200 Subject: [PATCH] changed StreetPointFinder in Readers to pointer --- .../StreetPointFinder/JunctionReader.cpp | 6 ++--- .../StreetPointFinder/JunctionReader.h | 4 +-- .../StreetPointFinder/SinkReader.cpp | 6 ++--- .../StreetPointFinder/SinkReader.h | 4 +-- .../StreetPointFinder/SourceReader.cpp | 4 +-- .../StreetPointFinder/SourceReader.h | 4 +-- src/Traffic/Junction/JunctionData.h | 1 + src/Traffic/Junction/JunctionRandom.cpp | 27 +++++++++---------- src/Traffic/Junction/JunctionRandom.h | 6 ++--- src/Traffic/TrafficMovementFactory.cpp | 6 ++--- 10 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/GridGenerator/StreetPointFinder/JunctionReader.cpp b/src/GridGenerator/StreetPointFinder/JunctionReader.cpp index c0ebd8b88..438f9ddd9 100644 --- a/src/GridGenerator/StreetPointFinder/JunctionReader.cpp +++ b/src/GridGenerator/StreetPointFinder/JunctionReader.cpp @@ -9,7 +9,7 @@ JunctionReaderData::JunctionReaderData(std::vector<uint> inCells, std::vector<ui inCells{ inCells }, outCells{ outCells }, carCanNotEnterThisOutCell{ carCanNotEnterThisOutCell }, trafficLightSwitchTime{ trafficLightSwitchTime } {} -void JunctionReader::readJunctions(std::string filename, StreetPointFinder streetPointFinder) +void JunctionReader::readJunctions(std::string filename, StreetPointFinder* streetPointFinder) { *logging::out << logging::Logger::INFO_INTERMEDIATE << "StreetPointFinder::readJunctions( " << filename << " )" << "\n"; @@ -97,10 +97,10 @@ unsigned int JunctionReader::getCellIndex(unsigned int streetIndex, char startOr uint i = 0; unsigned int cellIndex = 0; while (i < streetIndex) { - cellIndex += streetPointFinder.streets[i].numberOfCells; + cellIndex += streetPointFinder->streets[i].numberOfCells; ++i; } if (startOrEnd == 's') return cellIndex; - return cellIndex + streetPointFinder.streets[streetIndex].numberOfCells - 1; + return cellIndex + streetPointFinder->streets[streetIndex].numberOfCells - 1; } diff --git a/src/GridGenerator/StreetPointFinder/JunctionReader.h b/src/GridGenerator/StreetPointFinder/JunctionReader.h index 015e7d33d..a53d27521 100644 --- a/src/GridGenerator/StreetPointFinder/JunctionReader.h +++ b/src/GridGenerator/StreetPointFinder/JunctionReader.h @@ -33,9 +33,9 @@ struct VF_PUBLIC JunctionReader { std::vector<JunctionReaderData> junctions; Neighbors specialNeighbors; - StreetPointFinder streetPointFinder; + StreetPointFinder* streetPointFinder; - void readJunctions(std::string filename, StreetPointFinder streetPointFinder); + void readJunctions(std::string filename, StreetPointFinder* streetPointFinder); private: diff --git a/src/GridGenerator/StreetPointFinder/SinkReader.cpp b/src/GridGenerator/StreetPointFinder/SinkReader.cpp index 15eee8a3a..3c3e76689 100644 --- a/src/GridGenerator/StreetPointFinder/SinkReader.cpp +++ b/src/GridGenerator/StreetPointFinder/SinkReader.cpp @@ -7,7 +7,7 @@ SinkReaderData::SinkReaderData(uint sinkIndex, float sinkBlockedPossibility) : sinkIndex{ sinkIndex }, sinkBlockedPossibility{ sinkBlockedPossibility } {} -void SinkReader::readSinks(std::string filename, StreetPointFinder streetPointFinder) +void SinkReader::readSinks(std::string filename, StreetPointFinder* streetPointFinder) { *logging::out << logging::Logger::INFO_INTERMEDIATE << "StreetPointFinder::readSinks( " << filename << " )" << "\n"; @@ -35,9 +35,9 @@ unsigned int SinkReader::getCellIndexEnd(unsigned int streetIndex) uint i = 0; unsigned int cellIndex = 0; while (i < streetIndex) { - cellIndex += streetPointFinder.streets[i].numberOfCells; + cellIndex += streetPointFinder->streets[i].numberOfCells; ++i; } - return cellIndex + streetPointFinder.streets[streetIndex].numberOfCells - 1; + return cellIndex + streetPointFinder->streets[streetIndex].numberOfCells - 1; } diff --git a/src/GridGenerator/StreetPointFinder/SinkReader.h b/src/GridGenerator/StreetPointFinder/SinkReader.h index 323d8acfc..aa5e31519 100644 --- a/src/GridGenerator/StreetPointFinder/SinkReader.h +++ b/src/GridGenerator/StreetPointFinder/SinkReader.h @@ -19,9 +19,9 @@ struct VF_PUBLIC SinkReaderData{ struct VF_PUBLIC SinkReader { std::vector<SinkReaderData> sinks; - StreetPointFinder streetPointFinder; + StreetPointFinder* streetPointFinder; - void readSinks(std::string filename, StreetPointFinder streetPointFinder); + void readSinks(std::string filename, StreetPointFinder* streetPointFinder); private: unsigned int getCellIndexEnd(unsigned int streetIndex); diff --git a/src/GridGenerator/StreetPointFinder/SourceReader.cpp b/src/GridGenerator/StreetPointFinder/SourceReader.cpp index f666047d4..e9cab0847 100644 --- a/src/GridGenerator/StreetPointFinder/SourceReader.cpp +++ b/src/GridGenerator/StreetPointFinder/SourceReader.cpp @@ -8,7 +8,7 @@ SourceReaderData::SourceReaderData(unsigned int sourceIndex, float sourcePossibi {} -void SourceReader::readSources(std::string filename, StreetPointFinder streetPointFinder) +void SourceReader::readSources(std::string filename, StreetPointFinder* streetPointFinder) { *logging::out << logging::Logger::INFO_INTERMEDIATE << "StreetPointFinder::readSources( " << filename << " )" << "\n"; @@ -37,7 +37,7 @@ unsigned int SourceReader::getCellIndexStart(unsigned int streetIndex) uint i = 0; unsigned int cellIndex = 0; while (i < streetIndex) { - cellIndex += streetPointFinder.streets[i].numberOfCells; + cellIndex += streetPointFinder->streets[i].numberOfCells; ++i; } return cellIndex; diff --git a/src/GridGenerator/StreetPointFinder/SourceReader.h b/src/GridGenerator/StreetPointFinder/SourceReader.h index c352f87f0..de0e6acab 100644 --- a/src/GridGenerator/StreetPointFinder/SourceReader.h +++ b/src/GridGenerator/StreetPointFinder/SourceReader.h @@ -19,9 +19,9 @@ struct VF_PUBLIC SourceReaderData { struct VF_PUBLIC SourceReader { std::vector<SourceReaderData> sources; - StreetPointFinder streetPointFinder; + StreetPointFinder* streetPointFinder; - void readSources(std::string filename, StreetPointFinder streetPointFinder); + void readSources(std::string filename, StreetPointFinder* streetPointFinder); private: unsigned int getCellIndexStart(unsigned int streetIndex); diff --git a/src/Traffic/Junction/JunctionData.h b/src/Traffic/Junction/JunctionData.h index f74e15de4..f9b4a452c 100644 --- a/src/Traffic/Junction/JunctionData.h +++ b/src/Traffic/Junction/JunctionData.h @@ -22,6 +22,7 @@ public: std::vector<uint> oldSpeeds; uint trafficLightSwitchTime; //no TrafficLight: 0 + uint halfNumStreets; std::mt19937 engine = RandomHelper::make_engine(); std::uniform_real_distribution<float> distFloat{ 0.0, 1.0 }; diff --git a/src/Traffic/Junction/JunctionRandom.cpp b/src/Traffic/Junction/JunctionRandom.cpp index b31291fd3..26a3e6dd0 100644 --- a/src/Traffic/Junction/JunctionRandom.cpp +++ b/src/Traffic/Junction/JunctionRandom.cpp @@ -14,8 +14,6 @@ JunctionRandom::JunctionRandom(const std::vector<uint> &inCellIndices, const std::vector<uint> &outCellIndices, uint trafficLightSwitchTime) { - this->data.trafficLightSwitchTime = trafficLightSwitchTime; - data.inCellIndices = inCellIndices; data.outCellIndices = outCellIndices; @@ -31,6 +29,9 @@ JunctionRandom::JunctionRandom(const std::vector<uint> &inCellIndices, const std std::fill(data.alreadyMoved.begin(), data.alreadyMoved.end(), 0); data.oldSpeeds.resize(inRoads); + + this->data.trafficLightSwitchTime = trafficLightSwitchTime; + data.halfNumStreets = static_cast<uint>(std::floor(static_cast<float>(data.inCellIndices.size()) * 0.5f)); } @@ -99,40 +100,38 @@ void JunctionRandom::calculateTimeStep(TrafficMovement& road, uint currentTimest } writeConcentrations(road); - generateRedTrafficLights(currentTimestep); + calculateTrafficLightTimeStep(currentTimestep); } -void JunctionRandom::generateRedTrafficLights(uint currentTimestep) +void JunctionRandom::calculateTrafficLightTimeStep(uint currentTimestep) { if (data.trafficLightSwitchTime > 0) { - uint halfNumStreets = static_cast<uint>(std::floor(static_cast<float>(data.inCellIndices.size()) * 0.5f)); - if (static_cast<uint>(std::floor(static_cast<float>(currentTimestep) / static_cast<float>(data.trafficLightSwitchTime))) % 2 == 0) - turnFirstHalfRed(currentTimestep, halfNumStreets); + turnFirstHalfRed(currentTimestep); else - turnSecondHalfRed(currentTimestep, halfNumStreets); + turnSecondHalfRed(currentTimestep); } } -void JunctionRandom::turnFirstHalfRed(uint currentTimestep, uint halfNumStreets) +void JunctionRandom::turnFirstHalfRed(uint currentTimestep) { - for (uint i = 0; i < halfNumStreets; i++) + for (uint i = 0; i < data.halfNumStreets; i++) data.carCanEnter[i] = false; if (currentTimestep % data.trafficLightSwitchTime == 0) //first timestep with green light --> open the streets that were closed before - for (uint i = halfNumStreets; i < data.inCellIndices.size(); i++) + for (uint i = data.halfNumStreets; i < data.inCellIndices.size(); i++) if (data.carsOnJunction[i] == -1) data.carCanEnter[i] = true; } -void JunctionRandom::turnSecondHalfRed(uint currentTimestep, uint halfNumStreets) +void JunctionRandom::turnSecondHalfRed(uint currentTimestep) { - for (uint i = halfNumStreets; i < data.inCellIndices.size(); i++) + for (uint i = data.halfNumStreets; i < data.inCellIndices.size(); i++) data.carCanEnter[i] = false; if (currentTimestep % data.trafficLightSwitchTime == 0) //first timestep with green light --> open the streets that were closed before - for (uint i = 0; i < halfNumStreets; i++) + for (uint i = 0; i < data.halfNumStreets; i++) if (data.carsOnJunction[i] == -1) data.carCanEnter[i] = true; } diff --git a/src/Traffic/Junction/JunctionRandom.h b/src/Traffic/Junction/JunctionRandom.h index 96d8e31b5..e14f3d68d 100644 --- a/src/Traffic/Junction/JunctionRandom.h +++ b/src/Traffic/Junction/JunctionRandom.h @@ -49,9 +49,9 @@ private: int chooseOutCell(int index); int generateRandomOutCellIndex(uint outCellsTempSize); - void generateRedTrafficLights(uint currentTimestep); - void turnFirstHalfRed(uint currentTimestep, uint halfNumStreets); - void turnSecondHalfRed(uint currentTimestep, uint halfNumStreets); + void calculateTrafficLightTimeStep(uint currentTimestep); + void turnFirstHalfRed(uint currentTimestep); + void turnSecondHalfRed(uint currentTimestep); void writeConcentrations(TrafficMovement &road); diff --git a/src/Traffic/TrafficMovementFactory.cpp b/src/Traffic/TrafficMovementFactory.cpp index b933780d6..55979bf1b 100644 --- a/src/Traffic/TrafficMovementFactory.cpp +++ b/src/Traffic/TrafficMovementFactory.cpp @@ -68,17 +68,17 @@ void TrafficMovementFactory::initTrafficMovement(std::string path, bool useGPU, JunctionReader junctionReader; //junctionReader.readJunctions("C:/Users/schoen/Desktop/git/MS2/git/targets/apps/LBM/Basel/resources/Junctions.txt", finder); - junctionReader.readJunctions(inputPath + "Junctions.txt", finder); + junctionReader.readJunctions(inputPath + "Junctions.txt", &finder); SinkReader sinkReader; //sinkReader.readSinks("C:/Users/schoen/Desktop/git/MS2/git/targets/apps/LBM/Basel/resources/Sinks.txt", finder); - sinkReader.readSinks(inputPath + "Sinks.txt", finder); + sinkReader.readSinks(inputPath + "Sinks.txt", &finder); SourceReader sourceReader; //sourceReader.readSources("C:/Users/schoen/Desktop/git/MS2/git/targets/apps/LBM/Basel/resources/Sources.txt", finder); - sourceReader.readSources(inputPath + "Sources.txt", finder); + sourceReader.readSources(inputPath + "Sources.txt", &finder); //calculate RoadLength -- GitLab