SUMO - Simulation of Urban MObility
duarouter_main.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Main for DUAROUTER
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #ifdef HAVE_VERSION_H
33 #include <version.h>
34 #endif
35 
36 #include <xercesc/sax/SAXException.hpp>
37 #include <xercesc/sax/SAXParseException.hpp>
39 #include <iostream>
40 #include <string>
41 #include <limits.h>
42 #include <ctime>
43 #include <router/ROLoader.h>
44 #include <router/RONet.h>
45 #include <router/ROEdge.h>
49 #include <utils/vehicle/CHRouter.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 
66 // ===========================================================================
67 // functions
68 // ===========================================================================
69 /* -------------------------------------------------------------------------
70  * data processing methods
71  * ----------------------------------------------------------------------- */
77 void
78 initNet(RONet& net, ROLoader& loader, OptionsCont& oc) {
79  // load the net
80  RODUAEdgeBuilder builder;
81  ROEdge::setGlobalOptions(oc.getBool("weights.interpolate"));
82  loader.loadNet(net, builder);
83  // load the weights when wished/available
84  if (oc.isSet("weight-files")) {
85  loader.loadWeights(net, "weight-files", oc.getString("weight-attribute"), false, oc.getBool("weights.expand"));
86  }
87  if (oc.isSet("lane-weight-files")) {
88  loader.loadWeights(net, "lane-weight-files", oc.getString("weight-attribute"), true, oc.getBool("weights.expand"));
89  }
90 }
91 
92 
93 
97 void
98 computeRoutes(RONet& net, ROLoader& loader, OptionsCont& oc) {
99  // initialise the loader
100  loader.openRoutes(net);
101  // build the router
103  const std::string measure = oc.getString("weight-attribute");
104  const std::string routingAlgorithm = oc.getString("routing-algorithm");
105  const SUMOTime begin = string2time(oc.getString("begin"));
106  const SUMOTime end = string2time(oc.getString("end"));
107  if (measure == "traveltime") {
108  if (routingAlgorithm == "dijkstra") {
109  if (net.hasPermissions()) {
111  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic);
112  } else {
114  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic);
115  }
116  } else if (routingAlgorithm == "astar") {
117  if (net.hasPermissions()) {
119  const AStar::LookupTable* lookup = 0;
120  if (oc.isSet("astar.all-distances")) {
121  lookup = new AStar::FLT(oc.getString("astar.all-distances"), (int)ROEdge::getAllEdges().size());
122  } else if (oc.isSet("astar.landmark-distances")) {
125  begin, end, std::numeric_limits<int>::max(), 1);
126  ROVehicle defaultVehicle(SUMOVehicleParameter(), 0, net.getVehicleTypeSecure(DEFAULT_VTYPE_ID), &net);
127  lookup = new AStar::LMLT(oc.getString("astar.landmark-distances"), ROEdge::getAllEdges(), &router, &defaultVehicle,
128  oc.isSet("astar.save-landmark-distances") ? oc.getString("astar.save-landmark-distances") : "", oc.getInt("routing-threads"));
129  }
130  router = new AStar(ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic, lookup);
131  } else {
133  const AStar::LookupTable* lookup = 0;
134  if (oc.isSet("astar.all-distances")) {
135  lookup = new AStar::FLT(oc.getString("astar.all-distances"), (int)ROEdge::getAllEdges().size());
136  } else if (oc.isSet("astar.landmark-distances")) {
139  begin, end, std::numeric_limits<int>::max(), 1);
140  ROVehicle defaultVehicle(SUMOVehicleParameter(), 0, net.getVehicleTypeSecure(DEFAULT_VTYPE_ID), &net);
141  lookup = new AStar::LMLT(oc.getString("astar.landmark-distances"), ROEdge::getAllEdges(), &router, &defaultVehicle,
142  oc.isSet("astar.save-landmark-distances") ? oc.getString("astar.save-landmark-distances") : "", oc.getInt("routing-threads"));
143  }
144  router = new AStar(ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic, lookup);
145  }
146  } else if (routingAlgorithm == "CH") {
147  const SUMOTime weightPeriod = (oc.isSet("weight-files") ?
148  string2time(oc.getString("weight-period")) :
149  std::numeric_limits<int>::max());
150  if (net.hasPermissions()) {
152  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic, SVC_IGNORING, weightPeriod, true);
153  } else {
155  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic, SVC_IGNORING, weightPeriod, false);
156  }
157  } else if (routingAlgorithm == "CHWrapper") {
158  const SUMOTime weightPeriod = (oc.isSet("weight-files") ?
159  string2time(oc.getString("weight-period")) :
160  std::numeric_limits<int>::max());
163  begin, end, weightPeriod, oc.getInt("routing-threads"));
164  } else {
165  throw ProcessError("Unknown routing Algorithm '" + routingAlgorithm + "'!");
166  }
167  } else {
169  if (measure == "CO") {
170  op = &ROEdge::getEmissionEffort<PollutantsInterface::CO>;
171  } else if (measure == "CO2") {
172  op = &ROEdge::getEmissionEffort<PollutantsInterface::CO2>;
173  } else if (measure == "PMx") {
174  op = &ROEdge::getEmissionEffort<PollutantsInterface::PM_X>;
175  } else if (measure == "HC") {
176  op = &ROEdge::getEmissionEffort<PollutantsInterface::HC>;
177  } else if (measure == "NOx") {
178  op = &ROEdge::getEmissionEffort<PollutantsInterface::NO_X>;
179  } else if (measure == "fuel") {
180  op = &ROEdge::getEmissionEffort<PollutantsInterface::FUEL>;
181  } else if (measure == "electricity") {
182  op = &ROEdge::getEmissionEffort<PollutantsInterface::ELEC>;
183  } else if (measure == "noise") {
185  } else {
186  throw ProcessError("Unknown measure (weight attribute '" + measure + "')!");
187  }
188  if (net.hasPermissions()) {
190  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), op, &ROEdge::getTravelTimeStatic);
191  } else {
193  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), op, &ROEdge::getTravelTimeStatic);
194  }
195  }
196  int carWalk = 0;
197  for (const std::string& opt : oc.getStringVector("persontrip.transfer.car-walk")) {
198  if (opt == "parkingAreas") {
200  } else if (opt == "ptStops") {
201  carWalk |= ROIntermodalRouter::PT_STOPS;
202  } else if (opt == "allJunctions") {
204  }
205  }
208  // process route definitions
209  try {
210  net.openOutput(oc);
211  loader.processRoutes(begin, end, string2time(oc.getString("route-steps")), net, provider);
212  net.writeIntermodal(oc, provider.getIntermodalRouter());
213  // end the processing
214  net.cleanup();
215  } catch (ProcessError&) {
216  net.cleanup();
217  throw;
218  }
219 }
220 
221 
222 /* -------------------------------------------------------------------------
223  * main
224  * ----------------------------------------------------------------------- */
225 int
226 main(int argc, char** argv) {
228  // give some application descriptions
229  oc.setApplicationDescription("Shortest path router and DUE computer for the microscopic road traffic simulation SUMO.");
230  oc.setApplicationName("duarouter", "SUMO duarouter Version " VERSION_STRING);
231  int ret = 0;
232  RONet* net = 0;
233  try {
234  XMLSubSys::init();
236  OptionsIO::setArgs(argc, argv);
238  if (oc.processMetaOptions(argc < 2)) {
240  return 0;
241  }
242  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
244  if (!RODUAFrame::checkOptions()) {
245  throw ProcessError();
246  }
248  // load data
249  ROLoader loader(oc, false, !oc.getBool("no-step-log"));
250  net = new RONet();
251  initNet(*net, loader, oc);
252  // build routes
253  try {
254  computeRoutes(*net, loader, oc);
255  } catch (XERCES_CPP_NAMESPACE::SAXParseException& e) {
256  WRITE_ERROR(toString(e.getLineNumber()));
257  ret = 1;
258  } catch (XERCES_CPP_NAMESPACE::SAXException& e) {
259  WRITE_ERROR(TplConvert::_2str(e.getMessage()));
260  ret = 1;
261  }
262  if (MsgHandler::getErrorInstance()->wasInformed() || ret != 0) {
263  throw ProcessError();
264  }
265  } catch (const ProcessError& e) {
266  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
267  WRITE_ERROR(e.what());
268  }
269  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
270  ret = 1;
271 #ifndef _DEBUG
272  } catch (const std::exception& e) {
273  if (std::string(e.what()) != std::string("")) {
274  WRITE_ERROR(e.what());
275  }
276  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
277  ret = 1;
278  } catch (...) {
279  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
280  ret = 1;
281 #endif
282  }
283  delete net;
285  if (ret == 0) {
286  std::cout << "Success." << std::endl;
287  }
288  return ret;
289 }
290 
291 
292 
293 /****************************************************************************/
294 
Computes the shortest path through a contracted network.
Definition: CHRouter.h:69
IntermodalRouter< E, L, N, V > & getIntermodalRouter() const
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:53
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:75
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:82
int main(int argc, char **argv)
void writeIntermodal(const OptionsCont &options, ROIntermodalRouter &router) const
Writes the intermodal network and weights if requested.
Definition: RONet.cpp:234
void openRoutes(RONet &net)
Builds and opens all route loaders.
Definition: ROLoader.cpp:160
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid for usage within duarouter...
Definition: RODUAFrame.cpp:178
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:64
void initNet(RONet &net, ROLoader &loader, OptionsCont &oc)
static void adaptIntermodalRouter(ROIntermodalRouter &router)
Definition: RONet.cpp:657
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
Computes the shortest path through a network using the A* algorithm.
Definition: AStarRouter.h:84
bool hasPermissions() const
Definition: RONet.cpp:688
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const std::string DEFAULT_VTYPE_ID
static void close()
Closes all of an applications subsystems.
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:61
IntermodalRouter< ROEdge, ROLane, RONode, ROVehicle > ROIntermodalRouter
Definition: RORoutable.h:50
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
Interface for building instances of duarouter-edges.
void openOutput(const OptionsCont &options)
Opens the output for computed routes.
Definition: RONet.cpp:214
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
A vehicle as used by router.
Definition: ROVehicle.h:59
static void fillOptions()
Inserts options used by duarouter into the OptionsCont-singleton.
Definition: RODUAFrame.cpp:51
void cleanup()
closes the file output for computed routes and deletes associated threads if necessary ...
Definition: RONet.cpp:253
static double getTravelTimeStatic(const ROEdge *const edge, const ROVehicle *const veh, double time)
Returns the travel time for the given edge.
Definition: ROEdge.h:404
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
Computes the shortest path through a network using the Dijkstra algorithm.
The data loader.
Definition: ROLoader.h:62
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::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
void computeRoutes(RONet &net, ROLoader &loader, OptionsCont &oc)
public transport stops and access
virtual void loadNet(RONet &toFill, ROAbstractEdgeBuilder &eb)
Loads the network.
Definition: ROLoader.cpp:119
#define VERSION_STRING
Definition: config.h:210
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
The router&#39;s network representation.
Definition: RONet.h:74
Structure representing possible vehicle parameter.
static const ROEdgeVector & getAllEdges()
Returns all ROEdges.
Definition: ROEdge.cpp:319
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:190
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:84
A storage for options typed value containers)
Definition: OptionsCont.h:98
static void initRandGlobal(std::mt19937 *which=0)
Reads the given random number options and initialises the random number generator in accordance...
Definition: RandHelper.cpp:76
static double getNoiseEffort(const ROEdge *const edge, const ROVehicle *const veh, double time)
Definition: ROEdge.cpp:198
static void setGlobalOptions(const bool interpolate)
Definition: ROEdge.h:454
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:277
long long int SUMOTime
Definition: TraCIDefs.h:51
static void initOutputOptions()
Definition: MsgHandler.cpp:192
static std::string _2str(const int var)
convert int to string
Definition: TplConvert.h:56
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:251
junctions with edges allowing the additional mode
vehicles ignoring classes
Computes the shortest path through a contracted network.
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.