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// ===========================================================================
53
54
55// ===========================================================================
56// method definitions
57// ===========================================================================
58MSRouteHandler::MSRouteHandler(const std::string& file, bool addVehiclesDirectly) :
59 SUMORouteHandler(file, addVehiclesDirectly ? "" : "routes", true),
60 MapMatcher(OptionsCont::getOptions().getBool("mapmatch.junctions"),
61 OptionsCont::getOptions().getBool("mapmatch.taz"),
62 OptionsCont::getOptions().getFloat("mapmatch.distance"),
63 MsgHandler::getErrorInstance()),
64 myActiveRouteRepeat(0),
65 myActiveRoutePeriod(0),
66 myActiveRoutePermanent(false),
67 myActiveType(ObjectTypeEnum::UNDEFINED),
68 myHaveVia(false),
69 myActiveTransportablePlan(nullptr),
70 myAddVehiclesDirectly(addVehiclesDirectly),
71 myCurrentVTypeDistribution(nullptr),
72 myCurrentRouteDistribution(nullptr),
73 myAmLoadingState(false),
74 myScaleSuffix(OptionsCont::getOptions().getString("scale-suffix")),
75 myReplayRerouting(OptionsCont::getOptions().getBool("replay-rerouting")),
76 myStartTriggeredInFlow(false) {
77 myActiveRoute.reserve(100);
78}
79
80
82
83
84void
95
96
97void
103
104
105void
107 const std::string element = toString(tag);
108 myActiveRoute.clear();
109 bool useTaz = OptionsCont::getOptions().getBool("with-taz");
111 WRITE_WARNINGF(TL("Taz usage was requested but no taz present in % '%'!"), element, myVehicleParameter->id);
112 useTaz = false;
113 }
114 bool ok = true;
115 const std::string rid = "for " + element + " '" + myVehicleParameter->id + "'";
118 if (!vc.getVTypeDistribution(myVehicleParameter->vtypeid)) {
119 MSVehicleType* const type = vc.getVType(myVehicleParameter->vtypeid, &myParsingRNG);
120 if (type != nullptr) {
121 vClass = type->getParameter().vehicleClass;
122 }
123 }
124 // from-attributes
125 if ((useTaz || (!attrs.hasAttribute(SUMO_ATTR_FROM) && !attrs.hasAttribute(SUMO_ATTR_FROMXY) && !attrs.hasAttribute(SUMO_ATTR_FROMLONLAT))) &&
127 const bool useJunction = attrs.hasAttribute(SUMO_ATTR_FROM_JUNCTION);
128 const std::string tazType = useJunction ? "junction" : "taz";
129 const std::string tazID = attrs.get<std::string>(useJunction ? SUMO_ATTR_FROM_JUNCTION : SUMO_ATTR_FROM_TAZ, myVehicleParameter->id.c_str(), ok);
130 const MSEdge* fromTaz = MSEdge::dictionary(tazID + "-source");
131 if (fromTaz == nullptr) {
132 throw ProcessError("Source " + tazType + " '" + tazID + "' not known " + rid + "!"
133 + (useJunction ? JUNCTION_TAZ_MISSING_HELP : ""));
134 } else if (fromTaz->getNumSuccessors() == 0 && tag != SUMO_TAG_PERSON) {
135 throw ProcessError("Source " + tazType + " '" + tazID + "' has no outgoing edges " + rid + "!");
136 } else {
137 myActiveRoute.push_back(fromTaz);
138 }
139 } else if (attrs.hasAttribute(SUMO_ATTR_FROMXY)) {
140 parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_FROMXY, myVehicleParameter->id.c_str(), ok), false, vClass, myActiveRoute, rid, true, ok);
141 if (myMapMatchTAZ && ok) {
142 myVehicleParameter->fromTaz = myActiveRoute.back()->getID();
144 }
145 } else if (attrs.hasAttribute(SUMO_ATTR_FROMLONLAT)) {
146 parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_FROMLONLAT, myVehicleParameter->id.c_str(), ok), true, vClass, myActiveRoute, rid, true, ok);
147 if (myMapMatchTAZ && ok) {
148 myVehicleParameter->fromTaz = myActiveRoute.back()->getID();
150 }
151 } else {
152 MSEdge::parseEdgesList(attrs.getOpt<std::string>(SUMO_ATTR_FROM, myVehicleParameter->id.c_str(), ok),
153 myActiveRoute, rid);
154 }
155 if (!ok) {
156 throw ProcessError();
157 }
158
159 // via-attributes
162 }
163 ConstMSEdgeVector viaEdges;
164 if (attrs.hasAttribute(SUMO_ATTR_VIAXY)) {
165 parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_VIAXY, myVehicleParameter->id.c_str(), ok), false, vClass, viaEdges, rid, false, ok);
166 } else if (attrs.hasAttribute(SUMO_ATTR_VIALONLAT)) {
167 parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_VIALONLAT, myVehicleParameter->id.c_str(), ok), true, vClass, viaEdges, rid, false, ok);
168 } else if (attrs.hasAttribute(SUMO_ATTR_VIAJUNCTIONS)) {
169 for (std::string junctionID : attrs.get<std::vector<std::string> >(SUMO_ATTR_VIAJUNCTIONS, myVehicleParameter->id.c_str(), ok)) {
170 const MSEdge* viaSink = MSEdge::dictionary(junctionID + "-sink");
171 if (viaSink == nullptr) {
172 throw ProcessError("Junction-taz '" + junctionID + "' not found." + JUNCTION_TAZ_MISSING_HELP);
173 } else {
174 viaEdges.push_back(viaSink);
175 }
176 }
177 } else {
178 MSEdge::parseEdgesList(attrs.getOpt<std::string>(SUMO_ATTR_VIA, myVehicleParameter->id.c_str(), ok),
179 viaEdges, rid);
180 }
181 if (!viaEdges.empty()) {
182 myHaveVia = true;
183 }
184 for (const MSEdge* e : viaEdges) {
185 myActiveRoute.push_back(e);
186 myVehicleParameter->via.push_back(e->getID());
187 }
188
189 // to-attributes
190 if ((useTaz || (!attrs.hasAttribute(SUMO_ATTR_TO) && !attrs.hasAttribute(SUMO_ATTR_TOXY) && !attrs.hasAttribute(SUMO_ATTR_TOLONLAT))) &&
192 const bool useJunction = attrs.hasAttribute(SUMO_ATTR_TO_JUNCTION);
193 const std::string tazType = useJunction ? "junction" : "taz";
194 const std::string tazID = attrs.get<std::string>(useJunction ? SUMO_ATTR_TO_JUNCTION : SUMO_ATTR_TO_TAZ, myVehicleParameter->id.c_str(), ok, true);
195 const MSEdge* toTaz = MSEdge::dictionary(tazID + "-sink");
196 if (toTaz == nullptr) {
197 throw ProcessError("Sink " + tazType + " '" + tazID + "' not known " + rid + "!"
198 + (useJunction ? JUNCTION_TAZ_MISSING_HELP : ""));
199 } else if (toTaz->getNumPredecessors() == 0 && tag != SUMO_TAG_PERSON) {
200 throw ProcessError("Sink " + tazType + " '" + tazID + "' has no incoming edges " + rid + "!");
201 } else {
202 myActiveRoute.push_back(toTaz);
203 }
204 } else if (attrs.hasAttribute(SUMO_ATTR_TOXY)) {
205 parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_TOXY, myVehicleParameter->id.c_str(), ok, true), false, vClass, myActiveRoute, rid, false, ok);
206 if (myMapMatchTAZ && ok) {
207 myVehicleParameter->toTaz = myActiveRoute.back()->getID();
209 }
210 } else if (attrs.hasAttribute(SUMO_ATTR_TOLONLAT)) {
211 parseGeoEdges(attrs.get<PositionVector>(SUMO_ATTR_TOLONLAT, myVehicleParameter->id.c_str(), ok, true), true, vClass, myActiveRoute, rid, false, ok);
212 if (myMapMatchTAZ && ok) {
213 myVehicleParameter->toTaz = myActiveRoute.back()->getID();
215 }
216 } else {
217 MSEdge::parseEdgesList(attrs.getOpt<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok, "", true),
218 myActiveRoute, rid);
219 }
221 if (myVehicleParameter->routeid == "") {
223 }
224}
225
226
227void
229 try {
231 && element != SUMO_TAG_RIDE && element != SUMO_TAG_TRANSPORT && element != SUMO_TAG_PARAM) {
232 const std::string mode = myActiveType == ObjectTypeEnum::PERSON ? "ride" : "transport";
233 throw ProcessError("Triggered departure for " + myActiveTypeName + " '" + myVehicleParameter->id + "' requires starting with a " + mode + ".");
234 }
235 if (myVehicleParameter == nullptr) {
237 myHaveVia = false;
238 }
239 SUMORouteHandler::myStartElement(element, attrs);
240 switch (element) {
242 addTransportable(attrs, true);
243 break;
245 addTransportable(attrs, false);
246 break;
247 case SUMO_TAG_FLOW:
248 if (myVehicleParameter) {
249 parseFromViaTo((SumoXMLTag)element, attrs);
250 }
251 break;
252 case SUMO_TAG_TRIP:
253 parseFromViaTo((SumoXMLTag)element, attrs);
254 break;
255 default:
256 break;
257 }
258 } catch (ProcessError&) {
260 throw;
261 }
262}
263
264
265void
267 bool ok = true;
268 myCurrentVTypeDistributionID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
269 if (ok) {
271 if (attrs.hasAttribute(SUMO_ATTR_VTYPES)) {
272 std::vector<double> probs;
273 if (attrs.hasAttribute(SUMO_ATTR_PROBS)) {
274 StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_PROBS, myCurrentVTypeDistributionID.c_str(), ok));
275 while (st.hasNext()) {
276 probs.push_back(StringUtils::toDoubleSecure(st.next(), 1.0));
277 }
278 }
279 const std::string vTypes = attrs.get<std::string>(SUMO_ATTR_VTYPES, myCurrentVTypeDistributionID.c_str(), ok);
280 StringTokenizer st(vTypes);
281 int probIndex = 0;
282 while (st.hasNext()) {
283 const std::string& vtypeID = st.next();
285 if (dist != nullptr) {
286 const double distProb = ((int)probs.size() > probIndex ? probs[probIndex] : 1.) / dist->getOverallProb();
287 std::vector<double>::const_iterator probIt = dist->getProbs().begin();
288 for (MSVehicleType* const type : dist->getVals()) {
289 myCurrentVTypeDistribution->add(type, distProb * *probIt);
290 probIt++;
291 }
292 } else {
294 if (type == nullptr) {
295 throw ProcessError("Unknown vtype '" + vtypeID + "' in distribution '" + myCurrentVTypeDistributionID + "'.");
296 }
297 const double prob = ((int)probs.size() > probIndex ? probs[probIndex] : type->getDefaultProbability());
298 myCurrentVTypeDistribution->add(type, prob);
299 }
300 probIndex++;
301 }
302 if (probs.size() > 0 && probIndex != (int)probs.size()) {
303 WRITE_WARNING("Got " + toString(probs.size()) + " probabilities for " + toString(probIndex) +
304 " types in vTypeDistribution '" + myCurrentVTypeDistributionID + "'");
305 }
306 }
307 }
308}
309
310
311void
313 if (myCurrentVTypeDistribution != nullptr) {
314 if (MSGlobals::gStateLoaded && MSNet::getInstance()->getVehicleControl().hasVTypeDistribution(myCurrentVTypeDistributionID)) {
316 return;
317 }
320 throw ProcessError(TLF("Vehicle type distribution '%' is empty.", myCurrentVTypeDistributionID));
321 }
322 if (!MSNet::getInstance()->getVehicleControl().addVTypeDistribution(myCurrentVTypeDistributionID, myCurrentVTypeDistribution)) {
324 throw ProcessError(TLF("Another vehicle type (or distribution) with the id '%' exists.", myCurrentVTypeDistributionID));
325 }
327 }
328}
329
330
331void
335 // check whether the id is really necessary
336 std::string rid;
337 if (myCurrentRouteDistribution != nullptr) {
339 rid = "distribution '" + myCurrentRouteDistributionID + "'";
340 } else if (myVehicleParameter != nullptr) {
341 // ok, a vehicle is wrapping the route,
342 // we may use this vehicle's id as default
343 myActiveRouteID = "!" + myVehicleParameter->id; // !!! document this
344 if (attrs.hasAttribute(SUMO_ATTR_ID)) {
345 WRITE_WARNINGF(TL("Ids of internal routes are ignored (vehicle '%')."), myVehicleParameter->id);
346 }
347 } else {
348 bool ok = true;
349 myActiveRouteID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok, false);
350 if (!ok) {
351 return;
352 }
353 rid = "'" + myActiveRouteID + "'";
354 }
355 if (myVehicleParameter != nullptr) { // have to do this here for nested route distributions
356 rid = "for vehicle '" + myVehicleParameter->id + "'";
357 }
358 bool ok = true;
359 if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
360 MSEdge::parseEdgesList(attrs.get<std::string>(SUMO_ATTR_EDGES, myActiveRouteID.c_str(), ok), myActiveRoute, rid);
361 }
362 myActiveRouteRefID = attrs.getOpt<std::string>(SUMO_ATTR_REFID, myActiveRouteID.c_str(), ok, "");
364 throw ProcessError(TLF("Invalid reference to route '%' in route %.", myActiveRouteRefID, rid));
365 }
368 myActiveRouteRepeat = attrs.getOpt<int>(SUMO_ATTR_REPEAT, myActiveRouteID.c_str(), ok, 0);
372 // handle obsolete attribute name
374 myActiveRoutePermanent = attrs.getOpt<bool>(SUMO_ATTR_STATE, myActiveRouteID.c_str(), ok, false);
375 if (attrs.hasAttribute(SUMO_ATTR_PERIOD)) {
376 WRITE_WARNING(TL("Attribute 'period' is deprecated for route. Use 'cycleTime' instead."));
377 }
378 myCurrentCosts = attrs.getOpt<double>(SUMO_ATTR_COST, myActiveRouteID.c_str(), ok, -1);
379 if (ok && myCurrentCosts != -1 && myCurrentCosts < 0) {
380 WRITE_WARNING(TLF("Invalid cost for route '%'.", myActiveRouteID));
381 }
382}
383
384
385void
387 // Currently unused
388}
389
390
391void
393 // Currently unused
394}
395
396
397void
399 // Currently unsued
400}
401
402
403void
404MSRouteHandler::closeRoute(const bool mayBeDisconnected) {
405 std::string type = "vehicle";
406 if (mayBeDisconnected) {
408 type = "flow";
409 } else {
410 type = "trip";
411 }
412 }
413
414 try {
415 const bool mustReroute = myActiveRoute.size() == 0 && myActiveRouteStops.size() != 0;
416 if (mustReroute) {
417 // implicit route from stops
419 myActiveRoute.push_back(MSEdge::dictionary(stop.edge));
420 }
421 }
422 if (myActiveRoute.size() == 0) {
423 delete myActiveRouteColor;
424 myActiveRouteColor = nullptr;
425 if (myActiveRouteRefID != "" && myCurrentRouteDistribution != nullptr) {
427 if (route != nullptr) {
429 }
430 myActiveRouteID = "";
432 return;
433 }
434 if (myVehicleParameter != nullptr) {
435 throw ProcessError("The route for " + type + " '" + myVehicleParameter->id + "' has no edges.");
436 } else {
437 throw ProcessError(TLF("Route '%' has no edges.", myActiveRouteID));
438 }
439 }
440 if (myActiveRoute.size() == 1 && myActiveRoute.front()->isTazConnector()) {
441 throw ProcessError("The routing information for " + type + " '" + myVehicleParameter->id + "' is insufficient.");
442 }
443 if (myActiveRouteRepeat > 0) {
444 // duplicate route
446 auto tmpStops = myActiveRouteStops;
447
450 std::string errSuffix = ".";
451 if (myVehicleParameter != nullptr) {
454 if (vtype != nullptr) {
455 vClass = vtype->getVehicleClass();
456 errSuffix = TLF(" for vehicle '%' with vClass %.", myVehicleParameter->id, getVehicleClassNames(vClass));
457 }
458 }
459 if (myActiveRoute.size() > 0 && !myActiveRoute.back()->isConnectedTo(*myActiveRoute.front(), vClass)) {
460 if (tmpStops.size() == 0 || tmpStops.back().jump < 0) {
461 throw ProcessError(TLF("Disconnected route '%' when repeating. Last edge '%' is not connected to first edge '%'%",
462 myActiveRouteID, myActiveRoute.back()->getID(), myActiveRoute.front()->getID(), errSuffix));
463 }
464 }
465 }
466 for (int i = 0; i < myActiveRouteRepeat; i++) {
467 myActiveRoute.insert(myActiveRoute.begin(), tmpEdges.begin(), tmpEdges.end());
468 for (SUMOVehicleParameter::Stop stop : tmpStops) {
469 if (stop.until > 0) {
470 if (myActiveRoutePeriod <= 0) {
471 const std::string description = myVehicleParameter != nullptr
472 ? "for " + type + " '" + myVehicleParameter->id + "'"
473 : "'" + myActiveRouteID + "'";
474 throw ProcessError(TLF("Cannot repeat stops with 'until' in route % because no cycleTime is defined.", description));
475 }
476 stop.until += myActiveRoutePeriod * (i + 1);
477 }
478 if (stop.arrival > 0) {
479 if (myActiveRoutePeriod <= 0) {
480 const std::string description = myVehicleParameter != nullptr
481 ? "for " + type + " '" + myVehicleParameter->id + "'"
482 : "'" + myActiveRouteID + "'";
483 throw ProcessError(TLF("Cannot repeat stops with 'arrival' in route % because no cycleTime is defined.", description));
484 }
485 stop.arrival += myActiveRoutePeriod * (i + 1);
486 }
487 stop.index = STOP_INDEX_REPEAT;
488 myActiveRouteStops.push_back(stop);
489 }
490 }
491 if (myActiveRouteStops.size() > 0) {
492 // never jump on the last stop of a repeating route
493 myActiveRouteStops.back().jump = -1;
494 }
495 }
496 MSRoute* const route = new MSRoute(myActiveRouteID, myActiveRoute,
501 route->setCosts(myCurrentCosts);
502 route->setReroute(mustReroute);
503 myActiveRoute.clear();
504 ConstMSRoutePtr constRoute = std::shared_ptr<const MSRoute>(route);
505 if (!MSRoute::dictionary(myActiveRouteID, constRoute)) {
507 if (myVehicleParameter != nullptr) {
508 if (MSNet::getInstance()->getVehicleControl().getVehicle(myVehicleParameter->id) == nullptr) {
509 throw ProcessError("Another route for " + type + " '" + myVehicleParameter->id + "' exists.");
510 } else {
511 throw ProcessError(TLF("A vehicle with id '%' already exists.", myVehicleParameter->id));
512 }
513 } else {
514 throw ProcessError(TLF("Another route (or distribution) with the id '%' exists.", myActiveRouteID));
515 }
516 }
517 } else {
518 if (myCurrentRouteDistribution != nullptr) {
520 }
521 }
522 myActiveRouteID = "";
523 myActiveRouteColor = nullptr;
524 myActiveRouteStops.clear();
526 } catch (ProcessError&) {
528 throw;
529 }
530}
531
532
533void
535 // check whether the id is really necessary
536 if (myVehicleParameter != nullptr) {
537 // ok, a vehicle is wrapping the route,
538 // we may use this vehicle's id as default
539 myCurrentRouteDistributionID = "!" + myVehicleParameter->id; // !!! document this
540 // we have to record this or we cannot remove the distribution later
542 } else {
543 bool ok = true;
544 myCurrentRouteDistributionID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
545 if (!ok) {
546 return;
547 }
548 }
550 std::vector<double> probs;
551 if (attrs.hasAttribute(SUMO_ATTR_PROBS)) {
552 bool ok = true;
553 StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_PROBS, myCurrentRouteDistributionID.c_str(), ok));
554 while (st.hasNext()) {
555 probs.push_back(StringUtils::toDoubleSecure(st.next(), 1.0));
556 }
557 }
558 if (attrs.hasAttribute(SUMO_ATTR_ROUTES)) {
559 bool ok = true;
560 StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_ROUTES, myCurrentRouteDistributionID.c_str(), ok));
561 int probIndex = 0;
562 while (st.hasNext()) {
563 std::string routeID = st.next();
565 if (route == nullptr) {
566 throw ProcessError("Unknown route '" + routeID + "' in distribution '" + myCurrentRouteDistributionID + "'.");
567 }
568 const double prob = ((int)probs.size() > probIndex ? probs[probIndex] : 1.0);
569 myCurrentRouteDistribution->add(route, prob, false);
570 probIndex++;
571 }
572 if (probs.size() > 0 && probIndex != (int)probs.size()) {
573 WRITE_WARNING("Got " + toString(probs.size()) + " probabilities for " + toString(probIndex) +
574 " routes in routeDistribution '" + myCurrentRouteDistributionID + "'");
575 }
576 }
577}
578
579
580void
582 if (myCurrentRouteDistribution != nullptr) {
583 const bool haveSameID = MSRoute::dictionary(myCurrentRouteDistributionID, &myParsingRNG) != nullptr;
584 if (MSGlobals::gStateLoaded && haveSameID) {
587 return;
588 }
589 if (haveSameID) {
591 throw ProcessError(TLF("Another route (or distribution) with the id '%' exists.", myCurrentRouteDistributionID));
592 }
595 throw ProcessError(TLF("Route distribution '%' is empty.", myCurrentRouteDistributionID));
596 }
599 }
600}
601
602
603void
605 // get nested route
606 const std::string embeddedRouteID = "!" + myVehicleParameter->id;
607 ConstMSRoutePtr route = nullptr;
608 if (myReplayRerouting) {
610 if (rDist != nullptr && rDist->getVals().size() > 0) {
611 route = rDist->getVals().front();
612 }
613 }
614 if (route == nullptr) {
615 route = MSRoute::dictionary(embeddedRouteID, &myParsingRNG);
616 }
619 // let's check whether this vehicle had to depart before the simulation starts
622 return;
623 }
624 }
625
626 // get the vehicle's type
627 MSVehicleType* vtype = nullptr;
628
629 try {
630 if (myVehicleParameter->vtypeid != "") {
631 vtype = vehControl.getVType(myVehicleParameter->vtypeid, &myParsingRNG);
632 if (vtype == nullptr) {
633 throw ProcessError("The vehicle type '" + myVehicleParameter->vtypeid + "' for vehicle '" + myVehicleParameter->id + "' is not known.");
634 }
635 if (vtype->getVehicleClass() == SVC_PEDESTRIAN) {
636 WRITE_WARNINGF(TL("Vehicle type '%' with vClass=pedestrian should only be used for persons and not for vehicle '%'."), vtype->getID(), myVehicleParameter->id);
637 }
638 } else {
639 // there should be one (at least the default one)
640 vtype = vehControl.getVType(DEFAULT_VTYPE_ID, &myParsingRNG);
641 }
643 // if the route id was given, prefer that one
644 if (route != nullptr && !myAmLoadingState) {
645 WRITE_WARNINGF(TL("Ignoring child element 'route' for vehicle '%' because attribute 'route' is set."), myVehicleParameter->id);
646 }
648 }
649 if (route == nullptr) {
650 // nothing found? -> error
651 if (myVehicleParameter->routeid != "") {
652 throw ProcessError("The route '" + myVehicleParameter->routeid + "' for vehicle '" + myVehicleParameter->id + "' is not known.");
653 } else {
654 throw ProcessError(TLF("Vehicle '%' has no route.", myVehicleParameter->id));
655 }
656 }
657 myActiveRouteID = "";
658
659 } catch (ProcessError&) {
661 throw;
662 }
663 if (route->mustReroute()) {
665 if (myVehicleParameter->stops.size() > 0) {
666 route = addVehicleStopsToImplicitRoute(route, false);
667 }
668 }
672 myVehicleParameter->departEdge >= (int)route->getEdges().size()) {
673 throw ProcessError("Vehicle '" + myVehicleParameter->id + "' has invalid departEdge index "
674 + toString(myVehicleParameter->departEdge) + " for route with " + toString(route->getEdges().size()) + " edges.");
675 }
676 }
680 myVehicleParameter->arrivalEdge >= (int)route->getEdges().size()) {
681 throw ProcessError("Vehicle '" + myVehicleParameter->id + "' has invalid arrivalEdge index "
682 + toString(myVehicleParameter->arrivalEdge) + " for route with " + toString(route->getEdges().size()) + " edges.");
683 }
684 }
685
686 // try to build the vehicle
687 SUMOVehicle* vehicle = nullptr;
688 if (vehControl.getVehicle(myVehicleParameter->id) == nullptr) {
690 try {
691 vehicle = vehControl.buildVehicle(myVehicleParameter, route, vtype, !MSGlobals::gCheckRoutes, source, !myAmLoadingState);
692 } catch (const ProcessError& e) {
693 myVehicleParameter = nullptr;
695 WRITE_WARNING(e.what());
696 vehControl.deleteVehicle(vehicle, true);
697 myVehicleParameter = nullptr;
698 vehicle = nullptr;
699 return;
700 } else {
701 throw;
702 }
703 }
704 const SUMOTime origDepart = myVehicleParameter->depart;
705 // maybe we do not want this vehicle to be inserted due to scaling
706 int quota = myAmLoadingState ? 1 : vehControl.getQuota(vehControl.getScale() * vtype->getParameter().scale);
707 if (quota > 0) {
710 vehControl.addVehicle(myVehicleParameter->id, vehicle);
711 if (myReplayRerouting) {
713 if (rDist != nullptr) {
714 for (int i = 0; i < (int)rDist->getVals().size() - 1; i++) {
715 SUMOTime replacedAt = rDist->getVals()[i]->getReplacedTime();
716 auto* cmd = new Command_RouteReplacement(vehicle->getID(), rDist->getVals()[i + 1]);
717 if (i == 0 && replacedAt >= 0 && replacedAt == myVehicleParameter->depart) {
718 // routing in the insertion step happens *after* insertion
720 } else {
722 }
723 }
724 }
725 }
726 int offset = 0;
727 for (int i = 1; i < quota; i++) {
730 }
732 newPars->id = myVehicleParameter->id + myScaleSuffix + toString(i + offset);
733 while (vehControl.getVehicle(newPars->id) != nullptr) {
734 offset += 1;
735 newPars->id = myVehicleParameter->id + myScaleSuffix + toString(i + offset);
736 }
739 // resample type
740 vtype = vehControl.getVType(myVehicleParameter->vtypeid, &myParsingRNG);
741 }
742 vehicle = vehControl.buildVehicle(newPars, route, vtype, !MSGlobals::gCheckRoutes, source, !myAmLoadingState);
743 vehControl.addVehicle(newPars->id, vehicle);
744 }
745 myVehicleParameter = nullptr;
746 } else {
747 vehControl.deleteVehicle(vehicle, true);
748 myVehicleParameter = nullptr;
749 vehicle = nullptr;
750 }
751 } else {
752 // strange: another vehicle with the same id already exists
754 // and was not loaded while loading a simulation state
755 // -> error
756 std::string veh_id = myVehicleParameter->id;
758 std::string scaleWarning = "";
759 if (vehControl.getScale() * vtype->getParameter().scale > 1 && veh_id.find(myScaleSuffix) != std::string::npos) {
760 scaleWarning = "\n (Possibly duplicate id due to using option --scale. Set option --scale-suffix to prevent this)";
761 }
762 throw ProcessError("Another vehicle with the id '" + veh_id + "' exists." + scaleWarning);
763 } else {
764 // ok, it seems to be loaded previously while loading a simulation state
765 vehicle = nullptr;
766 }
767 }
768 // check whether the vehicle shall be added directly to the network or
769 // shall stay in the internal buffer
770 if (vehicle != nullptr) {
773 }
774 }
775}
776
777
780 // the route was defined without edges and its current edges were
781 // derived from route-stops.
782 // We may need to add additional edges for the vehicle-stops
784 assert(route->getStops().size() > 0);
785 ConstMSEdgeVector edges = route->getEdges();
787 MSEdge* stopEdge = MSEdge::dictionary(stop.edge);
788 if (stop.index == 0) {
789 if (edges.front() != stopEdge ||
790 route->getStops().front().endPos < stop.endPos) {
791 edges.insert(edges.begin(), stopEdge);
792 }
793 } else if (stop.index == STOP_INDEX_END) {
794 if (edges.back() != stopEdge ||
795 route->getStops().back().endPos > stop.endPos) {
796 edges.push_back(stopEdge);
797 }
798 } else {
799 WRITE_WARNINGF(TL("Could not merge vehicle stops for vehicle '%' into implicitly defined route '%'"), myVehicleParameter->id, route->getID());
800 }
801 }
802 ConstMSRoutePtr newRoute = std::make_shared<MSRoute>("!" + myVehicleParameter->id, edges,
803 isPermanent, new RGBColor(route->getColor()), route->getStops());
804 if (!MSRoute::dictionary(newRoute->getID(), newRoute)) {
805 throw ProcessError("Could not adapt implicit route for " + std::string(isPermanent ? "flow" : "vehicle") + " '" + myVehicleParameter->id + "'");
806 }
807 return newRoute;
808}
809
810
811void
813 try {
814 if (myActiveTransportablePlan->size() == 0) {
815 std::string error = myActiveTypeName + " '" + myVehicleParameter->id + "' has no plan.";
816 error[0] = (char)::toupper((char)error[0]);
817 throw ProcessError(error);
818 }
819 // let's check whether this transportable had to depart before the simulation starts
823 return;
824 }
825 // type existence has been checked on opening
828 && type->getVehicleClass() != SVC_PEDESTRIAN
830 WRITE_WARNINGF(TL("Person '%' receives type '%' which implicitly uses unsuitable vClass '%'."), myVehicleParameter->id, type->getID(), toString(type->getVehicleClass()));
831 }
834 if (created > 0) {
836 } else {
838 }
839 } catch (ProcessError&) {
841 throw;
842 }
843}
844
845
846void
850
851
852void
856
857
858void
862
863
864void
868
869
870void
872 try {
873 const std::string fid = myVehicleParameter->id;
874 if (myActiveTransportablePlan->size() == 0) {
875 throw ProcessError(myActiveTypeName + "Flow '" + fid + "' has no plan.");
876 }
877 // let's check whether this transportable (person/container) had to depart before the simulation starts
881 return;
882 }
883 // instantiate all persons/containers of this flow
884 int i = 0;
886 std::string baseID = myVehicleParameter->id;
889 throw ProcessError("probabilistic " + myActiveTypeName + "Flow '" + fid + "' must specify end time");
890 } else {
893 // type existence has been checked on opening
895 addFlowTransportable(t, type, baseID, i++);
896 }
897 }
898 }
899 } else {
902 // poisson: randomize first depart
904 }
905 for (; i < myVehicleParameter->repetitionNumber && (myVehicleParameter->repetitionNumber != std::numeric_limits<long long int>::max()
907 // type existence has been checked on opening
911 }
912 }
914 } catch (ProcessError&) {
916 throw;
917 }
919}
920
921
922int
923MSRouteHandler::addFlowTransportable(SUMOTime depart, MSVehicleType* type, const std::string& baseID, int i) {
924 try {
925 int numCreated = 0;
926 MSNet* const net = MSNet::getInstance();
929 //MSTransportableControl& pc = net->getPersonControl();
930 const int quota = vc.getQuota(vc.getScale() * type->getParameter().scale, tc.getLoadedNumber());
931 if (quota == 0) {
932 tc.addDiscarded();
933 }
934 for (int j = 0; j < quota; j++) {
935 if (i > 0 || j > 0) {
936 // copy parameter and plan because the transportable takes over responsibility
938 *copyParam = *myVehicleParameter;
939 myVehicleParameter = copyParam;
941 MSStage* lastStage = nullptr;
942 for (MSStage* const s : *myActiveTransportablePlan) {
943 copyPlan->push_back(s->clone());
944 if (lastStage != nullptr && s->getStageType() == MSStageType::WALKING && lastStage->getDestinationStop() != nullptr) {
945 MSStageMoving* walk = static_cast<MSStageMoving*>(copyPlan->back());
946 walk->setDepartPos(lastStage->getDestinationStop()->getAccessPos(walk->getEdge(), &myParsingRNG));
947 }
948 lastStage = s;
949 }
950 myActiveTransportablePlan = copyPlan;
952 const double initialDepartPos = RandHelper::rand(myActiveTransportablePlan->front()->getDestination()->getLength(), &myParsingRNG);
953 myActiveTransportablePlan->front()->setArrivalPos(initialDepartPos);
954 }
955 }
956 myVehicleParameter->id = (baseID
957 + (i >= 0 ? "." + toString(i) : "")
958 + (j > 0 ? "." + toString(j) : ""));
959 if (MSGlobals::gStateLoaded && tc.get(myVehicleParameter->id) != nullptr) {
960 return numCreated;
961 }
966 numCreated++;
967 if (!tc.add(transportable)) {
968 std::string error = "Another " + myActiveTypeName + " with the id '" + myVehicleParameter->id + "' exists.";
969 delete transportable;
971 throw ProcessError(error);
972 } else if ((net->hasPersons() && net->getPersonControl().get(myVehicleParameter->id) != nullptr)
973 && (net->hasContainers() && net->getContainerControl().get(myVehicleParameter->id) != nullptr)) {
974 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);
975 }
976 }
977 return numCreated;
978 } catch (ProcessError&) {
980 throw;
981 }
982}
983
984
985void
988 vehType->check();
989 if (!MSNet::getInstance()->getVehicleControl().addVType(vehType)) {
990 const std::string id = vehType->getID();
991 delete vehType;
993 throw ProcessError(TLF("Another vehicle type (or distribution) with the id '%' exists.", id));
994 }
995 } else {
996 if (myCurrentVTypeDistribution != nullptr) {
998 }
999 }
1000}
1001
1002
1003void
1007 delete myVehicleParameter;
1008 myVehicleParameter = nullptr;
1009 return;
1010 }
1011 // let's check whether vehicles had to depart before the simulation starts
1014 const SUMOTime offsetToBegin = string2time(OptionsCont::getOptions().getString("begin")) - myVehicleParameter->depart;
1015 while (myVehicleParameter->repetitionTotalOffset < offsetToBegin) {
1018 delete myVehicleParameter;
1019 myVehicleParameter = nullptr;
1020 return;
1021 }
1022 }
1023 }
1024 if (MSNet::getInstance()->getVehicleControl().getVType(myVehicleParameter->vtypeid, &myParsingRNG) == nullptr) {
1025 throw ProcessError("The vehicle type '" + myVehicleParameter->vtypeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
1026 }
1029 closeRoute(true);
1030 }
1032 if (route == nullptr) {
1033 throw ProcessError("The route '" + myVehicleParameter->routeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
1034 }
1035 if (route->mustReroute()) {
1037 if (myVehicleParameter->stops.size() > 0) {
1038 route = addVehicleStopsToImplicitRoute(route, true);
1039 myVehicleParameter->routeid = route->getID();
1040 }
1041 }
1045 myVehicleParameter->departEdge >= (int)route->getEdges().size()) {
1046 throw ProcessError("Flow '" + myVehicleParameter->id + "' has invalid departEdge index "
1047 + toString(myVehicleParameter->departEdge) + " for route with " + toString(route->getEdges().size()) + " edges.");
1048 }
1049 }
1053 myVehicleParameter->arrivalEdge >= (int)route->getEdges().size()) {
1054 throw ProcessError("Flow '" + myVehicleParameter->id + "' has invalid arrivalEdge index "
1055 + toString(myVehicleParameter->arrivalEdge) + " for route with " + toString(route->getEdges().size()) + " edges.");
1056 }
1057 }
1058 myActiveRouteID = "";
1059
1060 // check whether the vehicle shall be added directly to the network or
1061 // shall stay in the internal buffer
1063 if (MSNet::getInstance()->getInsertionControl().addFlow(myVehicleParameter)) {
1065 } else {
1067 delete myVehicleParameter;
1068 } else {
1069 throw ProcessError(TLF("Another flow with the id '%' exists.", myVehicleParameter->id));
1070 }
1071 }
1072 }
1073 myVehicleParameter = nullptr;
1074}
1075
1076
1077void
1083
1084void
1088
1089void
1093
1094void
1096 if (myVehicleParameter == nullptr) {
1097 throw ProcessError(TLF("Cannot define % stage without %.", toString(modeTag), toString(modeTag)));
1098 }
1099 try {
1100 const std::string mode = modeTag == SUMO_TAG_RIDE ? "ride" : "transport";
1101 std::string agent = "person";
1102 std::string stop = "bus stop";
1104 agent = "container";
1105 stop = "container stop";
1106 }
1107
1108 if (!((myActiveType == ObjectTypeEnum::PERSON && modeTag == SUMO_TAG_RIDE) ||
1110 throw ProcessError("Found " + mode + " inside " + agent + " element");
1111 }
1112 const std::string aid = myVehicleParameter->id;
1113 bool ok = true;
1114 const MSEdge* from = nullptr;
1115 const std::string desc = attrs.getOpt<std::string>(SUMO_ATTR_LINES, aid.c_str(), ok, LINE_ANY);
1116 StringTokenizer st(desc);
1117 MSStoppingPlace* s = retrieveStoppingPlace(attrs, " in " + agent + " '" + aid + "'");
1118 MSEdge* to = nullptr;
1119 if (s != nullptr) {
1120 to = &s->getLane().getEdge();
1121 }
1122 double arrivalPos = attrs.getOpt<double>(SUMO_ATTR_ARRIVALPOS, aid.c_str(), ok,
1123 s == nullptr ? std::numeric_limits<double>::infinity() : s->getEndLanePosition());
1124
1125 const SUMOVehicleParameter* startVeh = nullptr;
1126 const MSEdge* startVehFrom = nullptr;
1128 if (st.size() != 1) {
1129 throw ProcessError("Triggered departure for " + agent + " '" + aid + "' requires a unique lines value.");
1130 }
1131 // agent starts
1133 const std::string vehID = st.front();
1134 SUMOVehicle* sVeh = vehControl.getVehicle(vehID);
1135 if (sVeh == nullptr) {
1136 if (MSNet::getInstance()->hasFlow(vehID)) {
1137 startVeh = MSNet::getInstance()->getInsertionControl().getFlowPars(vehID);
1138 if (startVeh != nullptr) {
1139 ConstMSRoutePtr const route = MSRoute::dictionary(startVeh->routeid);
1140 startVehFrom = route->getEdges().front();
1141 // flows are inserted at the end of the time step so we
1142 // do delay the pedestrian event by one time step
1143 myVehicleParameter->depart = startVeh->depart + DELTA_T;
1145 }
1146 }
1147 } else {
1148 startVeh = &sVeh->getParameter();
1149 startVehFrom = sVeh->getRoute().getEdges().front();
1150 myVehicleParameter->depart = startVeh->depart;
1151 }
1152 if (startVeh == nullptr) {
1153 if (mySkippedVehicles.count(vehID) == 0) {
1154 throw ProcessError("Unknown vehicle '" + vehID + "' in triggered departure for " + agent + " '" + aid + "'.");
1155 }
1156 // we cannot simply throw here because we need to parse the rest of the person (just to discard it)
1157 from = MSEdge::getAllEdges().front(); // a dummy edge to keep parsing active
1158 } else if (startVeh->departProcedure == DepartDefinition::TRIGGERED) {
1159 throw ProcessError("Cannot use triggered vehicle '" + vehID + "' in triggered departure for " + agent + " '" + aid + "'.");
1160 }
1161 }
1162
1163 if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
1164 const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, aid.c_str(), ok);
1165 from = MSEdge::dictionary(fromID);
1166 if (from == nullptr) {
1167 throw ProcessError("The from edge '" + fromID + "' within a " + mode + " of " + agent + " '" + aid + "' is not known.");
1168 }
1169 if (!myActiveTransportablePlan->empty() && myActiveTransportablePlan->back()->getDestination() != from) {
1170 const bool stopWithAccess = (myActiveTransportablePlan->back()->getDestinationStop() != nullptr
1171 && &myActiveTransportablePlan->back()->getDestinationStop()->getLane().getEdge() == from);
1172 const bool transferAtJunction = (from->getFromJunction() == myActiveTransportablePlan->back()->getDestination()->getFromJunction()
1173 || from->getFromJunction() == myActiveTransportablePlan->back()->getDestination()->getToJunction());
1174 if (!(stopWithAccess || transferAtJunction)) {
1175 throw ProcessError("Disconnected plan for " + agent + " '" + aid +
1176 "' (edge '" + fromID + "' != edge '" + myActiveTransportablePlan->back()->getDestination()->getID() + "').");
1177 }
1178 }
1179 if (startVeh != nullptr && startVehFrom != from) {
1180 throw ProcessError("Disconnected plan for triggered " + agent + " '" + aid +
1181 "' (edge '" + fromID + "' != edge '" + startVehFrom->getID() + "').");
1182 }
1183 } else if (startVeh != nullptr) {
1184 from = startVehFrom;
1185 }
1186 if (myActiveTransportablePlan->empty()) {
1187 if (from == nullptr) {
1188 throw ProcessError("The start edge for " + agent + " '" + aid + "' is not known.");
1189 } else {
1191 from, nullptr, -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start", true));
1192 }
1193 }
1194 // given attribute may override given stopping place due access requirements
1195 if (to == nullptr || attrs.hasAttribute(SUMO_ATTR_TO)) {
1196 const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, aid.c_str(), ok);
1197 to = MSEdge::dictionary(toID);
1198 if (to == nullptr) {
1199 throw ProcessError("The to edge '" + toID + "' within a " + mode + " of " + agent + " '" + aid + "' is not known.");
1200 }
1201 }
1202 const std::string group = attrs.getOpt<std::string>(SUMO_ATTR_GROUP, aid.c_str(), ok, OptionsCont::getOptions().getString("persontrip.default.group"));
1203 const std::string intendedVeh = attrs.getOpt<std::string>(SUMO_ATTR_INTENDED, nullptr, ok, "");
1204 const SUMOTime intendedDepart = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DEPART, nullptr, ok, -1);
1205 arrivalPos = SUMOVehicleParameter::interpretEdgePos(arrivalPos, to->getLength(), SUMO_ATTR_ARRIVALPOS, agent + " '" + aid + "' takes a " + mode + " to edge '" + to->getID() + "'");
1206 MSStageDriving* stage = new MSStageDriving(from, to, s, arrivalPos, 0.0, st.getVector(), group, intendedVeh, intendedDepart);
1207 // for loading from saved state
1208 stage->setDeparted(attrs.getOptSUMOTimeReporting(SUMO_ATTR_STARTED, nullptr, ok, -1));
1209 stage->setEnded(attrs.getOptSUMOTimeReporting(SUMO_ATTR_ENDED, nullptr, ok, -1));
1210 stage->setVehicleID(attrs.getOpt<std::string>(SUMO_ATTR_VEHICLE, nullptr, ok, ""));
1211 stage->setVehicleDistance(attrs.getOpt<double>(SUMO_ATTR_ROUTELENGTH, nullptr, ok, -1));
1212 myActiveTransportablePlan->push_back(stage);
1213 myParamStack.push_back(stage);
1214 } catch (ProcessError&) {
1216 throw;
1217 }
1218}
1219
1221MSRouteHandler::retrieveStoppingPlace(const SUMOSAXAttributes& attrs, const std::string& errorSuffix, SUMOVehicleParameter::Stop* stopParam) {
1222 bool ok = true;
1223 // dummy stop parameter to hold the attributes
1225 if (stopParam != nullptr) {
1226 stop = *stopParam;
1227 } else {
1228 stop.busstop = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, nullptr, ok, "");
1229 stop.busstop = attrs.getOpt<std::string>(SUMO_ATTR_TRAIN_STOP, nullptr, ok, stop.busstop); // alias
1230 stop.chargingStation = attrs.getOpt<std::string>(SUMO_ATTR_CHARGING_STATION, nullptr, ok, "");
1231 stop.overheadWireSegment = attrs.getOpt<std::string>(SUMO_ATTR_OVERHEAD_WIRE_SEGMENT, nullptr, ok, "");
1232 stop.containerstop = attrs.getOpt<std::string>(SUMO_ATTR_CONTAINER_STOP, nullptr, ok, "");
1233 stop.parkingarea = attrs.getOpt<std::string>(SUMO_ATTR_PARKING_AREA, nullptr, ok, "");
1234 }
1235 MSStoppingPlace* toStop = nullptr;
1236 if (stop.busstop != "") {
1238 if (toStop == nullptr) {
1239 ok = false;
1240 WRITE_ERROR(TLF("The busStop '%' is not known%.", stop.busstop, errorSuffix));
1241 }
1242 } else if (stop.containerstop != "") {
1244 if (toStop == nullptr) {
1245 ok = false;
1246 WRITE_ERROR(TLF("The containerStop '%' is not known%.", stop.containerstop, errorSuffix));
1247 }
1248 } else if (stop.parkingarea != "") {
1250 if (toStop == nullptr) {
1251 ok = false;
1252 WRITE_ERROR(TLF("The parkingArea '%' is not known%.", stop.parkingarea, errorSuffix));
1253 }
1254 } else if (stop.chargingStation != "") {
1255 // ok, we have a charging station
1257 if (toStop == nullptr) {
1258 ok = false;
1259 WRITE_ERROR(TLF("The chargingStation '%' is not known%.", stop.chargingStation, errorSuffix));
1260 }
1261 } else if (stop.overheadWireSegment != "") {
1262 // ok, we have an overhead wire segment
1264 if (toStop == nullptr) {
1265 ok = false;
1266 WRITE_ERROR(TLF("The overhead wire segment '%' is not known%.", stop.overheadWireSegment, errorSuffix));
1267 }
1268 }
1269 if (!ok && MSGlobals::gCheckRoutes) {
1270 throw ProcessError(TLF("Invalid stop definition%.", errorSuffix));
1271 }
1272 return toStop;
1273}
1274
1277 Parameterised* result = nullptr;
1278 try {
1279 std::string errorSuffix;
1281 errorSuffix = " in person '" + myVehicleParameter->id + "'";
1283 errorSuffix = " in container '" + myVehicleParameter->id + "'";
1284 } else if (myVehicleParameter != nullptr) {
1285 errorSuffix = " in vehicle '" + myVehicleParameter->id + "'";
1286 } else {
1287 errorSuffix = " in route '" + myActiveRouteID + "'";
1288 }
1290 bool ok = parseStop(stop, attrs, errorSuffix, MsgHandler::getErrorInstance());
1291 if (!ok) {
1293 throw ProcessError();
1294 }
1295 return result;
1296 }
1297 const MSEdge* edge = nullptr;
1298 // patch chargingStation stop on a parkingArea
1299 if (stop.chargingStation != "") {
1301 const MSParkingArea* pa = cs->getParkingArea();
1302 if (pa != nullptr) {
1303 stop.parkingarea = pa->getID();
1305 }
1306 }
1307 MSStoppingPlace* toStop = retrieveStoppingPlace(attrs, errorSuffix, &stop);
1308 // if one of the previous stops is defined
1309 if (toStop != nullptr) {
1310 const MSLane& l = toStop->getLane();
1311 stop.lane = l.getID();
1312 if ((stop.parametersSet & STOP_END_SET) == 0) {
1313 stop.endPos = toStop->getEndLanePosition();
1314 } else {
1315 stop.endPos = attrs.get<double>(SUMO_ATTR_ENDPOS, nullptr, ok);
1316 }
1317 stop.startPos = toStop->getBeginLanePosition();
1318 edge = &l.getEdge();
1319 } else {
1320 // no, the lane and the position should be given directly
1321 // get the lane
1322 stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, nullptr, ok, "");
1323 stop.edge = attrs.getOpt<std::string>(SUMO_ATTR_EDGE, nullptr, ok, "");
1324 if (ok && stop.edge != "") { // edge is given directly
1325 edge = MSEdge::dictionary(stop.edge);
1326 if (edge == nullptr || (edge->isInternal() && !MSGlobals::gUsingInternalLanes)) {
1327 throw ProcessError(TLF("The edge '%' for a stop is not known%.", stop.edge, errorSuffix));
1328 }
1329 } else if (ok && stop.lane != "") { // lane is given directly
1330 MSLane* stopLane = MSLane::dictionary(stop.lane);
1331 if (stopLane == nullptr) {
1332 // check for opposite-direction stop
1333 stopLane = MSBaseVehicle::interpretOppositeStop(stop);
1334 if (stopLane != nullptr) {
1335 edge = MSEdge::dictionary(stop.edge);
1336 }
1337 } else {
1338 edge = &stopLane->getEdge();
1339 }
1340 if (stopLane == nullptr || (stopLane->isInternal() && !MSGlobals::gUsingInternalLanes)) {
1341 throw ProcessError(TLF("The lane '%' for a stop is not known%.", stop.lane, errorSuffix));
1342 }
1343 } else if (ok && ((attrs.hasAttribute(SUMO_ATTR_X) && attrs.hasAttribute(SUMO_ATTR_Y))
1344 || (attrs.hasAttribute(SUMO_ATTR_LON) && attrs.hasAttribute(SUMO_ATTR_LAT)))) {
1345 Position pos;
1346 bool geo = false;
1347 if (attrs.hasAttribute(SUMO_ATTR_X) && attrs.hasAttribute(SUMO_ATTR_Y)) {
1348 pos = Position(attrs.get<double>(SUMO_ATTR_X, myVehicleParameter->id.c_str(), ok), attrs.get<double>(SUMO_ATTR_Y, myVehicleParameter->id.c_str(), ok));
1349 } else {
1350 pos = Position(attrs.get<double>(SUMO_ATTR_LON, myVehicleParameter->id.c_str(), ok), attrs.get<double>(SUMO_ATTR_LAT, myVehicleParameter->id.c_str(), ok));
1351 geo = true;
1352 }
1353 PositionVector positions;
1354 positions.push_back(pos);
1355 ConstMSEdgeVector geoEdges;
1357 auto& vc = MSNet::getInstance()->getVehicleControl();
1358 if (!vc.getVTypeDistribution(myVehicleParameter->vtypeid)) {
1359 MSVehicleType* const type = vc.getVType(myVehicleParameter->vtypeid, &myParsingRNG);
1360 if (type != nullptr) {
1361 vClass = type->getParameter().vehicleClass;
1362 }
1363 }
1364 parseGeoEdges(positions, geo, vClass, geoEdges, myVehicleParameter->id, true, ok, true);
1365 if (ok) {
1366 edge = geoEdges.front();
1367 if (geo) {
1369 }
1371 stop.endPos = edge->getLanes()[0]->getShape().nearest_offset_to_point2D(pos, false);
1372 } else {
1373 throw ProcessError(TLF("Could not map stop position '%' to the network%.", pos, errorSuffix));
1374 }
1375 } else {
1376 if (myActiveTransportablePlan && !myActiveTransportablePlan->empty()) { // use end of movement before
1377 toStop = myActiveTransportablePlan->back()->getDestinationStop();
1378 if (toStop != nullptr) { // use end of movement before definied as a stopping place
1379 edge = &toStop->getLane().getEdge();
1380 stop.lane = toStop->getLane().getID();
1381 stop.endPos = toStop->getEndLanePosition();
1382 stop.startPos = toStop->getBeginLanePosition();
1383 } else { // use end of movement before definied as lane/edge
1384 edge = myActiveTransportablePlan->back()->getDestination();
1385 stop.lane = edge->getLanes()[0]->getID();
1386 stop.endPos = myActiveTransportablePlan->back()->unspecifiedArrivalPos() ?
1388 stop.startPos = MAX2(0., stop.endPos - MIN_STOP_LENGTH);
1389 }
1390 } else {
1391 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);
1393 throw ProcessError(msg);
1394 } else {
1395 WRITE_WARNING(msg);
1396 return result;
1397 }
1398 }
1399 }
1400 stop.endPos = attrs.getOpt<double>(SUMO_ATTR_ENDPOS, nullptr, ok, edge->getLength());
1401 if (attrs.hasAttribute(SUMO_ATTR_POSITION)) {
1402 WRITE_WARNINGF(TL("Deprecated attribute 'pos' in description of stop%."), errorSuffix);
1403 stop.endPos = attrs.getOpt<double>(SUMO_ATTR_POSITION, nullptr, ok, stop.endPos);
1404 }
1405 if (stop.endPos < 0) {
1406 stop.endPos += edge->getLength();
1407 }
1408 stop.startPos = attrs.getOpt<double>(SUMO_ATTR_STARTPOS, nullptr, ok, MAX2(0., stop.endPos - MIN_STOP_LENGTH));
1409 if (!myAmLoadingState) {
1410 const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, nullptr, ok, !attrs.hasAttribute(SUMO_ATTR_STARTPOS) && !attrs.hasAttribute(SUMO_ATTR_ENDPOS))
1412 if (!ok || (checkStopPos(stop.startPos, stop.endPos, edge->getLength(), 0, friendlyPos) != StopPos::STOPPOS_VALID)) {
1413 throw ProcessError(TLF("Invalid start or end position for stop on %'%.",
1414 stop.lane != "" ? ("lane '" + stop.lane) : ("edge '" + stop.edge), errorSuffix));
1415 }
1416 }
1417 }
1418 stop.edge = edge->getID();
1420 if (myActiveTransportablePlan->empty()) {
1421 double departPos = toStop == nullptr || myVehicleParameter->wasSet(VEHPARS_DEPARTPOS_SET)
1423 : (toStop->getBeginLanePosition() + toStop->getEndLanePosition()) / 2;
1425 edge, toStop, -1, myVehicleParameter->depart, departPos, "start", true));
1426 } else if (myActiveTransportablePlan->back()->getDestination() != edge) {
1427 if (myActiveTransportablePlan->back()->getDestination()->isTazConnector()) {
1428 myActiveTransportablePlan->back()->setDestination(edge, toStop);
1429 } else if (myActiveTransportablePlan->back()->getJumpDuration() < 0) {
1430 throw ProcessError(TLF("Disconnected plan for % '%' (%!=%).", myActiveTypeName, myVehicleParameter->id,
1431 edge->getID(), myActiveTransportablePlan->back()->getDestination()->getID()));
1432 }
1433 }
1434 // transporting veh stops somewhere
1435 else if (myActiveTransportablePlan->back()->getStageType() == MSStageType::WAITING
1437 const double start = SUMOVehicleParameter::interpretEdgePos(stop.startPos, edge->getLength(), SUMO_ATTR_STARTPOS, "stopping at " + edge->getID());
1438 const double end = SUMOVehicleParameter::interpretEdgePos(stop.endPos, edge->getLength(), SUMO_ATTR_ENDPOS, "stopping at " + edge->getID());
1439 const double prevAr = myActiveTransportablePlan->back()->getArrivalPos();
1440 if (start > prevAr + NUMERICAL_EPS || end < prevAr - NUMERICAL_EPS) {
1441 WRITE_WARNINGF(TL("Disconnected plan for % '%' (stop range %-% does not cover previous arrival position %)."),
1443 }
1444 }
1445 std::string actType = attrs.getOpt<std::string>(SUMO_ATTR_ACTTYPE, nullptr, ok, "");
1446 double pos = (stop.startPos + stop.endPos) / 2.;
1447 if (!myActiveTransportablePlan->empty() && myActiveTransportablePlan->back()->getJumpDuration() < 0) {
1448 pos = myActiveTransportablePlan->back()->unspecifiedArrivalPos() ?
1450 }
1451 myActiveTransportablePlan->push_back(new MSStageWaiting(edge, toStop, stop.duration, stop.until, pos, actType, false, stop.jump));
1452 result = myActiveTransportablePlan->back();
1453
1454 } else if (myVehicleParameter != nullptr) {
1455 myVehicleParameter->stops.push_back(stop);
1456 result = &myVehicleParameter->stops.back();
1457 } else {
1458 myActiveRouteStops.push_back(stop);
1459 result = &myActiveRouteStops.back();
1460 }
1461 if (myInsertStopEdgesAt >= 0) {
1462 //std::cout << " myInsertStopEdgesAt=" << myInsertStopEdgesAt << " edge=" << edge->getID() << " myRoute=" << toString(myActiveRoute) << "\n";
1463 if (edge->isInternal()) {
1464 if (myInsertStopEdgesAt > 0 && *(myActiveRoute.begin() + (myInsertStopEdgesAt - 1)) != edge->getNormalBefore()) {
1467 }
1470 } else {
1471 myActiveRoute.insert(myActiveRoute.begin() + myInsertStopEdgesAt, edge);
1473 }
1474 } else if (myHaveVia) {
1475 // vias were loaded, check for consistency
1476 if (std::find(myActiveRoute.begin(), myActiveRoute.end(), edge) == myActiveRoute.end()) {
1477 WRITE_WARNINGF(TL("Stop edge '%' missing in attribute 'via' for % '%'."),
1479 }
1480 }
1481 } catch (ProcessError&) {
1483 throw;
1484 }
1485 return result;
1486}
1487
1488
1489void
1490MSRouteHandler::parseWalkPositions(const SUMOSAXAttributes& attrs, const std::string& personID,
1491 const MSEdge* fromEdge, const MSEdge*& toEdge,
1492 double& departPos, double& arrivalPos, MSStoppingPlace*& bs,
1493 const MSStage* const lastStage, bool& ok) {
1494 try {
1495 const std::string description = "person '" + personID + "' walking from edge '" + fromEdge->getID() + "'";
1496
1497 if (attrs.hasAttribute(SUMO_ATTR_DEPARTPOS)) {
1498 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."));
1499 }
1500 departPos = 0.;
1501 if (lastStage != nullptr) {
1502 if (lastStage->getDestinationStop() != nullptr) {
1503 departPos = lastStage->getDestinationStop()->getAccessPos(fromEdge, &myParsingRNG);
1504 } else if (lastStage->getDestination() == fromEdge) {
1505 departPos = lastStage->getArrivalPos();
1506 } else if (lastStage->getDestination()->getToJunction() == fromEdge->getToJunction()) {
1507 departPos = fromEdge->getLength();
1508 }
1509 }
1510
1511 bs = retrieveStoppingPlace(attrs, " " + description);
1512 if (bs != nullptr) {
1513 arrivalPos = bs->getAccessPos(toEdge != nullptr ? toEdge : &bs->getLane().getEdge());
1514 if (arrivalPos < 0) {
1515 throw ProcessError("Bus stop '" + bs->getID() + "' is not connected to arrival edge '" + toEdge->getID() + "' for " + description + ".");
1516 }
1518 const double length = toEdge != nullptr ? toEdge->getLength() : bs->getLane().getLength();
1519 const double arrPos = SUMOVehicleParserHelper::parseWalkPos(SUMO_ATTR_ARRIVALPOS, myHardFail, description, length,
1520 attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, description.c_str(), ok), &myParsingRNG);
1521 if (arrPos >= bs->getBeginLanePosition() && arrPos < bs->getEndLanePosition()) {
1522 arrivalPos = arrPos;
1523 } else {
1524 WRITE_WARNINGF(TL("Ignoring arrivalPos for % because it is outside the given stop '%'."), description, toString(SUMO_ATTR_BUS_STOP));
1525 arrivalPos = bs->getAccessPos(&bs->getLane().getEdge());
1526 }
1527 }
1528 } else {
1529 if (toEdge == nullptr) {
1530 throw ProcessError(TLF("No destination edge for %.", description));
1531 }
1534 attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, description.c_str(), ok), &myParsingRNG);
1535 } else {
1536 arrivalPos = toEdge->getLength() / 2.;
1537 }
1538 }
1539 } catch (ProcessError&) {
1541 throw;
1542 }
1543}
1544
1545
1546void
1548 if (myVehicleParameter == nullptr) {
1549 throw ProcessError(TL("Cannot define person stage without person."));
1550 }
1551 try {
1552 myActiveRoute.clear();
1553 bool ok = true;
1554 const char* const id = myVehicleParameter->id.c_str();
1555 const MSEdge* from = nullptr;
1556 const MSEdge* to = nullptr;
1561 from = myActiveRoute.front();
1562 } else if (myActiveTransportablePlan->empty()) {
1563 throw ProcessError(TLF("Start edge not defined for person '%'.", myVehicleParameter->id));
1564 } else {
1565 from = myActiveTransportablePlan->back()->getDestination();
1566 }
1569 to = myActiveRoute.back();
1570 } // else, to may also be derived from stopping place
1571
1572 const SUMOTime duration = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DURATION, id, ok, -1);
1573 if (attrs.hasAttribute(SUMO_ATTR_DURATION) && duration <= 0) {
1574 throw ProcessError(TLF("Non-positive walking duration for '%'.", myVehicleParameter->id));
1575 }
1576
1577 double departPos = 0;
1578 double arrivalPos = 0;
1579 MSStoppingPlace* stoppingPlace = nullptr;
1580 parseWalkPositions(attrs, myVehicleParameter->id, from, to, departPos, arrivalPos, stoppingPlace, nullptr, ok);
1581
1582 SVCPermissions modeSet = 0;
1583 if (attrs.hasAttribute(SUMO_ATTR_MODES)) {
1584 const std::string modes = attrs.getOpt<std::string>(SUMO_ATTR_MODES, id, ok, "");
1585 std::string errorMsg;
1586 // try to parse person modes
1587 if (!SUMOVehicleParameter::parsePersonModes(modes, "person", id, modeSet, errorMsg)) {
1588 throw InvalidArgument(errorMsg);
1589 }
1590 } else {
1591 modeSet = myVehicleParameter->modes;
1592 }
1593 const std::string group = attrs.getOpt<std::string>(SUMO_ATTR_GROUP, id, ok, OptionsCont::getOptions().getString("persontrip.default.group"));
1595 const std::string types = attrs.getOpt<std::string>(SUMO_ATTR_VTYPES, id, ok, myVehicleParameter->vTypes);
1596 for (StringTokenizer st(types); st.hasNext();) {
1597 const std::string vtypeid = st.next();
1598 const MSVehicleType* const vType = vehControl.getVType(vtypeid);
1599 if (vType == nullptr) {
1600 throw InvalidArgument("The vehicle type '" + vtypeid + "' in a trip for person '" + myVehicleParameter->id + "' is not known.");
1601 }
1602 modeSet |= (vType->getVehicleClass() == SVC_BICYCLE) ? SVC_BICYCLE : SVC_PASSENGER;
1603 }
1604 const double speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, id, ok, -1.);
1605 if (attrs.hasAttribute(SUMO_ATTR_SPEED) && speed <= 0) {
1606 throw ProcessError(TLF("Non-positive walking speed for '%'.", myVehicleParameter->id));
1607 }
1608 const double walkFactor = attrs.getOpt<double>(SUMO_ATTR_WALKFACTOR, id, ok, OptionsCont::getOptions().getFloat("persontrip.walkfactor"));
1609 const double departPosLat = interpretDepartPosLat(attrs.getOpt<std::string>(SUMO_ATTR_DEPARTPOS_LAT, nullptr, ok, ""), -1, "personTrip");
1610 if (ok) {
1611 if (myActiveTransportablePlan->empty()) {
1612 double initialDepartPos = myVehicleParameter->departPos;
1614 initialDepartPos = RandHelper::rand(from->getLength(), &myParsingRNG);
1615 }
1616 myActiveTransportablePlan->push_back(new MSStageWaiting(from, nullptr, -1, myVehicleParameter->depart, initialDepartPos, "start", true));
1617 }
1619 MSStoppingPlace* fromStop = myActiveTransportablePlan->empty() ? nullptr : myActiveTransportablePlan->back()->getDestinationStop();
1620 myActiveTransportablePlan->push_back(new MSStageTrip(from, fromStop, to == nullptr ? &stoppingPlace->getLane().getEdge() : to,
1621 stoppingPlace, duration, modeSet, types, speed, walkFactor, group,
1622 departPosLat, attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS), arrivalPos));
1623 myParamStack.push_back(myActiveTransportablePlan->back());
1626 }
1627 }
1628 myActiveRoute.clear();
1629 } catch (ProcessError&) {
1631 throw;
1632 }
1633}
1634
1635
1636void
1638 if (myVehicleParameter == nullptr) {
1639 throw ProcessError(TL("Cannot define person stage without person."));
1640 }
1641 myActiveRouteID = "";
1643 try {
1644 myActiveRoute.clear();
1645 bool ok = true;
1646 const SUMOTime duration = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DURATION, nullptr, ok, -1);
1647 if (attrs.hasAttribute(SUMO_ATTR_DURATION) && duration <= 0) {
1648 throw ProcessError(TLF("Non-positive walking duration for '%'.", myVehicleParameter->id));
1649 }
1650 double speed = -1; // default to vType speed
1651 if (attrs.hasAttribute(SUMO_ATTR_SPEED)) {
1652 speed = attrs.get<double>(SUMO_ATTR_SPEED, nullptr, ok);
1653 if (speed <= 0) {
1654 throw ProcessError(TLF("Non-positive walking speed for '%'.", myVehicleParameter->id));
1655 }
1656 }
1657 double departPos = 0;
1658 double arrivalPos = 0;
1659 MSStoppingPlace* bs = nullptr;
1660 if (attrs.hasAttribute(SUMO_ATTR_ROUTE)) {
1661 myActiveRouteID = attrs.get<std::string>(SUMO_ATTR_ROUTE, myVehicleParameter->id.c_str(), ok);
1663 if (route == nullptr) {
1664 throw ProcessError("The route '" + myActiveRouteID + "' for walk of person '" + myVehicleParameter->id + "' is not known.");
1665 }
1666 myActiveRoute = route->getEdges();
1667 } else {
1669 }
1670 if (myActiveTransportablePlan->empty()) {
1671 double initialDepartPos = myVehicleParameter->departPos;
1673 initialDepartPos = RandHelper::rand(myActiveRoute.front()->getLength(), &myParsingRNG);
1674 }
1675 myActiveTransportablePlan->push_back(new MSStageWaiting(myActiveRoute.front(), nullptr, -1, myVehicleParameter->depart, initialDepartPos, "start", true));
1676 }
1677 parseWalkPositions(attrs, myVehicleParameter->id, myActiveRoute.front(), myActiveRoute.back(), departPos, arrivalPos, bs, myActiveTransportablePlan->back(), ok);
1678 if (myActiveRoute.empty()) {
1679 throw ProcessError(TLF("No edges to walk for person '%'.", myVehicleParameter->id));
1680 }
1681 if (myActiveTransportablePlan->back()->getDestination() != myActiveRoute.front() &&
1682 myActiveTransportablePlan->back()->getDestination()->getToJunction() != myActiveRoute.front()->getFromJunction() &&
1683 myActiveTransportablePlan->back()->getDestination()->getToJunction() != myActiveRoute.front()->getToJunction()) {
1684 if (myActiveTransportablePlan->back()->getDestinationStop() == nullptr || myActiveTransportablePlan->back()->getDestinationStop()->getAccessPos(myActiveRoute.front()) < 0.) {
1685 throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + myActiveRoute.front()->getID() + " not connected to " + myActiveTransportablePlan->back()->getDestination()->getID() + ").");
1686 }
1687 }
1688 const int departLane = attrs.getOpt<int>(SUMO_ATTR_DEPARTLANE, nullptr, ok, -1);
1689 const double departPosLat = interpretDepartPosLat(attrs.getOpt<std::string>(SUMO_ATTR_DEPARTPOS_LAT, nullptr, ok, ""), departLane, "walk");
1690 MSStageWalking* stage = new MSStageWalking(myVehicleParameter->id, myActiveRoute, bs, duration, speed, departPos, arrivalPos, departPosLat, departLane, myActiveRouteID);
1691 stage->setDeparted(attrs.getOptSUMOTimeReporting(SUMO_ATTR_STARTED, nullptr, ok, -1));
1692 stage->setEnded(attrs.getOptSUMOTimeReporting(SUMO_ATTR_ENDED, nullptr, ok, -1));
1694 if (attrs.hasAttribute(SUMO_ATTR_EXITTIMES) && OptionsCont::getOptions().getBool("vehroute-output.exit-times")) {
1695 std::vector<SUMOTime>* exitTimes = new std::vector<SUMOTime>();
1696 for (const std::string& tStr : attrs.get<std::vector<std::string> >(SUMO_ATTR_EXITTIMES, nullptr, ok)) {
1697 exitTimes->push_back(string2time(tStr));
1698 }
1699 stage->setExitTimes(exitTimes);
1700 }
1703 }
1704 myActiveTransportablePlan->push_back(stage);
1705 myParamStack.push_back(stage);
1706 myActiveRoute.clear();
1707 } catch (ProcessError&) {
1709 throw;
1710 }
1711 } else { // parse walks from->to as person trips
1712 addPersonTrip(attrs);
1713 }
1714}
1715
1716double
1717MSRouteHandler::interpretDepartPosLat(const std::string& value, int departLane, const std::string& element) {
1718 double pos = MSPModel::UNSPECIFIED_POS_LAT;
1719 if (value == "") {
1720 return pos;
1721 }
1722 std::string error;
1724 if (SUMOVehicleParameter::parseDepartPosLat(value, element, myVehicleParameter->id, pos, dpd, error)) {
1725 if (dpd != DepartPosLatDefinition::GIVEN) {
1727 if (lane == nullptr) {
1728 throw ProcessError(TLF("Could not find departure lane for walk of person '%' when interpreting departPosLat", myVehicleParameter->id));
1729 }
1730 const double usableWidth = lane->getWidth() - 0.5;
1731 switch (dpd) {
1733 pos = -usableWidth / 2;
1734 break;
1736 pos = usableWidth / 2;
1737 break;
1739 pos = 0;
1740 break;
1746 break;
1747 default:
1748 break;
1749 }
1750 }
1751 } else {
1752 throw ProcessError(error);
1753 }
1754 return pos;
1755}
1756
1757
1758void
1759MSRouteHandler::addTransportable(const SUMOSAXAttributes& /*attrs*/, const bool isPerson) {
1761 if (!MSNet::getInstance()->getVehicleControl().hasVType(myVehicleParameter->vtypeid)) {
1762 const std::string error = TLF("The type '%' for % '%' is not known.", myVehicleParameter->vtypeid, myActiveTypeName, myVehicleParameter->id);
1764 throw ProcessError(error);
1765 }
1767}
1768
1769
1770void
1772 try {
1773 myActiveRoute.clear();
1774 const std::string cid = myVehicleParameter->id;
1775 bool ok = true;
1776 const MSEdge* from = nullptr;
1777 const MSEdge* to = nullptr;
1778 MSStoppingPlace* cs = nullptr;
1779
1780 double speed;
1782 if (attrs.hasAttribute(SUMO_ATTR_SPEED)) { // speed is explicitly set
1783 speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, nullptr, ok, -1);
1784 if (!ok) {
1785 throw ProcessError(TLF("Could not read tranship speed for container '%'.", cid));
1786 }
1787 } else if (vtype != nullptr && vtype->wasSet(VTYPEPARS_MAXSPEED_SET)) { // speed is set by vtype
1788 speed = vtype->getMaxSpeed();
1789 } else { // default speed value
1791 }
1792 if (speed <= 0) {
1793 throw ProcessError(TLF("Non-positive tranship speed for container '%'.", cid));
1794 }
1795 // values from preceding stage:
1796 const MSEdge* preEdge = nullptr;
1797 double prePos = 0;
1798 if (!myActiveTransportablePlan->empty()) {
1799 preEdge = myActiveTransportablePlan->back()->getDestination();
1800 prePos = myActiveTransportablePlan->back()->getArrivalPos();
1801 }
1802 // set depart position as given attribute value, arrival position of preceding stage or default (=0)
1803 double departPos = attrs.getOpt<double>(SUMO_ATTR_DEPARTPOS, cid.c_str(), ok, prePos);
1804
1805 if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
1806 MSEdge::parseEdgesList(attrs.get<std::string>(SUMO_ATTR_EDGES, cid.c_str(), ok), myActiveRoute, myActiveRouteID);
1807 } else {
1808 // set 'from':
1809 if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
1810 const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, cid.c_str(), ok);
1811 from = MSEdge::dictionary(fromID);
1812 if (from == nullptr) {
1813 throw ProcessError("The from edge '" + fromID + "' within a tranship of container '" + cid + "' is not known.");
1814 }
1815 if (preEdge != nullptr && preEdge != from) {
1816 throw ProcessError("Disconnected plan for container '" + cid + "' (" + from->getID() + "!=" + preEdge->getID() + ").");
1817 }
1818 } else if (preEdge == nullptr) {
1819 throw ProcessError(TLF("The start edge for container '%' is not known.", cid));
1820 } else {
1821 from = preEdge;
1822 }
1823 // set 'to':
1824 if (attrs.hasAttribute(SUMO_ATTR_TO)) {
1825 const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, cid.c_str(), ok);
1826 to = MSEdge::dictionary(toID);
1827 if (to == nullptr) {
1828 throw ProcessError("The to edge '" + toID + "' within a tranship of container '" + cid + "' is not known.");
1829 }
1830 } else {
1831 const std::string description = "container '" + cid + "' transhipping from edge '" + from->getID() + "'";
1832 cs = retrieveStoppingPlace(attrs, " " + description);
1833 if (cs != nullptr) {
1834 to = &cs->getLane().getEdge();
1835 } else {
1836 throw ProcessError(TLF("Inconsistent tranship for container '%', needs either: 'edges', 'to', 'containerStop' (or any other stopping place)", cid));
1837 }
1838 }
1839 myActiveRoute.push_back(from);
1840 myActiveRoute.push_back(to);
1841 }
1842 if (myActiveRoute.empty()) {
1843 throw ProcessError(TLF("No edges to tranship container '%'.", cid));
1844 }
1845 if (preEdge == nullptr) { // additional 'stop' to start the container plan
1847 myActiveRoute.front(), nullptr, -1, myVehicleParameter->depart, departPos, "start", true));
1848 }
1849 double arrivalPos = attrs.getOpt<double>(SUMO_ATTR_ARRIVALPOS, cid.c_str(), ok,
1850 cs == nullptr ? myActiveRoute.back()->getLength() : cs->getEndLanePosition());
1851 myActiveTransportablePlan->push_back(new MSStageTranship(myActiveRoute, cs, speed, departPos, arrivalPos));
1852 myParamStack.push_back(myActiveTransportablePlan->back());
1853 myActiveRoute.clear();
1854 } catch (ProcessError&) {
1856 throw;
1857 }
1858}
1859
1860
1861void
1863 for (const auto& edge : MSEdge::getAllEdges()) {
1864 if (edge->isNormal() || MSGlobals::gUsingInternalLanes) {
1865 for (MSLane* lane : edge->getLanes()) {
1866 Boundary b = lane->getShape().getBoxBoundary();
1867 const float cmin[2] = {(float) b.xmin(), (float) b.ymin()};
1868 const float cmax[2] = {(float) b.xmax(), (float) b.ymax()};
1869 tree->Insert(cmin, cmax, lane);
1870 }
1871 }
1872 }
1873}
1874
1875
1876SumoRNG*
1878 return &myParsingRNG;
1879}
1880
1881
1882MSEdge*
1883MSRouteHandler::retrieveEdge(const std::string& id) {
1884 return MSEdge::dictionary(id);
1885}
1886
1887
1888/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:74
#define JUNCTION_TAZ_MISSING_HELP
Definition MapMatcher.h:30
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:287
#define WRITE_ERROR(msg)
Definition MsgHandler.h:295
#define WRITE_WARNING(msg)
Definition MsgHandler.h:286
#define TL(string)
Definition MsgHandler.h:304
#define TLF(string,...)
Definition MsgHandler.h:306
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.h:32
SUMOTime DELTA_T
Definition SUMOTime.cpp:38
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
#define SUMOTime_MAX
Definition SUMOTime.h:34
#define TIME2STEPS(x)
Definition SUMOTime.h:60
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.
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
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_CONTAINER_STOP
A container stop.
@ SUMO_TAG_CONTAINERFLOW
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_FLOW
a flow definition using from and to edges or a route
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_TAG_TRANSPORT
@ SUMO_TAG_RIDE
@ SUMO_TAG_OVERHEAD_WIRE_SEGMENT
An overhead wire segment.
@ 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_CONTAINER_STOP
@ SUMO_ATTR_PARKING_AREA
@ SUMO_ATTR_VIAXY
@ SUMO_ATTR_Y
@ SUMO_ATTR_EDGE
@ SUMO_ATTR_DEPARTPOS_LAT
@ SUMO_ATTR_BUS_STOP
@ SUMO_ATTR_TRAIN_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_CHARGING_STATION
@ SUMO_ATTR_ROUTES
@ SUMO_ATTR_MODES
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_EXITTIMES
@ SUMO_ATTR_OVERHEAD_WIRE_SEGMENT
@ 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:49
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:77
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition MSEdge.cpp:1120
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition MSEdge.h:168
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:1144
const MSEdge * getNormalSuccessor() const
if this edge is an internal edge, return its first normal successor, otherwise the edge itself
Definition MSEdge.cpp:981
const MSJunction * getToJunction() const
Definition MSEdge.h:427
double getLength() const
return the length of the edge
Definition MSEdge.h:694
bool isInternal() const
return whether this edge is an internal edge
Definition MSEdge.h:269
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:1081
const MSEdge * getNormalBefore() const
if this edge is an internal edge, return its first normal predecessor, otherwise the edge itself
Definition MSEdge.cpp:971
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:617
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition MSLane.cpp:2521
bool isInternal() const
Definition MSLane.cpp:2652
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:775
double getWidth() const
Returns the lane's width.
Definition MSLane.h:646
The simulated network and simulation perfomer.
Definition MSNet.h:89
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:199
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition MSNet.h:495
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition MSNet.h:505
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition MSNet.cpp:1295
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition MSNet.cpp:1496
bool hasContainers() const
Returns whether containers are simulated.
Definition MSNet.h:435
bool hasPersons() const
Returns whether persons are simulated.
Definition MSNet.h:419
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition MSNet.h:455
SUMOTime getStateLoaderTime() const
return the next time for route loading the time of state loading
Definition MSNet.h:358
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:402
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1286
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 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
Wether 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
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.
static SumoRNG myParsingRNG
A random number generator used to choose from vtype/route distributions and computing the speed facto...
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
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:74
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:89
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
StopParVector myActiveRouteStops
List of the stops on the parsed route.
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.
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 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)
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
std::string overheadWireSegment
(Optional) overhead line segment 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.
std::string busstop
(Optional) bus stop if one is assigned to the stop
std::string containerstop
(Optional) container stop if one is assigned to the stop
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
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.
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 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