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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
19 // Main for SUMO
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #ifdef HAVE_VERSION_H
29 #include <version.h>
30 #endif
31 
32 #include <ctime>
33 #include <string>
34 #include <iostream>
35 #include <netload/NLBuilder.h>
42 #include <utils/common/ToString.h>
43 #include <utils/common/StdDefs.h>
44 #include <utils/xml/XMLSubSys.h>
46 
47 
48 // ===========================================================================
49 // functions
50 // ===========================================================================
51 /* -------------------------------------------------------------------------
52  * main
53  * ----------------------------------------------------------------------- */
54 int
55 main(int argc, char** argv) {
57  // give some application descriptions
58  oc.setApplicationDescription("A microscopic, multi-modal traffic simulation.");
59  oc.setApplicationName("sumo", "Eclipse SUMO Version " VERSION_STRING);
60  gSimulation = true;
61  int ret = 0;
62  try {
63  // initialise subsystems
65  OptionsIO::setArgs(argc, argv);
66  // load the net
68  while (state == MSNet::SIMSTATE_LOADING) {
69  MSNet* net = NLBuilder::init();
70  if (net != nullptr) {
71  state = net->simulate(string2time(oc.getString("begin")), string2time(oc.getString("end")));
72  delete net;
73  } else {
74  break;
75  }
76  }
77  } catch (const ProcessError& e) {
78  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
79  WRITE_ERROR(e.what());
80  }
81  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
82  ret = 1;
83 #ifndef _DEBUG
84  } catch (const std::exception& e) {
85  if (std::string(e.what()) != std::string("")) {
86  WRITE_ERROR(e.what());
87  }
88  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
89  ret = 1;
90  } catch (...) {
91  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
92  ret = 1;
93 #endif
94  }
97  return ret;
98 }
99 
100 
101 /****************************************************************************/
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:48
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:76
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:308
static void close()
Closes all of an applications subsystems.
int main(int argc, char **argv)
Definition: sumo_main.cpp:55
SimulationState
Possible states of a simulation - running or stopped with different reasons.
Definition: MSNet.h:90
The simulated network and simulation perfomer.
Definition: MSNet.h:85
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:55
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
bool gSimulation
Definition: StdDefs.cpp:30
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:42
#define VERSION_STRING
Definition: version.h:1
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:248
The simulation is loading.
Definition: MSNet.h:92
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:113
A storage for options typed value containers)
Definition: OptionsCont.h:92
static MSNet * init()
Definition: NLBuilder.cpp:220
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.