SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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.sourceforge.net/
12 // Copyright (C) 2001-2012 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>
51 #include "RODUAEdgeBuilder.h"
52 #include <router/ROFrame.h>
54 #include <utils/options/Option.h>
60 #include <utils/common/ToString.h>
61 #include <utils/xml/XMLSubSys.h>
62 #include "RODUAFrame.h"
64 
65 #ifdef HAVE_MESOSIM // catchall for internal stuff
66 #include <internal/BulkStarRouter.h>
67 #include <internal/CHRouter.h>
68 #include <internal/CHRouterWrapper.h>
69 #endif // have HAVE_MESOSIM
70 
71 #ifdef CHECK_MEMORY_LEAKS
72 #include <foreign/nvwa/debug_new.h>
73 #endif // CHECK_MEMORY_LEAKS
74 
75 
76 // ===========================================================================
77 // functions
78 // ===========================================================================
79 /* -------------------------------------------------------------------------
80  * data processing methods
81  * ----------------------------------------------------------------------- */
87 void
88 initNet(RONet& net, ROLoader& loader, OptionsCont& oc) {
89  // load the net
90  RODUAEdgeBuilder builder(oc.getBool("weights.expand"), oc.getBool("weights.interpolate"));
91  loader.loadNet(net, builder);
92  // load the weights when wished/available
93  if (oc.isSet("weight-files")) {
94  loader.loadWeights(net, "weight-files", oc.getString("weight-attribute"), false);
95  }
96  if (oc.isSet("lane-weight-files")) {
97  loader.loadWeights(net, "lane-weight-files", oc.getString("weight-attribute"), true);
98  }
99 }
100 
101 
102 
106 void
108  // initialise the loader
109  loader.openRoutes(net);
110  // prepare the output
111  net.openOutput(oc.getString("output-file"), true, oc.getString("vtype-output"));
112  // build the router
114  const std::string measure = oc.getString("weight-attribute");
115  const std::string routingAlgorithm = oc.getString("routing-algorithm");
116  if (measure == "traveltime") {
117  if (routingAlgorithm == "dijkstra") {
118  if (net.hasRestrictions()) {
120  net.getEdgeNo(), oc.getBool("ignore-errors"), &ROEdge::getTravelTime);
121  } else {
123  net.getEdgeNo(), oc.getBool("ignore-errors"), &ROEdge::getTravelTime);
124  }
125  } else if (routingAlgorithm == "astar") {
126  if (net.hasRestrictions()) {
128  net.getEdgeNo(), oc.getBool("ignore-errors"), &ROEdge::getTravelTime);
129  } else {
131  net.getEdgeNo(), oc.getBool("ignore-errors"), &ROEdge::getTravelTime);
132  }
133 #ifdef HAVE_MESOSIM // catchall for internal stuff
134  } else if (routingAlgorithm == "bulkstar") {
135  if (net.hasRestrictions()) {
136  router = new BulkStarRouterTT<ROEdge, ROVehicle, prohibited_withRestrictions<ROEdge, ROVehicle> >(
138  } else {
139  router = new BulkStarRouterTT<ROEdge, ROVehicle, prohibited_noRestrictions<ROEdge, ROVehicle> >(
141  }
142 
143  } else if (routingAlgorithm == "CH") {
144  // defaultVehicle is only in constructor and may be safely deleted
145  // it is mainly needed for its maximum speed. @todo XXX make this configurable
147  const SUMOTime begin = string2time(oc.getString("begin"));
148  const SUMOTime weightPeriod = (oc.isSet("weight-files") ?
149  string2time(oc.getString("weight-period")) :
151  if (net.hasRestrictions()) {
152  router = new CHRouter<ROEdge, ROVehicle, prohibited_withRestrictions<ROEdge, ROVehicle> >(
153  net.getEdgeNo(), oc.getBool("ignore-errors"), &ROEdge::getTravelTime, &defaultVehicle, begin, weightPeriod, true);
154  } else {
155  router = new CHRouter<ROEdge, ROVehicle, prohibited_noRestrictions<ROEdge, ROVehicle> >(
156  net.getEdgeNo(), oc.getBool("ignore-errors"), &ROEdge::getTravelTime, &defaultVehicle, begin, weightPeriod, false);
157  }
158 
159  } else if (routingAlgorithm == "CHWrapper") {
160  const SUMOTime begin = string2time(oc.getString("begin"));
161  const SUMOTime weightPeriod = (oc.isSet("weight-files") ?
162  string2time(oc.getString("weight-period")) :
164 
165  if (!net.hasRestrictions()) {
166  WRITE_WARNING("CHWrapper is only needed for a restricted network");
167  }
168  router = new CHRouterWrapper<ROEdge, ROVehicle, prohibited_withRestrictions<ROEdge, ROVehicle> >(
169  oc.getBool("ignore-errors"), &ROEdge::getTravelTime, begin, weightPeriod);
170 
171 #endif // have HAVE_MESOSIM
172  } else {
173  throw ProcessError("Unknown routing Algorithm '" + routingAlgorithm + "'!");
174  }
175 
176  } else {
178  if (measure == "CO") {
179  op = &ROEdge::getCOEffort;
180  } else if (measure == "CO2") {
181  op = &ROEdge::getCO2Effort;
182  } else if (measure == "PMx") {
183  op = &ROEdge::getPMxEffort;
184  } else if (measure == "HC") {
185  op = &ROEdge::getHCEffort;
186  } else if (measure == "NOx") {
187  op = &ROEdge::getNOxEffort;
188  } else if (measure == "fuel") {
189  op = &ROEdge::getFuelEffort;
190  } else if (measure == "noise") {
192  } else {
193  net.closeOutput();
194  throw ProcessError("Unknown measure (weight attribute '" + measure + "')!");
195  }
196  if (net.hasRestrictions()) {
198  net.getEdgeNo(), oc.getBool("ignore-errors"), op, &ROEdge::getTravelTime);
199  } else {
201  net.getEdgeNo(), oc.getBool("ignore-errors"), op, &ROEdge::getTravelTime);
202  }
203  }
204  // process route definitions
205  try {
206  if (routingAlgorithm == "bulkstar") {
207  // need to load all routes for spatial aggregation
208  loader.processAllRoutesWithBulkRouter(string2time(oc.getString("begin")), string2time(oc.getString("end")), net, *router);
209  } else if (!oc.getBool("unsorted-input")) {
210  // the routes are sorted - process stepwise
211  loader.processRoutesStepWise(string2time(oc.getString("begin")), string2time(oc.getString("end")), net, *router);
212  } else {
213  // the routes are not sorted: load all and process
214  loader.processAllRoutes(string2time(oc.getString("begin")), string2time(oc.getString("end")), net, *router);
215  }
216  // end the processing
217  net.closeOutput();
218  delete router;
220  } catch (ProcessError&) {
221  net.closeOutput();
222  delete router;
224  throw;
225  }
226 }
227 
228 
229 /* -------------------------------------------------------------------------
230  * main
231  * ----------------------------------------------------------------------- */
232 int
233 main(int argc, char** argv) {
235  // give some application descriptions
236  oc.setApplicationDescription("Shortest path router and DUE computer for the microscopic road traffic simulation SUMO.");
237  oc.setApplicationName("duarouter", "SUMO duarouter Version " + (std::string)VERSION_STRING);
238  int ret = 0;
239  RONet* net = 0;
240  try {
241  XMLSubSys::init(false);
243  OptionsIO::getOptions(true, argc, argv);
244  if (oc.processMetaOptions(argc < 2)) {
247  return 0;
248  }
250  if (!RODUAFrame::checkOptions()) {
251  throw ProcessError();
252  }
254  // load data
255  ROLoader loader(oc, false);
256  net = new RONet();
257  initNet(*net, loader, oc);
258  // build routes
259  try {
260  computeRoutes(*net, loader, oc);
261  } catch (SAXParseException& e) {
262  WRITE_ERROR(toString(e.getLineNumber()));
263  ret = 1;
264  } catch (SAXException& e) {
265  WRITE_ERROR(TplConvert<XMLCh>::_2str(e.getMessage()));
266  ret = 1;
267  }
268  if (MsgHandler::getErrorInstance()->wasInformed() || ret != 0) {
269  throw ProcessError();
270  }
271  } catch (ProcessError& e) {
272  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
273  WRITE_ERROR(e.what());
274  }
275  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
276  ret = 1;
277 #ifndef _DEBUG
278  } catch (...) {
279  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
280  ret = 1;
281 #endif
282  }
283  delete net;
286  if (ret == 0) {
287  std::cout << "Success." << std::endl;
288  }
289  return ret;
290 }
291 
292 
293 
294 /****************************************************************************/
295