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 <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
00067
00068
00069
00070
00076 void
00077 initNet(RONet &net, ROLoader &loader, OptionsCont &oc) {
00078
00079 RODUAEdgeBuilder builder(oc.getBool("expand-weights"), oc.getBool("interpolate"));
00080 loader.loadNet(net, builder);
00081
00082 if (oc.isSet("weights")) {
00083 loader.loadWeights(net, "weights", oc.getString("measure"), false);
00084 }
00085 if (oc.isSet("lane-weights")) {
00086 loader.loadWeights(net, "lane-weights", oc.getString("measure"), true);
00087 }
00088 }
00089
00090
00091
00095 void
00096 computeRoutes(RONet &net, ROLoader &loader, OptionsCont &oc) {
00097
00098 loader.openRoutes(net);
00099
00100 try {
00101 net.openOutput(oc.getString("output"), true);
00102 } catch (IOError &e) {
00103 throw e;
00104 }
00105
00106 SUMOAbstractRouter<ROEdge, ROVehicle> *router;
00107 std::string measure = oc.getString("measure");
00108 if (measure=="traveltime") {
00109 if (net.hasRestrictions()) {
00110 router = new DijkstraRouterTT_Direct<ROEdge, ROVehicle, prohibited_withRestrictions<ROEdge, ROVehicle> >(
00111 net.getEdgeNo(), oc.getBool("continue-on-unbuild"), &ROEdge::getTravelTime);
00112 } else {
00113 router = new DijkstraRouterTT_Direct<ROEdge, ROVehicle, prohibited_noRestrictions<ROEdge, ROVehicle> >(
00114 net.getEdgeNo(), oc.getBool("continue-on-unbuild"), &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("continue-on-unbuild"), op, &ROEdge::getTravelTime);
00136 } else {
00137 router = new DijkstraRouterEffort_Direct<ROEdge, ROVehicle, prohibited_noRestrictions<ROEdge, ROVehicle> >(
00138 net.getEdgeNo(), oc.getBool("continue-on-unbuild"), op, &ROEdge::getTravelTime);
00139 }
00140 }
00141
00142 try {
00143
00144 if (!oc.getBool("unsorted")) {
00145 loader.processRoutesStepWise(string2time(oc.getString("begin")), string2time(oc.getString("end")), net, *router);
00146 }
00147
00148 else {
00149 loader.processAllRoutes(string2time(oc.getString("begin")), string2time(oc.getString("end")), net, *router);
00150 }
00151
00152 net.closeOutput();
00153 delete router;
00154 } catch (ProcessError &) {
00155 net.closeOutput();
00156 delete router;
00157 throw;
00158 }
00159 }
00160
00161
00162
00163
00164
00165 int
00166 main(int argc, char **argv) {
00167 OptionsCont &oc = OptionsCont::getOptions();
00168
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()) throw ProcessError();
00183 RandHelper::initRandGlobal();
00184
00185 ROLoader loader(oc, false);
00186 net = new RONet();
00187 initNet(*net, loader, oc);
00188
00189 try {
00190 computeRoutes(*net, loader, oc);
00191 } catch (SAXParseException &e) {
00192 MsgHandler::getErrorInstance()->inform(toString(e.getLineNumber()));
00193 ret = 1;
00194 } catch (SAXException &e) {
00195 MsgHandler::getErrorInstance()->inform(TplConvert<XMLCh>::_2str(e.getMessage()));
00196 ret = 1;
00197 }
00198 if (MsgHandler::getErrorInstance()->wasInformed()||ret!=0) {
00199 throw ProcessError();
00200 }
00201 } catch (ProcessError &e) {
00202 if (std::string(e.what())!=std::string("Process Error") && std::string(e.what())!=std::string("")) {
00203 MsgHandler::getErrorInstance()->inform(e.what());
00204 }
00205 MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
00206 ret = 1;
00207 #ifndef _DEBUG
00208 } catch (...) {
00209 MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
00210 ret = 1;
00211 #endif
00212 }
00213 delete net;
00214 OutputDevice::closeAll();
00215 SystemFrame::close();
00216 if (ret==0) {
00217 std::cout << "Success." << std::endl;
00218 }
00219 return ret;
00220 }
00221
00222
00223
00224
00225