main.cpp 4.14 KB
Newer Older
1
/**
Weichen's avatar
Weichen committed
2 3
 * \file        main.cpp
 * \date        Jan 15, 2013
4
 * \version     v0.6
Mohcine Chraibi's avatar
Mohcine Chraibi committed
5
 * \copyright   <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved.
Weichen's avatar
Weichen committed
6
 *
7
 * \section License
8 9 10
 * This file is part of JuPedSim.
 *
 * JuPedSim is free software: you can redistribute it and/or modify
Weichen's avatar
Weichen committed
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.
 *
Weichen's avatar
Weichen committed
20 21
 * You should have received a copy of the GNU Lesser General Public License
 * along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 * \section Description
Weichen's avatar
Weichen committed
24
 * main function
25
 *
Mohcine Chraibi's avatar
Mohcine Chraibi committed
26
 *
Weichen's avatar
Weichen committed
27 28
 **/

Ulrich Kemloh's avatar
Ulrich Kemloh committed
29 30
#include "geometry/Building.h"
#include "general/ArgumentParser.h"
31
#include "./Simulation.h"
32
#include "pedestrian/AgentsSourcesManager.h"
33
#include "matsim/HybridSimulationManager.h"
34 35 36 37

#include <thread>
#include <functional>
//#include <boost/version.hpp>
Mohcine Chraibi's avatar
Mohcine Chraibi committed
38

39 40
int main(int argc, char **argv)
{
41
     //gathering some statistics about the runtime
42
     time_t starttime, endtime;
43

44 45
     // Log = new FileHandler("./Logfile.dat");
     Log = new STDIOHandler();
46

47
     // Parsing the arguments
48
     ArgumentParser* args = new ArgumentParser();
49
     bool status=args->ParseArgs(argc, argv);
50

51
     // create and initialize the simulation engine
52 53
     // Simulation
     time(&starttime);
54

55
     Simulation sim(*args);
56 57

     if(status&&sim.InitArgs(*args))
58
     {
59 60
          //evacuation time
          int evacTime = 0;
61
          //Start the thread for managing incoming messages from MatSim
62
          auto hybrid=args->GetHybridSimManager();
63 64 65 66
          //process the hybrid simulation
          if(hybrid)
          {
               evacTime=hybrid->Run(sim);
67
          }
68 69 70 71
          //process the normal simulation
          else
          {
               //Start the threads for managing the sources of agents if any
72
               std::thread t1(sim.GetAgentSrcManager());
73

74
               //std::thread t1(&AgentsSourcesManager::Run, &sim.GetAgentSrcManager());
75

76 77
               //main thread for the simulation
               Log->Write("INFO: \tStart runSimulation()");
78 79
               //evacTime = sim.RunSimulation(args->GetTmax());
               evacTime = sim.RunStandardSimulation(args->GetTmax());
80 81
               Log->Write("\nINFO: \tEnd runSimulation()");
               time(&endtime);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
82

83 84 85
               //the execution is finished at this time
               //so join the main thread
               t1.join();
86

87
          }
88

89
          // some statistics output
90 91 92 93
          if(args->ShowStatistics())
          {
               sim.PrintStatistics();
          }
94

95 96
          if (sim.GetPedsNumber())
          {
Mohcine Chraibi's avatar
Mohcine Chraibi committed
97
               Log->Write("WARNING: \nPedestrians not evacuated [%d] using [%d] threads",
98 99
                         sim.GetPedsNumber(), args->GetMaxOpenMPThreads());
          }
Ulrich Kemloh's avatar
Ulrich Kemloh committed
100

101
          double execTime = difftime(endtime, starttime);
102 103 104 105 106 107
          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());
108

109
          if (nullptr == dynamic_cast<STDIOHandler*>(Log))
110
          {
111 112 113 114 115 116 117
               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());
          }
118

119
     }
Oliver Schmidts's avatar
Oliver Schmidts committed
120
     else
121 122 123
     {
          Log->Write("INFO:\tFinishing...");
     }
124 125 126
     // do the last cleaning
     delete args;
     delete Log;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
127

128
     return (EXIT_SUCCESS);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
129
}