diff --git a/src/GridGenerator/StreetPointFinder/JunctionReader.cpp b/src/GridGenerator/StreetPointFinder/JunctionReader.cpp index c0ebd8b8847c7ad295b837522fabf0db7ea5c9f5..438f9ddd914a3ffa4668193838356ec763768ecf 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 015e7d33daffd8650bd080218580b8e9a7e1feb9..a53d275214461c2a053e474b7a23b8671086115b 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 15eee8a3a9b9d0d5e875c43ac07ee1a9c376c07b..3c3e766898dd001c92206f945066b180ed2c19ad 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 323d8acfc85999468cd2bef68db43b7afb67217d..aa5e3151983014cc98615b9cf0e13826e7aa499e 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 f666047d478b1820b33ee0aebf621120c85211f3..e9cab08476f10a0f61860225b4d9771ef3166638 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 c352f87f01abb17ea10028c23045f84ff1012430..de0e6acab76f111f19b96f65721d6fabd8de059d 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 f74e15de448a226d9043dd4a3282c77d623b291b..f9b4a452ca1fd7d4343e4702fcd69908c6c1974a 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 b31291fd395c88d3862dc93caa869a90933503a6..26a3e6dd053df9fa1c437f7017b6b0024108ca9c 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 96d8e31b5cc357fff89d63282ad010b4043d6421..e14f3d68d6723b546ffec12cf760f9a0eb284c09 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 b933780d6008b3baf8869b68b77b274a364fbecc..55979bf1bb64710f6e3bd22d0de84e6d15e9fcdd 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