From 50537e39a24840a4949f7356d21e67b5a74d9aa3 Mon Sep 17 00:00:00 2001 From: Ulrich Kemloh Date: Mon, 10 Nov 2014 17:25:53 +0100 Subject: [PATCH] changing functions signature from void to bool. Geometry functions now return false on failure. --- IO/IODispatcher.cpp | 138 ++++++++------- Simulation.cpp | 312 ++++++++++++++++++--------------- Simulation.h | 2 +- events/EventManager.cpp | 29 +-- general/Macros.h | 3 + geometry/Building.cpp | 62 ++++--- geometry/Building.h | 10 +- geometry/Goal.cpp | 7 +- geometry/Goal.h | 2 +- geometry/Obstacle.cpp | 12 +- geometry/Obstacle.h | 2 +- geometry/SubRoom.cpp | 18 +- geometry/SubRoom.h | 8 +- main.cpp | 54 +++--- math/GCFMModel.cpp | 16 +- math/GCFMModel.h | 19 +- math/GompertzModel.cpp | 12 +- math/GompertzModel.h | 14 +- math/OperationalModel.h | 3 +- pedestrian/Pedestrian.cpp | 2 +- routing/CognitiveMapRouter.cpp | 3 +- routing/CognitiveMapRouter.h | 2 +- routing/DirectionStrategy.cpp | 64 +++---- routing/DummyRouter.cpp | 3 +- routing/DummyRouter.h | 2 +- routing/GlobalRouter.cpp | 4 +- routing/GlobalRouter.h | 4 +- routing/GraphRouter.cpp | 6 +- routing/GraphRouter.h | 2 +- routing/MeshRouter.cpp | 3 +- routing/MeshRouter.h | 2 +- routing/QuickestPathRouter.cpp | 6 +- routing/QuickestPathRouter.h | 2 +- routing/Router.h | 2 +- routing/RoutingEngine.cpp | 7 +- routing/RoutingEngine.h | 3 +- routing/SafestPathRouter.cpp | 10 +- routing/SafestPathRouter.h | 3 +- routing/graph/RoutingGraph.cpp | 8 +- 39 files changed, 460 insertions(+), 401 deletions(-) diff --git a/IO/IODispatcher.cpp b/IO/IODispatcher.cpp index 1e6b8187..9d468157 100644 --- a/IO/IODispatcher.cpp +++ b/IO/IODispatcher.cpp @@ -315,9 +315,9 @@ void TrajectoriesJPSV04::WriteFrame(int frameNr, Building* building) string caption = r->GetCaption(); if ((rooms_to_plot.empty() == false) - && (IsElementInVector(rooms_to_plot, caption) == false)) { - continue; - } + && (IsElementInVector(rooms_to_plot, caption) == false)) { + continue; + } data.append(WritePed(ped)); } @@ -341,6 +341,7 @@ TrajectoriesFLAT::TrajectoriesFLAT() : Trajectories() void TrajectoriesFLAT::WriteHeader(int nPeds, double fps, Building* building, int seed) { + (void) seed; (void) nPeds; char tmp[CLENGTH] = ""; Write("#description: my super simulation"); sprintf(tmp, "#framerate: %0.2f",fps); @@ -356,7 +357,7 @@ void TrajectoriesFLAT::WriteHeader(int nPeds, double fps, Building* building, in void TrajectoriesFLAT::WriteGeometry(Building* building) { - + (void) building; } void TrajectoriesFLAT::WriteFrame(int frameNr, Building* building) @@ -392,6 +393,8 @@ TrajectoriesVTK::TrajectoriesVTK() void TrajectoriesVTK::WriteHeader(int nPeds, double fps, Building* building, int seed) { + //suppress unused warnings + (void) nPeds; (void) fps ; (void) seed; Write("# vtk DataFile Version 4.0"); Write(building->GetCaption()); Write("ASCII"); @@ -447,6 +450,7 @@ void TrajectoriesVTK::WriteGeometry(Building* building) void TrajectoriesVTK::WriteFrame(int frameNr, Building* building) { + (void) frameNr; (void)building; } void TrajectoriesVTK::WriteFooter() @@ -481,24 +485,24 @@ void TrajectoriesJPSV06::WriteHeader(int nPeds, double fps, Building* building, void TrajectoriesJPSV06::WriteGeometry(Building* building) { // just put a link to the geometry file -// string embed_geometry; -// embed_geometry.append("\t\n"); -// char file_location[CLENGTH] = ""; -// sprintf(file_location, "\t\n", building->GetGeometryFilename().c_str()); -// embed_geometry.append(file_location); -// //embed_geometry.append("\t\n"); -// -// const map& hlines=building->GetAllHlines(); -// if(hlines.size()>0){ -// //embed_geometry.append("\t\n"); -// for (std::map::const_iterator it=hlines.begin(); it!=hlines.end(); ++it) -// { -// embed_geometry.append(it->second->WriteElement()); -// } -// //embed_geometry.append("\t\n"); -// } -// embed_geometry.append("\t\n"); -// Write(embed_geometry); + // string embed_geometry; + // embed_geometry.append("\t\n"); + // char file_location[CLENGTH] = ""; + // sprintf(file_location, "\t\n", building->GetGeometryFilename().c_str()); + // embed_geometry.append(file_location); + // //embed_geometry.append("\t\n"); + // + // const map& hlines=building->GetAllHlines(); + // if(hlines.size()>0){ + // //embed_geometry.append("\t\n"); + // for (std::map::const_iterator it=hlines.begin(); it!=hlines.end(); ++it) + // { + // embed_geometry.append(it->second->WriteElement()); + // } + // //embed_geometry.append("\t\n"); + // } + // embed_geometry.append("\t\n"); + // Write(embed_geometry); //set the content of the file string fileName=building->GetProjectRootDir()+"/"+building->GetGeometryFilename().c_str(); @@ -510,51 +514,51 @@ void TrajectoriesJPSV06::WriteGeometry(Building* building) buffer << t.rdbuf(); embed_geometry=buffer.str(); Write(embed_geometry); -// -// -// //collecting the hlines -// std::stringstream hlines_buffer; -// // add the header -// hlines_buffer<<" "< "<& hlines=building->GetAllHlines(); -// for (std::map::const_iterator it=hlines.begin(); it!=hlines.end(); ++it) -// { -// Hline* hl=it->second; -// hlines_buffer <<"\tGetID()<<"\" room_id=\""<GetRoom1()->GetID() -// <<"\" subroom_id=\""<< hl->GetSubRoom1()->GetSubRoomID()<<"\">"<GetPoint1()._x<<"\" py=\""<< hl->GetPoint1()._y<<"\" />"<GetPoint2()._x<<"\" py=\""<< hl->GetPoint2()._y<<"\" />"<"< "< "<Write("WARNING:\t missing %s tag while writing the geometry in the trajectory file.",to_replace.c_str()); -// } -// -// embed_geometry.replace(start_pos, to_replace.length(), hline_string); -// Write(embed_geometry); - -// Write("\t"); -// Write("\t\t"); -// Write("\t\t"); -// Write("\t\t"); -// Write("\t\t"); -// Write("\t\t"); -// Write("\t\t"); -// Write("\t\t"); -// Write("\t\n"); + // + // + // //collecting the hlines + // std::stringstream hlines_buffer; + // // add the header + // hlines_buffer<<" "< "<& hlines=building->GetAllHlines(); + // for (std::map::const_iterator it=hlines.begin(); it!=hlines.end(); ++it) + // { + // Hline* hl=it->second; + // hlines_buffer <<"\tGetID()<<"\" room_id=\""<GetRoom1()->GetID() + // <<"\" subroom_id=\""<< hl->GetSubRoom1()->GetSubRoomID()<<"\">"<GetPoint1()._x<<"\" py=\""<< hl->GetPoint1()._y<<"\" />"<GetPoint2()._x<<"\" py=\""<< hl->GetPoint2()._y<<"\" />"<"< "< "<Write("WARNING:\t missing %s tag while writing the geometry in the trajectory file.",to_replace.c_str()); + // } + // + // embed_geometry.replace(start_pos, to_replace.length(), hline_string); + // Write(embed_geometry); + + // Write("\t"); + // Write("\t\t"); + // Write("\t\t"); + // Write("\t\t"); + // Write("\t\t"); + // Write("\t\t"); + // Write("\t\t"); + // Write("\t\t"); + // Write("\t\n"); } void TrajectoriesJPSV06::WriteFrame(int frameNr, Building* building) diff --git a/Simulation.cpp b/Simulation.cpp index 110fa144..72f2c952 100644 --- a/Simulation.cpp +++ b/Simulation.cpp @@ -28,7 +28,6 @@ * **/ - #include "Simulation.h" #include "math/GCFMModel.h" @@ -42,7 +41,6 @@ #define omp_get_max_threads() 1 #endif - using namespace std; OutputHandler* Log; @@ -51,7 +49,7 @@ Simulation::Simulation() { _nPeds = 0; _tmax = 0; - _seed=8091983; + _seed = 8091983; _deltaT = 0; _building = NULL; _distribution = NULL; @@ -59,11 +57,11 @@ Simulation::Simulation() _operationalModel = NULL; _solver = NULL; _iod = new IODispatcher(); - _fps=1; - _em=NULL; - _argsParser=NULL; - _hpc=-1; - _profiling=false; + _fps = 1; + _em = NULL; + _argsParser = NULL; + _hpc = -1; + _profiling = false; } Simulation::~Simulation() @@ -82,57 +80,64 @@ int Simulation::GetPedsNumber() const return _nPeds; } -void Simulation::InitArgs(ArgumentParser* args) +bool Simulation::InitArgs(ArgumentParser* args) { char tmp[CLENGTH]; string s = "Parameter:\n"; - _argsParser=args; - switch (args->GetLog()) { + _argsParser = args; + switch (args->GetLog()) + { case 0: // no log file //Log = new OutputHandler(); break; case 1: - if(Log) delete Log; + if (Log) + delete Log; Log = new STDIOHandler(); break; case 2: { - char name[CLENGTH]=""; - sprintf(name,"%s.P0.dat",args->GetErrorLogFile().c_str()); - if(Log) delete Log; + char name[CLENGTH] = ""; + sprintf(name, "%s.P0.dat", args->GetErrorLogFile().c_str()); + if (Log) + delete Log; Log = new FileHandler(name); } - break; + break; default: printf("Wrong option for Logfile!\n\n"); - exit(0); + return false; } - - if(args->GetPort()!=-1) { - switch(args->GetFileFormat()) { + if (args->GetPort() != -1) { + switch (args->GetFileFormat()) + { case FORMAT_XML_PLAIN_WITH_MESH: case FORMAT_XML_PLAIN: { - OutputHandler* travisto = new SocketHandler(args->GetHostname(), args->GetPort()); - Trajectories* output= new TrajectoriesJPSV06(); + OutputHandler* travisto = new SocketHandler(args->GetHostname(), + args->GetPort()); + Trajectories* output = new TrajectoriesJPSV06(); output->SetOutputHandler(travisto); _iod->AddIO(output); break; } case FORMAT_XML_BIN: { - Log->Write("INFO: \tFormat xml-bin not yet supported in streaming\n"); + Log->Write( + "INFO: \tFormat xml-bin not yet supported in streaming\n"); //exit(0); break; } case FORMAT_PLAIN: { - Log->Write("INFO: \tFormat plain not yet supported in streaming\n"); - exit(0); + Log->Write( + "INFO: \tFormat plain not yet supported in streaming\n"); + return false; break; } case FORMAT_VTK: { - Log->Write("INFO: \tFormat vtk not yet supported in streaming\n"); - exit(0); + Log->Write( + "INFO: \tFormat vtk not yet supported in streaming\n"); + return false; break; } } @@ -140,26 +145,30 @@ void Simulation::InitArgs(ArgumentParser* args) s.append("\tonline streaming enabled \n"); } - if(args->GetTrajectoriesFile().empty()==false) { - switch (args->GetFileFormat()) { + if (args->GetTrajectoriesFile().empty() == false) { + switch (args->GetFileFormat()) + { case FORMAT_XML_PLAIN: { - OutputHandler* tofile = new FileHandler(args->GetTrajectoriesFile().c_str()); - Trajectories* output= new TrajectoriesJPSV05(); + OutputHandler* tofile = new FileHandler( + args->GetTrajectoriesFile().c_str()); + Trajectories* output = new TrajectoriesJPSV05(); output->SetOutputHandler(tofile); _iod->AddIO(output); break; } case FORMAT_PLAIN: { - OutputHandler* file = new FileHandler(args->GetTrajectoriesFile().c_str()); - Trajectories* output= new TrajectoriesFLAT(); + OutputHandler* file = new FileHandler( + args->GetTrajectoriesFile().c_str()); + Trajectories* output = new TrajectoriesFLAT(); output->SetOutputHandler(file); _iod->AddIO(output); break; } case FORMAT_VTK: { Log->Write("INFO: \tFormat vtk not yet supported\n"); - OutputHandler* file = new FileHandler((args->GetTrajectoriesFile() +".vtk").c_str()); - Trajectories* output= new TrajectoriesVTK(); + OutputHandler* file = new FileHandler( + (args->GetTrajectoriesFile() + ".vtk").c_str()); + Trajectories* output = new TrajectoriesVTK(); output->SetOutputHandler(file); _iod->AddIO(output); break; @@ -190,7 +199,8 @@ void Simulation::InitArgs(ArgumentParser* args) int direction = args->GetExitStrategy(); sprintf(tmp, "\tDirection to the exit: %d\n", direction); s.append(tmp); - switch (direction) { + switch (direction) + { case 1: _direction = new DirectionMiddlePoint(); break; @@ -205,17 +215,20 @@ void Simulation::InitArgs(ArgumentParser* args) break; default: _direction = new DirectionMinSeperationShorterLine(); - sprintf(tmp, "\t Warning Direction %d is not in [1,4]. Fall back to 2\n", direction); + sprintf(tmp, + "\t Warning Direction %d is not in [1,4]. Fall back to 2\n", + direction); s.append(tmp); break; } - int model = args->GetModel(); - if(model == MODEL_GFCM) - { //GCFM - //if(args->GetHPCFlag()==0){ - _operationalModel = new GCFMModel(_direction, args->GetNuPed(), args->GetNuWall(), args->GetDistEffMaxPed(), - args->GetDistEffMaxWall(), args->GetIntPWidthPed(), args->GetIntPWidthWall(), - args->GetMaxFPed(), args->GetMaxFWall()); + int model = args->GetModel(); + if (model == MODEL_GFCM) { //GCFM + //if(args->GetHPCFlag()==0){ + _operationalModel = new GCFMModel(_direction, args->GetNuPed(), + args->GetNuWall(), args->GetDistEffMaxPed(), + args->GetDistEffMaxWall(), args->GetIntPWidthPed(), + args->GetIntPWidthWall(), args->GetMaxFPed(), + args->GetMaxFWall()); s.append("\tModel: GCFMModel\n"); s.append(_operationalModel->GetDescription()); //} @@ -233,11 +246,11 @@ void Simulation::InitArgs(ArgumentParser* args) //s.append("\tModel: GCFMModel\n"); //s.append(_model->writeParameter()); //} - } - else if (model == MODEL_GOMPERTZ) - { //Gompertz - _operationalModel = new GompertzModel(_direction, args->GetNuPed(), args->GetaPed(), args->GetbPed(), args->GetcPed(), - args->GetNuWall(), args->GetaWall(), args->GetbWall(), args->GetcWall() ); + } else if (model == MODEL_GOMPERTZ) { //Gompertz + _operationalModel = new GompertzModel(_direction, args->GetNuPed(), + args->GetaPed(), args->GetbPed(), args->GetcPed(), + args->GetNuWall(), args->GetaWall(), args->GetbWall(), + args->GetcWall()); s.append("\tModel: GompertzModel\n"); s.append(_operationalModel->GetDescription()); } @@ -248,14 +261,14 @@ void Simulation::InitArgs(ArgumentParser* args) s.append(tmp); //switch (solver) { //case 1: - //_solver = new EulerSolver(_model); - //break; - //case 2: - // _solver = new VelocityVerletSolver(_model); - // break; - //case 3: - // _solver = new LeapfrogSolver(_model); - // break; + //_solver = new EulerSolver(_model); + //break; + //case 2: + // _solver = new VelocityVerletSolver(_model); + // break; + //case 3: + // _solver = new LeapfrogSolver(_model); + // break; //} sprintf(tmp, "\tnCPU: %d\n", args->GetMaxOpenMPThreads()); s.append(tmp); @@ -266,23 +279,24 @@ void Simulation::InitArgs(ArgumentParser* args) sprintf(tmp, "\tdt: %f\n", _deltaT); s.append(tmp); - _fps=args->Getfps(); + _fps = args->Getfps(); sprintf(tmp, "\tfps: %f\n", _fps); s.append(tmp); // Route choice - vector< pair > routers= args->GetRoutingStrategy(); - RoutingEngine* routingEngine= new RoutingEngine(); + vector > routers = args->GetRoutingStrategy(); + RoutingEngine* routingEngine = new RoutingEngine(); - for (unsigned int r= 0; rSetID(routerID); router->SetStrategy(strategy); routingEngine->AddRouter(router); @@ -290,7 +304,7 @@ void Simulation::InitArgs(ArgumentParser* args) break; } case ROUTING_GLOBAL_SHORTEST: { - Router* router=new GlobalRouter(); + Router* router = new GlobalRouter(); router->SetID(routerID); router->SetStrategy(strategy); routingEngine->AddRouter(router); @@ -298,7 +312,7 @@ void Simulation::InitArgs(ArgumentParser* args) break; } case ROUTING_QUICKEST: { - Router* router=new QuickestPathRouter(); + Router* router = new QuickestPathRouter(); router->SetID(routerID); router->SetStrategy(strategy); routingEngine->AddRouter(router); @@ -306,7 +320,7 @@ void Simulation::InitArgs(ArgumentParser* args) break; } case ROUTING_DYNAMIC: { - Router* router=new GraphRouter(); + Router* router = new GraphRouter(); router->SetID(routerID); router->SetStrategy(strategy); routingEngine->AddRouter(router); @@ -314,7 +328,7 @@ void Simulation::InitArgs(ArgumentParser* args) break; } case ROUTING_NAV_MESH: { - Router* router=new MeshRouter(); + Router* router = new MeshRouter(); router->SetID(routerID); router->SetStrategy(strategy); routingEngine->AddRouter(router); @@ -322,7 +336,7 @@ void Simulation::InitArgs(ArgumentParser* args) break; } case ROUTING_DUMMY: { - Router* router=new DummyRouter(); + Router* router = new DummyRouter(); router->SetID(routerID); router->SetStrategy(strategy); routingEngine->AddRouter(router); @@ -330,7 +344,7 @@ void Simulation::InitArgs(ArgumentParser* args) break; } case ROUTING_SAFEST: { - Router * router=new SafestPathRouter(); + Router * router = new SafestPathRouter(); router->SetID(routerID); router->SetStrategy(strategy); routingEngine->AddRouter(router); @@ -338,7 +352,7 @@ void Simulation::InitArgs(ArgumentParser* args) break; } case ROUTING_COGNITIVEMAP: { - Router* router=new CognitiveMapRouter(); + Router* router = new CognitiveMapRouter(); router->SetID(routerID); router->SetStrategy(strategy); routingEngine->AddRouter(router); @@ -347,8 +361,8 @@ void Simulation::InitArgs(ArgumentParser* args) } case ROUTING_UNDEFINED: default: - cout<<"router not available"<SetProjectFilename(args->GetProjectFile()); _building->SetProjectRootDir(args->GetProjectRootDir()); - _building->LoadGeometry(); - _building->LoadRoutingInfo(args->GetProjectFile()); + if (!_building->LoadGeometry()) + return false; + + if (!_building->LoadRoutingInfo(args->GetProjectFile())) + return false; //_building->AddSurroundingRoom(); - _building->InitGeometry(); // create the polygons - _building->LoadTrafficInfo(); + if(!_building->InitGeometry()) + return false; // create the polygons + + if(!_building->LoadTrafficInfo()) + return false; - _nPeds=_distribution->Distribute(_building); + _nPeds = _distribution->Distribute(_building); //using linkedcells if (args->GetLinkedCells()) { @@ -378,31 +398,35 @@ void Simulation::InitArgs(ArgumentParser* args) } // initialize the routing engine before doing any other things - routingEngine->Init(_building); + if(routingEngine->Init(_building)==false) + return false; //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. - _operationalModel->Init(_building); + if(_operationalModel->Init(_building)==false) + return false; //other initializations - const vector< Pedestrian* >& allPeds = _building->GetAllPedestrians(); - for(Pedestrian *ped: allPeds) - { - ped->Setdt(_deltaT); - } + const vector& allPeds = _building->GetAllPedestrians(); + for (Pedestrian *ped : allPeds) { + ped->Setdt(_deltaT); + } //pBuilding->WriteToErrorLog(); //get the seed - _seed=args->GetSeed(); + _seed = args->GetSeed(); // perform a general check to the . - _building->SanityCheck(); + if(_building->SanityCheck()==false) + return false; + //size of the cells/GCFM/Gompertz - if(args->GetDistEffMaxPed()>args->GetLinkedCellSize()){ - Log->Write("ERROR: the linked-cell size [%f] should be bigger than the force range [%f]", - args->GetLinkedCellSize(),args->GetDistEffMaxPed()); - exit(EXIT_FAILURE); + if (args->GetDistEffMaxPed() > args->GetLinkedCellSize()) { + Log->Write( + "ERROR: the linked-cell size [%f] should be bigger than the force range [%f]", + args->GetLinkedCellSize(), args->GetDistEffMaxPed()); + return false; } //read the events @@ -420,20 +444,22 @@ void Simulation::InitArgs(ArgumentParser* args) //((GPU_ocl_GCFMModel*) _model)->initCL(_building->GetNumberOfPedestrians()); //} //_building->SaveGeometry("test.sav.xml"); -} + //everything went fine + return true; +} int Simulation::RunSimulation() { int frameNr = 1; // Frame Number int writeInterval = (int) ((1. / _fps) / _deltaT + 0.5); writeInterval = (writeInterval <= 0) ? 1 : writeInterval; // mustn't be <= 0 - double t=0.0; + double t = 0.0; // writing the header - _iod->WriteHeader(_nPeds, _fps, _building,_seed); + _iod->WriteHeader(_nPeds, _fps, _building, _seed); _iod->WriteGeometry(_building); - _iod->WriteFrame(0,_building); + _iod->WriteFrame(0, _building); //first initialisation needed by the linked-cells UpdateRoutesAndLocations(); @@ -444,29 +470,28 @@ int Simulation::RunSimulation() //time(&starttime); // main program loop - for (t = 0; t < _tmax && _nPeds > 0; ++frameNr) - { + for (t = 0; t < _tmax && _nPeds > 0; ++frameNr) { t = 0 + (frameNr - 1) * _deltaT; // update the positions - _operationalModel->ComputeNextTimeStep(t,_deltaT,_building); + _operationalModel->ComputeNextTimeStep(t, _deltaT, _building); // update the routes and locations //Update(); UpdateRoutesAndLocations(); //update the events - _em->Update_Events(t,_deltaT); + _em->Update_Events(t, _deltaT); //other updates //someone might have leave the building - _nPeds=_building->GetAllPedestrians().size(); + _nPeds = _building->GetAllPedestrians().size(); //update the linked cells _building->UpdateGrid(); // update the global time - Pedestrian::SetGlobalTime(t); + Pedestrian::SetGlobalTime(t); // write the trajectories if (frameNr % writeInterval == 0) { @@ -484,12 +509,13 @@ int Simulation::RunSimulation() _iod->WriteFooter(); //if(_hpc==1) - // ((GPU_GCFMModel*) _model)->DeleteBuffers(); + // ((GPU_GCFMModel*) _model)->DeleteBuffers(); //temporary work around since the total number of frame is only available at the end of the simulation. - if(_argsParser->GetFileFormat()==FORMAT_XML_BIN) { + if (_argsParser->GetFileFormat() == FORMAT_XML_BIN) { - delete _iod; _iod=NULL; + delete _iod; + _iod = NULL; // char tmp[CLENGTH]; // int f= frameNr / writeInterval ; @@ -498,16 +524,17 @@ int Simulation::RunSimulation() char replace[CLENGTH]; // open the file and replace the 8th line - sprintf(replace,"sed -i '9s/.*/ %d /' %s", frameNr/ writeInterval, _argsParser->GetTrajectoriesFile().c_str()); - int result=system(replace); - Log->Write("INFO:\t Updating the framenumber exits with code [%d]",result); + sprintf(replace, "sed -i '9s/.*/ %d /' %s", frameNr / writeInterval, + _argsParser->GetTrajectoriesFile().c_str()); + int result = system(replace); + Log->Write("INFO:\t Updating the framenumber exits with code [%d]", + result); } //return the evacuation time return (int) t; } - void Simulation::UpdateRoutesAndLocations() { //pedestrians to be deleted @@ -516,8 +543,8 @@ void Simulation::UpdateRoutesAndLocations() pedsToRemove.reserve(100); //just reserve some space // collect all pedestrians in the simulation. - const vector< Pedestrian* >& allPeds = _building->GetAllPedestrians(); - const map& goals=_building->GetAllGoals(); + const vector& allPeds = _building->GetAllPedestrians(); + const map& goals = _building->GetAllGoals(); unsigned int nSize = allPeds.size(); int nThreads = omp_get_max_threads(); @@ -531,22 +558,19 @@ void Simulation::UpdateRoutesAndLocations() if ((threadID == nThreads - 1)) end = nSize - 1; - for (int p = start; p <= end; ++p) - { + for (int p = start; p <= end; ++p) { Pedestrian* ped = allPeds[p]; Room* room = _building->GetRoom(ped->GetRoomID()); SubRoom* sub = room->GetSubRoom(ped->GetSubRoomID()); //set the new room if needed if ((ped->GetFinalDestination() == FINAL_DEST_OUT) - && (room->GetCaption() == "outside")) - { + && (room->GetCaption() == "outside")) { #pragma omp critical pedsToRemove.push_back(ped); - } - else if ((ped->GetFinalDestination() != FINAL_DEST_OUT) - && (goals.at(ped->GetFinalDestination())->Contains(ped->GetPos()))) - { + } else if ((ped->GetFinalDestination() != FINAL_DEST_OUT) + && (goals.at(ped->GetFinalDestination())->Contains( + ped->GetPos()))) { #pragma omp critical pedsToRemove.push_back(ped); } @@ -554,18 +578,22 @@ void Simulation::UpdateRoutesAndLocations() // reposition in the case the pedestrians "accidently left the room" not via the intended exit. // That may happen if the forces are too high for instance // the ped is removed from the simulation, if it could not be reassigned - else if (!sub->IsInSubRoom(ped)) - { + else if (!sub->IsInSubRoom(ped)) { bool assigned = false; - const std::vector& allRooms=_building->GetAllRooms(); - for (Room* room : allRooms) - { - const vector& allSubs=room->GetAllSubRooms(); - for(SubRoom* sub : allSubs) - { - SubRoom* old_sub= allRooms[ped->GetRoomID()]->GetSubRoom(ped->GetSubRoomID()); - if ((sub->IsInSubRoom(ped->GetPos())) && (sub->IsDirectlyConnectedWith(old_sub))) { - ped->SetRoomID(room->GetID(), room->GetCaption()); + const std::vector& allRooms = + _building->GetAllRooms(); + for (Room* room : allRooms) { + const vector& allSubs = + room->GetAllSubRooms(); + for (SubRoom* sub : allSubs) { + SubRoom* old_sub = + allRooms[ped->GetRoomID()]->GetSubRoom( + ped->GetSubRoomID()); + if ((sub->IsInSubRoom(ped->GetPos())) + && (sub->IsDirectlyConnectedWith( + old_sub))) { + ped->SetRoomID(room->GetID(), + room->GetCaption()); ped->SetSubRoomID(sub->GetSubRoomID()); ped->ClearMentalMap(); // reset the destination //ped->FindRoute(); @@ -577,8 +605,7 @@ void Simulation::UpdateRoutesAndLocations() break; // stop the loop } - if (assigned == false) - { + if (assigned == false) { #pragma omp critical pedsToRemove.push_back(ped); } @@ -587,21 +614,21 @@ void Simulation::UpdateRoutesAndLocations() //finally actualize the route if (ped->FindRoute() == -1) { //a destination could not be found for that pedestrian - Log->Write("\tINFO: \tCould not found a route for pedestrian %d",ped->GetID()); + Log->Write( + "\tINFO: \tCould not found a route for pedestrian %d", + ped->GetID()); + //exit(EXIT_FAILURE); #pragma omp critical pedsToRemove.push_back(ped); } } } - // remove the pedestrians that have left the building - for (unsigned int p = 0; p < pedsToRemove.size(); p++) - { + for (unsigned int p = 0; p < pedsToRemove.size(); p++) { _building->DeletePedestrian(pedsToRemove[p]); } - // temporary fix for the safest path router // if (dynamic_cast(_routingEngine->GetRouter(1))) // { @@ -615,10 +642,13 @@ void Simulation::PrintStatistics() Log->Write("\nEXIT USAGE:"); const map& transitions = _building->GetAllTransitions(); map::const_iterator itr; - for(itr = transitions.begin(); itr != transitions.end(); ++itr) { - Transition* goal = itr->second; - if(goal->IsExit()) { - Log->Write("Exit ID [%d] used by [%d] pedestrians. Last passing time [%0.2f] s",goal->GetID(),goal->GetDoorUsage(),goal->GetLastPassingTime()); + for (itr = transitions.begin(); itr != transitions.end(); ++itr) { + Transition* goal = itr->second; + if (goal->IsExit()) { + Log->Write( + "Exit ID [%d] used by [%d] pedestrians. Last passing time [%0.2f] s", + goal->GetID(), goal->GetDoorUsage(), + goal->GetLastPassingTime()); } } } diff --git a/Simulation.h b/Simulation.h index 70baf074..f7ecc01d 100644 --- a/Simulation.h +++ b/Simulation.h @@ -100,7 +100,7 @@ public: /** * Read parameters from the argument parser class. */ - void InitArgs(ArgumentParser *args); + bool InitArgs(ArgumentParser *args); /** * @return the total simulated/evacuation time diff --git a/events/EventManager.cpp b/events/EventManager.cpp index e50425fa..da3cadcb 100644 --- a/events/EventManager.cpp +++ b/events/EventManager.cpp @@ -22,10 +22,10 @@ EventManager::EventManager(Building *_b){ _lastUpdateTime=0; _deltaT=0; if(!_file){ - Log->Write("INFO:\tDatei events.txt nicht gefunden. Dynamisches Eventhandling nicht moeglich."); + Log->Write("INFO:\tFiles 'events.txt' missing. Realtime interaction with the simulation not possible."); } else{ - Log->Write("INFO:\tDatei events.txt gefunden. Dynamisches Eventhandling moeglich."); + Log->Write("INFO:\tFile 'events.txt' will be monitored for new events."); _dynamic=true; } } @@ -42,7 +42,7 @@ void EventManager::SetProjectRootDir(const std::string &filename){ } void EventManager::readEventsXml(){ - Log->Write("INFO: \tLooking for events"); + Log->Write("INFO: \tLooking for pre-defined events in other files"); //get the geometry filename from the project file TiXmlDocument doc(_projectFilename); if (!doc.LoadFile()){ @@ -97,16 +97,19 @@ void EventManager::readEventsXml(){ Log->Write("INFO: \tEvents were read\n"); } -void EventManager::listEvents(){ - if(_event_times.size()==0){ - Log->Write("INFO: \tNo events in the events.xml"); - } - else{ - char buf[10],buf2[10]; - for(unsigned int i=0;i<_event_times.size();i++){ - sprintf(buf,"%f",_event_times[i]); - sprintf(buf2,"%d",_event_ids[i]); - Log->Write("INFO: \tAfter "+string(buf)+" sec: "+_event_types[i]+" "+string(buf2)+" "+_event_states[i]); +void EventManager::listEvents() +{ + if (_event_times.size() == 0) { + //this notification was already printed ealier + //Log->Write("INFO: \tNo events in the events.xml"); + } else { + char buf[10], buf2[10]; + for (unsigned int i = 0; i < _event_times.size(); i++) { + sprintf(buf, "%f", _event_times[i]); + sprintf(buf2, "%d", _event_ids[i]); + Log->Write( + "INFO: \tAfter " + string(buf) + " sec: " + _event_types[i] + + " " + string(buf2) + " " + _event_states[i]); } } diff --git a/general/Macros.h b/general/Macros.h index 7049a892..be6d113e 100644 --- a/general/Macros.h +++ b/general/Macros.h @@ -162,4 +162,7 @@ template return true; } } + +//another useful macro +//#define UNUSED(expr) (void)(expr) #endif /* _MACROS_H */ diff --git a/geometry/Building.cpp b/geometry/Building.cpp index 39179b92..66a90868 100644 --- a/geometry/Building.cpp +++ b/geometry/Building.cpp @@ -259,7 +259,7 @@ void Building::AddSurroundingRoom() } -void Building::InitGeometry() +bool Building::InitGeometry() { Log->Write("INFO: \tInit Geometry"); for (int i = 0; i < GetNumberOfRooms(); i++) { @@ -284,7 +284,8 @@ void Building::InitGeometry() } // initialize the poly - s->ConvertLineToPoly(goals); + if(! s->ConvertLineToPoly(goals)) + return false; s->CalculateArea(); goals.clear(); @@ -292,11 +293,14 @@ void Building::InitGeometry() const vector& obstacles = s->GetAllObstacles(); for (unsigned int obs = 0; obs < obstacles.size(); ++obs) { if (obstacles[obs]->GetClosed() == 1) - obstacles[obs]->ConvertLineToPoly(); + if(!obstacles[obs]->ConvertLineToPoly()) + return false; } } } Log->Write("INFO: \tInit Geometry successful!!!\n"); + + return true; } @@ -324,7 +328,7 @@ const std::string& Building::GetGeometryFilename() const return _geometryFilename; } -void Building::LoadGeometry(const std::string &geometryfile) +bool Building::LoadGeometry(const std::string &geometryfile) { //get the geometry filename from the project file string geoFilenameWithPath= _projectRootDir + geometryfile; @@ -335,7 +339,7 @@ void Building::LoadGeometry(const std::string &geometryfile) if (!doc.LoadFile()) { Log->Write("ERROR: \t%s", doc.ErrorDesc()); Log->Write("\t could not parse the project file"); - exit(EXIT_FAILURE); + return false; } Log->Write("INFO: \tParsing the geometry file"); @@ -352,23 +356,23 @@ void Building::LoadGeometry(const std::string &geometryfile) if (!docGeo.LoadFile()) { Log->Write("ERROR: \t%s", docGeo.ErrorDesc()); Log->Write("\t could not parse the geometry file"); - exit(EXIT_FAILURE); + return false; } TiXmlElement* xRootNode = docGeo.RootElement(); if( ! xRootNode ) { Log->Write("ERROR:\tRoot element does not exist"); - exit(EXIT_FAILURE); + return false; } if( xRootNode->ValueStr () != "geometry" ) { Log->Write("ERROR:\tRoot element value is not 'geometry'."); - exit(EXIT_FAILURE); + return false; } if(xRootNode->Attribute("unit")) if(string(xRootNode->Attribute("unit")) != "m") { Log->Write("ERROR:\tOnly the unit m (meters) is supported. \n\tYou supplied [%s]",xRootNode->Attribute("unit")); - exit(EXIT_FAILURE); + return false; } double version = xmltof(xRootNode->Attribute("version"), -1); @@ -377,7 +381,7 @@ void Building::LoadGeometry(const std::string &geometryfile) Log->Write(" \tWrong geometry version!"); Log->Write(" \tOnly version >= %s supported",JPS_VERSION); Log->Write(" \tPlease update the version of your geometry file to %s",JPS_VERSION); - exit(EXIT_FAILURE); + return false; } _caption = xmltoa(xRootNode->Attribute("caption"), "virtual building"); @@ -388,7 +392,7 @@ void Building::LoadGeometry(const std::string &geometryfile) TiXmlNode* xRoomsNode = xRootNode->FirstChild("rooms"); if (!xRoomsNode) { Log->Write("ERROR: \tThe geometry should have at least one room and one subroom"); - exit(EXIT_FAILURE); + return false; } for(TiXmlElement* xRoom = xRoomsNode->FirstChildElement("room"); xRoom; @@ -431,7 +435,7 @@ void Building::LoadGeometry(const std::string &geometryfile) if(xSubRoom->FirstChildElement("up")==NULL) { Log->Write("ERROR:\t the attribute and are missing for the stair"); Log->Write("ERROR:\t check your geometry file"); - exit(EXIT_FAILURE); + return false; } double up_x = xmltof( xSubRoom->FirstChildElement("up")->Attribute("px"), 0.0); double up_y = xmltof( xSubRoom->FirstChildElement("up")->Attribute("py"), 0.0); @@ -601,8 +605,10 @@ void Building::LoadGeometry(const std::string &geometryfile) AddTransition(t); } - Log->Write("INFO: \tLoading building file successful!!!\n"); + + //everything went fine + return true; } @@ -851,18 +857,21 @@ bool Building::IsVisible(const Point& p1, const Point& p2, bool considerHlines) return true; } -void Building::SanityCheck() +bool Building::SanityCheck() { Log->Write("INFO: \tChecking the geometry for artifacts"); + bool status = true; for (unsigned int i = 0; i < _rooms.size(); i++) { Room* room = _rooms[i]; for (int j = 0; j < room->GetNumberOfSubRooms(); j++) { SubRoom* sub = room->GetSubRoom(j); - sub->SanityCheck(); + if (!sub->SanityCheck()) + status = false; } } Log->Write("INFO: \t...Done!!!\n"); + return status; } @@ -938,25 +947,25 @@ void Building::InitGrid(double cellSize) Log->Write("INFO: \tDone with Initializing the grid "); } -void Building::LoadRoutingInfo(const string &filename) +bool Building::LoadRoutingInfo(const string &filename) { Log->Write("INFO:\tLoading extra routing information"); if (filename == "") { Log->Write("INFO:\t No file supplied !"); Log->Write("INFO:\t done with loading extra routing information"); - return; + return true; } TiXmlDocument docRouting(filename); if (!docRouting.LoadFile()) { Log->Write("ERROR: \t%s", docRouting.ErrorDesc()); Log->Write("ERROR: \t could not parse the routing file"); - exit(EXIT_FAILURE); + return false; } TiXmlElement* xRootNode = docRouting.RootElement(); if( ! xRootNode ) { Log->Write("ERROR:\tRoot element does not exist"); - exit(EXIT_FAILURE); + return false; } //load goals and routes @@ -993,7 +1002,9 @@ void Building::LoadRoutingInfo(const string &filename) } } - goal->ConvertLineToPoly(); + if(!goal->ConvertLineToPoly()) + return false; + AddGoal(goal); _routingEngine->AddFinalDestinationID(goal->GetId()); } @@ -1008,7 +1019,7 @@ void Building::LoadRoutingInfo(const string &filename) double id = xmltof(trip->Attribute("id"), -1); if (id == -1) { Log->Write("ERROR:\t id missing for trip"); - exit(EXIT_FAILURE); + return false; } string sTrip = trip->FirstChild()->ValueStr(); vector vTrip; @@ -1023,9 +1034,10 @@ void Building::LoadRoutingInfo(const string &filename) _routingEngine->AddTrip(vTrip); } Log->Write("INFO:\tdone with loading extra routing information"); + return true; } -void Building::LoadTrafficInfo() +bool Building::LoadTrafficInfo() { Log->Write("INFO:\tLoading the traffic info file"); @@ -1035,14 +1047,13 @@ void Building::LoadTrafficInfo() if (!doc.LoadFile()) { Log->Write("ERROR: \t%s", doc.ErrorDesc()); Log->Write("ERROR: \t could not parse the project file"); - exit(EXIT_FAILURE); + return false; } TiXmlNode* xRootNode = doc.RootElement()->FirstChild("traffic_constraints"); if( ! xRootNode ) { Log->Write("WARNING:\tcould not find any traffic information"); - return; - //exit(EXIT_FAILURE); + return true; } //processing the rooms node @@ -1076,6 +1087,7 @@ void Building::LoadTrafficInfo() } } Log->Write("INFO:\tDone with loading traffic info file"); + return true; } diff --git a/geometry/Building.h b/geometry/Building.h index d24f3614..006ae966 100644 --- a/geometry/Building.h +++ b/geometry/Building.h @@ -163,7 +163,7 @@ public: LCGrid* GetGrid() const; // convenience methods - void InitGeometry(); + bool InitGeometry(); void InitGrid(double cellSize); //void InitRoomsAndSubroomsMap(); void InitSavePedPathway(const std::string &filename); @@ -193,7 +193,7 @@ public: * * @param filename, the geometry file */ - void LoadGeometry(const std::string &geometryfile=""); + bool LoadGeometry(const std::string &geometryfile=""); /** * Write the geometry to the given file. @@ -203,15 +203,15 @@ public: */ bool SaveGeometry(const std::string &filename); - void LoadTrafficInfo(); - void LoadRoutingInfo(const std::string &filename); + bool LoadTrafficInfo(); + bool LoadRoutingInfo(const std::string &filename); void WriteToErrorLog() const; /** * Check the scenario for possible errors and * output user specific informations. */ - void SanityCheck(); + bool SanityCheck(); private: diff --git a/geometry/Goal.cpp b/geometry/Goal.cpp index d352c255..a2157819 100644 --- a/geometry/Goal.cpp +++ b/geometry/Goal.cpp @@ -182,9 +182,8 @@ bool Goal::Contains(const Point& ped) const return false; } -void Goal::ConvertLineToPoly() +bool Goal::ConvertLineToPoly() { - vector copy; vector tmpPoly; Point point; @@ -219,11 +218,11 @@ void Goal::ConvertLineToPoly() char tmp[CLENGTH]; sprintf(tmp, "ERROR: \tGoal::ConvertLineToPoly(): ID %d !!!\n", _id); Log->Write(tmp); - exit(0); + return false; } _poly = tmpPoly; - ComputeControid(); + return true; } const Point& Goal::GetCentroid() const diff --git a/geometry/Goal.h b/geometry/Goal.h index 3f239a57..3fe6596f 100644 --- a/geometry/Goal.h +++ b/geometry/Goal.h @@ -90,7 +90,7 @@ public: /** * Create the obstacles polygonal structure from the walls */ - void ConvertLineToPoly(); + bool ConvertLineToPoly(); /** * @return the Goal as a polygon diff --git a/geometry/Obstacle.cpp b/geometry/Obstacle.cpp index 59b6ecf8..93cd9a1b 100644 --- a/geometry/Obstacle.cpp +++ b/geometry/Obstacle.cpp @@ -209,15 +209,16 @@ bool Obstacle::Contains(const Point& ped) const return false; } -void Obstacle::ConvertLineToPoly() +bool Obstacle::ConvertLineToPoly() { - - if(_isClosed==0.0) { + if(_isClosed==0.0) + { char tmp[CLENGTH]; sprintf(tmp, "INFO: \tObstacle [%d] is not closed. Not converting to polyline.\n", _id); Log->Write(tmp); - return; + return true; } + vector copy; vector tmpPoly; Point point; @@ -252,9 +253,10 @@ void Obstacle::ConvertLineToPoly() char tmp[CLENGTH]; sprintf(tmp, "ERROR: \tObstacle::ConvertLineToPoly(): ID %d !!!\n", _id); Log->Write(tmp); - exit(0); + return false; } _poly = tmpPoly; + return true; } const Point Obstacle::GetCentroid() const diff --git a/geometry/Obstacle.h b/geometry/Obstacle.h index 9dcbb3cd..9302a956 100644 --- a/geometry/Obstacle.h +++ b/geometry/Obstacle.h @@ -112,7 +112,7 @@ public: /** * Create the obstacles polygonal structure from the walls */ - void ConvertLineToPoly(); + bool ConvertLineToPoly(); /** * @return the obstacle as a polygon diff --git a/geometry/SubRoom.cpp b/geometry/SubRoom.cpp index 143d7e6f..557301e8 100644 --- a/geometry/SubRoom.cpp +++ b/geometry/SubRoom.cpp @@ -465,7 +465,7 @@ void SubRoom::CheckObstacles() } } -void SubRoom::SanityCheck() +bool SubRoom::SanityCheck() { if(_obstacles.size()==0) { if((IsConvex()==false) && (_hlines.size()==0)) { @@ -482,7 +482,7 @@ void SubRoom::SanityCheck() // everything is fine } } - + return true; } ///http://stackoverflow.com/questions/471962/how-do-determine-if-a-polygon-is-complex-convex-nonconvex @@ -622,7 +622,7 @@ void NormalSubRoom::WriteToErrorLog() const } } -void NormalSubRoom::ConvertLineToPoly(vector goals) +bool NormalSubRoom::ConvertLineToPoly(vector goals) { vector copy; vector tmpPoly; @@ -664,9 +664,10 @@ void NormalSubRoom::ConvertLineToPoly(vector goals) Log->Write(tmp); sprintf(tmp, "ERROR: \tDistance between the points: %lf !!!\n", (tmpPoly[0] - point).Norm()); Log->Write(tmp); - exit(EXIT_FAILURE); + return false; } _poly = tmpPoly; + return true; } @@ -866,11 +867,10 @@ const Point* Stair::CheckCorner(const Point** otherPoint, const Point** aktPoint return rueck; } -void Stair::ConvertLineToPoly(vector goals) +bool Stair::ConvertLineToPoly(vector goals) { //return NormalSubRoom::ConvertLineToPoly(goals); - vector copy; vector orgPoly = vector (); const Point* aktPoint; @@ -924,7 +924,7 @@ void Stair::ConvertLineToPoly(vector goals) sprintf(tmp, "ERROR: \tStair::ConvertLineToPoly(): SubRoom %d Room %d Anfangspunkt ungleich Endpunkt!!!\n" "\t(%f, %f) != (%f, %f)\n", GetSubRoomID(), GetRoomID(), x1, y1, x2, y2); Log->Write(tmp); - exit(EXIT_FAILURE); + return false; } if (orgPoly.size() != 4) { @@ -932,7 +932,7 @@ void Stair::ConvertLineToPoly(vector goals) sprintf(tmp, "ERROR: \tStair::ConvertLineToPoly(): Stair %d Room %d ist kein Viereck!!!\n" "Anzahl Ecken: %d\n", GetSubRoomID(), (int)GetRoomID(), (int)orgPoly.size()); Log->Write(tmp); - exit(EXIT_FAILURE); + return false; } vector neuPoly = (orgPoly); // ganz kleine Treppen (nur eine Stufe) nicht @@ -957,6 +957,8 @@ void Stair::ConvertLineToPoly(vector goals) } } _poly = neuPoly; + + return true; } bool Stair::IsInSubRoom(const Point& ped) const diff --git a/geometry/SubRoom.h b/geometry/SubRoom.h index 10871641..72e640e0 100644 --- a/geometry/SubRoom.h +++ b/geometry/SubRoom.h @@ -237,7 +237,7 @@ public: * Check the subroom for possible errors and * output user specific informations. */ - void SanityCheck(); + bool SanityCheck(); //navigation void AddCrossing(Crossing* line); @@ -291,7 +291,7 @@ public: virtual std::string WritePolyLine() const=0; /// convert all walls and transitions(doors) into a polygon representing the subroom - virtual void ConvertLineToPoly(std::vector goals) = 0; + virtual bool ConvertLineToPoly(std::vector goals) = 0; ///check whether the pedestrians is still in the subroom virtual bool IsInSubRoom(const Point& ped) const = 0; @@ -327,7 +327,7 @@ public: std::string WritePolyLine() const; void WriteToErrorLog() const; - void ConvertLineToPoly(std::vector goals); + bool ConvertLineToPoly(std::vector goals); bool IsInSubRoom(const Point& ped) const; }; @@ -362,7 +362,7 @@ public: std::string WriteSubRoom() const; std::string WritePolyLine() const; virtual void WriteToErrorLog() const; - virtual void ConvertLineToPoly(std::vector goals); + virtual bool ConvertLineToPoly(std::vector goals); bool IsInSubRoom(const Point& ped) const; }; diff --git a/main.cpp b/main.cpp index ab63210d..13380cb0 100644 --- a/main.cpp +++ b/main.cpp @@ -48,36 +48,38 @@ int main(int argc, char **argv) time(&starttime); Simulation sim = Simulation(); - sim.InitArgs(args); - Log->Write("INFO: \tStart runSimulation()"); - int evacTime = sim.RunSimulation(); - Log->Write("\nINFO: \tEnd runSimulation()"); - time(&endtime); + if(sim.InitArgs(args)) + { + Log->Write("INFO: \tStart runSimulation()"); + int evacTime = sim.RunSimulation(); + Log->Write("\nINFO: \tEnd runSimulation()"); + time(&endtime); - // some output - double execTime = difftime(endtime, starttime); + // some output + double execTime = difftime(endtime, starttime); - if (sim.GetPedsNumber()) - Log->Write("\nPedestrians not evacuated [%d] using [%d] threads", - sim.GetPedsNumber(), - args->GetMaxOpenMPThreads()); + if (sim.GetPedsNumber()) { + Log->Write("\nPedestrians not evacuated [%d] using [%d] threads", + sim.GetPedsNumber(), args->GetMaxOpenMPThreads()); + } - Log->Write("\nExec Time [s] : %.2f", execTime); - Log->Write("Evac Time [s] : %d", evacTime); - Log->Write("Realtime Factor : %.2f X", evacTime / execTime); - Log->Write("Number of Threads : %d", args->GetMaxOpenMPThreads()); - Log->Write("Warnings : %d", Log->GetWarnings() ); - Log->Write("Errors : %d", Log->GetErrors() ); - // sim.PrintStatistics(); - if (NULL == dynamic_cast(Log)) { - printf("\nExec Time [s] : %4.2f\n", execTime); - printf("Evac Time [s] : %d\n", evacTime); - printf("Realtime Factor : %.2f (X)\n", evacTime / execTime); - printf("Number of Threads : %d\n", args->GetMaxOpenMPThreads()); - printf("Warnings : %d\n", Log->GetWarnings() ); - printf("Errors : %d\n", Log->GetErrors() ); - } + Log->Write("\nExec Time [s] : %.2f", execTime); + Log->Write("Evac Time [s] : %d", evacTime); + Log->Write("Realtime Factor : %.2f X", evacTime / execTime); + Log->Write("Number of Threads : %d", args->GetMaxOpenMPThreads()); + Log->Write("Warnings : %d", Log->GetWarnings()); + Log->Write("Errors : %d", Log->GetErrors()); + // sim.PrintStatistics(); + if (NULL == dynamic_cast(Log)) { + printf("\nExec Time [s] : %4.2f\n", execTime); + printf("Evac Time [s] : %d\n", evacTime); + printf("Realtime Factor : %.2f (X)\n", evacTime / execTime); + printf("Number of Threads : %d\n", args->GetMaxOpenMPThreads()); + printf("Warnings : %d\n", Log->GetWarnings()); + printf("Errors : %d\n", Log->GetErrors()); + } + } // do the last cleaning delete args; delete Log; diff --git a/math/GCFMModel.cpp b/math/GCFMModel.cpp index 0e50dbdd..f90a2015 100644 --- a/math/GCFMModel.cpp +++ b/math/GCFMModel.cpp @@ -69,7 +69,7 @@ GCFMModel::~GCFMModel(void) } -void GCFMModel::Init (Building* building) const +bool GCFMModel::Init (Building* building) const { const vector< Pedestrian* >& allPeds = building->GetAllPedestrians(); for(unsigned int p=0;pWrite( "ERROR: \allPeds::Init() cannot initialise phi! " "dist to target is 0\n"); - exit(EXIT_FAILURE); + return false; } JEllipse E = ped->GetEllipse(); @@ -103,6 +103,7 @@ void GCFMModel::Init (Building* building) const E.SetSinPhi(sinPhi); ped->SetEllipse(E); } + return true; } void GCFMModel::ComputeNextTimeStep(double current, double deltaT, Building* building) const @@ -628,14 +629,3 @@ string GCFMModel::GetDescription() const return rueck; } - - - -/** - * implementation of Linked-cell combined with openMP - */ - -void GCFMModel::CalculateForce(double time, double tip1, Building* building) const -{ - -} diff --git a/math/GCFMModel.h b/math/GCFMModel.h index f162d16a..414f8c84 100644 --- a/math/GCFMModel.h +++ b/math/GCFMModel.h @@ -64,10 +64,16 @@ public: double GetDistEffMaxPed() const; double GetDistEffMaxWall() const; - // virtual function + /** + * Compute the next simulation step + * Solve the differential equations and update the positions and velocities + * @param current the actual time + * @param deltaT the next timestep + * @param building the geometry object + */ virtual void ComputeNextTimeStep(double current, double deltaT, Building* building) const; virtual std::string GetDescription() const; - virtual void Init (Building* building) const; + virtual bool Init (Building* building) const; private: /// define the strategy for crossing a door (used for calculating the driving force) @@ -116,15 +122,6 @@ private: Point ForceRepStatPoint(Pedestrian* ped, const Point& p, double l, double vn) const; Point ForceInterpolation(double v0, double K_ij, const Point& e, double v, double d, double r, double l) const; - /** - * Calculate the forces and update the pedestrians position and velocities - * @param t - * @param tp - * @param building - */ - void CalculateForce(double t, double tp, Building* building) const; - - }; diff --git a/math/GompertzModel.cpp b/math/GompertzModel.cpp index f0936f73..499da26f 100644 --- a/math/GompertzModel.cpp +++ b/math/GompertzModel.cpp @@ -72,7 +72,7 @@ GompertzModel::~GompertzModel() } -void GompertzModel::Init (Building* building) const +bool GompertzModel::Init (Building* building) const { const vector< Pedestrian* >& allPeds = building->GetAllPedestrians(); @@ -99,7 +99,7 @@ void GompertzModel::Init (Building* building) const Log->Write( "ERROR: \allPeds::Init() cannot initialise phi! " "dist to target is 0\n"); - exit(EXIT_FAILURE); + return false; } JEllipse E = ped->GetEllipse(); @@ -107,6 +107,7 @@ void GompertzModel::Init (Building* building) const E.SetSinPhi(sinPhi); ped->SetEllipse(E); } + return true; } void GompertzModel::ComputeNextTimeStep(double current, double deltaT, Building* building) const @@ -123,7 +124,7 @@ void GompertzModel::ComputeNextTimeStep(double current, double deltaT, Building* int partSize; partSize = (int) (nSize / nThreads); - int debugPed = -69;//10; + //int debugPed = -69;//10; //building->GetGrid()->HighlightNeighborhood(debugPed, building); @@ -482,10 +483,6 @@ Point GompertzModel::ForceRepWall(Pedestrian* ped, const Wall& w) const return F_wrep; } -void GompertzModel::CalculateForce(double time, double tip1, Building* building) const -{ - -} string GompertzModel::GetDescription() const { string rueck; @@ -500,6 +497,7 @@ string GompertzModel::GetDescription() const rueck.append(tmp); return rueck; } + DirectionStrategy* GompertzModel::GetDirection() const { return _direction; diff --git a/math/GompertzModel.h b/math/GompertzModel.h index 5b3d867b..f2a1df18 100644 --- a/math/GompertzModel.h +++ b/math/GompertzModel.h @@ -163,14 +163,6 @@ public: */ double GetcWall() const; - /** - * Solve the differential equations and update the positions and velocities - * @param t the actual time - * @param tp the next timestep - * @param building the geometry object - */ - virtual void CalculateForce(double t, double tp, Building* building) const; - /** * @return all model parameters in a nicely formatted string */ @@ -180,10 +172,14 @@ public: * initialize the phi angle * @param building */ - virtual void Init (Building* building) const; + virtual bool Init (Building* building) const; /** * Compute the next simulation step + * Solve the differential equations and update the positions and velocities + * @param current the actual time + * @param deltaT the next timestep + * @param building the geometry object */ virtual void ComputeNextTimeStep(double current, double deltaT, Building* building) const; }; diff --git a/math/OperationalModel.h b/math/OperationalModel.h index 91a0a348..c862cc51 100644 --- a/math/OperationalModel.h +++ b/math/OperationalModel.h @@ -52,8 +52,9 @@ public: * Performs whatever initialization is needed/required. * This function is called at the beginning the simulation once. * @param building, the building object + * return the status of the initialisation */ - virtual void Init (Building* building) const = 0; + virtual bool Init (Building* building) const = 0; /** * @return a description of the model possibly with all model parameters in a nicely formatted string diff --git a/pedestrian/Pedestrian.cpp b/pedestrian/Pedestrian.cpp index eef897c4..936dfc85 100644 --- a/pedestrian/Pedestrian.cpp +++ b/pedestrian/Pedestrian.cpp @@ -439,7 +439,7 @@ double Pedestrian::GetTimeInJam() const void Pedestrian::SetSmoothTurning(bool smt) { - _newOrientationDelay = 0; + _newOrientationDelay = 0; } diff --git a/routing/CognitiveMapRouter.cpp b/routing/CognitiveMapRouter.cpp index 7b2ef03d..18e62ac6 100644 --- a/routing/CognitiveMapRouter.cpp +++ b/routing/CognitiveMapRouter.cpp @@ -107,7 +107,7 @@ void CognitiveMapRouter::CheckAndInitPedestrian(Pedestrian * p) } -void CognitiveMapRouter::Init(Building * b) +bool CognitiveMapRouter::Init(Building * b) { Log->Write("INFO:\tInit the Cognitive Map Router Engine"); building = b; @@ -118,4 +118,5 @@ void CognitiveMapRouter::Init(Building * b) //Init Sensor Manager sensor_manager = SensorManager::InitWithAllSensors(b, cm_storage); Log->Write("INFO:\tInitialized SensorManager"); + return true; } diff --git a/routing/CognitiveMapRouter.h b/routing/CognitiveMapRouter.h index 75b98805..922d8d96 100644 --- a/routing/CognitiveMapRouter.h +++ b/routing/CognitiveMapRouter.h @@ -51,7 +51,7 @@ public: virtual ~CognitiveMapRouter(); virtual int FindExit(Pedestrian* p); - virtual void Init(Building* b); + virtual bool Init(Building* b); protected: void CheckAndInitPedestrian(Pedestrian *); diff --git a/routing/DirectionStrategy.cpp b/routing/DirectionStrategy.cpp index 6e5c55a8..a9138362 100644 --- a/routing/DirectionStrategy.cpp +++ b/routing/DirectionStrategy.cpp @@ -46,11 +46,13 @@ DirectionStrategy::~DirectionStrategy() /// 1 Point DirectionMiddlePoint::GetTarget(Room* room, Pedestrian* ped) const { - return (ped->GetExitLine()->GetPoint1() + ped->GetExitLine()->GetPoint2())*0.5; + (void)room; // suppress the unused warning + return (ped->GetExitLine()->GetPoint1() + ped->GetExitLine()->GetPoint2())*0.5; } /// 2 Point DirectionMinSeperationShorterLine::GetTarget(Room* room, Pedestrian* ped) const { + (void)room; // suppress the unused warning double d = ped->GetEllipse().GetBmin() + 0.1 ; // shoulder//0.5; const Point& p1 = ped->GetExitLine()->GetPoint1(); @@ -81,35 +83,37 @@ Point DirectionMinSeperationShorterLine::GetTarget(Room* room, Pedestrian* ped) /// 3 Point DirectionInRangeBottleneck::GetTarget(Room* room, Pedestrian* ped) const { - const Point& p1 = ped->GetExitLine()->GetPoint1(); - const Point& p2 = ped->GetExitLine()->GetPoint2(); - Line ExitLine = Line(p1, p2); - Point Lot = ExitLine.LotPoint( ped->GetPos() ); - Point ExitMiddle = (p1+p2)*0.5; - double d = 0.2; - Point diff = (p1 - p2).Normalized() * d; - Line e_neu = Line(p1 - diff, p2 + diff); - - if(ped->GetID() == -10) - { - printf("=======\nX=[%.2f], Y=[%.2f]\n", ped->GetPos().GetX(), ped->GetPos().GetY()); - printf("p1=[%.2f, %.2f], p2=[%.2f, %.2f]\n", p1.GetX(), p1.GetY(), p2.GetX(), p2.GetY()); - printf("e_neu=[%.2f, %.2f]===[%.2f, %.2f]\n", e_neu.GetPoint1().GetX(), e_neu.GetPoint1().GetY(), e_neu.GetPoint2().GetX(), e_neu.GetPoint2().GetY() ); - } - - if ( e_neu.IsInLineSegment(Lot) ) { - if(ped->GetID() == -10){ - printf("Return Lot=[%.2f, %.2f]\n", Lot.GetX(), Lot.GetY() ); - if(0 && ped->GetPos().GetX() > 56) - getc(stdin);} - return Lot; - } else { - if(ped->GetID() == -10){ - printf("Return Middle=[%.2f, %.2f]\n", ExitMiddle.GetX(), ExitMiddle.GetY() ); - if(0 && ped->GetPos().GetX() > 56) - getc(stdin);} - return ExitMiddle; - } + (void)room; // suppress the unused warning + + const Point& p1 = ped->GetExitLine()->GetPoint1(); + const Point& p2 = ped->GetExitLine()->GetPoint2(); + Line ExitLine = Line(p1, p2); + Point Lot = ExitLine.LotPoint( ped->GetPos() ); + Point ExitMiddle = (p1+p2)*0.5; + double d = 0.2; + Point diff = (p1 - p2).Normalized() * d; + Line e_neu = Line(p1 - diff, p2 + diff); + + if(ped->GetID() == -10) + { + printf("=======\nX=[%.2f], Y=[%.2f]\n", ped->GetPos().GetX(), ped->GetPos().GetY()); + printf("p1=[%.2f, %.2f], p2=[%.2f, %.2f]\n", p1.GetX(), p1.GetY(), p2.GetX(), p2.GetY()); + printf("e_neu=[%.2f, %.2f]===[%.2f, %.2f]\n", e_neu.GetPoint1().GetX(), e_neu.GetPoint1().GetY(), e_neu.GetPoint2().GetX(), e_neu.GetPoint2().GetY() ); + } + + if ( e_neu.IsInLineSegment(Lot) ) { + if(ped->GetID() == -10){ + printf("Return Lot=[%.2f, %.2f]\n", Lot.GetX(), Lot.GetY() ); + if(0 && ped->GetPos().GetX() > 56) + getc(stdin);} + return Lot; + } else { + if(ped->GetID() == -10){ + printf("Return Middle=[%.2f, %.2f]\n", ExitMiddle.GetX(), ExitMiddle.GetY() ); + if(0 && ped->GetPos().GetX() > 56) + getc(stdin);} + return ExitMiddle; + } } diff --git a/routing/DummyRouter.cpp b/routing/DummyRouter.cpp index 155d42a4..2b168d9d 100644 --- a/routing/DummyRouter.cpp +++ b/routing/DummyRouter.cpp @@ -47,7 +47,7 @@ int DummyRouter::FindExit(Pedestrian* p) return 1; } -void DummyRouter::Init(Building* b) +bool DummyRouter::Init(Building* b) { _building=b; Log->Write("ERROR: \tdo not use this <> router !!"); @@ -68,6 +68,7 @@ void DummyRouter::Init(Building* b) // iter->second->WriteToErrorLog(); // } // exit(EXIT_FAILURE); + return true; } diff --git a/routing/DummyRouter.h b/routing/DummyRouter.h index ea2664ef..cfc2554d 100644 --- a/routing/DummyRouter.h +++ b/routing/DummyRouter.h @@ -42,7 +42,7 @@ public: virtual ~DummyRouter(); virtual int FindExit(Pedestrian* p); - virtual void Init(Building* b); + virtual bool Init(Building* b); }; diff --git a/routing/GlobalRouter.cpp b/routing/GlobalRouter.cpp index 43797186..787acd08 100644 --- a/routing/GlobalRouter.cpp +++ b/routing/GlobalRouter.cpp @@ -82,7 +82,7 @@ GlobalRouter::~GlobalRouter() _accessPoints.clear(); } -void GlobalRouter::Init(Building* building) +bool GlobalRouter::Init(Building* building) { //necessary if the init is called several times during the simulation @@ -471,6 +471,8 @@ void GlobalRouter::Init(Building* building) //WriteGraphGV("routing_graph.gv",1,rooms); Log->Write("INFO:\tDone with the Global Router Engine!"); //exit(0); + + return true; } void GlobalRouter::Reset(){ diff --git a/routing/GlobalRouter.h b/routing/GlobalRouter.h index a3d9dd67..d39c8b37 100644 --- a/routing/GlobalRouter.h +++ b/routing/GlobalRouter.h @@ -2,7 +2,7 @@ * \file GlobalRouter.h * \date Dec 15, 2010 * \version v0.5 - * \copyright <2009-2014> Forschungszentrum Jülich GmbH. All rights reserved. + * \copyright <2009-2014> Forschungszentrum J�lich GmbH. All rights reserved. * * \section License * This file is part of JuPedSim. @@ -62,7 +62,7 @@ public: */ virtual ~GlobalRouter(); - virtual void Init(Building* building); + virtual bool Init(Building* building); virtual int FindExit(Pedestrian* p); diff --git a/routing/GraphRouter.cpp b/routing/GraphRouter.cpp index 0862429f..2845ec82 100644 --- a/routing/GraphRouter.cpp +++ b/routing/GraphRouter.cpp @@ -142,9 +142,10 @@ int GraphRouter::FindExit(Pedestrian* p) } } -void GraphRouter::Init(Building* b) +bool GraphRouter::Init(Building* b) { - GlobalRouter::Init(b); + if(GlobalRouter::Init(b)==false) + return false; Log->Write("ERROR: GRAPHROUTER is not ready to use yet."); _building = b; @@ -154,4 +155,5 @@ void GraphRouter::Init(Building* b) // b->GetTransition("200E Normal Exit E3")->Close(); //std::cout << b->GetTransition("200E Normal Exit E3")->IsOpen() << std::endl; + return true; } diff --git a/routing/GraphRouter.h b/routing/GraphRouter.h index 710f04e2..249de23f 100644 --- a/routing/GraphRouter.h +++ b/routing/GraphRouter.h @@ -40,7 +40,7 @@ public: virtual ~GraphRouter(); virtual int FindExit(Pedestrian* p); - virtual void Init(Building* b); + virtual bool Init(Building* b); private: RoutingGraphStorage g; diff --git a/routing/MeshRouter.cpp b/routing/MeshRouter.cpp index 726e1cc6..b2f8d434 100644 --- a/routing/MeshRouter.cpp +++ b/routing/MeshRouter.cpp @@ -845,7 +845,7 @@ void MeshRouter::FixMeshEdges() } } -void MeshRouter::Init(Building* b) +bool MeshRouter::Init(Building* b) { _building=b; //Log->Write("WARNING: \tdo not use this <> router !!"); @@ -955,6 +955,7 @@ void MeshRouter::Init(Building* b) } _meshdata=new MeshData(nodes,edges,outedges,mCellGroups); FixMeshEdges(); + return true; } void MeshRouter::WriteMeshToFile(const string& filename) diff --git a/routing/MeshRouter.h b/routing/MeshRouter.h index 6e10b5ed..e8f80a42 100644 --- a/routing/MeshRouter.h +++ b/routing/MeshRouter.h @@ -51,7 +51,7 @@ public: virtual ~MeshRouter(); virtual int FindExit(Pedestrian* p); - virtual void Init(Building* b); + virtual bool Init(Building* b); }; diff --git a/routing/QuickestPathRouter.cpp b/routing/QuickestPathRouter.cpp index 3f7fb618..535e254d 100644 --- a/routing/QuickestPathRouter.cpp +++ b/routing/QuickestPathRouter.cpp @@ -294,13 +294,14 @@ double QuickestPathRouter::gain(double time) } -void QuickestPathRouter::Init(Building* building) +bool QuickestPathRouter::Init(Building* building) { Log->Write("INFO:\tInit Quickest Path Router Engine"); // prefer path through corridors to path through rooms SetEdgeCost(10.0); - GlobalRouter::Init(building); + if (GlobalRouter::Init(building) == false) + return false; // activate the spotlight for tracking some pedestrians //Pedestrian::ActivateSpotlightSystem(true); @@ -313,6 +314,7 @@ void QuickestPathRouter::Init(Building* building) //DumpAccessPoints(1185); //exit(0); Log->Write("INFO:\tDone with Quickest Path Router Engine!"); + return true; } void QuickestPathRouter::SelectReferencePedestrian(Pedestrian* myself, Pedestrian** myref, double jamThreshold, int exitID, int* flag) diff --git a/routing/QuickestPathRouter.h b/routing/QuickestPathRouter.h index c9367dad..84eeef8b 100644 --- a/routing/QuickestPathRouter.h +++ b/routing/QuickestPathRouter.h @@ -54,7 +54,7 @@ public: virtual int FindExit(Pedestrian* ped); - virtual void Init(Building* building); + virtual bool Init(Building* building); private: diff --git a/routing/Router.h b/routing/Router.h index 944352c5..533e9cbb 100644 --- a/routing/Router.h +++ b/routing/Router.h @@ -129,7 +129,7 @@ public: * its Routing engine using the supplied building object. * @param b the building object */ - virtual void Init(Building* b) = 0; + virtual bool Init(Building* b) = 0; }; diff --git a/routing/RoutingEngine.cpp b/routing/RoutingEngine.cpp index 3b7d6ee7..d89ded40 100644 --- a/routing/RoutingEngine.cpp +++ b/routing/RoutingEngine.cpp @@ -107,9 +107,12 @@ void RoutingEngine::AddTrip(vector trip) _tripsCollection.push_back(trip); } -void RoutingEngine::Init(Building* building) +bool RoutingEngine::Init(Building* building) { + bool status=true; for(unsigned int r=0; r<_routersCollection.size(); r++) { - _routersCollection[r]->Init(building); + if(_routersCollection[r]->Init(building)==false) + status=false; } + return status; } diff --git a/routing/RoutingEngine.h b/routing/RoutingEngine.h index 5ff08286..4602d6ff 100644 --- a/routing/RoutingEngine.h +++ b/routing/RoutingEngine.h @@ -95,8 +95,9 @@ public: /** * Initialize all routers with the current building object * @param building + * @return the status of the initialisation */ - void Init(Building* building); + bool Init(Building* building); private: /// collections of all routers used diff --git a/routing/SafestPathRouter.cpp b/routing/SafestPathRouter.cpp index 75820fe2..2d674f5b 100644 --- a/routing/SafestPathRouter.cpp +++ b/routing/SafestPathRouter.cpp @@ -87,11 +87,12 @@ SafestPathRouter::~SafestPathRouter() delete dFinalLineEvac; } -void SafestPathRouter::Init(Building* building) +bool SafestPathRouter::Init(Building* building) { //Load the FDS file info //handle over to the global router engine - GlobalRouter::Init(building); + if(GlobalRouter::Init(building)==false) + return false; for (int i = 0; i < _building->GetNumberOfRooms(); i++) { @@ -150,6 +151,8 @@ void SafestPathRouter::Init(Building* building) //cout << rR[i] << " "; //} + + return true; } @@ -493,7 +496,8 @@ void SafestPathRouter::ReadMatrixFromFDS() void SafestPathRouter::GetHline(Building* building) { - + //suppress the unused warning +(void)building; /* // cout << dFinalLineEvac[j]<< " "; diff --git a/routing/SafestPathRouter.h b/routing/SafestPathRouter.h index 9a1210aa..d41afe7a 100644 --- a/routing/SafestPathRouter.h +++ b/routing/SafestPathRouter.h @@ -46,8 +46,7 @@ public: * Load the fds simulation file and preprocess the input, * before calling the Init from the Global RouterEngine */ - virtual void Init(Building* building); - + virtual bool Init(Building* building); /** * Bypass using diff --git a/routing/graph/RoutingGraph.cpp b/routing/graph/RoutingGraph.cpp index 6dbdd65a..c0d09770 100644 --- a/routing/graph/RoutingGraph.cpp +++ b/routing/graph/RoutingGraph.cpp @@ -199,7 +199,7 @@ RoutingGraph * RoutingGraph::BuildGraph() } //print(); return this; -}; +} /** * RoutingGraph::addVertex(NavLine * nav_line) @@ -316,7 +316,7 @@ void RoutingGraph::addEdge(Vertex * v1, Vertex * v2, SubRoom* sub) v1->edges[v2->id] = new_edge; } -}; +} bool RoutingGraph::checkVisibility(Line* l1, Line* l2, SubRoom* sub) { @@ -479,7 +479,7 @@ void RoutingGraph::print() map * RoutingGraph::GetAllVertexes() { return &vertexes; -}; +} Vertex * RoutingGraph::GetVertex(int id) @@ -491,7 +491,7 @@ Vertex * RoutingGraph::GetVertex(int id) } else { return NULL; } -}; +} /**************************************** * Class Vertex -- GitLab