Eclipse SUMO - Simulation of Urban MObility
RODUAFrame.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-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // Sets and checks options for dua-routing
21 /****************************************************************************/
22 #include <config.h>
23 
24 #include <iostream>
25 #include <fstream>
26 #include <ctime>
28 #include <utils/options/Option.h>
31 #include <utils/common/ToString.h>
32 #include "RODUAFrame.h"
33 #include <router/ROFrame.h>
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
42 void
45  oc.addCallExample("-c <CONFIGURATION>", "run routing with options from file");
46 
47  // insert options sub-topics
48  SystemFrame::addConfigurationOptions(oc); // fill this subtopic, too
49  oc.addOptionSubTopic("Input");
50  oc.addOptionSubTopic("Output");
51  oc.addOptionSubTopic("Processing");
52  oc.addOptionSubTopic("Defaults");
53  oc.addOptionSubTopic("Time");
54 
55  // insert options
57  // to make the transition from --trip-files easier, but has a conflict with jtrrouter
58  oc.addSynonyme("route-files", "t", true);
60  addDUAOptions();
61  // add rand options
63 }
64 
65 
66 void
69  oc.doRegister("alternatives-output", new Option_FileName());
70  oc.addSynonyme("alternatives-output", "alternatives");
71  oc.addDescription("alternatives-output", "Output", "Write generated route alternatives to FILE");
72 
73  oc.doRegister("intermodal-network-output", new Option_FileName());
74  oc.addDescription("intermodal-network-output", "Output", "Write edge splits and connectivity to FILE");
75 
76  oc.doRegister("intermodal-weight-output", new Option_FileName());
77  oc.addDescription("intermodal-weight-output", "Output", "Write intermodal edges with lengths and travel times to FILE");
78 
79  oc.doRegister("write-trips", new Option_Bool(false));
80  oc.addDescription("write-trips", "Output", "Write trips instead of vehicles (for validating trip input)");
81 
82  oc.doRegister("write-trips.geo", new Option_Bool(false));
83  oc.addDescription("write-trips.geo", "Output", "Write trips with geo-coordinates");
84 
85  oc.doRegister("write-trips.junctions", new Option_Bool(false));
86  oc.addDescription("write-trips.junctions", "Output", "Write trips with fromJunction and toJunction");
87 
88  oc.doRegister("write-costs", new Option_Bool(false));
89  oc.addDescription("write-costs", "Output", "Include the cost attribute in route output");
90 
91  // register import options
92  oc.doRegister("weight-files", 'w', new Option_FileName());
93  oc.addSynonyme("weight-files", "weights");
94  oc.addDescription("weight-files", "Input", "Read network weights from FILE(s)");
95 
96  oc.doRegister("lane-weight-files", new Option_FileName());
97  oc.addDescription("lane-weight-files", "Input", "Read lane-based network weights from FILE(s)");
98 
99  oc.doRegister("weight-attribute", 'x', new Option_String("traveltime"));
100  oc.addSynonyme("weight-attribute", "measure", true);
101  oc.addDescription("weight-attribute", "Input", "Name of the xml attribute which gives the edge weight");
102 
103  // register further processing options
104  // ! The subtopic "Processing" must be initialised earlier !
105  oc.doRegister("weights.expand", new Option_Bool(false));
106  oc.addSynonyme("weights.expand", "expand-weights", true);
107  oc.addDescription("weights.expand", "Processing", "Expand weights behind the simulation's end");
108 
109  oc.doRegister("weights.random-factor", new Option_Float(1.));
110  oc.addDescription("weights.random-factor", "Processing", "Edge weights for routing are dynamically disturbed by a random factor drawn uniformly from [1,FLOAT)");
111 
112  oc.doRegister("routing-algorithm", new Option_String("dijkstra"));
113  oc.addDescription("routing-algorithm", "Processing", "Select among routing algorithms ['dijkstra', 'astar', 'CH', 'CHWrapper']");
114 
115  oc.doRegister("weight-period", new Option_String("3600", "TIME"));
116  oc.addDescription("weight-period", "Processing", "Aggregation period for the given weight files; triggers rebuilding of Contraction Hierarchy");
117 
118  oc.doRegister("weights.priority-factor", new Option_Float(0));
119  oc.addDescription("weights.priority-factor", "Processing", "Consider edge priorities in addition to travel times, weighted by factor");
120 
121  oc.doRegister("astar.all-distances", new Option_FileName());
122  oc.addDescription("astar.all-distances", "Processing", "Initialize lookup table for astar from the given file (generated by marouter --all-pairs-output)");
123 
124  oc.doRegister("astar.landmark-distances", new Option_FileName());
125  oc.addDescription("astar.landmark-distances", "Processing", "Initialize lookup table for astar ALT-variant from the given file");
126 
127  oc.doRegister("astar.save-landmark-distances", new Option_FileName());
128  oc.addDescription("astar.save-landmark-distances", "Processing", "Save lookup table for astar ALT-variant to the given file");
129 }
130 
131 
132 void
135  // register Gawron's DUE-settings
136  oc.doRegister("gawron.beta", new Option_Float(double(0.3)));
137  oc.addSynonyme("gawron.beta", "gBeta", true);
138  oc.addDescription("gawron.beta", "Processing", "Use FLOAT as Gawron's beta");
139 
140  oc.doRegister("gawron.a", new Option_Float(double(0.05)));
141  oc.addSynonyme("gawron.a", "gA", true);
142  oc.addDescription("gawron.a", "Processing", "Use FLOAT as Gawron's a");
143 
144  oc.doRegister("exit-times", new Option_Bool(false));
145  oc.addDescription("exit-times", "Output", "Write exit times (weights) for each edge");
146 
147  oc.doRegister("route-length", new Option_Bool(false));
148  oc.addDescription("route-length", "Output", "Include total route length in the output");
149 
150  oc.doRegister("keep-all-routes", new Option_Bool(false));
151  oc.addDescription("keep-all-routes", "Processing", "Save routes with near zero probability");
152 
153  oc.doRegister("skip-new-routes", new Option_Bool(false));
154  oc.addDescription("skip-new-routes", "Processing", "Only reuse routes from input, do not calculate new ones");
155 
156  oc.doRegister("keep-route-probability", new Option_Float(0));
157  oc.addDescription("keep-route-probability", "Processing", "The probability of keeping the old route");
158 
159  oc.doRegister("ptline-routing", new Option_Bool(false));
160  oc.addDescription("ptline-routing", "Processing", "Route all public transport input");
161 
162  oc.doRegister("logit", new Option_Bool(false)); // deprecated
163  oc.addDescription("logit", "Processing", "Use c-logit model (deprecated in favor of --route-choice-method logit)");
164 
165  oc.doRegister("route-choice-method", new Option_String("gawron"));
166  oc.addDescription("route-choice-method", "Processing", "Choose a route choice method: gawron, logit, or lohse");
167 
168  oc.doRegister("logit.beta", new Option_Float(double(-1)));
169  oc.addSynonyme("logit.beta", "lBeta", true);
170  oc.addDescription("logit.beta", "Processing", "Use FLOAT as logit's beta");
171 
172  oc.doRegister("logit.gamma", new Option_Float(double(1)));
173  oc.addSynonyme("logit.gamma", "lGamma", true);
174  oc.addDescription("logit.gamma", "Processing", "Use FLOAT as logit's gamma");
175 
176  oc.doRegister("logit.theta", new Option_Float(double(-1)));
177  oc.addSynonyme("logit.theta", "lTheta", true);
178  oc.addDescription("logit.theta", "Processing", "Use FLOAT as logit's theta (negative values mean auto-estimation)");
179 
180  oc.doRegister("persontrip.walkfactor", new Option_Float(double(0.75)));
181  oc.addDescription("persontrip.walkfactor", "Processing", "Use FLOAT as a factor on pedestrian maximum speed during intermodal routing");
182 
183  oc.doRegister("persontrip.walk-opposite-factor", new Option_Float(1.0));
184  oc.addDescription("persontrip.walk-opposite-factor", "Processing", "Use FLOAT as a factor on walking speed against vehicle traffic direction");
185 
186  oc.doRegister("persontrip.transfer.car-walk", new Option_StringVector(StringVector({ "parkingAreas" })));
187  oc.addDescription("persontrip.transfer.car-walk", "Processing",
188  "Where are mode changes from car to walking allowed (possible values: 'parkingAreas', 'ptStops', 'allJunctions' and combinations)");
189 
190  oc.doRegister("persontrip.transfer.taxi-walk", new Option_StringVector());
191  oc.addDescription("persontrip.transfer.taxi-walk", "Processing", "Where taxis can drop off customers ('allJunctions, 'ptStops')");
192 
193  oc.doRegister("persontrip.transfer.walk-taxi", new Option_StringVector());
194  oc.addDescription("persontrip.transfer.walk-taxi", "Processing", "Where taxis can pick up customers ('allJunctions, 'ptStops')");
195 
196  oc.doRegister("persontrip.taxi.waiting-time", new Option_String("300", "TIME"));
197  oc.addDescription("persontrip.taxi.waiting-time", "Processing", "Estimated time for taxi pickup");
198 
199  oc.doRegister("railway.max-train-length", new Option_Float(1000.0));
200  oc.addDescription("railway.max-train-length", "Processing", "Use FLOAT as a maximum train length when initializing the railway router");
201 }
202 
203 
204 bool
207  bool ok = ROFrame::checkOptions(oc);
208 
210  std::string error;
211  if (oc.isSet("departlane") && !SUMOVehicleParameter::parseDepartLane(oc.getString("departlane"), "option", "departlane", p.departLane, p.departLaneProcedure, error)) {
212  WRITE_ERROR(error);
213  ok = false;
214  }
215  if (oc.isSet("departpos") && !SUMOVehicleParameter::parseDepartPos(oc.getString("departpos"), "option", "departpos", p.departPos, p.departPosProcedure, error)) {
216  WRITE_ERROR(error);
217  ok = false;
218  }
219  if (oc.isSet("departspeed") && !SUMOVehicleParameter::parseDepartSpeed(oc.getString("departspeed"), "option", "departspeed", p.departSpeed, p.departSpeedProcedure, error)) {
220  WRITE_ERROR(error);
221  ok = false;
222  }
223  if (oc.isSet("arrivallane") && !SUMOVehicleParameter::parseArrivalLane(oc.getString("arrivallane"), "option", "arrivallane", p.arrivalLane, p.arrivalLaneProcedure, error)) {
224  WRITE_ERROR(error);
225  ok = false;
226  }
227  if (oc.isSet("arrivalpos") && !SUMOVehicleParameter::parseArrivalPos(oc.getString("arrivalpos"), "option", "arrivalpos", p.arrivalPos, p.arrivalPosProcedure, error)) {
228  WRITE_ERROR(error);
229  ok = false;
230  }
231  if (oc.isSet("arrivalspeed") && !SUMOVehicleParameter::parseArrivalSpeed(oc.getString("arrivalspeed"), "option", "arrivalspeed", p.arrivalSpeed, p.arrivalSpeedProcedure, error)) {
232  WRITE_ERROR(error);
233  ok = false;
234  }
235 
236  if (oc.getString("routing-algorithm") != "dijkstra" && oc.getString("weight-attribute") != "traveltime") {
237  WRITE_ERROR("Routing algorithm '" + oc.getString("routing-algorithm") + "' does not support weight-attribute '" + oc.getString("weight-attribute") + "'.");
238  return false;
239  }
240  if (oc.getBool("bulk-routing") && (oc.getString("routing-algorithm") == "CH" || oc.getString("routing-algorithm") == "CHWrapper")) {
241  WRITE_ERROR("Routing algorithm '" + oc.getString("routing-algorithm") + "' does not support bulk routing.");
242  return false;
243  }
244  if (oc.isDefault("routing-algorithm") && (oc.isSet("astar.all-distances") || oc.isSet("astar.landmark-distances") || oc.isSet("astar.save-landmark-distances"))) {
245  oc.set("routing-algorithm", "astar");
246  }
247 
248  if (oc.getString("route-choice-method") != "gawron" && oc.getString("route-choice-method") != "logit") {
249  WRITE_ERROR("Invalid route choice method '" + oc.getString("route-choice-method") + "'.");
250  return false;
251  }
252  if (oc.getBool("logit")) {
253  WRITE_WARNING("The --logit option is deprecated, please use --route-choice-method logit.");
254  oc.set("route-choice-method", "logit");
255  }
256 
257  if (oc.isSet("output-file") && !oc.isSet("alternatives-output")) {
258  const std::string& filename = oc.getString("output-file");
259  const int len = (int)filename.length();
260  if (len > 4 && filename.substr(len - 4) == ".xml") {
261  oc.set("alternatives-output", filename.substr(0, len - 4) + ".alt.xml");
262  } else if (len > 4 && filename.substr(len - 3) == ".gz") {
263  oc.set("alternatives-output", filename.substr(0, len - 3) + ".alt.gz");
264  } else {
265  WRITE_WARNING("Cannot derive file name for alternatives output, skipping it.");
266  }
267  }
268  if (oc.getBool("write-trips.junctions")) {
269  if (oc.isDefault("write-trips")) {
270  oc.set("write-trips", "true");
271  } else if (!oc.getBool("write-trips")) {
272  WRITE_WARNING("Option --write-trips.junctions takes no affect when --write-trips is disabled.");
273  }
274  }
275  return ok;
276 }
277 
278 
279 /****************************************************************************/
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:288
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
std::vector< std::string > StringVector
Definition of a vector of strings.
Definition: Option.h:43
A storage for options typed value containers)
Definition: OptionsCont.h:89
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:75
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
Definition: OptionsCont.cpp:96
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
static void addImportOptions()
Inserts import options used by duarouter into the OptionsCont-singleton.
Definition: RODUAFrame.cpp:67
static void addDUAOptions()
Inserts dua options used by duarouter into the OptionsCont-singleton.
Definition: RODUAFrame.cpp:133
static void fillOptions()
Inserts options used by duarouter into the OptionsCont-singleton.
Definition: RODUAFrame.cpp:43
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid for usage within duarouter.
Definition: RODUAFrame.cpp:205
static bool checkOptions(OptionsCont &oc)
Checks whether options are valid.
Definition: ROFrame.cpp:187
static void fillOptions(OptionsCont &oc)
Inserts options used by routing applications into the OptionsCont-singleton.
Definition: ROFrame.cpp:42
static void insertRandOptions()
Initialises the given options container with random number options.
Definition: RandHelper.cpp:43
Structure representing possible vehicle parameter.
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
ArrivalSpeedDefinition arrivalSpeedProcedure
Information how the vehicle's end speed shall be chosen.
double departSpeed
(optional) The initial speed of the vehicle
static bool parseArrivalLane(const std::string &val, const std::string &element, const std::string &id, int &lane, ArrivalLaneDefinition &ald, std::string &error)
Validates a given arrivalLane value.
ArrivalLaneDefinition arrivalLaneProcedure
Information how the vehicle shall choose the lane to arrive on.
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
static bool parseDepartSpeed(const std::string &val, const std::string &element, const std::string &id, double &speed, DepartSpeedDefinition &dsd, std::string &error)
Validates a given departSpeed value.
static bool parseArrivalPos(const std::string &val, const std::string &element, const std::string &id, double &pos, ArrivalPosDefinition &apd, std::string &error)
Validates a given arrivalPos value.
static bool parseArrivalSpeed(const std::string &val, const std::string &element, const std::string &id, double &speed, ArrivalSpeedDefinition &asd, std::string &error)
Validates a given arrivalSpeed value.
double departPos
(optional) The position the vehicle shall depart from
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle's initial speed shall be chosen.
double arrivalPos
(optional) The position the vehicle shall arrive on
static bool parseDepartLane(const std::string &val, const std::string &element, const std::string &id, int &lane, DepartLaneDefinition &dld, std::string &error)
Validates a given departLane value.
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
double arrivalSpeed
(optional) The final speed of the vehicle (not used yet)
static bool parseDepartPos(const std::string &val, const std::string &element, const std::string &id, double &pos, DepartPosDefinition &dpd, std::string &error)
Validates a given departPos value.
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
static void addConfigurationOptions(OptionsCont &oc)
Adds configuration options to the given container.
Definition: SystemFrame.cpp:38