Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSRouteHandler.cpp
Go to the documentation of this file.
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/****************************************************************************/
23// Parser and container for routes during their loading
24/****************************************************************************/
25#include <config.h>
26
27#include "MSRouteHandler.h"
35#include <microsim/MSEdge.h>
36#include <microsim/MSLane.h>
48
49// ===========================================================================
50// static members
51// ===========================================================================
52
53
54// ===========================================================================
55// method definitions
56// ===========================================================================
57MSRouteHandler::MSRouteHandler(const std::string& file, bool addVehiclesDirectly) :
58 SUMORouteHandler(file, addVehiclesDirectly ? "" : "routes", true),
59 MapMatcher(OptionsCont::getOptions().getBool("mapmatch.junctions"),
60 OptionsCont::getOptions().getBool("mapmatch.taz"),
61 OptionsCont::getOptions().getFloat("mapmatch.distance"),
62 MsgHandler::getErrorInstance()),
63 myActiveRouteRepeat(0),
64 myActiveRoutePeriod(0),
65 myActiveRoutePermanent(false),
66 myActiveType(ObjectTypeEnum::UNDEFINED),
67 myHaveVia(false),
68 myActiveTransportablePlan(nullptr),
69 myAddVehiclesDirectly(addVehiclesDirectly),
70 myCurrentVTypeDistribution(nullptr),
71 myCurrentRouteDistribution(nullptr),
72 myAmLoadingState(false),
73 myScaleSuffix(OptionsCont::getOptions().getString("scale-suffix")),
74 myReplayRerouting(OptionsCont::getOptions().getBool("replay-rerouting")),
75 myStartTriggeredInFlow(false) {
76 myActiveRoute.reserve(100);
77}
78
79
81
82
83void
94
95
96void
102
103
104void
106 const std::string element = toString(tag);
107 myActiveRoute.clear();
108 bool useTaz = OptionsCont::getOptions().getBool("with-taz");
110 WRITE_WARNINGF(TL("Taz usage was requested but no taz present in % '%'!"), element, myVehicleParameter->id);
111 useTaz = false;
112 }
113 bool ok = true;
114 const std::string rid = "for " + element + " '" + myVehicleParameter->id + "'";
117 if (!vc.getVTypeDistribution(myVehicleParameter->vtypeid)) {
118 MSVehicleType* const type = vc.getVType(myVehicleParameter->vtypeid, &myParsingRNG);
119 if (type != nullptr) {
120 vClass = type->getParameter().vehicleClass;
121 }
122 }
123 // from-attributes
124 if ((useTaz || (!attrs.hasAttribute(SUMO_ATTR_FROM) && !attrs.hasAttribute(SUMO_ATTR_FROMXY) && !attrs.hasAttribute(SUMO_ATTR_FROMLONLAT))) &&
126 const bool useJunction = attrs.hasAttribute(SUMO_ATTR_FROM_JUNCTION);
127 const std::string tazType = useJunction ? "junction" : "taz";
128 const std::string tazID = attrs.get<std::string>(useJunction ? SUMO_ATTR_FROM_JUNCTION : SUMO_ATTR_FROM_TAZ, myVehicleParameter->id.c_str(), ok);
129 const MSEdge* fromTaz = MSEdge::dictionary(tazID + "-source");
130 if (fromTaz == nullptr) {
131 throw ProcessError("Source " + tazType + " '" + tazID + "' not known " + rid + "!"
132 + (useJunction ? JUNCTION_TAZ_MISSING_HELP : ""));
133 } else if (fromTaz->getNumSuccessors() == 0 && tag != SUMO_TAG_PERSON) {
134 throw ProcessError("Source " + tazType + " '" + tazID + "' has no outgoing edges " + rid + "!");
135 } else {
136 myActiveRoute.push_back(fromTaz);
137 }
138 } else if (attrs.hasAttribute(SUMO_ATTR_FROMXY)) {
139 parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_FROMXY, myVehicleParameter->id.c_str(), ok), false, vClass, myActiveRoute, rid, true, ok);
140 if (myMapMatchTAZ && ok) {
141 myVehicleParameter->fromTaz = myActiveRoute.back()->getID();
143 }
144 } else if (attrs.hasAttribute(SUMO_ATTR_FROMLONLAT)) {
145 parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_FROMLONLAT, myVehicleParameter->id.c_str(), ok), true, vClass, myActiveRoute, rid, true, ok);
146 if (myMapMatchTAZ && ok) {
147 myVehicleParameter->fromTaz = myActiveRoute.back()->getID();
149 }
150 } else {
151 MSEdge::parseEdgesList(attrs.getOpt<std::string>(SUMO_ATTR_FROM, myVehicleParameter->id.c_str(), ok),
152 myActiveRoute, rid);
153 }
154 if (!ok) {
155 throw ProcessError();
156 }
157
158 // via-attributes
161 }
162 ConstMSEdgeVector viaEdges;
163 if (attrs.hasAttribute(SUMO_ATTR_VIAXY)) {
164 parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_VIAXY, myVehicleParameter->id.c_str(), ok), false, vClass, viaEdges, rid, false, ok);
165 } else if (attrs.hasAttribute(SUMO_ATTR_VIALONLAT)) {
166 parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_VIALONLAT, myVehicleParameter->id.c_str(), ok), true, vClass, viaEdges, rid, false, ok);
167 } else if (attrs.hasAttribute(SUMO_ATTR_VIAJUNCTIONS)) {
168 for (std::string junctionID : attrs.get<std::vector<std::string> >(SUMO_ATTR_VIAJUNCTIONS, myVehicleParameter->id.c_str(), ok)) {
169 const MSEdge* viaSink = MSEdge::dictionary(junctionID + "-sink");
170 if (viaSink == nullptr) {
171 throw ProcessError("Junction-taz '" + junctionID + "' not found." + JUNCTION_TAZ_MISSING_HELP);
172 } else {
173 viaEdges.push_back(viaSink);
174 }
175 }
176 } else {
177 MSEdge::parseEdgesList(attrs.getOpt<std::string>(SUMO_ATTR_VIA, myVehicleParameter->id.c_str(), ok),
178 viaEdges, rid);
179 }
180 if (!viaEdges.empty()) {
181 myHaveVia = true;
182 }
183 for (const MSEdge* e : viaEdges) {
184 myActiveRoute.push_back(e);
185 myVehicleParameter->via.push_back(e->getID());
186 }
187
188 // to-attributes
189 if ((useTaz || (!attrs.hasAttribute(SUMO_ATTR_TO) && !attrs.hasAttribute(SUMO_ATTR_TOXY) && !attrs.hasAttribute(SUMO_ATTR_TOLONLAT))) &&
191 const bool useJunction = attrs.hasAttribute(SUMO_ATTR_TO_JUNCTION);
192 const std::string tazType = useJunction ? "junction" : "taz";
193 const std::string tazID = attrs.get<std::string>(useJunction ? SUMO_ATTR_TO_JUNCTION : SUMO_ATTR_TO_TAZ, myVehicleParameter->id.c_str(), ok, true);
194 const MSEdge* toTaz = MSEdge::dictionary(tazID + "-sink");
195 if (toTaz == nullptr) {
196 throw ProcessError("Sink " + tazType + " '" + tazID + "' not known " + rid + "!"
197 + (useJunction ? JUNCTION_TAZ_MISSING_HELP : ""));
198 } else if (toTaz->getNumPredecessors() == 0 && tag != SUMO_TAG_PERSON) {
199 throw ProcessError("Sink " + tazType + " '" + tazID + "' has no incoming edges " + rid + "!");
200 } else {
201 myActiveRoute.push_back(toTaz);
202 }
203 } else if (attrs.hasAttribute(SUMO_ATTR_TOXY)) {
204 parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_TOXY, myVehicleParameter->id.c_str(), ok, true), false, vClass, myActiveRoute, rid, false, ok);
205 if (myMapMatchTAZ && ok) {
206 myVehicleParameter->toTaz = myActiveRoute.back()->getID();
208 }
209 } else if (attrs.hasAttribute(SUMO_ATTR_TOLONLAT)) {
210 parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_TOLONLAT, myVehicleParameter->id.c_str(), ok, true), true, vClass, myActiveRoute, rid, false, ok);
211 if (myMapMatchTAZ && ok) {
212 myVehicleParameter->toTaz = myActiveRoute.back()->getID();
214 }
215 } else {
216 MSEdge::parseEdgesList(attrs.getOpt<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok, "", true),
217 myActiveRoute, rid);
218 }
220 if (myVehicleParameter->routeid == "") {
222 }
223}
224
225
226void
229 myElementStack.push_back(element);
230 return;
231 }
232 try {
234 && element != SUMO_TAG_RIDE && element != SUMO_TAG_TRANSPORT && element != SUMO_TAG_PARAM) {
235 const std::string mode = myActiveType == ObjectTypeEnum::PERSON ? "ride" : "transport";
236 throw ProcessError("Triggered departure for " + myActiveTypeName + " '" + myVehicleParameter->id + "' requires starting with a " + mode + ".");
237 }
238 if (myVehicleParameter == nullptr) {
240 myHaveVia = false;
241 }
242 SUMORouteHandler::myStartElement(element, attrs);
243 switch (element) {
245 addTransportable(attrs, true);
246 break;
248 addTransportable(attrs, false);
249 break;
250 case SUMO_TAG_FLOW:
251 if (myVehicleParameter) {
252 parseFromViaTo((SumoXMLTag)element, attrs);
253 }
254 break;
255 case SUMO_TAG_TRIP:
256 parseFromViaTo((SumoXMLTag)element, attrs);
257 break;
258 default:
259 break;
260 }
261 } catch (ProcessError&) {
263 throw;
264 }
265}
266
267
268void
272 return;
273 }
276 myParamStack.pop_back();
277 myActiveRoute.clear();
279 }
280 myElementStack.pop_back();
281}
282
283
284void
286 bool ok = true;
287 myCurrentVTypeDistributionID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
288 if (ok) {
290 if (attrs.hasAttribute(SUMO_ATTR_VTYPES)) {
291 std::vector<double> probs;
292 if (attrs.hasAttribute(SUMO_ATTR_PROBS)) {
293 StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_PROBS, myCurrentVTypeDistributionID.c_str(), ok));
294 while (st.hasNext()) {
295 probs.push_back(StringUtils::toDoubleSecure(st.next(), 1.0));
296 }
297 }
298 const std::string vTypes = attrs.get<std::string>(SUMO_ATTR_VTYPES, myCurrentVTypeDistributionID.c_str(), ok);
299 StringTokenizer st(vTypes);
300 int probIndex = 0;
301 while (st.hasNext()) {
302 const std::string& vtypeID = st.next();
304 if (dist != nullptr) {
305 const double distProb = ((int)probs.size() > probIndex ? probs[probIndex] : 1.) / dist->getOverallProb();
306 std::vector<double>::const_iterator probIt = dist->getProbs().begin();
307 for (MSVehicleType* const type : dist->getVals()) {
308 myCurrentVTypeDistribution->add(type, distProb * *probIt);
309 probIt++;
310 }
311 } else {
313 if (type == nullptr) {
314 throw ProcessError("Unknown vtype '" + vtypeID + "' in distribution '" + myCurrentVTypeDistributionID + "'.");
315 }
316 const double prob = ((int)probs.size() > probIndex ? probs[probIndex] : type->getDefaultProbability());
317 myCurrentVTypeDistribution->add(type, prob);
318 }
319 probIndex++;
320 }
321 if (probs.size() > 0 && probIndex != (int)probs.size()) {
322 WRITE_WARNING("Got " + toString(probs.size()) + " probabilities for " + toString(probIndex) +
323 " types in vTypeDistribution '" + myCurrentVTypeDistributionID + "'");
324 }
325 }
326 }
327}
328
329
330void
332 if (myCurrentVTypeDistribution != nullptr) {
333 if (MSGlobals::gStateLoaded && MSNet::getInstance()->getVehicleControl().hasVTypeDistribution(myCurrentVTypeDistributionID)) {
336 return;
337 }
340 throw ProcessError(TLF("Vehicle type distribution '%' is empty.", myCurrentVTypeDistributionID));
341 }
342 if (!MSNet::getInstance()->getVehicleControl().addVTypeDistribution(myCurrentVTypeDistributionID, myCurrentVTypeDistribution)) {
344 throw ProcessError(TLF("Another vehicle type (or distribution) with the id '%' exists.", myCurrentVTypeDistributionID));
345 }
347 }
348}
349
350
351void
355 // check whether the id is really necessary
356 std::string rid;
357 if (myCurrentRouteDistribution != nullptr) {
359 rid = "distribution '" + myCurrentRouteDistributionID + "'";
360 } else if (myVehicleParameter != nullptr) {
361 // ok, a vehicle is wrapping the route,
362 // we may use this vehicle's id as default
363 myActiveRouteID = "!" + myVehicleParameter->id; // !!! document this
364 if (attrs.hasAttribute(SUMO_ATTR_ID)) {
365 WRITE_WARNINGF(TL("Ids of internal routes are ignored (vehicle '%')."), myVehicleParameter->id);
366 }
367 } else {
368 bool ok = true;
369 myActiveRouteID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok, false);
370 if (!ok) {
371 return;
372 }
373 rid = "'" + myActiveRouteID + "'";
374 }
375 if (myVehicleParameter != nullptr) { // have to do this here for nested route distributions
376 rid = "for vehicle '" + myVehicleParameter->id + "'";
377 }
378 bool ok = true;
379 if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
380 MSEdge::parseEdgesList(attrs.get<std::string>(SUMO_ATTR_EDGES, myActiveRouteID.c_str(), ok), myActiveRoute, rid);
381 }
382 myActiveRouteRefID = attrs.getOpt<std::string>(SUMO_ATTR_REFID, myActiveRouteID.c_str(), ok, "");
384 throw ProcessError(TLF("Invalid reference to route '%' in route %.", myActiveRouteRefID, rid));
385 }
388 myActiveRouteRepeat = attrs.getOpt<int>(SUMO_ATTR_REPEAT, myActiveRouteID.c_str(), ok, 0);
392 // handle obsolete attribute name
394 myActiveRoutePermanent = attrs.getOpt<bool>(SUMO_ATTR_STATE, myActiveRouteID.c_str(), ok, false);
395 if (attrs.hasAttribute(SUMO_ATTR_PERIOD)) {
396 WRITE_WARNING(TL("Attribute 'period' is deprecated for route. Use 'cycleTime' instead."));
397 }
398 myCurrentCosts = attrs.getOpt<double>(SUMO_ATTR_COST, myActiveRouteID.c_str(), ok, -1);
399 if (ok && myCurrentCosts != -1 && myCurrentCosts < 0) {
400 WRITE_WARNING(TLF("Invalid cost for route '%'.", myActiveRouteID));
401 }
402}
403
404
405void
407 // Currently unused
408}
409
410
411void
413 // Currently unused
414}
415
416
417void
419 // Currently unsued
420}
421
422
423void
424MSRouteHandler::closeRoute(const bool mayBeDisconnected) {
425 std::string type = "vehicle";
426 if (mayBeDisconnected) {
428 type = "flow";
429 } else {
430 type = "trip";
431 }
432 }
433
434 try {
435 const bool mustReroute = myActiveRoute.size() == 0 && myActiveRouteStops.size() != 0;
436 if (mustReroute) {
437 // implicit route from stops
439 myActiveRoute.push_back(MSEdge::dictionary(stop.edge));
440 }
441 }
442 if (myActiveRoute.size() == 0) {
443 delete myActiveRouteColor;
444 myActiveRouteColor = nullptr;
445 if (myActiveRouteRefID != "" && myCurrentRouteDistribution != nullptr) {
447 if (route != nullptr) {
449 }
450 myActiveRouteID = "";
452 return;
453 }
454 if (myVehicleParameter != nullptr) {
455 throw ProcessError("The route for " + type + " '" + myVehicleParameter->id + "' has no edges.");
456 } else {
457 throw ProcessError(TLF("Route '%' has no edges.", myActiveRouteID));
458 }
459 }
460 if (myActiveRoute.size() == 1 && myActiveRoute.front()->isTazConnector()) {
461 throw ProcessError("The routing information for " + type + " '" + myVehicleParameter->id + "' is insufficient.");
462 }
463 if (myActiveRouteRepeat > 0) {
464 // duplicate route
466 auto tmpStops = myActiveRouteStops;
467
470 std::string errSuffix = ".";
471 if (myVehicleParameter != nullptr) {
474 if (vtype != nullptr) {
475 vClass = vtype->getVehicleClass();
476 errSuffix = TLF(" for vehicle '%' with vClass %.", myVehicleParameter->id, getVehicleClassNames(vClass));
477 }
478 }
479 if (myActiveRoute.size() > 0 && !myActiveRoute.back()->isConnectedTo(*myActiveRoute.front(), vClass)) {
480 if (tmpStops.size() == 0 || tmpStops.back().jump < 0) {
481 throw ProcessError(TLF("Disconnected route '%' when repeating. Last edge '%' is not connected to first edge '%'%",
482 myActiveRouteID, myActiveRoute.back()->getID(), myActiveRoute.front()->getID(), errSuffix));
483 }
484 }
485 }
486 for (int i = 0; i < myActiveRouteRepeat; i++) {
487 myActiveRoute.insert(myActiveRoute.begin(), tmpEdges.begin(), tmpEdges.end());
488 for (SUMOVehicleParameter::Stop stop : tmpStops) {
489 if (stop.until > 0) {
490 if (myActiveRoutePeriod <= 0) {
491 const std::string description = myVehicleParameter != nullptr
492 ? "for " + type + " '" + myVehicleParameter->id + "'"
493 : "'" + myActiveRouteID + "'";
494 throw ProcessError(TLF("Cannot repeat stops with 'until' in route % because no cycleTime is defined.", description));
495 }
496 stop.until += myActiveRoutePeriod * (i + 1);
497 }
498 if (stop.arrival > 0) {
499 if (myActiveRoutePeriod <= 0) {
500 const std::string description = myVehicleParameter != nullptr
501 ? "for " + type + " '" + myVehicleParameter->id + "'"
502 : "'" + myActiveRouteID + "'";
503 throw ProcessError(TLF("Cannot repeat stops with 'arrival' in route % because no cycleTime is defined.", description));
504 }
505 stop.arrival += myActiveRoutePeriod * (i + 1);
506 }
507 stop.index = STOP_INDEX_REPEAT;
508 myActiveRouteStops.push_back(stop);
509 }
510 }
511 if (myActiveRouteStops.size() > 0) {
512 // never jump on the last stop of a repeating route
513 myActiveRouteStops.back().jump = -1;
514 }
515 }
516 MSRoute* const route = new MSRoute(myActiveRouteID, myActiveRoute,
521 route->setCosts(myCurrentCosts);
522 route->setReroute(mustReroute);
523 myActiveRoute.clear();
524 ConstMSRoutePtr constRoute = std::shared_ptr<const MSRoute>(route);
525 if (!MSRoute::dictionary(myActiveRouteID, constRoute)) {
527 if (myVehicleParameter != nullptr) {
528 if (MSNet::getInstance()->getVehicleControl().getVehicle(myVehicleParameter->id) == nullptr) {
529 throw ProcessError("Another route for " + type + " '" + myVehicleParameter->id + "' exists.");
530 } else {
531 throw ProcessError(TLF("A vehicle with id '%' already exists.", myVehicleParameter->id));
532 }
533 } else {
534 throw ProcessError(TLF("Another route (or distribution) with the id '%' exists.", myActiveRouteID));
535 }
536 }
537 } else {
538 if (myCurrentRouteDistribution != nullptr) {
540 }
541 }
542 myActiveRouteID = "";
543 myActiveRouteColor = nullptr;
544 myActiveRouteStops.clear();
546 } catch (ProcessError&) {
548 throw;
549 }
550}
551
552
553void
555 // check whether the id is really necessary
556 if (myVehicleParameter != nullptr) {
557 // ok, a vehicle is wrapping the route,
558 // we may use this vehicle's id as default
559 myCurrentRouteDistributionID = "!" + myVehicleParameter->id; // !!! document this
560 // we have to record this or we cannot remove the distribution later
562 } else {
563 bool ok = true;
564 myCurrentRouteDistributionID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
565 if (!ok) {
566 return;
567 }
568 }
570 std::vector<double> probs;
571 if (attrs.hasAttribute(SUMO_ATTR_PROBS)) {
572 bool ok = true;
573 StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_PROBS, myCurrentRouteDistributionID.c_str(), ok));
574 while (st.hasNext()) {
575 probs.push_back(StringUtils::toDoubleSecure(st.next(), 1.0));
576 }
577 }
578 if (attrs.hasAttribute(SUMO_ATTR_ROUTES)) {
579 bool ok = true;
580 StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_ROUTES, myCurrentRouteDistributionID.c_str(), ok));
581 int probIndex = 0;
582 while (st.hasNext()) {
583 std::string routeID = st.next();
585 if (route == nullptr) {
586 throw ProcessError("Unknown route '" + routeID + "' in distribution '" + myCurrentRouteDistributionID + "'.");
587 }
588 const double prob = ((int)probs.size() > probIndex ? probs[probIndex] : 1.0);
589 myCurrentRouteDistribution->add(route, prob, false);
590 probIndex++;
591 }
592 if (probs.size() > 0 && probIndex != (int)probs.size()) {
593 WRITE_WARNING("Got " + toString(probs.size()) + " probabilities for " + toString(probIndex) +
594 " routes in routeDistribution '" + myCurrentRouteDistributionID + "'");
595 }
596 }
597}
598
599
600void
602 if (myCurrentRouteDistribution != nullptr) {
603 const bool haveSameID = MSRoute::dictionary(myCurrentRouteDistributionID, &myParsingRNG) != nullptr;
604 if (MSGlobals::gStateLoaded && haveSameID) {
607 return;
608 }
609 if (haveSameID) {
611 throw ProcessError(TLF("Another route (or distribution) with the id '%' exists.", myCurrentRouteDistributionID));
612 }
615 throw ProcessError(TLF("Route distribution '%' is empty.", myCurrentRouteDistributionID));
616 }
619 }
620}
621
622
623void
625 // get nested route
626 const std::string embeddedRouteID = "!" + myVehicleParameter->id;
627 ConstMSRoutePtr route = nullptr;
628 if (myReplayRerouting) {
630 if (rDist != nullptr && rDist->getVals().size() > 0) {
631 route = rDist->getVals().front();
632 }
633 }
634 if (route == nullptr) {
635 route = MSRoute::dictionary(embeddedRouteID, &myParsingRNG);
636 }
639 // let's check whether this vehicle had to depart before the simulation starts
642 if (route != nullptr && route->getID() == embeddedRouteID) {
643 route->checkRemoval();
644 }
645 return;
646 }
647 }
648
649 // get the vehicle's type
650 MSVehicleType* vtype = nullptr;
651
652 try {
653 if (myVehicleParameter->vtypeid != "") {
654 vtype = vehControl.getVType(myVehicleParameter->vtypeid, &myParsingRNG);
655 if (vtype == nullptr) {
656 throw ProcessError("The vehicle type '" + myVehicleParameter->vtypeid + "' for vehicle '" + myVehicleParameter->id + "' is not known.");
657 }
658 if (vtype->getVehicleClass() == SVC_PEDESTRIAN) {
659 WRITE_WARNINGF(TL("Vehicle type '%' with vClass=pedestrian should only be used for persons and not for vehicle '%'."), vtype->getID(), myVehicleParameter->id);
660 }
661 } else {
662 // there should be one (at least the default one)
663 vtype = vehControl.getVType(DEFAULT_VTYPE_ID, &myParsingRNG);
664 }
666 // if the route id was given, prefer that one
667 if (route != nullptr && !myAmLoadingState) {
668 WRITE_WARNINGF(TL("Ignoring child element 'route' for vehicle '%' because attribute 'route' is set."), myVehicleParameter->id);
669 }
671 }
672 if (route == nullptr) {
673 // nothing found? -> error
674 if (myVehicleParameter->routeid != "") {
675 throw ProcessError("The route '" + myVehicleParameter->routeid + "' for vehicle '" + myVehicleParameter->id + "' is not known.");
676 } else {
677 throw ProcessError(TLF("Vehicle '%' has no route.", myVehicleParameter->id));
678 }
679 }
680 myActiveRouteID = "";
681
682 } catch (ProcessError&) {
684 throw;
685 }
686 if (route->mustReroute()) {
688 if (myVehicleParameter->stops.size() > 0) {
689 route = addVehicleStopsToImplicitRoute(route, false);
690 }
691 }
695 myVehicleParameter->departEdge >= (int)route->getEdges().size()) {
696 throw ProcessError("Vehicle '" + myVehicleParameter->id + "' has invalid departEdge index "
697 + toString(myVehicleParameter->departEdge) + " for route with " + toString(route->getEdges().size()) + " edges.");
698 }
699 }
703 myVehicleParameter->arrivalEdge >= (int)route->getEdges().size()) {
704 throw ProcessError("Vehicle '" + myVehicleParameter->id + "' has invalid arrivalEdge index "
705 + toString(myVehicleParameter->arrivalEdge) + " for route with " + toString(route->getEdges().size()) + " edges.");
706 }
707 }
708
709 if (route->getEdges().size() == 1
714 WRITE_WARNINGF(TL("Vehicle '%' ignores unreachable arrivalPos %."),
717 }
718
719 // try to build the vehicle
720 SUMOVehicle* vehicle = nullptr;
721 if (vehControl.getVehicle(myVehicleParameter->id) == nullptr) {
723 try {
724 vehicle = vehControl.buildVehicle(myVehicleParameter, route, vtype, !MSGlobals::gCheckRoutes, source, !myAmLoadingState);
725 } catch (const ProcessError& e) {
726 myVehicleParameter = nullptr;
728 WRITE_WARNING(e.what());
729 vehControl.deleteVehicle(vehicle, true);
730 myVehicleParameter = nullptr;
731 vehicle = nullptr;
732 return;
733 } else {
734 throw;
735 }
736 }
737 const SUMOTime origDepart = myVehicleParameter->depart;
738 // maybe we do not want this vehicle to be inserted due to scaling
739 int quota = myAmLoadingState ? 1 : vehControl.getQuota(vehControl.getScale() * vtype->getParameter().scale);
740 if (quota > 0) {
743 vehControl.addVehicle(myVehicleParameter->id, vehicle);
744 if (myReplayRerouting) {
746 if (rDist != nullptr) {
747 for (int i = 0; i < (int)rDist->getVals().size() - 1; i++) {
748 SUMOTime replacedAt = rDist->getVals()[i]->getReplacedTime();
749 auto* cmd = new Command_RouteReplacement(vehicle->getID(), rDist->getVals()[i + 1]);
750 if (replacedAt >= 0 && replacedAt == myVehicleParameter->depart) {
751 // routing in the insertion step happens *after* insertion
753 } else {
755 }
756 }
757 }
758 }
759 int offset = 0;
760 for (int i = 1; i < quota; i++) {
763 }
765 newPars->id = myVehicleParameter->id + myScaleSuffix + toString(i + offset);
766 while (vehControl.getVehicle(newPars->id) != nullptr) {
767 offset += 1;
768 newPars->id = myVehicleParameter->id + myScaleSuffix + toString(i + offset);
769 }
772 // resample type
773 vtype = vehControl.getVType(myVehicleParameter->vtypeid, &myParsingRNG);
774 }
775 vehicle = vehControl.buildVehicle(newPars, route, vtype, !MSGlobals::gCheckRoutes, source, !myAmLoadingState);
776 vehControl.addVehicle(newPars->id, vehicle);
777 }
778 myVehicleParameter = nullptr;
779 } else {
780 // persons and containers that depart triggered by this vehicle are discarded as well (#18596)
782 vehControl.deleteVehicle(vehicle, true);
783 myVehicleParameter = nullptr;
784 vehicle = nullptr;
785 }
786 } else {
787 // strange: another vehicle with the same id already exists
789 // and was not loaded while loading a simulation state
790 // -> error
791 std::string veh_id = myVehicleParameter->id;
793 std::string scaleWarning = "";
794 if (vehControl.getScale() * vtype->getParameter().scale > 1 && veh_id.find(myScaleSuffix) != std::string::npos) {
795 scaleWarning = "\n (Possibly duplicate id due to using option --scale. Set option --scale-suffix to prevent this)";
796 }
797 throw ProcessError("Another vehicle with the id '" + veh_id + "' exists." + scaleWarning);
798 } else {
799 // ok, it seems to be loaded previously while loading a simulation state
800 vehicle = nullptr;
801 }
802 }
803 // check whether the vehicle shall be added directly to the network or
804 // shall stay in the internal buffer
805 if (vehicle != nullptr) {
808 }
809 }
810}
811
812
815 // the route was defined without edges and its current edges were
816 // derived from route-stops.
817 // We may need to add additional edges for the vehicle-stops
819 assert(route->getStops().size() > 0);
820 ConstMSEdgeVector edges = route->getEdges();
822 MSEdge* stopEdge = MSEdge::dictionary(stop.edge);
823 if (stop.index == 0) {
824 if (edges.front() != stopEdge ||
825 route->getStops().front().endPos < stop.endPos) {
826 edges.insert(edges.begin(), stopEdge);
827 }
828 } else if (stop.index == STOP_INDEX_END) {
829 if (edges.back() != stopEdge ||
830 route->getStops().back().endPos > stop.endPos) {
831 edges.push_back(stopEdge);
832 }
833 } else {
834 WRITE_WARNINGF(TL("Could not merge vehicle stops for vehicle '%' into implicitly defined route '%'"), myVehicleParameter->id, route->getID());
835 }
836 }
837 ConstMSRoutePtr newRoute = std::make_shared<MSRoute>("!" + myVehicleParameter->id, edges,
838 isPermanent, new RGBColor(route->getColor()), route->getStops());
839 if (!MSRoute::dictionary(newRoute->getID(), newRoute)) {
840 throw ProcessError("Could not adapt implicit route for " + std::string(isPermanent ? "flow" : "vehicle") + " '" + myVehicleParameter->id + "'");
841 }
842 return newRoute;
843}
844
845
846void
848 try {
849 if (myActiveTransportablePlan->size() == 0) {
850 std::string error = myActiveTypeName + " '" + myVehicleParameter->id + "' has no plan.";
851 error[0] = (char)::toupper((char)error[0]);
852 throw ProcessError(error);
853 }
854 // let's check whether this transportable had to depart before the simulation starts
858 return;
859 }
860 // type existence has been checked on opening
863 && type->getVehicleClass() != SVC_PEDESTRIAN
865 WRITE_WARNINGF(TL("Person '%' receives type '%' which implicitly uses unsuitable vClass '%'."), myVehicleParameter->id, type->getID(), toString(type->getVehicleClass()));
866 }
869 if (created > 0) {
871 } else {
873 }
874 } catch (ProcessError&) {
876 throw;
877 }
878}
879
880
881void
885
886
887void
891
892
893void
897
898
899void
903
904
905void
907 try {
908 const std::string fid = myVehicleParameter->id;
909 if (myActiveTransportablePlan->size() == 0) {
910 throw ProcessError(myActiveTypeName + "Flow '" + fid + "' has no plan.");
911 }
912 // let's check whether this transportable (person/container) had to depart before the simulation starts
916 return;
917 }
918 // instantiate all persons/containers of this flow
919 int i = 0;
921 std::string baseID = myVehicleParameter->id;
924 throw ProcessError("probabilistic " + myActiveTypeName + "Flow '" + fid + "' must specify end time");
925 } else {
928 // type existence has been checked on opening
930 addFlowTransportable(t, type, baseID, i++);
931 }
932 }
933 }
934 } else {
937 // poisson: randomize first depart
939 }
940 for (; i < myVehicleParameter->repetitionNumber && (myVehicleParameter->repetitionNumber != std::numeric_limits<long long int>::max()
942 // type existence has been checked on opening
946 }
947 }
949 } catch (ProcessError&) {
951 throw;
952 }
954}
955
956
957int
958MSRouteHandler::addFlowTransportable(SUMOTime depart, MSVehicleType* type, const std::string& baseID, int i) {
959 try {
960 int numCreated = 0;
961 MSNet* const net = MSNet::getInstance();
964 //MSTransportableControl& pc = net->getPersonControl();
965 const int quota = vc.getQuota(vc.getScale() * type->getParameter().scale, tc.getLoadedNumber());
966 if (quota == 0) {
967 tc.addDiscarded();
968 }
969 for (int j = 0; j < quota; j++) {
970 if (i > 0 || j > 0) {
971 // copy parameter and plan because the transportable takes over responsibility
973 *copyParam = *myVehicleParameter;
974 myVehicleParameter = copyParam;
976 MSStage* lastStage = nullptr;
977 for (MSStage* const s : *myActiveTransportablePlan) {
978 copyPlan->push_back(s->clone());
979 if (lastStage != nullptr && s->getStageType() == MSStageType::WALKING && lastStage->getDestinationStop() != nullptr) {
980 MSStageMoving* walk = static_cast<MSStageMoving*>(copyPlan->back());
981 walk->setDepartPos(lastStage->getDestinationStop()->getAccessPos(walk->getEdge(), &myParsingRNG));
982 }
983 lastStage = s;
984 }
985 myActiveTransportablePlan = copyPlan;
987 const double initialDepartPos = RandHelper::rand(myActiveTransportablePlan->front()->getDestination()->getLength(), &myParsingRNG);
988 myActiveTransportablePlan->front()->setArrivalPos(initialDepartPos);
989 }
990 }
991 myVehicleParameter->id = (baseID
992 + (i >= 0 ? "." + toString(i) : "")
993 + (j > 0 ? "." + toString(j) : ""));
994 if (MSGlobals::gStateLoaded && tc.get(myVehicleParameter->id) != nullptr) {
995 return numCreated;
996 }
1001 numCreated++;
1002 if (!tc.add(transportable)) {
1003 std::string error = "Another " + myActiveTypeName + " with the id '" + myVehicleParameter->id + "' exists.";
1004 delete transportable;
1006 throw ProcessError(error);
1007 } else if ((net->hasPersons() && net->getPersonControl().get(myVehicleParameter->id) != nullptr)
1008 && (net->hasContainers() && net->getContainerControl().get(myVehicleParameter->id) != nullptr)) {
1009 WRITE_WARNINGF(TL("There exists a person and a container with the same id '%'. Starting with SUMO 1.9.0 this is an error."), myVehicleParameter->id);
1010 }
1011 }
1012 return numCreated;
1013 } catch (ProcessError&) {
1015 throw;
1016 }
1017}
1018
1019
1020void
1022 MSVehicleType* vehType = nullptr;
1023 if (myCurrentVTypeRef.empty()) {
1025 vehType->check();
1026 if (!MSNet::getInstance()->getVehicleControl().addVType(vehType)) {
1027 const std::string id = vehType->getID();
1028 delete vehType;
1030 throw ProcessError(TLF("Another vehicle type (or distribution) with the id '%' exists.", id));
1031 }
1032 }
1033 }
1034 if (myCurrentVTypeDistribution != nullptr) {
1035 if (!myCurrentVTypeRef.empty()) {
1037 if (dist != nullptr) {
1038 const double distProb = (myCurrentVTypeProbability >= 0 ? myCurrentVTypeProbability : 1) / dist->getOverallProb();
1039 std::vector<double>::const_iterator probIt = dist->getProbs().begin();
1040 for (MSVehicleType* const type : dist->getVals()) {
1041 myCurrentVTypeDistribution->add(type, distProb * *probIt);
1042 probIt++;
1043 }
1044 return;
1045 } else {
1047 }
1048 }
1049 double probability = myCurrentVTypeProbability >= 0 ? myCurrentVTypeProbability : vehType->getDefaultProbability();
1050 myCurrentVTypeDistribution->add(vehType, probability);
1051 }
1052}
1053
1054
1055void
1059 delete myVehicleParameter;
1060 myVehicleParameter = nullptr;
1061 return;
1062 }
1063 // let's check whether vehicles had to depart before the simulation starts
1066 const SUMOTime offsetToBegin = string2time(OptionsCont::getOptions().getString("begin")) - myVehicleParameter->depart;
1067 while (myVehicleParameter->repetitionTotalOffset < offsetToBegin) {
1070 delete myVehicleParameter;
1071 myVehicleParameter = nullptr;
1072 return;
1073 }
1074 }
1075 }
1076 if (MSNet::getInstance()->getVehicleControl().getVType(myVehicleParameter->vtypeid, &myParsingRNG) == nullptr) {
1077 throw ProcessError("The vehicle type '" + myVehicleParameter->vtypeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
1078 }
1081 closeRoute(true);
1082 }
1084 if (route == nullptr) {
1085 throw ProcessError("The route '" + myVehicleParameter->routeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
1086 }
1087 if (route->mustReroute()) {
1089 if (myVehicleParameter->stops.size() > 0) {
1090 route = addVehicleStopsToImplicitRoute(route, true);
1091 myVehicleParameter->routeid = route->getID();
1092 }
1093 }
1097 myVehicleParameter->departEdge >= (int)route->getEdges().size()) {
1098 throw ProcessError("Flow '" + myVehicleParameter->id + "' has invalid departEdge index "
1099 + toString(myVehicleParameter->departEdge) + " for route with " + toString(route->getEdges().size()) + " edges.");
1100 }
1101 }
1105 myVehicleParameter->arrivalEdge >= (int)route->getEdges().size()) {
1106 throw ProcessError("Flow '" + myVehicleParameter->id + "' has invalid arrivalEdge index "
1107 + toString(myVehicleParameter->arrivalEdge) + " for route with " + toString(route->getEdges().size()) + " edges.");
1108 }
1109 }
1110 myActiveRouteID = "";
1111
1112 // check whether the vehicle shall be added directly to the network or
1113 // shall stay in the internal buffer
1115 if (MSNet::getInstance()->getInsertionControl().addFlow(myVehicleParameter)) {
1117 } else {
1119 delete myVehicleParameter;
1120 } else {
1121 throw ProcessError(TLF("Another flow with the id '%' exists.", myVehicleParameter->id));
1122 }
1123 }
1124 }
1125 myVehicleParameter = nullptr;
1126}
1127
1128
1129void
1135
1136void
1140
1141void
1145
1146void
1148 if (myVehicleParameter == nullptr) {
1149 throw ProcessError(TLF("Cannot define % stage without %.", toString(modeTag), toString(modeTag)));
1150 }
1151 try {
1152 const std::string mode = modeTag == SUMO_TAG_RIDE ? "ride" : "transport";
1153 std::string agent = "person";
1154 std::string stop = "bus stop";
1156 agent = "container";
1157 stop = "container stop";
1158 }
1159
1160 if (!((myActiveType == ObjectTypeEnum::PERSON && modeTag == SUMO_TAG_RIDE) ||
1162 throw ProcessError("Found " + mode + " inside " + agent + " element");
1163 }
1164 const std::string aid = myVehicleParameter->id;
1165 bool ok = true;
1166 const MSEdge* from = nullptr;
1167 const std::string desc = attrs.getOpt<std::string>(SUMO_ATTR_LINES, aid.c_str(), ok, LINE_ANY);
1168 StringTokenizer st(desc);
1169 MSStoppingPlace* s = retrieveStoppingPlace(attrs, " in " + agent + " '" + aid + "'");
1170 MSEdge* to = nullptr;
1171 if (s != nullptr) {
1172 to = &s->getLane().getEdge();
1173 }
1174 double arrivalPos = attrs.getOpt<double>(SUMO_ATTR_ARRIVALPOS, aid.c_str(), ok,
1175 s == nullptr ? std::numeric_limits<double>::infinity() : s->getEndLanePosition());
1176
1177 const SUMOVehicleParameter* startVeh = nullptr;
1178 const MSEdge* startVehFrom = nullptr;
1180 if (st.size() != 1) {
1181 throw ProcessError("Triggered departure for " + agent + " '" + aid + "' requires a unique lines value.");
1182 }
1183 // agent starts
1185 const std::string vehID = st.front();
1186 SUMOVehicle* sVeh = vehControl.getVehicle(vehID);
1187 if (sVeh == nullptr) {
1188 if (MSNet::getInstance()->hasFlow(vehID)) {
1189 startVeh = MSNet::getInstance()->getInsertionControl().getFlowPars(vehID);
1190 if (startVeh != nullptr) {
1191 ConstMSRoutePtr const route = MSRoute::dictionary(startVeh->routeid);
1192 startVehFrom = route->getEdges().front();
1193 // flows are inserted at the end of the time step so we
1194 // do delay the pedestrian event by one time step
1195 myVehicleParameter->depart = startVeh->depart + DELTA_T;
1197 }
1198 }
1199 } else {
1200 startVeh = &sVeh->getParameter();
1201 startVehFrom = sVeh->getRoute().getEdges().front();
1202 myVehicleParameter->depart = startVeh->depart;
1203 }
1204 if (startVeh == nullptr) {
1205 if (myScaledVehicles.count(vehID) != 0) {
1206 WRITE_WARNINGF(TL("Skipping % '%' with triggered departure because vehicle '%' was removed by scaling."), agent, aid, vehID);
1207 } else if (mySkippedVehicles.count(vehID) == 0) {
1208 throw ProcessError("Unknown vehicle '" + vehID + "' in triggered departure for " + agent + " '" + aid + "'.");
1209 }
1210 // we cannot simply throw here because we need to parse the rest of the person (just to discard it)
1211 from = MSEdge::getAllEdges().front(); // a dummy edge to keep parsing active
1212 } else if (startVeh->departProcedure == DepartDefinition::TRIGGERED) {
1213 throw ProcessError("Cannot use triggered vehicle '" + vehID + "' in triggered departure for " + agent + " '" + aid + "'.");
1214 }
1215 }
1216
1217 if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
1218 const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, aid.c_str(), ok);
1219 from = MSEdge::dictionary(fromID);
1220 if (from == nullptr) {
1221 throw ProcessError("The from edge '" + fromID + "' within a " + mode + " of " + agent + " '" + aid + "' is not known.");
1222 }
1223 if (!myActiveTransportablePlan->empty() && myActiveTransportablePlan->back()->getDestination() != from) {
1224 const bool stopWithAccess = (myActiveTransportablePlan->back()->getDestinationStop() != nullptr
1225 && &myActiveTransportablePlan->back()->getDestinationStop()->getLane().getEdge() == from);
1226 const bool transferAtJunction = (from->getFromJunction() == myActiveTransportablePlan->back()->getDestination()->getFromJunction()
1227 || from->getFromJunction() == myActiveTransportablePlan->back()->getDestination()->getToJunction());
1228 if (!(stopWithAccess || transferAtJunction)) {
1229 throw ProcessError("Disconnected plan for " + agent + " '" + aid +
1230 "' (edge '" + fromID + "' != edge '" + myActiveTransportablePlan->back()->getDestination()->getID() + "').");
1231 }
1232 }
1233 if (startVeh != nullptr && startVehFrom != from) {
1234 throw ProcessError("Disconnected plan for triggered " + agent + " '" + aid +
1235 "' (edge '" + fromID + "' != edge '" + startVehFrom->getID() + "').");
1236 }
1237 } else if (startVeh != nullptr) {
1238 from = startVehFrom;
1239 }
1240 if (myActiveTransportablePlan->empty()) {
1241 if (from == nullptr) {
1242 throw ProcessError("The start edge for " + agent + " '" + aid + "' is not known.");
1243 } else {
1245 from, nullptr, -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start", true));
1246 }
1247 }
1248 // given attribute may override given stopping place due access requirements
1249 if (to == nullptr || attrs.hasAttribute(SUMO_ATTR_TO)) {
1250 const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, aid.c_str(), ok);
1251 to = MSEdge::dictionary(toID);
1252 if (to == nullptr) {
1253 throw ProcessError("The to edge '" + toID + "' within a " + mode + " of " + agent + " '" + aid + "' is not known.");
1254 }
1255 }
1256 const std::string group = attrs.getOpt<std::string>(SUMO_ATTR_GROUP, aid.c_str(), ok, OptionsCont::getOptions().getString("persontrip.default.group"));
1257 const std::string intendedVeh = attrs.getOpt<std::string>(SUMO_ATTR_INTENDED, nullptr, ok, "");
1258 const SUMOTime intendedDepart = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DEPART, nullptr, ok, -1);
1259 arrivalPos = SUMOVehicleParameter::interpretEdgePos(arrivalPos, to->getLength(), SUMO_ATTR_ARRIVALPOS, agent + " '" + aid + "' takes a " + mode + " to edge '" + to->getID() + "'");
1260 MSStageDriving* stage = new MSStageDriving(from, to, s, arrivalPos, 0.0, st.getVector(), group, intendedVeh, intendedDepart);
1261 // for loading from saved state
1262 stage->setDeparted(attrs.getOptSUMOTimeReporting(SUMO_ATTR_STARTED, nullptr, ok, -1));
1263 stage->setEnded(attrs.getOptSUMOTimeReporting(SUMO_ATTR_ENDED, nullptr, ok, -1));
1264 stage->setVehicleID(attrs.getOpt<std::string>(SUMO_ATTR_VEHICLE, nullptr, ok, ""));
1265 stage->setVehicleDistance(attrs.getOpt<double>(SUMO_ATTR_ROUTELENGTH, nullptr, ok, -1));
1266 myActiveTransportablePlan->push_back(stage);
1267 myParamStack.push_back(stage);
1268 } catch (ProcessError&) {
1270 throw;
1271 }
1272}
1273
1275MSRouteHandler::retrieveStoppingPlace(const SUMOSAXAttributes& attrs, const std::string& errorSuffix, SUMOVehicleParameter::Stop* stopParam) {
1276 MSStoppingPlace* toStop = nullptr;
1278 std::string id;
1279 bool ok = SUMOVehicleParserHelper::parseStopTag(attrs, stopParam, tag, id);
1280 if (tag != SUMO_TAG_NOTHING) {
1281 toStop = MSNet::getInstance()->getStoppingPlace(id, tag);
1282 if (toStop == nullptr) {
1283 ok = false;
1284 WRITE_ERROR(TLF("The % '%' is not known%.", toString(tag), id, errorSuffix));
1285 }
1286 }
1287 if (!ok && MSGlobals::gCheckRoutes) {
1288 throw ProcessError(TLF("Invalid stop definition%.", errorSuffix));
1289 }
1290 return toStop;
1291}
1292
1295 Parameterised* result = nullptr;
1296 try {
1297 std::string errorSuffix;
1299 errorSuffix = " in person '" + myVehicleParameter->id + "'";
1301 errorSuffix = " in container '" + myVehicleParameter->id + "'";
1302 } else if (myVehicleParameter != nullptr) {
1303 errorSuffix = " in vehicle '" + myVehicleParameter->id + "'";
1304 } else {
1305 errorSuffix = " in route '" + myActiveRouteID + "'";
1306 }
1308 bool ok = parseStop(stop, attrs, errorSuffix, MsgHandler::getErrorInstance());
1309 if (!ok) {
1311 throw ProcessError();
1312 }
1313 return result;
1314 }
1315 const MSEdge* edge = nullptr;
1316 // patch chargingStation stop on a parkingArea
1317 if (stop.chargingStation != "") {
1319 const MSParkingArea* pa = cs->getParkingArea();
1320 if (pa != nullptr) {
1321 stop.parkingarea = pa->getID();
1323 }
1324 }
1325 MSStoppingPlace* toStop = retrieveStoppingPlace(attrs, errorSuffix, &stop);
1326 // if one of the previous stops is defined
1327 if (toStop != nullptr) {
1328 const MSLane& l = toStop->getLane();
1329 stop.lane = l.getID();
1330 if ((stop.parametersSet & STOP_END_SET) == 0) {
1331 stop.endPos = toStop->getEndLanePosition();
1332 } else {
1333 stop.endPos = attrs.get<double>(SUMO_ATTR_ENDPOS, nullptr, ok);
1334 }
1335 stop.startPos = toStop->getBeginLanePosition();
1336 edge = &l.getEdge();
1337 } else {
1338 // no, the lane and the position should be given directly
1339 // get the lane
1340 stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, nullptr, ok, "");
1341 stop.edge = attrs.getOpt<std::string>(SUMO_ATTR_EDGE, nullptr, ok, "");
1342 if (ok && stop.edge != "") { // edge is given directly
1343 edge = MSEdge::dictionary(stop.edge);
1344 if (edge == nullptr || (edge->isInternal() && !MSGlobals::gUsingInternalLanes)) {
1345 throw ProcessError(TLF("The edge '%' for a stop is not known%.", stop.edge, errorSuffix));
1346 }
1347 } else if (ok && stop.lane != "") { // lane is given directly
1348 MSLane* stopLane = MSLane::dictionary(stop.lane);
1349 if (stopLane == nullptr) {
1350 // check for opposite-direction stop
1351 stopLane = MSBaseVehicle::interpretOppositeStop(stop);
1352 if (stopLane != nullptr) {
1353 edge = MSEdge::dictionary(stop.edge);
1354 }
1355 } else {
1356 edge = &stopLane->getEdge();
1357 }
1358 if (stopLane == nullptr || (stopLane->isInternal() && !MSGlobals::gUsingInternalLanes)) {
1359 throw ProcessError(TLF("The lane '%' for a stop is not known%.", stop.lane, errorSuffix));
1360 }
1361 } else if (ok && ((attrs.hasAttribute(SUMO_ATTR_X) && attrs.hasAttribute(SUMO_ATTR_Y))
1362 || (attrs.hasAttribute(SUMO_ATTR_LON) && attrs.hasAttribute(SUMO_ATTR_LAT)))) {
1363 Position pos;
1364 bool geo = false;
1365 if (attrs.hasAttribute(SUMO_ATTR_X) && attrs.hasAttribute(SUMO_ATTR_Y)) {
1366 pos = Position(attrs.get<double>(SUMO_ATTR_X, myVehicleParameter->id.c_str(), ok), attrs.get<double>(SUMO_ATTR_Y, myVehicleParameter->id.c_str(), ok));
1367 } else {
1368 pos = Position(attrs.get<double>(SUMO_ATTR_LON, myVehicleParameter->id.c_str(), ok), attrs.get<double>(SUMO_ATTR_LAT, myVehicleParameter->id.c_str(), ok));
1369 geo = true;
1370 }
1371 PositionVector positions;
1372 positions.push_back(pos);
1373 ConstMSEdgeVector geoEdges;
1375 auto& vc = MSNet::getInstance()->getVehicleControl();
1376 if (!vc.getVTypeDistribution(myVehicleParameter->vtypeid)) {
1377 MSVehicleType* const type = vc.getVType(myVehicleParameter->vtypeid, &myParsingRNG);
1378 if (type != nullptr) {
1379 vClass = type->getParameter().vehicleClass;
1380 }
1381 }
1382 parseGeoEdges(positions, geo, vClass, geoEdges, myVehicleParameter->id, true, ok, true);
1383 if (ok) {
1384 edge = geoEdges.front();
1385 if (geo) {
1387 }
1389 stop.endPos = edge->getLanes()[0]->getShape().nearest_offset_to_point2D(pos, false);
1390 } else {
1391 throw ProcessError(TLF("Could not map stop position '%' to the network%.", pos, errorSuffix));
1392 }
1393 } else {
1394 if (myActiveTransportablePlan && !myActiveTransportablePlan->empty()) { // use end of movement before
1395 toStop = myActiveTransportablePlan->back()->getDestinationStop();
1396 if (toStop != nullptr) { // use end of movement before definied as a stopping place
1397 edge = &toStop->getLane().getEdge();
1398 stop.lane = toStop->getLane().getID();
1399 stop.endPos = toStop->getEndLanePosition();
1400 stop.startPos = toStop->getBeginLanePosition();
1401 } else { // use end of movement before definied as lane/edge
1402 edge = myActiveTransportablePlan->back()->getDestination();
1403 stop.lane = edge->getLanes()[0]->getID();
1404 stop.endPos = myActiveTransportablePlan->back()->unspecifiedArrivalPos() ?
1406 stop.startPos = MAX2(0., stop.endPos - MIN_STOP_LENGTH);
1407 }
1408 } else {
1409 const std::string msg = TLF("A stop must be placed on a busStop, a chargingStation, an overheadWireSegment, a containerStop, a parkingArea, an edge or a lane%.", errorSuffix);
1411 throw ProcessError(msg);
1412 } else {
1413 WRITE_WARNING(msg);
1414 return result;
1415 }
1416 }
1417 }
1418 stop.endPos = attrs.getOpt<double>(SUMO_ATTR_ENDPOS, nullptr, ok, edge->getLength());
1419 if (attrs.hasAttribute(SUMO_ATTR_POSITION)) {
1420 WRITE_WARNINGF(TL("Deprecated attribute 'pos' in description of stop%."), errorSuffix);
1421 stop.endPos = attrs.getOpt<double>(SUMO_ATTR_POSITION, nullptr, ok, stop.endPos);
1422 }
1423 if (stop.endPos < 0) {
1424 stop.endPos += edge->getLength();
1425 }
1426 stop.startPos = attrs.getOpt<double>(SUMO_ATTR_STARTPOS, nullptr, ok, MAX2(0., stop.endPos - MIN_STOP_LENGTH));
1427 if (!myAmLoadingState) {
1428 const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, nullptr, ok, !attrs.hasAttribute(SUMO_ATTR_STARTPOS) && !attrs.hasAttribute(SUMO_ATTR_ENDPOS))
1430 if (!ok || (checkStopPos(stop.startPos, stop.endPos, edge->getLength(), 0, friendlyPos) != StopPos::STOPPOS_VALID)) {
1431 throw ProcessError(TLF("Invalid start or end position for stop on %'%.",
1432 stop.lane != "" ? ("lane '" + stop.lane) : ("edge '" + stop.edge), errorSuffix));
1433 }
1434 }
1435 }
1436 stop.edge = edge->getID();
1438 if (myActiveTransportablePlan->empty()) {
1439 double departPos = toStop == nullptr || myVehicleParameter->wasSet(VEHPARS_DEPARTPOS_SET)
1441 : (toStop->getBeginLanePosition() + toStop->getEndLanePosition()) / 2;
1443 edge, toStop, -1, myVehicleParameter->depart, departPos, "start", true));
1444 } else if (myActiveTransportablePlan->back()->getDestination() != edge) {
1445 if (myActiveTransportablePlan->back()->getDestination()->isTazConnector()) {
1446 myActiveTransportablePlan->back()->setDestination(edge, toStop);
1447 } else if (myActiveTransportablePlan->back()->getJumpDuration() < 0) {
1448 throw ProcessError(TLF("Disconnected plan for % '%' (%!=%).", myActiveTypeName, myVehicleParameter->id,
1449 edge->getID(), myActiveTransportablePlan->back()->getDestination()->getID()));
1450 }
1451 }
1452 // transporting veh stops somewhere
1453 else if (myActiveTransportablePlan->back()->getStageType() == MSStageType::WAITING
1455 const double start = SUMOVehicleParameter::interpretEdgePos(stop.startPos, edge->getLength(), SUMO_ATTR_STARTPOS, "stopping at " + edge->getID());
1456 const double end = SUMOVehicleParameter::interpretEdgePos(stop.endPos, edge->getLength(), SUMO_ATTR_ENDPOS, "stopping at " + edge->getID());
1457 const double prevAr = myActiveTransportablePlan->back()->getArrivalPos();
1458 if (start > prevAr + NUMERICAL_EPS || end < prevAr - NUMERICAL_EPS) {
1459 WRITE_WARNINGF(TL("Disconnected plan for % '%' (stop range %-% does not cover previous arrival position %)."),
1461 }
1462 }
1463 std::string actType = attrs.getOpt<std::string>(SUMO_ATTR_ACTTYPE, nullptr, ok, "");
1464 double pos = (stop.startPos + stop.endPos) / 2.;
1465 if (!myActiveTransportablePlan->empty() && myActiveTransportablePlan->back()->getJumpDuration() < 0) {
1466 pos = myActiveTransportablePlan->back()->unspecifiedArrivalPos() ?
1468 }
1469 myActiveTransportablePlan->push_back(new MSStageWaiting(edge, toStop, stop.duration, stop.until, pos, actType, false, stop.jump));
1470 result = myActiveTransportablePlan->back();
1471
1472 } else if (myVehicleParameter != nullptr) {
1473 myVehicleParameter->stops.push_back(stop);
1474 result = &myVehicleParameter->stops.back();
1475 } else {
1476 myActiveRouteStops.push_back(stop);
1477 result = &myActiveRouteStops.back();
1478 }
1479 if (myInsertStopEdgesAt >= 0) {
1480 //std::cout << " myInsertStopEdgesAt=" << myInsertStopEdgesAt << " edge=" << edge->getID() << " myRoute=" << toString(myActiveRoute) << "\n";
1481 if (edge->isInternal()) {
1482 if (myInsertStopEdgesAt > 0 && *(myActiveRoute.begin() + (myInsertStopEdgesAt - 1)) != edge->getNormalBefore()) {
1485 }
1488 } else {
1489 myActiveRoute.insert(myActiveRoute.begin() + myInsertStopEdgesAt, edge);
1491 }
1492 } else if (myHaveVia) {
1493 // vias were loaded, check for consistency
1494 if (std::find(myActiveRoute.begin(), myActiveRoute.end(), edge) == myActiveRoute.end()) {
1495 WRITE_WARNINGF(TL("Stop edge '%' missing in attribute 'via' for % '%'."),
1497 }
1498 }
1499 } catch (ProcessError&) {
1501 throw;
1502 }
1503 return result;
1504}
1505
1506
1507void
1508MSRouteHandler::parseWalkPositions(const SUMOSAXAttributes& attrs, const std::string& personID,
1509 const MSEdge* fromEdge, const MSEdge*& toEdge,
1510 double& departPos, double& arrivalPos, MSStoppingPlace*& bs,
1511 const MSStage* const lastStage, bool& ok) {
1512 try {
1513 const std::string description = "person '" + personID + "' walking from edge '" + fromEdge->getID() + "'";
1514
1515 if (attrs.hasAttribute(SUMO_ATTR_DEPARTPOS)) {
1516 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."));
1517 }
1518 departPos = 0.;
1519 if (lastStage != nullptr) {
1520 if (lastStage->getDestinationStop() != nullptr) {
1521 departPos = lastStage->getDestinationStop()->getAccessPos(fromEdge, &myParsingRNG);
1522 } else if (lastStage->getDestination() == fromEdge) {
1523 departPos = lastStage->getArrivalPos();
1524 } else if (lastStage->getDestination()->getToJunction() == fromEdge->getToJunction()) {
1525 departPos = fromEdge->getLength();
1526 }
1527 }
1528
1529 bs = retrieveStoppingPlace(attrs, " " + description);
1530 if (bs != nullptr) {
1531 const MSEdge* const arrivalEdge = toEdge != nullptr ? toEdge : &bs->getLane().getEdge();
1532 arrivalPos = bs->getAccessPos(arrivalEdge);
1533 if (arrivalPos < 0) {
1534 const std::string message = TLF("Bus stop '%' is not connected to arrival edge '%' for %.",
1535 bs->getID(), arrivalEdge->getID(), description);
1537 throw ProcessError(message);
1538 }
1539 WRITE_WARNINGF(TL("% Skipping this plan."), message);
1540 // The person or person flow is the parent of this stage.
1542 return;
1543 }
1545 const double length = toEdge != nullptr ? toEdge->getLength() : bs->getLane().getLength();
1546 const double arrPos = SUMOVehicleParserHelper::parseWalkPos(SUMO_ATTR_ARRIVALPOS, myHardFail, description, length,
1547 attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, description.c_str(), ok), &myParsingRNG);
1548 if (arrPos >= bs->getBeginLanePosition() && arrPos < bs->getEndLanePosition()) {
1549 arrivalPos = arrPos;
1550 } else {
1551 WRITE_WARNINGF(TL("Ignoring arrivalPos for % because it is outside the given stop '%'."), description, toString(SUMO_ATTR_BUS_STOP));
1552 arrivalPos = bs->getAccessPos(&bs->getLane().getEdge());
1553 }
1554 }
1555 } else {
1556 if (toEdge == nullptr) {
1557 throw ProcessError(TLF("No destination edge for %.", description));
1558 }
1561 attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, description.c_str(), ok), &myParsingRNG);
1562 } else {
1563 arrivalPos = toEdge->getLength() / 2.;
1564 }
1565 }
1566 } catch (ProcessError&) {
1568 throw;
1569 }
1570}
1571
1572
1573void
1575 if (myVehicleParameter == nullptr) {
1576 throw ProcessError(TL("Cannot define person stage without person."));
1577 }
1578 try {
1579 myActiveRoute.clear();
1580 bool ok = true;
1581 const char* const id = myVehicleParameter->id.c_str();
1582 const MSEdge* from = nullptr;
1583 const MSEdge* to = nullptr;
1586 const bool hasExplicitFrom = (attrs.hasAttribute(SUMO_ATTR_FROM) || attrs.hasAttribute(SUMO_ATTR_FROM_JUNCTION)
1589 if (hasExplicitFrom) {
1590 from = myActiveRoute.front();
1591 } else if (myActiveTransportablePlan->empty()) {
1592 throw ProcessError(TLF("Start edge not defined for person '%'.", myVehicleParameter->id));
1593 } else {
1594 from = myActiveTransportablePlan->back()->getDestination();
1595 }
1596 if (hasExplicitFrom && !myActiveTransportablePlan->empty()) {
1597 const MSEdge* const previousDestination = myActiveTransportablePlan->back()->getDestination();
1598 if (previousDestination != nullptr && previousDestination != from) {
1599 WRITE_WARNINGF(TL("Person '%' jumps from edge '%' to personTrip origin edge '%'."),
1600 id, previousDestination->getID(), from->getID());
1601 }
1602 }
1605 to = myActiveRoute.back();
1606 } // else, to may also be derived from stopping place
1607
1608 const SUMOTime duration = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DURATION, id, ok, -1);
1609 if (attrs.hasAttribute(SUMO_ATTR_DURATION) && duration <= 0) {
1610 throw ProcessError(TLF("Non-positive walking duration for '%'.", myVehicleParameter->id));
1611 }
1612
1613 double departPos = 0;
1614 double arrivalPos = 0;
1615 MSStoppingPlace* stoppingPlace = nullptr;
1616 parseWalkPositions(attrs, myVehicleParameter->id, from, to, departPos, arrivalPos, stoppingPlace, nullptr, ok);
1618 return;
1619 }
1620
1621 SVCPermissions modeSet = 0;
1622 if (attrs.hasAttribute(SUMO_ATTR_MODES)) {
1623 const std::string modes = attrs.getOpt<std::string>(SUMO_ATTR_MODES, id, ok, "");
1624 std::string errorMsg;
1625 // try to parse person modes
1626 if (!SUMOVehicleParameter::parsePersonModes(modes, "person", id, modeSet, errorMsg)) {
1627 throw InvalidArgument(errorMsg);
1628 }
1629 } else {
1630 modeSet = myVehicleParameter->modes;
1631 }
1632 const std::string group = attrs.getOpt<std::string>(SUMO_ATTR_GROUP, id, ok, OptionsCont::getOptions().getString("persontrip.default.group"));
1634 const std::string types = attrs.getOpt<std::string>(SUMO_ATTR_VTYPES, id, ok, myVehicleParameter->vTypes);
1635 for (StringTokenizer st(types); st.hasNext();) {
1636 const std::string vtypeid = st.next();
1637 const MSVehicleType* const vType = vehControl.getVType(vtypeid);
1638 if (vType == nullptr) {
1639 throw InvalidArgument("The vehicle type '" + vtypeid + "' in a trip for person '" + myVehicleParameter->id + "' is not known.");
1640 }
1641 modeSet |= (vType->getVehicleClass() == SVC_BICYCLE) ? SVC_BICYCLE : SVC_PASSENGER;
1642 }
1643 const double speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, id, ok, -1.);
1644 if (attrs.hasAttribute(SUMO_ATTR_SPEED) && speed <= 0) {
1645 throw ProcessError(TLF("Non-positive walking speed for '%'.", myVehicleParameter->id));
1646 }
1647 const double walkFactor = attrs.getOpt<double>(SUMO_ATTR_WALKFACTOR, id, ok, OptionsCont::getOptions().getFloat("persontrip.walkfactor"));
1648 const double departPosLat = interpretDepartPosLat(attrs.getOpt<std::string>(SUMO_ATTR_DEPARTPOS_LAT, nullptr, ok, ""), -1, "personTrip");
1649 if (ok) {
1650 if (myActiveTransportablePlan->empty()) {
1651 double initialDepartPos = myVehicleParameter->departPos;
1653 initialDepartPos = RandHelper::rand(from->getLength(), &myParsingRNG);
1654 }
1655 myActiveTransportablePlan->push_back(new MSStageWaiting(from, nullptr, -1, myVehicleParameter->depart, initialDepartPos, "start", true));
1656 }
1658 MSStoppingPlace* fromStop = myActiveTransportablePlan->empty() ? nullptr : myActiveTransportablePlan->back()->getDestinationStop();
1659 myActiveTransportablePlan->push_back(new MSStageTrip(from, fromStop, to == nullptr ? &stoppingPlace->getLane().getEdge() : to,
1660 stoppingPlace, duration, modeSet, types, speed, walkFactor, group,
1661 departPosLat, attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS), arrivalPos));
1662 myParamStack.push_back(myActiveTransportablePlan->back());
1665 }
1666 }
1667 myActiveRoute.clear();
1668 } catch (ProcessError&) {
1670 throw;
1671 }
1672}
1673
1674
1675void
1677 if (myVehicleParameter == nullptr) {
1678 throw ProcessError(TL("Cannot define person stage without person."));
1679 }
1680 myActiveRouteID = "";
1682 try {
1683 myActiveRoute.clear();
1684 bool ok = true;
1685 const SUMOTime duration = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DURATION, nullptr, ok, -1);
1686 if (attrs.hasAttribute(SUMO_ATTR_DURATION) && duration <= 0) {
1687 throw ProcessError(TLF("Non-positive walking duration for '%'.", myVehicleParameter->id));
1688 }
1689 double speed = -1; // default to vType speed
1690 if (attrs.hasAttribute(SUMO_ATTR_SPEED)) {
1691 speed = attrs.get<double>(SUMO_ATTR_SPEED, nullptr, ok);
1692 if (speed <= 0) {
1693 throw ProcessError(TLF("Non-positive walking speed for '%'.", myVehicleParameter->id));
1694 }
1695 }
1696 double departPos = 0;
1697 double arrivalPos = 0;
1698 MSStoppingPlace* bs = nullptr;
1699 if (attrs.hasAttribute(SUMO_ATTR_ROUTE)) {
1700 myActiveRouteID = attrs.get<std::string>(SUMO_ATTR_ROUTE, myVehicleParameter->id.c_str(), ok);
1702 if (route == nullptr) {
1703 throw ProcessError("The route '" + myActiveRouteID + "' for walk of person '" + myVehicleParameter->id + "' is not known.");
1704 }
1705 myActiveRoute = route->getEdges();
1706 } else {
1708 }
1709 if (myActiveTransportablePlan->empty()) {
1710 double initialDepartPos = myVehicleParameter->departPos;
1712 initialDepartPos = RandHelper::rand(myActiveRoute.front()->getLength(), &myParsingRNG);
1713 }
1714 myActiveTransportablePlan->push_back(new MSStageWaiting(myActiveRoute.front(), nullptr, -1, myVehicleParameter->depart, initialDepartPos, "start", true));
1715 }
1716 parseWalkPositions(attrs, myVehicleParameter->id, myActiveRoute.front(), myActiveRoute.back(), departPos, arrivalPos, bs, myActiveTransportablePlan->back(), ok);
1718 return;
1719 }
1720 if (myActiveRoute.empty()) {
1721 throw ProcessError(TLF("No edges to walk for person '%'.", myVehicleParameter->id));
1722 }
1723 if (myActiveTransportablePlan->back()->getDestination() != myActiveRoute.front() &&
1724 myActiveTransportablePlan->back()->getDestination()->getToJunction() != myActiveRoute.front()->getFromJunction() &&
1725 myActiveTransportablePlan->back()->getDestination()->getToJunction() != myActiveRoute.front()->getToJunction()) {
1726 if (myActiveTransportablePlan->back()->getDestinationStop() == nullptr || myActiveTransportablePlan->back()->getDestinationStop()->getAccessPos(myActiveRoute.front()) < 0.) {
1727 throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + myActiveRoute.front()->getID() + " not connected to " + myActiveTransportablePlan->back()->getDestination()->getID() + ").");
1728 }
1729 }
1730 const int departLane = attrs.getOpt<int>(SUMO_ATTR_DEPARTLANE, nullptr, ok, -1);
1731 const double departPosLat = interpretDepartPosLat(attrs.getOpt<std::string>(SUMO_ATTR_DEPARTPOS_LAT, nullptr, ok, ""), departLane, "walk");
1732 MSStageWalking* stage = new MSStageWalking(myVehicleParameter->id, myActiveRoute, bs, duration, speed, departPos, arrivalPos, departPosLat, departLane, myActiveRouteID);
1733 stage->setDeparted(attrs.getOptSUMOTimeReporting(SUMO_ATTR_STARTED, nullptr, ok, -1));
1734 stage->setEnded(attrs.getOptSUMOTimeReporting(SUMO_ATTR_ENDED, nullptr, ok, -1));
1736 if (attrs.hasAttribute(SUMO_ATTR_EXITTIMES) && OptionsCont::getOptions().getBool("vehroute-output.exit-times")) {
1737 std::vector<SUMOTime>* exitTimes = new std::vector<SUMOTime>();
1738 for (const std::string& tStr : attrs.get<std::vector<std::string> >(SUMO_ATTR_EXITTIMES, nullptr, ok)) {
1739 exitTimes->push_back(string2time(tStr));
1740 }
1741 stage->setExitTimes(exitTimes);
1742 }
1745 }
1746 myActiveTransportablePlan->push_back(stage);
1747 myParamStack.push_back(stage);
1748 myActiveRoute.clear();
1749 } catch (ProcessError&) {
1751 throw;
1752 }
1753 } else { // parse walks from->to as person trips
1754 addPersonTrip(attrs);
1755 }
1756}
1757
1758double
1759MSRouteHandler::interpretDepartPosLat(const std::string& value, int departLane, const std::string& element) {
1760 double pos = MSPModel::UNSPECIFIED_POS_LAT;
1761 if (value == "") {
1762 return pos;
1763 }
1764 std::string error;
1766 if (SUMOVehicleParameter::parseDepartPosLat(value, element, myVehicleParameter->id, pos, dpd, error)) {
1767 if (dpd != DepartPosLatDefinition::GIVEN) {
1769 if (lane == nullptr) {
1770 throw ProcessError(TLF("Could not find departure lane for walk of person '%' when interpreting departPosLat", myVehicleParameter->id));
1771 }
1772 const double usableWidth = lane->getWidth() - 0.5;
1773 switch (dpd) {
1775 pos = -usableWidth / 2;
1776 break;
1778 pos = usableWidth / 2;
1779 break;
1781 pos = 0;
1782 break;
1788 break;
1789 default:
1790 break;
1791 }
1792 }
1793 } else {
1794 throw ProcessError(error);
1795 }
1796 return pos;
1797}
1798
1799
1800void
1801MSRouteHandler::addTransportable(const SUMOSAXAttributes& /*attrs*/, const bool isPerson) {
1803 if (!MSNet::getInstance()->getVehicleControl().hasVType(myVehicleParameter->vtypeid)) {
1804 const std::string error = TLF("The type '%' for % '%' is not known.", myVehicleParameter->vtypeid, myActiveTypeName, myVehicleParameter->id);
1806 throw ProcessError(error);
1807 }
1809}
1810
1811
1812void
1814 try {
1815 myActiveRoute.clear();
1816 const std::string cid = myVehicleParameter->id;
1817 bool ok = true;
1818 const MSEdge* from = nullptr;
1819 const MSEdge* to = nullptr;
1820 MSStoppingPlace* cs = nullptr;
1821
1822 double speed;
1824 if (attrs.hasAttribute(SUMO_ATTR_SPEED)) { // speed is explicitly set
1825 speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, nullptr, ok, -1);
1826 if (!ok) {
1827 throw ProcessError(TLF("Could not read tranship speed for container '%'.", cid));
1828 }
1829 } else if (vtype != nullptr && vtype->wasSet(VTYPEPARS_MAXSPEED_SET)) { // speed is set by vtype
1830 speed = vtype->getMaxSpeed();
1831 } else { // default speed value
1833 }
1834 if (speed <= 0) {
1835 throw ProcessError(TLF("Non-positive tranship speed for container '%'.", cid));
1836 }
1837 // values from preceding stage:
1838 const MSEdge* preEdge = nullptr;
1839 double prePos = 0;
1840 if (!myActiveTransportablePlan->empty()) {
1841 preEdge = myActiveTransportablePlan->back()->getDestination();
1842 prePos = myActiveTransportablePlan->back()->getArrivalPos();
1843 }
1844 // set depart position as given attribute value, arrival position of preceding stage or default (=0)
1845 double departPos = attrs.getOpt<double>(SUMO_ATTR_DEPARTPOS, cid.c_str(), ok, prePos);
1846
1847 if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
1848 MSEdge::parseEdgesList(attrs.get<std::string>(SUMO_ATTR_EDGES, cid.c_str(), ok), myActiveRoute, myActiveRouteID);
1849 } else {
1850 // set 'from':
1851 if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
1852 const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, cid.c_str(), ok);
1853 from = MSEdge::dictionary(fromID);
1854 if (from == nullptr) {
1855 throw ProcessError("The from edge '" + fromID + "' within a tranship of container '" + cid + "' is not known.");
1856 }
1857 if (preEdge != nullptr && preEdge != from) {
1858 throw ProcessError("Disconnected plan for container '" + cid + "' (" + from->getID() + "!=" + preEdge->getID() + ").");
1859 }
1860 } else if (preEdge == nullptr) {
1861 throw ProcessError(TLF("The start edge for container '%' is not known.", cid));
1862 } else {
1863 from = preEdge;
1864 }
1865 // set 'to':
1866 if (attrs.hasAttribute(SUMO_ATTR_TO)) {
1867 const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, cid.c_str(), ok);
1868 to = MSEdge::dictionary(toID);
1869 if (to == nullptr) {
1870 throw ProcessError("The to edge '" + toID + "' within a tranship of container '" + cid + "' is not known.");
1871 }
1872 } else {
1873 const std::string description = "container '" + cid + "' transhipping from edge '" + from->getID() + "'";
1874 cs = retrieveStoppingPlace(attrs, " " + description);
1875 if (cs != nullptr) {
1876 to = &cs->getLane().getEdge();
1877 } else {
1878 throw ProcessError(TLF("Inconsistent tranship for container '%', needs either: 'edges', 'to', 'containerStop' (or any other stopping place)", cid));
1879 }
1880 }
1881 myActiveRoute.push_back(from);
1882 myActiveRoute.push_back(to);
1883 }
1884 if (myActiveRoute.empty()) {
1885 throw ProcessError(TLF("No edges to tranship container '%'.", cid));
1886 }
1887 if (preEdge == nullptr) { // additional 'stop' to start the container plan
1889 myActiveRoute.front(), nullptr, -1, myVehicleParameter->depart, departPos, "start", true));
1890 }
1891 double arrivalPos = attrs.getOpt<double>(SUMO_ATTR_ARRIVALPOS, cid.c_str(), ok,
1892 cs == nullptr ? myActiveRoute.back()->getLength() : cs->getEndLanePosition());
1893 myActiveTransportablePlan->push_back(new MSStageTranship(myActiveRoute, cs, speed, departPos, arrivalPos));
1894 myParamStack.push_back(myActiveTransportablePlan->back());
1895 myActiveRoute.clear();
1896 } catch (ProcessError&) {
1898 throw;
1899 }
1900}
1901
1902
1903void
1905 for (const auto& edge : MSEdge::getAllEdges()) {
1906 if (edge->isNormal() || MSGlobals::gUsingInternalLanes) {
1907 for (MSLane* lane : edge->getLanes()) {
1908 Boundary b = lane->getShape().getBoxBoundary();
1909 const float cmin[2] = {(float) b.xmin(), (float) b.ymin()};
1910 const float cmax[2] = {(float) b.xmax(), (float) b.ymax()};
1911 tree->Insert(cmin, cmax, lane);
1912 }
1913 }
1914 }
1915}
1916
1917
1918SumoRNG*
1920 return &myParsingRNG;
1921}
1922
1923
1924const SUMOVTypeParameter*
1925MSRouteHandler::getVTypeParameter(const std::string& refid) {
1926 const auto t = MSNet::getInstance()->getVehicleControl().getVType(refid);
1927 return t != nullptr ? &t->getParameter() : nullptr;
1928}
1929
1930
1931MSEdge*
1932MSRouteHandler::retrieveEdge(const std::string& id) {
1933 return MSEdge::dictionary(id);
1934}
1935
1936
1937/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:75
#define JUNCTION_TAZ_MISSING_HELP
Definition MapMatcher.h:30
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:299
#define WRITE_ERROR(msg)
Definition MsgHandler.h:307
#define WRITE_WARNING(msg)
Definition MsgHandler.h:298
#define TL(string)
Definition MsgHandler.h:316
#define TLF(string,...)
Definition MsgHandler.h:318
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.h:32
SUMOTime DELTA_T
Definition SUMOTime.cpp:39
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:47
constexpr SUMOTime TIME2STEPS(double x)
Definition SUMOTime.h:60
#define SUMOTime_MAX
Definition SUMOTime.h:34
const long long int VTYPEPARS_MAXSPEED_SET
const long long int VTYPEPARS_VEHICLECLASS_SET
const std::string & getVehicleClassNames(SVCPermissions permissions, bool expand)
Returns the ids of the given classes, divided using a ' '.
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
const double DEFAULT_VEH_PROB
const std::string DEFAULT_VTYPE_ID
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_PEDESTRIAN
pedestrian
const double DEFAULT_CONTAINER_TRANSHIP_SPEED
@ GIVEN
The edge index is given.
@ DEFAULT
No information given; use default.
const int STOP_INDEX_END
const long long int VEHPARS_FORCE_REROUTE
DepartPosLatDefinition
Possible ways to choose the lateral departure position.
@ RANDOM
The lateral position is chosen randomly.
@ RIGHT
At the rightmost side of the lane.
@ GIVEN
The position is given.
@ LEFT
At the leftmost side of the lane.
@ FREE
A free lateral position is chosen.
@ CENTER
At the center of the lane.
@ RANDOM_FREE
If a fixed number of random choices fails, a free lateral position is chosen.
@ RANDOM
A random position is chosen.
@ GIVEN
The position is given.
const long long int VEHPARS_ROUTE_SET
const std::string LINE_ANY
const long long int VEHPARS_TO_TAZ_SET
const long long int VEHPARS_DEPARTPOS_SET
const long long int VEHPARS_ARRIVALPOS_SET
const int STOP_INDEX_REPEAT
const long long int VEHPARS_FROM_TAZ_SET
@ GIVEN
The arrival position is given.
const int STOP_END_SET
const double MIN_STOP_LENGTH
@ BEGIN
The departure is at simulation start.
@ GIVEN
The time is given.
@ TRIGGERED
The departure is person triggered.
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
@ SUMO_TAG_NOTHING
invalid tag, must be the last one
@ SUMO_TAG_CONTAINERFLOW
@ SUMO_TAG_FLOW
a flow definition using from and to edges or a route
@ SUMO_TAG_TRANSPORT
@ SUMO_TAG_RIDE
@ SUMO_TAG_PARAM
parameter associated to a certain key
@ SUMO_TAG_PERSON
@ SUMO_TAG_PERSONFLOW
@ SUMO_TAG_TRIP
a single trip definition (used by router)
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_LINES
@ SUMO_ATTR_LANE
@ SUMO_ATTR_DEPART
@ SUMO_ATTR_LON
@ SUMO_ATTR_REFID
@ SUMO_ATTR_FROM_JUNCTION
@ SUMO_ATTR_VIALONLAT
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_STARTED
@ SUMO_ATTR_WAITINGTIME
@ SUMO_ATTR_VIA
@ SUMO_ATTR_REPLACED_AT_TIME
@ SUMO_ATTR_VIAXY
@ SUMO_ATTR_Y
@ SUMO_ATTR_EDGE
@ SUMO_ATTR_DEPARTPOS_LAT
@ SUMO_ATTR_BUS_STOP
@ SUMO_ATTR_ENDPOS
@ SUMO_ATTR_TO_JUNCTION
@ SUMO_ATTR_X
@ SUMO_ATTR_ARRIVALPOS
@ SUMO_ATTR_ACTTYPE
@ SUMO_ATTR_PROBS
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_TOLONLAT
@ SUMO_ATTR_ROUTES
@ SUMO_ATTR_MODES
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_EXITTIMES
@ SUMO_ATTR_DEPARTPOS
@ SUMO_ATTR_GROUP
@ SUMO_ATTR_ENDED
@ SUMO_ATTR_COST
@ SUMO_ATTR_PERIOD
@ SUMO_ATTR_TO_TAZ
@ SUMO_ATTR_TO
@ SUMO_ATTR_FROM
@ SUMO_ATTR_FROM_TAZ
@ SUMO_ATTR_DEPARTLANE
@ SUMO_ATTR_REPLACED_ON_INDEX
@ SUMO_ATTR_VIAJUNCTIONS
@ SUMO_ATTR_FROMXY
@ SUMO_ATTR_ROUTELENGTH
@ SUMO_ATTR_PROB
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_LAT
@ SUMO_ATTR_WALKFACTOR
@ SUMO_ATTR_VEHICLE
@ SUMO_ATTR_TOXY
@ SUMO_ATTR_ROUTE
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ SUMO_ATTR_DURATION
@ SUMO_ATTR_FROMLONLAT
@ SUMO_ATTR_REPEAT
@ SUMO_ATTR_INTENDED
@ SUMO_ATTR_POSITION
@ SUMO_ATTR_CYCLETIME
@ SUMO_ATTR_STATE
The state of a link.
T MAX2(T a, T b)
Definition StdDefs.h:86
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
double ymin() const
Returns minimum y-coordinate.
Definition Boundary.cpp:127
double xmin() const
Returns minimum x-coordinate.
Definition Boundary.cpp:115
PositionVector getShape(const bool closeShape) const
get position vector (shape) based on this boundary
Definition Boundary.cpp:444
double ymax() const
Returns maximum y-coordinate.
Definition Boundary.cpp:133
double xmax() const
Returns maximum x-coordinate.
Definition Boundary.cpp:121
Writes the state of the tls to a file (in each second)
void error(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Handler for XML-errors.
const std::string & getFileName() const
returns the current file name
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
bool x2cartesian_const(Position &from) const
Converts the given coordinate into a cartesian using the previous initialisation.
static MSLane * interpretOppositeStop(SUMOVehicleParameter::Stop &stop)
interpret stop lane on opposite side of the road
const MSParkingArea * getParkingArea() const
Get the parking area the charging station is placed on.
A road/street connecting two junctions.
Definition MSEdge.h:78
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition MSEdge.cpp:1157
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition MSEdge.h:169
static void parseEdgesList(const std::string &desc, ConstMSEdgeVector &into, const std::string &rid)
Parses the given string assuming it contains a list of edge ids divided by spaces.
Definition MSEdge.cpp:1183
const MSEdge * getNormalSuccessor() const
if this edge is an internal edge, return its first normal successor, otherwise the edge itself
Definition MSEdge.cpp:1017
const MSJunction * getToJunction() const
Definition MSEdge.h:428
double getLength() const
return the length of the edge
Definition MSEdge.h:695
bool isInternal() const
return whether this edge is an internal edge
Definition MSEdge.h:270
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary....
Definition MSEdge.cpp:1117
const MSEdge * getNormalBefore() const
if this edge is an internal edge, return its first normal predecessor, otherwise the edge itself
Definition MSEdge.cpp:1007
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
static bool gCheckRoutes
Definition MSGlobals.h:91
static bool gStateLoaded
Information whether a state has been loaded.
Definition MSGlobals.h:103
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition MSGlobals.h:81
const SUMOVehicleParameter * getFlowPars(const std::string &id) const
return parameters for the given flow
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
SUMOTime computeRandomDepartOffset() const
compute (optional) random offset to the departure time
Representation of a lane in the micro simulation.
Definition MSLane.h:84
double getLength() const
Returns the lane's length.
Definition MSLane.h:632
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition MSLane.cpp:2538
bool isInternal() const
Definition MSLane.cpp:2669
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:790
double getWidth() const
Returns the lane's width.
Definition MSLane.h:661
The simulated network and simulation perfomer.
Definition MSNet.h:90
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:201
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition MSNet.h:496
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition MSNet.h:506
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition MSNet.cpp:1326
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition MSNet.cpp:1527
bool hasContainers() const
Returns whether containers are simulated.
Definition MSNet.h:436
bool hasPersons() const
Returns whether persons are simulated.
Definition MSNet.h:420
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition MSNet.h:456
SUMOTime getStateLoaderTime() const
return the next time for route loading the time of state loading
Definition MSNet.h:359
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:403
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1317
static const double RANDOM_POS_LAT
magic value to encode randomized lateral offset for persons when starting a walk
Definition MSPModel.h:68
static const double UNSPECIFIED_POS_LAT
the default lateral offset for persons when starting a walk
Definition MSPModel.h:65
A lane area vehicles can halt at.
void closePerson() override
Ends the processing of a person.
RandomDistributor< ConstMSRoutePtr > * myCurrentRouteDistribution
The currently parsed distribution of routes (probability->route)
void addRideOrTransport(const SUMOSAXAttributes &attrs, const SumoXMLTag modeTag)
Processing of a transport.
void closeContainerFlow() override
Ends the processing of a containerFlow.
void openFlow(const SUMOSAXAttributes &attrs) override
opens a flow for reading
ConstMSRoutePtr addVehicleStopsToImplicitRoute(ConstMSRoutePtr route, bool isPermanent)
adapt implicit route (edges derived from stops) to additional vehicle-stops
void addWalk(const SUMOSAXAttributes &attrs) override
add a fully specified walk
void myEndElement(int element) override
Called when a closing tag occurs.
void addTransport(const SUMOSAXAttributes &attrs) override
Processing of a transport.
void deleteActivePlanAndVehicleParameter()
delete already created MSTransportablePlans if error occurs before handing over responsibility to a M...
void initLaneTree(NamedRTree *tree) override
bool myAmLoadingState
whether a state file is being loaded
bool myStartTriggeredInFlow
whether we are loading a personFlow that is starting triggered in a vehicle flow
void resetActivePlanAndVehicleParameter()
reset MSTransportablePlans after transportable tag closes
SUMOTime myActiveRoutePeriod
bool myHaveVia
Whether an object with 'via'-attribute is being parsed.
int addFlowTransportable(SUMOTime depart, MSVehicleType *type, const std::string &baseID, int i)
delete already created MSTransportablePlans if error occurs before handing over responsibility to a M...
void closeTransportable()
ends the processing of a transportable (as person or container)
MSEdge * retrieveEdge(const std::string &id) override
std::size_t myDiscardedTransportableDepth
Stack depth of a discarded transportable, or zero during normal parsing.
MSStoppingPlace * retrieveStoppingPlace(const SUMOSAXAttributes &attrs, const std::string &errorSuffix, SUMOVehicleParameter::Stop *stopParam=nullptr)
Parse destination stop.
std::string myCurrentVTypeDistributionID
The id of the currently parsed vehicle type distribution.
void openRoute(const SUMOSAXAttributes &attrs) override
opens a route for reading
void closeVehicleTypeDistribution() override
closes (ends) the building of a distribution
void addTranship(const SUMOSAXAttributes &attrs) override
Processing of a tranship.
void closeRoute(const bool mayBeDisconnected=false) override
closes (ends) the building of a route.
void parseFromViaTo(SumoXMLTag tag, const SUMOSAXAttributes &attrs)
Called for parsing from and to and the corresponding taz attributes.
void closeFlow() override
Ends the processing of a flow.
MSTransportable::MSTransportablePlan * myActiveTransportablePlan
The plan of the current transportable (person or container)
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs) override
Called on the opening of a tag;.
std::string myCurrentRouteDistributionID
The id of the currently parsed route distribution.
RandomDistributor< MSVehicleType * > * myCurrentVTypeDistribution
The currently parsed distribution of vehicle types (probability->vehicle type)
void closeContainer() override
Ends the processing of a container.
SUMOTime myActiveRouteReplacedAtTime
The time at which this route was replaced (from vehroute-output)
void closeTrip() override
Ends the processing of a trip.
void openTrip(const SUMOSAXAttributes &attrs) override
opens a trip for reading
void addPersonTrip(const SUMOSAXAttributes &attrs) override
add a routing request for a walking or intermodal person
ConstMSEdgeVector myActiveRoute
The current route.
int myActiveRouteRepeat
number of repetitions of the active route
ObjectTypeEnum myActiveType
The type of the current object.
SumoRNG * getRNG() override
const SUMOVTypeParameter * getVTypeParameter(const std::string &refid) override
void closePersonFlow() override
Ends the processing of a personFlow.
int myActiveRouteReplacedIndex
The index at which this route was replaced (from vehroute-output)
void closeRouteDistribution() override
closes (ends) the building of a distribution
MSRouteHandler(const std::string &file, bool addVehiclesDirectly)
standard constructor
std::string myScaleSuffix
prefix when copying vehicles with –scale
ObjectTypeEnum
enum for object type
double interpretDepartPosLat(const std::string &value, int departLane, const std::string &element)
virtual ~MSRouteHandler()
standard destructor
bool myAddVehiclesDirectly
Information whether vehicles shall be directly added to the network or kept within the buffer.
bool myReplayRerouting
whether loaded rerouting events shall be replayed
void openVehicleTypeDistribution(const SUMOSAXAttributes &attrs) override
opens a type distribution for reading
Parameterised * addStop(const SUMOSAXAttributes &attrs) override
Processing of a stop.
virtual void closeVehicle() override
Ends the processing of a vehicle (note: is virtual because is reimplemented in MSStateHandler)
void openRouteFlow(const SUMOSAXAttributes &attrs) override
opens a route flow for reading
void openRouteDistribution(const SUMOSAXAttributes &attrs) override
opens a route distribution for reading
void addRide(const SUMOSAXAttributes &attrs) override
Processing of a ride.
void parseWalkPositions(const SUMOSAXAttributes &attrs, const std::string &personID, const MSEdge *fromEdge, const MSEdge *&toEdge, double &departPos, double &arrivalPos, MSStoppingPlace *&bs, const MSStage *const lastStage, bool &ok)
@ brief parse depart- and arrival positions of a walk
bool myActiveRoutePermanent
whether the active route is stored indefinitely (used by state loader)
std::string myActiveTypeName
The name of the current object type.
void closeVType() override
Ends the processing of a vehicle type.
void addTransportable(const SUMOSAXAttributes &attrs, const bool isPerson) override
Processing of a person.
void closeTransportableFlow()
ends the flow of a transportable
void setReroute(bool reroute=true)
Definition MSRoute.h:224
const ConstMSEdgeVector & getEdges() const
Definition MSRoute.h:128
void setCosts(double costs)
Sets the costs of the route.
Definition MSRoute.h:209
static bool dictionary(const std::string &id, ConstMSRoutePtr route)
Adds a route to the dictionary.
Definition MSRoute.cpp:116
static RandomDistributor< ConstMSRoutePtr > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition MSRoute.cpp:168
void setPeriod(SUMOTime period)
sets the period
Definition MSRoute.h:201
void setVehicleDistance(double dist)
restore further state during loading
void setVehicleID(const std::string vehID)
const MSEdge * getDestination() const
returns the destination edge
Definition MSStage.cpp:65
virtual double getArrivalPos() const
Definition MSStage.h:97
static const double ARRIVALPOS_UNSPECIFIED
sentinel value
Definition MSStage.h:72
void setDeparted(SUMOTime now)
logs beginning of stage
Definition MSStage.cpp:115
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
Definition MSStage.h:88
MSStageType getStageType() const
Definition MSStage.h:138
void markSet(int what)
Definition MSStage.h:267
void setEnded(SUMOTime t)
sets end of stage
Definition MSStage.cpp:123
static const MSLane * checkDepartLane(const MSEdge *edge, SUMOVehicleClass svc, int laneIndex, const std::string &id)
interpret custom depart lane
void setTotalWaitingTime(SUMOTime t)
Restore waiting time when loading state.
const MSEdge * getEdge() const
Returns the current edge.
void setDepartPos(const double pos)
void setExitTimes(std::vector< SUMOTime > *exitTimes)
A lane area vehicles can halt at.
double getBeginLanePosition() const
Returns the begin position of this stop.
double getEndLanePosition() const
Returns the end position of this stop.
const MSLane & getLane() const
Returns the lane this stop is located at.
double getAccessPos(const MSEdge *edge, SumoRNG *rng=nullptr) const
the position on the given edge which is connected to this stop, -1 on failure
int getLoadedNumber() const
Returns the number of build transportables.
virtual MSTransportable * buildContainer(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan) const
Builds a new container.
virtual MSTransportable * buildPerson(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan, SumoRNG *rng) const
Builds a new person.
bool add(MSTransportable *transportable)
Adds a single transportable, returns false if an id clash occurred.
MSTransportable * get(const std::string &id) const
Returns the named transportable, if existing.
std::vector< MSStage * > MSTransportablePlan
the structure holding the plan of a transportable
The class responsible for building and deletion of vehicles.
VehicleDefinitionSource
possible origins of a vehicle definition
double getScale() const
sets the demand scaling factor
bool hasVTypeDistribution(const std::string &id) const
Asks for a vehicle type distribution.
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
int getQuota(double frac=-1, int loaded=-1) const
Returns the number of instances of the current vehicle that shall be emitted considering that "frac" ...
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, SumoRNG *rng=nullptr, bool readOnly=false)
Returns the named vehicle type or a sample from the named distribution.
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, ConstMSRoutePtr route, MSVehicleType *type, const bool ignoreStopErrors, const VehicleDefinitionSource source=ROUTEFILE, bool addRouteStops=true)
Builds a vehicle, increases the number of built vehicles.
const RandomDistributor< MSVehicleType * > * getVTypeDistribution(const std::string &typeDistID) const
return the vehicle type distribution with the given id
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false, bool wasKept=false)
Deletes the vehicle.
The car-following model and parameter.
double getDefaultProbability() const
Get the default probability of this vehicle type.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
double getMaxSpeed() const
Get vehicle's (technical) maximum speed [m/s].
const std::string & getID() const
Returns the name of the vehicle type.
bool wasSet(long long int what) const
Returns whether the given parameter was set.
static MSVehicleType * build(SUMOVTypeParameter &from, const std::string &fileName="")
Builds the microsim vehicle type described by the given parameter.
const SUMOVTypeParameter & getParameter() const
void check()
Checks whether vehicle type parameters may be problematic (Currently, only the value for the action s...
Provides utility functions for matching locations to edges (during route parsing)
Definition MapMatcher.h:45
void parseGeoEdges(const PositionVector &positions, bool geo, SUMOVehicleClass vClass, std::vector< const MSEdge * > &into, const std::string &rid, bool isFrom, bool &ok, bool forceEdge=false)
Definition MapMatcher.h:48
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
const std::string & getID() const
Returns the id.
Definition Named.h:73
A RT-tree for efficient storing of SUMO's Named objects.
Definition NamedRTree.h:61
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
Definition NamedRTree.h:79
A storage for options typed value containers)
Definition OptionsCont.h:92
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
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.
An upper class for objects with additional parameters.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Represents a generic random distribution.
double getOverallProb() const
Return the sum of the probabilites assigned to the members.
bool add(T val, double prob, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
const std::vector< T > & getVals() const
Returns the members of the distribution.
void clear()
Clears the distribution.
const std::vector< double > & getProbs() const
Returns the probabilities assigned to the members of the distribution.
Parser for routes during their loading.
bool parseStop(SUMOVehicleParameter::Stop &stop, const SUMOSAXAttributes &attrs, std::string errorSuffix, MsgHandler *const errorOutput)
parses attributes common to all stops
std::set< std::string > mySkippedVehicles
IDs of skipped vehicles to suppress errors for the triggered transportables within.
void registerLastDepart()
save last depart (only to be used if vehicle is not discarded)
double myCurrentCosts
The currently parsed route costs.
std::string myActiveRouteID
The id of the current route.
std::vector< Parameterised * > myParamStack
The stack of currently parsed parameterised objects.
SUMOVehicleParameter * myVehicleParameter
Parameter of the current vehicle, trip, person, container or flow.
const bool myHardFail
flag to enable or disable hard fails
static SumoRNG myParsingRNG
A random number generator used to choose from vtype/route distributions and computing the speed facto...
std::vector< int > myElementStack
hierarchy of elements being parsed
StopParVector myActiveRouteStops
List of the stops on the parsed route.
std::string myCurrentVTypeRef
if the currently parsed vType is only a reference to an existing type, store the refId
SUMOVTypeParameter * myCurrentVType
The currently parsed vehicle type.
static StopPos checkStopPos(double &startPos, double &endPos, const double laneLength, const double minLength, const bool friendlyPos)
check start and end position of a stop
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
double myActiveRouteProbability
The probability of the current route.
double myCurrentVTypeProbability
if the currently parsed vType is only a reference, store the probability here
int myInsertStopEdgesAt
where stop edges can be inserted into the current route (-1 means no insertion)
std::string myActiveRouteRefID
The id of the route the current route references to.
const RGBColor * myActiveRouteColor
The currently parsed route's color.
virtual void myEndElement(int element)
Called when a closing tag occurs.
std::set< std::string > myScaledVehicles
IDs of vehicles that were removed by scaling (to warn for the triggered transportables)
virtual bool checkLastDepart()
Checks whether the route file is sorted by departure time if needed.
Encapsulated SAX-Attributes.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue=T(), bool report=true) const
Tries to read given attribute assuming it is an int.
SUMOTime getOptSUMOTimeReporting(int attr, const char *objectid, bool &ok, SUMOTime defaultValue, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
Structure representing possible vehicle parameter.
bool wasSet(long long int what) const
Returns whether the given parameter was set.
double scale
individual scaling factor (-1 for undefined)
SUMOVehicleClass vehicleClass
The vehicle's class.
Representation of a vehicle.
Definition SUMOVehicle.h:63
virtual const MSRoute & getRoute() const =0
Returns the current route.
Definition of vehicle stop (position and duration)
std::string edge
The edge to stop at.
ParkingType parking
whether the vehicle is removed from the net while stopping
std::string lane
The lane to stop at.
std::string parkingarea
(Optional) parking area if one is assigned to the stop
double startPos
The stopping position start.
std::string chargingStation
(Optional) charging station if one is assigned to the stop
int parametersSet
Information for the output which parameter were set.
SUMOTime jump
transfer time if there shall be a jump from this stop to the next route edge
SUMOTime until
The time at which the vehicle may continue its journey.
double endPos
The stopping position end.
SUMOTime duration
The stopping duration.
Structure representing possible vehicle parameter.
double repetitionProbability
The probability for emitting a vehicle per second.
void incrementFlow(double scale, SumoRNG *rng=nullptr)
increment flow
std::string vtypeid
The vehicle's type id.
SUMOTime repetitionOffset
The time offset between vehicle reinsertions.
long long int repetitionsDone
The number of times the vehicle was already inserted.
std::vector< std::string > via
List of the via-edges the vehicle must visit.
SUMOTime repetitionTotalOffset
The offset between depart and the time for the next vehicle insertions.
long long int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
RouteIndexDefinition arrivalEdgeProcedure
Information how the vehicle's final edge shall be chosen.
SVCPermissions modes
The modes a person or container can use.
SUMOTime repetitionEnd
The time at which the flow ends (only needed when using repetitionProbability)
bool wasSet(long long int what) const
Returns whether the given parameter was set.
std::string vTypes
The types of usable (auto-generated) vehicles for a person / container.
double departPos
(optional) The position the vehicle shall depart from
double arrivalPos
(optional) The position the vehicle shall arrive on
std::string routeid
The vehicle's route id.
std::string id
The vehicle's id.
std::vector< Stop > stops
List of the stops the vehicle will make, TraCI may add entries here.
int departEdge
(optional) The initial edge within the route of the vehicle
static bool parsePersonModes(const std::string &modes, const std::string &element, const std::string &id, SVCPermissions &modeSet, std::string &error)
Validates a given person modes value.
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
static bool parseDepartPosLat(const std::string &val, const std::string &element, const std::string &id, double &pos, DepartPosLatDefinition &dpd, std::string &error)
Validates a given departPosLat value.
std::string toTaz
The vehicle's destination zone (district)
static double interpretEdgePos(double pos, double maximumValue, SumoXMLAttr attr, const std::string &id, bool silent=false)
Interprets negative edge positions and fits them onto a given edge.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
int arrivalEdge
(optional) The final edge within the route of the vehicle
std::string fromTaz
The vehicle's origin zone (district)
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
RouteIndexDefinition departEdgeProcedure
Information how the vehicle's initial edge shall be chosen.
static bool parseStopTag(const SUMOSAXAttributes &attrs, const SUMOVehicleParameter::Stop *stopParam, SumoXMLTag &tag, std::string &id)
parse named stopping place attrs (or use stopParam attrs) and return it's tag and id
static double parseWalkPos(SumoXMLAttr attr, const bool hardFail, const std::string &id, double maxPos, const std::string &val, SumoRNG *rng=0)
parse departPos or arrivalPos for a walk
bool hasNext()
returns the information whether further substrings exist
std::string next()
returns the next substring when it exists. Otherwise the behaviour is undefined
static double toDoubleSecure(const std::string &sData, const double def)
converts a string into the integer value described by it