|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Main for DUAROUTER 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 00020 00021 // =========================================================================== 00022 // included modules 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 <xercesc/sax/SAXException.hpp> 00035 #include <xercesc/sax/SAXParseException.hpp> 00036 #include <utils/common/TplConvert.h> 00037 #include <iostream> 00038 #include <string> 00039 #include <limits.h> 00040 #include <ctime> 00041 #include <router/ROLoader.h> 00042 #include <router/RONet.h> 00043 #include <router/ROEdge.h> 00044 #include <utils/common/DijkstraRouterTT.h> 00045 #include <utils/common/DijkstraRouterEffort.h> 00046 #include "RODUAEdgeBuilder.h" 00047 #include <router/ROFrame.h> 00048 #include <utils/common/MsgHandler.h> 00049 #include <utils/options/Option.h> 00050 #include <utils/options/OptionsCont.h> 00051 #include <utils/options/OptionsIO.h> 00052 #include <utils/common/UtilExceptions.h> 00053 #include <utils/common/SystemFrame.h> 00054 #include <utils/common/RandHelper.h> 00055 #include <utils/common/ToString.h> 00056 #include <utils/xml/XMLSubSys.h> 00057 #include "RODUAFrame.h" 00058 #include <utils/iodevices/OutputDevice.h> 00059 00060 #ifdef CHECK_MEMORY_LEAKS 00061 #include <foreign/nvwa/debug_new.h> 00062 #endif // CHECK_MEMORY_LEAKS 00063 00064 00065 // =========================================================================== 00066 // functions 00067 // =========================================================================== 00068 /* ------------------------------------------------------------------------- 00069 * data processing methods 00070 * ----------------------------------------------------------------------- */ 00076 void 00077 initNet(RONet& net, ROLoader& loader, OptionsCont& oc) { 00078 // load the net 00079 RODUAEdgeBuilder builder(oc.getBool("weights.expand"), oc.getBool("weights.interpolate")); 00080 loader.loadNet(net, builder); 00081 // load the weights when wished/available 00082 if (oc.isSet("weight-files")) { 00083 loader.loadWeights(net, "weight-files", oc.getString("weight-attribute"), false); 00084 } 00085 if (oc.isSet("lane-weight-files")) { 00086 loader.loadWeights(net, "lane-weight-files", oc.getString("weight-attribute"), true); 00087 } 00088 } 00089 00090 00091 00095 void 00096 computeRoutes(RONet& net, ROLoader& loader, OptionsCont& oc) { 00097 // initialise the loader 00098 loader.openRoutes(net); 00099 // prepare the output 00100 try { 00101 net.openOutput(oc.getString("output-file"), true); 00102 } catch (IOError& e) { 00103 throw e; 00104 } 00105 // build the router 00106 SUMOAbstractRouter<ROEdge, ROVehicle> *router; 00107 std::string measure = oc.getString("weight-attribute"); 00108 if (measure=="traveltime") { 00109 if (net.hasRestrictions()) { 00110 router = new DijkstraRouterTT_Direct<ROEdge, ROVehicle, prohibited_withRestrictions<ROEdge, ROVehicle> >( 00111 net.getEdgeNo(), oc.getBool("ignore-errors"), &ROEdge::getTravelTime); 00112 } else { 00113 router = new DijkstraRouterTT_Direct<ROEdge, ROVehicle, prohibited_noRestrictions<ROEdge, ROVehicle> >( 00114 net.getEdgeNo(), oc.getBool("ignore-errors"), &ROEdge::getTravelTime); 00115 } 00116 } else { 00117 DijkstraRouterEffort_Direct<ROEdge, ROVehicle, prohibited_withRestrictions<ROEdge, ROVehicle> >::Operation op; 00118 if (measure=="CO") { 00119 op = &ROEdge::getCOEffort; 00120 } else if (measure=="CO2") { 00121 op = &ROEdge::getCO2Effort; 00122 } else if (measure=="PMx") { 00123 op = &ROEdge::getPMxEffort; 00124 } else if (measure=="HC") { 00125 op = &ROEdge::getHCEffort; 00126 } else if (measure=="NOx") { 00127 op = &ROEdge::getNOxEffort; 00128 } else if (measure=="fuel") { 00129 op = &ROEdge::getFuelEffort; 00130 } else if (measure=="noise") { 00131 op = &ROEdge::getNoiseEffort; 00132 } 00133 if (net.hasRestrictions()) { 00134 router = new DijkstraRouterEffort_Direct<ROEdge, ROVehicle, prohibited_withRestrictions<ROEdge, ROVehicle> >( 00135 net.getEdgeNo(), oc.getBool("ignore-errors"), op, &ROEdge::getTravelTime); 00136 } else { 00137 router = new DijkstraRouterEffort_Direct<ROEdge, ROVehicle, prohibited_noRestrictions<ROEdge, ROVehicle> >( 00138 net.getEdgeNo(), oc.getBool("ignore-errors"), op, &ROEdge::getTravelTime); 00139 } 00140 } 00141 // process route definitions 00142 try { 00143 // the routes are sorted - process stepwise 00144 if (!oc.getBool("unsorted-input")) { 00145 loader.processRoutesStepWise(string2time(oc.getString("begin")), string2time(oc.getString("end")), net, *router); 00146 } 00147 // the routes are not sorted: load all and process 00148 else { 00149 loader.processAllRoutes(string2time(oc.getString("begin")), string2time(oc.getString("end")), net, *router); 00150 } 00151 // end the processing 00152 net.closeOutput(); 00153 delete router; 00154 } catch (ProcessError&) { 00155 net.closeOutput(); 00156 delete router; 00157 throw; 00158 } 00159 } 00160 00161 00162 /* ------------------------------------------------------------------------- 00163 * main 00164 * ----------------------------------------------------------------------- */ 00165 int 00166 main(int argc, char** argv) { 00167 OptionsCont& oc = OptionsCont::getOptions(); 00168 // give some application descriptions 00169 oc.setApplicationDescription("Shortest path router and DUE computer for the microscopic road traffic simulation SUMO."); 00170 oc.setApplicationName("duarouter", "SUMO duarouter Version " + (std::string)VERSION_STRING); 00171 int ret = 0; 00172 RONet* net = 0; 00173 try { 00174 XMLSubSys::init(false); 00175 RODUAFrame::fillOptions(); 00176 OptionsIO::getOptions(true, argc, argv); 00177 if (oc.processMetaOptions(argc < 2)) { 00178 SystemFrame::close(); 00179 return 0; 00180 } 00181 MsgHandler::initOutputOptions(); 00182 if (!RODUAFrame::checkOptions()) { 00183 throw ProcessError(); 00184 } 00185 RandHelper::initRandGlobal(); 00186 // load data 00187 ROLoader loader(oc, false); 00188 net = new RONet(); 00189 initNet(*net, loader, oc); 00190 // build routes 00191 try { 00192 computeRoutes(*net, loader, oc); 00193 } catch (SAXParseException& e) { 00194 WRITE_ERROR(toString(e.getLineNumber())); 00195 ret = 1; 00196 } catch (SAXException& e) { 00197 WRITE_ERROR(TplConvert<XMLCh>::_2str(e.getMessage())); 00198 ret = 1; 00199 } 00200 if (MsgHandler::getErrorInstance()->wasInformed()||ret!=0) { 00201 throw ProcessError(); 00202 } 00203 } catch (ProcessError& e) { 00204 if (std::string(e.what())!=std::string("Process Error") && std::string(e.what())!=std::string("")) { 00205 WRITE_ERROR(e.what()); 00206 } 00207 MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); 00208 ret = 1; 00209 #ifndef _DEBUG 00210 } catch (...) { 00211 MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false); 00212 ret = 1; 00213 #endif 00214 } 00215 delete net; 00216 OutputDevice::closeAll(); 00217 SystemFrame::close(); 00218 if (ret==0) { 00219 std::cout << "Success." << std::endl; 00220 } 00221 return ret; 00222 } 00223 00224 00225 00226 /****************************************************************************/ 00227