Skip to content
Snippets Groups Projects
Commit ee7b05cd authored by hiwis's avatar hiwis
Browse files

removed std::move()

parent 95acdc01
No related branches found
No related tags found
No related merge requests found
......@@ -79,7 +79,7 @@ void JunctionReader::readJunctions(std::string filename, StreetPointFinder* stre
if (onlyNeighbors) {
if (inCells.size() == 2 && outCells.size() == 2) {
specialNeighbors.cells.insert(specialNeighbors.cells.end(), inCells.begin(), inCells.end());
specialNeighbors.neighbors.push_back(outCells[1]);
specialNeighbors.neighbors.push_back(outCells[1]);
specialNeighbors.neighbors.push_back(outCells[0]);
onlyNeighbors = false;
......
......@@ -148,20 +148,20 @@ void RoadMaker::initVehicleLength(const uint vehicleLength)
}
void RoadMaker::setJunctions(std::vector<std::unique_ptr<Junction> > & junctions)
void RoadMaker::setJunctions(std::vector<std::shared_ptr<Junction> > & junctions)
{
for (auto& junc : junctions)
addJunction(move(junc));
addJunction(junc);
}
void RoadMaker::addJunction(std::unique_ptr<Junction>& junction)
void RoadMaker::addJunction(std::shared_ptr<Junction>& junction)
{
try {
junction->checkOutCellIndices(roadLength);
setJunctionAsNeighbor(junction);
this->junctions.push_back(move(junction));
this->junctions.push_back(junction);
if (junctions.size() > 999) throw std::runtime_error("too many junctions");
......@@ -174,7 +174,7 @@ void RoadMaker::addJunction(std::unique_ptr<Junction>& junction)
}
void RoadMaker::setJunctionAsNeighbor(std::unique_ptr<Junction> & junction)
void RoadMaker::setJunctionAsNeighbor(std::shared_ptr<Junction> & junction)
{
//set the junction as neighbor of the incoming cells
......@@ -200,20 +200,20 @@ void RoadMaker::setJunctionAsNeighbor(std::unique_ptr<Junction> & junction)
}
void RoadMaker::setSinks(std::vector<std::unique_ptr<Sink> > & sinks)
void RoadMaker::setSinks(std::vector<std::shared_ptr<Sink> > & sinks)
{
for (auto& sink : sinks)
addSink(move(sink));
addSink(sink);
}
void RoadMaker::addSink(std::unique_ptr<Sink>& sink)
void RoadMaker::addSink(std::shared_ptr<Sink>& sink)
{
try {
setSinkAsNeighbor(sink);
this->sinks.push_back(move(sink));
this->sinks.push_back(sink);
if (sinks.size() > 999) throw std::runtime_error("too many sinks");
......@@ -227,7 +227,7 @@ void RoadMaker::addSink(std::unique_ptr<Sink>& sink)
}
void RoadMaker::setSinkAsNeighbor(std::unique_ptr<Sink> & sink)
void RoadMaker::setSinkAsNeighbor(std::shared_ptr<Sink> & sink)
{
//set the sink as neighbor of the incoming cell
......@@ -247,18 +247,18 @@ void RoadMaker::setSinkAsNeighbor(std::unique_ptr<Sink> & sink)
void RoadMaker::setSources(std::vector< std::unique_ptr<Source> > & sources)
void RoadMaker::setSources(std::vector< std::shared_ptr<Source> > & sources)
{
for (auto& source : sources)
addSource(move(source));
addSource(source);
}
void RoadMaker::addSource(std::unique_ptr<Source>& source)
void RoadMaker::addSource(std::shared_ptr<Source>& source)
{
try {
if (source->getIndex() >= roadLength) throw invalidInput_error("Source index is greater than roadlength");
this->sources.push_back(move(source));
this->sources.push_back(source);
}
catch (const std::exception& e) {
......
......@@ -16,12 +16,12 @@ public:
~RoadMaker();
void setJunctions( std::vector<std::unique_ptr<Junction> > & junctions); //max 999 junctions
void addJunction(std::unique_ptr<Junction> & junction);
void setSinks(std::vector< std::unique_ptr<Sink> > & sinks); //max 999 sinks
void addSink(std::unique_ptr<Sink> & sink);
void setSources(std::vector< std::unique_ptr<Source> > & sources);
void addSource(std::unique_ptr<Source> & source);
void setJunctions( std::vector<std::shared_ptr<Junction> > & junctions); //max 999 junctions
void addJunction(std::shared_ptr<Junction> & junction);
void setSinks(std::vector< std::shared_ptr<Sink> > & sinks); //max 999 sinks
void addSink(std::shared_ptr<Sink> & sink);
void setSources(std::vector< std::shared_ptr<Source> > & sources);
void addSource(std::shared_ptr<Source> & source);
void setNeighbor(uint index, uint neighbor); // don't use it for setting sinks or junctions!
void setNeighborForCurve(uint index, uint neighbor);
......@@ -43,8 +43,8 @@ private:
void initVehicleLength(const uint vehicleLength);
int randomSpeed();
void setJunctionAsNeighbor(std::unique_ptr<Junction> & junction);
void setSinkAsNeighbor(std::unique_ptr<Sink> & sink);
void setJunctionAsNeighbor(std::shared_ptr<Junction> & junction);
void setSinkAsNeighbor(std::shared_ptr<Sink> & sink);
};
......@@ -11,6 +11,10 @@
#include "Utilities/Logger.h"
#include "GPU/TrafficTimestep.h"
#include "Output/ConcBySpeedAndAcceleration.h"
#include "Output/ConcentrationByPosition.h"
TrafficMovement::TrafficMovement(std::shared_ptr<RoadNetworkData> road, const real dawdlePossibility)
{
this->road = std::move(road);
......@@ -85,9 +89,9 @@ void TrafficMovement::setMaxAcceleration(uint maxAcceleration)
this->road->maxAcceleration = maxAcceleration;
}
void TrafficMovement::setConcentrationOutwriter(std::unique_ptr<ConcentrationOutwriter> writer)
void TrafficMovement::setConcentrationOutwriter(uint roadlength, real* concArrayStart)
{
this->concWriter = std::move(writer);
this->concWriter = std::make_unique<ConcBySpeedAndAcceleration>(ConcBySpeedAndAcceleration(roadlength, concArrayStart));
}
......
......@@ -26,7 +26,7 @@ public:
//setUp
void setSlowToStart(const real slowStartPossibility);
void setMaxAcceleration(uint maxAcceleration);
void setConcentrationOutwriter(std::unique_ptr<ConcentrationOutwriter> writer);
void setConcentrationOutwriter(uint roadlength, real* concArrayStart = 0);
void setSaveResultsTrue(uint timeSteps);
void setUseGPU(real * pConcArray = nullptr);
void setUseLogger();
......
......@@ -39,40 +39,39 @@ void TrafficMovementFactoryTest::initTrafficMovement(bool useGPU, real * pConcAr
std::vector<int> road(40);
std::fill(road.begin(), road.end(), -1);
road[9] = 5;
auto roadNetwork = std::make_unique<RoadMaker>(road, maxVelocity, vehicleLength);
auto roadNetwork = std::make_shared<RoadMaker>(road, maxVelocity, vehicleLength);
//RoadMaker(const uint roadLength, const uint maxVelocity, uint vehicleLength, const real vehicleDensity); //random vehicle Distribution
//RoadMaker(const std::vector<int> vehicleDistribution, const uint maxVelocity, uint vehicleLength); //given vehicle distribution
//RoadMaker(const uint roadLength, const uint maxVelocity, uint vehicleLength);//empty road
//Sources
std::unique_ptr<Source> source = std::make_unique <SourceRandom>(SourceRandom(0, 0.9f, maxVelocity));
std::unique_ptr<Source> source1 = std::make_unique <SourceRandom>(SourceRandom(11, 0.9f, maxVelocity));
std::shared_ptr<Source> source = std::make_shared <SourceRandom>(SourceRandom(0, 0.9f, maxVelocity));
std::shared_ptr<Source> source1 = std::make_shared <SourceRandom>(SourceRandom(11, 0.9f, maxVelocity));
roadNetwork->addSource(source);
roadNetwork->addSource(source1);
//Sinks
std::unique_ptr<Sink> s = std::make_unique <SinkRandom>(SinkRandom(roadLength-1, 0.5f));
std::unique_ptr<Sink> s1 = std::make_unique <SinkRandom>(SinkRandom(29, 0.5f));
roadNetwork->addSink(move(s));
roadNetwork->addSink(move(s1));
std::shared_ptr<Sink> s = std::make_shared <SinkRandom>(SinkRandom(roadLength-1, 0.5f));
std::shared_ptr<Sink> s1 = std::make_shared <SinkRandom>(SinkRandom(29, 0.5f));
roadNetwork->addSink(s);
roadNetwork->addSink(s1);
//Junctions
std::vector<uint> inCellIndices = { 9,19 };
std::vector<uint> outCellIndices = { 21,31 };
std::unique_ptr<Junction> j = std::make_unique<JunctionRandom>(JunctionRandom(inCellIndices, outCellIndices,5));
roadNetwork->addJunction(std::move(j));
std::shared_ptr<Junction> j = std::make_shared<JunctionRandom>(JunctionRandom(inCellIndices, outCellIndices,5));
roadNetwork->addJunction(j);
//init TrafficMovement
this->simulator = std::make_shared<TrafficMovement>(std::move(roadNetwork), dawdlePossibility);
this->simulator = std::make_shared<TrafficMovement>(roadNetwork, dawdlePossibility);
if (useSlowToStart) simulator->setSlowToStart(slowToStartPossibility);
simulator->setMaxAcceleration(maxAcceleration);
if (this->useGPU) simulator->setUseGPU(pConcArray);
//init ConcentrationOutwriter
if (!this->useGPU) {
std::unique_ptr<ConcentrationOutwriter> writer = std::make_unique<ConcBySpeedAndAcceleration>(ConcBySpeedAndAcceleration(simulator->getRoadLength(), pConcArray));
simulator->setConcentrationOutwriter(move(writer));
if (!this->useGPU) {;
simulator->setConcentrationOutwriter(simulator->getRoadLength(), pConcArray);
}
}
......
......@@ -90,30 +90,30 @@ void TrafficMovementFactory::initTrafficMovement(std::string path, bool useGPU,
//make RoadNetwork
auto roadNetwork = std::make_unique<RoadMaker>(roadLength, maxVelocity, vehicleLength, vehicleDensity);
auto roadNetwork = std::make_shared<RoadMaker>(roadLength, maxVelocity, vehicleLength, vehicleDensity);
//Sources
std::vector< std::unique_ptr<Source> > sources;
std::vector< std::shared_ptr<Source> > sources;
for (uint i = 0; i < sourceReader.sources.size(); i++)
sources.push_back(std::make_unique <SourceRandom>(sourceReader.sources[i].sourceIndex, sourceReader.sources[i].sourcePossibility, roadNetwork->getMaxVelocity()));
roadNetwork->setSources(move(sources));
sources.push_back(std::make_shared <SourceRandom>(sourceReader.sources[i].sourceIndex, sourceReader.sources[i].sourcePossibility, roadNetwork->getMaxVelocity()));
roadNetwork->setSources(sources);
//Sinks
std::vector< std::unique_ptr<Sink> > sinks;
std::vector< std::shared_ptr<Sink> > sinks;
for (uint i = 0; i < sinkReader.sinks.size(); i++)
sinks.push_back(std::make_unique <SinkRandom>(sinkReader.sinks[i].sinkIndex, sinkReader.sinks[i].sinkBlockedPossibility));
roadNetwork->setSinks(move(sinks));
sinks.push_back(std::make_shared <SinkRandom>(sinkReader.sinks[i].sinkIndex, sinkReader.sinks[i].sinkBlockedPossibility));
roadNetwork->setSinks(sinks);
//Junctions
std::vector <std::unique_ptr<Junction> > junctions;
std::vector <std::shared_ptr<Junction> > junctions;
for (uint i = 0; i < junctionReader.junctions.size(); i++) {
junctions.push_back(std::make_unique <JunctionRandom>(junctionReader.junctions[i].inCells, junctionReader.junctions[i].outCells, junctionReader.junctions[i].trafficLightSwitchTime));
junctions.push_back(std::make_shared <JunctionRandom>(junctionReader.junctions[i].inCells, junctionReader.junctions[i].outCells, junctionReader.junctions[i].trafficLightSwitchTime));
junctions[i]->setCellIndicesForNoUTurn(junctionReader.junctions[i].carCanNotEnterThisOutCell);
}
roadNetwork->setJunctions(move(junctions));
roadNetwork->setJunctions(junctions);
//set neighbors for curves
......@@ -123,7 +123,7 @@ void TrafficMovementFactory::initTrafficMovement(std::string path, bool useGPU,
//init TrafficMovement
this->simulator = std::make_shared<TrafficMovement>(move(roadNetwork), dawdlePossibility);
this->simulator = std::make_shared<TrafficMovement>(roadNetwork, dawdlePossibility);
simulator->setMaxAcceleration(maxAcceleration);
if (useSlowToStart) simulator->setSlowToStart(slowToStartPossibility);
if (useLogger) simulator->setUseLogger();
......@@ -131,10 +131,9 @@ void TrafficMovementFactory::initTrafficMovement(std::string path, bool useGPU,
//init ConcentrationOutwriter
if (!this->useGPU) {
std::unique_ptr<ConcentrationOutwriter> writer = std::make_unique<ConcBySpeedAndAcceleration>(ConcBySpeedAndAcceleration(simulator->getRoadLength(), pConcArray));
simulator->setConcentrationOutwriter(move(writer));
simulator->setConcentrationOutwriter(simulator->getRoadLength(), pConcArray);
}
//prepare writing to vtk
//this->outputPath = "M:/Basel2019/results/";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment