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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Main for DUAROUTER
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #ifdef HAVE_VERSION_H
27 #include <version.h>
28 #endif
29 
30 #include <iostream>
31 #include <string>
32 #include <limits.h>
33 #include <ctime>
34 #include <xercesc/sax/SAXException.hpp>
35 #include <xercesc/sax/SAXParseException.hpp>
41 #include <utils/common/ToString.h>
43 #include <utils/options/Option.h>
49 #include <utils/vehicle/CHRouter.h>
51 #include <utils/xml/XMLSubSys.h>
52 #include <router/ROFrame.h>
53 #include <router/ROLoader.h>
54 #include <router/RONet.h>
55 #include <router/ROEdge.h>
56 #include "RODUAEdgeBuilder.h"
57 #include "RODUAFrame.h"
58 
59 
60 // ===========================================================================
61 // functions
62 // ===========================================================================
63 /* -------------------------------------------------------------------------
64  * data processing methods
65  * ----------------------------------------------------------------------- */
71 void
72 initNet(RONet& net, ROLoader& loader, OptionsCont& oc) {
73  // load the net
74  RODUAEdgeBuilder builder;
75  ROEdge::setGlobalOptions(oc.getBool("weights.interpolate"));
76  loader.loadNet(net, builder);
77  // load the weights when wished/available
78  if (oc.isSet("weight-files")) {
79  loader.loadWeights(net, "weight-files", oc.getString("weight-attribute"), false, oc.getBool("weights.expand"));
80  }
81  if (oc.isSet("lane-weight-files")) {
82  loader.loadWeights(net, "lane-weight-files", oc.getString("weight-attribute"), true, oc.getBool("weights.expand"));
83  }
84 }
85 
86 
87 
91 void
92 computeRoutes(RONet& net, ROLoader& loader, OptionsCont& oc) {
93  // initialise the loader
94  loader.openRoutes(net);
95  // build the router
97  const std::string measure = oc.getString("weight-attribute");
98  const std::string routingAlgorithm = oc.getString("routing-algorithm");
99  const SUMOTime begin = string2time(oc.getString("begin"));
100  const SUMOTime end = string2time(oc.getString("end"));
101  if (measure == "traveltime") {
102  if (routingAlgorithm == "dijkstra") {
103  if (net.hasPermissions()) {
105  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic);
106  } else {
108  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic);
109  }
110  } else if (routingAlgorithm == "astar") {
111  if (net.hasPermissions()) {
113  const AStar::LookupTable* lookup = 0;
114  if (oc.isSet("astar.all-distances")) {
115  lookup = new AStar::FLT(oc.getString("astar.all-distances"), (int)ROEdge::getAllEdges().size());
116  } else if (oc.isSet("astar.landmark-distances")) {
119  begin, end, std::numeric_limits<int>::max(), 1);
120  ROVehicle defaultVehicle(SUMOVehicleParameter(), 0, net.getVehicleTypeSecure(DEFAULT_VTYPE_ID), &net);
121  lookup = new AStar::LMLT(oc.getString("astar.landmark-distances"), ROEdge::getAllEdges(), &router, &defaultVehicle,
122  oc.isSet("astar.save-landmark-distances") ? oc.getString("astar.save-landmark-distances") : "", oc.getInt("routing-threads"));
123  }
124  router = new AStar(ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic, lookup);
125  } else {
127  const AStar::LookupTable* lookup = 0;
128  if (oc.isSet("astar.all-distances")) {
129  lookup = new AStar::FLT(oc.getString("astar.all-distances"), (int)ROEdge::getAllEdges().size());
130  } else if (oc.isSet("astar.landmark-distances")) {
133  begin, end, std::numeric_limits<int>::max(), 1);
134  ROVehicle defaultVehicle(SUMOVehicleParameter(), 0, net.getVehicleTypeSecure(DEFAULT_VTYPE_ID), &net);
135  lookup = new AStar::LMLT(oc.getString("astar.landmark-distances"), ROEdge::getAllEdges(), &router, &defaultVehicle,
136  oc.isSet("astar.save-landmark-distances") ? oc.getString("astar.save-landmark-distances") : "", oc.getInt("routing-threads"));
137  }
138  router = new AStar(ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic, lookup);
139  }
140  } else if (routingAlgorithm == "CH") {
141  const SUMOTime weightPeriod = (oc.isSet("weight-files") ?
142  string2time(oc.getString("weight-period")) :
143  std::numeric_limits<int>::max());
144  if (net.hasPermissions()) {
146  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic, SVC_IGNORING, weightPeriod, true);
147  } else {
149  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic, SVC_IGNORING, weightPeriod, false);
150  }
151  } else if (routingAlgorithm == "CHWrapper") {
152  const SUMOTime weightPeriod = (oc.isSet("weight-files") ?
153  string2time(oc.getString("weight-period")) :
154  std::numeric_limits<int>::max());
157  begin, end, weightPeriod, oc.getInt("routing-threads"));
158  } else {
159  throw ProcessError("Unknown routing Algorithm '" + routingAlgorithm + "'!");
160  }
161  } else {
163  if (measure == "CO") {
164  op = &ROEdge::getEmissionEffort<PollutantsInterface::CO>;
165  } else if (measure == "CO2") {
166  op = &ROEdge::getEmissionEffort<PollutantsInterface::CO2>;
167  } else if (measure == "PMx") {
168  op = &ROEdge::getEmissionEffort<PollutantsInterface::PM_X>;
169  } else if (measure == "HC") {
170  op = &ROEdge::getEmissionEffort<PollutantsInterface::HC>;
171  } else if (measure == "NOx") {
172  op = &ROEdge::getEmissionEffort<PollutantsInterface::NO_X>;
173  } else if (measure == "fuel") {
174  op = &ROEdge::getEmissionEffort<PollutantsInterface::FUEL>;
175  } else if (measure == "electricity") {
176  op = &ROEdge::getEmissionEffort<PollutantsInterface::ELEC>;
177  } else if (measure == "noise") {
179  } else {
180  throw ProcessError("Unknown measure (weight attribute '" + measure + "')!");
181  }
182  if (net.hasPermissions()) {
184  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), op, &ROEdge::getTravelTimeStatic);
185  } else {
187  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), op, &ROEdge::getTravelTimeStatic);
188  }
189  }
190  int carWalk = 0;
191  for (const std::string& opt : oc.getStringVector("persontrip.transfer.car-walk")) {
192  if (opt == "parkingAreas") {
194  } else if (opt == "ptStops") {
196  } else if (opt == "allJunctions") {
198  }
199  }
201  new ROIntermodalRouter(RONet::adaptIntermodalRouter, carWalk, routingAlgorithm));
202  // process route definitions
203  try {
204  net.openOutput(oc);
205  loader.processRoutes(begin, end, string2time(oc.getString("route-steps")), net, provider);
206  net.writeIntermodal(oc, provider.getIntermodalRouter());
207  // end the processing
208  net.cleanup();
209  } catch (ProcessError&) {
210  net.cleanup();
211  throw;
212  }
213 }
214 
215 
216 /* -------------------------------------------------------------------------
217  * main
218  * ----------------------------------------------------------------------- */
219 int
220 main(int argc, char** argv) {
222  // give some application descriptions
223  oc.setApplicationDescription("Shortest path router and DUE computer for the microscopic, multi-modal traffic simulation SUMO.");
224  oc.setApplicationName("duarouter", "Eclipse SUMO duarouter Version " VERSION_STRING);
225  int ret = 0;
226  RONet* net = 0;
227  try {
228  XMLSubSys::init();
230  OptionsIO::setArgs(argc, argv);
232  if (oc.processMetaOptions(argc < 2)) {
234  return 0;
235  }
236  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
239  throw ProcessError();
240  }
242  // load data
243  ROLoader loader(oc, false, !oc.getBool("no-step-log"));
244  net = new RONet();
245  initNet(*net, loader, oc);
246  // build routes
247  try {
248  computeRoutes(*net, loader, oc);
249  } catch (XERCES_CPP_NAMESPACE::SAXParseException& e) {
250  WRITE_ERROR(toString(e.getLineNumber()));
251  ret = 1;
252  } catch (XERCES_CPP_NAMESPACE::SAXException& e) {
253  WRITE_ERROR(TplConvert::_2str(e.getMessage()));
254  ret = 1;
255  }
256  if (MsgHandler::getErrorInstance()->wasInformed() || ret != 0) {
257  throw ProcessError();
258  }
259  } catch (const ProcessError& e) {
260  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
261  WRITE_ERROR(e.what());
262  }
263  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
264  ret = 1;
265 #ifndef _DEBUG
266  } catch (const std::exception& e) {
267  if (std::string(e.what()) != std::string("")) {
268  WRITE_ERROR(e.what());
269  }
270  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
271  ret = 1;
272  } catch (...) {
273  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
274  ret = 1;
275 #endif
276  }
277  delete net;
279  if (ret == 0) {
280  std::cout << "Success." << std::endl;
281  }
282  return ret;
283 }
284 
285 
286 
287 /****************************************************************************/
288 
Computes the shortest path through a contracted network.
Definition: CHRouter.h:63
IntermodalRouter< E, L, N, V > & getIntermodalRouter() const
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:48
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:76
public transport stops and access
long long int SUMOTime
Definition: SUMOTime.h:36
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:76
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:154
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid for usage within duarouter...
Definition: RODUAFrame.cpp:172
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:59
void initNet(RONet &net, ROLoader &loader, OptionsCont &oc)
static void adaptIntermodalRouter(ROIntermodalRouter &router)
Definition: RONet.cpp:659
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
Computes the shortest path through a network using the A* algorithm.
Definition: AStarRouter.h:77
bool hasPermissions() const
Definition: RONet.cpp:691
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:55
IntermodalRouter< ROEdge, ROLane, RONode, ROVehicle > ROIntermodalRouter
Definition: RORoutable.h:44
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
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:53
static void fillOptions()
Inserts options used by duarouter into the OptionsCont-singleton.
Definition: RODUAFrame.cpp:45
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:398
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
Computes the shortest path through a network using the Dijkstra algorithm.
The data loader.
Definition: ROLoader.h:56
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:42
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) ...
static bool checkOptions()
checks shared options and sets StdDefs
#define VERSION_STRING
Definition: version.h:1
void computeRoutes(RONet &net, ROLoader &loader, OptionsCont &oc)
virtual void loadNet(RONet &toFill, ROAbstractEdgeBuilder &eb)
Loads the network.
Definition: ROLoader.cpp:113
junctions with edges allowing the additional mode
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:248
The router&#39;s network representation.
Definition: RONet.h:68
Structure representing possible vehicle parameter.
static const ROEdgeVector & getAllEdges()
Returns all ROEdges.
Definition: ROEdge.cpp:314
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:184
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:113
A storage for options typed value containers)
Definition: OptionsCont.h:92
static void initRandGlobal(std::mt19937 *which=0)
Reads the given random number options and initialises the random number generator in accordance...
Definition: RandHelper.cpp:72
static double getNoiseEffort(const ROEdge *const edge, const ROVehicle *const veh, double time)
Definition: ROEdge.cpp:193
static void setGlobalOptions(const bool interpolate)
Definition: ROEdge.h:448
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:277
static void initOutputOptions()
init output options
Definition: MsgHandler.cpp:239
static std::string _2str(const int var)
convert int to string
Definition: TplConvert.h:50
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:245
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.