Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2026 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 RORouteHandler.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Jakob Erdmann
17 : /// @author Sascha Krieg
18 : /// @author Michael Behrisch
19 : /// @date Mon, 9 Jul 2001
20 : ///
21 : // Parser and container for routes during their loading
22 : /****************************************************************************/
23 : #include <config.h>
24 :
25 : #include <string>
26 : #include <map>
27 : #include <vector>
28 : #include <iostream>
29 : #include <utils/iodevices/OutputDevice.h>
30 : #include <utils/xml/SUMOSAXHandler.h>
31 : #include <utils/xml/SUMOXMLDefinitions.h>
32 : #include <utils/geom/GeoConvHelper.h>
33 : #include <utils/common/FileHelpers.h>
34 : #include <utils/common/MsgHandler.h>
35 : #include <utils/common/StringTokenizer.h>
36 : #include <utils/common/UtilExceptions.h>
37 : #include <utils/options/OptionsCont.h>
38 : #include <utils/vehicle/SUMOVehicleParserHelper.h>
39 : #include <utils/xml/SUMOSAXReader.h>
40 : #include <utils/xml/XMLSubSys.h>
41 : #include <utils/iodevices/OutputDevice_String.h>
42 : #include "RONet.h"
43 : #include "ROEdge.h"
44 : #include "ROLane.h"
45 : #include "RORouteDef.h"
46 : #include "RORouteHandler.h"
47 :
48 : // ===========================================================================
49 : // method definitions
50 : // ===========================================================================
51 3894 : RORouteHandler::RORouteHandler(RONet& net, const std::string& file,
52 : const bool tryRepair,
53 : const bool emptyDestinationsAllowed,
54 : const bool ignoreErrors,
55 3894 : const bool checkSchema) :
56 : SUMORouteHandler(file, checkSchema ? "routes" : "", true),
57 7788 : MapMatcher(OptionsCont::getOptions().getBool("mapmatch.junctions"),
58 7788 : OptionsCont::getOptions().getBool("mapmatch.taz"),
59 3894 : OptionsCont::getOptions().getFloat("mapmatch.distance"),
60 3894 : ignoreErrors ? MsgHandler::getWarningInstance() : MsgHandler::getErrorInstance()),
61 3894 : myNet(net),
62 3894 : myActiveRouteRepeat(0),
63 3894 : myActiveRoutePeriod(0),
64 3894 : myActivePlan(nullptr),
65 3894 : myActiveContainerPlan(nullptr),
66 3894 : myActiveContainerPlanSize(0),
67 3894 : myTryRepair(tryRepair),
68 3894 : myEmptyDestinationsAllowed(emptyDestinationsAllowed),
69 3894 : myErrorOutput(ignoreErrors ? MsgHandler::getWarningInstance() : MsgHandler::getErrorInstance()),
70 3894 : myBegin(string2time(OptionsCont::getOptions().getString("begin"))),
71 3894 : myKeepVTypeDist(OptionsCont::getOptions().getBool("keep-vtype-distributions")),
72 7788 : myUnsortedInput(OptionsCont::getOptions().exists("unsorted-input") && OptionsCont::getOptions().getBool("unsorted-input")),
73 7673 : myWriteFlows(OptionsCont::getOptions().exists("keep-flows") && OptionsCont::getOptions().getBool("keep-flows")),
74 3894 : myCurrentVTypeDistribution(nullptr),
75 3894 : myCurrentAlternatives(nullptr),
76 3894 : myUseTaz(OptionsCont::getOptions().getBool("with-taz")),
77 3894 : myWriteJunctions(OptionsCont::getOptions().exists("write-trips")
78 7673 : && OptionsCont::getOptions().getBool("write-trips")
79 24228 : && OptionsCont::getOptions().getBool("write-trips.junctions")) {
80 3894 : myActiveRoute.reserve(100);
81 3894 : }
82 :
83 :
84 7788 : RORouteHandler::~RORouteHandler() {
85 3894 : delete myCurrentAlternatives;
86 11682 : }
87 :
88 :
89 : void
90 3561 : RORouteHandler::deleteActivePlanAndVehicleParameter() {
91 3561 : if (myActivePlan != nullptr) {
92 3407 : for (ROPerson::PlanItem* const it : *myActivePlan) {
93 194 : delete it;
94 : }
95 3213 : delete myActivePlan;
96 3213 : myActivePlan = nullptr;
97 : }
98 3561 : delete myActiveContainerPlan;
99 3561 : myActiveContainerPlan = nullptr;
100 3561 : delete myVehicleParameter;
101 3561 : myVehicleParameter = nullptr;
102 3561 : }
103 :
104 :
105 : void
106 191635 : RORouteHandler::parseFromViaTo(SumoXMLTag tag, const SUMOSAXAttributes& attrs, bool& ok) {
107 191635 : const std::string element = toString(tag);
108 : myActiveRoute.clear();
109 191635 : bool useTaz = myUseTaz;
110 191635 : if (myUseTaz && !myVehicleParameter->wasSet(VEHPARS_FROM_TAZ_SET) && !myVehicleParameter->wasSet(VEHPARS_TO_TAZ_SET)) {
111 0 : WRITE_WARNINGF(TL("Taz usage was requested but no taz present in % '%'!"), element, myVehicleParameter->id);
112 : useTaz = false;
113 : }
114 : SUMOVehicleClass vClass = SVC_PASSENGER;
115 191635 : if (!myNet.getVTypeDistribution(myVehicleParameter->vtypeid)) {
116 191603 : SUMOVTypeParameter* type = myNet.getVehicleTypeSecure(myVehicleParameter->vtypeid);
117 191603 : if (type != nullptr) {
118 191529 : vClass = type->vehicleClass;
119 : }
120 : }
121 : // from-attributes
122 191635 : const std::string rid = "for " + element + " '" + myVehicleParameter->id + "'";
123 207577 : if ((useTaz || (!attrs.hasAttribute(SUMO_ATTR_FROM) && !attrs.hasAttribute(SUMO_ATTR_FROMXY) && !attrs.hasAttribute(SUMO_ATTR_FROMLONLAT))) &&
124 31848 : (attrs.hasAttribute(SUMO_ATTR_FROM_TAZ) || attrs.hasAttribute(SUMO_ATTR_FROM_JUNCTION))) {
125 14962 : const bool useJunction = attrs.hasAttribute(SUMO_ATTR_FROM_JUNCTION);
126 14998 : const std::string tazType = useJunction ? "junction" : "taz";
127 14998 : const std::string tazID = attrs.get<std::string>(useJunction ? SUMO_ATTR_FROM_JUNCTION : SUMO_ATTR_FROM_TAZ, myVehicleParameter->id.c_str(), ok, true);
128 29924 : const ROEdge* fromTaz = myNet.getEdge(tazID + "-source");
129 14962 : if (fromTaz == nullptr) {
130 16 : myErrorOutput->inform("Source " + tazType + " '" + tazID + "' not known for " + element + " '" + myVehicleParameter->id + "'!"
131 8 : + (useJunction ? JUNCTION_TAZ_MISSING_HELP : ""));
132 8 : ok = false;
133 14954 : } else if (fromTaz->getNumSuccessors() == 0 && tag != SUMO_TAG_PERSON) {
134 0 : myErrorOutput->inform("Source " + tazType + " '" + tazID + "' has no outgoing edges for " + element + " '" + myVehicleParameter->id + "'!");
135 0 : ok = false;
136 : } else {
137 14954 : myActiveRoute.push_back(fromTaz);
138 14954 : if (useJunction && tag != SUMO_TAG_PERSON && !myWriteJunctions) {
139 7236 : myVehicleParameter->fromTaz = tazID;
140 7236 : myVehicleParameter->parametersSet |= VEHPARS_FROM_TAZ_SET;
141 : }
142 : }
143 176673 : } else if (attrs.hasAttribute(SUMO_ATTR_FROMXY)) {
144 102 : parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_FROMXY, myVehicleParameter->id.c_str(), ok), false, vClass, myActiveRoute, rid, true, ok);
145 102 : if (myMapMatchTAZ && ok) {
146 20 : myVehicleParameter->fromTaz = myActiveRoute.back()->getID();
147 20 : myVehicleParameter->parametersSet |= VEHPARS_FROM_TAZ_SET;
148 : }
149 176571 : } else if (attrs.hasAttribute(SUMO_ATTR_FROMLONLAT)) {
150 24 : parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_FROMLONLAT, myVehicleParameter->id.c_str(), ok), true, vClass, myActiveRoute, rid, true, ok);
151 24 : if (myMapMatchTAZ && ok) {
152 0 : myVehicleParameter->fromTaz = myActiveRoute.back()->getID();
153 0 : myVehicleParameter->parametersSet |= VEHPARS_FROM_TAZ_SET;
154 : }
155 : } else {
156 353094 : parseEdges(attrs.getOpt<std::string>(SUMO_ATTR_FROM, myVehicleParameter->id.c_str(), ok), myActiveRoute, rid, ok);
157 : }
158 191635 : if (!attrs.hasAttribute(SUMO_ATTR_VIA) && !attrs.hasAttribute(SUMO_ATTR_VIALONLAT) && !attrs.hasAttribute(SUMO_ATTR_VIAXY)) {
159 176994 : myInsertStopEdgesAt = (int)myActiveRoute.size();
160 : }
161 :
162 : // via-attributes
163 : ConstROEdgeVector viaEdges;
164 191635 : if (attrs.hasAttribute(SUMO_ATTR_VIAXY)) {
165 32 : parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_VIAXY, myVehicleParameter->id.c_str(), ok), false, vClass, viaEdges, rid, false, ok);
166 191603 : } else if (attrs.hasAttribute(SUMO_ATTR_VIALONLAT)) {
167 4 : parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_VIALONLAT, myVehicleParameter->id.c_str(), ok), true, vClass, viaEdges, rid, false, ok);
168 191599 : } else if (attrs.hasAttribute(SUMO_ATTR_VIAJUNCTIONS)) {
169 24 : for (std::string junctionID : attrs.get<std::vector<std::string> >(SUMO_ATTR_VIAJUNCTIONS, myVehicleParameter->id.c_str(), ok)) {
170 32 : const ROEdge* viaSink = myNet.getEdge(junctionID + "-sink");
171 16 : if (viaSink == nullptr) {
172 0 : myErrorOutput->inform("Junction-taz '" + junctionID + "' not found." + JUNCTION_TAZ_MISSING_HELP);
173 0 : ok = false;
174 : } else {
175 16 : viaEdges.push_back(viaSink);
176 : }
177 8 : }
178 : } else {
179 383182 : parseEdges(attrs.getOpt<std::string>(SUMO_ATTR_VIA, myVehicleParameter->id.c_str(), ok, "", true), viaEdges, rid, ok);
180 : }
181 225235 : for (const ROEdge* e : viaEdges) {
182 33600 : myActiveRoute.push_back(e);
183 33600 : myVehicleParameter->via.push_back(e->getID());
184 : }
185 :
186 : // to-attributes
187 208443 : if ((useTaz || (!attrs.hasAttribute(SUMO_ATTR_TO) && !attrs.hasAttribute(SUMO_ATTR_TOXY) && !attrs.hasAttribute(SUMO_ATTR_TOLONLAT))) &&
188 33580 : (attrs.hasAttribute(SUMO_ATTR_TO_TAZ) || attrs.hasAttribute(SUMO_ATTR_TO_JUNCTION))) {
189 14950 : const bool useJunction = attrs.hasAttribute(SUMO_ATTR_TO_JUNCTION);
190 14986 : const std::string tazType = useJunction ? "junction" : "taz";
191 14986 : const std::string tazID = attrs.get<std::string>(useJunction ? SUMO_ATTR_TO_JUNCTION : SUMO_ATTR_TO_TAZ, myVehicleParameter->id.c_str(), ok, true);
192 29900 : const ROEdge* toTaz = myNet.getEdge(tazID + "-sink");
193 14950 : if (toTaz == nullptr) {
194 0 : myErrorOutput->inform("Sink " + tazType + " '" + tazID + "' not known for " + element + " '" + myVehicleParameter->id + "'!"
195 0 : + (useJunction ? JUNCTION_TAZ_MISSING_HELP : ""));
196 0 : ok = false;
197 14950 : } else if (toTaz->getNumPredecessors() == 0 && tag != SUMO_TAG_PERSON) {
198 0 : myErrorOutput->inform("Sink " + tazType + " '" + tazID + "' has no incoming edges for " + element + " '" + myVehicleParameter->id + "'!");
199 0 : ok = false;
200 : } else {
201 14950 : myActiveRoute.push_back(toTaz);
202 14950 : if (useJunction && tag != SUMO_TAG_PERSON && !myWriteJunctions) {
203 7236 : myVehicleParameter->toTaz = tazID;
204 7236 : myVehicleParameter->parametersSet |= VEHPARS_TO_TAZ_SET;
205 : }
206 : }
207 176685 : } else if (attrs.hasAttribute(SUMO_ATTR_TOXY)) {
208 102 : parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_TOXY, myVehicleParameter->id.c_str(), ok, true), false, vClass, myActiveRoute, rid, false, ok);
209 102 : if (myMapMatchTAZ && ok) {
210 20 : myVehicleParameter->toTaz = myActiveRoute.back()->getID();
211 20 : myVehicleParameter->parametersSet |= VEHPARS_TO_TAZ_SET;
212 : }
213 176583 : } else if (attrs.hasAttribute(SUMO_ATTR_TOLONLAT)) {
214 24 : parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_TOLONLAT, myVehicleParameter->id.c_str(), ok, true), true, vClass, myActiveRoute, rid, false, ok);
215 24 : if (myMapMatchTAZ && ok) {
216 0 : myVehicleParameter->toTaz = myActiveRoute.back()->getID();
217 0 : myVehicleParameter->parametersSet |= VEHPARS_TO_TAZ_SET;
218 : }
219 : } else {
220 353118 : parseEdges(attrs.getOpt<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok, "", true), myActiveRoute, rid, ok);
221 : }
222 191635 : myActiveRouteID = "!" + myVehicleParameter->id;
223 191635 : if (myVehicleParameter->routeid == "") {
224 : myVehicleParameter->routeid = myActiveRouteID;
225 : }
226 383270 : }
227 :
228 :
229 : void
230 628512 : RORouteHandler::myStartElement(int element,
231 : const SUMOSAXAttributes& attrs) {
232 : try {
233 628512 : if (myActivePlan != nullptr && myActivePlan->empty() && myVehicleParameter->departProcedure == DepartDefinition::TRIGGERED && element != SUMO_TAG_RIDE && element != SUMO_TAG_PARAM) {
234 12 : throw ProcessError(TLF("Triggered departure for person '%' requires starting with a ride.", myVehicleParameter->id));
235 628508 : } else if (myActiveContainerPlan != nullptr && myActiveContainerPlanSize == 0 && myVehicleParameter->departProcedure == DepartDefinition::TRIGGERED && element != SUMO_TAG_TRANSPORT && element != SUMO_TAG_PARAM) {
236 12 : throw ProcessError(TLF("Triggered departure for container '%' requires starting with a transport.", myVehicleParameter->id));
237 : }
238 628504 : SUMORouteHandler::myStartElement(element, attrs);
239 628164 : bool ok = true;
240 628164 : switch (element) {
241 3213 : case SUMO_TAG_PERSON:
242 : case SUMO_TAG_PERSONFLOW: {
243 3213 : myActivePlan = new std::vector<ROPerson::PlanItem*>();
244 3213 : break;
245 : }
246 : case SUMO_TAG_RIDE:
247 : break; // handled in addRide, called from SUMORouteHandler::myStartElement
248 64 : case SUMO_TAG_CONTAINER:
249 : case SUMO_TAG_CONTAINERFLOW:
250 64 : myActiveContainerPlan = new OutputDevice_String(1);
251 64 : myActiveContainerPlanSize = 0;
252 64 : myActiveContainerPlan->openTag((SumoXMLTag)element);
253 64 : (*myActiveContainerPlan) << attrs;
254 : break;
255 60 : case SUMO_TAG_TRANSPORT:
256 : case SUMO_TAG_TRANSHIP:
257 60 : if (myActiveContainerPlan == nullptr) {
258 8 : throw ProcessError(TLF("Found % outside container element", toString((SumoXMLTag)element)));
259 : }
260 : // copy container elements
261 56 : myActiveContainerPlan->openTag((SumoXMLTag)element);
262 56 : (*myActiveContainerPlan) << attrs;
263 56 : myActiveContainerPlan->closeTag();
264 56 : myActiveContainerPlanSize++;
265 56 : break;
266 2573 : case SUMO_TAG_FLOW:
267 2573 : myActiveRouteProbability = DEFAULT_VEH_PROB;
268 2573 : parseFromViaTo((SumoXMLTag)element, attrs, ok);
269 : break;
270 185845 : case SUMO_TAG_TRIP:
271 185845 : myActiveRouteProbability = DEFAULT_VEH_PROB;
272 185845 : parseFromViaTo((SumoXMLTag)element, attrs, ok);
273 : break;
274 : default:
275 : break;
276 : }
277 352 : } catch (ProcessError&) {
278 352 : deleteActivePlanAndVehicleParameter();
279 352 : throw;
280 352 : }
281 628160 : }
282 :
283 :
284 : void
285 52 : RORouteHandler::openVehicleTypeDistribution(const SUMOSAXAttributes& attrs) {
286 52 : bool ok = true;
287 52 : myCurrentVTypeDistributionID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
288 52 : if (ok) {
289 52 : myCurrentVTypeDistribution = new RandomDistributor<SUMOVTypeParameter*>();
290 52 : if (attrs.hasAttribute(SUMO_ATTR_VTYPES)) {
291 : std::vector<double> probs;
292 36 : if (attrs.hasAttribute(SUMO_ATTR_PROBS)) {
293 8 : StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_PROBS, myCurrentVTypeDistributionID.c_str(), ok));
294 24 : while (st.hasNext()) {
295 32 : probs.push_back(StringUtils::toDoubleSecure(st.next(), 1.0));
296 : }
297 8 : }
298 36 : const std::string vTypes = attrs.get<std::string>(SUMO_ATTR_VTYPES, myCurrentVTypeDistributionID.c_str(), ok);
299 36 : StringTokenizer st(vTypes);
300 36 : int probIndex = 0;
301 84 : while (st.hasNext()) {
302 48 : const std::string typeID = st.next();
303 48 : const RandomDistributor<SUMOVTypeParameter*>* const dist = myNet.getVTypeDistribution(typeID);
304 : if (dist != nullptr) {
305 8 : const double distProb = ((int)probs.size() > probIndex ? probs[probIndex] : 1.) / dist->getOverallProb();
306 : std::vector<double>::const_iterator probIt = dist->getProbs().begin();
307 24 : for (SUMOVTypeParameter* const type : dist->getVals()) {
308 16 : myCurrentVTypeDistribution->add(type, distProb * *probIt);
309 : probIt++;
310 : }
311 : } else {
312 40 : SUMOVTypeParameter* const type = myNet.getVehicleTypeSecure(typeID);
313 40 : if (type == nullptr) {
314 24 : myErrorOutput->inform("Unknown vehicle type '" + typeID + "' in distribution '" + myCurrentVTypeDistributionID + "'.");
315 : } else {
316 32 : const double prob = ((int)probs.size() > probIndex ? probs[probIndex] : type->defaultProbability);
317 32 : myCurrentVTypeDistribution->add(type, prob);
318 : }
319 : }
320 48 : probIndex++;
321 : }
322 36 : if (probs.size() > 0 && probIndex != (int)probs.size()) {
323 0 : WRITE_WARNING("Got " + toString(probs.size()) + " probabilities for " + toString(probIndex) +
324 : " types in vTypeDistribution '" + myCurrentVTypeDistributionID + "'");
325 : }
326 72 : }
327 : }
328 52 : }
329 :
330 :
331 : void
332 52 : RORouteHandler::closeVehicleTypeDistribution() {
333 52 : if (myCurrentVTypeDistribution != nullptr) {
334 52 : if (myCurrentVTypeDistribution->getOverallProb() == 0) {
335 8 : delete myCurrentVTypeDistribution;
336 24 : myErrorOutput->inform("Vehicle type distribution '" + myCurrentVTypeDistributionID + "' is empty.");
337 44 : } else if (!myNet.addVTypeDistribution(myCurrentVTypeDistributionID, myCurrentVTypeDistribution)) {
338 0 : delete myCurrentVTypeDistribution;
339 0 : myErrorOutput->inform("Another vehicle type (or distribution) with the id '" + myCurrentVTypeDistributionID + "' exists.");
340 : }
341 52 : myCurrentVTypeDistribution = nullptr;
342 : }
343 52 : }
344 :
345 :
346 : void
347 235005 : RORouteHandler::openRoute(const SUMOSAXAttributes& attrs) {
348 : myActiveRoute.clear();
349 235005 : myInsertStopEdgesAt = -1;
350 : // check whether the id is really necessary
351 : std::string rid;
352 235005 : if (myCurrentAlternatives != nullptr) {
353 232607 : myActiveRouteID = myCurrentAlternatives->getID();
354 697821 : rid = "distribution '" + myCurrentAlternatives->getID() + "'";
355 2398 : } else if (myVehicleParameter != nullptr) {
356 : // ok, a vehicle is wrapping the route,
357 : // we may use this vehicle's id as default
358 1373 : myVehicleParameter->routeid = myActiveRouteID = "!" + myVehicleParameter->id; // !!! document this
359 1373 : if (attrs.hasAttribute(SUMO_ATTR_ID)) {
360 0 : WRITE_WARNINGF(TL("Ids of internal routes are ignored (vehicle '%')."), myVehicleParameter->id);
361 : }
362 : } else {
363 1025 : bool ok = true;
364 1025 : myActiveRouteID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
365 1025 : if (!ok) {
366 16 : return;
367 : }
368 3027 : rid = "'" + myActiveRouteID + "'";
369 : }
370 234989 : if (myVehicleParameter != nullptr) { // have to do this here for nested route distributions
371 698880 : rid = "for vehicle '" + myVehicleParameter->id + "'";
372 : }
373 234989 : bool ok = true;
374 234989 : if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
375 469962 : parseEdges(attrs.get<std::string>(SUMO_ATTR_EDGES, myActiveRouteID.c_str(), ok), myActiveRoute, rid, ok);
376 : }
377 469978 : myActiveRouteRefID = attrs.getOpt<std::string>(SUMO_ATTR_REFID, myActiveRouteID.c_str(), ok, "");
378 234989 : if (myActiveRouteRefID != "" && myNet.getRouteDef(myActiveRouteRefID) == nullptr) {
379 0 : myErrorOutput->inform("Invalid reference to route '" + myActiveRouteRefID + "' in route " + rid + ".");
380 : }
381 234989 : if (myCurrentAlternatives != nullptr && !attrs.hasAttribute(SUMO_ATTR_PROB)) {
382 48 : WRITE_WARNINGF(TL("No probability for route %, using default."), rid);
383 : }
384 234989 : myActiveRouteProbability = attrs.getOpt<double>(SUMO_ATTR_PROB, myActiveRouteID.c_str(), ok, DEFAULT_VEH_PROB);
385 234989 : if (ok && myActiveRouteProbability < 0) {
386 24 : myErrorOutput->inform("Invalid probability for route '" + myActiveRouteID + "'.");
387 : }
388 234989 : myActiveRouteColor = attrs.hasAttribute(SUMO_ATTR_COLOR) ? new RGBColor(attrs.get<RGBColor>(SUMO_ATTR_COLOR, myActiveRouteID.c_str(), ok)) : nullptr;
389 234989 : ok = true;
390 234989 : myActiveRouteRepeat = attrs.getOpt<int>(SUMO_ATTR_REPEAT, myActiveRouteID.c_str(), ok, 0);
391 234989 : myActiveRoutePeriod = attrs.getOptSUMOTimeReporting(SUMO_ATTR_CYCLETIME, myActiveRouteID.c_str(), ok, 0);
392 234989 : if (myActiveRouteRepeat > 0) {
393 : SUMOVehicleClass vClass = SVC_IGNORING;
394 8 : if (myVehicleParameter != nullptr) {
395 0 : SUMOVTypeParameter* type = myNet.getVehicleTypeSecure(myVehicleParameter->vtypeid);
396 0 : if (type != nullptr) {
397 0 : vClass = type->vehicleClass;
398 : }
399 : }
400 8 : if (myActiveRoute.size() > 0 && !myActiveRoute.back()->isConnectedTo(*myActiveRoute.front(), vClass)) {
401 0 : myErrorOutput->inform("Disconnected route " + rid + " when repeating.");
402 : }
403 : }
404 234989 : myCurrentCosts = attrs.getOpt<double>(SUMO_ATTR_COST, myActiveRouteID.c_str(), ok, -1);
405 234989 : if (ok && myCurrentCosts != -1 && myCurrentCosts < 0) {
406 24 : myErrorOutput->inform("Invalid cost for route '" + myActiveRouteID + "'.");
407 : }
408 : }
409 :
410 :
411 : void
412 1954 : RORouteHandler::openFlow(const SUMOSAXAttributes& /*attrs*/) {
413 : // currently unused
414 1954 : }
415 :
416 :
417 : void
418 619 : RORouteHandler::openRouteFlow(const SUMOSAXAttributes& /*attrs*/) {
419 : // currently unused
420 619 : }
421 :
422 :
423 : void
424 185845 : RORouteHandler::openTrip(const SUMOSAXAttributes& /*attrs*/) {
425 : // currently unused
426 185845 : }
427 :
428 :
429 : void
430 422744 : RORouteHandler::closeRoute(const bool mayBeDisconnected) {
431 422744 : const bool mustReroute = myActiveRoute.size() == 0 && myActiveRouteStops.size() != 0;
432 : if (mustReroute) {
433 : // implicit route from stops
434 20 : for (const SUMOVehicleParameter::Stop& stop : myActiveRouteStops) {
435 16 : ROEdge* edge = myNet.getEdge(stop.edge);
436 16 : myActiveRoute.push_back(edge);
437 : }
438 : }
439 422744 : if (myActiveRoute.size() == 0) {
440 24 : if (myActiveRouteRefID != "" && myCurrentAlternatives != nullptr) {
441 8 : myCurrentAlternatives->addAlternativeDef(myNet.getRouteDef(myActiveRouteRefID));
442 4 : myActiveRouteID = "";
443 : myActiveRouteRefID = "";
444 24 : return;
445 : }
446 20 : if (myVehicleParameter != nullptr) {
447 12 : myErrorOutput->inform("The route for vehicle '" + myVehicleParameter->id + "' has no edges.");
448 : } else {
449 48 : myErrorOutput->inform("Route '" + myActiveRouteID + "' has no edges.");
450 : }
451 20 : myActiveRouteID = "";
452 : myActiveRouteStops.clear();
453 20 : return;
454 : }
455 422720 : if (myActiveRoute.size() == 1 && myActiveRoute.front()->isTazConnector()) {
456 0 : myErrorOutput->inform("The routing information for vehicle '" + myVehicleParameter->id + "' is insufficient.");
457 0 : myActiveRouteID = "";
458 : myActiveRouteStops.clear();
459 0 : return;
460 : }
461 892692 : if (!mayBeDisconnected && OptionsCont::getOptions().exists("no-internal-links") && !OptionsCont::getOptions().getBool("no-internal-links")) {
462 : // fix internal edges which did not get parsed
463 : const ROEdge* last = nullptr;
464 : ConstROEdgeVector fullRoute;
465 1507261 : for (const ROEdge* roe : myActiveRoute) {
466 1272278 : if (last != nullptr) {
467 2529076 : for (const ROEdge* intern : last->getSuccessors()) {
468 1491781 : if (intern->isInternal() && intern->getSuccessors().size() == 1 && intern->getSuccessors().front() == roe) {
469 0 : fullRoute.push_back(intern);
470 : }
471 : }
472 : }
473 1272278 : fullRoute.push_back(roe);
474 : last = roe;
475 : }
476 234983 : myActiveRoute = fullRoute;
477 234983 : }
478 422720 : if (myActiveRouteRepeat > 0) {
479 : // duplicate route
480 8 : ConstROEdgeVector tmpEdges = myActiveRoute;
481 8 : auto tmpStops = myActiveRouteStops;
482 24 : for (int i = 0; i < myActiveRouteRepeat; i++) {
483 16 : myActiveRoute.insert(myActiveRoute.begin(), tmpEdges.begin(), tmpEdges.end());
484 80 : for (SUMOVehicleParameter::Stop stop : tmpStops) {
485 64 : if (stop.until > 0) {
486 32 : if (myActiveRoutePeriod <= 0) {
487 0 : const std::string description = myVehicleParameter != nullptr
488 0 : ? "for vehicle '" + myVehicleParameter->id + "'"
489 0 : : "'" + myActiveRouteID + "'";
490 0 : throw ProcessError(TLF("Cannot repeat stops with 'until' in route % because no cycleTime is defined.", description));
491 : }
492 32 : stop.until += myActiveRoutePeriod * (i + 1);
493 32 : stop.arrival += myActiveRoutePeriod * (i + 1);
494 : }
495 64 : myActiveRouteStops.push_back(stop);
496 64 : }
497 : }
498 8 : }
499 422720 : std::shared_ptr<RORoute> route = std::make_shared<RORoute>(myActiveRouteID, myCurrentCosts, myActiveRouteProbability, myActiveRoute,
500 422720 : myActiveRouteColor, myActiveRouteStops);
501 : myActiveRoute.clear();
502 422720 : if (myCurrentAlternatives == nullptr) {
503 190117 : if (myNet.getRouteDef(myActiveRouteID) != nullptr) {
504 0 : if (myVehicleParameter != nullptr) {
505 0 : myErrorOutput->inform("Another route for vehicle '" + myVehicleParameter->id + "' exists.");
506 : } else {
507 0 : myErrorOutput->inform("Another route (or distribution) with the id '" + myActiveRouteID + "' exists.");
508 : }
509 : myActiveRouteID = "";
510 : myActiveRouteStops.clear();
511 : return;
512 : } else {
513 190117 : myCurrentAlternatives = new RORouteDef(myActiveRouteID, 0, mayBeDisconnected || myTryRepair, mayBeDisconnected);
514 190117 : myCurrentAlternatives->addLoadedAlternative(route);
515 190117 : myNet.addRouteDef(myCurrentAlternatives);
516 190117 : myCurrentAlternatives = nullptr;
517 : }
518 : } else {
519 232603 : myCurrentAlternatives->addLoadedAlternative(route);
520 : }
521 : myActiveRouteID = "";
522 : myActiveRouteStops.clear();
523 : }
524 :
525 :
526 : void
527 91133 : RORouteHandler::openRouteDistribution(const SUMOSAXAttributes& attrs) {
528 : // check whether the id is really necessary
529 91133 : bool ok = true;
530 : std::string id;
531 91133 : if (myVehicleParameter != nullptr) {
532 : // ok, a vehicle is wrapping the route,
533 : // we may use this vehicle's id as default
534 90109 : myVehicleParameter->routeid = id = "!" + myVehicleParameter->id; // !!! document this
535 90109 : if (attrs.hasAttribute(SUMO_ATTR_ID)) {
536 0 : WRITE_WARNINGF(TL("Ids of internal route distributions are ignored (vehicle '%')."), myVehicleParameter->id);
537 : }
538 : } else {
539 1024 : id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
540 1024 : if (!ok) {
541 : return;
542 : }
543 : }
544 : // try to get the index of the last element
545 91125 : int index = attrs.getOpt<int>(SUMO_ATTR_LAST, id.c_str(), ok, 0);
546 91125 : if (ok && index < 0) {
547 16 : myErrorOutput->inform("Negative index of a route alternative (id='" + id + "').");
548 8 : return;
549 : }
550 : // build the alternative cont
551 91117 : myCurrentAlternatives = new RORouteDef(id, index, myTryRepair, false);
552 91117 : if (attrs.hasAttribute(SUMO_ATTR_ROUTES)) {
553 0 : ok = true;
554 0 : StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_ROUTES, id.c_str(), ok));
555 0 : while (st.hasNext()) {
556 0 : const std::string routeID = st.next();
557 0 : const RORouteDef* route = myNet.getRouteDef(routeID);
558 0 : if (route == nullptr) {
559 0 : myErrorOutput->inform("Unknown route '" + routeID + "' in distribution '" + id + "'.");
560 : } else {
561 0 : myCurrentAlternatives->addAlternativeDef(route);
562 : }
563 : }
564 0 : }
565 : }
566 :
567 :
568 : void
569 91117 : RORouteHandler::closeRouteDistribution() {
570 91117 : if (myCurrentAlternatives != nullptr) {
571 91101 : if (myCurrentAlternatives->getOverallProb() == 0) {
572 0 : myErrorOutput->inform("Route distribution '" + myCurrentAlternatives->getID() + "' is empty.");
573 0 : delete myCurrentAlternatives;
574 91101 : } else if (!myNet.addRouteDef(myCurrentAlternatives)) {
575 0 : myErrorOutput->inform("Another route (or distribution) with the id '" + myCurrentAlternatives->getID() + "' exists.");
576 0 : delete myCurrentAlternatives;
577 : } else {
578 182202 : if (myVehicleParameter != nullptr
579 181318 : && (myUseTaz || OptionsCont::getOptions().getBool("junction-taz"))
580 91261 : && (myVehicleParameter->wasSet(VEHPARS_FROM_TAZ_SET) ||
581 : myVehicleParameter->wasSet(VEHPARS_TO_TAZ_SET))) {
582 : // we are loading a rou.alt.xml, permit rerouting between taz
583 : bool ok = true;
584 : ConstROEdgeVector edges;
585 160 : if (myVehicleParameter->fromTaz != "") {
586 : const std::string tazID = myVehicleParameter->fromTaz;
587 320 : const ROEdge* fromTaz = myNet.getEdge(tazID + "-source");
588 160 : if (fromTaz == nullptr) {
589 0 : myErrorOutput->inform("Source taz '" + tazID + "' not known for vehicle '" + myVehicleParameter->id + "'!");
590 : ok = false;
591 160 : } else if (fromTaz->getNumSuccessors() == 0) {
592 0 : myErrorOutput->inform("Source taz '" + tazID + "' has no outgoing edges for vehicle '" + myVehicleParameter->id + "'!");
593 : ok = false;
594 : } else {
595 160 : edges.push_back(fromTaz);
596 : }
597 : } else {
598 0 : edges.push_back(myCurrentAlternatives->getOrigin());
599 : }
600 160 : if (myVehicleParameter->toTaz != "") {
601 : const std::string tazID = myVehicleParameter->toTaz;
602 320 : const ROEdge* toTaz = myNet.getEdge(tazID + "-sink");
603 160 : if (toTaz == nullptr) {
604 0 : myErrorOutput->inform("Sink taz '" + tazID + "' not known for vehicle '" + myVehicleParameter->id + "'!");
605 : ok = false;
606 160 : } else if (toTaz->getNumPredecessors() == 0) {
607 0 : myErrorOutput->inform("Sink taz '" + tazID + "' has no incoming edges for vehicle '" + myVehicleParameter->id + "'!");
608 : ok = false;
609 : } else {
610 160 : edges.push_back(toTaz);
611 : }
612 : } else {
613 0 : edges.push_back(myCurrentAlternatives->getDestination());
614 : }
615 160 : if (ok) {
616 : // negative probability indicates that this route should not be written
617 320 : myCurrentAlternatives->addLoadedAlternative(std::make_shared<RORoute>(myCurrentAlternatives->getID(), 0, -1, edges, nullptr, myActiveRouteStops));
618 : }
619 160 : }
620 : }
621 91101 : myCurrentAlternatives = nullptr;
622 : }
623 91117 : }
624 :
625 :
626 : void
627 278644 : RORouteHandler::closeVehicle() {
628 278644 : checkLastDepart();
629 : // get the vehicle id
630 278644 : if (myVehicleParameter->departProcedure == DepartDefinition::GIVEN && myVehicleParameter->depart < myBegin) {
631 4 : mySkippedVehicles.insert(myVehicleParameter->id);
632 4 : return;
633 : }
634 : // get vehicle type
635 278640 : SUMOVTypeParameter* type = myNet.getVehicleTypeSecure(myVehicleParameter->vtypeid);
636 278640 : if (type == nullptr) {
637 272 : myErrorOutput->inform("The vehicle type '" + myVehicleParameter->vtypeid + "' for vehicle '" + myVehicleParameter->id + "' is not known.");
638 136 : type = myNet.getVehicleTypeSecure(DEFAULT_VTYPE_ID);
639 : } else {
640 278504 : if (!myKeepVTypeDist) {
641 : // fix the type id in case we used a distribution
642 278500 : myVehicleParameter->vtypeid = type->id;
643 : }
644 : }
645 278640 : if (type->vehicleClass == SVC_PEDESTRIAN) {
646 120 : WRITE_WARNINGF(TL("Vehicle type '%' with vClass=pedestrian should only be used for persons and not for vehicle '%'."), type->id, myVehicleParameter->id);
647 : }
648 : // get the route
649 278640 : RORouteDef* route = myNet.getRouteDef(myVehicleParameter->routeid);
650 278612 : if (route == nullptr) {
651 56 : myErrorOutput->inform("The route of the vehicle '" + myVehicleParameter->id + "' is not known.");
652 28 : return;
653 : }
654 278612 : if (MsgHandler::getErrorInstance()->wasInformed()) {
655 : return;
656 : }
657 278464 : const bool needCopy = route->getID()[0] != '!';
658 278464 : if (needCopy) {
659 2574 : route = route->copy("!" + myVehicleParameter->id, myVehicleParameter->depart);
660 : }
661 : // build the vehicle
662 278464 : ROVehicle* veh = new ROVehicle(*myVehicleParameter, route, type, &myNet, myErrorOutput);
663 278464 : if (myNet.addVehicle(myVehicleParameter->id, veh)) {
664 278460 : registerLastDepart();
665 4 : } else if (needCopy) {
666 4 : delete route;
667 : }
668 278464 : delete myVehicleParameter;
669 278464 : myVehicleParameter = nullptr;
670 : }
671 :
672 :
673 : void
674 2074 : RORouteHandler::closeVType() {
675 2074 : if (myNet.addVehicleType(myCurrentVType)) {
676 2074 : if (myCurrentVTypeDistribution != nullptr) {
677 32 : myCurrentVTypeDistribution->add(myCurrentVType, myCurrentVType->defaultProbability);
678 : }
679 : }
680 4148 : if (OptionsCont::getOptions().isSet("restriction-params")) {
681 24 : const std::vector<std::string> paramKeys = OptionsCont::getOptions().getStringVector("restriction-params");
682 24 : myCurrentVType->cacheParamRestrictions(paramKeys);
683 24 : }
684 2074 : myCurrentVType = nullptr;
685 2074 : }
686 :
687 :
688 : void
689 3023 : RORouteHandler::closePerson() {
690 3023 : SUMOVTypeParameter* type = myNet.getVehicleTypeSecure(myVehicleParameter->vtypeid);
691 3023 : if (type == nullptr) {
692 0 : myErrorOutput->inform("The vehicle type '" + myVehicleParameter->vtypeid + "' for person '" + myVehicleParameter->id + "' is not known.");
693 0 : type = myNet.getVehicleTypeSecure(DEFAULT_PEDTYPE_ID);
694 : }
695 3023 : if (myActivePlan == nullptr || myActivePlan->empty()) {
696 40 : WRITE_WARNINGF(TL("Discarding person '%' because her plan is empty"), myVehicleParameter->id);
697 3003 : } else if (myVehicleParameter->departProcedure != DepartDefinition::GIVEN || myVehicleParameter->depart >= myBegin) {
698 2995 : ROPerson* person = new ROPerson(*myVehicleParameter, type);
699 6194 : for (ROPerson::PlanItem* item : *myActivePlan) {
700 3199 : person->getPlan().push_back(item);
701 : }
702 2995 : myActivePlan->clear();
703 2995 : if (myNet.addPerson(person)) {
704 2995 : checkLastDepart();
705 2995 : registerLastDepart();
706 : }
707 : }
708 3023 : deleteActivePlanAndVehicleParameter();
709 3023 : }
710 :
711 :
712 : void
713 186 : RORouteHandler::closePersonFlow() {
714 : std::string typeID = DEFAULT_PEDTYPE_ID;
715 186 : if (myNet.getVehicleTypeSecure(myVehicleParameter->vtypeid) == nullptr) {
716 0 : myErrorOutput->inform("The vehicle type '" + myVehicleParameter->vtypeid + "' for personFlow '" + myVehicleParameter->id + "' is not known.");
717 : } else {
718 186 : typeID = myVehicleParameter->vtypeid;
719 : }
720 186 : if (myActivePlan == nullptr || myActivePlan->empty()) {
721 0 : WRITE_WARNINGF(TL("Discarding personFlow '%' because their plan is empty"), myVehicleParameter->id);
722 : } else {
723 186 : checkLastDepart();
724 : // instantiate all persons of this flow
725 : int i = 0;
726 186 : std::string baseID = myVehicleParameter->id;
727 186 : if (myWriteFlows) {
728 158 : addFlowPerson(typeID, myVehicleParameter->depart, baseID, i);
729 28 : } else if (myVehicleParameter->repetitionProbability > 0) {
730 4 : if (myVehicleParameter->repetitionEnd == SUMOTime_MAX) {
731 0 : throw ProcessError(TLF("probabilistic personFlow '%' must specify end time", myVehicleParameter->id));
732 : } else {
733 44 : for (SUMOTime t = myVehicleParameter->depart; t < myVehicleParameter->repetitionEnd; t += TIME2STEPS(1)) {
734 40 : if (RandHelper::rand() < myVehicleParameter->repetitionProbability) {
735 20 : addFlowPerson(typeID, t, baseID, i++);
736 : }
737 : }
738 : }
739 : } else {
740 24 : SUMOTime depart = myVehicleParameter->depart;
741 : // uniform sampling of departures from range is equivalent to poisson flow (encoded by negative offset)
742 48 : if (OptionsCont::getOptions().getBool("randomize-flows") && myVehicleParameter->repetitionOffset >= 0) {
743 : std::vector<SUMOTime> departures;
744 4 : const SUMOTime range = myVehicleParameter->repetitionNumber * myVehicleParameter->repetitionOffset;
745 24 : for (int j = 0; j < myVehicleParameter->repetitionNumber; ++j) {
746 20 : departures.push_back(depart + RandHelper::rand(range));
747 : }
748 4 : std::sort(departures.begin(), departures.end());
749 : std::reverse(departures.begin(), departures.end());
750 24 : for (; i < myVehicleParameter->repetitionNumber; i++) {
751 20 : addFlowPerson(typeID, departures[i], baseID, i);
752 : depart += myVehicleParameter->repetitionOffset;
753 : }
754 4 : } else {
755 20 : const bool triggered = myVehicleParameter->departProcedure == DepartDefinition::TRIGGERED;
756 20 : if (myVehicleParameter->repetitionOffset < 0) {
757 : // poisson: randomize first depart
758 4 : myVehicleParameter->incrementFlow(1);
759 : }
760 172 : for (; i < myVehicleParameter->repetitionNumber && (triggered || depart + myVehicleParameter->repetitionTotalOffset <= myVehicleParameter->repetitionEnd); i++) {
761 152 : addFlowPerson(typeID, depart + myVehicleParameter->repetitionTotalOffset, baseID, i);
762 152 : if (myVehicleParameter->departProcedure != DepartDefinition::TRIGGERED) {
763 152 : myVehicleParameter->incrementFlow(1);
764 : }
765 : }
766 : }
767 : }
768 : }
769 186 : deleteActivePlanAndVehicleParameter();
770 186 : }
771 :
772 :
773 : void
774 350 : RORouteHandler::addFlowPerson(const std::string& typeID, SUMOTime depart, const std::string& baseID, int i) {
775 350 : SUMOVehicleParameter pars = *myVehicleParameter;
776 700 : pars.id = baseID + "." + toString(i);
777 350 : pars.depart = depart;
778 350 : const SUMOVTypeParameter* const type = myNet.getVehicleTypeSecure(typeID);
779 350 : if (!myKeepVTypeDist) {
780 350 : pars.vtypeid = type->id;
781 : }
782 350 : ROPerson* person = new ROPerson(pars, type);
783 700 : for (ROPerson::PlanItem* item : *myActivePlan) {
784 350 : person->getPlan().push_back(item->clone());
785 : }
786 350 : if (myNet.addPerson(person)) {
787 350 : if (i == 0) {
788 186 : registerLastDepart();
789 : }
790 : }
791 350 : }
792 :
793 :
794 : void
795 36 : RORouteHandler::closeContainer() {
796 36 : myActiveContainerPlan->closeTag();
797 36 : if (myActiveContainerPlanSize > 0) {
798 36 : myNet.addContainer(myVehicleParameter->depart, myActiveContainerPlan->getString());
799 36 : checkLastDepart();
800 36 : registerLastDepart();
801 : } else {
802 0 : WRITE_WARNINGF(TL("Discarding container '%' because its plan is empty"), myVehicleParameter->id);
803 : }
804 36 : delete myVehicleParameter;
805 36 : myVehicleParameter = nullptr;
806 36 : delete myActiveContainerPlan;
807 36 : myActiveContainerPlan = nullptr;
808 36 : myActiveContainerPlanSize = 0;
809 36 : }
810 :
811 :
812 20 : void RORouteHandler::closeContainerFlow() {
813 20 : myActiveContainerPlan->closeTag();
814 20 : if (myActiveContainerPlanSize > 0) {
815 20 : myNet.addContainer(myVehicleParameter->depart, myActiveContainerPlan->getString());
816 20 : checkLastDepart();
817 20 : registerLastDepart();
818 : } else {
819 0 : WRITE_WARNINGF(TL("Discarding containerFlow '%' because its plan is empty"), myVehicleParameter->id);
820 : }
821 20 : delete myVehicleParameter;
822 20 : myVehicleParameter = nullptr;
823 20 : delete myActiveContainerPlan;
824 20 : myActiveContainerPlan = nullptr;
825 20 : myActiveContainerPlanSize = 0;
826 20 : }
827 :
828 :
829 : void
830 2573 : RORouteHandler::closeFlow() {
831 2573 : checkLastDepart();
832 : // @todo: consider myScale?
833 2573 : if (myVehicleParameter->repetitionNumber == 0) {
834 8 : delete myVehicleParameter;
835 8 : myVehicleParameter = nullptr;
836 8 : return;
837 : }
838 : // let's check whether vehicles had to depart before the simulation starts
839 2565 : myVehicleParameter->repetitionsDone = 0;
840 2565 : const SUMOTime offsetToBegin = myBegin - myVehicleParameter->depart;
841 2749 : while (myVehicleParameter->repetitionTotalOffset < offsetToBegin) {
842 186 : myVehicleParameter->incrementFlow(1);
843 186 : if (myVehicleParameter->repetitionsDone == myVehicleParameter->repetitionNumber) {
844 2 : delete myVehicleParameter;
845 2 : myVehicleParameter = nullptr;
846 2 : return;
847 : }
848 : }
849 2563 : if (myNet.getVehicleTypeSecure(myVehicleParameter->vtypeid) == nullptr) {
850 54 : myErrorOutput->inform("The vehicle type '" + myVehicleParameter->vtypeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
851 : }
852 2563 : if (myVehicleParameter->routeid[0] == '!' && myNet.getRouteDef(myVehicleParameter->routeid) == nullptr) {
853 1894 : closeRoute(true);
854 : }
855 2563 : if (myNet.getRouteDef(myVehicleParameter->routeid) == nullptr) {
856 0 : myErrorOutput->inform("The route '" + myVehicleParameter->routeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
857 0 : delete myVehicleParameter;
858 0 : myVehicleParameter = nullptr;
859 0 : return;
860 : }
861 2563 : myActiveRouteID = "";
862 2563 : if (!MsgHandler::getErrorInstance()->wasInformed()) {
863 5108 : if (myNet.addFlow(myVehicleParameter, OptionsCont::getOptions().getBool("randomize-flows"))) {
864 2550 : registerLastDepart();
865 : } else {
866 8 : myErrorOutput->inform("Another flow with the id '" + myVehicleParameter->id + "' exists.");
867 4 : delete myVehicleParameter;
868 : }
869 : } else {
870 9 : delete myVehicleParameter;
871 : }
872 2563 : myVehicleParameter = nullptr;
873 2563 : myInsertStopEdgesAt = -1;
874 : }
875 :
876 :
877 : void
878 185845 : RORouteHandler::closeTrip() {
879 185845 : closeRoute(true);
880 185845 : closeVehicle();
881 185845 : }
882 :
883 :
884 : const SUMOVehicleParameter::Stop*
885 6172 : RORouteHandler::retrieveStoppingPlace(const SUMOSAXAttributes& attrs, const std::string& errorSuffix, std::string& id, const SUMOVehicleParameter::Stop* stopParam) {
886 : // dummy stop parameter to hold the attributes
887 6172 : SUMOVehicleParameter::Stop stop;
888 6172 : if (stopParam != nullptr) {
889 2883 : stop = *stopParam;
890 : } else {
891 3289 : bool ok = true;
892 6578 : stop.busstop = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, nullptr, ok, "");
893 3289 : stop.busstop = attrs.getOpt<std::string>(SUMO_ATTR_TRAIN_STOP, nullptr, ok, stop.busstop); // alias
894 3289 : stop.chargingStation = attrs.getOpt<std::string>(SUMO_ATTR_CHARGING_STATION, nullptr, ok, "");
895 3289 : stop.overheadWireSegment = attrs.getOpt<std::string>(SUMO_ATTR_OVERHEAD_WIRE_SEGMENT, nullptr, ok, "");
896 3289 : stop.containerstop = attrs.getOpt<std::string>(SUMO_ATTR_CONTAINER_STOP, nullptr, ok, "");
897 6578 : stop.parkingarea = attrs.getOpt<std::string>(SUMO_ATTR_PARKING_AREA, nullptr, ok, "");
898 : }
899 : const SUMOVehicleParameter::Stop* toStop = nullptr;
900 6172 : if (stop.busstop != "") {
901 2797 : toStop = myNet.getStoppingPlace(stop.busstop, SUMO_TAG_BUS_STOP);
902 : id = stop.busstop;
903 2797 : if (toStop == nullptr) {
904 0 : WRITE_ERROR("The busStop '" + stop.busstop + "' is not known" + errorSuffix);
905 : }
906 3375 : } else if (stop.containerstop != "") {
907 32 : toStop = myNet.getStoppingPlace(stop.containerstop, SUMO_TAG_CONTAINER_STOP);
908 : id = stop.containerstop;
909 32 : if (toStop == nullptr) {
910 0 : WRITE_ERROR("The containerStop '" + stop.containerstop + "' is not known" + errorSuffix);
911 : }
912 3343 : } else if (stop.parkingarea != "") {
913 24 : toStop = myNet.getStoppingPlace(stop.parkingarea, SUMO_TAG_PARKING_AREA);
914 : id = stop.parkingarea;
915 24 : if (toStop == nullptr) {
916 0 : WRITE_ERROR("The parkingArea '" + stop.parkingarea + "' is not known" + errorSuffix);
917 : }
918 3319 : } else if (stop.chargingStation != "") {
919 : // ok, we have a charging station
920 20 : toStop = myNet.getStoppingPlace(stop.chargingStation, SUMO_TAG_CHARGING_STATION);
921 : id = stop.chargingStation;
922 20 : if (toStop == nullptr) {
923 0 : WRITE_ERROR("The chargingStation '" + stop.chargingStation + "' is not known" + errorSuffix);
924 : }
925 3299 : } else if (stop.overheadWireSegment != "") {
926 : // ok, we have an overhead wire segment
927 0 : toStop = myNet.getStoppingPlace(stop.overheadWireSegment, SUMO_TAG_OVERHEAD_WIRE_SEGMENT);
928 : id = stop.overheadWireSegment;
929 0 : if (toStop == nullptr) {
930 0 : WRITE_ERROR("The overhead wire segment '" + stop.overheadWireSegment + "' is not known" + errorSuffix);
931 : }
932 : }
933 6172 : return toStop;
934 6172 : }
935 :
936 : Parameterised*
937 2899 : RORouteHandler::addStop(const SUMOSAXAttributes& attrs) {
938 : Parameterised* result = nullptr;
939 2899 : if (myActiveContainerPlan != nullptr) {
940 16 : myActiveContainerPlan->openTag(SUMO_TAG_STOP);
941 16 : (*myActiveContainerPlan) << attrs;
942 16 : myActiveContainerPlan->closeTag();
943 16 : myActiveContainerPlanSize++;
944 16 : return result;
945 : }
946 : std::string errorSuffix;
947 2883 : if (myActivePlan != nullptr) {
948 384 : errorSuffix = " in person '" + myVehicleParameter->id + "'.";
949 : } else if (myActiveContainerPlan != nullptr) {
950 : errorSuffix = " in container '" + myVehicleParameter->id + "'.";
951 2755 : } else if (myVehicleParameter != nullptr) {
952 2145 : errorSuffix = " in vehicle '" + myVehicleParameter->id + "'.";
953 : } else {
954 6120 : errorSuffix = " in route '" + myActiveRouteID + "'.";
955 : }
956 2883 : SUMOVehicleParameter::Stop stop;
957 5766 : bool ok = parseStop(stop, attrs, errorSuffix, myErrorOutput);
958 2883 : if (!ok) {
959 : return result;
960 : }
961 : // try to parse the assigned bus stop
962 2883 : const ROEdge* edge = nullptr;
963 : std::string stoppingPlaceID;
964 2883 : const SUMOVehicleParameter::Stop* stoppingPlace = retrieveStoppingPlace(attrs, errorSuffix, stoppingPlaceID, &stop);
965 : bool hasPos = false;
966 2883 : if (stoppingPlace != nullptr) {
967 2689 : stop.lane = stoppingPlace->lane;
968 2689 : stop.endPos = stoppingPlace->endPos;
969 2689 : stop.startPos = stoppingPlace->startPos;
970 10756 : edge = myNet.getEdge(SUMOXMLDefinitions::getEdgeIDFromLane(stop.lane));
971 : } else {
972 : // no, the lane and the position should be given
973 194 : stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, nullptr, ok, "");
974 194 : stop.edge = attrs.getOpt<std::string>(SUMO_ATTR_EDGE, nullptr, ok, "");
975 194 : if (ok && stop.edge != "") {
976 54 : edge = myNet.getEdge(stop.edge);
977 54 : if (edge == nullptr) {
978 0 : myErrorOutput->inform("The edge '" + stop.edge + "' for a stop is not known" + errorSuffix);
979 0 : return result;
980 : }
981 140 : } else if (ok && stop.lane != "") {
982 324 : edge = myNet.getEdge(SUMOXMLDefinitions::getEdgeIDFromLane(stop.lane));
983 108 : if (edge == nullptr) {
984 0 : myErrorOutput->inform("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix);
985 0 : return result;
986 : }
987 32 : } else if (ok && ((attrs.hasAttribute(SUMO_ATTR_X) && attrs.hasAttribute(SUMO_ATTR_Y))
988 20 : || (attrs.hasAttribute(SUMO_ATTR_LON) && attrs.hasAttribute(SUMO_ATTR_LAT)))) {
989 : Position pos;
990 : bool geo = false;
991 32 : if (attrs.hasAttribute(SUMO_ATTR_X) && attrs.hasAttribute(SUMO_ATTR_Y)) {
992 12 : pos = Position(attrs.get<double>(SUMO_ATTR_X, myVehicleParameter->id.c_str(), ok), attrs.get<double>(SUMO_ATTR_Y, myVehicleParameter->id.c_str(), ok));
993 : } else {
994 20 : pos = Position(attrs.get<double>(SUMO_ATTR_LON, myVehicleParameter->id.c_str(), ok), attrs.get<double>(SUMO_ATTR_LAT, myVehicleParameter->id.c_str(), ok));
995 : geo = true;
996 : }
997 32 : PositionVector positions;
998 32 : positions.push_back(pos);
999 : ConstROEdgeVector geoEdges;
1000 : SUMOVehicleClass vClass = SVC_PASSENGER;
1001 32 : if (!myNet.getVTypeDistribution(myVehicleParameter->vtypeid)) {
1002 32 : SUMOVTypeParameter* type = myNet.getVehicleTypeSecure(myVehicleParameter->vtypeid);
1003 32 : if (type != nullptr) {
1004 32 : vClass = type->vehicleClass;
1005 : }
1006 : }
1007 32 : parseGeoEdges(positions, geo, vClass, geoEdges, myVehicleParameter->id, true, ok, true);
1008 32 : if (ok) {
1009 32 : edge = geoEdges.front();
1010 : hasPos = true;
1011 32 : if (geo) {
1012 20 : GeoConvHelper::getFinal().x2cartesian_const(pos);
1013 : }
1014 32 : stop.parametersSet |= STOP_END_SET;
1015 32 : stop.endPos = edge->getLanes()[0]->getShape().nearest_offset_to_point2D(pos, false);
1016 : } else {
1017 : return result;
1018 : }
1019 32 : } else if (!ok || (stop.lane == "" && stop.edge == "")) {
1020 0 : myErrorOutput->inform("A stop must be placed on a bus stop, a container stop, a parking area, an edge or a lane" + errorSuffix);
1021 0 : return result;
1022 : }
1023 : if (!hasPos) {
1024 162 : stop.endPos = attrs.getOpt<double>(SUMO_ATTR_ENDPOS, nullptr, ok, edge->getLength());
1025 : }
1026 194 : stop.startPos = attrs.getOpt<double>(SUMO_ATTR_STARTPOS, nullptr, ok, stop.endPos - 2 * POSITION_EPS);
1027 242 : const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, nullptr, ok, !attrs.hasAttribute(SUMO_ATTR_STARTPOS) && !attrs.hasAttribute(SUMO_ATTR_ENDPOS));
1028 194 : const double endPosOffset = edge->isInternal() ? edge->getNormalBefore()->getLength() : 0;
1029 194 : if (!ok || (checkStopPos(stop.startPos, stop.endPos, edge->getLength() + endPosOffset, POSITION_EPS, friendlyPos) != SUMORouteHandler::StopPos::STOPPOS_VALID)) {
1030 0 : myErrorOutput->inform("Invalid start or end position for stop" + errorSuffix);
1031 0 : return result;
1032 : }
1033 : }
1034 2883 : stop.edge = edge->getID();
1035 2883 : if (myActivePlan != nullptr) {
1036 128 : ROPerson::addStop(*myActivePlan, stop, edge);
1037 128 : result = myActivePlan->back()->getStopParameters();
1038 2755 : } else if (myVehicleParameter != nullptr) {
1039 715 : myVehicleParameter->stops.push_back(stop);
1040 715 : result = &myVehicleParameter->stops.back();
1041 : } else {
1042 2040 : myActiveRouteStops.push_back(stop);
1043 : result = &myActiveRouteStops.back();
1044 : }
1045 2883 : if (myInsertStopEdgesAt >= 0) {
1046 494 : myActiveRoute.insert(myActiveRoute.begin() + myInsertStopEdgesAt, edge);
1047 494 : myInsertStopEdgesAt++;
1048 : }
1049 : return result;
1050 2883 : }
1051 :
1052 :
1053 : void
1054 108 : RORouteHandler::addRide(const SUMOSAXAttributes& attrs) {
1055 108 : bool ok = true;
1056 108 : std::vector<ROPerson::PlanItem*>& plan = *myActivePlan;
1057 108 : const std::string pid = myVehicleParameter->id;
1058 :
1059 : const ROEdge* from = nullptr;
1060 : const ROEdge* to = nullptr;
1061 108 : parseFromViaTo(SUMO_TAG_PERSON, attrs, ok);
1062 116 : if (attrs.hasAttribute(SUMO_ATTR_FROM) || attrs.hasAttribute(SUMO_ATTR_FROM_JUNCTION) || attrs.hasAttribute(SUMO_ATTR_FROM_TAZ)
1063 116 : || attrs.hasAttribute(SUMO_ATTR_FROMLONLAT) || attrs.hasAttribute(SUMO_ATTR_FROMXY)) {
1064 104 : if (ok) {
1065 104 : from = myActiveRoute.front();
1066 : }
1067 4 : } else if (plan.empty()) {
1068 0 : myErrorOutput->inform("The start edge for person '" + pid + "' is not known.");
1069 0 : return;
1070 : }
1071 : std::string stoppingPlaceID;
1072 216 : const SUMOVehicleParameter::Stop* stop = retrieveStoppingPlace(attrs, " for ride of person '" + myVehicleParameter->id + "'", stoppingPlaceID);
1073 108 : if (stop != nullptr) {
1074 84 : to = myNet.getEdge(SUMOXMLDefinitions::getEdgeIDFromLane(stop->lane));
1075 : } else {
1076 84 : if (attrs.hasAttribute(SUMO_ATTR_TO) || attrs.hasAttribute(SUMO_ATTR_TO_JUNCTION) || attrs.hasAttribute(SUMO_ATTR_TO_TAZ)
1077 84 : || attrs.hasAttribute(SUMO_ATTR_TOLONLAT) || attrs.hasAttribute(SUMO_ATTR_TOXY)) {
1078 80 : to = myActiveRoute.back();
1079 : } else {
1080 0 : myErrorOutput->inform("The to edge is missing within a ride of '" + myVehicleParameter->id + "'.");
1081 0 : return;
1082 : }
1083 : }
1084 108 : double arrivalPos = attrs.getOpt<double>(SUMO_ATTR_ARRIVALPOS, myVehicleParameter->id.c_str(), ok,
1085 : stop == nullptr ? std::numeric_limits<double>::infinity() : stop->endPos);
1086 108 : const std::string lines = attrs.getOpt<std::string>(SUMO_ATTR_LINES, pid.c_str(), ok, LINE_ANY);
1087 216 : const std::string group = attrs.getOpt<std::string>(SUMO_ATTR_GROUP, pid.c_str(), ok, "");
1088 :
1089 108 : if (plan.empty() && myVehicleParameter->departProcedure == DepartDefinition::TRIGGERED) {
1090 36 : StringTokenizer st(lines);
1091 72 : if (st.size() != 1 || st.get(0) == LINE_ANY) {
1092 0 : myErrorOutput->inform("Triggered departure for person '" + pid + "' requires a unique lines value.");
1093 0 : return;
1094 : }
1095 36 : const std::string vehID = st.front();
1096 36 : if (myNet.knowsVehicle(vehID)) {
1097 20 : const SUMOTime vehDepart = myNet.getDeparture(vehID);
1098 20 : if (vehDepart == -1) {
1099 0 : myErrorOutput->inform("Cannot use triggered vehicle '" + vehID + "' in triggered departure for person '" + pid + "'.");
1100 0 : return;
1101 : }
1102 20 : myVehicleParameter->depart = vehDepart + 1; // write person after vehicle
1103 : } else {
1104 : if (mySkippedVehicles.count(vehID) == 0) {
1105 16 : myErrorOutput->inform("Unknown vehicle '" + vehID + "' in triggered departure for person '" + pid + "'.");
1106 8 : return;
1107 : }
1108 8 : myVehicleParameter->departProcedure = DepartDefinition::GIVEN; // make sure the person gets skipped due to depart time
1109 : }
1110 36 : }
1111 100 : ROPerson::addRide(plan, from, to, lines, arrivalPos, stoppingPlaceID, group);
1112 : }
1113 :
1114 :
1115 : void
1116 32 : RORouteHandler::addTransport(const SUMOSAXAttributes& attrs) {
1117 32 : if (myActiveContainerPlan != nullptr && myActiveContainerPlanSize == 0 && myVehicleParameter->departProcedure == DepartDefinition::TRIGGERED) {
1118 12 : bool ok = true;
1119 : const std::string pid = myVehicleParameter->id;
1120 12 : const std::string desc = attrs.get<std::string>(SUMO_ATTR_LINES, pid.c_str(), ok);
1121 16 : StringTokenizer st(desc);
1122 12 : if (st.size() != 1) {
1123 0 : throw ProcessError(TLF("Triggered departure for container '%' requires a unique lines value.", pid));
1124 : }
1125 12 : const std::string vehID = st.front();
1126 12 : if (!myNet.knowsVehicle(vehID)) {
1127 : if (mySkippedVehicles.count(vehID) == 0) {
1128 12 : throw ProcessError("Unknown vehicle '" + vehID + "' in triggered departure for container '" + pid + "'.");
1129 : }
1130 : return;
1131 : }
1132 8 : SUMOTime vehDepart = myNet.getDeparture(vehID);
1133 8 : if (vehDepart == -1) {
1134 0 : throw ProcessError("Cannot use triggered vehicle '" + vehID + "' in triggered departure for container '" + pid + "'.");
1135 : }
1136 8 : myVehicleParameter->depart = vehDepart + 1; // write container after vehicle
1137 12 : }
1138 : }
1139 :
1140 :
1141 : void
1142 32 : RORouteHandler::addTranship(const SUMOSAXAttributes& /*attrs*/) {
1143 32 : }
1144 :
1145 :
1146 : void
1147 779738 : RORouteHandler::parseEdges(const std::string& desc, ConstROEdgeVector& into,
1148 : const std::string& rid, bool& ok) {
1149 3215740 : for (StringTokenizer st(desc); st.hasNext();) {
1150 1656264 : const std::string id = st.next();
1151 1656264 : const ROEdge* edge = myNet.getEdge(id);
1152 1656264 : if (edge == nullptr) {
1153 60 : myErrorOutput->inform("The edge '" + id + "' within the route " + rid + " is not known.");
1154 30 : ok = false;
1155 : } else {
1156 1656234 : into.push_back(edge);
1157 : }
1158 779738 : }
1159 779738 : }
1160 :
1161 :
1162 : void
1163 3109 : RORouteHandler::parseWalkPositions(const SUMOSAXAttributes& attrs, const std::string& personID,
1164 : const ROEdge* /*fromEdge*/, const ROEdge*& toEdge,
1165 : double& departPos, double& arrivalPos, std::string& busStopID,
1166 : const ROPerson::PlanItem* const lastStage, bool& ok) {
1167 3109 : const std::string description = "walk or personTrip of '" + personID + "'.";
1168 3109 : if (attrs.hasAttribute(SUMO_ATTR_DEPARTPOS)) {
1169 0 : WRITE_WARNING(TL("The attribute departPos is no longer supported for walks, please use the person attribute, the arrivalPos of the previous step or explicit stops."));
1170 : }
1171 3109 : departPos = myVehicleParameter->departPos;
1172 3109 : if (lastStage != nullptr) {
1173 156 : departPos = lastStage->getDestinationPos();
1174 : }
1175 :
1176 3109 : busStopID = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, nullptr, ok, "");
1177 :
1178 3109 : const SUMOVehicleParameter::Stop* bs = retrieveStoppingPlace(attrs, description, busStopID);
1179 3109 : if (bs != nullptr) {
1180 396 : toEdge = myNet.getEdge(SUMOXMLDefinitions::getEdgeIDFromLane(bs->lane));
1181 132 : arrivalPos = (bs->startPos + bs->endPos) / 2;
1182 : }
1183 3109 : if (toEdge != nullptr) {
1184 3109 : if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
1185 254 : arrivalPos = SUMOVehicleParserHelper::parseWalkPos(SUMO_ATTR_ARRIVALPOS,
1186 254 : myHardFail, description, toEdge->getLength(),
1187 508 : attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, description.c_str(), ok));
1188 : }
1189 : } else {
1190 0 : throw ProcessError(TLF("No destination edge for %.", description));
1191 : }
1192 3109 : }
1193 :
1194 :
1195 : void
1196 3109 : RORouteHandler::addPersonTrip(const SUMOSAXAttributes& attrs) {
1197 3109 : bool ok = true;
1198 3109 : const char* const id = myVehicleParameter->id.c_str();
1199 : assert(!attrs.hasAttribute(SUMO_ATTR_EDGES));
1200 : const ROEdge* from = nullptr;
1201 3109 : const ROEdge* to = nullptr;
1202 3109 : parseFromViaTo(SUMO_TAG_PERSON, attrs, ok);
1203 3109 : myInsertStopEdgesAt = -1;
1204 3757 : if (attrs.hasAttribute(SUMO_ATTR_FROM) || attrs.hasAttribute(SUMO_ATTR_FROM_JUNCTION) || attrs.hasAttribute(SUMO_ATTR_FROM_TAZ)
1205 3277 : || attrs.hasAttribute(SUMO_ATTR_FROMLONLAT) || attrs.hasAttribute(SUMO_ATTR_FROMXY)) {
1206 2957 : if (ok) {
1207 2945 : from = myActiveRoute.front();
1208 : }
1209 152 : } else if (myActivePlan->empty()) {
1210 0 : throw ProcessError(TLF("Start edge not defined for person '%'.", myVehicleParameter->id));
1211 : } else {
1212 152 : from = myActivePlan->back()->getDestination();
1213 : }
1214 3729 : if (attrs.hasAttribute(SUMO_ATTR_TO) || attrs.hasAttribute(SUMO_ATTR_TO_JUNCTION) || attrs.hasAttribute(SUMO_ATTR_TO_TAZ)
1215 3257 : || attrs.hasAttribute(SUMO_ATTR_TOLONLAT) || attrs.hasAttribute(SUMO_ATTR_TOXY)) {
1216 2977 : to = myActiveRoute.back();
1217 : } // else, to may also be derived from stopping place
1218 :
1219 3109 : const SUMOTime duration = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DURATION, id, ok, -1);
1220 3109 : if (attrs.hasAttribute(SUMO_ATTR_DURATION) && duration <= 0) {
1221 0 : throw ProcessError(TLF("Non-positive walking duration for '%'.", myVehicleParameter->id));
1222 : }
1223 :
1224 3109 : double departPos = 0;
1225 3109 : double arrivalPos = std::numeric_limits<double>::infinity();
1226 : std::string busStopID;
1227 3109 : const ROPerson::PlanItem* const lastStage = myActivePlan->empty() ? nullptr : myActivePlan->back();
1228 3109 : parseWalkPositions(attrs, myVehicleParameter->id, from, to, departPos, arrivalPos, busStopID, lastStage, ok);
1229 :
1230 3109 : const std::string modes = attrs.getOpt<std::string>(SUMO_ATTR_MODES, id, ok, "");
1231 6218 : const std::string group = attrs.getOpt<std::string>(SUMO_ATTR_GROUP, id, ok, "");
1232 : SVCPermissions modeSet = 0;
1233 8377 : for (StringTokenizer st(modes); st.hasNext();) {
1234 2159 : const std::string mode = st.next();
1235 2159 : if (mode == "car") {
1236 614 : modeSet |= SVC_PASSENGER;
1237 1545 : } else if (mode == "taxi") {
1238 93 : modeSet |= SVC_TAXI;
1239 1452 : } else if (mode == "bicycle") {
1240 12 : modeSet |= SVC_BICYCLE;
1241 1440 : } else if (mode == "public") {
1242 1440 : modeSet |= SVC_BUS;
1243 : } else {
1244 0 : throw InvalidArgument("Unknown person mode '" + mode + "'.");
1245 : }
1246 3109 : }
1247 3109 : const std::string types = attrs.getOpt<std::string>(SUMO_ATTR_VTYPES, id, ok, "");
1248 3109 : double walkFactor = attrs.getOpt<double>(SUMO_ATTR_WALKFACTOR, id, ok, OptionsCont::getOptions().getFloat("persontrip.walkfactor"));
1249 3109 : if (ok) {
1250 3097 : const std::string originStopID = myActivePlan->empty() ? "" : myActivePlan->back()->getStopDest();
1251 3097 : ROPerson::addTrip(*myActivePlan, myVehicleParameter->id, from, to, modeSet, types,
1252 : departPos, originStopID, arrivalPos, busStopID, walkFactor, group);
1253 3097 : myParamStack.push_back(myActivePlan->back());
1254 : }
1255 3109 : }
1256 :
1257 :
1258 : void
1259 1242 : RORouteHandler::addWalk(const SUMOSAXAttributes& attrs) {
1260 : // parse walks from->to as person trips
1261 1242 : if (attrs.hasAttribute(SUMO_ATTR_EDGES) || attrs.hasAttribute(SUMO_ATTR_ROUTE)) {
1262 : // XXX allow --repair?
1263 72 : bool ok = true;
1264 72 : if (attrs.hasAttribute(SUMO_ATTR_ROUTE)) {
1265 12 : const std::string routeID = attrs.get<std::string>(SUMO_ATTR_ROUTE, myVehicleParameter->id.c_str(), ok);
1266 12 : RORouteDef* routeDef = myNet.getRouteDef(routeID);
1267 12 : const std::shared_ptr<const RORoute> route = routeDef != nullptr ? routeDef->getFirstRoute() : nullptr;
1268 12 : if (route == nullptr) {
1269 0 : throw ProcessError("The route '" + routeID + "' for walk of person '" + myVehicleParameter->id + "' is not known.");
1270 : }
1271 12 : myActiveRoute = route->getEdgeVector();
1272 : } else {
1273 : myActiveRoute.clear();
1274 240 : parseEdges(attrs.get<std::string>(SUMO_ATTR_EDGES, myVehicleParameter->id.c_str(), ok), myActiveRoute, " walk for person '" + myVehicleParameter->id + "'", ok);
1275 : }
1276 72 : const char* const objId = myVehicleParameter->id.c_str();
1277 72 : const double duration = attrs.getOpt<double>(SUMO_ATTR_DURATION, objId, ok, -1);
1278 72 : if (attrs.hasAttribute(SUMO_ATTR_DURATION) && duration <= 0) {
1279 0 : throw ProcessError(TLF("Non-positive walking duration for '%'.", myVehicleParameter->id));
1280 : }
1281 72 : const double speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, objId, ok, -1.);
1282 72 : if (attrs.hasAttribute(SUMO_ATTR_SPEED) && speed <= 0) {
1283 0 : throw ProcessError(TLF("Non-positive walking speed for '%'.", myVehicleParameter->id));
1284 : }
1285 : double departPos = 0.;
1286 : double arrivalPos = std::numeric_limits<double>::infinity();
1287 72 : if (attrs.hasAttribute(SUMO_ATTR_DEPARTPOS)) {
1288 0 : WRITE_WARNING(TL("The attribute departPos is no longer supported for walks, please use the person attribute, the arrivalPos of the previous step or explicit stops."));
1289 : }
1290 72 : if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
1291 32 : arrivalPos = SUMOVehicleParserHelper::parseWalkPos(SUMO_ATTR_ARRIVALPOS, myHardFail, objId, myActiveRoute.back()->getLength(), attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, objId, ok));
1292 : }
1293 : std::string stoppingPlaceID;
1294 72 : const std::string errorSuffix = " for walk of person '" + myVehicleParameter->id + "'";
1295 72 : retrieveStoppingPlace(attrs, errorSuffix, stoppingPlaceID);
1296 72 : if (ok) {
1297 72 : ROPerson::addWalk(*myActivePlan, myActiveRoute, duration, speed, departPos, arrivalPos, stoppingPlaceID);
1298 72 : myParamStack.push_back(myActivePlan->back());
1299 : }
1300 : } else {
1301 1170 : addPersonTrip(attrs);
1302 : }
1303 1242 : }
1304 :
1305 :
1306 : void
1307 77 : RORouteHandler::initLaneTree(NamedRTree* tree) {
1308 6214 : for (const auto& edgeItem : myNet.getEdgeMap()) {
1309 11599 : for (ROLane* lane : edgeItem.second->getLanes()) {
1310 5462 : Boundary b = lane->getShape().getBoxBoundary();
1311 5462 : const float cmin[2] = {(float) b.xmin(), (float) b.ymin()};
1312 5462 : const float cmax[2] = {(float) b.xmax(), (float) b.ymax()};
1313 5462 : tree->Insert(cmin, cmax, lane);
1314 : }
1315 : }
1316 77 : }
1317 :
1318 :
1319 : ROEdge*
1320 512 : RORouteHandler::retrieveEdge(const std::string& id) {
1321 512 : return myNet.getEdge(id);
1322 : }
1323 :
1324 : bool
1325 284454 : RORouteHandler::checkLastDepart() {
1326 284454 : if (!myUnsortedInput) {
1327 283633 : return SUMORouteHandler::checkLastDepart();
1328 : }
1329 : return true;
1330 : }
1331 :
1332 : /****************************************************************************/
|