sumo_main.cpp
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029
00030 #ifdef HAVE_VERSION_H
00031 #include <version.h>
00032 #endif
00033
00034 #include <ctime>
00035 #include <string>
00036 #include <iostream>
00037 #include <microsim/MSNet.h>
00038 #include <microsim/MSRoute.h>
00039 #include <microsim/MSEmitControl.h>
00040 #include <microsim/MSVehicleControl.h>
00041 #include <netload/NLBuilder.h>
00042 #include <netload/NLHandler.h>
00043 #include <netload/NLTriggerBuilder.h>
00044 #include <netload/NLEdgeControlBuilder.h>
00045 #include <netload/NLJunctionControlBuilder.h>
00046 #include <netload/NLDetectorBuilder.h>
00047 #include <netload/NLGeomShapeBuilder.h>
00048 #include <utils/options/OptionsCont.h>
00049 #include <utils/options/OptionsIO.h>
00050 #include <utils/common/MsgHandler.h>
00051 #include <utils/common/SystemFrame.h>
00052 #include <utils/common/UtilExceptions.h>
00053 #include <utils/common/FileHelpers.h>
00054 #include <utils/common/StringTokenizer.h>
00055 #include <utils/common/ToString.h>
00056 #include <utils/xml/XMLSubSys.h>
00057 #include <microsim/MSFrame.h>
00058 #include <microsim/output/MSDetectorControl.h>
00059 #include <utils/iodevices/OutputDevice.h>
00060
00061 #ifdef CHECK_MEMORY_LEAKS
00062 #include <foreign/nvwa/debug_new.h>
00063 #endif
00064
00065
00066
00067
00068
00069
00070
00074 MSNet *
00075 load(OptionsCont &oc) {
00076 MSFrame::setMSGlobals(oc);
00077 MSNet *net = new MSNet(new MSVehicleControl(), new MSEventControl(),
00078 new MSEventControl(), new MSEventControl());
00079 NLEdgeControlBuilder eb;
00080 NLJunctionControlBuilder jb(*net, oc);
00081 NLDetectorBuilder db(*net);
00082 NLTriggerBuilder tb;
00083 NLGeomShapeBuilder sb(*net);
00084 NLHandler handler("", *net, db, tb, eb, jb, sb);
00085 tb.setHandler(&handler);
00086 NLBuilder builder(oc, *net, eb, jb, db, handler);
00087 if (!builder.build()) {
00088 delete net;
00089 throw ProcessError();
00090 }
00091 return net;
00092 }
00093
00094
00095
00096
00097
00098 int
00099 main(int argc, char **argv) {
00100 OptionsCont &oc = OptionsCont::getOptions();
00101
00102 oc.setApplicationDescription("A microscopic road traffic simulation.");
00103 oc.setApplicationName("sumo", "SUMO sumo Version " + (std::string)VERSION_STRING);
00104 int ret = 0;
00105 MSNet *net = 0;
00106 try {
00107
00108 XMLSubSys::init(false);
00109 MSFrame::fillOptions();
00110 OptionsIO::getOptions(true, argc, argv);
00111 if (oc.processMetaOptions(argc < 2)) {
00112 SystemFrame::close();
00113 return 0;
00114 }
00115
00116 initGuiShapeNames();
00117 MsgHandler::initOutputOptions();
00118 if (!MSFrame::checkOptions()) throw ProcessError();
00119 RandHelper::initRandGlobal();
00120
00121 net = load(oc);
00122 if (net!=0) {
00123 SUMOTime begin = string2time(oc.getString("begin"));
00124 SUMOTime end = string2time(oc.getString("end"));
00125
00126 WRITE_MESSAGE("Simulation started with time: " + time2string(begin));
00127
00128 ret = net->simulate(begin, end);
00129
00130 WRITE_MESSAGE("Simulation ended at time: " + time2string(net->getCurrentTimeStep()));
00131 }
00132 } catch (ProcessError &e) {
00133 if (std::string(e.what())!=std::string("Process Error") && std::string(e.what())!=std::string("")) {
00134 MsgHandler::getErrorInstance()->inform(e.what());
00135 }
00136 MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
00137 ret = 1;
00138 #ifndef _DEBUG
00139 } catch (...) {
00140 MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
00141 ret = 1;
00142 #endif
00143 }
00144 delete net;
00145 OutputDevice::closeAll();
00146 SystemFrame::close();
00147 return ret;
00148 }
00149
00150
00151
00152
00153