SUMO - Simulation of Urban MObility
sumo_main.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // Main for SUMO
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #ifdef HAVE_VERSION_H
36 #include <version.h>
37 #endif
38 
39 #include <ctime>
40 #include <string>
41 #include <iostream>
42 #include <microsim/MSGlobals.h>
43 #include <microsim/MSNet.h>
44 #include <microsim/MSRoute.h>
46 #include <netload/NLBuilder.h>
47 #include <netload/NLHandler.h>
59 #include <utils/common/ToString.h>
60 #include <utils/xml/XMLSubSys.h>
61 #include <microsim/MSFrame.h>
64 
65 #ifdef HAVE_INTERNAL
66 #include <mesosim/MEVehicleControl.h>
67 #endif
68 
69 #ifndef NO_TRACI
71 #endif
72 
73 
74 #ifdef CHECK_MEMORY_LEAKS
75 #include <foreign/nvwa/debug_new.h>
76 #endif
77 
78 // ===========================================================================
79 // functions
80 // ===========================================================================
81 /* -------------------------------------------------------------------------
82  * data processing methods
83  * ----------------------------------------------------------------------- */
87 MSNet*
90  MSVehicleControl* vc = 0;
91 #ifdef HAVE_INTERNAL
93  vc = new MEVehicleControl();
94  } else {
95 #endif
96  vc = new MSVehicleControl();
97 #ifdef HAVE_INTERNAL
98  }
99 #endif
100  MSNet* net = new MSNet(vc, new MSEventControl(),
101  new MSEventControl(), new MSEventControl());
102 #ifndef NO_TRACI
103  // need to init TraCI-Server before loading routes to catch VEHICLE_STATE_BUILT
104  TraCIServer::openSocket(std::map<int, TraCIServer::CmdExecutor>());
105 #endif
106 
108  NLDetectorBuilder db(*net);
109  NLJunctionControlBuilder jb(*net, db);
110  NLTriggerBuilder tb;
111  NLHandler handler("", *net, db, tb, eb, jb);
112  tb.setHandler(&handler);
113  NLBuilder builder(oc, *net, eb, jb, db, handler);
114  if (!builder.build()) {
115  delete net;
116  throw ProcessError();
117  }
118  return net;
119 }
120 
121 
122 /* -------------------------------------------------------------------------
123  * main
124  * ----------------------------------------------------------------------- */
125 int
126 main(int argc, char** argv) {
128  // give some application descriptions
129  oc.setApplicationDescription("A microscopic road traffic simulation.");
130  oc.setApplicationName("sumo", "SUMO Version " + getBuildName(VERSION_STRING));
131  int ret = 0;
132  MSNet* net = 0;
133  try {
134  // initialise subsystems
135  XMLSubSys::init();
137  OptionsIO::getOptions(true, argc, argv);
138  if (oc.processMetaOptions(argc < 2)) {
140  return 0;
141  }
142  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
144  if (!MSFrame::checkOptions()) {
145  throw ProcessError();
146  }
149  // load the net
150  net = load(oc);
151  if (net != 0) {
152  ret = net->simulate(string2time(oc.getString("begin")), string2time(oc.getString("end")));
153  }
154  } catch (const ProcessError& e) {
155  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
156  WRITE_ERROR(e.what());
157  }
158  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
159  ret = 1;
160 #ifndef _DEBUG
161  } catch (const std::exception& e) {
162  if (std::string(e.what()) != std::string("")) {
163  WRITE_ERROR(e.what());
164  }
165  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
166  ret = 1;
167  } catch (...) {
168  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
169  ret = 1;
170 #endif
171  }
172  delete net;
174  return ret;
175 }
176 
177 
178 /****************************************************************************/
void setHandler(NLHandler *handler)
Sets the parent handler to use for nested parsing.
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:58
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
Builds detectors for microsim.
static void getOptions(bool loadConfig, int argc=0, char **argv=0)
Parses the command line arguments and loads the configuration optionally.
Definition: OptionsIO.cpp:64
The main interface for loading a microsim.
Definition: NLBuilder.h:68
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:69
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
static MTRand * getParsingRNG()
int simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:280
static void close()
Closes all of an applications subsystems.
int main(int argc, char **argv)
Definition: sumo_main.cpp:126
The simulated network and simulation perfomer.
Definition: MSNet.h:94
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
static void initRandGlobal(MTRand *which=0)
Reads the given random number options and initialises the random number generator in accordance...
Definition: RandHelper.cpp:68
static void fillOptions()
Inserts options used by the simulation into the OptionsCont-singleton.
Definition: MSFrame.cpp:69
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Builder of microsim-junctions and tls.
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
const std::string getBuildName(const std::string &version)
attach some build flags to the version string
Definition: StdDefs.cpp:88
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:48
#define VERSION_STRING
Definition: config.h:230
The XML-Handler for network loading.
Definition: NLHandler.h:93
static bool checkOptions()
Checks the set options.
Definition: MSFrame.cpp:401
virtual bool build()
Builds and initialises the simulation.
Definition: NLBuilder.cpp:122
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
static void openSocket(const std::map< int, CmdExecutor > &execs)
Initialises the server.
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:89
A storage for options typed value containers)
Definition: OptionsCont.h:108
static const bool gUseMesoSim
Definition: MSGlobals.h:102
static void setMSGlobals(OptionsCont &oc)
Sets the global microsim-options.
Definition: MSFrame.cpp:460
The class responsible for building and deletion of vehicles.
MSNet * load(OptionsCont &oc)
Definition: sumo_main.cpp:88
Builds trigger objects for microsim.
static void initOutputOptions()
Definition: MsgHandler.cpp:197
Stores time-dependant events and executes them at the proper time.
Interface for building edges.
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.