SUMO - Simulation of Urban MObility

duarouter_main.cpp

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