SUMO - Simulation of Urban MObility
sumo_main.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
21 // Main for SUMO
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #ifdef HAVE_VERSION_H
35 #include <version.h>
36 #endif
37 
38 #include <ctime>
39 #include <string>
40 #include <iostream>
41 #include <netload/NLBuilder.h>
47 #include <utils/common/ToString.h>
48 #include <utils/xml/XMLSubSys.h>
49 
50 #ifndef NO_TRACI
52 #endif
53 
54 
55 // ===========================================================================
56 // functions
57 // ===========================================================================
58 /* -------------------------------------------------------------------------
59  * main
60  * ----------------------------------------------------------------------- */
61 int
62 main(int argc, char** argv) {
64  // give some application descriptions
65  oc.setApplicationDescription("A microscopic road traffic simulation.");
66  oc.setApplicationName("sumo", "SUMO Version " VERSION_STRING);
67  int ret = 0;
68  try {
69  // initialise subsystems
71  OptionsIO::setArgs(argc, argv);
72  // load the net
74  while (state == MSNet::SIMSTATE_LOADING) {
75  MSNet* net = NLBuilder::init();
76  if (net != nullptr) {
77  state = net->simulate(string2time(oc.getString("begin")), string2time(oc.getString("end")));
78  delete net;
79  } else {
80  break;
81  }
82  }
83  } catch (const ProcessError& e) {
84  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
85  WRITE_ERROR(e.what());
86  }
87  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
88  ret = 1;
89 #ifndef _DEBUG
90  } catch (const std::exception& e) {
91  if (std::string(e.what()) != std::string("")) {
92  WRITE_ERROR(e.what());
93  }
94  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
95  ret = 1;
96  } catch (...) {
97  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
98  ret = 1;
99 #endif
100  }
101 #ifndef NO_TRACI
103 #endif
105  return ret;
106 }
107 
108 
109 /****************************************************************************/
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:53
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:75
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
SimulationState simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:313
static void close()
Closes all of an applications subsystems.
int main(int argc, char **argv)
Definition: sumo_main.cpp:62
SimulationState
Possible states of a simulation - running or stopped with different reasons.
Definition: MSNet.h:95
The simulated network and simulation perfomer.
Definition: MSNet.h:90
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:61
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
static void close()
request termination of connection
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:46
#define VERSION_STRING
Definition: config.h:210
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
The simulation is loading.
Definition: MSNet.h:97
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:84
A storage for options typed value containers)
Definition: OptionsCont.h:98
static MSNet * init()
Definition: NLBuilder.cpp:226
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.