Simulation.cpp 21.1 KB
Newer Older
1
/**
Weichen's avatar
Weichen committed
2 3
 * \file        Simulation.cpp
 * \date        Dec 15, 2010
4
 * \version     v0.6
Weichen's avatar
Weichen committed
5
 * \copyright   <2009-2014> Forschungszentrum Jülich GmbH. All rights reserved.
6
 *
Weichen's avatar
Weichen committed
7
 * \section License
8 9 10
 * This file is part of JuPedSim.
 *
 * JuPedSim is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Lesser General Public License as published by
12 13 14 15 16 17 18 19
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * JuPedSim is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
20
 * You should have received a copy of the GNU Lesser General Public License
Weichen's avatar
Weichen committed
21
 * along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 * \section Description
24 25 26 27
 * The Simulation class represents a simulation of pedestrians
 * based on a certain model in a specific scenario. A simulation is defined by
 * various parameters and functions.
 *
Weichen's avatar
Weichen committed
28 29 30
 *
 **/

Ulrich Kemloh's avatar
Ulrich Kemloh committed
31 32
#include "Simulation.h"

Ulrich Kemloh's avatar
Ulrich Kemloh committed
33 34
#include "math/GCFMModel.h"
#include "math/GompertzModel.h"
35 36
#include "pedestrian/AgentsSourcesManager.h"
#include "pedestrian/AgentsQueue.h"
37
#include "matsim/HybridSimulationManager.h"
38 39 40

#ifdef _OPENMP
#include <omp.h>
41

42 43 44 45 46
#else
#define omp_get_thread_num() 0
#define omp_get_max_threads()  1
#endif

Ulrich Kemloh's avatar
Ulrich Kemloh committed
47
using namespace std;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
48

49 50
OutputHandler* Log;

51
Simulation::Simulation(const ArgumentParser& args)
52 53
{
     _nPeds = 0;
54
     _seed = 8091983;
55
     _deltaT = 0;
Oliver Schmidts's avatar
Oliver Schmidts committed
56
     _building = nullptr;
57
     //_direction = NULL;
Oliver Schmidts's avatar
Oliver Schmidts committed
58 59
     _operationalModel = nullptr;
     _solver = nullptr;
60
     _iod = new IODispatcher();
61
     _fps = 1;
Oliver Schmidts's avatar
Oliver Schmidts committed
62
     _em = nullptr;
63
     _argsParser = args;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
64 65
}

66 67 68 69 70
Simulation::~Simulation()
{
     delete _solver;
     delete _iod;
     delete _em;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
71 72
}

Oliver Schmidts's avatar
Oliver Schmidts committed
73
long Simulation::GetPedsNumber() const
74 75
{
     return _nPeds;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
76 77
}

78
bool Simulation::InitArgs(const ArgumentParser& args)
79 80 81 82
{
     char tmp[CLENGTH];
     string s = "Parameter:\n";

83
     switch (args.GetLog())
84
     {
85 86 87 88 89
     case 0:
          // no log file
          //Log = new OutputHandler();
          break;
     case 1:
90 91
          if (Log)
               delete Log;
92 93 94
          Log = new STDIOHandler();
          break;
     case 2: {
95
          char name[CLENGTH] = "";
96
          sprintf(name, "%s.P0.dat", args.GetErrorLogFile().c_str());
97 98
          if (Log)
               delete Log;
99 100
          Log = new FileHandler(name);
     }
101
     break;
102 103
     default:
          printf("Wrong option for Logfile!\n\n");
104
          return false;
105 106
     }

107 108
     if (args.GetPort() != -1) {
          switch (args.GetFileFormat())
109
          {
110 111
          case FORMAT_XML_PLAIN_WITH_MESH:
          case FORMAT_XML_PLAIN: {
112 113
               OutputHandler* travisto = new SocketHandler(args.GetHostname(),
                         args.GetPort());
114
               Trajectories* output = new TrajectoriesJPSV06();
115 116
               output->SetOutputHandler(travisto);
               _iod->AddIO(output);
117 118 119
               break;
          }
          case FORMAT_XML_BIN: {
120 121
               Log->Write(
                         "INFO: \tFormat xml-bin not yet supported in streaming\n");
Ulrich Kemloh's avatar
Ulrich Kemloh committed
122
               //exit(0);
123 124 125
               break;
          }
          case FORMAT_PLAIN: {
126 127 128
               Log->Write(
                         "INFO: \tFormat plain not yet supported in streaming\n");
               return false;
129 130
          }
          case FORMAT_VTK: {
131 132 133
               Log->Write(
                         "INFO: \tFormat vtk not yet supported in streaming\n");
               return false;
134
          }
135 136 137
          default: {
               return false;
          }
138 139 140 141 142
          }

          s.append("\tonline streaming enabled \n");
     }

143 144
     if (args.GetTrajectoriesFile().empty() == false) {
          switch (args.GetFileFormat())
145
          {
146
          case FORMAT_XML_PLAIN: {
147
               OutputHandler* tofile = new FileHandler(
148
                         args.GetTrajectoriesFile().c_str());
149
               Trajectories* output = new TrajectoriesJPSV05();
150 151
               output->SetOutputHandler(tofile);
               _iod->AddIO(output);
152 153 154
               break;
          }
          case FORMAT_PLAIN: {
155
               OutputHandler* file = new FileHandler(
156
                         args.GetTrajectoriesFile().c_str());
157
               Trajectories* output = new TrajectoriesFLAT();
158 159
               output->SetOutputHandler(file);
               _iod->AddIO(output);
160 161 162 163
               break;
          }
          case FORMAT_VTK: {
               Log->Write("INFO: \tFormat vtk not yet supported\n");
164
               OutputHandler* file = new FileHandler(
165
                         (args.GetTrajectoriesFile() + ".vtk").c_str());
166
               Trajectories* output = new TrajectoriesVTK();
167 168 169 170
               output->SetOutputHandler(file);
               _iod->AddIO(output);
               break;
          }
171

172 173 174 175 176 177 178 179 180 181 182 183
          case FORMAT_XML_PLAIN_WITH_MESH: {
               //OutputHandler* tofile = new FileHandler(args->GetTrajectoriesFile().c_str());
               //if(_iod) delete _iod;
               //_iod = new TrajectoriesXML_MESH();
               //_iod->AddIO(tofile);
               break;
          }
          case FORMAT_XML_BIN: {
               // OutputHandler* travisto = new SocketHandler(args->GetHostname(), args->GetPort());
               // Trajectories* output= new TrajectoriesJPSV06();
               // output->SetOutputHandler(travisto);
               // _iod->AddIO(output);
184 185
               break;
          }
186 187 188
          default: {
               break;
          }
189 190 191
          }
     }

Oliver Schmidts's avatar
Oliver Schmidts committed
192

193

194
     _operationalModel = args.GetModel();
195
     s.append(_operationalModel->GetDescription());
196

197
     // ODE solver which is never used!
198
     auto solver = args.GetSolver();
199
     sprintf(tmp, "\tODE Solver: %d\n", solver);
200
     s.append(tmp);
201

202
     sprintf(tmp, "\tnCPU: %d\n", args.GetMaxOpenMPThreads());
Mohcine Chraibi's avatar
Mohcine Chraibi committed
203
     s.append(tmp);
204
     sprintf(tmp, "\tt_max: %f\n", args.GetTmax());
205
     s.append(tmp);
206
     _deltaT = args.Getdt();
207 208 209
     sprintf(tmp, "\tdt: %f\n", _deltaT);
     s.append(tmp);

210
     _fps = args.Getfps();
211 212
     sprintf(tmp, "\tfps: %f\n", _fps);
     s.append(tmp);
213
     //Log->Write(s.c_str());
214

Oliver Schmidts's avatar
Oliver Schmidts committed
215 216
     _routingEngine = args.GetRoutingEngine();
     auto distributor = std::unique_ptr<PedDistributor>(new PedDistributor(_argsParser.GetProjectFile(), _argsParser.GetAgentsParameters(),_argsParser.GetSeed()));
217
     // IMPORTANT: do not change the order in the following..
Oliver Schmidts's avatar
Oliver Schmidts committed
218
     _building = std::unique_ptr<Building>(new Building(args.GetProjectFile(), args.GetProjectRootDir(), *_routingEngine, *distributor, args.GetLinkedCellSize()));
219

220
     // Initialize the agents sources that have been collected in the pedestrians distributor
221
     _agentSrcManager.SetBuilding(_building.get());
222 223 224
     for (const auto& src: distributor->GetAgentsSources())
     {
          _agentSrcManager.AddSource(src);
225
          //src->Dump();
226 227
     }

228 229 230 231
     //iniitalize the hybridmode if defined
     if(nullptr!=(_hybridSimManager=args.GetHybridSimManager()))
     {
          _hybridSimManager->Init(_building.get());
232
     }
233

234 235 236
     //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.
Oliver Schmidts's avatar
Oliver Schmidts committed
237
     if(_operationalModel->Init(_building.get())==false)
238
          return false;
239 240

     //other initializations
241 242 243 244
     const vector<Pedestrian*>& allPeds = _building->GetAllPedestrians();
     for (Pedestrian *ped : allPeds) {
          ped->Setdt(_deltaT);
     }
Oliver Schmidts's avatar
Oliver Schmidts committed
245
     _nPeds = allPeds.size();
246 247 248
     //pBuilding->WriteToErrorLog();

     //get the seed
249
     _seed = args.GetSeed();
250

251
     //size of the cells/GCFM/Gompertz
252
     if (args.GetDistEffMaxPed() > args.GetLinkedCellSize()) {
253 254
          Log->Write(
                    "ERROR: the linked-cell size [%f] should be bigger than the force range [%f]",
255
                    args.GetLinkedCellSize(), args.GetDistEffMaxPed());
256
          return false;
257
     }
258

Ulrich Kemloh's avatar
Ulrich Kemloh committed
259
     //read and initialize events
Oliver Schmidts's avatar
Oliver Schmidts committed
260
     _em = new EventManager(_building.get());
Ulrich Kemloh's avatar
Ulrich Kemloh committed
261 262 263 264
     if(_em->ReadEventsXml()==false)
     {
          Log->Write("ERROR: \tCould not initialize events handling");
     }
Ulrich Kemloh's avatar
Ulrich Kemloh committed
265
     _em->ListEvents();
266

267
     //_building->SaveGeometry("test.sav.xml");
Ulrich Kemloh's avatar
Ulrich Kemloh committed
268

269 270 271
     //if(_building->SanityCheck()==false)
     //     return false;

272 273 274
     //everything went fine
     return true;
}
Ulrich Kemloh's avatar
Ulrich Kemloh committed
275

276 277
int Simulation::RunStandardSimulation(double maxSimTime)
{
278
     RunHeader(_nPeds + _agentSrcManager.GetMaxAgentNumber());
279 280 281 282 283 284
     double t=RunBody(maxSimTime);
     RunFooter();
     return (int)t;

}
//TODO: use RunHeader, RunBody and RunFooter
285
int Simulation::RunSimulation(double maxSimTime)
286 287 288 289
{
     int frameNr = 1; // Frame Number
     int writeInterval = (int) ((1. / _fps) / _deltaT + 0.5);
     writeInterval = (writeInterval <= 0) ? 1 : writeInterval; // mustn't be <= 0
290
     double t = 0.0;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
291

292
     // writing the header
Oliver Schmidts's avatar
Oliver Schmidts committed
293 294 295
     _iod->WriteHeader(_nPeds, _fps, _building.get(), _seed);
     _iod->WriteGeometry(_building.get());
     _iod->WriteFrame(0, _building.get());
Ulrich Kemloh's avatar
Ulrich Kemloh committed
296

297
     //first initialisation needed by the linked-cells
298
     UpdateRoutesAndLocations();
299
     ProcessAgentsQueue();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
300

301 302 303 304
     //needed to control the execution time PART 1
     //in the case you want to run in no faster than realtime
     //time_t starttime, endtime;
     //time(&starttime);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
305

306
     // main program loop
307
     while ( (_nPeds || !_agentSrcManager.IsCompleted() ) && t < maxSimTime)
308
     {
309
          t = 0 + (frameNr - 1) * _deltaT;
310

311
          //process the queue for incoming pedestrians
312 313
          ProcessAgentsQueue();

314 315 316
          //cout<<"nPeds: "<<_nPeds<<endl;
          //cout<<"manager: "<<_agentSrcManager.IsCompleted()<<endl;

317
          // update the positions
Oliver Schmidts's avatar
Oliver Schmidts committed
318
          _operationalModel->ComputeNextTimeStep(t, _deltaT, _building.get());
319

320
          //update the routes and locations
321 322 323
          UpdateRoutesAndLocations();

          //update the events
324 325
          //_em->Update_Events(t);
          _em->ProcessEvent();
326 327

          //other updates
328
          //someone might have left the building
329
          _nPeds = _building->GetAllPedestrians().size();
330 331 332 333 334

          //update the linked cells
          _building->UpdateGrid();

          // update the global time
335
          Pedestrian::SetGlobalTime(t);
336 337

          // write the trajectories
338
          if (0 == frameNr % writeInterval) {
Oliver Schmidts's avatar
Oliver Schmidts committed
339
               _iod->WriteFrame(frameNr / writeInterval, _building.get());
340
          }
341

342 343 344 345 346
          // needed to control the execution time PART 2
          // time(&endtime);
          // double timeToWait=t-difftime(endtime, starttime);
          // clock_t goal = timeToWait*1000 + clock();
          // while (goal > clock());
347
          ++frameNr;
348 349 350
     }
     // writing the footer
     _iod->WriteFooter();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
351

352
     //if(_hpc==1)
353
     //  ((GPU_GCFMModel*) _model)->DeleteBuffers();
354

355
     //temporary work around since the total number of frame is only available at the end of the simulation.
356 357
     if (_argsParser.GetFileFormat() == FORMAT_XML_BIN)
     {
358 359
          delete _iod;
          _iod = NULL;
360
          //reopen the file and write the missing information
361

Ulrich Kemloh's avatar
Ulrich Kemloh committed
362 363 364 365
          // char tmp[CLENGTH];
          // int f= frameNr / writeInterval ;
          // sprintf(tmp,"<frameCount>%07d</frameCount>",f);
          // string frameCount (tmp);
366

367 368
          char replace[CLENGTH];
          // open the file and replace the 8th line
369
          sprintf(replace, "sed -i '9s/.*/ %d /' %s", frameNr / writeInterval,
370
                    _argsParser.GetTrajectoriesFile().c_str());
371 372 373
          int result = system(replace);
          Log->Write("INFO:\t Updating the framenumber exits with code [%d]",
                    result);
374
     }
375

376 377
     //return the evacuation time
     return (int) t;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
378 379
}

380
void Simulation::UpdateRoutesAndLocations()
381
{
382 383 384 385 386 387
     //pedestrians to be deleted
     //you should better create this in the constructor and allocate it once.
     vector<Pedestrian*> pedsToRemove;
     pedsToRemove.reserve(100); //just reserve some space

     // collect all pedestrians in the simulation.
388 389
     const vector<Pedestrian*>& allPeds = _building->GetAllPedestrians();
     const map<int, Goal*>& goals = _building->GetAllGoals();
390

391
     unsigned long nSize = allPeds.size();
392 393 394 395 396 397 398 399 400 401 402
     int nThreads = omp_get_max_threads();
     int partSize = nSize / nThreads;

#pragma omp parallel  default(shared) num_threads(nThreads)
     {
          const int threadID = omp_get_thread_num();
          int start = threadID * partSize;
          int end = (threadID + 1) * partSize - 1;
          if ((threadID == nThreads - 1))
               end = nSize - 1;

403
          for (int p = start; p <= end; ++p) {
404 405
               Pedestrian* ped = allPeds[p];
               Room* room = _building->GetRoom(ped->GetRoomID());
406
               SubRoom* sub0 = room->GetSubRoom(ped->GetSubRoomID());
407 408 409

               //set the new room if needed
               if ((ped->GetFinalDestination() == FINAL_DEST_OUT)
410
                         && (room->GetCaption() == "outside")) {
411 412
#pragma omp critical
                    pedsToRemove.push_back(ped);
413 414 415
               } else if ((ped->GetFinalDestination() != FINAL_DEST_OUT)
                         && (goals.at(ped->GetFinalDestination())->Contains(
                                   ped->GetPos()))) {
416 417 418 419 420 421 422
#pragma omp critical
                    pedsToRemove.push_back(ped);
               }

               // 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
423
               else if (!sub0->IsInSubRoom(ped))
424
               {
425
                    bool assigned = false;
426 427 428
                    auto& allRooms = _building->GetAllRooms();

                    for (auto&& it_room : allRooms)
429
                    {
430 431
                         auto&& room=it_room.second;
                         for (auto&& it_sub : room->GetAllSubRooms())
432
                         {
433 434 435
                              auto&& sub=it_sub.second;
                              auto&& old_room =allRooms.at(ped->GetRoomID());
                              auto&& old_sub =old_room->GetSubRoom(
436
                                        ped->GetSubRoomID());
437 438
                              if ((sub->IsInSubRoom(ped->GetPos()))
                                        && (sub->IsDirectlyConnectedWith(
439 440
                                                  old_sub)))
                              {
441 442 443
                                   ped->SetRoomID(room->GetID(),
                                             room->GetCaption());
                                   ped->SetSubRoomID(sub->GetSubRoomID());
444 445
                                   ped->ClearMentalMap(); // reset the destination
                                   //ped->FindRoute();
446

447 448
                                   //the agent left the old iroom
                                   //actualize the egress time for that iroom
449 450
                                   old_room->SetEgressTime(ped->GetGlobalTime());

451 452 453 454
                                   assigned = true;
                                   break;
                              }
                         }
455
                         if (assigned)
456 457 458
                              break; // stop the loop
                    }

459
                    if (!assigned) {
460 461
#pragma omp critical
                         pedsToRemove.push_back(ped);
462
                         //the agent left the old room
Ulrich Kemloh's avatar
Ulrich Kemloh committed
463
                         //actualize the eggress time for that room
464
                         allRooms.at(ped->GetRoomID())->SetEgressTime(ped->GetGlobalTime());
465

466 467 468 469 470 471
                    }
               }

               //finally actualize the route
               if (ped->FindRoute() == -1) {
                    //a destination could not be found for that pedestrian
472
                    Log->Write("ERROR: \tCould not find a route for pedestrian %d",ped->GetID());
473
                    //exit(EXIT_FAILURE);
474 475 476 477 478 479
#pragma omp critical
                    pedsToRemove.push_back(ped);
               }
          }
     }

480 481 482 483 484 485 486 487 488 489 490 491 492

     if (_hybridSimManager)
     {
          AgentsQueueOut::Add(pedsToRemove);
     }
     else
     {
          // remove the pedestrians that have left the building
          for (unsigned int p = 0; p < pedsToRemove.size(); p++)
          {
               _building->DeletePedestrian(pedsToRemove[p]);
          }

493 494 495 496 497 498 499 500
     }

     //    temporary fix for the safest path router
     //    if (dynamic_cast<SafestPathRouter*>(_routingEngine->GetRouter(1)))
     //    {
     //         SafestPathRouter* spr = dynamic_cast<SafestPathRouter*>(_routingEngine->GetRouter(1));
     //         spr->ComputeAndUpdateDestinations(_allPedestians);
     //    }
Ulrich Kemloh's avatar
Ulrich Kemloh committed
501
}
Ulrich Kemloh's avatar
Ulrich Kemloh committed
502

503 504
void Simulation::PrintStatistics()
{
505 506
     Log->Write("\nRooms Egress Time:");
     Log->Write("==================");
507 508
     Log->Write("id\tcaption\tegress time (s)");

509
     for(const auto& it:_building->GetAllRooms())
510
     {
511
          auto&& room=it.second;
512
          if(room->GetCaption()!="outside")
513
               Log->Write("%d\t%s\t%.2f",room->GetID(),room->GetCaption().c_str(),room->GetEgressTime());
514 515
     }

516 517
     Log->Write("\nUsage of Exits");
     Log->Write("==========");
518
     for (const auto& itr : _building->GetAllTransitions()) {
519
          Transition* goal = itr.second;
520 521 522 523 524
          if (goal->IsExit()) {
               Log->Write(
                         "Exit ID [%d] used by [%d] pedestrians. Last passing time [%0.2f] s",
                         goal->GetID(), goal->GetDoorUsage(),
                         goal->GetLastPassingTime());
525 526
          }
     }
527 528

     Log->Write("\n");
Ulrich Kemloh's avatar
Ulrich Kemloh committed
529
}
530

531 532 533 534 535 536 537 538 539 540 541 542
void Simulation::RunHeader(long nPed)
{
     // writing the header
     if(nPed==-1) nPed=_nPeds;
     _iod->WriteHeader(nPed, _fps, _building.get(), _seed);
     _iod->WriteGeometry(_building.get());
     _iod->WriteFrame(0, _building.get());

     //first initialisation needed by the linked-cells
      UpdateRoutesAndLocations();
      ProcessAgentsQueue();
}
543

544
int Simulation::RunBody(double maxSimTime)
545
{
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
     //needed to control the execution time PART 1
     //in the case you want to run in no faster than realtime
     //time_t starttime, endtime;
     //time(&starttime);

     //frame number. This function can be called many times,
     static int frameNr = 1; // Frame Number
     int writeInterval = (int) ((1. / _fps) / _deltaT + 0.5);
     writeInterval = (writeInterval <= 0) ? 1 : writeInterval; // mustn't be <= 0

     //take the current time from the pedestrian
     double t=Pedestrian::GetGlobalTime();

     //process the queue for incoming pedestrians
     //important since the number of peds is used
     //to break the main simulation loop
     ProcessAgentsQueue();
     _nPeds = _building->GetAllPedestrians().size();

     // main program loop
     while ( (_nPeds || !_agentSrcManager.IsCompleted() ) && t < maxSimTime)
     {
          t = 0 + (frameNr - 1) * _deltaT;

          //process the queue for incoming pedestrians
          ProcessAgentsQueue();

573 574 575
          //update the linked cells
          _building->UpdateGrid();

576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
          // update the positions
          _operationalModel->ComputeNextTimeStep(t, _deltaT, _building.get());

          //update the routes and locations
          UpdateRoutesAndLocations();

          //update the events
          //_em->Update_Events(t);
          _em->ProcessEvent();

          //other updates
          //someone might have left the building
          _nPeds = _building->GetAllPedestrians().size();


          // update the global time
          Pedestrian::SetGlobalTime(t);

          // write the trajectories
          if (0 == frameNr % writeInterval) {
               _iod->WriteFrame(frameNr / writeInterval, _building.get());
          }

          // needed to control the execution time PART 2
          // time(&endtime);
          // double timeToWait=t-difftime(endtime, starttime);
          // clock_t goal = timeToWait*1000 + clock();
          // while (goal > clock());
          ++frameNr;
     }
     return (int) t;
607 608
}

609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
void Simulation::RunFooter()
{
     // writing the footer
     _iod->WriteFooter();

     //temporary work around since the total number of frame is only available at the end of the simulation.
     if (_argsParser.GetFileFormat() == FORMAT_XML_BIN)
     {
          delete _iod;
          _iod = NULL;
          //reopen the file and write the missing information

          // char tmp[CLENGTH];
          // int f= frameNr / writeInterval ;
          // sprintf(tmp,"<frameCount>%07d</frameCount>",f);
          // string frameCount (tmp);

          //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);
     }
}



637 638
void Simulation::ProcessAgentsQueue()
{
639 640

     //incoming pedestrians
641 642 643 644 645 646
     vector<Pedestrian*> peds;
     AgentsQueue::GetandClear(peds);
     for(auto&& ped: peds)
     {
          _building->AddPedestrian(ped);
     }
647 648 649 650 651 652

     //outgoing pedestrians
     if (_hybridSimManager)
     {
          _hybridSimManager->ProcessOutgoingAgent();
     }
653
}
654

655
AgentsSourcesManager& Simulation::GetAgentSrcManager()
656 657 658
{
     return _agentSrcManager;
}