SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00011 // Main for SUMO 00012 /****************************************************************************/ 00013 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00014 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00015 /****************************************************************************/ 00016 // 00017 // This file is part of SUMO. 00018 // SUMO is free software: you can redistribute it and/or modify 00019 // it under the terms of the GNU General Public License as published by 00020 // the Free Software Foundation, either version 3 of the License, or 00021 // (at your option) any later version. 00022 // 00023 /****************************************************************************/ 00024 00025 00026 // =========================================================================== 00027 // included modules 00028 // =========================================================================== 00029 #ifdef _MSC_VER 00030 #include <windows_config.h> 00031 #else 00032 #include <config.h> 00033 #endif 00034 00035 #ifdef HAVE_VERSION_H 00036 #include <version.h> 00037 #endif 00038 00039 #include <ctime> 00040 #include <string> 00041 #include <iostream> 00042 #include <microsim/MSNet.h> 00043 #include <microsim/MSRoute.h> 00044 #include <microsim/MSVehicleControl.h> 00045 #include <netload/NLBuilder.h> 00046 #include <netload/NLHandler.h> 00047 #include <netload/NLTriggerBuilder.h> 00048 #include <netload/NLEdgeControlBuilder.h> 00049 #include <netload/NLJunctionControlBuilder.h> 00050 #include <netload/NLDetectorBuilder.h> 00051 #include <utils/options/OptionsCont.h> 00052 #include <utils/options/OptionsIO.h> 00053 #include <utils/common/MsgHandler.h> 00054 #include <utils/common/SystemFrame.h> 00055 #include <utils/common/UtilExceptions.h> 00056 #include <utils/common/FileHelpers.h> 00057 #include <utils/common/StringTokenizer.h> 00058 #include <utils/common/ToString.h> 00059 #include <utils/xml/XMLSubSys.h> 00060 #include <microsim/MSFrame.h> 00061 #include <microsim/output/MSDetectorControl.h> 00062 #include <utils/iodevices/OutputDevice.h> 00063 00064 #ifdef HAVE_MESOSIM 00065 #include <mesosim/MEVehicleControl.h> 00066 #endif 00067 00068 #ifdef CHECK_MEMORY_LEAKS 00069 #include <foreign/nvwa/debug_new.h> 00070 #endif 00071 00072 // =========================================================================== 00073 // functions 00074 // =========================================================================== 00075 /* ------------------------------------------------------------------------- 00076 * data processing methods 00077 * ----------------------------------------------------------------------- */ 00081 MSNet* 00082 load(OptionsCont& oc) { 00083 MSFrame::setMSGlobals(oc); 00084 MSVehicleControl* vc = 0; 00085 #ifdef HAVE_MESOSIM 00086 if (MSGlobals::gUseMesoSim) { 00087 vc = new MEVehicleControl(); 00088 } else { 00089 #endif 00090 vc = new MSVehicleControl(); 00091 #ifdef HAVE_MESOSIM 00092 } 00093 #endif 00094 MSNet* net = new MSNet(vc, new MSEventControl(), 00095 new MSEventControl(), new MSEventControl()); 00096 NLEdgeControlBuilder eb; 00097 NLDetectorBuilder db(*net); 00098 NLJunctionControlBuilder jb(*net, db); 00099 NLTriggerBuilder tb; 00100 NLHandler handler("", *net, db, tb, eb, jb); 00101 tb.setHandler(&handler); 00102 NLBuilder builder(oc, *net, eb, jb, db, handler); 00103 if (!builder.build()) { 00104 delete net; 00105 throw ProcessError(); 00106 } 00107 return net; 00108 } 00109 00110 00111 /* ------------------------------------------------------------------------- 00112 * main 00113 * ----------------------------------------------------------------------- */ 00114 int 00115 main(int argc, char** argv) { 00116 OptionsCont& oc = OptionsCont::getOptions(); 00117 // give some application descriptions 00118 oc.setApplicationDescription("A microscopic road traffic simulation."); 00119 oc.setApplicationName("sumo", "SUMO sumo Version " + (std::string)VERSION_STRING); 00120 int ret = 0; 00121 MSNet* net = 0; 00122 try { 00123 // initialise subsystems 00124 XMLSubSys::init(false); 00125 MSFrame::fillOptions(); 00126 OptionsIO::getOptions(true, argc, argv); 00127 if (oc.processMetaOptions(argc < 2)) { 00128 OutputDevice::closeAll(); 00129 SystemFrame::close(); 00130 return 0; 00131 } 00132 MsgHandler::initOutputOptions(); 00133 if (!MSFrame::checkOptions()) { 00134 throw ProcessError(); 00135 } 00136 RandHelper::initRandGlobal(); 00137 // load the net 00138 net = load(oc); 00139 if (net != 0) { 00140 ret = net->simulate(string2time(oc.getString("begin")), string2time(oc.getString("end"))); 00141 } 00142 } catch (ProcessError& e) { 00143 if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) { 00144 WRITE_ERROR(e.what()); 00145 } 00146 MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); 00147 ret = 1; 00148 #ifndef _DEBUG 00149 } catch (...) { 00150 MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false); 00151 ret = 1; 00152 #endif 00153 } 00154 delete net; 00155 OutputDevice::closeAll(); 00156 SystemFrame::close(); 00157 return ret; 00158 } 00159 00160 00161 00162 /****************************************************************************/ 00163