diff --git a/Simulation.cpp b/Simulation.cpp index 2c9408ee1f03ae830305b5b0cad3c9f4a450b015..b4f271f21cbeb5256b6f1e54e4c743f074137eb3 100644 --- a/Simulation.cpp +++ b/Simulation.cpp @@ -52,13 +52,13 @@ Simulation::Simulation(const ArgumentParser& args) _tmax = 0; _seed = 8091983; _deltaT = 0; - _building = NULL; + _building = nullptr; //_direction = NULL; - _operationalModel = NULL; - _solver = NULL; + _operationalModel = nullptr; + _solver = nullptr; _iod = new IODispatcher(); _fps = 1; - _em = NULL; + _em = nullptr; _hpc = -1; _profiling = false; _argsParser = args; @@ -66,13 +66,12 @@ Simulation::Simulation(const ArgumentParser& args) Simulation::~Simulation() { - delete _building; delete _solver; delete _iod; delete _em; } -int Simulation::GetPedsNumber() const +long Simulation::GetPedsNumber() const { return _nPeds; } @@ -191,7 +190,7 @@ bool Simulation::InitArgs(const ArgumentParser& args) } } - _distribution = std::unique_ptr<PedDistributor>(new PedDistributor(_argsParser.GetProjectFile(), _argsParser.GetAgentsParameters(),_argsParser.GetSeed())); + _operationalModel = args.GetModel(); s.append(_operationalModel->GetDescription()); @@ -214,49 +213,15 @@ bool Simulation::InitArgs(const ArgumentParser& args) sprintf(tmp, "\tfps: %f\n", _fps); s.append(tmp); - // Route choice - - auto routingEngine = args.GetRoutingEngine(); - - - + _routingEngine = args.GetRoutingEngine(); + auto distributor = std::unique_ptr<PedDistributor>(new PedDistributor(_argsParser.GetProjectFile(), _argsParser.GetAgentsParameters(),_argsParser.GetSeed())); // IMPORTANT: do not change the order in the following.. - _building = new Building(); - _building->SetRoutingEngine(routingEngine.get()); - _building->SetProjectFilename(args.GetProjectFile()); - _building->SetProjectRootDir(args.GetProjectRootDir()); - - if (!_building->LoadGeometry()) - return false; - - if (!_building->LoadRoutingInfo(args.GetProjectFile())) - return false; - _building->AddSurroundingRoom(); - - if(!_building->InitGeometry()) - return false; // create the polygons - - if(!_building->LoadTrafficInfo()) - return false; - - _nPeds = _distribution->Distribute(_building); - - //using linkedcells - if (args.GetLinkedCells()) { - s.append("\tusing Linked-Cells for spatial queries\n"); - _building->InitGrid(args.GetLinkedCellSize()); - } else { - _building->InitGrid(-1); - } - - // initialize the routing engine before doing any other things - if(routingEngine->Init(_building)==false) - return false; + _building = std::unique_ptr<Building>(new Building(args.GetProjectFile(), args.GetProjectRootDir(), *_routingEngine, *distributor, args.GetLinkedCellSize())); //perform customs initialisation, like computing the phi for the gcfm //this should be called after the routing engine has been initialised // because a direction is needed for this initialisation. - if(_operationalModel->Init(_building)==false) + if(_operationalModel->Init(_building.get())==false) return false; //other initializations @@ -264,15 +229,12 @@ bool Simulation::InitArgs(const ArgumentParser& args) for (Pedestrian *ped : allPeds) { ped->Setdt(_deltaT); } + _nPeds = allPeds.size(); //pBuilding->WriteToErrorLog(); //get the seed _seed = args.GetSeed(); - // perform a general check to the . - if(_building->SanityCheck()==false) - return false; - //size of the cells/GCFM/Gompertz if (args.GetDistEffMaxPed() > args.GetLinkedCellSize()) { Log->Write( @@ -282,7 +244,7 @@ bool Simulation::InitArgs(const ArgumentParser& args) } //read the events - _em = new EventManager(_building); + _em = new EventManager(_building.get()); _em->readEventsXml(); _em->listEvents(); @@ -307,9 +269,9 @@ int Simulation::RunSimulation() double t = 0.0; // writing the header - _iod->WriteHeader(_nPeds, _fps, _building, _seed); - _iod->WriteGeometry(_building); - _iod->WriteFrame(0, _building); + _iod->WriteHeader(_nPeds, _fps, _building.get(), _seed); + _iod->WriteGeometry(_building.get()); + _iod->WriteFrame(0, _building.get()); //first initialisation needed by the linked-cells UpdateRoutesAndLocations(); @@ -325,7 +287,7 @@ int Simulation::RunSimulation() t = 0 + (frameNr - 1) * _deltaT; // update the positions - _operationalModel->ComputeNextTimeStep(t, _deltaT, _building); + _operationalModel->ComputeNextTimeStep(t, _deltaT, _building.get()); // update the routes and locations //Update(); @@ -346,7 +308,7 @@ int Simulation::RunSimulation() // write the trajectories if (frameNr % writeInterval == 0) { - _iod->WriteFrame(frameNr / writeInterval, _building); + _iod->WriteFrame(frameNr / writeInterval, _building.get()); } // needed to control the execution time PART 2 diff --git a/Simulation.h b/Simulation.h index 3c5630bc11edc18b5a496e9f90ca238dcf88aa94..1b1186e33de21afb82878bfdbc5590a0e7e7a57b 100644 --- a/Simulation.h +++ b/Simulation.h @@ -68,14 +68,11 @@ private: ///seed using for the random number generator unsigned int _seed; /// building object - Building* _building; - ///initial distribution of the pedestrians - std::unique_ptr<PedDistributor> _distribution; - /// door crossing strategy for the pedestrians - //DirectionStrategy* _direction; + std::unique_ptr<Building> _building; /// Force model to use std::shared_ptr<OperationalModel> _operationalModel; /// differential equation solver + std::shared_ptr<RoutingEngine> _routingEngine; ODESolver* _solver; /// writing the trajectories to file IODispatcher* _iod; @@ -95,7 +92,7 @@ public: /** * Initialize the number of agents in the simulation */ - int GetPedsNumber() const; + long GetPedsNumber() const; /** * Read parameters from the argument parser class. diff --git a/general/ArgumentParser.cpp b/general/ArgumentParser.cpp index 549a7ab1b8d7239aa01a78ee863d45fb6d82e2bc..190ba9e4c3ac847986cc1f136734854da10b4055 100644 --- a/general/ArgumentParser.cpp +++ b/general/ArgumentParser.cpp @@ -1056,7 +1056,9 @@ int ArgumentParser::GetLog() const double ArgumentParser::GetLinkedCellSize() const { - return pLinkedCellSize; + if (pLinkedCells) + return pLinkedCellSize; + return -1; } unsigned int ArgumentParser::GetSeed() const diff --git a/geometry/Building.cpp b/geometry/Building.cpp index 8578ad0aac288d64b1804e6940c3ab2283f8e455..7ea209d977dcb456e19d590d5d3004a0488cb212 100644 --- a/geometry/Building.cpp +++ b/geometry/Building.cpp @@ -34,8 +34,8 @@ #ifdef _SIMULATOR #include "../pedestrian/Pedestrian.h" #include "../mpi/LCGrid.h" -#include "../routing/RoutingEngine.h" #include "../routing/SafestPathRouter.h" + #endif //#undef _OPENMP @@ -60,11 +60,27 @@ Building::Building() _projectFilename = ""; _geometryFilename= ""; _rooms = vector<Room*>(); - _routingEngine = NULL; - _linkedCellGrid = NULL; + _routingEngine = nullptr; + _linkedCellGrid = nullptr; _savePathway = false; } +Building::Building(const std::string& filename, const std::string& rootDir, RoutingEngine& engine, PedDistributor& distributor, double linkedCellSize) + :_projectFilename{filename}, _projectRootDir{rootDir}, _routingEngine{&engine} +{ + _caption = "no_caption"; + _rooms = vector<Room*>(); + _savePathway = false; + this->LoadGeometry(); + this->LoadRoutingInfo(filename); + this->AddSurroundingRoom(); + this->InitGeometry(); + this->LoadTrafficInfo(); + distributor.Distribute(this); + this->InitGrid(linkedCellSize); + _routingEngine->Init(this); + this->SanityCheck(); +} Building::~Building() { @@ -1364,3 +1380,5 @@ bool Building::SaveGeometry(const std::string &filename) } #endif // _SIMULATOR + + diff --git a/geometry/Building.h b/geometry/Building.h index b4cecc6cee3de70a3d56c8623988bd9fcce85572..a613bb3d60854878db2393a4302356717e8c95df 100644 --- a/geometry/Building.h +++ b/geometry/Building.h @@ -41,12 +41,15 @@ #include "Hline.h" #include "Obstacle.h" #include "Goal.h" +#include "../routing/RoutingEngine.h" +#include "../pedestrian/PedDistributor.h" class RoutingEngine; class Pedestrian; class Transition; class LCGrid; class ForceModel; +class PedDistributor; class Building { @@ -74,6 +77,7 @@ private: public: /// constructor Building(); + Building(const std::string&, const std::string&, RoutingEngine&, PedDistributor&, double); /// destructor virtual ~Building(); diff --git a/main.cpp b/main.cpp index 57ac309bf3f79d6ea1203bd425d69d5b21ef88b9..3b88ee1020abb386fd7277bb5e8f65f133a3c99c 100644 --- a/main.cpp +++ b/main.cpp @@ -81,6 +81,8 @@ int main(int argc, char **argv) printf("Errors : %d\n", Log->GetErrors()); } } + else + Log->Write("error occured while parsing"); // do the last cleaning delete args; delete Log; diff --git a/pedestrian/PedDistributor.cpp b/pedestrian/PedDistributor.cpp index 0533dad95cdcc054e13bd066a43ae9baa9fc54c0..35c20b77e8912f742f8e86436f3772b67146aca8 100644 --- a/pedestrian/PedDistributor.cpp +++ b/pedestrian/PedDistributor.cpp @@ -218,7 +218,6 @@ PedDistributor::~PedDistributor() } _start_dis_sub.clear(); _start_dis.clear(); - //empty the parameters maps } diff --git a/routing/RoutingEngine.cpp b/routing/RoutingEngine.cpp index c0688cd5870ead2150b869de4119b55f0c7e835d..6885b6ec4a1c0ec0d80b0bc2765c915b6d27ce18 100644 --- a/routing/RoutingEngine.cpp +++ b/routing/RoutingEngine.cpp @@ -114,5 +114,6 @@ bool RoutingEngine::Init(Building* building) if(_routersCollection[r]->Init(building)==false) status=false; } + Log->Write("bad status" + status); return status; }