Eclipse 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-2019 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 /****************************************************************************/
16 // Main for DUAROUTER
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #ifdef HAVE_VERSION_H
26 #include <version.h>
27 #endif
28 
29 #include <iostream>
30 #include <string>
31 #include <limits.h>
32 #include <ctime>
33 #include <memory>
34 #include <xercesc/sax/SAXException.hpp>
35 #include <xercesc/sax/SAXParseException.hpp>
41 #include <utils/common/ToString.h>
43 #include <utils/options/Option.h>
48 #include <utils/router/CHRouter.h>
50 #include <utils/xml/XMLSubSys.h>
51 #include <router/ROFrame.h>
52 #include <router/ROLoader.h>
53 #include <router/RONet.h>
54 #include <router/ROEdge.h>
55 #include "RODUAEdgeBuilder.h"
56 #include "RODUAFrame.h"
57 
58 
59 // ===========================================================================
60 // functions
61 // ===========================================================================
62 /* -------------------------------------------------------------------------
63  * data processing methods
64  * ----------------------------------------------------------------------- */
70 void
71 initNet(RONet& net, ROLoader& loader, OptionsCont& oc) {
72  // load the net
73  RODUAEdgeBuilder builder;
74  ROEdge::setGlobalOptions(oc.getBool("weights.interpolate"));
75  loader.loadNet(net, builder);
76  // load the weights when wished/available
77  if (oc.isSet("weight-files")) {
78  loader.loadWeights(net, "weight-files", oc.getString("weight-attribute"), false, oc.getBool("weights.expand"));
79  }
80  if (oc.isSet("lane-weight-files")) {
81  loader.loadWeights(net, "lane-weight-files", oc.getString("weight-attribute"), true, oc.getBool("weights.expand"));
82  }
83 }
84 
85 
86 
90 void
91 computeRoutes(RONet& net, ROLoader& loader, OptionsCont& oc) {
92  // initialise the loader
93  loader.openRoutes(net);
94  // 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  router = new DijkstraRouter<ROEdge, ROVehicle>(ROEdge::getAllEdges(), oc.getBool("ignore-errors"), ttFunction, nullptr, false, nullptr, net.hasPermissions(), oc.isSet("restriction-params"));
104  } else if (routingAlgorithm == "astar") {
105  typedef AStarRouter<ROEdge, ROVehicle> AStar;
106  std::shared_ptr<const AStar::LookupTable> lookup;
107  if (oc.isSet("astar.all-distances")) {
108  lookup = std::make_shared<const AStar::FLT>(oc.getString("astar.all-distances"), (int)ROEdge::getAllEdges().size());
109  } else if (oc.isSet("astar.landmark-distances")) {
112  begin, end, std::numeric_limits<int>::max(), 1);
113  ROVehicle defaultVehicle(SUMOVehicleParameter(), nullptr, net.getVehicleTypeSecure(DEFAULT_VTYPE_ID), &net);
114  lookup = std::make_shared<const AStar::LMLT>(oc.getString("astar.landmark-distances"), ROEdge::getAllEdges(), &chrouter, &defaultVehicle,
115  oc.isSet("astar.save-landmark-distances") ? oc.getString("astar.save-landmark-distances") : "", oc.getInt("routing-threads"));
116  }
117  router = new AStar(ROEdge::getAllEdges(), oc.getBool("ignore-errors"), ttFunction, lookup, net.hasPermissions(), oc.isSet("restriction-params"));
118  } else if (routingAlgorithm == "CH") {
119  const SUMOTime weightPeriod = (oc.isSet("weight-files") ?
120  string2time(oc.getString("weight-period")) :
121  std::numeric_limits<int>::max());
122  router = new CHRouter<ROEdge, ROVehicle>(
123  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic, SVC_IGNORING, weightPeriod, net.hasPermissions(), oc.isSet("restriction-params"));
124  } else if (routingAlgorithm == "CHWrapper") {
125  const SUMOTime weightPeriod = (oc.isSet("weight-files") ?
126  string2time(oc.getString("weight-period")) :
127  std::numeric_limits<int>::max());
130  begin, end, weightPeriod, oc.getInt("routing-threads"));
131  } else {
132  throw ProcessError("Unknown routing Algorithm '" + routingAlgorithm + "'!");
133  }
134  } else {
136  if (measure == "CO") {
137  op = &ROEdge::getEmissionEffort<PollutantsInterface::CO>;
138  } else if (measure == "CO2") {
139  op = &ROEdge::getEmissionEffort<PollutantsInterface::CO2>;
140  } else if (measure == "PMx") {
141  op = &ROEdge::getEmissionEffort<PollutantsInterface::PM_X>;
142  } else if (measure == "HC") {
143  op = &ROEdge::getEmissionEffort<PollutantsInterface::HC>;
144  } else if (measure == "NOx") {
145  op = &ROEdge::getEmissionEffort<PollutantsInterface::NO_X>;
146  } else if (measure == "fuel") {
147  op = &ROEdge::getEmissionEffort<PollutantsInterface::FUEL>;
148  } else if (measure == "electricity") {
149  op = &ROEdge::getEmissionEffort<PollutantsInterface::ELEC>;
150  } else if (measure == "noise") {
152  } else {
153  throw ProcessError("Unknown measure (weight attribute '" + measure + "')!");
154  }
156  ROEdge::getAllEdges(), oc.getBool("ignore-errors"), op, ttFunction, false, nullptr, net.hasPermissions(), oc.isSet("restriction-params"));
157  }
158  int carWalk = 0;
159  for (const std::string& opt : oc.getStringVector("persontrip.transfer.car-walk")) {
160  if (opt == "parkingAreas") {
162  } else if (opt == "ptStops") {
164  } else if (opt == "allJunctions") {
166  }
167  }
169  new ROIntermodalRouter(RONet::adaptIntermodalRouter, carWalk, routingAlgorithm));
170  // process route definitions
171  try {
172  net.openOutput(oc);
173  loader.processRoutes(begin, end, string2time(oc.getString("route-steps")), net, provider);
174  net.writeIntermodal(oc, provider.getIntermodalRouter());
175  // end the processing
176  net.cleanup();
177  } catch (ProcessError&) {
178  net.cleanup();
179  throw;
180  }
181 }
182 
183 
184 /* -------------------------------------------------------------------------
185  * main
186  * ----------------------------------------------------------------------- */
187 int
188 main(int argc, char** argv) {
190  // give some application descriptions
191  oc.setApplicationDescription("Shortest path router and DUE computer for the microscopic, multi-modal traffic simulation SUMO.");
192  oc.setApplicationName("duarouter", "Eclipse SUMO duarouter Version " VERSION_STRING);
193  int ret = 0;
194  RONet* net = nullptr;
195  try {
196  XMLSubSys::init();
198  OptionsIO::setArgs(argc, argv);
200  if (oc.processMetaOptions(argc < 2)) {
202  return 0;
203  }
204  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
207  throw ProcessError();
208  }
210  // load data
211  ROLoader loader(oc, false, !oc.getBool("no-step-log"));
212  net = new RONet();
213  initNet(*net, loader, oc);
214  // build routes
215  try {
216  computeRoutes(*net, loader, oc);
217  } catch (XERCES_CPP_NAMESPACE::SAXParseException& e) {
218  WRITE_ERROR(toString(e.getLineNumber()));
219  ret = 1;
220  } catch (XERCES_CPP_NAMESPACE::SAXException& e) {
221  WRITE_ERROR(StringUtils::transcode(e.getMessage()));
222  ret = 1;
223  }
224  if (MsgHandler::getErrorInstance()->wasInformed() || ret != 0) {
225  throw ProcessError();
226  }
227  } catch (const ProcessError& e) {
228  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
229  WRITE_ERROR(e.what());
230  }
231  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
232  ret = 1;
233 #ifndef _DEBUG
234  } catch (const std::exception& e) {
235  if (std::string(e.what()) != std::string("")) {
236  WRITE_ERROR(e.what());
237  }
238  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
239  ret = 1;
240  } catch (...) {
241  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
242  ret = 1;
243 #endif
244  }
245  delete net;
247  if (ret == 0) {
248  std::cout << "Success." << std::endl;
249  }
250  return ret;
251 }
252 
253 
254 
255 /****************************************************************************/
256 
OptionsCont::isSet
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
Definition: OptionsCont.cpp:135
ROLoader
The data loader.
Definition: ROLoader.h:55
ROEdge::getAllEdges
static const ROEdgeVector & getAllEdges()
Returns all ROEdges.
Definition: ROEdge.cpp:344
OptionsCont::getInt
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
Definition: OptionsCont.cpp:215
OptionsCont::processMetaOptions
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
Definition: OptionsCont.cpp:557
ToString.h
RONet::openOutput
void openOutput(const OptionsCont &options)
Opens the output for computed routes.
Definition: RONet.cpp:214
PedestrianRouter
Definition: MSNet.h:81
SystemFrame::close
static void close()
Closes all of an applications subsystems.
Definition: SystemFrame.cpp:133
MsgHandler::initOutputOptions
static void initOutputOptions()
init output options
Definition: MsgHandler.cpp:216
ROLoader::openRoutes
void openRoutes(RONet &net)
Builds and opens all route loaders.
Definition: ROLoader.cpp:161
IntermodalNetwork::ALL_JUNCTIONS
@ ALL_JUNCTIONS
junctions with edges allowing the additional mode
Definition: IntermodalNetwork.h:93
OptionsCont.h
MsgHandler.h
ROEdge::getTravelTimeStatic
static double getTravelTimeStatic(const ROEdge *const edge, const ROVehicle *const veh, double time)
Returns the travel time for the given edge.
Definition: ROEdge.h:412
RONet::hasPermissions
bool hasPermissions() const
Definition: RONet.cpp:692
OptionsCont::getString
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Definition: OptionsCont.cpp:201
MsgHandler::inform
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:118
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
IntermodalNetwork::PARKING_AREAS
@ PARKING_AREAS
parking areas
Definition: IntermodalNetwork.h:89
OptionsCont::getBool
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Definition: OptionsCont.cpp:222
RONet::writeIntermodal
void writeIntermodal(const OptionsCont &options, ROIntermodalRouter &router) const
Writes the intermodal network and weights if requested.
Definition: RONet.cpp:235
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:57
RONet::adaptIntermodalRouter
static void adaptIntermodalRouter(ROIntermodalRouter &router)
Definition: RONet.cpp:660
RONet
The router's network representation.
Definition: RONet.h:63
ROVehicle
A vehicle as used by router.
Definition: ROVehicle.h:52
ROFrame.h
SUMOVehicleParameter
Structure representing possible vehicle parameter.
Definition: SUMOVehicleParameter.h:297
ROLoader.h
ROIntermodalRouter
IntermodalRouter< ROEdge, ROLane, RONode, ROVehicle > ROIntermodalRouter
Definition: RORoutable.h:43
CHRouterWrapper.h
ROEdge::getNoiseEffort
static double getNoiseEffort(const ROEdge *const edge, const ROVehicle *const veh, double time)
Definition: ROEdge.cpp:208
DijkstraRouter
Computes the shortest path through a network using the Dijkstra algorithm.
Definition: DijkstraRouter.h:61
ROEdge::setGlobalOptions
static void setGlobalOptions(const bool interpolate)
Definition: ROEdge.h:466
gWeightsRandomFactor
double gWeightsRandomFactor
Definition: StdDefs.cpp:30
OptionsCont::getStringVector
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
Definition: OptionsCont.cpp:235
CHRouter.h
main
int main(int argc, char **argv)
Definition: duarouter_main.cpp:188
OptionsCont::setApplicationName
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.
Definition: OptionsCont.cpp:481
ROEdge::getTravelTimeStaticRandomized
static double getTravelTimeStaticRandomized(const ROEdge *const edge, const ROVehicle *const veh, double time)
Definition: ROEdge.h:416
SystemFrame.h
XMLSubSys::setValidation
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:58
RONet.h
AStarRouter.h
DEFAULT_VTYPE_ID
const std::string DEFAULT_VTYPE_ID
CHRouterWrapper
Computes the shortest path through a contracted network.
Definition: CHRouterWrapper.h:63
IntermodalNetwork::PT_STOPS
@ PT_STOPS
public transport stops and access
Definition: IntermodalNetwork.h:91
OutputDevice.h
ProcessError
Definition: UtilExceptions.h:39
UtilExceptions.h
XMLSubSys::init
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:47
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
ROLoader::loadNet
virtual void loadNet(RONet &toFill, ROAbstractEdgeBuilder &eb)
Loads the network.
Definition: ROLoader.cpp:113
RODUAFrame.h
RouterProvider
Definition: RouterProvider.h:37
initNet
void initNet(RONet &net, ROLoader &loader, OptionsCont &oc)
Definition: duarouter_main.cpp:71
string2time
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:44
RODUAFrame::checkOptions
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid for usage within duarouter.
Definition: RODUAFrame.cpp:178
RandHelper::initRandGlobal
static void initRandGlobal(std::mt19937 *which=0)
Reads the given random number options and initialises the random number generator in accordance.
Definition: RandHelper.cpp:77
SUMOAbstractRouter< ROEdge, ROVehicle >
RODUAEdgeBuilder.h
OptionsIO::getOptions
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:75
OptionsCont::setApplicationDescription
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
Definition: OptionsCont.cpp:489
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
StringUtils.h
RONet::cleanup
void cleanup()
closes the file output for computed routes and deletes associated threads if necessary
Definition: RONet.cpp:254
StringUtils::transcode
static std::string transcode(const XMLCh *const data)
converts a 0-terminated XMLCh* array (usually UTF-16, stemming from Xerces) into std::string in UTF-8
Definition: StringUtils.h:136
Option.h
RODUAEdgeBuilder
Interface for building instances of duarouter-edges.
Definition: RODUAEdgeBuilder.h:50
CHRouter
Computes the shortest path through a contracted network.
Definition: CHRouter.h:61
RouterProvider::getIntermodalRouter
IntermodalRouter< E, L, N, V > & getIntermodalRouter() const
Definition: RouterProvider.h:57
AStarRouter
Computes the shortest path through a network using the A* algorithm.
Definition: AStarRouter.h:77
OptionsIO::setArgs
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:54
config.h
ROLoader::processRoutes
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:191
RandHelper.h
DijkstraRouter.h
SystemFrame::checkOptions
static bool checkOptions()
checks shared options and sets StdDefs
Definition: SystemFrame.cpp:120
computeRoutes
void computeRoutes(RONet &net, ROLoader &loader, OptionsCont &oc)
Definition: duarouter_main.cpp:91
MsgHandler::getErrorInstance
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:81
SVC_IGNORING
@ SVC_IGNORING
vehicles ignoring classes
Definition: SUMOVehicleClass.h:135
RONet::getVehicleTypeSecure
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:278
VERSION_STRING
#define VERSION_STRING
Definition: config.h:210
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:283
ROEdge.h
RODUAFrame::fillOptions
static void fillOptions()
Inserts options used by duarouter into the OptionsCont-singleton.
Definition: RODUAFrame.cpp:44
OptionsIO.h
XMLSubSys.h
ROLoader::loadWeights
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:252