Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSBaseVehicle.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/****************************************************************************/
21// A base class for vehicle implementations
22/****************************************************************************/
23#include <config.h>
24
25#include <iostream>
26#include <cassert>
27#include <algorithm>
28#include <functional>
36#include <mesosim/MELoop.h>
37#include <mesosim/MEVehicle.h>
53#include "MSEventControl.h"
54#include "MSGlobals.h"
55#include "MSVehicleControl.h"
56#include "MSVehicleType.h"
57#include "MSEdge.h"
58#include "MSLane.h"
59#include "MSMoveReminder.h"
61#include "MSNet.h"
62#include "MSStop.h"
63#include "MSParkingArea.h"
64#include "MSInsertionControl.h"
65#include "MSStopOptimizer.h"
66#include "MSBaseVehicle.h"
67
68//#define DEBUG_REROUTE
69//#define DEBUG_ADD_STOP
70//#define DEBUG_COND (getID() == "")
71//#define DEBUG_COND (true)
72//#define DEBUG_REPLACE_ROUTE
73#define DEBUG_COND (isSelected())
74
75// ===========================================================================
76// static members
77// ===========================================================================
79std::vector<MSTransportable*> MSBaseVehicle::myEmptyTransportableVector;
80#ifdef _DEBUG
81std::set<std::string> MSBaseVehicle::myShallTraceMoveReminders;
82#endif
84
85// ===========================================================================
86// Influencer method definitions
87// ===========================================================================
88
91
92// ===========================================================================
93// method definitions
94// ===========================================================================
95
96double
98 throw ProcessError("getPreviousSpeed() is not available for non-MSVehicles.");
99}
100
101
103 MSVehicleType* type, const double speedFactor) :
104 SUMOVehicle(pars->id),
105 myParameter(pars),
106 myRoute(route),
107 myType(type),
108 myCurrEdge(route->begin()),
109 myChosenSpeedFactor(pars->speedFactor < 0 ? speedFactor : pars->speedFactor),
111 myPersonDevice(nullptr),
112 myContainerDevice(nullptr),
113 myEnergyParams(nullptr),
115 myDepartPos(-1),
116 myArrivalPos(-1),
117 myArrivalLane(-1),
120 myOdometer(0.),
122 myRoutingMode(libsumo::ROUTING_MODE_DEFAULT),
124 myRandomSeed(RandHelper::murmur3_32(pars->id, RandHelper::getSeed())),
125 myEdgeWeights(nullptr)
126#ifdef _DEBUG
127 , myTraceMoveReminders(myShallTraceMoveReminders.count(pars->id) > 0)
128#endif
129{
130 if ((*myRoute->begin())->isTazConnector() || myRoute->getLastEdge()->isTazConnector()) {
132 }
133 if ((pars->parametersSet & VEHPARS_FORCE_REROUTE) == 0) {
135 }
138}
139
140
142 delete myEdgeWeights;
143 if (myParameter->repetitionNumber == -1) {
144 // this is not a flow (flows call checkDist in MSInsertionControl::determineCandidates)
146 }
147 for (MSVehicleDevice* dev : myDevices) {
148 delete dev;
149 }
150 delete myEnergyParams;
151 delete myParkingMemory;
152 delete myChargingMemory;
154 delete myParameter;
155}
156
157
158void
160 // the check for an instance is needed for the unit tests which do not construct a network
161 // TODO Optimize for speed and there should be a better way to check whether a vehicle is part of a flow
162 if (MSNet::hasInstance() && !MSNet::getInstance()->hasFlow(getFlowID())) {
163 myRoute->checkRemoval();
164 }
165}
166
167
168std::string
170 return getID().substr(0, getID().rfind('.'));
171}
172
173
174void
177 for (MSVehicleDevice* dev : myDevices) {
178 myMoveReminders.push_back(std::make_pair(dev, 0.));
179 }
181 // ensure we have the emission parameters even if we don't have the device
183 }
184}
185
186
187void
188MSBaseVehicle::setID(const std::string& /*newID*/) {
189 throw ProcessError(TL("Changing a vehicle ID is not permitted"));
190}
191
194 return *myParameter;
195}
196
197
198void
200 delete myParameter;
201 myParameter = newParameter;
202}
203
204
205bool
209
210double
214
215
216const MSEdge*
217MSBaseVehicle::succEdge(int nSuccs) const {
218 if (myCurrEdge + nSuccs < myRoute->end() && std::distance(myCurrEdge, myRoute->begin()) <= nSuccs) {
219 return *(myCurrEdge + nSuccs);
220 } else {
221 return nullptr;
222 }
223}
224
225
226const MSEdge*
228 return *myCurrEdge;
229}
230
231
232const std::set<SUMOTrafficObject::NumericalID>
234 std::set<SUMOTrafficObject::NumericalID> result;
235 for (auto e = myCurrEdge; e != myRoute->end(); ++e) {
236 result.insert((*e)->getNumericalID());
237 }
238 return result;
239}
240
241
242bool
244 if (stop == nullptr) {
245 return false;
246 }
247 for (const MSStop& s : myStops) {
248 if (s.busstop == stop
249 || s.containerstop == stop
250 || s.parkingarea == stop
251 || s.chargingStation == stop) {
252 return true;
253 }
254 }
255 return false;
256}
257
258bool
260 for (const MSStop& s : myStops) {
261 if (&s.lane->getEdge() == edge) {
262 return true;
263 }
264 }
265 return myRoute->getLastEdge() == edge;
266}
267
268
269bool
270MSBaseVehicle::reroute(SUMOTime t, const std::string& info, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit, const bool withTaz, const bool silent, const MSEdge* sink) {
271 // check whether to reroute
272 const MSEdge* source = nullptr;
273 if (onInit) {
274 if (withTaz) {
275 source = MSEdge::dictionary(myParameter->fromTaz + "-source");
276 if (source == nullptr) {
277 source = myRoute->getEdges().front();
278 }
279 } else {
280 source = myRoute->getEdges().front();
281 }
282 } else {
283 source = *getRerouteOrigin();
284 }
285 if (sink == nullptr) {
286 sink = withTaz ? MSEdge::dictionary(myParameter->toTaz + "-sink") : myRoute->getLastEdge();
287 if (sink == nullptr) {
288 sink = myRoute->getLastEdge();
289 }
290 }
291 // on insertion, the new route is compared against the complete loaded route
292 ConstMSEdgeVector oldEdgesRemaining(onInit ? myRoute->begin() : (source == *myCurrEdge ? myCurrEdge : myCurrEdge + 1), myRoute->end());
293 ConstMSEdgeVector edges;
294 if (source != sink || !sink->prohibits(this)) {
295 edges.push_back(source);
296 }
297 std::vector<StopEdgeInfo> stops;
298 std::set<int> jumps;
299
300
301 double sourcePos = getPositionOnLane();
302#ifdef DEBUG_REROUTE
303 if (DEBUG_COND) {
304 std::cout << " curEdge=" << (*myCurrEdge)->getID() << " source=" << source->getID() << " sourcePos=" << sourcePos << " lane=" << Named::getIDSecure(getLane()) << " departPos=" << myParameter->departPos << " oldEdgesRemaining=" << toString(oldEdgesRemaining) << "\n";
305 }
306#endif
308 sourcePos = myParameter->departPos;
309 } else if (getLane() != nullptr && source != &getLane()->getEdge()) {
310 // routing starts on the next edge
311 sourcePos = 0;
312 }
313 if (myParameter->via.size() == 0) {
314 double firstPos = INVALID_DOUBLE;
315 double lastPos = INVALID_DOUBLE;
316 stops = getStopEdges(firstPos, lastPos, jumps);
317 if (stops.size() > 0) {
319 sourcePos = getNextStop().pars.endPos;
320 }
321 if ( !isStopped() && myStops.front().pars.speed == 0) {
322 sourcePos += getBrakeGap();
323 }
324 // avoid superfluous waypoints for first and last edge
325 const bool skipFirst = stops.front().edge == source && (source != getEdge() || sourcePos <= firstPos + NUMERICAL_EPS);
326#ifdef DEBUG_REROUTE
327 if (DEBUG_COND) {
328 std::cout << SIMTIME << " reroute " << info << " veh=" << getID() << " lane=" << Named::getIDSecure(getLane())
329 << " source=" << source->getID() << " sourcePos=" << sourcePos << " firstPos=" << firstPos << " arrivalPos=" << myArrivalPos << " lastPos=" << lastPos
330 << " route=" << toString(myRoute->getEdges()) << " skipFirst=" << skipFirst << "\n";
331 }
332#endif
333 if (stops.size() == 1 && skipFirst) {
334 stops.clear();
335 } else if (skipFirst) {
336 sourcePos = stops.front().pos;
337 stops.erase(stops.begin());
338 }
339 }
340 } else {
341 std::set<const MSEdge*> jumpEdges;
342 std::map<const MSEdge*, StopEdgeInfo> stopsOnVia;
343 for (const MSStop& stop : myStops) {
344 if (stop.pars.jump >= 0) {
345 jumpEdges.insert(*stop.edge);
346 }
347 auto itsov = stopsOnVia.find(*stop.edge);
348 if (itsov == stopsOnVia.end()) {
349 stopsOnVia.insert({*stop.edge, StopEdgeInfo(*stop.edge, stop.pars.priority, stop.getArrivalFallback(), stop.getEndPos(*this))});
350 } else {
351 itsov->second.priority = addStopPriority(itsov->second.priority, stop.pars.priority);
352 }
353 }
354 // via takes precedence over stop edges
355 // there is a consistency check in MSRouteHandler::addStop that warns when a stop edge is not part of the via edges
356 for (std::vector<std::string>::const_iterator it = myParameter->via.begin(); it != myParameter->via.end(); ++it) {
357 MSEdge* viaEdge = MSEdge::dictionary(*it);
358 if ((viaEdge == source && it == myParameter->via.begin()) || (viaEdge == sink && myParameter->via.end() - it == 1)) {
359 continue;
360 }
361 assert(viaEdge != 0);
362 if (!viaEdge->isTazConnector() && viaEdge->allowedLanes(getVClass()) == nullptr) {
363 throw ProcessError(TLF("Vehicle '%' is not allowed on any lane of via edge '%'.", getID(), viaEdge->getID()));
364 }
365 auto itsov = stopsOnVia.find(viaEdge);
366 const double priority = (itsov == stopsOnVia.end() ? -1 : itsov->second.priority);
367 const SUMOTime arrival = (itsov == stopsOnVia.end() ? -1 : itsov->second.arrival);
368 const double pos = (itsov == stopsOnVia.end() ? 0 : itsov->second.pos);
369 stops.push_back(StopEdgeInfo(viaEdge, priority, arrival, pos));
370 // @todo determine whether the viaEdge is also used by a stop and then use the stop priority here
371 if (jumpEdges.count(viaEdge) != 0) {
372 jumps.insert((int)stops.size());
373 }
374 }
375 }
376 if ((stops.size() == 0 && (source != sink || sourcePos > myArrivalPos))
377 || ((stops.size() != 0) && (stops.back().edge != sink || myArrivalPos < stops.back().pos))) {
378 stops.push_back(StopEdgeInfo(sink, -1, -1, myArrivalPos, true));
379 }
380#ifdef DEBUG_REROUTE
381 if (DEBUG_COND) {
382 std::cout << SIMTIME << " reroute veh=" << getID() << " onInit=" << onInit << " source=" << source->getID() << " sink=" << sink->getID() << " sourcePos=" << sourcePos << " arrivalPos=" << myArrivalPos << " stops:\n";
383 for (auto item : stops) {
384 std::cout << " e=" << item.edge->getID() << " pos=" << item.pos << " isSink=" << item.isSink << "\n";
385 }
386 }
387#endif
388 int stopIndex = -1;
389 auto stopIt = myStops.begin();
390 SUMOTime startTime = t;
391 bool hasSkipped = false;
392 const double origSourcePos = sourcePos;
393 const MSEdge* origSource = source;
395 for (auto& stopEdgeInfo : stops) {
396 const MSEdge* const stopEdge = stopEdgeInfo.edge;
397 const double priority = stopEdgeInfo.priority;
398 stopIndex++;
400 if (jumps.count(stopIndex) != 0) {
401 edges.push_back(stopEdge);
402 source = stopEdge;
403 continue;
404 }
405 // !!! need to adapt t here
406 router.compute(source, sourcePos, stopEdge, stopEdgeInfo.pos, this, t, into, silent || priority >= 0);
407#ifdef DEBUG_REROUTE
408 if (DEBUG_COND) {
409 std::cout << SIMTIME << " reroute veh=" << getID() << " source=" << source->getID() << " sourcePos=" << sourcePos << " target=" << stopEdgeInfo.edge->getID() << " targetPos=" << stopEdgeInfo.pos << " edges=" << toString(into) << "\n";
410 }
411#endif
412 if (into.size() > 0) {
413 // stopIt->edge may be invalid when trying to reroute for novel stops
414 while (stopIt != myStops.end() && stopIt->lane->getNextNormal()->getID() != stopEdge->getID()) {
415 stopIt++;
416 }
417
418 startTime += TIME2STEPS(router.recomputeCostsPos(into, this, sourcePos, stopEdgeInfo.pos, startTime));
419 if (stopIt != myStops.end()) {
420 if (stopIt->pars.priority >= 0 && info != "device.rerouting") {
421 // consider skipping this stop if it cannot be reached in a timely manner
422 if (stopIt != myStops.end()) {
423 SUMOTime arrival = stopEdgeInfo.arrival;
424 if (arrival > 0) {
425 SUMOTime delay = startTime - arrival;
426 //std::cout << " t=" << time2string(t) << " veh=" << getID() << " info=" << info << " stopIndex=" << stopIndex
427 // << " into=" << toString(into) << " sourcePos=" << sourcePos << " stopPos=" << stopPos
428 // << " startTime=" << time2string(startTime) << " arrival=" << time2string(arrival) << " delay=" << time2string(delay) << "\n";
429 if (delay > 0) {
430 if (delay > maxDelay) {
431 stopEdgeInfo.skipped = true;
432 stopEdgeInfo.delay = delay;
433 hasSkipped = true;
434 continue;
435 }
436 }
437 }
438 }
439 }
440 sourcePos = stopEdgeInfo.pos;
441 startTime += stopIt->getMinDuration(startTime);
442 }
443 edges.pop_back();
444 edges.insert(edges.end(), into.begin(), into.end());
445 if (edges.back()->isTazConnector()) {
446 edges.pop_back();
447 }
448 source = edges.back();
449 stopEdgeInfo.routeIndex = (int)edges.size() - 1;
450 } else {
451 if (priority >= 0) {
452 stopEdgeInfo.skipped = true;
453 hasSkipped = true;
454 continue;
455 } else if (stopEdgeInfo.isSink) {
456 //error = TLF("Vehicle '%' has no valid route from edge '%' to destination edge '%'.", getID(), source->getID(), stopEdge->getID());
457 edges.clear();
458 if (source == stopEdge && stops.size() == 1 && sourcePos > myArrivalPos) {
459 edges.push_back(stopEdge);
460 WRITE_WARNING(TLF("Vehicle '%' ignores arrivalPos % when driving from edge '%' to edge '%' with departPos %.",
461 getID(), myArrivalPos, source->getID(), stopEdge->getID(), sourcePos));
462 }
463 } else if (source == stopEdge && stopEdgeInfo.stopPar != nullptr && stopEdgeInfo.stopPar->endPos >= sourcePos) {
464 // special case: no failure on dynamically computed stop position
465 edges.clear();
466 } else {
467 std::string error = TLF("Vehicle '%' has no valid route from edge '%' to stop edge '%'.", getID(), source->getID(), stopEdge->getID());
468 if (MSGlobals::gCheckRoutes || silent) {
469 throw ProcessError(error);
470 } else {
471 WRITE_WARNING(error);
472 edges.push_back(source);
473 source = stopEdge;
474 }
475 }
476 }
477 }
478 if (hasSkipped) {
479 MSStopOptimizer opti(this, router, t, maxDelay);
480 edges = opti.optimizeSkipped(origSource, origSourcePos, stops, edges);
481 for (auto stop : stops) {
482 if (stop.skipped || stop.origEdge != nullptr) {
483 const MSEdge* origEdge = stop.origEdge == nullptr ? stop.edge : stop.origEdge;
484 if (stop.delay > 0) {
485 WRITE_WARNING(TLF("Vehicle '%' skips stop on edge '%' with delay % at time %.", getID(), origEdge->getID(), time2string(stop.delay), time2string(SIMSTEP)));
486 } else if (stop.backtracked) {
487 WRITE_WARNING(TLF("Vehicle '%' skips stop on edge '%' with priority % at time %.", getID(), origEdge->getID(), stop.priority, time2string(SIMSTEP)));
488 } else {
489 WRITE_WARNING(TLF("Vehicle '%' skips unreachable stop on edge '%' with priority % at time %.", getID(), origEdge->getID(), stop.priority, time2string(SIMSTEP)));
490 }
491 }
492 }
493 }
494
495 // router.setHint(myCurrEdge, myRoute->end(), this, t);
496 if (edges.empty() && silent) {
497 return false;
498 }
499 if (!edges.empty() && edges.front()->isTazConnector()) {
500 edges.erase(edges.begin());
501 }
502 if (!edges.empty() && edges.back()->isTazConnector()) {
503 edges.pop_back();
504 }
505 const double routeCost = router.recomputeCosts(edges, this, t);
506 // trips have no loaded route to compare against when routed on insertion
507 const bool isTripInit = onInit && myParameter->wasSet(VEHPARS_FORCE_REROUTE);
508 const double previousCost = isTripInit ? routeCost : router.recomputeCosts(oldEdgesRemaining, this, t);
509 const double savings = previousCost - routeCost;
510 bool savingsOk = isTripInit || info != "device.rerouting" || gWeightsRandomFactor != 1;
511 if (!savingsOk) {
512 MSDevice_Routing* routingDevice = static_cast<MSDevice_Routing*>(getDevice(typeid(MSDevice_Routing)));
513 assert(routingDevice != 0);
514 savingsOk = routingDevice->sufficientSaving(previousCost, routeCost);
515 if (!savingsOk) {
516 std::string dummyMsg;
517 if (!hasValidRoute(dummyMsg, oldEdgesRemaining.begin(), oldEdgesRemaining.end(), true)) {
518 // the old route is prohibted (i.e. due to temporary permission changes)
519 savingsOk = true;
520 }
521 }
522 }
523 //if (getID() == "43") std::cout << SIMTIME << " pCost=" << previousCost << " cost=" << routeCost
524 // << " onInit=" << onInit
525 // << " prevEdges=" << toString(oldEdgesRemaining)
526 // << " newEdges=" << toString(edges)
527 // << "\n";
528 if (savingsOk) {
529 replaceRouteEdges(edges, routeCost, savings, info, onInit, false, hasSkipped);
530 }
531 // this must be called even if the route could not be replaced
532 if (onInit) {
533 if (edges.empty()) {
535 throw ProcessError(TLF("Vehicle '%' has no valid route.", getID()));
536 } else if (source->isTazConnector()) {
537 WRITE_WARNINGF(TL("Removing vehicle '%' which has no valid route."), getID());
539 return false;
540 }
541 }
544 }
545 return !edges.empty();
546}
547
548
549bool
550MSBaseVehicle::replaceRouteEdges(ConstMSEdgeVector& edges, double cost, double savings, const std::string& info, bool onInit, bool check, bool removeStops, std::string* msgReturn) {
551 if (edges.empty()) {
552 WRITE_WARNINGF(TL("No route for vehicle '%' found."), getID());
553 if (msgReturn != nullptr) {
554 *msgReturn = "No route found";
555 }
556 return false;
557 }
558 // build a new id, first
559 std::string id = getID();
560 if (id[0] != '!') {
561 id = "!" + id;
562 }
563 const std::string idSuffix = id + "!var#";
564 int varIndex = 1;
565 id = idSuffix + toString(varIndex);
566 while (MSRoute::hasRoute(id)) {
567 id = idSuffix + toString(++varIndex);
568 }
569 int oldSize = (int)edges.size();
570 if (!onInit) {
571 const MSEdge* const origin = *getRerouteOrigin();
572 if (origin != *myCurrEdge && edges.front() == origin) {
573 edges.insert(edges.begin(), *myCurrEdge);
574 oldSize = (int)edges.size();
575 }
576 edges.insert(edges.begin(), myRoute->begin(), myCurrEdge);
577 }
578 if (edges == myRoute->getEdges() && haveValidStopEdges(true)) {
579 // re-assign stop iterators when rerouting to a new parkingArea / insertStop
580 return true;
581 }
582 const RGBColor& c = myRoute->getColor();
583 MSRoute* newRoute = new MSRoute(id, edges, false, &c == &RGBColor::DEFAULT_COLOR ? nullptr : new RGBColor(c), StopParVector());
584 newRoute->setCosts(cost);
585 newRoute->setSavings(savings);
586 ConstMSRoutePtr constRoute = std::shared_ptr<MSRoute>(newRoute);
587 if (!MSRoute::dictionary(id, constRoute)) {
588 delete newRoute;
589 if (msgReturn != nullptr) {
590 *msgReturn = "duplicate routeID '" + id + "'";
591 }
592 return false;
593 }
594
595 std::string msg;
596 if (check && !hasValidRoute(msg, constRoute)) {
597 WRITE_WARNINGF(TL("Invalid route replacement for vehicle '%'. %"), getID(), msg);
599 if (msgReturn != nullptr) {
600 *msgReturn = msg;
601 }
602 return false;
603 }
604 }
605 if (!replaceRoute(constRoute, info, onInit, (int)edges.size() - oldSize, false, removeStops, msgReturn)) {
606 return false;
607 }
608 return true;
609}
610
611
612bool
613MSBaseVehicle::replaceRoute(ConstMSRoutePtr newRoute, const std::string& info, bool onInit, int offset, bool addRouteStops, bool removeStops, std::string* msgReturn) {
614 const ConstMSEdgeVector& edges = newRoute->getEdges();
615 // rebuild in-vehicle route information
616 if (onInit) {
617 myCurrEdge = newRoute->begin();
618 } else {
619 MSRouteIterator newCurrEdge = std::find(edges.begin() + offset, edges.end(), *myCurrEdge);
620 if (newCurrEdge == edges.end()) {
621 if (msgReturn != nullptr) {
622 *msgReturn = TLF("current edge '%' not found in new route", (*myCurrEdge)->getID());
623 }
624#ifdef DEBUG_REPLACE_ROUTE
625 if (DEBUG_COND) {
626 std::cout << " newCurrEdge not found\n";
627 }
628#endif
629 return false;
630 }
631 if (getLane() != nullptr) {
632 if (getLane()->getEdge().isInternal() && (
633 (newCurrEdge + 1) == edges.end() || (*(newCurrEdge + 1)) != &(getLane()->getOutgoingViaLanes().front().first->getEdge()))) {
634 if (msgReturn != nullptr) {
635 *msgReturn = TL("Vehicle is on junction-internal edge leading elsewhere");
636 }
637#ifdef DEBUG_REPLACE_ROUTE
638 if (DEBUG_COND) {
639 std::cout << " Vehicle is on junction-internal edge leading elsewhere\n";
640 }
641#endif
642 return false;
643 } else if (getPositionOnLane() > getLane()->getLength()
644 && (myCurrEdge + 1) != myRoute->end()
645 && (newCurrEdge + 1) != edges.end()
646 && *(myCurrEdge + 1) != *(newCurrEdge + 1)) {
647 if (msgReturn != nullptr) {
648 *msgReturn = TL("Vehicle is moving past junction and committed to move to another successor edge");
649 }
650#ifdef DEBUG_REPLACE_ROUTE
651 if (DEBUG_COND) {
652 std::cout << " Vehicle is moving past junction and committed to move to another successor edge\n";
653 }
654#endif
655 return false;
656 }
657 }
658 myCurrEdge = newCurrEdge;
659 }
660 const bool stopsFromScratch = onInit && myRoute->getStops().empty();
661 // assign new route
663 myRoute = newRoute;
664 // update arrival definition
666 // save information that the vehicle was rerouted
668 myStopUntilOffset += myRoute->getPeriod();
670 if (!onInit && isRail() && MSRailSignalControl::hasInstance()) {
671 // we need to update driveways (add/remove reminders) before the next call to MSRailSignalControl::updateSignals
672 //
673 // rerouting may be triggered through
674 // - MoveReminders (executeMove->activateReminders)
675 // - rerouters
676 // - devices (MSDevice_Stationfinder)
677 // - TraCI (changeTarget, replaceStop, ...
678 // - events (MSDevice_Routing::myRerouteCommand, MSDevice_Taxi::triggerDispatch)
679 //
680 // Since activateReminders actively modifies reminders, adding/deleting reminders would create a mess
681 // hence, we use an event to be safe for all case
682
685 }
686#ifdef DEBUG_REPLACE_ROUTE
687 if (DEBUG_COND) {
688 std::cout << SIMTIME << " veh=" << getID() << " replaceRoute info=" << info << " on " << (*myCurrEdge)->getID()
689 << " lane=" << Named::getIDSecure(getLane())
690 << " stopsFromScratch=" << stopsFromScratch
691 << " newSize=" << newRoute->getEdges().size()
692 << " newIndex=" << (myCurrEdge - newRoute->begin())
693 << " edges=" << toString(newRoute->getEdges())
694 << "\n";
695 }
696#endif
697 // remove past stops which are not on the route anymore
698 for (StopParVector::iterator it = myPastStops.begin(); it != myPastStops.end();) {
699 const MSEdge* stopEdge = (it->edge.empty()) ? &MSLane::dictionary(it->lane)->getEdge() : MSEdge::dictionary(it->edge);
700 if (std::find(myRoute->begin(), myRoute->end(), stopEdge) == myRoute->end()) {
701 it = myPastStops.erase(it);
702 } else {
703 ++it;
704 }
705 }
706 // if we did not drive yet it may be best to simply reassign the stops from scratch
707 if (stopsFromScratch) {
708 myStops.clear();
710 } else {
711 // recheck old stops
712 MSRouteIterator searchStart = myCurrEdge;
713 double lastPos = getPositionOnLane() + getBrakeGap();
714 if (getLane() != nullptr && getLane()->isInternal()
715 && myStops.size() > 0 && !myStops.front().lane->isInternal()) {
716 // searchStart is still incoming to the intersection so lastPos
717 // relative to that edge must be adapted
718 lastPos += (*myCurrEdge)->getLength();
719 }
720 int stopIndex = 0;
721 for (std::list<MSStop>::iterator iter = myStops.begin(); iter != myStops.end();) {
722 int lastToSkip = 0;
723 double endPos = iter->getEndPos(*this);
724#ifdef DEBUG_REPLACE_ROUTE
725 if (DEBUG_COND) {
726 std::cout << " stopEdge=" << iter->lane->getEdge().getID() << " start=" << (searchStart - myCurrEdge) << " endPos=" << endPos << " lastPos=" << lastPos << "\n";
727 }
728#endif
729 if (*searchStart != &iter->lane->getEdge()
730 // loop required to reach upstream position
731 || endPos + NUMERICAL_EPS < lastPos
732 // loop requested at duplicate pos
733 || (endPos == lastPos && iter->pars.index == STOP_INDEX_REPEAT)
734 // index encodes a skip
735 || (iter->pars.index > (int)myPastStops.size() + stopIndex
736 // and we are not already past the skipped edge
737 && lastToSkip < (int)iter->skips.size()
738 && searchStart - myRoute->begin() <= iter->skips[lastToSkip])) {
739 if (searchStart != edges.end() && !iter->reached) {
740#ifdef DEBUG_REPLACE_ROUTE
741 if (DEBUG_COND) {
742 std::cout << " skip " << (*searchStart)->getID() << "\n";
743 }
744#endif
745 lastToSkip++;
746 searchStart++;
747 }
748 }
749 lastPos = endPos;
750
751 iter->edge = std::find(searchStart, edges.end(), &iter->lane->getEdge());
752#ifdef DEBUG_REPLACE_ROUTE
753 if (DEBUG_COND) {
754 std::cout << " foundIndex=" << (iter->edge - myCurrEdge) << " end=" << (edges.end() - myCurrEdge) << "\n";
755 }
756#endif
757 if (iter->edge == edges.end() && iter->pars.priority >= 0) {
758 const std::string oldEdge = iter->pars.edge;
759 const std::string oldName = iter->getStoppingPlaceName().first;
760 if (replaceWithAlternative(iter, searchStart, edges.end())) {
761 WRITE_WARNINGF(TL("Vehicle '%' replaced stop on edge '%' (named '%') and now stops at '%' instead; after rerouting (%) at time=%."),
762 getID(), oldEdge, oldName, iter->getDescription(true), info, time2string(SIMSTEP));
763 }
764 }
765 if (iter->edge == edges.end()) {
766 if (!removeStops) {
767 WRITE_ERRORF(TL("Vehicle '%' could not assign stop '%' after rerouting (%) at time=%."), getID(), iter->getDescription(), info, time2string(SIMSTEP));
768 }
769 iter = myStops.erase(iter);
770 continue;
771 } else {
772 setSkips(*iter, stopIndex);
773 searchStart = iter->edge;
774 }
775 ++iter;
776 stopIndex++;
777 }
778 // add new stops
779 if (addRouteStops) {
780 for (StopParVector::const_iterator i = newRoute->getStops().begin(); i != newRoute->getStops().end(); ++i) {
781 std::string error;
783 if (error != "") {
784 WRITE_WARNING(error);
785 }
786 }
787 }
788 }
789 return true;
790}
791
792
793bool
794MSBaseVehicle::replaceWithAlternative(std::list<MSStop>::iterator iter, const MSRouteIterator searchStart, const MSRouteIterator end) {
795 std::pair<std::string, SumoXMLTag> nameTag = iter->getStoppingPlaceName();
796 if (!nameTag.first.empty()) {
797 const std::vector<MSStoppingPlace*>& alternatives = MSNet::getInstance()->getStoppingPlaceAlternatives(nameTag.first, nameTag.second);
798 for (MSStoppingPlace* alt : alternatives) {
799 //std::cout << SIMTIME << " veh=" << getID() << " name=" << nameTag.first << " alt=" << alt->getID() << "\n";
800 if (&alt->getLane().getEdge() == &iter->lane->getEdge()
801 || !alt->getLane().allowsVehicleClass(getVClass())) {
802 continue;
803 }
804 iter->edge = std::find(searchStart, end, &alt->getLane().getEdge());
805 if (iter->edge != end) {
806 iter->replaceStoppingPlace(alt);
807 return true;
808 }
809 }
810 }
811 return false;
812}
813
814
815double
817 return 0;
818}
819
820
821void
827
828
831 const SUMOTime dep = getParameter().depart;
832 if (dep < 0) {
833 return 0;
834 }
835 return hasDeparted() ? getDeparture() - dep : SIMSTEP - dep;
836}
837
838
839bool
841 return succEdge(1) == nullptr;
842}
843
844
845int
847 return (int) std::distance(myRoute->begin(), myCurrEdge);
848}
849
850
851int
853 if (myParameter->arrivalEdge >= 0) {
855 } else {
856 return myRoute->size() - getRoutePosition();
857 }
858}
859
860
861void
863 myCurrEdge = myRoute->begin() + index;
864 const_cast<SUMOVehicleParameter*>(myParameter)->departLaneProcedure = departLaneProcedure;
865 // !!! hack
866 myArrivalPos = (*(myRoute->end() - 1))->getLanes()[0]->getLength();
867}
868
869double
873
874bool
876 if (t->isPerson() && getPersonNumber() >= getVehicleType().getPersonCapacity()) {
877 return false;
878 } else if (!t->isPerson() && getContainerNumber() >= getVehicleType().getContainerCapacity()) {
879 return false;
880 }
881 if (isStopped() && myStops.begin()->pars.permitted.size() > 0
882 && myStops.begin()->pars.permitted.count(t->getID()) == 0) {
883 return false;
884 }
885 MSDevice_Taxi* taxiDevice = static_cast<MSDevice_Taxi*>(getDevice(typeid(MSDevice_Taxi)));
886 if (taxiDevice != nullptr) {
887 return taxiDevice->allowsBoarding(t);
888 }
889 return true;
890}
891
892
893void
895 if (transportable->isPerson()) {
896 if (myPersonDevice == nullptr) {
900 }
901 }
902 myPersonDevice->addTransportable(transportable);
903 } else {
904 if (myContainerDevice == nullptr) {
908 }
909 }
910 myContainerDevice->addTransportable(transportable);
911 }
912 if (myEnergyParams != nullptr) {
914 }
915}
916
917
918void
920 if (isPerson) {
922 myMoveReminders.insert(myMoveReminders.begin(), std::make_pair(myPersonDevice, 0.));
923 } else {
925 myMoveReminders.insert(myMoveReminders.begin(), std::make_pair(myContainerDevice, 0.));
926 }
927}
928
929
930bool
932 for (const MSStop& stop : myStops) {
933 if (stop.edge == it && stop.pars.jump >= 0) {
934 return true;
935 } else if (stop.edge > it) {
936 return false;
937 }
938 }
939 return false;
940}
941
942
943bool
944MSBaseVehicle::hasValidRoute(std::string& msg, ConstMSRoutePtr route) const {
946 if (route == nullptr) {
947 route = myRoute;
948 } else {
949 start = route->begin();
950 }
951 const bool checkJumps = route == myRoute; // the edge iterators in the stops are invalid otherwise
952 return hasValidRoute(msg, start, route->end(), checkJumps);
953}
954
955
956bool
957MSBaseVehicle::hasValidRoute(std::string& msg, MSRouteIterator start, MSRouteIterator last, bool checkJumps) const {
958 MSRouteIterator lastValid = last - 1;
959 // check connectivity, first
960 for (MSRouteIterator e = start; e != lastValid; ++e) {
961 const MSEdge& next = **(e + 1);
962 if ((*e)->allowedLanes(next, myType->getVehicleClass()) == nullptr) {
963 if (!checkJumps || !hasJump(e)) {
965 || (!next.hasTransientPermissions() && !(*e)->hasTransientPermissions())) {
966 msg = TLF("No connection between edge '%' and edge '%'.", (*e)->getID(), (*(e + 1))->getID());
967 return false;
968 }
969 }
970 }
971 }
972 // check usable lanes, then
973 for (MSRouteIterator e = start; e != last; ++e) {
974 if ((*e)->prohibits(this)) {
975 msg = TLF("Edge '%' prohibits.", (*e)->getID());
976 return false;
977 }
978 }
979 return true;
980}
981
982
983bool
985 if (!(*myCurrEdge)->isTazConnector()) {
987 msg = TLF("Departure speed for vehicle '%' is too high for the vehicle type '%'.", getID(), myType->getID());
989 return false;
990 }
991 }
992 if (myRoute->getEdges().size() > 0 && !(*myCurrEdge)->prohibits(this)) {
993 myRouteValidity &= ~ROUTE_START_INVALID_PERMISSIONS;
994 return true;
995 } else {
996 msg = TLF("Vehicle '%' is not allowed to depart on any lane of edge '%'.", getID(), (*myCurrEdge)->getID());
998 return false;
999 }
1000}
1001
1002
1003int
1004MSBaseVehicle::getRouteValidity(bool update, bool silent, std::string* msgReturn) {
1005 if (!update) {
1006 return myRouteValidity;
1007 }
1008 // insertion check must be done in any case
1009 std::string msg;
1010 if (!hasValidRouteStart(msg)) {
1012 throw ProcessError(msg);
1013 } else if (!silent) {
1014 // vehicle will be discarded
1015 WRITE_WARNING(msg);
1016 } else if (msgReturn != nullptr) {
1017 *msgReturn = msg;
1018 }
1019 }
1020 if ((MSGlobals::gCheckRoutes || myRoute->getFirstEdge()->isInternal())
1022 // we could check after the first rerouting
1024 if (!hasValidRoute(msg, myRoute)) {
1026 throw ProcessError(TLF("Vehicle '%' has no valid route. %", getID(), msg));
1027 }
1028 }
1029 myRouteValidity &= ~ROUTE_UNCHECKED;
1030 return myRouteValidity;
1031}
1032
1033
1034bool
1036 for (auto item : myMoveReminders) {
1037 if (item.first == rem) {
1038 return true;
1039 }
1040 }
1041 return false;
1042}
1043
1044
1045void
1047#ifdef _DEBUG
1048 if (myTraceMoveReminders) {
1049 traceMoveReminder("add", rem, pos, true);
1050 }
1051#endif
1052 myMoveReminders.push_back(std::make_pair(rem, pos));
1053}
1054
1055
1056void
1058 for (MoveReminderCont::iterator r = myMoveReminders.begin(); r != myMoveReminders.end(); ++r) {
1059 if (r->first == rem) {
1060#ifdef _DEBUG
1061 if (myTraceMoveReminders) {
1062 traceMoveReminder("remove", rem, 0, false);
1063 }
1064#endif
1065 myMoveReminders.erase(r);
1066 return;
1067 }
1068 }
1069}
1070
1071
1072void
1074 // notifyEnter may cause new reminders to be added so we cannot use an iterator
1075 for (int i = 0; i < (int)myMoveReminders.size();) {
1076 MSMoveReminder* rem = myMoveReminders[i].first;
1077 const double remPos = myMoveReminders[i].second;
1078 // skip the reminder if it is a lane reminder but not for my lane (indicated by rem->second > 0.)
1079 if (rem->getLane() != nullptr && remPos > 0.) {
1080#ifdef _DEBUG
1081 if (myTraceMoveReminders) {
1082 traceMoveReminder("notifyEnter_skipped", rem, remPos, true);
1083 }
1084#endif
1085 ++i;
1086 } else {
1087 if (rem->notifyEnter(*this, reason, enteredLane)) {
1088#ifdef _DEBUG
1089 if (myTraceMoveReminders) {
1090 traceMoveReminder("notifyEnter", rem, remPos, true);
1091 }
1092#endif
1093 ++i;
1094 } else {
1095#ifdef _DEBUG
1096 if (myTraceMoveReminders) {
1097 traceMoveReminder("notifyEnter", rem, remPos, false);
1098 }
1099#endif
1100 myMoveReminders.erase(myMoveReminders.begin() + i);
1101 }
1102 }
1103 }
1104}
1105
1106
1107bool
1109 return isRailway(getVClass()) || isRailway(getCurrentEdge()->getPermissions());
1110}
1111
1112void
1114 if (myRoute->getLastEdge()->isTazConnector()) {
1115 return;
1116 }
1117 const int arrivalEdgeIndex = MIN2(myParameter->arrivalEdge, (int)myRoute->getEdges().size() - 1);
1118 if (arrivalEdgeIndex != myParameter->arrivalEdge) {
1119 if (!(onInit && myParameter->wasSet(VEHPARS_FORCE_REROUTE))) {
1120 WRITE_WARNINGF(TL("Vehicle '%' ignores attribute arrivalEdge=% after rerouting at time=% (routeLength=%)"),
1121 getID(), myParameter->arrivalEdge, time2string(SIMSTEP), myRoute->getEdges().size() - 1);
1122 }
1123 }
1124 const MSEdge* arrivalEdge = myParameter->arrivalEdge >= 0 ? myRoute->getEdges()[arrivalEdgeIndex] : myRoute->getLastEdge();
1125 if (!onInit) {
1126 arrivalEdge = myRoute->getLastEdge();
1127 // ignore arrivalEdge parameter after rerouting
1128 const_cast<SUMOVehicleParameter*>(myParameter)->arrivalEdge = -1;
1129 }
1130 const std::vector<MSLane*>& lanes = arrivalEdge->getLanes();
1131 const double lastLaneLength = lanes[0]->getLength();
1134 if (fabs(myParameter->arrivalPos) > lastLaneLength) {
1135 WRITE_WARNINGF(TL("Vehicle '%' will not be able to arrive at the given position!"), getID());
1136 }
1137 // Maybe we should warn the user about invalid inputs!
1138 myArrivalPos = MIN2(myParameter->arrivalPos, lastLaneLength);
1139 if (myArrivalPos < 0) {
1140 myArrivalPos = MAX2(myArrivalPos + lastLaneLength, 0.);
1141 }
1142 break;
1144 myArrivalPos = RandHelper::rand(lastLaneLength);
1145 break;
1147 myArrivalPos = lastLaneLength / 2.;
1148 break;
1149 default:
1150 myArrivalPos = lastLaneLength;
1151 break;
1152 }
1154 if (myParameter->arrivalLane >= (int)lanes.size() || !lanes[myParameter->arrivalLane]->allowsVehicleClass(myType->getVehicleClass())) {
1155 WRITE_WARNINGF(TL("Vehicle '%' will not be able to arrive at the given lane '%_%'!"), getID(), arrivalEdge->getID(), toString(myParameter->arrivalLane));
1156 }
1157 myArrivalLane = MIN2(myParameter->arrivalLane, (int)(lanes.size() - 1));
1159 myArrivalLane = -1;
1160 for (MSLane* lane : lanes) {
1161 if (lane->allowsVehicleClass(myType->getVehicleClass())) {
1162 myArrivalLane = lane->getIndex();
1163 break;
1164 }
1165 }
1166 if (myArrivalLane == -1) {
1167 WRITE_WARNINGF(TL("Vehicle '%' has no usable arrivalLane on edge '%'."), getID(), arrivalEdge->getID());
1168 myArrivalLane = 0;
1169 }
1171 // pick random lane among all usable lanes
1172 std::vector<MSLane*> usable;
1173 for (MSLane* lane : lanes) {
1174 if (lane->allowsVehicleClass(myType->getVehicleClass())) {
1175 usable.push_back(lane);
1176 }
1177 }
1178 if (usable.empty()) {
1179 WRITE_WARNINGF(TL("Vehicle '%' has no usable arrivalLane on edge '%'."), getID(), arrivalEdge->getID());
1180 myArrivalLane = 0;
1181 } else {
1182 myArrivalLane = usable[RandHelper::rand(0, (int)usable.size())]->getIndex();
1183 }
1184 }
1186 for (std::vector<MSLane*>::const_iterator l = lanes.begin(); l != lanes.end(); ++l) {
1187 if (myParameter->arrivalSpeed <= (*l)->getVehicleMaxSpeed(this)) {
1188 return;
1189 }
1190 }
1191 WRITE_WARNINGF(TL("Vehicle '%' will not be able to arrive with the given speed!"), getID());
1192 }
1193}
1194
1195void
1199 const int routeEdges = (int)myRoute->getEdges().size();
1201 // write specific edge in vehroute output for reproducibility
1202 pars->departEdge = RandHelper::rand(0, routeEdges);
1204 }
1205 assert(pars->departEdge >= 0);
1206 if (pars->departEdge >= routeEdges) {
1207 WRITE_WARNINGF(TL("Ignoring departEdge % for vehicle '%' with % route edges"), toString(pars->departEdge), getID(), toString(routeEdges));
1208 } else {
1209 myCurrEdge = myRoute->begin() + pars->departEdge;
1210 }
1211 }
1213 const int routeEdges = (int)myRoute->getEdges().size();
1214 const int begin = (int)(myCurrEdge - myRoute->begin());
1215 // write specific edge in vehroute output for reproducibility
1216 pars->arrivalEdge = RandHelper::rand(begin, routeEdges);
1218 assert(pars->arrivalEdge >= begin);
1219 assert(pars->arrivalEdge < routeEdges);
1220 }
1221}
1222
1223int
1227
1228int
1232 } else {
1234 }
1235}
1236
1237double
1239 return MAX2(0., MIN2(1., getVehicleType().getImpatience()
1240 + (hasInfluencer() ? getBaseInfluencer()->getExtraImpatience() : 0)
1242}
1243
1244
1245MSDevice*
1246MSBaseVehicle::getDevice(const std::type_info& type) const {
1247 for (MSVehicleDevice* const dev : myDevices) {
1248 if (typeid(*dev) == type) {
1249 return dev;
1250 }
1251 }
1252 return nullptr;
1253}
1254
1255
1256void
1258 // the parameters may hold the name of a vTypeDistribution but we are interested in the actual type
1259 const std::string& typeID = myParameter->vtypeid != getVehicleType().getID() ? getVehicleType().getID() : "";
1261 // params and stops must be written in child classes since they may wish to add additional attributes first
1262 out.writeAttr(SUMO_ATTR_ROUTE, myRoute->getID());
1266 }
1268 const int precision = out.getPrecision();
1269 out.setPrecision(MAX2(gPrecisionRandom, precision));
1271 out.setPrecision(precision);
1272 }
1274 out.writeAttr(SUMO_ATTR_REROUTE, true);
1275 }
1277 // could be set from stop
1279 }
1280 // here starts the vehicle internal part (see loading)
1281 // @note: remember to close the vehicle tag when calling this in a subclass!
1282}
1283
1284
1285bool
1286MSBaseVehicle::handleCollisionStop(MSStop& stop, const double distToStop) {
1287 UNUSED_PARAMETER(stop);
1288 UNUSED_PARAMETER(distToStop);
1289 return true;
1290}
1291
1292
1293bool
1295 return !myStops.empty() && myStops.begin()->reached /*&& myState.mySpeed < SUMO_const_haltingSpeed @todo #1864#*/;
1296}
1297
1298
1299bool
1301 return (isStopped() && (myStops.begin()->pars.parking == ParkingType::OFFROAD)
1302 && (myStops.begin()->parkingarea == nullptr || !myStops.begin()->parkingarea->parkOnRoad())
1303 && (myStops.begin()->getSpeed() == 0 || getSpeed() < SUMO_const_haltingSpeed));
1304}
1305
1306
1307bool
1309 return myPastStops.size() > 0 && myPastStops.back().jump >= 0 && getEdge()->getID() == myPastStops.back().edge && myPastStops.back().ended == SIMSTEP;
1310}
1311
1312
1313bool
1315 return isStopped() && (myStops.begin()->triggered || myStops.begin()->containerTriggered || myStops.begin()->joinTriggered);
1316}
1317
1318
1319bool
1321 return isStopped() && (myStops.begin()->pars.parking == ParkingType::OFFROAD);
1322}
1323
1324
1325bool
1326MSBaseVehicle::isStoppedInRange(const double pos, const double tolerance, bool checkFuture) const {
1327 if (isStopped() || (checkFuture && hasStops())) {
1328 const MSStop& stop = myStops.front();
1329 return stop.pars.startPos - tolerance <= pos && stop.pars.endPos + tolerance >= pos;
1330 }
1331 return false;
1332}
1333
1334bool
1335MSBaseVehicle::replaceParkingArea(MSParkingArea* parkingArea, std::string& errorMsg) {
1336 // Check if there is a parking area to be replaced
1337 if (parkingArea == 0) {
1338 errorMsg = "new parkingArea is NULL";
1339 return false;
1340 }
1341 if (myStops.size() == 0) {
1342 errorMsg = "vehicle has no stops";
1343 return false;
1344 }
1345 if (myStops.front().parkingarea == 0) {
1346 errorMsg = "first stop is not at parkingArea";
1347 return false;
1348 }
1349 MSStop& first = myStops.front();
1350 SUMOVehicleParameter::Stop& stopPar = const_cast<SUMOVehicleParameter::Stop&>(first.pars);
1351 std::string oldStopEdgeID = first.lane->getEdge().getID();
1352 // merge subsequent duplicate stops equals to parking area
1353 for (std::list<MSStop>::iterator iter = ++myStops.begin(); iter != myStops.end();) {
1354 if (iter->parkingarea == parkingArea) {
1355 stopPar.duration += iter->duration;
1356 myStops.erase(iter++);
1357 } else {
1358 break;
1359 }
1360 }
1361 stopPar.lane = parkingArea->getLane().getID();
1362 stopPar.parkingarea = parkingArea->getID();
1363 stopPar.startPos = parkingArea->getBeginLanePosition();
1364 stopPar.endPos = parkingArea->getEndLanePosition();
1365 stopPar.index = STOP_INDEX_FIT;
1366 first.edge = myRoute->end(); // will be patched in replaceRoute
1367 first.lane = &parkingArea->getLane();
1368 first.parkingarea = parkingArea;
1369
1370 // patch via edges
1371 std::string newStopEdgeID = parkingArea->getLane().getEdge().getID();
1372 if (myParameter->via.size() > 0 && myParameter->via.front() != newStopEdgeID) {
1373 if (myParameter->via.front() == oldStopEdgeID) {
1374 myParameter->via.erase(myParameter->via.begin());
1375 }
1376 myParameter->via.insert(myParameter->via.begin(), newStopEdgeID);
1377 }
1378 return true;
1379}
1380
1381
1384 MSParkingArea* nextParkingArea = nullptr;
1385 if (!myStops.empty()) {
1387 MSStop stop = myStops.front();
1388 if (!stop.reached && stop.parkingarea != nullptr) {
1389 nextParkingArea = stop.parkingarea;
1390 }
1391 }
1392 return nextParkingArea;
1393}
1394
1395
1398 MSParkingArea* currentParkingArea = nullptr;
1399 if (isParking()) {
1400 currentParkingArea = myStops.begin()->parkingarea;
1401 }
1402 return currentParkingArea;
1403}
1404
1405
1406const std::vector<std::string>&
1409 return myParameter->parkingBadges;
1410 } else {
1412 }
1413}
1414
1415
1416double
1417MSBaseVehicle::basePos(const MSEdge* edge) const {
1418 double result = MIN2(getVehicleType().getLength() + POSITION_EPS, edge->getMinLength());
1419 if (hasStops()
1420 && myStops.front().edge == myRoute->begin()
1421 && (&myStops.front().lane->getEdge()) == *myStops.front().edge) {
1422 result = MIN2(result, MAX2(0.0, myStops.front().getEndPos(*this)));
1423 }
1424 return result;
1425}
1426
1427
1428MSLane*
1430 const std::string edgeID = SUMOXMLDefinitions::getEdgeIDFromLane(stop.lane);
1431 const MSEdge* edge = MSEdge::dictionary(edgeID);
1432 if (edge == nullptr || edge->getOppositeEdge() == nullptr || stop.lane.find("_") == std::string::npos) {
1433 return nullptr;
1434 }
1435 const int laneIndex = SUMOXMLDefinitions::getIndexFromLane(stop.lane);
1436 if (laneIndex < (edge->getNumLanes() + edge->getOppositeEdge()->getNumLanes())) {
1437 const int oppositeIndex = edge->getOppositeEdge()->getNumLanes() + edge->getNumLanes() - 1 - laneIndex;
1438 stop.edge = edgeID;
1439 return edge->getOppositeEdge()->getLanes()[oppositeIndex];
1440 }
1441 return nullptr;
1442}
1443
1444
1445bool
1446MSBaseVehicle::addStop(const SUMOVehicleParameter::Stop& stopPar, std::string& errorMsg, SUMOTime untilOffset,
1447 MSRouteIterator* searchStart) {
1448 MSStop stop(stopPar);
1449 if (stopPar.lane == "") {
1450 MSEdge* e = MSEdge::dictionary(stopPar.edge);
1451 stop.lane = e->getFirstAllowed(getVClass(), false, getRoutingMode());
1452 if (stop.lane == nullptr) {
1453 errorMsg = "Vehicle '" + myParameter->id + "' is not allowed to stop on any lane of edge '" + stopPar.edge + "'.";
1454 return false;
1455 }
1456 } else {
1457 stop.lane = MSLane::dictionary(stopPar.lane);
1458 if (stop.lane == nullptr) {
1459 // must be an opposite stop
1460 SUMOVehicleParameter::Stop tmp = stopPar;
1461 stop.lane = interpretOppositeStop(tmp);
1462 assert(stop.lane != nullptr);
1463 }
1465 errorMsg = "Vehicle '" + myParameter->id + "' is not allowed to stop on lane '" + stopPar.lane + "'.";
1466 return false;
1467 }
1468 }
1470 stop.segment = MSGlobals::gMesoNet->getSegmentForEdge(stop.lane->getEdge(), stop.getEndPos(*this));
1471 if (stop.lane->isInternal()) {
1472 errorMsg = "Mesoscopic simulation does not allow stopping on internal edge '" + stopPar.edge + "' for vehicle '" + myParameter->id + "'.";
1473 return false;
1474 }
1475 }
1476 stop.initPars(stopPar);
1477 if (stopPar.until != -1) {
1478 // !!! it would be much cleaner to invent a constructor for stops which takes "until" as an argument
1479 const_cast<SUMOVehicleParameter::Stop&>(stop.pars).until += untilOffset;
1480 }
1481 if (stopPar.arrival != -1) {
1482 const_cast<SUMOVehicleParameter::Stop&>(stop.pars).arrival += untilOffset;
1483 }
1484 std::string stopType = "stop";
1485 std::string stopID = "";
1486 double parkingLength = stop.pars.endPos - stop.pars.startPos;
1487 if (stop.busstop != nullptr) {
1488 stopType = toString(stop.busstop->getElement());
1489 stopID = stop.busstop->getID();
1490 parkingLength = stop.busstop->getParkingLength();
1491 } else if (stop.containerstop != nullptr) {
1492 stopType = "containerStop";
1493 stopID = stop.containerstop->getID();
1494 parkingLength = stop.containerstop->getParkingLength();
1495 } else if (stop.chargingStation != nullptr) {
1496 stopType = "chargingStation";
1497 stopID = stop.chargingStation->getID();
1498 parkingLength = stop.chargingStation->getParkingLength();
1499 } else if (stop.overheadWireSegment != nullptr) {
1500 stopType = "overheadWireSegment";
1501 stopID = stop.overheadWireSegment->getID();
1502 parkingLength = stop.overheadWireSegment->getParkingLength();
1503 } else if (stop.parkingarea != nullptr) {
1504 stopType = "parkingArea";
1505 stopID = stop.parkingarea->getID();
1506 }
1507 const std::string errorMsgStart = stopID == "" ? stopType : stopType + " '" + stopID + "'";
1508
1509 if (stop.pars.startPos < 0 || stop.pars.endPos > stop.lane->getLength()) {
1510 errorMsg = errorMsgStart + " for vehicle '" + myParameter->id + "' on lane '" + stop.lane->getID() + "' has an invalid position.";
1511 return false;
1512 }
1513 if (stopType != "stop" && stopType != "parkingArea" && myType->getLength() / 2. > parkingLength
1514 // do not warn for stops that fill the whole lane
1515 && parkingLength < stop.lane->getLength()
1516 // do not warn twice for the same stop
1517 && MSNet::getInstance()->warnOnce(stopType + ":" + stopID)) {
1518 errorMsg = errorMsgStart + " on lane '" + stop.lane->getID() + "' is too short for vehicle '" + myParameter->id + "'.";
1519 }
1520 if (stopType == "parkingArea" && !stop.parkingarea->accepts(this)) {
1521 // forbid access in case the parking requests other badges
1522 errorMsg = errorMsgStart + "on lane '" + stop.lane->getID() + "' forbids access because vehicle '" + myParameter->id + "' does not provide any valid badge.";
1523 return false;
1524 }
1525 const MSEdge* stopLaneEdge = &stop.lane->getEdge();
1526 const MSEdge* stopEdge;
1527 if (stopLaneEdge->getOppositeEdge() != nullptr && stopLaneEdge->getOppositeEdge()->getID() == stopPar.edge) {
1528 // stop lane is on the opposite side
1529 stopEdge = stopLaneEdge->getOppositeEdge();
1530 stop.isOpposite = true;
1531 } else {
1532 // if stop is on an internal edge the normal edge before the intersection is used
1533 stopEdge = stopLaneEdge->getNormalBefore();
1534 }
1535 MSRouteIterator succ = myCurrEdge + 1; // we're using the address but only within the scope of this function (and recursive calls)
1536 if (searchStart == nullptr) {
1537 searchStart = &myCurrEdge;
1538 if (stopLaneEdge->isNormal() && getLane() != nullptr && getLane()->isInternal()) {
1539 // already on the intersection but myCurrEdge is before it
1540 searchStart = &succ;
1541 }
1542 }
1543#ifdef DEBUG_ADD_STOP
1544 if (DEBUG_COND) {
1545 std::cout << "addStop desc=" << stop.getDescription() << " stopEdge=" << stopEdge->getID()
1546 << " searchStart=" << ((*searchStart) == myRoute->end() ? "END" : (**searchStart)->getID())
1547 << " index=" << (int)((*searchStart) - myRoute->begin()) << " route=" << toString(myRoute->getEdges())
1548 << " stopParIndex=" << stopPar.index
1549 << "\n";
1550 }
1551#endif
1552 stop.edge = std::find(*searchStart, myRoute->end(), stopEdge);
1553 MSRouteIterator prevStopEdge = myCurrEdge;
1554 const MSEdge* prevEdge = (getLane() == nullptr ? getEdge() : &getLane()->getEdge());
1555 double prevStopPos = getPositionOnLane();
1556 // where to insert the stop
1557 std::list<MSStop>::iterator iter = myStops.begin();
1558 if (stopPar.index == STOP_INDEX_END || stopPar.index >= static_cast<int>(myStops.size()) || stopPar.index == STOP_INDEX_REPEAT) {
1559 iter = myStops.end();
1560 if (myStops.size() > 0 && myStops.back().edge >= *searchStart) {
1561 prevStopEdge = myStops.back().edge;
1562 prevEdge = &myStops.back().lane->getEdge();
1563 prevStopPos = myStops.back().pars.endPos;
1564 stop.edge = std::find(prevStopEdge, myRoute->end(), stopEdge);
1565 if (prevStopEdge == stop.edge // laneEdge check is insufficient for looped routes
1566 && prevEdge == &stop.lane->getEdge() // route iterator check insufficient for internal lane stops
1567 && (prevStopPos > stop.pars.endPos ||
1568 (prevStopPos == stop.pars.endPos && stopPar.index == STOP_INDEX_REPEAT))) {
1569 stop.edge = std::find(prevStopEdge + 1, myRoute->end(), stopEdge);
1570 }
1571#ifdef DEBUG_ADD_STOP
1572 if (DEBUG_COND) {
1573 std::cout << " (@end) prevStopEdge=" << (*prevStopEdge)->getID() << " prevStopPos=" << prevStopPos << " index=" << (int)(prevStopEdge - myRoute->begin())
1574 << " foundIndex=" << (stop.edge == myRoute->end() ? -1 : (int)(stop.edge - myRoute->begin())) << "\n";
1575 }
1576#endif
1577 }
1578 // skip a number of occurences of stopEdge in looped route
1579 int skipLooped = stopPar.index - static_cast<int>(myStops.size());
1580 for (int j = 0; j < skipLooped; j++) {
1581 auto nextIt = std::find(stop.edge + 1, myRoute->end(), stopEdge);
1582 if (nextIt == myRoute->end()) {
1583 if (std::find(myRoute->begin(), stop.edge, stopEdge) != stop.edge) {
1584 // only warn if the route loops over the stop edge at least once
1585 errorMsg = errorMsgStart + " for vehicle '" + myParameter->id + "' could not skip " + toString(skipLooped) + " occurences of stop edge '" + stopEdge->getID() + "' in looped route.";
1586 }
1587 break;
1588 } else {
1589 stop.edge = nextIt;
1590 }
1591 }
1592 } else {
1593 if (stopPar.index == STOP_INDEX_FIT) {
1594 while (iter != myStops.end() && (iter->edge < stop.edge ||
1595 (iter->pars.endPos < stop.pars.endPos && iter->edge == stop.edge) ||
1596 (stop.lane->getEdge().isInternal() && iter->edge == stop.edge))) {
1597 prevStopEdge = iter->edge;
1598 prevStopPos = iter->pars.endPos;
1599 ++iter;
1600 }
1601 } else {
1602 int index = stopPar.index;
1603 while (index > 0) {
1604 prevStopEdge = iter->edge;
1605 prevStopPos = iter->pars.endPos;
1606 ++iter;
1607 --index;
1608 }
1609#ifdef DEBUG_ADD_STOP
1610 if (DEBUG_COND) {
1611 std::cout << " (@fit) prevStopEdge=" << (*prevStopEdge)->getID() << " index=" << (int)(prevStopEdge - myRoute->begin()) << "\n";
1612 }
1613#endif
1614 stop.edge = std::find(prevStopEdge, myRoute->end(), stopEdge);
1615 }
1616 }
1617 const bool wasTooClose = errorMsg != "" && errorMsg.find("too close") != std::string::npos;
1618 if (stop.edge == myRoute->end()) {
1619 if (!wasTooClose) {
1620 errorMsg = errorMsgStart + " for vehicle '" + myParameter->id + "' on lane '" + stop.lane->getID() + "' is not downstream the current route.";
1621 }
1622 return false;
1623 }
1624
1625 const bool tooClose = (prevStopEdge == stop.edge && prevEdge == &stop.lane->getEdge() &&
1626 prevStopPos + (iter == myStops.begin() && !instantStopping() ? getBrakeGap() : 0) > stop.pars.endPos + POSITION_EPS);
1627
1628 if (prevStopEdge > stop.edge ||
1629 // a collision-stop happens after vehicle movement and may move the
1630 // vehicle backwards on its lane (prevStopPos is the vehicle position)
1631 (tooClose && !stop.pars.collision)
1632 || (stop.lane->getEdge().isInternal() && stop.lane->getNextNormal() != *(stop.edge + 1))) {
1633 // check if the edge occurs again later in the route
1634 //std::cout << " could not add stop " << errorMsgStart << " prevStops=" << myStops.size() << " searchStart=" << (*searchStart - myRoute->begin()) << " route=" << toString(myRoute->getEdges()) << "\n";
1635 if (tooClose && prevStopPos <= stop.pars.endPos + POSITION_EPS) {
1636 errorMsg = errorMsgStart + " for vehicle '" + myParameter->id + "' on lane '" + stop.pars.lane + "' is too close to brake.";
1637 }
1638 MSRouteIterator next = stop.edge + 1;
1639 return addStop(stopPar, errorMsg, untilOffset, &next);
1640 }
1641 // David.C:
1642 //if (!stop.parking && (myCurrEdge == stop.edge && myState.myPos > stop.endPos - getCarFollowModel().brakeGap(myState.mySpeed))) {
1643 const double endPosOffset = stop.lane->getEdge().isInternal() ? (*stop.edge)->getLength() : 0;
1644 const double distToStop = stop.pars.endPos + endPosOffset - getPositionOnLane();
1645 if (stop.pars.collision && !handleCollisionStop(stop, distToStop)) {
1646 return false;
1647 }
1648 if (!hasDeparted() && myCurrEdge == stop.edge) {
1649 double pos = -1;
1651 pos = myParameter->departPos;
1652 if (pos < 0.) {
1653 pos += (*myCurrEdge)->getLength();
1654 }
1655 }
1657 pos = MIN2(stop.pars.endPos + endPosOffset, basePos(*myCurrEdge));
1658 }
1659 if (pos > stop.pars.endPos + endPosOffset) {
1660 if (stop.edge != myRoute->end()) {
1661 // check if the edge occurs again later in the route
1662 MSRouteIterator next = stop.edge + 1;
1663 return addStop(stopPar, errorMsg, untilOffset, &next);
1664 }
1665 errorMsg = errorMsgStart + " for vehicle '" + myParameter->id + "' on lane '" + stop.lane->getID() + "' is before departPos.";
1666 return false;
1667 }
1668 }
1669 if (iter != myStops.begin()) {
1670 std::list<MSStop>::iterator iter2 = iter;
1671 iter2--;
1672 if (stop.getUntil() >= 0 && iter2->getUntil() > stop.getUntil()
1673 && (!MSGlobals::gUseStopEnded || iter2->pars.ended < 0 || stop.pars.ended >= 0)) {
1674 errorMsg = errorMsgStart + " for vehicle '" + myParameter->id + "' on lane '" + stop.lane->getID()
1675 + "' set to end at " + time2string(stop.getUntil())
1676 + " earlier than previous stop at " + time2string(iter2->getUntil()) + ".";
1677 }
1678 if (stop.pars.arrival >= 0 && iter2->pars.arrival > stop.pars.arrival) {
1679 errorMsg = errorMsgStart + " for vehicle '" + myParameter->id + "' on lane '" + stop.lane->getID()
1680 + "' set to start at " + time2string(stop.pars.arrival)
1681 + " earlier than previous stop end at " + time2string(iter2->getUntil()) + ".";
1682 }
1683 if (stop.pars.arrival >= 0 && iter2->pars.arrival > stop.pars.arrival) {
1684 errorMsg = errorMsgStart + " for vehicle '" + myParameter->id + "' on lane '" + stop.lane->getID()
1685 + "' set to start at " + time2string(stop.pars.arrival)
1686 + " earlier than previous stop arrival at " + time2string(iter2->pars.arrival) + ".";
1687 }
1688 } else {
1689 if (stop.getUntil() >= 0 && getParameter().depart > stop.getUntil()
1690 && (!MSGlobals::gUseStopEnded || stop.pars.ended < 0)) {
1691 errorMsg = errorMsgStart + " for vehicle '" + myParameter->id + "' on lane '" + stop.lane->getID()
1692 + "' set to end at " + time2string(stop.getUntil())
1693 + " earlier than departure at " + time2string(getParameter().depart) + ".";
1694 }
1695 }
1696 if (stop.getUntil() >= 0 && stop.getArrival() > stop.getUntil() && errorMsg == "") {
1697 errorMsg = errorMsgStart + " for vehicle '" + myParameter->id + "' on lane '" + stop.lane->getID()
1698 + "' set to end at " + time2string(stop.getUntil())
1699 + " earlier than arrival at " + time2string(stop.getArrival()) + ".";
1700 }
1701 setSkips(stop, (int)myStops.size());
1702 myStops.insert(iter, stop);
1703 if (stopPar.tripId != "") {
1705 }
1706#ifdef DEBUG_ADD_STOP
1707 if (DEBUG_COND) {
1708 std::cout << " added stop " << errorMsgStart << " totalStops=" << myStops.size()
1709 << " routeIndex=" << (stop.edge - myRoute->begin())
1710 << " stopIndex=" << std::distance(myStops.begin(), iter)
1711 //<< " searchStart=" << (*searchStart - myRoute->begin())
1712 //<< " route=" << toString(myRoute->getEdges())
1713 << "\n";
1714 }
1715#endif
1716 return true;
1717}
1718
1719
1720void
1721MSBaseVehicle::setSkips(MSStop& stop, int prevActiveStops) {
1722 if (hasDeparted() && stop.edge > myRoute->begin()) {
1723 // if the route is looped we must patch the index to ensure that state
1724 // loading (and vehroute-output) encode the correct number of skips
1725 stop.skips.clear();
1726 MSRouteIterator itPrev;
1727 double prevEndPos;
1728 if (prevActiveStops > 0) {
1729 assert((int)myStops.size() >= prevActiveStops);
1730 auto prevStopIt = myStops.begin();
1731 std::advance(prevStopIt, prevActiveStops - 1);
1732 const MSStop& prev = *prevStopIt;
1733 itPrev = prev.edge;
1734 prevEndPos = prev.pars.endPos;
1735 } else if (myPastStops.size() > 0) {
1736 itPrev = myRoute->begin() + myPastStops.back().routeIndex;
1737 prevEndPos = myPastStops.back().endPos;
1738 } else {
1739 itPrev = myRoute->begin() + myParameter->departEdge;
1740 prevEndPos = myDepartPos;
1741 }
1742 //auto itPrevOrig = itPrev;
1743 if (*itPrev == *stop.edge && prevEndPos > stop.pars.endPos) {
1744 itPrev++;
1745 }
1746 //std::cout << SIMTIME << " veh=" << getID() << " prevActive=" << prevActiveStops << " edge=" << (*stop.edge)->getID() << " routeIndex=" << (stop.edge - myRoute->begin()) << " prevIndex=" << (itPrev - myRoute->begin()) << "\n";
1747 while (itPrev < stop.edge) {
1748 if (*itPrev == *stop.edge) {
1749 stop.skips.push_back((int)(itPrev - myRoute->begin()));
1750 }
1751 itPrev++;
1752 }
1753 int newIndex = STOP_INDEX_END;
1754 if (!stop.skips.empty()) {
1755 //if (getID() == "77_0_0") {
1756 // std::cout << SIMTIME << " veh=" << getID() << " past=" << myPastStops.size() << " prevActive=" << prevActiveStops
1757 // << " edge=" << (*stop.edge)->getID() << " routeIndex=" << (stop.edge - myRoute->begin())
1758 // << " prevEdge=" << (*itPrevOrig)->getID()
1759 // << " prevIndex=" << (itPrevOrig - myRoute->begin())
1760 // << " skips=" << foundSkips << "\n";
1761 //}
1762 newIndex = (int)myPastStops.size() + prevActiveStops + (int)stop.skips.size();
1763 }
1764 const_cast<SUMOVehicleParameter::Stop&>(stop.pars).index = newIndex;
1765 }
1766}
1767
1768
1771 for (int i = 0; i < (int)myMoveReminders.size();) {
1772 auto rem = &myMoveReminders[i];
1773 if (rem->first->notifyReroute(*this)) {
1774#ifdef _DEBUG
1775 if (myTraceMoveReminders) {
1776 traceMoveReminder("notifyReroute", rem->first, rem->second, true);
1777 }
1778#endif
1779 ++i;
1780 } else {
1781#ifdef _DEBUG
1782 if (myTraceMoveReminders) {
1783 traceMoveReminder("notifyReroute", rem->first, rem->second, false);
1784 }
1785#endif
1786 myMoveReminders.erase(myMoveReminders.begin() + i);
1787 }
1788 }
1790 // event only called once
1791 return 0;
1792}
1793
1794
1795void
1796MSBaseVehicle::addStops(const bool ignoreStopErrors, MSRouteIterator* searchStart, bool addRouteStops) {
1797 if (addRouteStops) {
1798 for (const SUMOVehicleParameter::Stop& stop : myRoute->getStops()) {
1799 std::string errorMsg;
1800 if (!addStop(stop, errorMsg, myParameter->depart, searchStart) && !ignoreStopErrors) {
1801 throw ProcessError(errorMsg);
1802 }
1803 if (errorMsg != "") {
1804 WRITE_WARNING(errorMsg);
1805 }
1806 }
1807 }
1809 for (const SUMOVehicleParameter::Stop& stop : myParameter->stops) {
1810 std::string errorMsg;
1811 if (!addStop(stop, errorMsg, untilOffset, searchStart) && !ignoreStopErrors) {
1812 throw ProcessError(errorMsg);
1813 }
1814 if (errorMsg != "") {
1815 WRITE_WARNING(errorMsg);
1816 }
1817 }
1818}
1819
1820
1821bool
1824 int i = 0;
1825 bool ok = true;
1826 for (const MSStop& stop : myStops) {
1827 MSRouteIterator it;
1828 if (stop.lane->isInternal()) {
1829 // find the normal predecessor and ensure that the next route edge
1830 // matches the successor of the internal edge successor
1831 it = std::find(start, myRoute->end(), stop.lane->getEdge().getNormalBefore());
1832 if (it != myRoute->end() && (
1833 it + 1 == myRoute->end() || *(it + 1) != stop.lane->getEdge().getNormalSuccessor())) {
1834 it = myRoute->end(); // signal failure
1835 }
1836 } else {
1837 it = std::find(start, myRoute->end(), &stop.lane->getEdge());
1838 }
1839 if (it == myRoute->end()) {
1840 if (!silent) {
1841 WRITE_ERRORF("Stop % on edge '%' is not found after edge '%' (% after current) for vehicle '%' at time=%.",
1842 i, stop.lane->getEdge().getID(), (*start)->getID(), toString(start - myCurrEdge), getID(), time2string(SIMSTEP));
1843 }
1844 ok = false;
1845 } else {
1846 MSRouteIterator it2;
1847 for (it2 = myRoute->begin(); it2 != myRoute->end(); it2++) {
1848 if (it2 == stop.edge) {
1849 break;
1850 }
1851 }
1852 if (it2 == myRoute->end()) {
1853 if (!silent) {
1854 WRITE_ERRORF("Stop % on edge '%' used invalid route index for vehicle '%' at time=%.",
1855 i, stop.lane->getEdge().getID(), getID(), time2string(SIMSTEP));
1856 }
1857 ok = false;
1858 } else if (it2 < start) {
1859 if (!silent) {
1860 WRITE_ERRORF("Stop % on edge '%' used invalid (relative) route index % expected after % for vehicle '%' at time=%.",
1861 i, stop.lane->getEdge().getID(), toString(it2 - myCurrEdge), toString(start - myCurrEdge), getID(), time2string(SIMSTEP));
1862 }
1863 ok = false;
1864 } else {
1865 start = stop.edge;
1866 }
1867 }
1868 i++;
1869 }
1870 return ok;
1871}
1872
1873
1874std::vector<MSBaseVehicle::StopEdgeInfo>
1875MSBaseVehicle::getStopEdges(double& firstPos, double& lastPos, std::set<int>& jumps) const {
1876 assert(haveValidStopEdges());
1877 std::vector<StopEdgeInfo> result;
1878 const MSStop* prev = nullptr;
1879 const MSEdge* internalSuccessor = nullptr;
1880 for (const MSStop& stop : myStops) {
1881 if (stop.reached) {
1882 if (stop.pars.jump >= 0) {
1883 jumps.insert((int)result.size());
1884 }
1885 continue;
1886 }
1887 double stopPos = stop.getEndPos(*this);
1888 if ((prev == nullptr
1889 || prev->edge != stop.edge
1890 || (prev->lane == stop.lane && prev->getEndPos(*this) > stopPos))
1891 && *stop.edge != internalSuccessor) {
1892 if (stop.lane->isInternal()) {
1893 stopPos = (*stop.edge)->getLength();
1894 }
1895 result.push_back(StopEdgeInfo(*stop.edge, stop.pars.priority, stop.getArrivalFallback(), stopPos));
1896 result.back().nameTag = stop.getStoppingPlaceName();
1897 result.back().stopPar = &stop.pars;
1898 if (stop.lane->isInternal()) {
1899 internalSuccessor = stop.lane->getNextNormal();
1900 result.push_back(StopEdgeInfo(internalSuccessor, stop.pars.priority, stop.getArrivalFallback(), 0));
1901 } else {
1902 internalSuccessor = nullptr;
1903 }
1904 } else if (prev != nullptr && prev->edge == stop.edge) {
1905 result.back().priority = addStopPriority(result.back().priority, stop.pars.priority);
1906 }
1907 prev = &stop;
1908 if (firstPos == INVALID_DOUBLE) {
1909 if (stop.parkingarea != nullptr) {
1910 firstPos = MAX2(0., stopPos);
1911 } else {
1912 firstPos = stopPos;
1913 }
1914 }
1915 lastPos = stopPos;
1916 if (stop.pars.jump >= 0) {
1917 jumps.insert((int)result.size() - 1);
1918 }
1919 }
1920 //std::cout << SIMTIME << " getStopEdges veh=" << getID() << "\n";
1921 //for (auto item : result) {
1922 // std::cout << " e=" << item.edge->getID() << " pos=" << item.pos << "\n";
1923 //}
1924 return result;
1925}
1926
1927
1928double
1929MSBaseVehicle::addStopPriority(double p1, double p2) {
1930 if (p1 < 0 || p2 < 0) {
1931 return p1;
1932 }
1933 return p1 + p2;
1934}
1935
1936std::vector<std::pair<int, double> >
1938 std::vector<std::pair<int, double> > result;
1939 for (std::list<MSStop>::const_iterator iter = myStops.begin(); iter != myStops.end(); ++iter) {
1940 result.push_back(std::make_pair(
1941 (int)(iter->edge - myRoute->begin()),
1942 iter->getEndPos(*this)));
1943 }
1944 return result;
1945}
1946
1947
1948const MSStop&
1950 assert(myStops.size() > 0);
1951 return myStops.front();
1952}
1953
1954MSStop&
1956 assert(myStops.size() > 0);
1957 return myStops.front();
1958}
1959
1962 if (isStopped()) {
1963 return myStops.front().duration;
1964 } else {
1965 return 0;
1966 }
1967}
1968
1969
1970MSStop&
1971MSBaseVehicle::getStop(int nextStopIndex) {
1972 if (nextStopIndex < 0 || (int)myStops.size() <= nextStopIndex) {
1973 throw InvalidArgument(TLF("Invalid stop index % (has % stops).", nextStopIndex, myStops.size()));
1974 }
1975 auto stopIt = myStops.begin();
1976 std::advance(stopIt, nextStopIndex);
1977 return *stopIt;
1978}
1979
1980
1983 if (hasStops()) {
1984 return &myStops.front().pars;
1985 }
1986 return nullptr;
1987}
1988
1989
1990bool
1992 //if the stop exists update the duration
1993 for (std::list<MSStop>::iterator iter = myStops.begin(); iter != myStops.end(); iter++) {
1994 if (iter->lane->getID() == stop.lane && fabs(iter->pars.endPos - stop.endPos) < POSITION_EPS) {
1995 // update existing stop
1996 if (stop.duration == 0 && stop.until < 0 && !iter->reached) {
1997 myStops.erase(iter);
1998 } else {
1999 iter->duration = stop.duration;
2000 iter->triggered = stop.triggered;
2001 iter->containerTriggered = stop.containerTriggered;
2002 const_cast<SUMOVehicleParameter::Stop&>(iter->pars).until = stop.until;
2003 const_cast<SUMOVehicleParameter::Stop&>(iter->pars).parking = stop.parking;
2004 }
2005 return true;
2006 }
2007 }
2008 const bool result = addStop(stop, errorMsg);
2009 if (result) {
2011 myParameter->stops.push_back(stop);
2012 }
2013 return result;
2014}
2015
2016
2017void
2024
2025
2026bool
2028 if (hasStops() && nextStopIndex < (int)myStops.size()) {
2029 if (nextStopIndex == 0 && isStopped()) {
2031 } else {
2032 auto stopIt = myStops.begin();
2033 std::advance(stopIt, nextStopIndex);
2034 if (stopIt->parkingarea != nullptr && stopIt->parkingarea->isReservable()) {
2035 stopIt->parkingarea->removeSpaceReservation(this);
2036 }
2037 myStops.erase(stopIt);
2038 }
2039 if (!hasDeparted() && (int)myParameter->stops.size() > nextStopIndex) {
2040 // stops will be rebuilt from scratch on rerouting so we must patch the stops in myParameter
2041 auto stopIt2 = myParameter->stops.begin();
2042 std::advance(stopIt2, nextStopIndex);
2043 const_cast<SUMOVehicleParameter*>(myParameter)->stops.erase(stopIt2);
2044 }
2045 return true;
2046 } else {
2047 return false;
2048 }
2049}
2050
2051
2052bool
2053MSBaseVehicle::replaceStop(int nextStopIndex, SUMOVehicleParameter::Stop stop, const std::string& info, bool teleport, std::string& errorMsg) {
2054 const int n = (int)myStops.size();
2055 if (nextStopIndex < 0 || nextStopIndex >= n) {
2056 errorMsg = TLF("invalid nextStopIndex % for % remaining stops", nextStopIndex, n);
2057 return false;
2058 }
2059 if (nextStopIndex == 0 && isStopped()) {
2060 errorMsg = TL("cannot replace reached stop");
2061 return false;
2062 }
2064 MSLane* stopLane = MSLane::dictionary(stop.lane);
2065 MSEdge* stopEdge = &stopLane->getEdge();
2066
2067 auto itStop = myStops.begin();
2068 std::advance(itStop, nextStopIndex);
2069 MSStop& replacedStop = *itStop;
2070
2071 // check parking access rights
2072 if (stop.parkingarea != "") {
2074 if (pa != nullptr && !pa->accepts(this)) {
2075 errorMsg = TLF("vehicle '%' does not have the right badge to access parkingArea '%'", getID(), stop.parkingarea);
2076 return false;
2077 }
2078 }
2079
2080 if (replacedStop.lane == stopLane && replacedStop.pars.endPos == stop.endPos && !teleport) {
2081 // only replace stop attributes
2082 const_cast<SUMOVehicleParameter::Stop&>(replacedStop.pars) = stop;
2083 replacedStop.initPars(stop);
2084 return true;
2085 }
2086
2087 if (!stopLane->allowsVehicleClass(getVClass(), myRoutingMode)) {
2088 errorMsg = TLF("disallowed stop lane '%'", stopLane->getID());
2089 return false;
2090 }
2091
2092 const ConstMSEdgeVector& oldEdges = getRoute().getEdges();
2093 std::vector<MSStop> stops(myStops.begin(), myStops.end());
2094 const int junctionOffset = getLane() != nullptr && getLane()->isInternal() ? 1 : 0;
2095 MSRouteIterator itStart = nextStopIndex == 0 ? getCurrentRouteEdge() + junctionOffset : stops[nextStopIndex - 1].edge;
2096 double startPos = nextStopIndex == 0 ? getPositionOnLane() : stops[nextStopIndex - 1].pars.endPos;
2097 MSRouteIterator itEnd = nextStopIndex == n - 1 ? oldEdges.end() - 1 : stops[nextStopIndex + 1].edge;
2098 auto endPos = nextStopIndex == n - 1 ? getArrivalPos() : stops[nextStopIndex + 1].pars.endPos;
2100
2101 bool newDestination = nextStopIndex == n - 1 && stops[nextStopIndex].edge == oldEdges.end() - 1;
2102
2103 ConstMSEdgeVector toNewStop;
2104 if (!teleport) {
2105 router.compute(*itStart, startPos, stopEdge, stop.endPos, this, t, toNewStop, true);
2106 if (toNewStop.size() == 0) {
2107 errorMsg = TLF("no route found from edge '%' to stop edge '%'", (*itStart)->getID(), stopEdge->getID());
2108 return false;
2109 }
2110 }
2111
2112 ConstMSEdgeVector fromNewStop;
2113 if (!newDestination) {
2114 router.compute(stopEdge, stop.endPos, *itEnd, endPos, this, t, fromNewStop, true);
2115 if (fromNewStop.size() == 0) {
2116 errorMsg = TLF("no route found from stop edge '%' to edge '%'", stopEdge->getID(), (*itEnd)->getID());
2117 return false;
2118 }
2119 }
2120
2122 const_cast<SUMOVehicleParameter::Stop&>(replacedStop.pars) = stop;
2123 replacedStop.initPars(stop);
2124 replacedStop.edge = myRoute->end(); // will be patched in replaceRoute
2125 replacedStop.lane = stopLane;
2127 replacedStop.segment = MSGlobals::gMesoNet->getSegmentForEdge(replacedStop.lane->getEdge(), replacedStop.getEndPos(*this));
2128 if (replacedStop.lane->isInternal()) {
2129 errorMsg = TLF("Mesoscopic simulation does not allow stopping on internal edge '%' for vehicle '%'.", stop.edge, getID());
2130 return false;
2131 }
2132 }
2133
2134 ConstMSEdgeVector oldRemainingEdges(myCurrEdge, getRoute().end());
2135 ConstMSEdgeVector newEdges; // only remaining
2136 newEdges.insert(newEdges.end(), myCurrEdge, itStart);
2137 if (!teleport) {
2138 newEdges.insert(newEdges.end(), toNewStop.begin(), toNewStop.end() - 1);
2139 } else {
2140 newEdges.push_back(*itStart);
2141 }
2142 if (!newDestination) {
2143 newEdges.insert(newEdges.end(), fromNewStop.begin(), fromNewStop.end() - 1);
2144 newEdges.insert(newEdges.end(), itEnd, oldEdges.end());
2145 } else {
2146 newEdges.push_back(stopEdge);
2147 }
2148 //std::cout << SIMTIME << " replaceStop veh=" << getID()
2149 // << " teleport=" << teleport
2150 // << " busStop=" << stop.busstop
2151 // << " oldEdges=" << oldRemainingEdges.size()
2152 // << " newEdges=" << newEdges.size()
2153 // << " toNewStop=" << toNewStop.size()
2154 // << " fromNewStop=" << fromNewStop.size()
2155 // << "\n";
2156
2157 const double routeCost = router.recomputeCosts(newEdges, this, t);
2158 const double previousCost = router.recomputeCosts(oldRemainingEdges, this, t);
2159 const double savings = previousCost - routeCost;
2160 if (!hasDeparted() && (int)myParameter->stops.size() > nextStopIndex) {
2161 // stops will be rebuilt from scratch so we must patch the stops in myParameter
2162 const_cast<SUMOVehicleParameter*>(myParameter)->stops[nextStopIndex] = stop;
2163 }
2164 if (teleport) {
2165 // let the vehicle jump rather than teleport
2166 // we add a jump-stop at the end of the edge (unless the vehicle is
2167 // already configure to jump before the replaced stop)
2168 if (!insertJump(nextStopIndex, itStart, errorMsg)) {
2169 return false;
2170 };
2171 }
2172 return replaceRouteEdges(newEdges, routeCost, savings, info, !hasDeparted(), false, false, &errorMsg);
2173}
2174
2175
2176bool
2177MSBaseVehicle::rerouteBetweenStops(int nextStopIndex, const std::string& info, bool teleport, std::string& errorMsg) {
2178 const int n = (int)myStops.size();
2179 if (nextStopIndex < 0 || nextStopIndex > n) {
2180 errorMsg = TLF("invalid nextStopIndex % for % remaining stops", nextStopIndex, n);
2181 return false;
2182 }
2183 if (nextStopIndex == 0 && isStopped()) {
2184 errorMsg = TL("cannot reroute towards reached stop");
2185 return false;
2186 }
2188
2189 const ConstMSEdgeVector& oldEdges = getRoute().getEdges();
2190 std::vector<MSStop> stops(myStops.begin(), myStops.end());
2191 const int junctionOffset = getLane() != nullptr && getLane()->isInternal() ? 1 : 0;
2192 MSRouteIterator itStart = nextStopIndex == 0 ? getCurrentRouteEdge() + junctionOffset : stops[nextStopIndex - 1].edge;
2193 double startPos = nextStopIndex == 0 ? getPositionOnLane() : stops[nextStopIndex - 1].pars.endPos;
2194 MSRouteIterator itEnd = nextStopIndex == n ? oldEdges.end() - 1 : stops[nextStopIndex].edge;
2195 auto endPos = nextStopIndex == n ? getArrivalPos() : stops[nextStopIndex].pars.endPos;
2197
2198 ConstMSEdgeVector newBetween;
2199 if (!teleport) {
2200 router.compute(*itStart, startPos, *itEnd, endPos, this, t, newBetween, true);
2201 if (newBetween.size() == 0) {
2202 errorMsg = TLF("no route found from edge '%' to stop edge '%'", (*itStart)->getID(), (*itEnd)->getID());
2203 return false;
2204 }
2205 }
2206
2207 ConstMSEdgeVector oldRemainingEdges(myCurrEdge, getRoute().end());
2208 ConstMSEdgeVector newEdges; // only remaining
2209 newEdges.insert(newEdges.end(), myCurrEdge, itStart);
2210 if (!teleport) {
2211 newEdges.insert(newEdges.end(), newBetween.begin(), newBetween.end() - 1);
2212 } else {
2213 newEdges.push_back(*itStart);
2214 }
2215 newEdges.insert(newEdges.end(), itEnd, oldEdges.end());
2216 //std::cout << SIMTIME << " rerouteBetweenStops veh=" << getID()
2217 // << " oldEdges=" << oldRemainingEdges.size()
2218 // << " newEdges=" << newEdges.size()
2219 // << " toNewStop=" << toNewStop.size()
2220 // << " fromNewStop=" << fromNewStop.size()
2221 // << "\n";
2222
2223 const double routeCost = router.recomputeCosts(newEdges, this, t);
2224 const double previousCost = router.recomputeCosts(oldRemainingEdges, this, t);
2225 const double savings = previousCost - routeCost;
2226
2227 if (teleport) {
2228 // let the vehicle jump rather than teleport
2229 // we add a jump-stop at the end of the edge (unless the vehicle is
2230 // already configure to jump before the replaced stop)
2231 if (!insertJump(nextStopIndex, itStart, errorMsg)) {
2232 return false;
2233 };
2234 }
2235 return replaceRouteEdges(newEdges, routeCost, savings, info, !hasDeparted(), false, false, &errorMsg);
2236}
2237
2238
2239bool
2240MSBaseVehicle::insertJump(int nextStopIndex, MSRouteIterator itStart, std::string& errorMsg) {
2241 bool needJump = true;
2242 if (nextStopIndex > 0) {
2243 auto itPriorStop = myStops.begin();
2244 std::advance(itPriorStop, nextStopIndex - 1);
2245 const MSStop& priorStop = *itPriorStop;
2246 if (priorStop.pars.jump >= 0) {
2247 needJump = false;
2248 }
2249 }
2250 if (needJump) {
2251 SUMOVehicleParameter::Stop jumpStopPars;
2252 jumpStopPars.endPos = (*itStart)->getLength();
2253 jumpStopPars.speed = 1000;
2254 jumpStopPars.jump = 0;
2255 jumpStopPars.edge = (*itStart)->getID();
2257 MSLane* jumpStopLane = nullptr;
2258 for (MSLane* cand : (*itStart)->getLanes()) {
2259 if (cand->allowsVehicleClass(getVClass())) {
2260 jumpStopLane = cand;
2261 break;
2262 }
2263 }
2264 if (jumpStopLane == nullptr) {
2265 errorMsg = TL("unable to replace stop with teleporting");
2266 return false;
2267 }
2268 auto itStop = myStops.begin();
2269 std::advance(itStop, nextStopIndex);
2270 MSStop jumpStop(jumpStopPars);
2271 jumpStop.initPars(jumpStopPars);
2272 jumpStop.lane = jumpStopLane;
2273 jumpStop.edge = myRoute->end(); // will be patched in replaceRoute
2274 myStops.insert(itStop, jumpStop);
2275 if (!hasDeparted() && (int)myParameter->stops.size() > nextStopIndex) {
2276 // stops will be rebuilt from scratch so we must patch the stops in myParameter
2277 auto it = myParameter->stops.begin() + nextStopIndex;
2278 const_cast<SUMOVehicleParameter*>(myParameter)->stops.insert(it, jumpStopPars);
2279 }
2280 }
2281 return true;
2282}
2283
2284
2285bool
2286MSBaseVehicle::insertStop(int nextStopIndex, SUMOVehicleParameter::Stop stop, const std::string& info, bool teleport, std::string& errorMsg) {
2287 const int n = (int)myStops.size();
2288 if (nextStopIndex < 0 || nextStopIndex > n) {
2289 errorMsg = TLF("invalid nextStopIndex % for % remaining stops", nextStopIndex, n);
2290 return false;
2291 }
2292 if (nextStopIndex == 0 && isStopped()) {
2293 errorMsg = TL("cannot insert stop before the currently reached stop");
2294 return false;
2295 }
2297 MSLane* stopLane = MSLane::dictionary(stop.lane);
2298 MSEdge* stopEdge = &stopLane->getEdge();
2299
2300 if (!stopLane->allowsVehicleClass(getVClass(), myRoutingMode)) {
2301 errorMsg = TLF("disallowed stop lane '%'", stopLane->getID());
2302 return false;
2303 }
2304
2305 // check parking access rights
2306 if (stop.parkingarea != "") {
2308 if (pa != nullptr && !pa->accepts(this)) {
2309 errorMsg = TLF("Vehicle '%' does not have the right badge to access parkingArea '%'.", getID(), stop.parkingarea);
2310 return false;
2311 }
2312 }
2313
2314 const ConstMSEdgeVector& oldEdges = getRoute().getEdges();
2315 std::vector<MSStop> stops(myStops.begin(), myStops.end());
2316 const int junctionOffset = ((getLane() != nullptr && getLane()->isInternal())
2317 || getRerouteOrigin() != getCurrentRouteEdge()) ? 1 : 0;
2318 MSRouteIterator itStart = nextStopIndex == 0 ? getCurrentRouteEdge() + junctionOffset : stops[nextStopIndex - 1].edge;
2319 double startPos = nextStopIndex == 0 ? getPositionOnLane() : stops[nextStopIndex - 1].pars.endPos;
2320 MSRouteIterator itEnd = nextStopIndex == n ? oldEdges.end() - 1 : stops[nextStopIndex].edge;
2321 auto endPos = nextStopIndex == n ? getArrivalPos() : stops[nextStopIndex].pars.endPos;
2323
2324 const bool newDestination = nextStopIndex == n && stopEdge == oldEdges.back();
2325 const bool needLoop = nextStopIndex > 0 && *itStart == stopEdge && startPos >= stop.endPos;
2326 if (needLoop && startPos == stop.endPos) {
2327 // assume that two stops at the same position indicate a looped route
2328 startPos += POSITION_EPS;
2329 stop.index = STOP_INDEX_REPEAT;
2330 } else if (!hasDeparted()) {
2331 stop.index = STOP_INDEX_END;
2332 }
2333
2334 MSRouteIterator itSentintel = itEnd + 1;
2335 MSRouteIterator onRouteStart = itStart + (needLoop ? 1 : 0);
2336 const bool onRoute = std::find(onRouteStart, itSentintel, stopEdge) != itSentintel;
2337 if (onRoute) {
2338 if (!hasDeparted() && (int)myParameter->stops.size() >= nextStopIndex) {
2339 // stops will be rebuilt from scratch so we must patch the stops in myParameter
2340 auto it = myParameter->stops.begin() + nextStopIndex;
2341 const_cast<SUMOVehicleParameter*>(myParameter)->stops.insert(it, stop);
2342 }
2343 const bool ok = addStop(stop, errorMsg, 0, &onRouteStart);
2344 if (ok) {
2345 updateBestLanes(true, !hasDeparted() ? (*myCurrEdge)->getLanes().front() : 0);
2346 }
2347 return ok;
2348 }
2349
2350 ConstMSEdgeVector toNewStop;
2351 if (!teleport) {
2352 router.compute(*itStart, startPos, stopEdge, stop.endPos, this, t, toNewStop, true);
2353 if (toNewStop.size() == 0) {
2354 errorMsg = TLF("no route found from edge '%' to stop edge '%'", (*itStart)->getID(), stopEdge->getID());
2355 return false;
2356 }
2357 }
2358
2359 ConstMSEdgeVector fromNewStop;
2360 if (!newDestination) {
2361 router.compute(stopEdge, stop.endPos, *itEnd, endPos, this, t, fromNewStop, true);
2362 if (fromNewStop.size() == 0) {
2363 errorMsg = TLF("no route found from stop edge '%' to edge '%'", stopEdge->getID(), (*itEnd)->getID());
2364 return false;
2365 }
2366 }
2367
2368 auto itStop = myStops.begin();
2369 std::advance(itStop, nextStopIndex);
2370 MSStop newStop(stop);
2371 newStop.initPars(stop);
2372 newStop.edge = myRoute->end(); // will be patched in replaceRoute
2373 newStop.lane = stopLane;
2375 newStop.segment = MSGlobals::gMesoNet->getSegmentForEdge(newStop.lane->getEdge(), newStop.getEndPos(*this));
2376 if (newStop.lane->isInternal()) {
2377 errorMsg = TLF("Mesoscopic simulation does not allow stopping on internal edge '%' for vehicle '%'.", stop.edge, getID());
2378 return false;
2379 }
2380 }
2381 myStops.insert(itStop, newStop);
2382
2383 ConstMSEdgeVector oldRemainingEdges(myCurrEdge, getRoute().end());
2384 ConstMSEdgeVector newEdges; // only remaining
2385 newEdges.insert(newEdges.end(), myCurrEdge, itStart);
2386 if (!teleport) {
2387 newEdges.insert(newEdges.end(), toNewStop.begin(), toNewStop.end() - 1);
2388 } else {
2389 newEdges.push_back(*itStart);
2390 }
2391 if (!newDestination) {
2392 newEdges.insert(newEdges.end(), fromNewStop.begin(), fromNewStop.end() - 1);
2393 newEdges.insert(newEdges.end(), itEnd, oldEdges.end());
2394 } else {
2395 newEdges.push_back(stopEdge);
2396 }
2397 //std::cout << SIMTIME << " insertStop veh=" << getID()
2398 // << " teleport=" << teleport
2399 // << " busStop=" << stop.busstop
2400 // << " oldEdges=" << oldRemainingEdges.size()
2401 // << " newEdges=" << newEdges.size()
2402 // << " toNewStop=" << toNewStop.size()
2403 // << " fromNewStop=" << fromNewStop.size()
2404 // << "\n";
2405
2406 const double routeCost = router.recomputeCosts(newEdges, this, t);
2407 const double previousCost = router.recomputeCosts(oldRemainingEdges, this, t);
2408 const double savings = previousCost - routeCost;
2409
2410 if (!hasDeparted() && (int)myParameter->stops.size() >= nextStopIndex) {
2411 // stops will be rebuilt from scratch so we must patch the stops in myParameter
2412 auto it = myParameter->stops.begin() + nextStopIndex;
2413 const_cast<SUMOVehicleParameter*>(myParameter)->stops.insert(it, stop);
2414 }
2415 return replaceRouteEdges(newEdges, routeCost, savings, info, !hasDeparted(), false, false, &errorMsg);
2416}
2417
2418
2421 if (myEnergyParams == nullptr) {
2423 double tMass = 0;
2424 if (myPersonDevice != nullptr) {
2426 tMass += t->getVehicleType().getMass();
2427 }
2428 }
2429 if (myContainerDevice != nullptr) {
2431 tMass += t->getVehicleType().getMass();
2432 }
2433 }
2435 }
2436 return myEnergyParams;
2437}
2438
2439
2440double
2442 if (static_cast<MSDevice_Battery*>(getDevice(typeid(MSDevice_Battery))) != 0) {
2443 MSDevice_Battery* batteryOfVehicle = dynamic_cast<MSDevice_Battery*>(getDevice(typeid(MSDevice_Battery)));
2444 return batteryOfVehicle->getActualBatteryCapacity();
2445 } else {
2446 if (static_cast<MSDevice_ElecHybrid*>(getDevice(typeid(MSDevice_ElecHybrid))) != 0) {
2447 MSDevice_ElecHybrid* batteryOfVehicle = dynamic_cast<MSDevice_ElecHybrid*>(getDevice(typeid(MSDevice_ElecHybrid)));
2448 return batteryOfVehicle->getActualBatteryCapacity();
2449 }
2450 }
2451 return -1;
2452}
2453
2454
2455double
2457 if (static_cast<MSDevice_Battery*>(getDevice(typeid(MSDevice_Battery))) != 0) {
2458 MSDevice_Battery* batteryOfVehicle = dynamic_cast<MSDevice_Battery*>(getDevice(typeid(MSDevice_Battery)));
2459 return batteryOfVehicle->getActualBatteryCapacity() / batteryOfVehicle->getMaximumBatteryCapacity();
2460 } else {
2461 if (static_cast<MSDevice_ElecHybrid*>(getDevice(typeid(MSDevice_ElecHybrid))) != 0) {
2462 MSDevice_ElecHybrid* batteryOfVehicle = dynamic_cast<MSDevice_ElecHybrid*>(getDevice(typeid(MSDevice_ElecHybrid)));
2463 return batteryOfVehicle->getActualBatteryCapacity() / batteryOfVehicle->getMaximumBatteryCapacity();
2464 }
2465 }
2466 return -1;
2467}
2468
2469
2470double
2472 if (static_cast<MSDevice_Battery*>(getDevice(typeid(MSDevice_Battery))) != 0) {
2473 MSDevice_Battery* batteryOfVehicle = dynamic_cast<MSDevice_Battery*>(getDevice(typeid(MSDevice_Battery)));
2474 return batteryOfVehicle->getEnergyCharged();
2475 } else {
2476 if (static_cast<MSDevice_ElecHybrid*>(getDevice(typeid(MSDevice_ElecHybrid))) != 0) {
2477 MSDevice_ElecHybrid* batteryOfVehicle = dynamic_cast<MSDevice_ElecHybrid*>(getDevice(typeid(MSDevice_ElecHybrid)));
2478 return batteryOfVehicle->getEnergyCharged();
2479 }
2480 }
2481 return -1;
2482}
2483
2484
2485double
2487 if (static_cast<MSDevice_Battery*>(getDevice(typeid(MSDevice_Battery))) != 0) {
2488 MSDevice_Battery* batteryOfVehicle = dynamic_cast<MSDevice_Battery*>(getDevice(typeid(MSDevice_Battery)));
2489 return batteryOfVehicle->getMaximumChargeRate();
2490 }
2491 return -1;
2492}
2493
2494
2495double
2497 if (static_cast<MSDevice_ElecHybrid*>(getDevice(typeid(MSDevice_ElecHybrid))) != 0) {
2498 MSDevice_ElecHybrid* elecHybridDevice = dynamic_cast<MSDevice_ElecHybrid*>(getDevice(typeid(MSDevice_ElecHybrid)));
2499 return elecHybridDevice->getCurrentFromOverheadWire();
2500 }
2501
2502 return NAN;
2503}
2504
2505double
2507 if (isOnRoad() || isIdling()) {
2509 } else {
2510 return 0.;
2511 }
2512}
2513
2514
2519
2520
2525
2526
2529 if (myEdgeWeights == nullptr) {
2531 }
2532 return *myEdgeWeights;
2533}
2534
2535
2536
2537
2538int
2540 int boarded = myPersonDevice == nullptr ? 0 : myPersonDevice->size();
2541 return boarded + myParameter->personNumber;
2542}
2543
2544int
2546 int leavingPersonNumber = 0;
2547 const std::vector<MSTransportable*>& persons = getPersons();
2548 for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
2549 MSStageDriving* const stage = dynamic_cast<MSStageDriving*>((*it_p)->getCurrentStage());
2550 const MSStop* stop = &myStops.front();
2551 const MSVehicle* joinVeh = dynamic_cast<MSVehicle*>(MSNet::getInstance()->getVehicleControl().getVehicle((*stop).pars.join));
2552 if (stop && stage->canLeaveVehicle(*it_p, *this, *stop) && !MSDevice_Transportable::willTransferAtJoin(*it_p, joinVeh)) {
2553 leavingPersonNumber++;
2554 }
2555 }
2556 return leavingPersonNumber;
2557}
2558
2559std::vector<std::string>
2561 std::vector<std::string> ret;
2562 const std::vector<MSTransportable*>& persons = getPersons();
2563 for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
2564 ret.push_back((*it_p)->getID());
2565 }
2566 return ret;
2567}
2568
2569int
2571 int loaded = myContainerDevice == nullptr ? 0 : myContainerDevice->size();
2572 return loaded + myParameter->containerNumber;
2573}
2574
2575
2576void
2578 // this might be called from the MSTransportable destructor so we cannot do a dynamic cast to determine the type
2579 if (myPersonDevice != nullptr) {
2581 }
2582 if (myContainerDevice != nullptr) {
2584 }
2585 if (myEnergyParams != nullptr) {
2587 }
2588}
2589
2590
2591void
2597
2598
2599const std::vector<MSTransportable*>&
2601 if (myPersonDevice == nullptr) {
2603 } else {
2605 }
2606}
2607
2608
2609const std::vector<MSTransportable*>&
2611 if (myContainerDevice == nullptr) {
2613 } else {
2615 }
2616}
2617
2618
2619bool
2620MSBaseVehicle::isLineStop(double position) const {
2621 if (myParameter->line == "") {
2622 // not a public transport line
2623 return false;
2624 }
2625 for (const SUMOVehicleParameter::Stop& stop : myParameter->stops) {
2626 if (stop.startPos <= position && position <= stop.endPos) {
2627 return true;
2628 }
2629 }
2630 for (const SUMOVehicleParameter::Stop& stop : myRoute->getStops()) {
2631 if (stop.startPos <= position && position <= stop.endPos) {
2632 return true;
2633 }
2634 }
2635 return false;
2636}
2637
2638
2639bool
2640MSBaseVehicle::hasDevice(const std::string& deviceName) const {
2641 for (MSDevice* const dev : myDevices) {
2642 if (dev->deviceName() == deviceName) {
2643 return true;
2644 }
2645 }
2646 return false;
2647}
2648
2649
2650void
2651MSBaseVehicle::createDevice(const std::string& deviceName) {
2652 if (!hasDevice(deviceName)) {
2653 if (deviceName == "rerouting") {
2654 ((SUMOVehicleParameter*)myParameter)->setParameter("has." + deviceName + ".device", "true");
2656 if (hasDeparted()) {
2657 // vehicle already departed: disable pre-insertion rerouting and enable regular routing behavior
2658 MSDevice_Routing* routingDevice = static_cast<MSDevice_Routing*>(getDevice(typeid(MSDevice_Routing)));
2659 assert(routingDevice != 0);
2661 }
2662 } else {
2663 throw InvalidArgument(TLF("creating device of type '%' is not supported", deviceName));
2664 }
2665 }
2666}
2667
2668
2669std::string
2670MSBaseVehicle::getDeviceParameter(const std::string& deviceName, const std::string& key) const {
2671 for (MSVehicleDevice* const dev : myDevices) {
2672 if (dev->deviceName() == deviceName) {
2673 return dev->getParameter(key);
2674 }
2675 }
2676 throw InvalidArgument(TLF("no device of type '%' exists", deviceName));
2677}
2678
2679
2680void
2681MSBaseVehicle::setDeviceParameter(const std::string& deviceName, const std::string& key, const std::string& value) {
2682 for (MSVehicleDevice* const dev : myDevices) {
2683 if (dev->deviceName() == deviceName) {
2684 dev->setParameter(key, value);
2685 return;
2686 }
2687 }
2688 throw InvalidArgument(TLF("no device of type '%' exists", deviceName));
2689}
2690
2691
2692void
2693MSBaseVehicle::setJunctionModelParameter(const std::string& key, const std::string& value) {
2696 const_cast<SUMOVehicleParameter&>(getParameter()).setParameter(key, value);
2697 // checked in MSLink::ignoreFoe
2698 } else {
2699 throw InvalidArgument(TLF("Vehicle '%' does not support junctionModel parameter '%'.", getID(), key));
2700 }
2701}
2702
2703
2704void
2705MSBaseVehicle::setCarFollowModelParameter(const std::string& key, const std::string& value) {
2706 // handle some generic params first and then delegate to the carFollowModel itself
2709 const_cast<SUMOVehicleParameter&>(getParameter()).setParameter(key, value);
2710 // checked in MSVehicle::planMove
2711 } else {
2712 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(this);
2713 if (microVeh) {
2714 // remove 'carFollowModel.' prefix
2715 const std::string attrName = key.substr(15);
2716 microVeh->getCarFollowModel().setParameter(microVeh, attrName, value);
2717 }
2718 }
2719}
2720
2721
2722void
2724 /* Design idea for additional junction model parameters:
2725 We can distinguish between 3 levels of parameters
2726 1. typically shared by multiple vehicles -> vType parameter
2727 2. specific to one vehicle but stays constant throughout the simulation -> vehicle parameter
2728 3. specific to one vehicle and expected to change during simulation -> prefixed generic vehicle parameter
2729 */
2730 for (auto item : getParameter().getParametersMap()) {
2731 if (StringUtils::startsWith(item.first, "junctionModel.")) {
2732 setJunctionModelParameter(item.first, item.second);
2733 } else if (StringUtils::startsWith(item.first, "carFollowModel.")) {
2734 setCarFollowModelParameter(item.first, item.second);
2735 }
2736 }
2737 const std::string routingModeStr = getStringParam("device.rerouting.mode");
2738 try {
2739 int routingMode = StringUtils::toInt(routingModeStr);
2740 if (routingMode != libsumo::ROUTING_MODE_DEFAULT) {
2741 setRoutingMode(routingMode);
2743 // vehicles wishes to use traffic-dependent routing weights on triggere rerouting
2744 // (initWeightUpdate would be triggered anyway when equipped with device.rerouting)
2747 }
2748 }
2749 } catch (NumberFormatException&) {
2750 // @todo interpret symbolic constants
2751 throw ProcessError(TLF("could not interpret routing.mode '%'", routingModeStr));
2752 }
2753}
2754
2755
2764
2765
2766void
2768 assert(type != nullptr);
2769 // save old parameters before possible type deletion
2770 const double oldMu = myType->getSpeedFactor().getParameter(0);
2771 const double oldDev = myType->getSpeedFactor().getParameter(1);
2772 if (myType->isVehicleSpecific() && type != myType) {
2774 }
2775 // adapt myChosenSpeedFactor to the new type
2776 if (oldDev == 0.) {
2777 // old type had speedDev 0, reroll
2779 } else {
2780 // map old speedFactor onto new distribution
2781 const double distPoint = (myChosenSpeedFactor - oldMu) / oldDev;
2782 const double newMu = type->getSpeedFactor().getParameter(0);
2783 const double newDev = type->getSpeedFactor().getParameter(1);
2784 myChosenSpeedFactor = newMu + distPoint * newDev;
2785 // respect distribution limits
2788 }
2789 myType = type;
2790 if (myEnergyParams != nullptr) {
2792 }
2793}
2794
2795
2798 if (myType->isVehicleSpecific()) {
2799 return *const_cast<MSVehicleType*>(myType);
2800 }
2801 MSVehicleType* type = myType->buildSingularType(myType->getID() + "@" + getID());
2802 replaceVehicleType(type);
2803 return *type;
2804}
2805
2806
2807int
2809 const MSLane* const lane = getLane();
2810 if (lane == nullptr) {
2811 return getEdge()->getLanes()[0]->getRNGIndex();
2812 } else {
2813 return lane->getRNGIndex();
2814 }
2815}
2816
2817
2818SumoRNG*
2820 const MSLane* lane = getLane();
2821 if (lane == nullptr) {
2822 return getEdge()->getLanes()[0]->getRNG();
2823 } else {
2824 return lane->getRNG();
2825 }
2826}
2827
2828std::string
2829MSBaseVehicle::getPrefixedParameter(const std::string& key, std::string& error) const {
2830 const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(this);
2831 if (StringUtils::startsWith(key, "device.")) {
2832 StringTokenizer tok(key, ".");
2833 if (tok.size() < 3) {
2834 error = TLF("Invalid device parameter '%' for vehicle '%'.", key, getID());
2835 return "";
2836 }
2837 try {
2838 return getDeviceParameter(tok.get(1), key.substr(tok.get(0).size() + tok.get(1).size() + 2));
2839 } catch (InvalidArgument& e) {
2840 error = TLF("Vehicle '%' does not support device parameter '%' (%).", getID(), key, e.what());
2841 return "";
2842 }
2843 } else if (StringUtils::startsWith(key, "laneChangeModel.")) {
2844 if (microVeh == nullptr) {
2845 error = TLF("Mesoscopic vehicle '%' does not support laneChangeModel parameters.", getID());
2846 return "";
2847 }
2848 const std::string attrName = key.substr(16);
2849 try {
2850 return microVeh->getLaneChangeModel().getParameter(attrName);
2851 } catch (InvalidArgument& e) {
2852 error = TLF("Vehicle '%' does not support laneChangeModel parameter '%' (%).", getID(), key, e.what());
2853 return "";
2854 }
2855 } else if (StringUtils::startsWith(key, "carFollowModel.")) {
2856 if (microVeh == nullptr) {
2857 error = TLF("Mesoscopic vehicle '%' does not support carFollowModel parameters.", getID());
2858 return "";
2859 }
2860 const std::string attrName = key.substr(15);
2861 try {
2862 return microVeh->getCarFollowModel().getParameter(microVeh, attrName);
2863 } catch (InvalidArgument& e) {
2864 error = TLF("Vehicle '%' does not support carFollowModel parameter '%' (%).", getID(), key, e.what());
2865 return "";
2866 }
2867 } else if (StringUtils::startsWith(key, "has.") && StringUtils::endsWith(key, ".device")) {
2868 StringTokenizer tok(key, ".");
2869 if (tok.size() != 3) {
2870 error = TL("Invalid check for device. Expected format is 'has.DEVICENAME.device'.");
2871 return "";
2872 }
2873 return hasDevice(tok.get(1)) ? "true" : "false";
2874 // parking related parameters start here
2875 } else if (key == "parking.rerouteCount") {
2877 } else if (StringUtils::startsWith(key, "parking.memory.")) {
2878 std::vector<std::string> values;
2879 if (getParkingMemory()) {
2880 if (key == "parking.memory.IDList") {
2881 for (const auto& item : *getParkingMemory()) {
2882 values.push_back(item.first->getID());
2883 }
2884 } else if (key == "parking.memory.score") {
2885 for (const auto& item : *getParkingMemory()) {
2886 values.push_back(item.second.score);
2887 }
2888 } else if (key == "parking.memory.blockedAtTime") {
2889 for (const auto& item : *getParkingMemory()) {
2890 values.push_back(toString(STEPS2TIME(item.second.blockedAtTime)));
2891 }
2892 } else if (key == "parking.memory.blockedAtTimeLocal") {
2893 for (const auto& item : *getParkingMemory()) {
2894 values.push_back(toString(STEPS2TIME(item.second.blockedAtTimeLocal)));
2895 }
2896 } else {
2897 error = TLF("Unsupported parking parameter '%' for vehicle '%'.", key, getID());
2898 }
2899 }
2900 return toString(values);
2901 } else {
2902 // default: custom user parameter
2903 return getParameter().getParameter(key, "");
2904 }
2905}
2906
2907
2908void
2915
2916
2917void
2923
2924
2925void
2927 if (myChargingMemory == nullptr) {
2929 }
2931}
2932
2933
2934void
2940
2941
2942void
2943MSBaseVehicle::rememberParkingAreaScore(const MSStoppingPlace* pa, const std::string& score) {
2944 if (myParkingMemory == nullptr) {
2946 }
2948}
2949
2950
2953 if (myParkingMemory == nullptr) {
2954 return -1;
2955 }
2956 return myParkingMemory->sawBlockedStoppingPlace(pa, local);
2957}
2958
2959
2966
2967
2970 if (myChargingMemory == nullptr) {
2971 return -1;
2972 }
2973 return myChargingMemory->sawBlockedStoppingPlace(cs, local);
2974}
2975
2976
2977void
2979 if (hasStops() && myStops.front().parkingarea != nullptr && myStops.front().parkingarea->isReservable()) {
2980 myStops.front().parkingarea->removeSpaceReservation(this);
2981 }
2982}
2983
2984
2985#ifdef _DEBUG
2986void
2987MSBaseVehicle::initMoveReminderOutput(const OptionsCont& oc) {
2988 if (oc.isSet("movereminder-output.vehicles")) {
2989 const std::vector<std::string> vehicles = oc.getStringVector("movereminder-output.vehicles");
2990 myShallTraceMoveReminders.insert(vehicles.begin(), vehicles.end());
2991 }
2992}
2993
2994
2995void
2996MSBaseVehicle::traceMoveReminder(const std::string& type, MSMoveReminder* rem, double pos, bool keep) const {
2997 OutputDevice& od = OptionsCont::getDeviceByOption("movereminder-output");
2998 od.openTag("movereminder");
2999 od.writeAttr(SUMO_ATTR_TIME, STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep()));
3000 od.writeAttr("veh", getID());
3002 od.writeAttr("type", type);
3003 od.writeAttr("pos", toString(pos));
3004 od.writeAttr("keep", toString(keep));
3005 od.closeTag();
3006}
3007#endif
3008
3009
3010/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:75
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition MSRoute.h:57
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:299
#define WRITE_ERRORF(...)
Definition MsgHandler.h:308
#define WRITE_WARNING(msg)
Definition MsgHandler.h:298
#define TL(string)
Definition MsgHandler.h:316
#define TLF(string,...)
Definition MsgHandler.h:318
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.h:32
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:107
#define STEPS2TIME(x)
Definition SUMOTime.h:58
#define SIMSTEP
Definition SUMOTime.h:69
constexpr SUMOTime TIME2STEPS(double x)
Definition SUMOTime.h:60
#define SUMOTime_MAX
Definition SUMOTime.h:34
#define SIMTIME
Definition SUMOTime.h:70
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permissions is a (exclusive) railway edge.
@ RANDOM
The edge is chosen randomly.
@ GIVEN
The edge index is given.
@ DEFAULT
No information given; use default.
const int STOP_INDEX_END
const long long int VEHPARS_FORCE_REROUTE
DepartLaneDefinition
Possible ways to choose a lane on depart.
@ GIVEN
The speed is given.
@ GIVEN
The position is given.
@ DEFAULT
No information given; use default.
@ BASE
Back-at-zero position.
const int STOP_SPEED_SET
const long long int VEHPARS_CFMODEL_PARAMS_SET
@ RANDOM
The lane is chosen randomly.
@ GIVEN
The arrival lane is given.
@ FIRST_ALLOWED
The rightmost lane the vehicle may use.
std::vector< SUMOVehicleParameter::Stop > StopParVector
@ GIVEN
The speed is given.
const int STOP_INDEX_REPEAT
const long long int VEHPARS_PARKING_BADGES_SET
const int STOP_INDEX_FIT
const long long int VEHPARS_JUNCTIONMODEL_PARAMS_SET
const long long int VEHPARS_SPEEDFACTOR_SET
@ RANDOM
The arrival position is chosen randomly.
@ GIVEN
The arrival position is given.
@ CENTER
Half the road length.
const int STOP_JUMP_SET
const long long int VEHPARS_LINE_SET
const long long int VEHPARS_INSERTION_CHECKS_SET
@ CONTAINER_TRIGGERED
The departure is container triggered.
@ TRIGGERED
The departure is person triggered.
@ SUMO_TAG_CLOSING_REROUTE
reroute of type closing
@ SUMO_TAG_VEHICLE
description of a vehicle
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_ATTR_CF_IGNORE_IDS
@ SUMO_ATTR_JM_IGNORE_IDS
@ SUMO_ATTR_JM_IGNORE_TYPES
@ SUMO_ATTR_LINE
@ SUMO_ATTR_REROUTE
@ SUMO_ATTR_DISTANCE
@ SUMO_ATTR_SPEEDFACTOR
@ SUMO_ATTR_ROUTE
@ SUMO_ATTR_ID
@ SUMO_ATTR_CF_IGNORE_TYPES
@ SUMO_ATTR_ARRIVALPOS_RANDOMIZED
@ SUMO_ATTR_TIME
trigger: the time of the step
double gWeightsRandomFactor
Definition StdDefs.cpp:35
int gPrecisionRandom
Definition StdDefs.cpp:30
const double INVALID_DOUBLE
invalid double
Definition StdDefs.h:68
T MIN2(T a, T b)
Definition StdDefs.h:80
const double SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
Definition StdDefs.h:62
T MAX2(T a, T b)
Definition StdDefs.h:86
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
double getMax() const
Returns the maximum value of this distribution.
double getMin() const
Returns the minimum value of this distribution.
double getParameter(const int index) const
Returns the nth parameter of this distribution.
An upper class for objects with additional parameters.
double getTransportableMass() const
Returns the mass of all transportables in the vehicle.
void setSecondary(const EnergyParams *secondaryParams)
Set secondary params.
void setTransportableMass(const double mass)
Sets the mass of all transportables in the vehicle.
static double computeNoise(SUMOEmissionClass c, double v, double a)
Returns the noise produced by the a vehicle of the given type at the given speed.
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
Definition MELoop.cpp:435
virtual std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this laneChangeModel. Throw exception for unsupported key
double getMaxSpeed() const
Returns the maximum speed (the minimum of desired and technical maximum speed)
bool haveValidStopEdges(bool silent=false) const
check whether all stop.edge MSRouteIterators are valid and in order
int myRoutingMode
routing mode (see TraCIConstants.h)
bool hasJump(const MSRouteIterator &it) const
check whether the vehicle has jump at the given part of its route
bool hasReminder(MSMoveReminder *rem) const
Checks whether the vehicle has the given MoveReminder.
static double addStopPriority(double p1, double p2)
std::list< MSStop > myStops
The vehicle's list of stops.
StoppingPlaceMemory * myParkingMemory
memory for parking search
double getImpatience() const
Returns this vehicles impatience.
void setSkips(MSStop &stop, int prevActiveStops)
patch stop.pars.index to record the number of skipped candidate edges before stop....
virtual ConstMSEdgeVector::const_iterator getRerouteOrigin() const
Returns the starting point for reroutes (usually the current edge)
const StoppingPlaceMemory * getParkingMemory() const
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
virtual void initDevices()
void rememberParkingAreaScore(const MSStoppingPlace *pa, const std::string &score)
score only needed when running with gui
const long long int myRandomSeed
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs'th successor of edge the vehicle is currently at.
int getDepartEdge() const
Returns the edge on which this vehicle shall depart.
void resetRoutePosition(int index, DepartLaneDefinition departLaneProcedure)
reset index of edge within route
std::string getDeviceParameter(const std::string &deviceName, const std::string &key) const
try to retrieve the given parameter from any of the vehicles devices, raise InvalidArgument if no dev...
StoppingPlaceMemory * myChargingMemory
bool replaceStop(int nextStopIndex, SUMOVehicleParameter::Stop stop, const std::string &info, bool teleport, std::string &errorMsg)
int getLeavingPersonNumber() const
Returns the number of leaving persons.
MSBaseVehicle(SUMOVehicleParameter *pars, ConstMSRoutePtr route, MSVehicleType *type, const double speedFactor)
Constructor.
void calculateArrivalParams(bool onInit)
(Re-)Calculates the arrival position and lane from the vehicle parameters
virtual double getArrivalPos() const
Returns this vehicle's desired arrivalPos for its current route (may change on reroute)
void setCarFollowModelParameter(const std::string &key, const std::string &value)
set individual carFollow model parameters (not type related)
void setRoutingMode(int value)
Sets routing behavior.
void resetParkingAreaScores()
static NumericalID myCurrentNumericalIndex
bool rerouteBetweenStops(int nextStopIndex, const std::string &info, bool teleport, std::string &errorMsg)
MoveReminderCont myMoveReminders
Currently relevant move reminders.
void rememberChargingStationScore(const MSStoppingPlace *cs, const std::string &score)
int getInsertionChecks() const
double myDepartPos
The real depart position.
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
double getMaxChargeRate() const
Returns the maximum charge rate allowed by the battery in the current time step (W)
void replaceParameter(const SUMOVehicleParameter *newParameter)
replace the vehicle parameter (deleting the old one)
void rememberBlockedParkingArea(const MSStoppingPlace *pa, bool local)
int getNumberParkingReroutes() const
std::vector< MSVehicleDevice * > myDevices
The devices this vehicle has.
virtual const MSEdge * getCurrentEdge() const
Returns the edge the vehicle is currently at (possibly an internal edge)
double getPreviousSpeed() const
Returns the vehicle's previous speed.
void removeTransportableMass(MSTransportable *t)
removes a person or containers mass
MSStop & getNextStopMutable()
virtual void updateBestLanes(bool forceRebuild=false, const MSLane *startLane=0)
virtual void addTransportable(MSTransportable *transportable)
Adds a person or container to this vehicle.
virtual BaseInfluencer & getBaseInfluencer()=0
Returns the velocity/lane influencer.
const SUMOVehicleParameter::Stop * getNextStopParameter() const
return parameters for the next stop (SUMOVehicle Interface)
void rememberBlockedChargingStation(const MSStoppingPlace *cs, bool local)
virtual bool replaceRoute(ConstMSRoutePtr route, const std::string &info, bool onInit=false, int offset=0, bool addRouteStops=true, bool removeStops=true, std::string *msgReturn=nullptr)
Replaces the current route by the given one.
SUMOTime activateRemindersOnReroute(SUMOTime currentTime)
remove outdated driveways on reroute
int getNumRemainingEdges() const
return the number of edges remaining in the route (include the current)
double getOdometer() const
Returns the distance that was already driven by this vehicle.
bool isRail() const
virtual bool hasArrived() const
Returns whether this vehicle has already arrived (by default this is true if the vehicle has reached ...
const NumericalID myNumericalID
bool isStoppedInRange(const double pos, const double tolerance, bool checkFuture=false) const
return whether the given position is within range of the current stop
bool isJumping() const
Returns whether the vehicle is perform a jump.
void checkRouteRemoval()
remove route at the end of the simulation
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
const MSVehicleType * myType
This vehicle's type.
const MSRouteIterator & getCurrentRouteEdge() const
Returns an iterator pointing to the current edge in this vehicles route.
bool isStoppedParking() const
Returns whether the vehicle is on a parking stop.
void unregisterWaiting()
mark vehicle as active
bool hasValidRoute(std::string &msg, ConstMSRoutePtr route=0) const
Validates the current or given route.
void cleanupParkingReservation()
unregisters from a parking reservation when changing or skipping stops
double getLength() const
Returns the vehicle's length.
bool isParking() const
Returns whether the vehicle is parking.
MSParkingArea * getCurrentParkingArea()
get the current parking area stop or nullptr
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
double getHarmonoise_NoiseEmissions() const
Returns noise emissions of the current state.
int getPersonNumber() const
Returns the number of persons.
double getRelativeStateOfCharge() const
Returns actual relative state of charge of battery (-)
void setJunctionModelParameter(const std::string &key, const std::string &value)
set individual junction model parameter (not type related)
void setDepartAndArrivalEdge()
apply departEdge and arrivalEdge attributes
void setID(const std::string &newID)
set the id (inherited from Named but forbidden for vehicles)
MSRouteIterator myCurrEdge
Iterator to current route-edge.
static MSLane * interpretOppositeStop(SUMOVehicleParameter::Stop &stop)
interpret stop lane on opposite side of the road
StopParVector myPastStops
The list of stops that the vehicle has already reached.
static std::vector< MSTransportable * > myEmptyTransportableVector
const std::vector< std::string > & getParkingBadges() const
get the valid parking access rights (vehicle settings override vehicle type settings)
bool hasDeparted() const
Returns whether this vehicle has already departed.
bool ignoreTransientPermissions() const
Returns whether this object is ignoring transient permission changes (during routing)
virtual void resetApproachOnReroute()
reset rail signal approach information
ConstMSRoutePtr myRoute
This vehicle's route.
MSDevice_Transportable * myContainerDevice
The containers this vehicle may have.
void resetChargingStationScores()
bool allowsBoarding(const MSTransportable *t) const
whether the given transportable is allowed to board this vehicle
double getStateOfCharge() const
Returns actual state of charge of battery (Wh) RICE_CHECK: This may be a misnomer,...
MSEdgeWeightsStorage & _getWeightsStorage() const
virtual bool handleCollisionStop(MSStop &stop, const double distToStop)
bool hasDevice(const std::string &deviceName) const
check whether the vehicle is equipped with a device of the given name
void addReminder(MSMoveReminder *rem, double pos=0)
Adds a MoveReminder dynamically.
SumoRNG * getRNG() const
SUMOTime getDeparture() const
Returns this vehicle's real departure time.
SUMOTime sawBlockedChargingStation(const MSStoppingPlace *cs, bool local) const
EnergyParams * getEmissionParameters() const
retrieve parameters for the energy consumption model
double basePos(const MSEdge *edge) const
departure position where the vehicle fits fully onto the edge (if possible)
void setDeviceParameter(const std::string &deviceName, const std::string &key, const std::string &value)
try to set the given parameter from any of the vehicles devices, raise InvalidArgument if no device p...
MSDevice_Transportable * myPersonDevice
The passengers this vehicle may have.
bool hasStops() const
Returns whether the vehicle has to stop somewhere.
std::string getFlowID() const
reconstruct flow id from vehicle id
virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
"Activates" all current move reminder
bool isLineStop(double position) const
returns whether the vehicle serves a public transport line that serves the given stop
double myChosenSpeedFactor
A precomputed factor by which the driver wants to be faster than the speed limit.
const MSStop & getNextStop() const
@ ROUTE_INVALID
route was checked and is valid
@ ROUTE_START_INVALID_PERMISSIONS
std::string getPrefixedParameter(const std::string &key, std::string &error) const
retrieve parameters of devices, models and the vehicle itself
bool replaceWithAlternative(std::list< MSStop >::iterator iter, const MSRouteIterator searchStart, const MSRouteIterator end)
replace stop with a same-name alternative that is on the route and return success
void addStops(const bool ignoreStopErrors, MSRouteIterator *searchStart=nullptr, bool addRouteStops=true)
Adds stops to the built vehicle.
void removeTransportable(MSTransportable *t)
removes a person or container
SUMOTime sawBlockedParkingArea(const MSStoppingPlace *pa, bool local) const
SUMOVehicleClass getVClass() const
Returns the vehicle's access class.
MSParkingArea * getNextParkingArea()
get the upcoming parking area stop or nullptr
int myArrivalLane
The destination lane where the vehicle stops.
int getRouteValidity(bool update=true, bool silent=false, std::string *msgReturn=nullptr)
check for route validity at first insertion attempt
MSStop & getStop(int nextStopIndex)
virtual ~MSBaseVehicle()
Destructor.
bool insertStop(int nextStopIndex, SUMOVehicleParameter::Stop stop, const std::string &info, bool teleport, std::string &errorMsg)
virtual bool instantStopping() const
whether instant stopping is permitted
SUMOTime myDeparture
The real departure time.
std::vector< std::string > getPersonIDList() const
Returns the list of persons.
const MSEdgeWeightsStorage & getWeightsStorage() const
Returns the vehicle's internal edge travel times/efforts container.
bool isStoppedTriggered() const
Returns whether the vehicle is on a triggered stop.
virtual bool resumeFromStopping()=0
virtual bool hasInfluencer() const =0
whether the vehicle is individually influenced (via TraCI or special parameters)
const std::set< SUMOTrafficObject::NumericalID > getUpcomingEdgeIDs() const
returns the numerical ids of edges to travel
void initTransportableDevice(bool isPerson)
init device during state loading
bool stopsAtEdge(const MSEdge *edge) const
Returns whether the vehicle stops at the given edge.
bool addStop(const SUMOVehicleParameter::Stop &stopPar, std::string &errorMsg, SUMOTime untilOffset=0, MSRouteIterator *searchStart=nullptr)
Adds a stop.
double getChargedEnergy() const
Returns the energy charged to the battery in the current time step (Wh)
void onDepart()
Called when the vehicle is inserted into the network.
void removeReminder(MSMoveReminder *rem)
Removes a MoveReminder dynamically.
SUMOTime getStopDuration() const
get remaining stop duration or 0 if the vehicle isn't stopped
virtual double getAcceleration() const
Returns the vehicle's acceleration.
virtual bool addTraciStop(SUMOVehicleParameter::Stop stop, std::string &errorMsg)
const MSRoute & getRoute() const
Returns the current route.
int getRoutingMode() const
return routing mode (configures router choice but also handling of transient permission changes)
int getRoutePosition() const
return index of edge within route
bool replaceParkingArea(MSParkingArea *parkingArea, std::string &errorMsg)
replace the current parking area stop with a new stop with merge duration
static const SUMOTime NOT_YET_DEPARTED
SUMOTime getDepartDelay() const
Returns the depart delay.
double getElecHybridCurrent() const
Returns actual current (A) of ElecHybrid device RICE_CHECK: Is this the current consumed from the ove...
bool myAmRegisteredAsWaiting
Whether this vehicle is registered as waiting for a person or container (for deadlock-recognition)
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT() const
returns the router according to the current routing mode of the vehicle
EnergyParams * myEnergyParams
The emission parameters this vehicle may have.
const SUMOVehicleParameter * myParameter
This vehicle's parameter.
virtual bool hasValidRouteStart(std::string &msg)
checks whether the vehicle can depart on the first edge
int myRouteValidity
status of the current vehicle route
std::vector< std::pair< int, double > > getStopIndices() const
return list of route indices for the remaining stops
SUMOTime myStopUntilOffset
The offset when adding route stops with 'until' on route replacement.
virtual bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
const std::vector< MSTransportable * > & getContainers() const
retrieve riding containers
bool reroute(SUMOTime t, const std::string &info, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false, const bool silent=false, const MSEdge *sink=nullptr)
Performs a rerouting using the given router.
bool stopsAt(MSStoppingPlace *stop) const
Returns whether the vehicle stops at the given stopping place.
int getRNGIndex() const
MSEdgeWeightsStorage * myEdgeWeights
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
void createDevice(const std::string &deviceName)
create device of the given type
bool isStopped() const
Returns whether the vehicle is at a stop.
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists, nullptr otherwise.
bool abortNextStop(int nextStopIndex=0)
deletes the next stop at the given index if it exists
int myNumberReroutes
The number of reroutings.
double myArrivalPos
The position on the destination lane where the vehicle stops.
bool insertJump(int nextStopIndex, MSRouteIterator itStart, std::string &errorMsg)
helper function
virtual void saveState(OutputDevice &out)
Saves the (common) state of a vehicle.
virtual void replaceVehicleType(const MSVehicleType *type)
Replaces the current vehicle type by the one given.
std::vector< StopEdgeInfo > getStopEdges(double &firstPos, double &lastPos, std::set< int > &jumps) const
Returns the list of still pending stop edges also returns the first and last stop position.
double myOdometer
A simple odometer to keep track of the length of the route already driven.
void initTransientModelParams()
init model parameters from generic params
int getContainerNumber() const
Returns the number of containers.
bool replaceRouteEdges(ConstMSEdgeVector &edges, double cost, double savings, const std::string &info, bool onInit=false, bool check=false, bool removeStops=true, std::string *msgReturn=nullptr)
Replaces the current route by the given edges.
virtual std::string getParameter(const MSVehicle *veh, const std::string &key) const
try to get the given parameter for this carFollowingModel
Definition MSCFModel.h:707
virtual void setParameter(MSVehicle *veh, const std::string &key, const std::string &value) const
try to set the given parameter for this carFollowingModel
Definition MSCFModel.h:720
Battery device for electric vehicles.
double getActualBatteryCapacity() const
Get the actual vehicle's Battery Capacity in Wh.
double getMaximumChargeRate() const
Get current charge rate in W depending on the state of charge.
double getMaximumBatteryCapacity() const
Get the total vehicle's Battery Capacity in Wh.
double getEnergyCharged() const
Get charged energy.
A device which collects info on the vehicle trip (mainly on departure and arrival)
double getMaximumBatteryCapacity() const
Get the total vehicle's Battery Capacity in kWh.
double getCurrentFromOverheadWire() const
Get actual current in the overhead wire segment.
double getEnergyCharged() const
Get charged energy.
double getActualBatteryCapacity() const
Get the actual vehicle's Battery Capacity in kWh.
A device that performs vehicle rerouting based on current edge speeds.
bool sufficientSaving(double oldCost, double newCost)
whether the change in saving is enough to trigger rerouting
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Computes a new route on vehicle insertion.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
A device which collects info on the vehicle trip (mainly on departure and arrival)
bool allowsBoarding(const MSTransportable *t) const
whether the given person is allowed to board this taxi
const std::vector< MSTransportable * > & getTransportables() const
Returns the list of transportables using this vehicle.
static bool willTransferAtJoin(const MSTransportable *t, const MSBaseVehicle *joinVeh)
check if boardingDuration should be applied
static MSDevice_Transportable * buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into, const bool isContainer)
Build devices for the given vehicle, if needed.
int size() const
Return the number of passengers / containers.
void addTransportable(MSTransportable *transportable)
Add a passenger.
void removeTransportable(MSTransportable *transportable)
Remove a passenger (TraCI)
Abstract in-vehicle / in-person device.
Definition MSDevice.h:62
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
Definition MSDevice.cpp:115
A road/street connecting two junctions.
Definition MSEdge.h:78
static void clear()
Clears the dictionary.
Definition MSEdge.cpp:1163
bool hasTransientPermissions() const
Definition MSEdge.cpp:1754
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition MSEdge.h:169
const MSEdge * getOppositeEdge() const
Returns the opposite direction edge if on exists else a nullptr.
Definition MSEdge.cpp:1423
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_IGNORING, bool ignoreTransientPermissions=false) const
Get the allowed lanes to reach the destination-edge.
Definition MSEdge.cpp:516
bool isNormal() const
return whether this edge is an internal edge
Definition MSEdge.h:265
bool isTazConnector() const
Definition MSEdge.h:293
int getNumLanes() const
Definition MSEdge.h:173
bool isInternal() const
return whether this edge is an internal edge
Definition MSEdge.h:270
bool prohibits(const SUMOVehicle *const vehicle) const
Returns whether the vehicle (class) is not allowed on the edge.
Definition MSEdge.h:637
double getMinLength() const
return the minimum length of all lanes (only differs from getLength for curved internal lanes)
Definition MSEdge.cpp:1786
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary....
Definition MSEdge.cpp:1117
const MSEdge * getNormalBefore() const
if this edge is an internal edge, return its first normal predecessor, otherwise the edge itself
Definition MSEdge.cpp:1007
MSLane * getFirstAllowed(SUMOVehicleClass vClass, bool defaultFirst=false, int routingMode=0) const
Definition MSEdge.cpp:791
A storage for edge travel times and efforts.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
static bool gUseMesoSim
Definition MSGlobals.h:106
static bool gCheckRoutes
Definition MSGlobals.h:91
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition MSGlobals.h:115
static int gInsertionChecks
The default value for insertion checks.
Definition MSGlobals.h:189
static SUMOTime gTimeToImpatience
Definition MSGlobals.h:78
static bool gHaveEmissions
Whether emission output of some type is needed (files or GUI)
Definition MSGlobals.h:186
static bool gUseStopEnded
whether the simulation should replay previous stop times
Definition MSGlobals.h:133
void descheduleDeparture(const SUMOVehicle *veh)
stops trying to emit the given vehicle (and delete it)
Representation of a lane in the micro simulation.
Definition MSLane.h:84
int getRNGIndex() const
returns the associated RNG index
Definition MSLane.h:241
const MSEdge * getNextNormal() const
Returns the lane's follower if it is an internal lane, the edge of the lane otherwise.
Definition MSLane.cpp:2514
double getLength() const
Returns the lane's length.
Definition MSLane.h:632
bool allowsVehicleClass(SUMOVehicleClass vclass) const
Definition MSLane.h:959
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition MSLane.cpp:2538
bool isInternal() const
Definition MSLane.cpp:2669
SumoRNG * getRNG() const
return the associated RNG
Definition MSLane.h:246
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:790
Something on a lane to be noticed about vehicle movement.
virtual bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane)
Checks whether the reminder is activated by a vehicle entering the lane.
const std::string & getDescription() const
Notification
Definition of a vehicle state.
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
const MSLane * getLane() const
Returns the lane the reminder works on.
@ NEWROUTE
The vehicle got a new route.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:201
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition MSNet.h:496
const std::vector< MSStoppingPlace * > & getStoppingPlaceAlternatives(const std::string &name, SumoXMLTag category) const
Definition MSNet.cpp:1562
MSVehicleRouter & getRouterTT(int rngIndex, const Prohibitions &prohibited={}) const
Definition MSNet.cpp:1659
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:335
static bool hasInstance()
Returns whether the network was already constructed.
Definition MSNet.h:159
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition MSNet.cpp:1527
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to, const std::string &info="")
Informs all added listeners about a vehicle's state change.
Definition MSNet.cpp:1402
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition MSNet.h:456
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:403
A lane area vehicles can halt at.
bool accepts(SUMOVehicle *veh) const override
Return the parking accepts the vehicle (due to its given badges)
static void storeTripId(const std::string &tripId, const std::string &vehID)
const ConstMSEdgeVector & getEdges() const
Definition MSRoute.h:128
void setCosts(double costs)
Sets the costs of the route.
Definition MSRoute.h:209
static bool hasRoute(const std::string &id)
returns whether a route with the given id exists
Definition MSRoute.cpp:159
static bool dictionary(const std::string &id, ConstMSRoutePtr route)
Adds a route to the dictionary.
Definition MSRoute.cpp:116
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
Definition MSRoute.cpp:194
void setSavings(double savings)
Sets the savings of the route.
Definition MSRoute.h:216
static void initEdgeWeights(SUMOVehicleClass svc, SUMOTime lastAdaption=-1, int index=-1)
initialize the edge weights if not done before
static void initWeightUpdate(SUMOTime lastAdaption=- 1)
intialize period edge weight update
static MSVehicleRouter & getRouterTT(const int rngIndex, SUMOVehicleClass svc, const Prohibitions &prohibited={})
return the vehicle router instance
bool canLeaveVehicle(const MSTransportable *t, const SUMOVehicle &veh, const MSStop &stop)
checks whether the person may exit at the current vehicle position
const MSLane * lane
The lane to stop at (microsim only)
Definition MSStop.h:50
MSStoppingPlace * containerstop
(Optional) container stop if one is assigned to the stop
Definition MSStop.h:56
std::string getDescription(bool nameOnly=false) const
get a short description for showing in the gui
Definition MSStop.cpp:73
bool isOpposite
whether this an opposite-direction stop
Definition MSStop.h:87
void initPars(const SUMOVehicleParameter::Stop &stopPar)
initialize attributes from the given stop parameters
Definition MSStop.cpp:152
const MESegment * segment
The segment to stop at (mesosim only)
Definition MSStop.h:52
bool reached
Information whether the stop has been reached.
Definition MSStop.h:75
MSRouteIterator edge
The edge in the route to stop at.
Definition MSStop.h:48
std::vector< int > skips
route indices on looped route that were skipped before this stop (after pior stop or depart edge)
Definition MSStop.h:95
double getEndPos(const SUMOVehicle &veh) const
return halting position for upcoming stop;
Definition MSStop.cpp:39
MSParkingArea * parkingarea
(Optional) parkingArea if one is assigned to the stop
Definition MSStop.h:58
MSStoppingPlace * chargingStation
(Optional) charging station if one is assigned to the stop
Definition MSStop.h:60
SUMOTime getUntil() const
return until / ended time
Definition MSStop.cpp:191
SUMOTime getArrival() const
return arrival / started time
Definition MSStop.cpp:197
const SUMOVehicleParameter::Stop pars
The stop parameter.
Definition MSStop.h:65
MSStoppingPlace * busstop
(Optional) bus stop if one is assigned to the stop
Definition MSStop.h:54
MSStoppingPlace * overheadWireSegment
(Optional) overhead wire segment if one is assigned to the stop
Definition MSStop.h:63
Finds a sequence of skips and stop alternatives to maximize priority of reached stops.
ConstMSEdgeVector optimizeSkipped(const MSEdge *source, double sourcePos, std::vector< StopEdgeInfo > &stops, ConstMSEdgeVector edges) const
A lane area vehicles can halt at.
double getBeginLanePosition() const
Returns the begin position of this stop.
double getParkingLength() const
SumoXMLTag getElement() const
return the type of this stopping place
double getEndLanePosition() const
Returns the end position of this stop.
const MSLane & getLane() const
Returns the lane this stop is located at.
bool isPerson() const override
Whether it is a person.
const MSVehicleType & getVehicleType() const override
Returns the object's "vehicle" type.
static const double DEFAULT_MAXDELAY
void vehicleDeparted(const SUMOVehicle &v)
Informs this control about a vehicle's departure.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
void removeVType(const MSVehicleType *vehType)
void unregisterOneWaiting()
decreases the count of vehicles waiting for a transport to allow recognition of person / container re...
Abstract in-vehicle device.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
MSAbstractLaneChangeModel & getLaneChangeModel()
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
Definition MSVehicle.h:973
The car-following model and parameter.
const EnergyParams * getEmissionParameters() const
retrieve parameters for the energy consumption model
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
double getMaxSpeed() const
Get vehicle's (technical) maximum speed [m/s].
double getDesiredMaxSpeed() const
Returns the vehicles's desired maximum speed.
const std::string & getID() const
Returns the name of the vehicle type.
const Distribution_Parameterized & getSpeedFactor() const
Returns this type's speed factor.
bool isVehicleSpecific() const
Returns whether this type belongs to a single vehicle only (was modified)
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
double getLength() const
Get vehicle's length [m].
double getMass() const
Get this vehicle type's mass.
double computeChosenSpeedDeviation(double speedFactorOverride, SumoRNG *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
MSVehicleType * buildSingularType(const std::string &id) const
Duplicates the microsim vehicle type giving the newly created type the given id, marking it as vehicl...
const std::vector< std::string > & getParkingBadges() const
Returns the parking access rights of this type.
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
Definition Named.h:66
const std::string & getID() const
Returns the id.
Definition Named.h:73
A storage for options typed value containers)
Definition OptionsCont.h:92
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
int getPrecision()
Returns the precision of the underlying stream.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precision or resets it to default.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
Definition RGBColor.h:218
Utility functions for using a global, resetable random number generator.
Definition RandHelper.h:127
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E * > &into, bool silent=false)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
virtual double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
double recomputeCostsPos(const std::vector< const E * > &edges, const V *const v, double fromPos, double toPos, SUMOTime msTime, double *lengthp=nullptr) const
std::string getStringParam(const std::string &paramName, const bool required=false, const std::string &deflt="") const
Retrieve a string parameter for the traffic object.
virtual const MSLane * getLane() const =0
Returns the lane the object is currently at.
long long int NumericalID
virtual double getSpeed() const =0
Returns the object's current speed.
virtual SUMOTime getWaitingTime(const bool accumulated=false) const =0
virtual bool isPerson() const
Whether it is a person.
double getFloatParam(const std::string &paramName, const bool required=false, const double deflt=INVALID_DOUBLE, bool checkDist=true) const
Retrieve a floating point parameter for the traffic object.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
Definition SUMOVehicle.h:63
virtual bool isIdling() const =0
Returns whether the vehicle is idling (waiting to re-enter the net.
virtual double getBrakeGap(bool delayed=false) const =0
get distance for coming to a stop (used for rerouting checks)
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.
double speed
the speed at which this stop counts as reached (waypoint mode)
std::string parkingarea
(Optional) parking area if one is assigned to the stop
double startPos
The stopping position start.
int parametersSet
Information for the output which parameter were set.
int index
at which position in the stops list
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.
bool triggered
whether an arriving person lets the vehicle continue
SUMOTime ended
the time at which this stop was ended
double endPos
The stopping position end.
std::string tripId
id of the trip within a cyclical public transport route
bool containerTriggered
whether an arriving container lets the vehicle continue
bool collision
Whether this stop was triggered by a collision.
SUMOTime arrival
The (expected) time at which the vehicle reaches the stop.
SUMOTime duration
The stopping duration.
Structure representing possible vehicle parameter.
ArrivalSpeedDefinition arrivalSpeedProcedure
Information how the vehicle's end speed shall be chosen.
double departSpeed
(optional) The initial speed of the vehicle
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.
ArrivalLaneDefinition arrivalLaneProcedure
Information how the vehicle shall choose the lane to arrive on.
long long int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
void write(OutputDevice &dev, const OptionsCont &oc, const SumoXMLTag altTag=SUMO_TAG_VEHICLE, const std::string &typeID="") const
Writes the parameters as a beginning element.
int personNumber
The static number of persons in the vehicle when it departs (not including boarding persons)
RouteIndexDefinition arrivalEdgeProcedure
Information how the vehicle's final edge shall be chosen.
bool wasSet(long long int what) const
Returns whether the given parameter was set.
double departPos
(optional) The position the vehicle shall depart from
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle's initial speed shall be chosen.
double arrivalPos
(optional) The position the vehicle shall arrive on
std::string routeid
The vehicle's route id.
std::string id
The vehicle's id.
std::vector< std::string > parkingBadges
The parking access rights.
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
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
std::string toTaz
The vehicle's destination zone (district)
double arrivalSpeed
(optional) The final speed of the vehicle (not used yet)
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
int insertionChecks
bitset of InsertionCheck
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.
std::string line
The vehicle's line (mainly for public transport)
int containerNumber
The static number of containers in the vehicle when it departs.
RouteIndexDefinition departEdgeProcedure
Information how the vehicle's initial edge shall be chosen.
static std::string getEdgeIDFromLane(const std::string laneID)
return edge id when given the lane ID
static int getIndexFromLane(const std::string laneID)
return lane index when given the lane ID
SUMOTime sawBlockedStoppingPlace(const MSStoppingPlace *stoppingPlace, bool local) const
Get the time the StoppingPlace was confirmed to be blocked.
void rememberStoppingPlaceScore(const MSStoppingPlace *stoppingPlace, const std::string &score)
score only needed when running with gui
void rememberBlockedStoppingPlace(const MSStoppingPlace *stoppingPlace, bool local)
Store the time the StoppingPlace was confirmed to be blocked.
int size() const
returns the number of existing substrings
std::string get(int pos) const
returns the item at the given position
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
static bool endsWith(const std::string &str, const std::string suffix)
Checks whether a given string ends with the suffix.
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
A wrapper for a Command function.
#define UNUSED_PARAMETER(x)
#define DEBUG_COND
TRACI_CONST int ROUTING_MODE_AGGREGATED
TRACI_CONST int ROUTING_MODE_DEFAULT
TRACI_CONST int ROUTING_MODE_AGGREGATED_CUSTOM
TRACI_CONST int ROUTING_MODE_IGNORE_TRANSIENT_PERMISSIONS