Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2025 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 : /****************************************************************************/
14 : /// @file RODUAFrame.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Jakob Erdmann
17 : /// @author Michael Behrisch
18 : /// @date Sept 2002
19 : ///
20 : // Sets and checks options for dua-routing
21 : /****************************************************************************/
22 : #include <config.h>
23 :
24 : #include <iostream>
25 : #include <fstream>
26 : #include <ctime>
27 : #include <utils/options/OptionsCont.h>
28 : #include <utils/options/Option.h>
29 : #include <utils/common/MsgHandler.h>
30 : #include <utils/common/UtilExceptions.h>
31 : #include <utils/common/ToString.h>
32 : #include "RODUAFrame.h"
33 : #include <router/ROFrame.h>
34 : #include <utils/common/RandHelper.h>
35 : #include <utils/common/SystemFrame.h>
36 : #include <utils/vehicle/SUMOVehicleParameter.h>
37 :
38 :
39 : // ===========================================================================
40 : // method definitions
41 : // ===========================================================================
42 : void
43 3670 : RODUAFrame::fillOptions() {
44 3670 : OptionsCont& oc = OptionsCont::getOptions();
45 7340 : oc.addCallExample("-c <CONFIGURATION>", TL("run routing with options from file"));
46 :
47 : // insert options sub-topics
48 3670 : SystemFrame::addConfigurationOptions(oc); // fill this subtopic, too
49 3670 : oc.addOptionSubTopic("Input");
50 3670 : oc.addOptionSubTopic("Output");
51 3670 : oc.addOptionSubTopic("Processing");
52 3670 : oc.addOptionSubTopic("Defaults");
53 3670 : oc.addOptionSubTopic("Time");
54 :
55 : // insert options
56 3670 : ROFrame::fillOptions(oc, true);
57 3670 : addImportOptions();
58 3670 : addDUAOptions();
59 : // add rand options
60 3670 : RandHelper::insertRandOptions(oc);
61 3670 : }
62 :
63 :
64 : void
65 3670 : RODUAFrame::addImportOptions() {
66 3670 : OptionsCont& oc = OptionsCont::getOptions();
67 3670 : oc.doRegister("alternatives-output", new Option_FileName());
68 7340 : oc.addSynonyme("alternatives-output", "alternatives");
69 7340 : oc.addDescription("alternatives-output", "Output", TL("Write generated route alternatives to FILE"));
70 :
71 3670 : oc.doRegister("intermodal-network-output", new Option_FileName());
72 7340 : oc.addDescription("intermodal-network-output", "Output", TL("Write edge splits and connectivity to FILE"));
73 :
74 3670 : oc.doRegister("intermodal-weight-output", new Option_FileName());
75 7340 : oc.addDescription("intermodal-weight-output", "Output", TL("Write intermodal edges with lengths and travel times to FILE"));
76 :
77 3670 : oc.doRegister("write-trips", new Option_Bool(false));
78 7340 : oc.addDescription("write-trips", "Output", TL("Write trips instead of vehicles (for validating trip input)"));
79 :
80 3670 : oc.doRegister("write-trips.geo", new Option_Bool(false));
81 7340 : oc.addDescription("write-trips.geo", "Output", TL("Write trips with geo-coordinates"));
82 :
83 3670 : oc.doRegister("write-trips.junctions", new Option_Bool(false));
84 7340 : oc.addDescription("write-trips.junctions", "Output", TL("Write trips with fromJunction and toJunction"));
85 :
86 3670 : oc.doRegister("write-costs", new Option_Bool(false));
87 7340 : oc.addDescription("write-costs", "Output", TL("Include the cost attribute in route output"));
88 :
89 : // register further processing options
90 : // ! The subtopic "Processing" must be initialised earlier !
91 3670 : oc.doRegister("weights.random-factor", new Option_Float(1.));
92 7340 : oc.addDescription("weights.random-factor", "Processing", TL("Edge weights for routing are dynamically disturbed by a random factor drawn uniformly from [1,FLOAT)"));
93 :
94 7340 : oc.doRegister("weight-period", new Option_String("3600", "TIME"));
95 7340 : oc.addDescription("weight-period", "Processing", TL("Aggregation period for the given weight files; triggers rebuilding of Contraction Hierarchy"));
96 :
97 3670 : oc.doRegister("weights.priority-factor", new Option_Float(0));
98 7340 : oc.addDescription("weights.priority-factor", "Processing", TL("Consider edge priorities in addition to travel times, weighted by factor"));
99 :
100 3670 : oc.doRegister("astar.all-distances", new Option_FileName());
101 7340 : oc.addDescription("astar.all-distances", "Processing", TL("Initialize lookup table for astar from the given file (generated by marouter --all-pairs-output)"));
102 :
103 3670 : oc.doRegister("astar.landmark-distances", new Option_FileName());
104 7340 : oc.addDescription("astar.landmark-distances", "Processing", TL("Initialize lookup table for astar ALT-variant from the given file"));
105 :
106 3670 : oc.doRegister("astar.save-landmark-distances", new Option_FileName());
107 7340 : oc.addDescription("astar.save-landmark-distances", "Processing", TL("Save lookup table for astar ALT-variant to the given file"));
108 :
109 3670 : oc.doRegister("scale", new Option_Float(1.));
110 7340 : oc.addDescription("scale", "Processing", TL("Scale demand by the given factor (by discarding or duplicating vehicles)"));
111 :
112 7340 : oc.doRegister("scale-suffix", new Option_String("."));
113 7340 : oc.addDescription("scale-suffix", "Processing", TL("Suffix to be added when creating ids for cloned vehicles"));
114 :
115 3670 : }
116 :
117 :
118 : void
119 3670 : RODUAFrame::addDUAOptions() {
120 3670 : OptionsCont& oc = OptionsCont::getOptions();
121 : // register Gawron's DUE-settings
122 3670 : oc.doRegister("gawron.beta", new Option_Float(double(0.9)));
123 7340 : oc.addSynonyme("gawron.beta", "gBeta", true);
124 7340 : oc.addDescription("gawron.beta", "Processing", TL("Use FLOAT as Gawron's beta"));
125 :
126 3670 : oc.doRegister("gawron.a", new Option_Float(double(0.5)));
127 7340 : oc.addSynonyme("gawron.a", "gA", true);
128 7340 : oc.addDescription("gawron.a", "Processing", TL("Use FLOAT as Gawron's a"));
129 :
130 3670 : oc.doRegister("exit-times", new Option_Bool(false));
131 7340 : oc.addDescription("exit-times", "Output", TL("Write exit times (weights) for each edge"));
132 :
133 3670 : oc.doRegister("route-length", new Option_Bool(false));
134 7340 : oc.addDescription("route-length", "Output", TL("Include total route length in the output"));
135 :
136 3670 : oc.doRegister("keep-all-routes", new Option_Bool(false));
137 7340 : oc.addDescription("keep-all-routes", "Processing", TL("Save routes with near zero probability"));
138 :
139 3670 : oc.doRegister("skip-new-routes", new Option_Bool(false));
140 7340 : oc.addDescription("skip-new-routes", "Processing", TL("Only reuse routes from input, do not calculate new ones"));
141 :
142 3670 : oc.doRegister("keep-route-probability", new Option_Float(0));
143 7340 : oc.addDescription("keep-route-probability", "Processing", TL("The probability of keeping the old route"));
144 :
145 3670 : oc.doRegister("ptline-routing", new Option_Bool(false));
146 7340 : oc.addDescription("ptline-routing", "Processing", TL("Route all public transport input"));
147 :
148 3670 : oc.doRegister("keep-flows", new Option_Bool(false));
149 7340 : oc.addDescription("keep-flows", "Processing", TL("Write flows instead of expanding them into vehicles"));
150 :
151 7340 : oc.doRegister("route-choice-method", new Option_String("gawron"));
152 7340 : oc.addDescription("route-choice-method", "Processing", TL("Choose a route choice method: gawron, logit, or lohse"));
153 :
154 3670 : oc.doRegister("logit", new Option_Bool(false)); // deprecated
155 7340 : oc.addDescription("logit", "Processing", TL("Use c-logit model (deprecated in favor of --route-choice-method logit)"));
156 :
157 3670 : oc.doRegister("logit.beta", new Option_Float(double(-1)));
158 7340 : oc.addSynonyme("logit.beta", "lBeta", true);
159 7340 : oc.addDescription("logit.beta", "Processing", TL("Use FLOAT as logit's beta"));
160 :
161 3670 : oc.doRegister("logit.gamma", new Option_Float(double(1)));
162 7340 : oc.addSynonyme("logit.gamma", "lGamma", true);
163 7340 : oc.addDescription("logit.gamma", "Processing", TL("Use FLOAT as logit's gamma"));
164 :
165 3670 : oc.doRegister("logit.theta", new Option_Float(double(-1)));
166 7340 : oc.addSynonyme("logit.theta", "lTheta", true);
167 7340 : oc.addDescription("logit.theta", "Processing", TL("Use FLOAT as logit's theta (negative values mean auto-estimation)"));
168 :
169 3670 : oc.doRegister("persontrip.walkfactor", new Option_Float(double(0.75)));
170 7340 : oc.addDescription("persontrip.walkfactor", "Processing", TL("Use FLOAT as a factor on pedestrian maximum speed during intermodal routing"));
171 :
172 3670 : oc.doRegister("persontrip.walk-opposite-factor", new Option_Float(1.0));
173 7340 : oc.addDescription("persontrip.walk-opposite-factor", "Processing", TL("Use FLOAT as a factor on walking speed against vehicle traffic direction"));
174 :
175 14680 : oc.doRegister("persontrip.transfer.car-walk", new Option_StringVector(StringVector({ "parkingAreas" })));
176 7340 : oc.addDescription("persontrip.transfer.car-walk", "Processing",
177 : "Where are mode changes from car to walking allowed (possible values: 'parkingAreas', 'ptStops', 'allJunctions' and combinations)");
178 :
179 3670 : oc.doRegister("persontrip.transfer.taxi-walk", new Option_StringVector());
180 7340 : oc.addDescription("persontrip.transfer.taxi-walk", "Processing", TL("Where taxis can drop off customers ('allJunctions, 'ptStops')"));
181 :
182 3670 : oc.doRegister("persontrip.transfer.walk-taxi", new Option_StringVector());
183 7340 : oc.addDescription("persontrip.transfer.walk-taxi", "Processing", TL("Where taxis can pick up customers ('allJunctions, 'ptStops')"));
184 :
185 7340 : oc.doRegister("persontrip.taxi.waiting-time", new Option_String("300", "TIME"));
186 7340 : oc.addDescription("persontrip.taxi.waiting-time", "Processing", TL("Estimated time for taxi pickup"));
187 :
188 3670 : oc.doRegister("persontrip.ride-public-line", new Option_Bool(false));
189 7340 : oc.addDescription("persontrip.ride-public-line", "Processing", TL("Only use the intended public transport line rather than any alternative line that stops at the destination"));
190 :
191 3670 : oc.doRegister("railway.max-train-length", new Option_Float(1000.0));
192 7340 : oc.addDescription("railway.max-train-length", "Processing", TL("Use FLOAT as a maximum train length when initializing the railway router"));
193 :
194 7340 : oc.doRegister("max-traveltime", new Option_String("-1", "TIME"));
195 7340 : oc.addDescription("max-traveltime", "Processing", TL("Declare routing failure if traveltime exceeds the given positive TIME"));
196 11010 : }
197 :
198 :
199 : bool
200 3411 : RODUAFrame::checkOptions() {
201 3411 : OptionsCont& oc = OptionsCont::getOptions();
202 3411 : bool ok = ROFrame::checkOptions(oc);
203 :
204 3411 : SUMOVehicleParameter p;
205 : std::string error;
206 3467 : if (oc.isSet("departlane") && !SUMOVehicleParameter::parseDepartLane(oc.getString("departlane"), "option", "departlane", p.departLane, p.departLaneProcedure, error)) {
207 12 : WRITE_ERROR(error);
208 : ok = false;
209 : }
210 3467 : if (oc.isSet("departpos") && !SUMOVehicleParameter::parseDepartPos(oc.getString("departpos"), "option", "departpos", p.departPos, p.departPosProcedure, error)) {
211 12 : WRITE_ERROR(error);
212 : ok = false;
213 : }
214 3467 : if (oc.isSet("departspeed") && !SUMOVehicleParameter::parseDepartSpeed(oc.getString("departspeed"), "option", "departspeed", p.departSpeed, p.departSpeedProcedure, error)) {
215 12 : WRITE_ERROR(error);
216 : ok = false;
217 : }
218 3467 : if (oc.isSet("arrivallane") && !SUMOVehicleParameter::parseArrivalLane(oc.getString("arrivallane"), "option", "arrivallane", p.arrivalLane, p.arrivalLaneProcedure, error)) {
219 12 : WRITE_ERROR(error);
220 : ok = false;
221 : }
222 3467 : if (oc.isSet("arrivalpos") && !SUMOVehicleParameter::parseArrivalPos(oc.getString("arrivalpos"), "option", "arrivalpos", p.arrivalPos, p.arrivalPosProcedure, error)) {
223 12 : WRITE_ERROR(error);
224 : ok = false;
225 : }
226 3467 : if (oc.isSet("arrivalspeed") && !SUMOVehicleParameter::parseArrivalSpeed(oc.getString("arrivalspeed"), "option", "arrivalspeed", p.arrivalSpeed, p.arrivalSpeedProcedure, error)) {
227 12 : WRITE_ERROR(error);
228 : ok = false;
229 : }
230 :
231 8967 : if (oc.getString("routing-algorithm") != "dijkstra" && oc.getString("weight-attribute") != "traveltime") {
232 9 : WRITE_ERRORF(TL("Routing algorithm '%' does not support weight-attribute '%'."), oc.getString("routing-algorithm"), oc.getString("weight-attribute"));
233 3 : return false;
234 : }
235 3560 : if (oc.getBool("bulk-routing") && (oc.getString("routing-algorithm") == "CH" || oc.getString("routing-algorithm") == "CHWrapper")) {
236 24 : WRITE_ERRORF(TL("Routing algorithm '%' does not support bulk routing."), oc.getString("routing-algorithm"));
237 12 : return false;
238 : }
239 7532 : if (oc.isDefault("routing-algorithm") && (oc.isSet("astar.all-distances") || oc.isSet("astar.landmark-distances") || oc.isSet("astar.save-landmark-distances"))) {
240 20 : oc.setDefault("routing-algorithm", "astar");
241 : }
242 3418 : if (!oc.isDefault("weights.random-factor") && (oc.isSet("astar.all-distances") || oc.isSet("astar.landmark-distances") || oc.isSet("astar.save-landmark-distances"))) {
243 4 : WRITE_WARNING(TL("The option --weights.random-factor should not be used together with astar and precomputed distances."));
244 : }
245 :
246 3558 : if (oc.getString("route-choice-method") != "gawron" && oc.getString("route-choice-method") != "logit") {
247 0 : WRITE_ERRORF(TL("Invalid route choice method '%'."), oc.getString("route-choice-method"));
248 0 : return false;
249 : }
250 6792 : if (oc.getBool("logit")) {
251 0 : WRITE_WARNING(TL("The --logit option is deprecated, please use --route-choice-method logit."));
252 0 : oc.set("route-choice-method", "logit");
253 : }
254 :
255 7024 : if (oc.isSet("output-file") && !oc.isSet("alternatives-output")) {
256 6296 : const std::string& filename = oc.getString("output-file");
257 3148 : const int len = (int)filename.length();
258 6295 : if (len > 4 && filename.substr(len - 4) == ".xml") {
259 11920 : oc.setDefault("alternatives-output", filename.substr(0, len - 4) + ".alt.xml");
260 335 : } else if (len > 7 && filename.substr(len - 7) == ".xml.gz") {
261 668 : oc.setDefault("alternatives-output", filename.substr(0, len - 7) + ".alt.xml.gz");
262 1 : } else if (len > 3 && filename.substr(len - 3) == ".gz") {
263 0 : oc.setDefault("alternatives-output", filename.substr(0, len - 3) + ".alt.gz");
264 : } else {
265 2 : WRITE_WARNING(TL("Cannot derive file name for alternatives output, skipping it."));
266 : }
267 : }
268 6792 : if (oc.getBool("write-trips.junctions")) {
269 40 : if (oc.isDefault("write-trips")) {
270 8 : oc.setDefault("write-trips", "true");
271 32 : } else if (!oc.getBool("write-trips")) {
272 0 : WRITE_WARNING(TL("Option --write-trips.junctions takes no affect when --write-trips is disabled."));
273 : }
274 : }
275 : return ok;
276 3411 : }
277 :
278 :
279 : /****************************************************************************/
|