SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
14 // Copyright (C) 2001-2013 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/MSNet.h>
43 #include <microsim/MSRoute.h>
45 #include <netload/NLBuilder.h>
46 #include <netload/NLHandler.h>
58 #include <utils/common/ToString.h>
59 #include <utils/xml/XMLSubSys.h>
60 #include <microsim/MSFrame.h>
63 
64 #ifdef HAVE_INTERNAL
65 #include <mesosim/MEVehicleControl.h>
66 #endif
67 
68 #ifdef CHECK_MEMORY_LEAKS
69 #include <foreign/nvwa/debug_new.h>
70 #endif
71 
72 // ===========================================================================
73 // functions
74 // ===========================================================================
75 /* -------------------------------------------------------------------------
76  * data processing methods
77  * ----------------------------------------------------------------------- */
81 MSNet*
84  MSVehicleControl* vc = 0;
85 #ifdef HAVE_INTERNAL
87  vc = new MEVehicleControl();
88  } else {
89 #endif
90  vc = new MSVehicleControl();
91 #ifdef HAVE_INTERNAL
92  }
93 #endif
94  MSNet* net = new MSNet(vc, new MSEventControl(),
95  new MSEventControl(), new MSEventControl());
97  NLDetectorBuilder db(*net);
98  NLJunctionControlBuilder jb(*net, db);
100  NLHandler handler("", *net, db, tb, eb, jb);
101  tb.setHandler(&handler);
102  NLBuilder builder(oc, *net, eb, jb, db, handler);
103  if (!builder.build()) {
104  delete net;
105  throw ProcessError();
106  }
107  return net;
108 }
109 
110 
111 /* -------------------------------------------------------------------------
112  * main
113  * ----------------------------------------------------------------------- */
114 int
115 main(int argc, char** argv) {
117  // give some application descriptions
118  oc.setApplicationDescription("A microscopic road traffic simulation.");
119  oc.setApplicationName("sumo", "SUMO sumo Version " + (std::string)VERSION_STRING);
120  int ret = 0;
121  MSNet* net = 0;
122  try {
123  // initialise subsystems
124  XMLSubSys::init();
126  OptionsIO::getOptions(true, argc, argv);
127  if (oc.processMetaOptions(argc < 2)) {
129  return 0;
130  }
131  XMLSubSys::setValidation(oc.getBool("xml-validation"));
133  if (!MSFrame::checkOptions()) {
134  throw ProcessError();
135  }
138  // load the net
139  net = load(oc);
140  if (net != 0) {
141  ret = net->simulate(string2time(oc.getString("begin")), string2time(oc.getString("end")));
142  }
143  } catch (const ProcessError& e) {
144  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
145  WRITE_ERROR(e.what());
146  }
147  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
148  ret = 1;
149 #ifndef _DEBUG
150  } catch (const std::exception& e) {
151  if (std::string(e.what()) != std::string("")) {
152  WRITE_ERROR(e.what());
153  }
154  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
155  ret = 1;
156  } catch (...) {
157  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
158  ret = 1;
159 #endif
160  }
161  delete net;
163  return ret;
164 }
165 
166 
167 /****************************************************************************/
void setHandler(NLHandler *handler)
Sets the parent handler to use for nested parsing.
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:57
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
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
int simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:259
static void close()
Closes all of an applications subsystems.
The simulated network and simulation perfomer.
Definition: MSNet.h:89
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:68
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.
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:48
static MTRand myVehicleParamsRNG
A random number generator used to choose from vtype/route distributions and computing the speed facto...
#define VERSION_STRING
Definition: config.h:227
static bool checkOptions()
Checks the set options.
Definition: MSFrame.cpp:358
virtual bool build()
Builds and initialises the simulation.
Definition: NLBuilder.cpp:122
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:201
static void setValidation(bool enableValidation)
Enables or disables validation.
Definition: XMLSubSys.cpp:68
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:98
static void setMSGlobals(OptionsCont &oc)
Sets the global microsim-options.
Definition: MSFrame.cpp:412
The class responsible for building and deletion of vehicles.
MSNet * load(OptionsCont &oc)
Definition: sumo_main.cpp:82
Builds trigger objects for microsim.
static void initOutputOptions()
Definition: MsgHandler.cpp:193
Stores time-dependant events and executes them at the proper time.
Interface for building edges.
int main(int argc, char *argv[])
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.