From 55b830729e3260f321016ef51eb16c259aaeb5c6 Mon Sep 17 00:00:00 2001 From: hiwis <hiwis@irmb.tu-bs.de> Date: Tue, 26 Feb 2019 12:48:33 +0100 Subject: [PATCH] Revert "Revert "Read Junctions, Sources and Sinks form Textfile"" This reverts commit 4ecb0274df4b067c4baf59099cd0a7eaf746b524. --- .../StreetPointFinder/JunctionReader.cpp | 64 +++++++++ .../StreetPointFinder/JunctionReader.h | 34 +++++ .../StreetPointFinder/SinkReader.cpp | 46 +++++++ .../StreetPointFinder/SinkReader.h | 31 +++++ .../StreetPointFinder/SourceReader.cpp | 48 +++++++ .../StreetPointFinder/SourceReader.h | 31 +++++ .../StreetPointFinder/StreetPointFinder.cpp | 2 +- .../StreetPointFinder/StreetPointFinder.h | 2 +- src/Traffic/{ => Junction}/Junction.h | 2 + src/Traffic/Junction/JunctionData.h | 26 ++++ src/Traffic/{ => Junction}/JunctionSimple.cpp | 120 +++++++++++------ src/Traffic/{ => Junction}/JunctionSimple.h | 26 ++-- .../{Sink.cpp => Junction/package.include} | 0 src/Traffic/JunctionData.h | 13 -- src/Traffic/OneWayRoad.cpp | 42 ++++-- src/Traffic/OneWayRoad.h | 13 +- src/Traffic/OneWayRoadSSJ.cpp | 37 +++++- src/Traffic/OneWayRoadSSJ.h | 1 + .../{ => Output}/ConcentrationByPosition.cpp | 0 .../{ => Output}/ConcentrationByPosition.h | 0 .../{ => Output}/ConcentrationOutwriter.h | 0 src/Traffic/Output/package.include | 0 src/Traffic/{ => RoadNetwork}/RoadMaker.cpp | 18 --- src/Traffic/{ => RoadNetwork}/RoadMaker.h | 4 +- .../{ => RoadNetwork}/RoadNetworkData.h | 10 +- src/Traffic/RoadNetwork/package.include | 0 src/Traffic/{ => Sink}/Sink.h | 0 src/Traffic/{ => Sink}/SinkData.h | 0 src/Traffic/{ => Sink}/SinkSimple.cpp | 0 src/Traffic/{ => Sink}/SinkSimple.h | 4 +- src/Traffic/Sink/package.include | 0 src/Traffic/Source.cpp | 1 - src/Traffic/{ => Source}/Source.h | 0 src/Traffic/{ => Source}/SourceData.h | 0 src/Traffic/{ => Source}/SourceTerm.cpp | 0 src/Traffic/{ => Source}/SourceTerm.h | 0 src/Traffic/Source/package.include | 0 src/Traffic/{ => Utilities}/RandomHelper.cpp | 0 src/Traffic/{ => Utilities}/RandomHelper.h | 0 src/Traffic/{ => Utilities}/VectorHelper.cpp | 0 src/Traffic/{ => Utilities}/VectorHelper.h | 0 .../{ => Utilities}/invalidInput_error.cpp | 0 .../{ => Utilities}/invalidInput_error.h | 0 src/Traffic/Utilities/package.include | 0 .../apps/LBM/Basel/resources/Junctions.txt | 5 + targets/apps/LBM/Basel/resources/Sinks.txt | 5 + targets/apps/LBM/Basel/resources/Sources.txt | 5 + targets/apps/LBM/TrafficTest/TrafficTest.cpp | 122 +++++++++++++----- 48 files changed, 562 insertions(+), 150 deletions(-) create mode 100644 src/GridGenerator/StreetPointFinder/JunctionReader.cpp create mode 100644 src/GridGenerator/StreetPointFinder/JunctionReader.h create mode 100644 src/GridGenerator/StreetPointFinder/SinkReader.cpp create mode 100644 src/GridGenerator/StreetPointFinder/SinkReader.h create mode 100644 src/GridGenerator/StreetPointFinder/SourceReader.cpp create mode 100644 src/GridGenerator/StreetPointFinder/SourceReader.h rename src/Traffic/{ => Junction}/Junction.h (90%) create mode 100644 src/Traffic/Junction/JunctionData.h rename src/Traffic/{ => Junction}/JunctionSimple.cpp (50%) rename src/Traffic/{ => Junction}/JunctionSimple.h (76%) rename src/Traffic/{Sink.cpp => Junction/package.include} (100%) delete mode 100644 src/Traffic/JunctionData.h rename src/Traffic/{ => Output}/ConcentrationByPosition.cpp (100%) rename src/Traffic/{ => Output}/ConcentrationByPosition.h (100%) rename src/Traffic/{ => Output}/ConcentrationOutwriter.h (100%) create mode 100644 src/Traffic/Output/package.include rename src/Traffic/{ => RoadNetwork}/RoadMaker.cpp (92%) rename src/Traffic/{ => RoadNetwork}/RoadMaker.h (96%) rename src/Traffic/{ => RoadNetwork}/RoadNetworkData.h (79%) create mode 100644 src/Traffic/RoadNetwork/package.include rename src/Traffic/{ => Sink}/Sink.h (100%) rename src/Traffic/{ => Sink}/SinkData.h (100%) rename src/Traffic/{ => Sink}/SinkSimple.cpp (100%) rename src/Traffic/{ => Sink}/SinkSimple.h (86%) create mode 100644 src/Traffic/Sink/package.include delete mode 100644 src/Traffic/Source.cpp rename src/Traffic/{ => Source}/Source.h (100%) rename src/Traffic/{ => Source}/SourceData.h (100%) rename src/Traffic/{ => Source}/SourceTerm.cpp (100%) rename src/Traffic/{ => Source}/SourceTerm.h (100%) create mode 100644 src/Traffic/Source/package.include rename src/Traffic/{ => Utilities}/RandomHelper.cpp (100%) rename src/Traffic/{ => Utilities}/RandomHelper.h (100%) rename src/Traffic/{ => Utilities}/VectorHelper.cpp (100%) rename src/Traffic/{ => Utilities}/VectorHelper.h (100%) rename src/Traffic/{ => Utilities}/invalidInput_error.cpp (100%) rename src/Traffic/{ => Utilities}/invalidInput_error.h (100%) create mode 100644 src/Traffic/Utilities/package.include create mode 100644 targets/apps/LBM/Basel/resources/Junctions.txt create mode 100644 targets/apps/LBM/Basel/resources/Sinks.txt create mode 100644 targets/apps/LBM/Basel/resources/Sources.txt diff --git a/src/GridGenerator/StreetPointFinder/JunctionReader.cpp b/src/GridGenerator/StreetPointFinder/JunctionReader.cpp new file mode 100644 index 000000000..3e813247e --- /dev/null +++ b/src/GridGenerator/StreetPointFinder/JunctionReader.cpp @@ -0,0 +1,64 @@ +#include "JunctionReader.h" + +#include <fstream> +#include <iostream> + + +JunctionInReader::JunctionInReader(std::vector<uint> inCells, std::vector<uint> outCells, std::vector<int> carCanNotEnterThisOutCell) : + inCells{ inCells }, outCells{ outCells }, carCanNotEnterThisOutCell{ carCanNotEnterThisOutCell } +{} + +void JunctionReader::readJunctions(std::string filename, StreetPointFinder streetPointFinder) +{ + *logging::out << logging::Logger::INFO_INTERMEDIATE << "StreetPointFinder::readJunctions( " << filename << " )" << "\n"; + + std::ifstream file; + file.open(filename.c_str()); + if (!file.is_open()) std::cerr << "File not found" << std::endl; + this->streetPointFinder = streetPointFinder; + + uint numberOfJunctions; + file >> numberOfJunctions; + + int streetIndex; + char startOrEnd; + + for (uint i = 0; i < numberOfJunctions; i++) { + std::vector<uint> inCells, outCells; + std::vector<int> carCanNotEnterThisOutCell; + + //inCells + for (uint i = 0; i < 4; i++) { + file >> streetIndex >> startOrEnd; + if (streetIndex >= 0) + inCells.push_back(getCellIndex(streetIndex, startOrEnd)); + } + + //outCells + for (uint i = 0; i < 4; i++) { + file >> streetIndex >> startOrEnd; + if (streetIndex >= 0) { + outCells.push_back(getCellIndex(streetIndex, startOrEnd)); + carCanNotEnterThisOutCell.push_back(getCellIndex(streetIndex, startOrEnd)); + }else if(streetIndex == -2) //allow u-turn + carCanNotEnterThisOutCell.push_back(-2); + } + + //make Junction + junctions.push_back(JunctionInReader(inCells, outCells, carCanNotEnterThisOutCell)); + } +} + + +unsigned int JunctionReader::getCellIndex(unsigned int streetIndex, char startOrEnd) +{ + uint i = 0; + unsigned int cellIndex = 0; + while (i < streetIndex) { + cellIndex += streetPointFinder.streets[i].numberOfCells; + ++i; + } + if (startOrEnd == 's') return cellIndex; + return cellIndex + streetPointFinder.streets[streetIndex].numberOfCells - 1; +} + diff --git a/src/GridGenerator/StreetPointFinder/JunctionReader.h b/src/GridGenerator/StreetPointFinder/JunctionReader.h new file mode 100644 index 000000000..027bfed70 --- /dev/null +++ b/src/GridGenerator/StreetPointFinder/JunctionReader.h @@ -0,0 +1,34 @@ +#ifndef JUNCTIOREADER_H +#define JUNCTIONREADER_H + +#include <vector> + +#include "Core/DataTypes.h" +#include "Core/Logger/Logger.h" + +#include "StreetPointFinder.h" + +#include <VirtualFluidsDefinitions.h> + +struct VF_PUBLIC JunctionInReader +{ + std::vector<uint> inCells; + std::vector<uint> outCells; + std::vector<int> carCanNotEnterThisOutCell; + + JunctionInReader(std::vector<uint> inCells, std::vector<uint> outCells, std::vector<int> carCanNotEnterThisOutCell); +}; + + +struct VF_PUBLIC JunctionReader +{ + std::vector<JunctionInReader> junctions; + StreetPointFinder streetPointFinder; + + void readJunctions(std::string filename, StreetPointFinder streetPointFinder); + + +private: + unsigned int getCellIndex(unsigned int streetIndex, char startOrEnd); +}; +#endif diff --git a/src/GridGenerator/StreetPointFinder/SinkReader.cpp b/src/GridGenerator/StreetPointFinder/SinkReader.cpp new file mode 100644 index 000000000..dfe196750 --- /dev/null +++ b/src/GridGenerator/StreetPointFinder/SinkReader.cpp @@ -0,0 +1,46 @@ +#include "SinkReader.h" + +#include <fstream> +#include <iostream> + +SinkInReader::SinkInReader(uint sinkIndex, float sinkBlockedPossibility) : + sinkIndex{ sinkIndex }, sinkBlockedPossibility{ sinkBlockedPossibility } +{} + +void SinkReader::readSinks(std::string filename, StreetPointFinder streetPointFinder) +{ + *logging::out << logging::Logger::INFO_INTERMEDIATE << "StreetPointFinder::readSinks( " << filename << " )" << "\n"; + + this->streetPointFinder = streetPointFinder; + + std::ifstream file; + file.open(filename.c_str()); + if (!file.is_open()) std::cerr << "File not found" << std::endl; + + uint numberOfSinks; + file >> numberOfSinks; + + uint streetIndex; + char startOrEnd; + float sinkBlockedPossibility; + + + for (uint i = 0; i < numberOfSinks; i++) { + file >> streetIndex >> startOrEnd >> sinkBlockedPossibility; + sinks.push_back(SinkInReader(getCellIndex(streetIndex, startOrEnd), sinkBlockedPossibility)); + } +} + +unsigned int SinkReader::getCellIndex(unsigned int streetIndex, char startOrEnd) +{ + uint i = 0; + unsigned int cellIndex = 0; + while (i < streetIndex) { + cellIndex += streetPointFinder.streets[i].numberOfCells; + ++i; + } + if (startOrEnd == 's') { + return cellIndex; + } + return cellIndex + streetPointFinder.streets[streetIndex].numberOfCells - 1; +} diff --git a/src/GridGenerator/StreetPointFinder/SinkReader.h b/src/GridGenerator/StreetPointFinder/SinkReader.h new file mode 100644 index 000000000..e4db88dc5 --- /dev/null +++ b/src/GridGenerator/StreetPointFinder/SinkReader.h @@ -0,0 +1,31 @@ +#ifndef SINKREADER_H +#define SINKREADER_H + +#include <vector> + +#include "Core/DataTypes.h" +#include "Core/Logger/Logger.h" + +#include "StreetPointFinder.h" + +#include <VirtualFluidsDefinitions.h> + +struct VF_PUBLIC SinkInReader{ + uint sinkIndex; + float sinkBlockedPossibility; + SinkInReader(uint sinkIndex, float sinkBlockedPossibility); +}; + +struct VF_PUBLIC SinkReader +{ + std::vector<SinkInReader> sinks; + StreetPointFinder streetPointFinder; + + void readSinks(std::string filename, StreetPointFinder streetPointFinder); + +private: + unsigned int getCellIndex(unsigned int streetIndex, char startOrEnd); +}; + + +#endif \ No newline at end of file diff --git a/src/GridGenerator/StreetPointFinder/SourceReader.cpp b/src/GridGenerator/StreetPointFinder/SourceReader.cpp new file mode 100644 index 000000000..25c67f36e --- /dev/null +++ b/src/GridGenerator/StreetPointFinder/SourceReader.cpp @@ -0,0 +1,48 @@ +#include "SourceReader.h" + +#include <fstream> +#include <iostream> + +SourceInReader::SourceInReader(unsigned int sourceIndex, float sourcePossibility): + sourceIndex{sourceIndex}, sourcePossibility{sourcePossibility} +{} + + +void SourceReader::readSources(std::string filename, StreetPointFinder streetPointFinder) +{ + *logging::out << logging::Logger::INFO_INTERMEDIATE << "StreetPointFinder::readSources( " << filename << " )" << "\n"; + + this->streetPointFinder = streetPointFinder; + + std::ifstream file; + file.open(filename.c_str()); + if (!file.is_open()) std::cerr << "File not found" << std::endl; + + uint numberOfSources; + file >> numberOfSources; + + uint streetIndex; + char startOrEnd; + float sourcePossibility; + + + for (uint i = 0; i < numberOfSources; i++) { + file >> streetIndex >> startOrEnd >> sourcePossibility; + sources.push_back(SourceInReader(getCellIndex(streetIndex, startOrEnd), sourcePossibility)); + } +} + + +unsigned int SourceReader::getCellIndex(unsigned int streetIndex, char startOrEnd) +{ + uint i = 0; + unsigned int cellIndex = 0; + while (i < streetIndex) { + cellIndex += streetPointFinder.streets[i].numberOfCells; + ++i; + } + if (startOrEnd == 's') { + return cellIndex; + } + return cellIndex + streetPointFinder.streets[streetIndex].numberOfCells - 1; +} diff --git a/src/GridGenerator/StreetPointFinder/SourceReader.h b/src/GridGenerator/StreetPointFinder/SourceReader.h new file mode 100644 index 000000000..c4816e636 --- /dev/null +++ b/src/GridGenerator/StreetPointFinder/SourceReader.h @@ -0,0 +1,31 @@ +#ifndef SOURCEREADER_H +#define SOURCEREADER_H + +#include <vector> + +#include "Core/DataTypes.h" +#include "Core/Logger/Logger.h" + +#include "StreetPointFinder.h" + +#include <VirtualFluidsDefinitions.h> + +struct VF_PUBLIC SourceInReader { + unsigned int sourceIndex; + float sourcePossibility; + SourceInReader(unsigned int sourceIndex, float sourcePossibility); +}; + +struct VF_PUBLIC SourceReader +{ + std::vector<SourceInReader> sources; + StreetPointFinder streetPointFinder; + + void readSources(std::string filename, StreetPointFinder streetPointFinder); + +private: + unsigned int getCellIndex(unsigned int streetIndex, char startOrEnd); +}; + + +#endif \ No newline at end of file diff --git a/src/GridGenerator/StreetPointFinder/StreetPointFinder.cpp b/src/GridGenerator/StreetPointFinder/StreetPointFinder.cpp index be7000ea7..8b522fa5b 100644 --- a/src/GridGenerator/StreetPointFinder/StreetPointFinder.cpp +++ b/src/GridGenerator/StreetPointFinder/StreetPointFinder.cpp @@ -298,7 +298,7 @@ void StreetPointFinder::writeVTK(std::string filename, const std::vector<int>& c } } - ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// file.close(); diff --git a/src/GridGenerator/StreetPointFinder/StreetPointFinder.h b/src/GridGenerator/StreetPointFinder/StreetPointFinder.h index 03e547209..e8099f209 100644 --- a/src/GridGenerator/StreetPointFinder/StreetPointFinder.h +++ b/src/GridGenerator/StreetPointFinder/StreetPointFinder.h @@ -28,7 +28,7 @@ struct VF_PUBLIC Street std::vector<uint> matrixIndicesLB; std::vector<uint> sparseIndicesLB; - // The constructor expect star and end for cells + // The constructor expect start and end for cells Street( real xStartCell, real yStartCell, real xEndCell, real yEndCell, real dx ); real getCoordinateX( int cellIndex ); diff --git a/src/Traffic/Junction.h b/src/Traffic/Junction/Junction.h similarity index 90% rename from src/Traffic/Junction.h rename to src/Traffic/Junction/Junction.h index a41175e6f..4772f3b5c 100644 --- a/src/Traffic/Junction.h +++ b/src/Traffic/Junction/Junction.h @@ -14,6 +14,8 @@ public: virtual void checkOutCellIndices(unsigned int roadLength) = 0; + virtual void setCellIndexForNoUTurn(std::vector<int> carCanNotEnterThisOutCell) = 0; + virtual bool acceptsCar(unsigned int cellIndex) = 0; //determines if a car can enter the junction virtual void registerCar(unsigned int cellIndex, unsigned int numberOfCellsAlreadyMoved, unsigned int speed) = 0; //registers all cars entering the junction virtual void calculateTimeStep(OneWayRoadSSJ& road) = 0; diff --git a/src/Traffic/Junction/JunctionData.h b/src/Traffic/Junction/JunctionData.h new file mode 100644 index 000000000..b4f92abac --- /dev/null +++ b/src/Traffic/Junction/JunctionData.h @@ -0,0 +1,26 @@ +#pragma once +#include <VirtualFluidsDefinitions.h> + +#include <vector> +#include <memory> +#include "Utilities\RandomHelper.h" + +struct VF_PUBLIC JunctionData +{ +public: + std::vector<unsigned int> inCellIndices; + std::vector<unsigned int> outCellIndices; + std::vector<int> carCanNotEnterThisOutCell; //no such inCell: -2 + + std::vector<unsigned int> freeOutCells; + + std::vector<bool> carCanEnter; + std::vector<int> carsOnJunction; + std::vector<unsigned int> alreadyMoved; + + std::mt19937 engine = RandomHelper::make_engine(); + uniform_int_distribution<unsigned int> distInt2{ 0, 1 }; + uniform_int_distribution<unsigned int> distInt3{ 0, 2 }; + uniform_int_distribution<unsigned int> distInt4{ 0, 3 }; +}; + diff --git a/src/Traffic/JunctionSimple.cpp b/src/Traffic/Junction/JunctionSimple.cpp similarity index 50% rename from src/Traffic/JunctionSimple.cpp rename to src/Traffic/Junction/JunctionSimple.cpp index eb8b4c3a7..6b1e789c6 100644 --- a/src/Traffic/JunctionSimple.cpp +++ b/src/Traffic/Junction/JunctionSimple.cpp @@ -2,42 +2,52 @@ -JunctionSimple::JunctionSimple(const vector<unsigned int> &inCellIndices, const vector<unsigned int> &outCellIndices) : - engine{ random_device{}() } +JunctionSimple::JunctionSimple(const vector<unsigned int> &inCellIndices, const vector<unsigned int> &outCellIndices) { data.inCellIndices = inCellIndices; data.outCellIndices = outCellIndices; unsigned int inRoads = inCellIndices.size(); - carCanEnter.resize(inRoads); - fill(carCanEnter.begin(), carCanEnter.end(), true); + data.carCanEnter.resize(inRoads); + fill(data.carCanEnter.begin(), data.carCanEnter.end(), true); - carsOnJunction.resize(inRoads); - fill(carsOnJunction.begin(), carsOnJunction.end(), -1); + data.carsOnJunction.resize(inRoads); + fill(data.carsOnJunction.begin(), data.carsOnJunction.end(), -1); - alreadyMoved.resize(inRoads); - fill(alreadyMoved.begin(), alreadyMoved.end(), 0); + data.alreadyMoved.resize(inRoads); + fill(data.alreadyMoved.begin(), data.alreadyMoved.end(), 0); } -JunctionSimple::~JunctionSimple() +void JunctionSimple::setCellIndexForNoUTurn(std::vector<int> carCanNotEnterThisOutCell) { + try { + + if (data.inCellIndices.size() != carCanNotEnterThisOutCell.size()) throw invalidInput_error("The Vector carCanNotEnterThisOutCell and inCellIndices have to be the same size."); + data.carCanNotEnterThisOutCell = carCanNotEnterThisOutCell; + + } + catch (const exception& e) { + cerr << e.what() << endl; + cin.get(); + exit(EXIT_FAILURE); + } } bool JunctionSimple::acceptsCar(unsigned int cellIndex) { - return carCanEnter[getInCellsVectorIndex(cellIndex)]; + return data.carCanEnter[getInCellsVectorIndex(cellIndex)]; } void JunctionSimple::registerCar(unsigned int cellIndex, unsigned int numberOfCellsAlreadyMoved, unsigned int speed) { unsigned int index = getInCellsVectorIndex(cellIndex); - carsOnJunction[index] = speed; - carCanEnter[index] = false; - alreadyMoved[index] = numberOfCellsAlreadyMoved; + data.carsOnJunction[index] = speed; + data.carCanEnter[index] = false; + data.alreadyMoved[index] = numberOfCellsAlreadyMoved; } @@ -55,7 +65,7 @@ unsigned int JunctionSimple::getInCellsVectorIndex(unsigned int cellIndex) } catch (const exception& e) { cerr << e.what() << endl; - cin.get(); + cin.get(); exit(EXIT_FAILURE); } } @@ -63,14 +73,14 @@ unsigned int JunctionSimple::getInCellsVectorIndex(unsigned int cellIndex) void JunctionSimple::updateJunction() { - freeOutCells = data.outCellIndices; + data.freeOutCells = data.outCellIndices; } void JunctionSimple::calculateTimeStep(OneWayRoadSSJ& road) { index = 0; - for (int carSpeed : carsOnJunction) { + for (int carSpeed : data.carsOnJunction) { if (carSpeed >= 0) { //check if there is a car on the junction @@ -78,29 +88,31 @@ void JunctionSimple::calculateTimeStep(OneWayRoadSSJ& road) cerr << "speed on junction was 0" << endl; else applyRules(carSpeed, index, road); - alreadyMoved[index] = 0; + data.alreadyMoved[index] = 0; } - ++ index; + ++index; } } -void JunctionSimple::applyRules(int & carSpeed,const int & index, OneWayRoadSSJ& road) +void JunctionSimple::applyRules(int & carSpeed, const int & index, OneWayRoadSSJ& road) { - remainingDistance = static_cast<unsigned int>(carSpeed) - alreadyMoved[index]; + remainingDistance = static_cast<unsigned int>(carSpeed) - data.alreadyMoved[index]; - if (remainingDistance > 0 && freeOutCells.size() > 0) { - outCell = chooseOutCell(); - breakCar(outCell, carSpeed, remainingDistance, road); + if (remainingDistance > 0) { + outCell = chooseOutCell(index); + if (outCell >= 0) { + breakCar(outCell, carSpeed, remainingDistance, road); - if (remainingDistance > 0) - moveCar(carSpeed, index, road); - else - carsOnJunction[index] = 1; + if (remainingDistance > 0) + moveCar(outCell, carSpeed, index, road); + else + data.carsOnJunction[index] = 1; + return; + } } - else - carsOnJunction[index] = 1; + data.carsOnJunction[index] = 1; } @@ -111,32 +123,54 @@ void JunctionSimple::breakCar(unsigned int outCellIndex, int &speed, unsigned in speed = speed - remainingDistance + gap; remainingDistance = gap; } - } -void JunctionSimple::moveCar(int & carSpeed, const int & index, OneWayRoadSSJ& road) +void JunctionSimple::moveCar(unsigned int outCell, int & carSpeed, const int & index, OneWayRoadSSJ& road) { road.moveJunctionCar(outCell, remainingDistance, carSpeed); - carsOnJunction[index] = -1; - carCanEnter[index] = true; + data.carsOnJunction[index] = -1; + data.carCanEnter[index] = true; } -unsigned int JunctionSimple::chooseOutCell() +int JunctionSimple::chooseOutCell(const int & index) { - uniform_int_distribution<unsigned int> distFloat(0, freeOutCells.size() - 1); - random = distFloat(engine); + vector<unsigned int> freeOutCellsTemp; - outCell = freeOutCells[random]; - freeOutCells.erase(freeOutCells.begin() + random); + if (data.carCanNotEnterThisOutCell.size() > 0 && data.carCanNotEnterThisOutCell[index]) { + for (unsigned int cell : data.freeOutCells) { + if (cell != data.carCanNotEnterThisOutCell[index]) + freeOutCellsTemp.push_back(cell); + } + } + else + freeOutCellsTemp = data.freeOutCells; + + + switch (freeOutCellsTemp.size()) { + case 0: + return -1; + case 1: + random = 0; + break; + case 2: + random = data.distInt2(data.engine); + break; + case 3: + random = data.distInt3(data.engine); + break; + case 4: + random = data.distInt4(data.engine); + break; + } + + outCell = freeOutCellsTemp[random]; + data.freeOutCells.erase(std::remove(data.freeOutCells.begin(), data.freeOutCells.end(), outCell), data.freeOutCells.end()); return outCell; } - - - const vector<unsigned int>& JunctionSimple::getInCellIndices() const { return data.inCellIndices; @@ -158,7 +192,7 @@ void JunctionSimple::dispJunction(const unsigned int index, unsigned int roadLen const unsigned int JunctionSimple::getNumCarsOnJunction() const { unsigned int num = 0; - for (auto car : carsOnJunction) { + for (auto car : data.carsOnJunction) { if (car >= 0) ++num; } @@ -168,7 +202,7 @@ const unsigned int JunctionSimple::getNumCarsOnJunction() const void JunctionSimple::checkOutCellIndices(unsigned int roadLength) { - try { + try { for (unsigned int cell : data.outCellIndices) if (cell >= roadLength) throw invalidInput_error("The indices of incoming cells to a junction are greater than the roadLength."); } diff --git a/src/Traffic/JunctionSimple.h b/src/Traffic/Junction/JunctionSimple.h similarity index 76% rename from src/Traffic/JunctionSimple.h rename to src/Traffic/Junction/JunctionSimple.h index 242724463..cf455de6f 100644 --- a/src/Traffic/JunctionSimple.h +++ b/src/Traffic/Junction/JunctionSimple.h @@ -4,9 +4,10 @@ #include <vector> #include <iostream> #include <random> +#include <algorithm> -#include "invalidInput_error.h" -#include "VectorHelper.h" +#include "Utilities/invalidInput_error.h" +#include "Utilities/VectorHelper.h" #include "Junction.h" #include "OneWayRoadSSJ.h" @@ -19,17 +20,11 @@ class VF_PUBLIC JunctionSimple : private: JunctionData data; - vector<unsigned int> freeOutCells; - - vector<bool> carCanEnter; - vector<int> carsOnJunction; - vector<unsigned int> alreadyMoved; - - mt19937 engine; - public: JunctionSimple(const vector<unsigned int> &inCellIndices, const vector<unsigned int> &outCellIndices); - ~JunctionSimple(); + ~JunctionSimple() {}; + + virtual void setCellIndexForNoUTurn(vector<int> carCanNotEnterThisOutCell); virtual bool acceptsCar(unsigned int cellIndex); //determines if a car can enter the junction virtual void registerCar(unsigned int cellIndex, unsigned int numberOfCellsAlreadyMoved, unsigned int speed); //registers all cars entering the junction @@ -41,20 +36,21 @@ public: virtual void dispJunction(const unsigned int index, unsigned int roadLength) const; virtual const unsigned int getNumCarsOnJunction() const; - virtual void checkOutCellIndices(unsigned int roadLength); + virtual void checkOutCellIndices(unsigned int roadLength); private: unsigned int getInCellsVectorIndex(unsigned int cellIndex); void applyRules(int &carSpeed,const int &index, OneWayRoadSSJ& road); void breakCar(unsigned int outCellIndex, int &speed, unsigned int &remainingDistance, OneWayRoadSSJ& road); - void moveCar(int & carSpeed, const int & index, OneWayRoadSSJ& road); - unsigned int chooseOutCell(); + void moveCar(unsigned int outCell, int & carSpeed, const int & index, OneWayRoadSSJ& road); + int chooseOutCell(const int & index); + private: //variables for temporaray calculations unsigned int remainingDistance; - unsigned int outCell; + int outCell; unsigned int random; unsigned int gap; int index; diff --git a/src/Traffic/Sink.cpp b/src/Traffic/Junction/package.include similarity index 100% rename from src/Traffic/Sink.cpp rename to src/Traffic/Junction/package.include diff --git a/src/Traffic/JunctionData.h b/src/Traffic/JunctionData.h deleted file mode 100644 index e7853947f..000000000 --- a/src/Traffic/JunctionData.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include <VirtualFluidsDefinitions.h> - -#include <vector> -#include <memory> - -struct VF_PUBLIC JunctionData -{ -public: - std::vector<unsigned int> inCellIndices; - std::vector<unsigned int> outCellIndices; -}; - diff --git a/src/Traffic/OneWayRoad.cpp b/src/Traffic/OneWayRoad.cpp index 12ffa09e7..8a7b6d463 100644 --- a/src/Traffic/OneWayRoad.cpp +++ b/src/Traffic/OneWayRoad.cpp @@ -13,8 +13,9 @@ OneWayRoad::OneWayRoad(unique_ptr<RoadNetworkData> road, const float dawdlePossi pcurrent = &this->road->current; pnext = &(this->road->next); + checkCurrentForSafetyDistance(); + initDawdle(dawdlePossibility); - initResults(); } @@ -28,10 +29,8 @@ OneWayRoad::~OneWayRoad() void OneWayRoad::initResults() { - if (saveResults) { - results.resize(road->roadLength, vector<int>(1)); - VectorHelper::fillVector(results, -10); - } + results.resize(road->roadLength, vector<int>(1)); + VectorHelper::fillVector(results, -10); } @@ -82,7 +81,10 @@ void OneWayRoad::setConcentrationOutwriter(unique_ptr<ConcentrationOutwriter> wr void OneWayRoad::setSaveResults(bool saveResults) { - saveResults = true; + if (saveResults) { + this->saveResults = true; + initResults(); + } } @@ -128,7 +130,7 @@ void OneWayRoad::initResultsForCalculation() void OneWayRoad::loopTroughTimesteps() { - for (int step = 1; step < timeSteps + 1; step++) { + for (unsigned int step = 1; step < timeSteps + 1; step++) { calculateTimestep(step); } } @@ -296,9 +298,13 @@ void OneWayRoad::writeResultsToFile() const } catch (const exception& e) { cerr << e.what() << endl; + cin.get(); + exit(EXIT_FAILURE); } catch (...) { cerr << "unknown exception while writing to file" << endl; + cin.get(); + exit(EXIT_FAILURE); } } @@ -324,6 +330,27 @@ void OneWayRoad::dispResults() VectorHelper::dispVectorColour(results); } + +void OneWayRoad::checkCurrentForSafetyDistance() +{ + if (road->safetyDistance > 0) { + unsigned int neighbor; + for (unsigned int i = 0; i < road->roadLength; i++) { + if ((*pcurrent)[i] > -1) { + neighbor = road->neighbors[i]; + for (unsigned int j = 1; j <= road->safetyDistance; j++) { + if ((*pcurrent)[neighbor] > -1) { + std::cerr << "timestep 0: safetyDistance was violated: carIndex: " << i << std::endl; + break; + } + neighbor = road->neighbors[neighbor]; + } + } + } + } +} + + void OneWayRoad::visualizeSafetyDistanceForConsole() { if (road->safetyDistance != 0) { @@ -372,5 +399,4 @@ void OneWayRoad::visualizeVehicleLengthForVTK() } } } - } \ No newline at end of file diff --git a/src/Traffic/OneWayRoad.h b/src/Traffic/OneWayRoad.h index a9879f3bb..ff4e4baf1 100644 --- a/src/Traffic/OneWayRoad.h +++ b/src/Traffic/OneWayRoad.h @@ -9,11 +9,11 @@ #include <iomanip> //formatting output streams #include <windows.h> //for colourful console output -#include "invalidInput_error.h" -#include "VectorHelper.h" -#include "RandomHelper.h" -#include "RoadNetworkData.h" -#include "ConcentrationOutwriter.h" +#include "Utilities/invalidInput_error.h" +#include "Utilities/VectorHelper.h" +#include "Utilities/RandomHelper.h" +#include "RoadNetwork/RoadNetworkData.h" +#include "Output/ConcentrationOutwriter.h" using namespace std; @@ -87,7 +87,8 @@ protected: void breakCar(unsigned int carIndex, unsigned int &speed); void dawdleCar(unsigned int carIndex, unsigned int &speed); virtual void moveCar(unsigned int carIndex, unsigned int speed); - + + void checkCurrentForSafetyDistance(); virtual void visualizeSafetyDistanceForConsole(); protected: diff --git a/src/Traffic/OneWayRoadSSJ.cpp b/src/Traffic/OneWayRoadSSJ.cpp index b4b6bcb03..5fa6c52f3 100644 --- a/src/Traffic/OneWayRoadSSJ.cpp +++ b/src/Traffic/OneWayRoadSSJ.cpp @@ -7,8 +7,9 @@ OneWayRoadSSJ::OneWayRoadSSJ(unique_ptr<RoadNetworkData> road, const float dawdl pcurrent = &this->road->current; pnext = &(this->road->next); + checkCurrentForSafetyDistance(); + initDawdle(dawdlePossibility); - initResults(); } OneWayRoadSSJ::OneWayRoadSSJ() @@ -28,8 +29,9 @@ void OneWayRoadSSJ::calculateTimestep(unsigned int step) VectorHelper::fillVector(*pnext, -1); vector<unsigned int> cars = findCarIndicesInCurrent(); - for (auto &car : cars) + for (auto &car : cars) { applyRules(car); + } for (auto &junction : road->junctions) { junction->updateJunction(); @@ -92,7 +94,6 @@ unsigned int OneWayRoadSSJ::iterateNeighborsInMove(unsigned int ¤tCell, un else break; } - return numberOfCellsMoved; } @@ -227,9 +228,8 @@ void OneWayRoadSSJ::visualizeSafetyDistanceForConsole() { neighbor = road->neighbors[i]; for (unsigned int j = 1; j <= road->safetyDistance; j++) { //junction or sink - if (neighbor <= -1000) { + if (neighbor <= -1000) break; - } if (results[neighbor][step] > -1) { cerr << "safetyDistance was violated: timestep: " << step << "\t carIndex: " << i << endl; break; @@ -245,6 +245,33 @@ void OneWayRoadSSJ::visualizeSafetyDistanceForConsole() { } + +void OneWayRoadSSJ::visualizeVehicleLengthForVTK() +{ + road->currentWithLongVehicles = *pcurrent; + + if (road->safetyDistance != 0) { + for (unsigned int i = 0; i < road->roadLength; i++) { + if ((*pcurrent)[i] > -1) { + int neighbor = road->neighbors[i]; + for (unsigned int j = 1; j <= road->safetyDistance; j++) { + if (neighbor <= -1000) + break; + if ((*pcurrent)[neighbor] > -1) { + cerr << "safetyDistance was violated: timestep: " << currentStep << "\t carIndex: " << i << endl; + break; + } + else + (road->currentWithLongVehicles)[neighbor] = (*pcurrent)[i]; + neighbor = road->neighbors[neighbor]; + } + } + } + } +} + + + void OneWayRoadSSJ::dispJunctionsAtCell(unsigned int index) const { for (auto& junc : road->junctions) { diff --git a/src/Traffic/OneWayRoadSSJ.h b/src/Traffic/OneWayRoadSSJ.h index 755a0bae8..36d6c83c7 100644 --- a/src/Traffic/OneWayRoadSSJ.h +++ b/src/Traffic/OneWayRoadSSJ.h @@ -20,6 +20,7 @@ public: virtual void dispResults(); virtual const unsigned int getNumberOfCars() const; //only use for testing + virtual void visualizeVehicleLengthForVTK(); private: diff --git a/src/Traffic/ConcentrationByPosition.cpp b/src/Traffic/Output/ConcentrationByPosition.cpp similarity index 100% rename from src/Traffic/ConcentrationByPosition.cpp rename to src/Traffic/Output/ConcentrationByPosition.cpp diff --git a/src/Traffic/ConcentrationByPosition.h b/src/Traffic/Output/ConcentrationByPosition.h similarity index 100% rename from src/Traffic/ConcentrationByPosition.h rename to src/Traffic/Output/ConcentrationByPosition.h diff --git a/src/Traffic/ConcentrationOutwriter.h b/src/Traffic/Output/ConcentrationOutwriter.h similarity index 100% rename from src/Traffic/ConcentrationOutwriter.h rename to src/Traffic/Output/ConcentrationOutwriter.h diff --git a/src/Traffic/Output/package.include b/src/Traffic/Output/package.include new file mode 100644 index 000000000..e69de29bb diff --git a/src/Traffic/RoadMaker.cpp b/src/Traffic/RoadNetwork/RoadMaker.cpp similarity index 92% rename from src/Traffic/RoadMaker.cpp rename to src/Traffic/RoadNetwork/RoadMaker.cpp index a1a958c26..3c07976ba 100644 --- a/src/Traffic/RoadMaker.cpp +++ b/src/Traffic/RoadNetwork/RoadMaker.cpp @@ -269,21 +269,3 @@ unsigned int RoadMaker::getMaxVelocity() return maxVelocity; } -void RoadMaker::checkCurrentForSafetyDistance() -{ - if (safetyDistance > 0) { - unsigned int neighbor; - for (unsigned int i = 0; i < roadLength; i++) { - if (current[i] > -1) { - neighbor = neighbors[i]; - for (unsigned int j = 1; j <= safetyDistance; j++) { - if ((current)[neighbor] > -1) { - std::cerr << "timestep 0: safetyDistance was violated: carIndex: " << i << std::endl; - break; - } - neighbor = neighbors[neighbor]; - } - } - } - } -} diff --git a/src/Traffic/RoadMaker.h b/src/Traffic/RoadNetwork/RoadMaker.h similarity index 96% rename from src/Traffic/RoadMaker.h rename to src/Traffic/RoadNetwork/RoadMaker.h index 29515c000..da6a9b722 100644 --- a/src/Traffic/RoadMaker.h +++ b/src/Traffic/RoadNetwork/RoadMaker.h @@ -1,7 +1,7 @@ #pragma once #include <random> #include "RoadNetworkData.h" -#include "RandomHelper.h" +#include "Utilities/RandomHelper.h" #include <VirtualFluidsDefinitions.h> struct VF_PUBLIC RoadMaker : @@ -23,8 +23,6 @@ public: void setNeighbor(unsigned int index, unsigned int neighbor); // don't use it for setting sinks or junctions! - void checkCurrentForSafetyDistance(); - unsigned int getMaxVelocity(); private: diff --git a/src/Traffic/RoadNetworkData.h b/src/Traffic/RoadNetwork/RoadNetworkData.h similarity index 79% rename from src/Traffic/RoadNetworkData.h rename to src/Traffic/RoadNetwork/RoadNetworkData.h index a175d1df8..64aa228ea 100644 --- a/src/Traffic/RoadNetworkData.h +++ b/src/Traffic/RoadNetwork/RoadNetworkData.h @@ -2,14 +2,14 @@ #include <memory> #include <vector> -#include "VectorHelper.h" -#include "invalidInput_error.h" +#include "Utilities/VectorHelper.h" +#include "Utilities/invalidInput_error.h" #include <VirtualFluidsDefinitions.h> -#include "Source.h" -#include "Sink.h" -#include "Junction.h" +#include "Source/Source.h" +#include "Sink/Sink.h" +#include "Junction/Junction.h" struct VF_PUBLIC RoadNetworkData diff --git a/src/Traffic/RoadNetwork/package.include b/src/Traffic/RoadNetwork/package.include new file mode 100644 index 000000000..e69de29bb diff --git a/src/Traffic/Sink.h b/src/Traffic/Sink/Sink.h similarity index 100% rename from src/Traffic/Sink.h rename to src/Traffic/Sink/Sink.h diff --git a/src/Traffic/SinkData.h b/src/Traffic/Sink/SinkData.h similarity index 100% rename from src/Traffic/SinkData.h rename to src/Traffic/Sink/SinkData.h diff --git a/src/Traffic/SinkSimple.cpp b/src/Traffic/Sink/SinkSimple.cpp similarity index 100% rename from src/Traffic/SinkSimple.cpp rename to src/Traffic/Sink/SinkSimple.cpp diff --git a/src/Traffic/SinkSimple.h b/src/Traffic/Sink/SinkSimple.h similarity index 86% rename from src/Traffic/SinkSimple.h rename to src/Traffic/Sink/SinkSimple.h index 409c316b7..583587d91 100644 --- a/src/Traffic/SinkSimple.h +++ b/src/Traffic/Sink/SinkSimple.h @@ -5,9 +5,9 @@ #include <iostream> #include <random> -#include "RandomHelper.h" +#include "Utilities/RandomHelper.h" #include "Sink.h" -#include "invalidInput_error.h" +#include "Utilities/invalidInput_error.h" using namespace std; diff --git a/src/Traffic/Sink/package.include b/src/Traffic/Sink/package.include new file mode 100644 index 000000000..e69de29bb diff --git a/src/Traffic/Source.cpp b/src/Traffic/Source.cpp deleted file mode 100644 index 1cc1a2393..000000000 --- a/src/Traffic/Source.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Source.h" diff --git a/src/Traffic/Source.h b/src/Traffic/Source/Source.h similarity index 100% rename from src/Traffic/Source.h rename to src/Traffic/Source/Source.h diff --git a/src/Traffic/SourceData.h b/src/Traffic/Source/SourceData.h similarity index 100% rename from src/Traffic/SourceData.h rename to src/Traffic/Source/SourceData.h diff --git a/src/Traffic/SourceTerm.cpp b/src/Traffic/Source/SourceTerm.cpp similarity index 100% rename from src/Traffic/SourceTerm.cpp rename to src/Traffic/Source/SourceTerm.cpp diff --git a/src/Traffic/SourceTerm.h b/src/Traffic/Source/SourceTerm.h similarity index 100% rename from src/Traffic/SourceTerm.h rename to src/Traffic/Source/SourceTerm.h diff --git a/src/Traffic/Source/package.include b/src/Traffic/Source/package.include new file mode 100644 index 000000000..e69de29bb diff --git a/src/Traffic/RandomHelper.cpp b/src/Traffic/Utilities/RandomHelper.cpp similarity index 100% rename from src/Traffic/RandomHelper.cpp rename to src/Traffic/Utilities/RandomHelper.cpp diff --git a/src/Traffic/RandomHelper.h b/src/Traffic/Utilities/RandomHelper.h similarity index 100% rename from src/Traffic/RandomHelper.h rename to src/Traffic/Utilities/RandomHelper.h diff --git a/src/Traffic/VectorHelper.cpp b/src/Traffic/Utilities/VectorHelper.cpp similarity index 100% rename from src/Traffic/VectorHelper.cpp rename to src/Traffic/Utilities/VectorHelper.cpp diff --git a/src/Traffic/VectorHelper.h b/src/Traffic/Utilities/VectorHelper.h similarity index 100% rename from src/Traffic/VectorHelper.h rename to src/Traffic/Utilities/VectorHelper.h diff --git a/src/Traffic/invalidInput_error.cpp b/src/Traffic/Utilities/invalidInput_error.cpp similarity index 100% rename from src/Traffic/invalidInput_error.cpp rename to src/Traffic/Utilities/invalidInput_error.cpp diff --git a/src/Traffic/invalidInput_error.h b/src/Traffic/Utilities/invalidInput_error.h similarity index 100% rename from src/Traffic/invalidInput_error.h rename to src/Traffic/Utilities/invalidInput_error.h diff --git a/src/Traffic/Utilities/package.include b/src/Traffic/Utilities/package.include new file mode 100644 index 000000000..e69de29bb diff --git a/targets/apps/LBM/Basel/resources/Junctions.txt b/targets/apps/LBM/Basel/resources/Junctions.txt new file mode 100644 index 000000000..624178339 --- /dev/null +++ b/targets/apps/LBM/Basel/resources/Junctions.txt @@ -0,0 +1,5 @@ +2 +1 e 6 e 7 e 4 e +5 s 2 s 3 s 9 s +0 e 5 e -1 a -1 a +8 s 1 s -1 a -1 a \ No newline at end of file diff --git a/targets/apps/LBM/Basel/resources/Sinks.txt b/targets/apps/LBM/Basel/resources/Sinks.txt new file mode 100644 index 000000000..86f4f3be8 --- /dev/null +++ b/targets/apps/LBM/Basel/resources/Sinks.txt @@ -0,0 +1,5 @@ +4 +2 e 0 +3 e 0 +9 e 0 +8 e 0 diff --git a/targets/apps/LBM/Basel/resources/Sources.txt b/targets/apps/LBM/Basel/resources/Sources.txt new file mode 100644 index 000000000..7ad46f19d --- /dev/null +++ b/targets/apps/LBM/Basel/resources/Sources.txt @@ -0,0 +1,5 @@ +4 +6 s 0.1 +7 s 0.1 +4 s 0.1 +0 s 0.1 \ No newline at end of file diff --git a/targets/apps/LBM/TrafficTest/TrafficTest.cpp b/targets/apps/LBM/TrafficTest/TrafficTest.cpp index acffce233..7f04d6470 100644 --- a/targets/apps/LBM/TrafficTest/TrafficTest.cpp +++ b/targets/apps/LBM/TrafficTest/TrafficTest.cpp @@ -2,17 +2,22 @@ #include <vector> #include <memory> +#include "Core/DataTypes.h" + #include "GridGenerator/StreetPointFinder/StreetPointFinder.h" +#include "GridGenerator/StreetPointFinder/JunctionReader.h" +#include "GridGenerator/StreetPointFinder/SourceReader.h" +#include "GridGenerator/StreetPointFinder/SinkReader.h" -#include "Traffic/RoadMaker.h" +#include "Traffic/RoadNetwork/RoadMaker.h" #include "Traffic/OneWayRoad.h" #include "Traffic/OneWayRoadSSJ.h" -#include "Traffic/SourceTerm.h" -#include "Traffic/Junction.h" -#include "Traffic/JunctionSimple.h" -#include "Traffic/Sink.h" -#include "Traffic/SinkSimple.h" -#include "Traffic/ConcentrationByPosition.h" +#include "Traffic/Source/SourceTerm.h" +#include "Traffic/Junction/Junction.h" +#include "Traffic/Junction/JunctionSimple.h" +#include "Traffic/Sink/Sink.h" +#include "Traffic/Sink/SinkSimple.h" +#include "Traffic/Output/ConcentrationByPosition.h" //using namespace std; @@ -31,15 +36,13 @@ int main() //Variables - int numberOfTimesteps = 100; - float vehicleDensity = 0.05; + int numberOfTimesteps = 10; + float vehicleDensity = 0.005; const unsigned int maxVelocity = 5; float dawdlePossibility = 0.5;//typical value: 0.2 unsigned int vehicleLength = 7; - - - + //StreetPointFinder @@ -48,31 +51,53 @@ int main() finder.readStreets("C:/Users/hiwi/BaselDokumente/VirtualFluidsGPU/git/targets/apps/LBM/streetTest/resources/ExampleStreets.txt"); finder.writeVTK("C:/Users/hiwi/Desktop/Basel_Ergebnisse/ExampleStreets.vtk"); + JunctionReader junctionReader; + junctionReader.readJunctions("C:/Users/hiwi/BaselDokumente/VirtualFluidsGPU/git/targets/apps/LBM/Basel/resources/Junctions.txt", finder); + SinkReader sinkReader; + sinkReader.readSinks("C:/Users/hiwi/BaselDokumente/VirtualFluidsGPU/git/targets/apps/LBM/Basel/resources/Sinks.txt", finder); + SourceReader sourceReader; + sourceReader.readSources("C:/Users/hiwi/BaselDokumente/VirtualFluidsGPU/git/targets/apps/LBM/Basel/resources/Sources.txt", finder); - //One RandomRoad + ////RandomRoad { - std::cout << "OneWay random" << std::endl; - - - unsigned int roadLength = 0; - for (unsigned int i = 0; i < 2; i++) { + for (unsigned int i = 0; i < finder.streets.size(); i++) { roadLength += finder.streets[i].numberOfCells; } auto roadNetwork = std::make_unique<RoadMaker>(roadLength, maxVelocity, vehicleLength, vehicleDensity); - auto simulator = std::make_shared<OneWayRoad>(move(roadNetwork), dawdlePossibility); - simulator->initCalculation(numberOfTimesteps); - //unique_ptr<ConcentrationOutwriter> writer = make_unique<ConcentrationByPosition>(ConcentrationByPosition(simulator->getRoadLength())); - //simulator->setConcentrationOutwriter(move(writer)); + vector< unique_ptr<Source> > sources; + for (uint i = 0; i < sourceReader.sources.size(); i++) + sources.push_back(make_unique <SourceTerm>(sourceReader.sources[i].sourceIndex, sourceReader.sources[i].sourcePossibility, roadNetwork->getMaxVelocity())); + roadNetwork->setSources(move(sources)); + + + vector< unique_ptr<Sink> > sinks; + for (uint i = 0; i < sinkReader.sinks.size(); i++) + sinks.push_back(make_unique <SinkSimple>(sinkReader.sinks[i].sinkIndex, sinkReader.sinks[i].sinkBlockedPossibility)); + roadNetwork->setSinks(move(sinks)); + vector <unique_ptr<Junction> > junctions; + for (uint i = 0; i < junctionReader.junctions.size(); i++) { + junctions.push_back(make_unique <JunctionSimple>(junctionReader.junctions[i].inCells, junctionReader.junctions[i].outCells)); + junctions[i]->setCellIndexForNoUTurn(junctionReader.junctions[i].carCanNotEnterThisOutCell); + } + roadNetwork->setJunctions(move(junctions)); + + + auto simulator = std::make_shared<OneWayRoadSSJ>(move(roadNetwork), dawdlePossibility); + simulator->initCalculation(numberOfTimesteps); + + + unique_ptr<ConcentrationOutwriter> writer = make_unique<ConcentrationByPosition>(ConcentrationByPosition(simulator->getRoadLength())); + simulator->setConcentrationOutwriter(move(writer)); std::string outputPath("C:/Users/hiwi/Desktop/Basel_Ergebnisse/"); @@ -85,10 +110,8 @@ int main() simulator->visualizeVehicleLengthForVTK(); finder.writeVTK(outputPath + outputFilename + "_" + std::to_string(step) + ".vtk", cars); } - std::cout << std::endl << std::endl; - } @@ -107,6 +130,52 @@ int main() + ////JunctionTest + //{ + // auto roadNetwork = std::make_unique<RoadMaker>(fiveCars, maxVelocity, vehicleLength); + + // vector <unsigned int> in4 = { 9 }; + // vector<unsigned int> out4 = { 10 }; + // std::unique_ptr<Junction> j = std::make_unique<JunctionSimple>(in4, out4); + // j->setCellIndexForNoUTurn({ 10 }); + // roadNetwork->addJunction(j); + + // std::shared_ptr<OneWayRoadSSJ> simulator = std::make_shared<OneWayRoadSSJ>(move(roadNetwork), dawdlePossibility); + // simulator->setSaveResults(true); + // simulator->initCalculation(numberOfTimesteps); + + // for (int step = 1; step < numberOfTimesteps + 1; step++) { + // simulator->calculateTimestep(step); + // } + + // std::cout << "Number of Cars: " << simulator->getNumberOfCars() << std::endl; + // simulator->dispResults(); + //} + + //{ + // dawdlePossibility = 0; + // vector<int> car = { -1,-1,-1,4,-1,-1,-1,-1,-1 }; + + // unique_ptr<RoadMaker> r = make_unique<RoadMaker>(car, 5, 2); + + // vector <unsigned int> in = { 4 }; + // vector <unsigned int> out = { 5 }; + // unique_ptr<Junction> j = make_unique<JunctionSimple>(JunctionSimple(in, out)); + // r->addJunction(j); + + // shared_ptr<OneWayRoadSSJ> simulator = make_shared<OneWayRoadSSJ>(move(r), dawdlePossibility); + // simulator->setSaveResults(true); + // simulator->initCalculation(1); + + // simulator->calculateTimestep(1); + + // bool success = false; + // if (simulator->getSpeedAtPosition(7) == 5) success = true; + // std::cout << success << std::endl; + // simulator->dispResults(); + //} + + ////OneWay random //{ // std::cout << "OneWay random" << std::endl; @@ -267,10 +336,5 @@ int main() - //junctionTest(maxVelocity, vehicleLength); - - //junctionTestCrossRoads(maxVelocity, vehicleLength); - - std::cin.get(); } -- GitLab