SUMO - Simulation of Urban MObility
duarouter_main.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Main for DUAROUTER
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #ifdef HAVE_VERSION_H
34 #include <version.h>
35 #endif
36 
37 #include <xercesc/sax/SAXException.hpp>
38 #include <xercesc/sax/SAXParseException.hpp>
40 #include <iostream>
41 #include <string>
42 #include <limits.h>
43 #include <ctime>
44 #include <router/ROLoader.h>
45 #include <router/RONet.h>
46 #include <router/ROEdge.h>
50 #include <utils/vehicle/CHRouter.h>
52 #include "RODUAEdgeBuilder.h"
53 #include <router/ROFrame.h>
55 #include <utils/options/Option.h>
61 #include <utils/common/ToString.h>
62 #include <utils/xml/XMLSubSys.h>
63 #include "RODUAFrame.h"
65 
66 #ifdef CHECK_MEMORY_LEAKS
67 #include <foreign/nvwa/debug_new.h>
68 #endif // CHECK_MEMORY_LEAKS
69 
70 
71 // ===========================================================================
72 // functions
73 // ===========================================================================
74 /* -------------------------------------------------------------------------
75  * data processing methods
76  * ----------------------------------------------------------------------- */
82 void
83 initNet(RONet& net, ROLoader& loader, OptionsCont& oc) {
84  // load the net
85  RODUAEdgeBuilder builder;
86  ROEdge::setGlobalOptions(oc.getBool("weights.interpolate"));
87  loader.loadNet(net, builder);
88  // load the weights when wished/available
89  if (oc.isSet("weight-files")) {
90  loader.loadWeights(net, "weight-files", oc.getString("weight-attribute"), false, oc.getBool("weights.expand"));
91  }
92  if (oc.isSet("lane-weight-files")) {
93  loader.loadWeights(net, "lane-weight-files", oc.getString("weight-attribute"), true, oc.getBool("weights.expand"));
94  }
95 }
96 
97 
98 
102 void
104  // initialise the loader
105  loader.openRoutes(net);
106  // prepare the output
107  const std::string& filename = oc.getString("output-file");
108  std::string altFilename = filename + ".alt";
109  const int len = (int)filename.length();
110  if (len > 4 && filename.substr(len - 4) == ".xml") {
111  altFilename = filename.substr(0, len - 4) + ".alt.xml";
112  } else if (len > 4 && filename.substr(len - 4) == ".sbx") {
113  altFilename = filename.substr(0, len - 4) + ".alt.sbx";
114  }
115  // build the router
117  const std::string measure = oc.getString("weight-attribute");
118  const std::string routingAlgorithm = oc.getString("routing-algorithm");
119  if (measure == "traveltime") {
120  if (routingAlgorithm == "dijkstra") {
121  if (net.hasPermissions()) {
123  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic);
124  } else {
126  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic);
127  }
128  } else if (routingAlgorithm == "astar") {
129  if (net.hasPermissions()) {
131  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic);
132  } else {
134  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic);
135  }
136  } else if (routingAlgorithm == "CH") {
137  const SUMOTime weightPeriod = (oc.isSet("weight-files") ?
138  string2time(oc.getString("weight-period")) :
140  if (net.hasPermissions()) {
142  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic, SVC_IGNORING, weightPeriod, true);
143  } else {
145  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic, SVC_IGNORING, weightPeriod, false);
146  }
147  } else if (routingAlgorithm == "CHWrapper") {
148  const SUMOTime begin = string2time(oc.getString("begin"));
149  const SUMOTime weightPeriod = (oc.isSet("weight-files") ?
150  string2time(oc.getString("weight-period")) :
152 
154  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic, begin, weightPeriod);
155  } else {
156  throw ProcessError("Unknown routing Algorithm '" + routingAlgorithm + "'!");
157  }
158  } else {
160  if (measure == "CO") {
161  op = &ROEdge::getEmissionEffort<PollutantsInterface::CO>;
162  } else if (measure == "CO2") {
163  op = &ROEdge::getEmissionEffort<PollutantsInterface::CO2>;
164  } else if (measure == "PMx") {
165  op = &ROEdge::getEmissionEffort<PollutantsInterface::PM_X>;
166  } else if (measure == "HC") {
167  op = &ROEdge::getEmissionEffort<PollutantsInterface::HC>;
168  } else if (measure == "NOx") {
169  op = &ROEdge::getEmissionEffort<PollutantsInterface::NO_X>;
170  } else if (measure == "fuel") {
171  op = &ROEdge::getEmissionEffort<PollutantsInterface::FUEL>;
172  } else if (measure == "electricity") {
173  op = &ROEdge::getEmissionEffort<PollutantsInterface::ELEC>;
174  } else if (measure == "noise") {
176  } else {
177  throw ProcessError("Unknown measure (weight attribute '" + measure + "')!");
178  }
179  if (net.hasPermissions()) {
181  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), op, &ROEdge::getTravelTimeStatic);
182  } else {
184  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), op, &ROEdge::getTravelTimeStatic);
185  }
186  }
189  // process route definitions
190  try {
191  net.openOutput(oc, altFilename);
192  loader.processRoutes(string2time(oc.getString("begin")), string2time(oc.getString("end")),
193  string2time(oc.getString("route-steps")), net, provider);
194  // end the processing
195  net.cleanup();
196  } catch (ProcessError&) {
197  net.cleanup();
198  throw;
199  }
200 }
201 
202 
203 /* -------------------------------------------------------------------------
204  * main
205  * ----------------------------------------------------------------------- */
206 int
207 main(int argc, char** argv) {
209  // give some application descriptions
210  oc.setApplicationDescription("Shortest path router and DUE computer for the microscopic road traffic simulation SUMO.");
211  oc.setApplicationName("duarouter", "SUMO duarouter Version " VERSION_STRING);
212  int ret = 0;
213  RONet* net = 0;
214  try {
215  XMLSubSys::init();
217  OptionsIO::setArgs(argc, argv);
219  if (oc.processMetaOptions(argc < 2)) {
221  return 0;
222  }
223  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
225  if (!RODUAFrame::checkOptions()) {
226  throw ProcessError();
227  }
229  // load data
230  ROLoader loader(oc, false, !oc.getBool("no-step-log"));
231  net = new RONet();
232  initNet(*net, loader, oc);
233  // build routes
234  try {
235  computeRoutes(*net, loader, oc);
236  } catch (XERCES_CPP_NAMESPACE::SAXParseException& e) {
237  WRITE_ERROR(toString(e.getLineNumber()));
238  ret = 1;
239  } catch (XERCES_CPP_NAMESPACE::SAXException& e) {
240  WRITE_ERROR(TplConvert::_2str(e.getMessage()));
241  ret = 1;
242  }
243  if (MsgHandler::getErrorInstance()->wasInformed() || ret != 0) {
244  throw ProcessError();
245  }
246  } catch (const ProcessError& e) {
247  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
248  WRITE_ERROR(e.what());
249  }
250  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
251  ret = 1;
252 #ifndef _DEBUG
253  } catch (const std::exception& e) {
254  if (std::string(e.what()) != std::string("")) {
255  WRITE_ERROR(e.what());
256  }
257  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
258  ret = 1;
259  } catch (...) {
260  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
261  ret = 1;
262 #endif
263  }
264  delete net;
266  if (ret == 0) {
267  std::cout << "Success." << std::endl;
268  }
269  return ret;
270 }
271 
272 
273 
274 /****************************************************************************/
275 
Computes the shortest path through a contracted network.
Definition: CHRouter.h:74
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:58
Computes the shortest path through a network using the Dijkstra algorithm.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
long long int SUMOTime
Definition: SUMOTime.h:43
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:72
int main(int argc, char **argv)
void openRoutes(RONet &net)
Builds and opens all route loaders.
Definition: ROLoader.cpp:165
static SUMOReal getNoiseEffort(const ROEdge *const edge, const ROVehicle *const veh, SUMOReal time)
Definition: ROEdge.cpp:183
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid for usage within duarouter...
Definition: RODUAFrame.cpp:143
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:69
void initNet(RONet &net, ROLoader &loader, OptionsCont &oc)
static void adaptIntermodalRouter(ROIntermodalRouter &router)
Definition: RONet.cpp:649
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
Computes the shortest path through a network using the A* algorithm.
Definition: AStarRouter.h:71
bool hasPermissions() const
Definition: RONet.cpp:676
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static void close()
Closes all of an applications subsystems.
Computes the shortest path through a network using the Dijkstra algorithm.
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:65
IntermodalRouter< ROEdge, ROLane, RONode, ROVehicle > ROIntermodalRouter
Definition: RORoutable.h:51
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
void openOutput(const OptionsCont &options, const std::string altFilename="")
Opens the output for computed routes.
Definition: RONet.cpp:230
static void initRandGlobal(MTRand *which=0)
Reads the given random number options and initialises the random number generator in accordance...
Definition: RandHelper.cpp:68
Interface for building instances of duarouter-edges.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
static void fillOptions()
Inserts options used by duarouter into the OptionsCont-singleton.
Definition: RODUAFrame.cpp:56
void cleanup()
closes the file output for computed routes and deletes associated threads if necessary ...
Definition: RONet.cpp:248
#define max(a, b)
Definition: polyfonts.c:65
The data loader.
Definition: ROLoader.h:63
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:46
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
void computeRoutes(RONet &net, ROLoader &loader, OptionsCont &oc)
virtual void loadNet(RONet &toFill, ROAbstractEdgeBuilder &eb)
Loads the network.
Definition: ROLoader.cpp:124
#define VERSION_STRING
Definition: config.h:225
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
The router&#39;s network representation.
Definition: RONet.h:76
static const ROEdgeVector & getAllEdges()
Returns all ROEdges.
Definition: ROEdge.cpp:282
void processRoutes(const SUMOTime start, const SUMOTime end, const SUMOTime increment, RONet &net, const RORouterProvider &provider)
Loads routes from all previously build route loaders.
Definition: ROLoader.cpp:201
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:89
A storage for options typed value containers)
Definition: OptionsCont.h:99
static void setGlobalOptions(const bool interpolate)
Definition: ROEdge.h:427
static void initOutputOptions()
Definition: MsgHandler.cpp:197
static std::string _2str(const int var)
convert int to string
Definition: TplConvert.h:57
bool loadWeights(RONet &net, const std::string &optionName, const std::string &measure, const bool useLanes, const bool boundariesOverride)
Loads the net weights.
Definition: ROLoader.cpp:268
vehicles ignoring classes
Computes the shortest path through a contracted network.
static SUMOReal getTravelTimeStatic(const ROEdge *const edge, const ROVehicle *const veh, SUMOReal time)
Returns the travel time for the given edge.
Definition: ROEdge.h:383
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.