Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
libsumo/Vehicle.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2012-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/****************************************************************************/
19// C++ Vehicle API
20/****************************************************************************/
21#include <config.h>
22
35#include <microsim/MSStop.h>
36#include <microsim/MSVehicle.h>
41#include <microsim/MSNet.h>
42#include <microsim/MSEdge.h>
43#include <microsim/MSLane.h>
48#include <mesosim/MEVehicle.h>
50#include <libsumo/TraCIDefs.h>
52#include "Helper.h"
53#include "Route.h"
54#include "Polygon.h"
55#include "Vehicle.h"
56
57#define CALL_MICRO_FUN(veh, fun, mesoResult) ((dynamic_cast<MSVehicle*>(veh) == nullptr ? (mesoResult) : dynamic_cast<MSVehicle*>(veh)->fun))
58#define CALL_MESO_FUN(veh, fun, microResult) ((dynamic_cast<MEVehicle*>(veh) == nullptr ? (microResult) : dynamic_cast<MEVehicle*>(veh)->fun))
59
60// ===========================================================================
61// debug defines
62// ===========================================================================
63//#define DEBUG_NEIGHBORS
64//#define DEBUG_DYNAMIC_SHAPES
65//#define DEBUG_MOVEXY
66#define DEBUG_COND (veh->isSelected())
67
68
69
70namespace libsumo {
71// ===========================================================================
72// static member initializations
73// ===========================================================================
74SubscriptionResults Vehicle::mySubscriptionResults;
75ContextSubscriptionResults Vehicle::myContextSubscriptionResults;
76
77
78// ===========================================================================
79// static member definitions
80// ===========================================================================
81bool
82Vehicle::isVisible(const SUMOVehicle* veh) {
83 return veh->isOnRoad() || veh->isParking() || veh->wasRemoteControlled();
84}
85
86
87bool
88Vehicle::isOnInit(const std::string& vehID) {
90 return sumoVehicle == nullptr || sumoVehicle->getLane() == nullptr;
91}
92
93
94std::vector<std::string>
95Vehicle::getIDList() {
96 std::vector<std::string> ids;
98 for (MSVehicleControl::constVehIt i = c.loadedVehBegin(); i != c.loadedVehEnd(); ++i) {
99 if (isVisible((*i).second)) {
100 ids.push_back((*i).first);
101 }
102 }
103 return ids;
104}
105
106int
107Vehicle::getIDCount() {
108 return (int)getIDList().size();
109}
110
111
112double
113Vehicle::getSpeed(const std::string& vehID) {
114 MSBaseVehicle* veh = Helper::getVehicle(vehID);
115 return isVisible(veh) ? veh->getSpeed() : INVALID_DOUBLE_VALUE;
116}
117
118double
119Vehicle::getLateralSpeed(const std::string& vehID) {
120 MSBaseVehicle* veh = Helper::getVehicle(vehID);
121 return isVisible(veh) ? CALL_MICRO_FUN(veh, getLaneChangeModel().getSpeedLat(), 0) : INVALID_DOUBLE_VALUE;
122}
123
124
125double
126Vehicle::getAcceleration(const std::string& vehID) {
127 MSBaseVehicle* veh = Helper::getVehicle(vehID);
128 return isVisible(veh) ? CALL_MICRO_FUN(veh, getAcceleration(), 0) : INVALID_DOUBLE_VALUE;
129}
130
131
132double
133Vehicle::getSpeedWithoutTraCI(const std::string& vehID) {
134 MSBaseVehicle* veh = Helper::getVehicle(vehID);
135 return isVisible(veh) ? CALL_MICRO_FUN(veh, getSpeedWithoutTraciInfluence(), veh->getSpeed()) : INVALID_DOUBLE_VALUE;
136}
137
138
139TraCIPosition
140Vehicle::getPosition(const std::string& vehID, const bool includeZ) {
141 MSBaseVehicle* veh = Helper::getVehicle(vehID);
142 if (isVisible(veh)) {
143 return Helper::makeTraCIPosition(veh->getPosition(), includeZ);
144 }
145 return TraCIPosition();
146}
147
148
149TraCIPosition
150Vehicle::getPosition3D(const std::string& vehID) {
151 return getPosition(vehID, true);
152}
153
154
155double
156Vehicle::getAngle(const std::string& vehID) {
157 MSBaseVehicle* veh = Helper::getVehicle(vehID);
158 return isVisible(veh) ? GeomHelper::naviDegree(veh->getAngle()) : INVALID_DOUBLE_VALUE;
159}
160
161
162double
163Vehicle::getSlope(const std::string& vehID) {
164 MSBaseVehicle* veh = Helper::getVehicle(vehID);
165 return (veh->isOnRoad() || veh->isParking()) ? veh->getSlope() : INVALID_DOUBLE_VALUE;
166}
167
168
169std::string
170Vehicle::getRoadID(const std::string& vehID) {
171 MSBaseVehicle* veh = Helper::getVehicle(vehID);
172 return isVisible(veh) ? CALL_MICRO_FUN(veh, getLane()->getEdge().getID(), veh->getEdge()->getID()) : "";
173}
174
175
176std::string
177Vehicle::getLaneID(const std::string& vehID) {
178 MSBaseVehicle* veh = Helper::getVehicle(vehID);
179 return veh->isOnRoad() ? CALL_MICRO_FUN(veh, getLane()->getID(), "") : "";
180}
181
182
183std::string
184Vehicle::getShadowLaneID(const std::string& vehID) {
185 MSBaseVehicle* veh = Helper::getVehicle(vehID);
186 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
187 return (microVeh != nullptr && microVeh->isOnRoad()) ? (Named::getIDSecure(microVeh->getLaneChangeModel().getShadowLane(),"")) : "";
188}
189
190
191int
192Vehicle::getLaneIndex(const std::string& vehID) {
193 MSBaseVehicle* veh = Helper::getVehicle(vehID);
194 if (veh->isOnRoad()) {
195 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
196 if (microVeh != nullptr) {
197 return microVeh->getLane()->getIndex();
198 } else {
199 MEVehicle* mesoVeh = dynamic_cast<MEVehicle*>(veh);
200 return mesoVeh->getQueIndex();
201 }
202 } else {
203 return INVALID_INT_VALUE;
204 }
205}
206
207std::string
208Vehicle::getSegmentID(const std::string& vehID) {
209 MSBaseVehicle* veh = Helper::getVehicle(vehID);
210 return veh->isOnRoad() ? CALL_MESO_FUN(veh, getSegment()->getID(), "") : "";
211}
212
213int
214Vehicle::getSegmentIndex(const std::string& vehID) {
215 MSBaseVehicle* veh = Helper::getVehicle(vehID);
216 return veh->isOnRoad() ? CALL_MESO_FUN(veh, getSegment()->getIndex(), INVALID_INT_VALUE) : INVALID_INT_VALUE;
217}
218
219std::string
220Vehicle::getTypeID(const std::string& vehID) {
221 return Helper::getVehicleType(vehID).getID();
222}
223
224
225std::string
226Vehicle::getRouteID(const std::string& vehID) {
227 return Helper::getVehicle(vehID)->getRoute().getID();
228}
229
230
231double
232Vehicle::getDeparture(const std::string& vehID) {
233 MSBaseVehicle* veh = Helper::getVehicle(vehID);
235}
236
237
238double
239Vehicle::getDepartDelay(const std::string& vehID) {
240 return STEPS2TIME(Helper::getVehicle(vehID)->getDepartDelay());
241}
242
243
244int
245Vehicle::getRouteIndex(const std::string& vehID) {
246 MSBaseVehicle* veh = Helper::getVehicle(vehID);
247 return veh->hasDeparted() ? veh->getRoutePosition() : INVALID_INT_VALUE;
248}
249
250
251TraCIColor
252Vehicle::getColor(const std::string& vehID) {
253 return Helper::makeTraCIColor(Helper::getVehicle(vehID)->getParameter().color);
254}
255
256double
257Vehicle::getLanePosition(const std::string& vehID) {
258 MSBaseVehicle* veh = Helper::getVehicle(vehID);
259 return (veh->isOnRoad() || veh->isParking()) ? veh->getPositionOnLane() : INVALID_DOUBLE_VALUE;
260}
261
262double
263Vehicle::getArrivalPos(const std::string& vehID) {
264 return Helper::getVehicle(vehID)->getArrivalPos();
265}
266
267double
268Vehicle::getLateralLanePosition(const std::string& vehID) {
269 MSBaseVehicle* veh = Helper::getVehicle(vehID);
270 return veh->isOnRoad() ? CALL_MICRO_FUN(veh, getLateralPositionOnLane(), 0) : INVALID_DOUBLE_VALUE;
271}
272
273double
274Vehicle::getCO2Emission(const std::string& vehID) {
275 MSBaseVehicle* veh = Helper::getVehicle(vehID);
276 return isVisible(veh) ? veh->getEmissions<PollutantsInterface::CO2>() : INVALID_DOUBLE_VALUE;
277}
278
279double
280Vehicle::getCOEmission(const std::string& vehID) {
281 MSBaseVehicle* veh = Helper::getVehicle(vehID);
282 return isVisible(veh) ? veh->getEmissions<PollutantsInterface::CO>() : INVALID_DOUBLE_VALUE;
283}
284
285double
286Vehicle::getHCEmission(const std::string& vehID) {
287 MSBaseVehicle* veh = Helper::getVehicle(vehID);
288 return isVisible(veh) ? veh->getEmissions<PollutantsInterface::HC>() : INVALID_DOUBLE_VALUE;
289}
290
291double
292Vehicle::getPMxEmission(const std::string& vehID) {
293 MSBaseVehicle* veh = Helper::getVehicle(vehID);
294 return isVisible(veh) ? veh->getEmissions<PollutantsInterface::PM_X>() : INVALID_DOUBLE_VALUE;
295}
296
297double
298Vehicle::getNOxEmission(const std::string& vehID) {
299 MSBaseVehicle* veh = Helper::getVehicle(vehID);
300 return isVisible(veh) ? veh->getEmissions<PollutantsInterface::NO_X>() : INVALID_DOUBLE_VALUE;
301}
302
303double
304Vehicle::getFuelConsumption(const std::string& vehID) {
305 MSBaseVehicle* veh = Helper::getVehicle(vehID);
306 return isVisible(veh) ? veh->getEmissions<PollutantsInterface::FUEL>() : INVALID_DOUBLE_VALUE;
307}
308
309double
310Vehicle::getNoiseEmission(const std::string& vehID) {
311 MSBaseVehicle* veh = Helper::getVehicle(vehID);
312 return isVisible(veh) ? veh->getHarmonoise_NoiseEmissions() : INVALID_DOUBLE_VALUE;
313}
314
315double
316Vehicle::getElectricityConsumption(const std::string& vehID) {
317 MSBaseVehicle* veh = Helper::getVehicle(vehID);
318 return isVisible(veh) ? veh->getEmissions<PollutantsInterface::ELEC>() : INVALID_DOUBLE_VALUE;
319}
320
321int
322Vehicle::getPersonNumber(const std::string& vehID) {
323 return Helper::getVehicle(vehID)->getPersonNumber();
324}
325
326int
327Vehicle::getPersonCapacity(const std::string& vehID) {
329}
330
331
332double
333Vehicle::getBoardingDuration(const std::string& vehID) {
334 return STEPS2TIME(Helper::getVehicleType(vehID).getLoadingDuration(true));
335}
336
337
338std::vector<std::string>
339Vehicle::getPersonIDList(const std::string& vehID) {
340 return Helper::getVehicle(vehID)->getPersonIDList();
341}
342
343std::pair<std::string, double>
344Vehicle::getLeader(const std::string& vehID, double dist) {
345 MSBaseVehicle* veh = Helper::getVehicle(vehID);
346 if (veh->isOnRoad()) {
347 std::pair<const MSVehicle* const, double> leaderInfo = veh->getLeader(dist, false);
348 const std::string leaderID = leaderInfo.first != nullptr ? leaderInfo.first->getID() : "";
349 double gap = leaderInfo.second;
350 if (leaderInfo.first != nullptr
351 && leaderInfo.first->getLane() != nullptr
352 && leaderInfo.first->getLane()->isInternal()
353 && veh->getLane() != nullptr
354 && (!veh->getLane()->isInternal()
355 || (veh->getLane()->getLinkCont().front()->getIndex() != leaderInfo.first->getLane()->getLinkCont().front()->getIndex()))) {
356 // leader is a linkLeader (see MSLink::getLeaderInfo)
357 // avoid internal gap values which may be negative (or -inf)
358 gap = MAX2(0.0, gap);
359 }
360 return std::make_pair(leaderID, gap);
361 } else {
362 return std::make_pair("", -1);
363 }
364}
365
366
367std::pair<std::string, double>
368Vehicle::getFollower(const std::string& vehID, double dist) {
369 MSBaseVehicle* veh = Helper::getVehicle(vehID);
370 if (veh->isOnRoad()) {
371 std::pair<const MSVehicle* const, double> leaderInfo = veh->getFollower(dist);
372 return std::make_pair(
373 leaderInfo.first != nullptr ? leaderInfo.first->getID() : "",
374 leaderInfo.second);
375 } else {
376 return std::make_pair("", -1);
377 }
378}
379
380
381std::vector<TraCIJunctionFoe>
382Vehicle::getJunctionFoes(const std::string& vehID, double dist) {
383 std::vector<TraCIJunctionFoe> result;
384 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
385 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
386 if (veh == nullptr) {
387 WRITE_WARNING("getJunctionFoes not applicable for meso");
388 } else if (veh->isOnRoad()) {
389 if (dist == 0) {
390 dist = veh->getCarFollowModel().brakeGap(veh->getSpeed()) + veh->getVehicleType().getMinGap();
391 }
392 const std::vector<const MSLane*> internalLanes;
393 // distance to the end of the lane
394 double curDist = -veh->getPositionOnLane();
395 for (const MSLane* lane : veh->getUpcomingLanesUntil(dist)) {
396 curDist += lane->getLength();
397 if (lane->isInternal()) {
398 const MSLink* exitLink = lane->getLinkCont().front();
399 int foeIndex = 0;
400 const std::vector<MSLink::ConflictInfo>& conflicts = exitLink->getConflicts();
401 const MSJunctionLogic* logic = exitLink->getJunction()->getLogic();
402 for (const MSLane* foeLane : exitLink->getFoeLanes()) {
403 const MSLink::ConflictInfo& ci = conflicts[foeIndex];
405 continue;
406 }
407 const double distBehindCrossing = ci.lengthBehindCrossing;
408 const MSLink* foeExitLink = foeLane->getLinkCont().front();
409 const double distToCrossing = curDist - distBehindCrossing;
410 const double foeDistBehindCrossing = ci.getFoeLengthBehindCrossing(foeExitLink);
411 for (auto item : foeExitLink->getApproaching()) {
412 const SUMOVehicle* foe = item.first;
413 TraCIJunctionFoe jf;
414 jf.foeId = foe->getID();
415 jf.egoDist = distToCrossing;
416 // approach information is from the start of the previous step
417 // but the foe vehicle then moved within that steop
418 const double prevFoeDist = SPEED2DIST(MSGlobals::gSemiImplicitEulerUpdate
419 ? foe->getSpeed()
420 : (foe->getSpeed() + foe->getPreviousSpeed()) / 2);
421 jf.foeDist = item.second.dist - foeDistBehindCrossing - prevFoeDist;
422 jf.egoExitDist = jf.egoDist + ci.conflictSize;
423 jf.foeExitDist = jf.foeDist + ci.getFoeConflictSize(foeExitLink);
424 jf.egoLane = lane->getID();
425 jf.foeLane = foeLane->getID();
426 jf.egoResponse = logic->getResponseFor(exitLink->getIndex()).test(foeExitLink->getIndex());
427 jf.foeResponse = logic->getResponseFor(foeExitLink->getIndex()).test(exitLink->getIndex());
428 result.push_back(jf);
429 }
430 foeIndex++;
431 }
432 }
433 }
434 }
435 return result;
436}
437
438
439double
440Vehicle::getWaitingTime(const std::string& vehID) {
441 return STEPS2TIME(Helper::getVehicle(vehID)->getWaitingTime());
442}
443
444
445double
446Vehicle::getAccumulatedWaitingTime(const std::string& vehID) {
447 MSBaseVehicle* veh = Helper::getVehicle(vehID);
448 return CALL_MICRO_FUN(veh, getAccumulatedWaitingSeconds(), INVALID_DOUBLE_VALUE);
449}
450
451
452double
453Vehicle::getAdaptedTraveltime(const std::string& vehID, double time, const std::string& edgeID) {
454 MSEdge* edge = Helper::getEdge(edgeID);
455 double value = INVALID_DOUBLE_VALUE;
457 return value;
458}
459
460
461double
462Vehicle::getEffort(const std::string& vehID, double time, const std::string& edgeID) {
463 MSEdge* edge = Helper::getEdge(edgeID);
464 double value = INVALID_DOUBLE_VALUE;
466 return value;
467}
468
469
470bool
471Vehicle::isRouteValid(const std::string& vehID) {
472 std::string msg;
473 return Helper::getVehicle(vehID)->hasValidRoute(msg);
474}
475
476
477std::vector<std::string>
478Vehicle::getRoute(const std::string& vehID) {
479 std::vector<std::string> result;
480 MSBaseVehicle* veh = Helper::getVehicle(vehID);
481 const MSRoute& r = veh->getRoute();
482 for (MSRouteIterator i = r.begin(); i != r.end(); ++i) {
483 result.push_back((*i)->getID());
484 }
485 return result;
486}
487
488
489int
490Vehicle::getSignals(const std::string& vehID) {
491 MSBaseVehicle* veh = Helper::getVehicle(vehID);
492 return CALL_MICRO_FUN(veh, getSignals(), MSVehicle::VEH_SIGNAL_NONE);
493}
494
495
496std::vector<TraCIBestLanesData>
497Vehicle::getBestLanes(const std::string& vehID) {
498 std::vector<TraCIBestLanesData> result;
499 MSVehicle* veh = dynamic_cast<MSVehicle*>(Helper::getVehicle(vehID));
500 if (veh != nullptr && veh->isOnRoad()) {
501 for (const MSVehicle::LaneQ& lq : veh->getBestLanes()) {
502 TraCIBestLanesData bld;
503 bld.laneID = lq.lane->getID();
504 bld.length = lq.length;
505 bld.occupation = lq.nextOccupation;
506 bld.bestLaneOffset = lq.bestLaneOffset;
507 bld.allowsContinuation = lq.allowsContinuation;
508 for (const MSLane* const lane : lq.bestContinuations) {
509 if (lane != nullptr) {
510 bld.continuationLanes.push_back(lane->getID());
511 }
512 }
513 result.emplace_back(bld);
514 }
515 }
516 return result;
517}
518
519
520std::vector<TraCINextTLSData>
521Vehicle::getNextTLS(const std::string& vehID) {
522 std::vector<TraCINextTLSData> result;
523 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
524 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
525 if (veh != nullptr) {
526 int view = 1;
527 double seen = veh->getEdge()->getLength() - veh->getPositionOnLane();
528 if (vehicle->isOnRoad()) {
529 const MSLane* lane = veh->getLane();
530 const std::vector<MSLane*>& bestLaneConts = veh->getBestLanesContinuation(lane);
531 seen = lane->getLength() - veh->getPositionOnLane();
532 std::vector<MSLink*>::const_iterator linkIt = MSLane::succLinkSec(*veh, view, *lane, bestLaneConts);
533 while (!lane->isLinkEnd(linkIt)) {
534 if (!lane->getEdge().isInternal()) {
535 if ((*linkIt)->isTLSControlled()) {
536 TraCINextTLSData ntd;
537 ntd.id = (*linkIt)->getTLLogic()->getID();
538 ntd.tlIndex = (*linkIt)->getTLIndex();
539 ntd.dist = seen;
540 ntd.state = (char)(*linkIt)->getState();
541 result.push_back(ntd);
542 }
543 }
544 lane = (*linkIt)->getViaLaneOrLane();
545 if (!lane->getEdge().isInternal()) {
546 view++;
547 }
548 seen += lane->getLength();
549 linkIt = MSLane::succLinkSec(*veh, view, *lane, bestLaneConts);
550 }
551 }
552 // consider edges beyond bestLanes
553 const int remainingEdges = (int)(veh->getRoute().end() - veh->getCurrentRouteEdge()) - view;
554 //std::cout << SIMTIME << " remainingEdges=" << remainingEdges << " seen=" << seen << " view=" << view << " best=" << toString(bestLaneConts) << "\n";
555 for (int i = 0; i < remainingEdges; i++) {
556 const MSEdge* prev = *(veh->getCurrentRouteEdge() + view + i - 1);
557 const MSEdge* next = *(veh->getCurrentRouteEdge() + view + i);
558 const std::vector<MSLane*>* allowed = prev->allowedLanes(*next, veh->getVClass());
559 if (allowed != nullptr && allowed->size() != 0) {
560 for (const MSLink* const link : allowed->front()->getLinkCont()) {
561 if (&link->getLane()->getEdge() == next) {
562 if (link->isTLSControlled()) {
563 TraCINextTLSData ntd;
564 ntd.id = link->getTLLogic()->getID();
565 ntd.tlIndex = link->getTLIndex();
566 ntd.dist = seen;
567 ntd.state = (char)link->getState();
568 result.push_back(ntd);
569 }
570 seen += next->getLength() + link->getInternalLengthsAfter();
571 break;
572 }
573 }
574 } else {
575 // invalid route, cannot determine nextTLS
576 break;
577 }
578 }
579
580 } else {
581 WRITE_WARNING("getNextTLS not yet implemented for meso");
582 }
583 return result;
584}
585
586std::vector<TraCINextStopData>
587Vehicle::getNextStops(const std::string& vehID) {
588 return getStops(vehID, 0);
589}
590
591std::vector<libsumo::TraCIConnection>
592Vehicle::getNextLinks(const std::string& vehID) {
593 std::vector<libsumo::TraCIConnection> result;
594 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
595 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
596 if (!vehicle->isOnRoad()) {
597 return result;
598 }
599 if (veh != nullptr) {
600 const MSLane* lane = veh->getLane();
601 const std::vector<MSLane*>& bestLaneConts = veh->getBestLanesContinuation(lane);
602 int view = 1;
603 const SUMOTime currTime = MSNet::getInstance()->getCurrentTimeStep();
604 std::vector<MSLink*>::const_iterator linkIt = MSLane::succLinkSec(*veh, view, *lane, bestLaneConts);
605 while (!lane->isLinkEnd(linkIt)) {
606 if (!lane->getEdge().isInternal()) {
607 const MSLink* link = (*linkIt);
608 const std::string approachedLane = link->getLane() != nullptr ? link->getLane()->getID() : "";
609 const bool hasPrio = link->havePriority();
610 const double speed = MIN2(lane->getSpeedLimit(), link->getLane()->getSpeedLimit());
611 const bool isOpen = link->opened(currTime, speed, speed, veh->getLength(),
613 veh->getWaitingTime(), veh->getLateralPositionOnLane(), nullptr, false, veh);
614 const bool hasFoe = link->hasApproachingFoe(currTime, currTime, 0, SUMOVTypeParameter::getDefaultDecel());
615 const std::string approachedInternal = link->getViaLane() != nullptr ? link->getViaLane()->getID() : "";
616 const std::string state = SUMOXMLDefinitions::LinkStates.getString(link->getState());
617 const std::string direction = SUMOXMLDefinitions::LinkDirections.getString(link->getDirection());
618 const double length = link->getLength();
619 result.push_back(TraCIConnection(approachedLane, hasPrio, isOpen, hasFoe, approachedInternal, state, direction, length));
620 }
621 lane = (*linkIt)->getViaLaneOrLane();
622 if (!lane->getEdge().isInternal()) {
623 view++;
624 }
625 linkIt = MSLane::succLinkSec(*veh, view, *lane, bestLaneConts);
626 }
627 // consider edges beyond bestLanes
628 const int remainingEdges = (int)(veh->getRoute().end() - veh->getCurrentRouteEdge()) - view;
629 for (int i = 0; i < remainingEdges; i++) {
630 const MSEdge* prev = *(veh->getCurrentRouteEdge() + view + i - 1);
631 const MSEdge* next = *(veh->getCurrentRouteEdge() + view + i);
632 const std::vector<MSLane*>* allowed = prev->allowedLanes(*next, veh->getVClass());
633 if (allowed != nullptr && allowed->size() != 0) {
634 for (const MSLink* const link : allowed->front()->getLinkCont()) {
635 if (&link->getLane()->getEdge() == next) {
636 const std::string approachedLane = link->getLane() != nullptr ? link->getLane()->getID() : "";
637 const bool hasPrio = link->havePriority();
638 const double speed = MIN2(lane->getSpeedLimit(), link->getLane()->getSpeedLimit());
639 const bool isOpen = link->opened(currTime, speed, speed, veh->getLength(),
641 veh->getWaitingTime(), veh->getLateralPositionOnLane(), nullptr, false, veh);
642 const bool hasFoe = link->hasApproachingFoe(currTime, currTime, 0, SUMOVTypeParameter::getDefaultDecel());
643 const std::string approachedInternal = link->getViaLane() != nullptr ? link->getViaLane()->getID() : "";
644 const std::string state = SUMOXMLDefinitions::LinkStates.getString(link->getState());
645 const std::string direction = SUMOXMLDefinitions::LinkDirections.getString(link->getDirection());
646 const double length = link->getLength();
647 result.push_back(TraCIConnection(approachedLane, hasPrio, isOpen, hasFoe, approachedInternal, state, direction, length));
648 }
649 }
650 } else {
651 // invalid route, cannot determine nextTLS
652 break;
653 }
654 }
655 } else {
656 WRITE_WARNING("getNextLinks not yet implemented for meso");
657 }
658 return result;
659}
660
661std::vector<TraCINextStopData>
662Vehicle::getStops(const std::string& vehID, int limit) {
663 std::vector<TraCINextStopData> result;
664 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
665 if (limit < 0) {
666 // return past stops up to the given limit
667 const StopParVector& pastStops = vehicle->getPastStops();
668 const int n = (int)pastStops.size();
669 for (int i = MAX2(0, n + limit); i < n; i++) {
670 result.push_back(Helper::buildStopData(pastStops[i]));
671 }
672 } else {
673 for (const MSStop& stop : vehicle->getStops()) {
674 if (!stop.pars.collision) {
675 TraCINextStopData nsd = Helper::buildStopData(stop.pars);
676 nsd.duration = STEPS2TIME(stop.duration);
677 result.push_back(nsd);
678 if (limit > 0 && (int)result.size() >= limit) {
679 break;
680 }
681 }
682 }
683 }
684 return result;
685}
686
687
688int
689Vehicle::getStopState(const std::string& vehID) {
690 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
691 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
692 if (veh == nullptr) {
693 WRITE_WARNING("getStopState not yet implemented for meso");
694 return 0;
695 }
696 int result = 0;
697 if (veh->isStopped()) {
698 const MSStop& stop = veh->getNextStop();
699 result = stop.getStateFlagsOld();
700 }
701 return result;
702}
703
704
705double
706Vehicle::getDistance(const std::string& vehID) {
707 MSBaseVehicle* veh = Helper::getVehicle(vehID);
708 if (veh->hasDeparted()) {
709 return veh->getOdometer();
710 } else {
712 }
713}
714
715
716double
717Vehicle::getDrivingDistance(const std::string& vehID, const std::string& edgeID, double pos, int laneIndex) {
718 MSBaseVehicle* veh = Helper::getVehicle(vehID);
719 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
720 if (veh->isOnRoad()) {
721 const MSLane* lane = microVeh != nullptr ? veh->getLane() : veh->getEdge()->getLanes()[0];
722 double distance = veh->getRoute().getDistanceBetween(veh->getPositionOnLane(), pos,
723 lane, Helper::getLaneChecking(edgeID, laneIndex, pos), veh->getRoutePosition());
724 if (distance == std::numeric_limits<double>::max()) {
726 }
727 return distance;
728 } else {
730 }
731}
732
733
734double
735Vehicle::getDrivingDistance2D(const std::string& vehID, double x, double y) {
736 MSBaseVehicle* veh = Helper::getVehicle(vehID);
737 if (veh == nullptr) {
739 }
740 if (veh->isOnRoad()) {
741 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
742 const MSLane* lane = microVeh != nullptr ? veh->getLane() : veh->getEdge()->getLanes()[0];
743 std::pair<MSLane*, double> roadPos = Helper::convertCartesianToRoadMap(Position(x, y), veh->getVehicleType().getVehicleClass());
744 double distance = veh->getRoute().getDistanceBetween(veh->getPositionOnLane(), roadPos.second,
745 lane, roadPos.first, veh->getRoutePosition());
746 if (distance == std::numeric_limits<double>::max()) {
748 }
749 return distance;
750 } else {
752 }
753}
754
755
756double
757Vehicle::getReferenceDistance(const std::string& vehID) {
758 MSBaseVehicle* veh = Helper::getVehicle(vehID);
759 if (veh->hasDeparted()) {
760 double lanePos = veh->getPositionOnLane();
761 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
762 if (microVeh != nullptr && microVeh->getLane()->isInternal()) {
763 lanePos = microVeh->getRoute().getDistanceBetween(0., lanePos, microVeh->getEdge()->getLanes()[0],
764 microVeh->getLane(), microVeh->getRoutePosition());
765 }
766 return veh->getEdge()->getDistanceAt(lanePos);
767 } else {
769 }
770}
771
772
773double
774Vehicle::getAllowedSpeed(const std::string& vehID) {
775 MSBaseVehicle* veh = Helper::getVehicle(vehID);
776 return veh->isOnRoad() ? CALL_MICRO_FUN(veh, getLane()->getVehicleMaxSpeed(veh), veh->getEdge()->getVehicleMaxSpeed(veh)) : INVALID_DOUBLE_VALUE;
777}
778
779
780double
781Vehicle::getSpeedFactor(const std::string& vehID) {
783}
784
785
786int
787Vehicle::getSpeedMode(const std::string& vehID) {
788 MSBaseVehicle* veh = Helper::getVehicle(vehID);
789 return CALL_MICRO_FUN(veh, getInfluencer().getSpeedMode(), INVALID_INT_VALUE);
790}
791
792
793int
794Vehicle::getLaneChangeMode(const std::string& vehID) {
795 MSBaseVehicle* veh = Helper::getVehicle(vehID);
796 return CALL_MICRO_FUN(veh, getInfluencer().getLaneChangeMode(), INVALID_INT_VALUE);
797}
798
799
800int
801Vehicle::getRoutingMode(const std::string& vehID) {
802 return Helper::getVehicle(vehID)->getRoutingMode();
803}
804
805
806std::string
807Vehicle::getLine(const std::string& vehID) {
808 return Helper::getVehicle(vehID)->getParameter().line;
809}
810
811
812std::vector<std::string>
813Vehicle::getVia(const std::string& vehID) {
814 return Helper::getVehicle(vehID)->getParameter().via;
815}
816
817
818std::pair<int, int>
819Vehicle::getLaneChangeState(const std::string& vehID, int direction) {
820 MSBaseVehicle* veh = Helper::getVehicle(vehID);
821 auto undefined = std::make_pair((int)LCA_UNKNOWN, (int)LCA_UNKNOWN);
822 return veh->isOnRoad() ? CALL_MICRO_FUN(veh, getLaneChangeModel().getSavedState(direction), undefined) : undefined;
823}
824
825
826std::string
827Vehicle::getParameter(const std::string& vehID, const std::string& key) {
828 MSBaseVehicle* veh = Helper::getVehicle(vehID);
829 std::string error;
830 std::string result = veh->getPrefixedParameter(key, error);
831 if (error != "") {
832 throw TraCIException(error);
833 }
834 return result;
835}
836
837
839
840
841std::vector<std::pair<std::string, double> >
842Vehicle::getNeighbors(const std::string& vehID, const int mode) {
843 int dir = (1 & mode) != 0 ? -1 : 1;
844 bool queryLeaders = (2 & mode) != 0;
845 bool blockersOnly = (4 & mode) != 0;
846 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
847 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
848 std::vector<std::pair<std::string, double> > result;
849 if (veh == nullptr) {
850 return result;
851 }
852#ifdef DEBUG_NEIGHBORS
853 if (DEBUG_COND) {
854 std::cout << "getNeighbors() for veh '" << vehID << "': dir=" << dir
855 << ", queryLeaders=" << queryLeaders
856 << ", blockersOnly=" << blockersOnly << std::endl;
857 }
858#endif
859 if (veh->getLaneChangeModel().isOpposite()) {
860 // getParallelLane works relative to lane forward direction
861 dir *= -1;
862 }
863
864 MSLane* targetLane = veh->getLane()->getParallelLane(dir);
865 if (targetLane == nullptr) {
866 return result;
867 }
868 // need to recompute leaders and followers (#8119)
869 const bool opposite = &veh->getLane()->getEdge() != &targetLane->getEdge();
870 MSLeaderDistanceInfo neighbors(targetLane->getWidth(), nullptr, 0.);
871 if (queryLeaders) {
872 if (opposite) {
873 double pos = targetLane->getOppositePos(veh->getPositionOnLane());
874 neighbors = targetLane->getFollowersOnConsecutive(veh, pos, true);
875 } else {
876 targetLane->addLeaders(veh, veh->getPositionOnLane(), neighbors);
877 }
878 } else {
879 if (opposite) {
880 double pos = targetLane->getOppositePos(veh->getPositionOnLane());
881 targetLane->addLeaders(veh, pos, neighbors);
882 neighbors.fixOppositeGaps(true);
883 } else {
884 neighbors = targetLane->getFollowersOnConsecutive(veh, veh->getBackPositionOnLane(), true);
885 }
886 }
887 if (blockersOnly) {
888 // filter out vehicles that aren't blocking
889 MSLeaderDistanceInfo blockers(targetLane->getWidth(), nullptr, 0.);
890 for (int i = 0; i < neighbors.numSublanes(); i++) {
891 CLeaderDist n = neighbors[i];
892 if (n.first != nullptr) {
893 const MSVehicle* follower = veh;
894 const MSVehicle* leader = n.first;
895 if (!queryLeaders) {
896 std::swap(follower, leader);
897 }
898 const double secureGap = (follower->getCarFollowModel().getSecureGap(
899 follower, leader, follower->getSpeed(), leader->getSpeed(), leader->getCarFollowModel().getMaxDecel())
900 * follower->getLaneChangeModel().getSafetyFactor());
901 if (n.second < secureGap) {
902 blockers.addLeader(n.first, n.second, 0, i);
903 }
904 }
905 }
906 neighbors = blockers;
907 }
908
909 if (neighbors.hasVehicles()) {
910 for (int i = 0; i < neighbors.numSublanes(); i++) {
911 CLeaderDist n = neighbors[i];
912 if (n.first != nullptr &&
913 // avoid duplicates
914 (result.size() == 0 || result.back().first != n.first->getID())) {
915 result.push_back(std::make_pair(n.first->getID(), n.second));
916 }
917 }
918 }
919 return result;
920}
921
922
923double
924Vehicle::getFollowSpeed(const std::string& vehID, double speed, double gap, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) {
925 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
926 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
927 if (veh == nullptr) {
928 WRITE_ERROR("getFollowSpeed not applicable for meso");
930 }
931 MSVehicle* leader = dynamic_cast<MSVehicle*>(MSNet::getInstance()->getVehicleControl().getVehicle(leaderID));
932 return veh->getCarFollowModel().followSpeed(veh, speed, gap, leaderSpeed, leaderMaxDecel, leader, MSCFModel::CalcReason::FUTURE);
933}
934
935
936double
937Vehicle::getSecureGap(const std::string& vehID, double speed, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) {
938 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
939 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
940 if (veh == nullptr) {
941 WRITE_ERROR("getSecureGap not applicable for meso");
943 }
944 MSVehicle* leader = dynamic_cast<MSVehicle*>(MSNet::getInstance()->getVehicleControl().getVehicle(leaderID));
945 return veh->getCarFollowModel().getSecureGap(veh, leader, speed, leaderSpeed, leaderMaxDecel);
946}
947
948
949double
950Vehicle::getStopSpeed(const std::string& vehID, const double speed, double gap) {
951 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
952 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
953 if (veh == nullptr) {
954 WRITE_ERROR("getStopSpeed not applicable for meso");
956 }
957 return veh->getCarFollowModel().stopSpeed(veh, speed, gap, MSCFModel::CalcReason::FUTURE);
958}
959
960double
961Vehicle::getStopDelay(const std::string& vehID) {
962 return Helper::getVehicle(vehID)->getStopDelay();
963}
964
965
966double
967Vehicle::getImpatience(const std::string& vehID) {
968 return Helper::getVehicle(vehID)->getImpatience();
969}
970
971
972double
973Vehicle::getStopArrivalDelay(const std::string& vehID) {
974 double result = Helper::getVehicle(vehID)->getStopArrivalDelay();
975 if (result == INVALID_DOUBLE) {
977 } else {
978 return result;
979 }
980}
981
982double
983Vehicle::getTimeLoss(const std::string& vehID) {
984 return Helper::getVehicle(vehID)->getTimeLossSeconds();
985}
986
987std::vector<std::string>
988Vehicle::getTaxiFleet(int taxiState) {
989 std::vector<std::string> result;
990 for (MSDevice_Taxi* taxi : MSDevice_Taxi::getFleet()) {
991 if (taxi->getHolder().hasDeparted()) {
992 if (taxiState == -1
993 || (taxiState == 0 && taxi->getState() == 0)
994 || (taxiState != 0 && (taxi->getState() & taxiState) == taxiState)) {
995 result.push_back(taxi->getHolder().getID());
996 }
997 }
998 }
999 return result;
1000}
1001
1002std::vector<std::string>
1003Vehicle::getLoadedIDList() {
1004 std::vector<std::string> ids;
1006 for (MSVehicleControl::constVehIt i = c.loadedVehBegin(); i != c.loadedVehEnd(); ++i) {
1007 ids.push_back(i->first);
1008 }
1009 return ids;
1010}
1011
1012std::vector<std::string>
1013Vehicle::getTeleportingIDList() {
1014 std::vector<std::string> ids;
1016 for (MSVehicleControl::constVehIt i = c.loadedVehBegin(); i != c.loadedVehEnd(); ++i) {
1017 SUMOVehicle* veh = i->second;
1018 if (veh->hasDeparted() && !isVisible(veh)) {
1019 ids.push_back(veh->getID());
1020 }
1021 }
1022 return ids;
1023}
1024
1025std::string
1026Vehicle::getEmissionClass(const std::string& vehID) {
1027 return PollutantsInterface::getName(Helper::getVehicleType(vehID).getEmissionClass());
1028}
1029
1030std::string
1031Vehicle::getShapeClass(const std::string& vehID) {
1032 return getVehicleShapeName(Helper::getVehicleType(vehID).getGuiShape());
1033}
1034
1035
1036double
1037Vehicle::getLength(const std::string& vehID) {
1038 return Helper::getVehicleType(vehID).getLength();
1039}
1040
1041
1042double
1043Vehicle::getAccel(const std::string& vehID) {
1045}
1046
1047
1048double
1049Vehicle::getDecel(const std::string& vehID) {
1051}
1052
1053
1054double Vehicle::getEmergencyDecel(const std::string& vehID) {
1056}
1057
1058
1059double Vehicle::getApparentDecel(const std::string& vehID) {
1061}
1062
1063
1064double Vehicle::getActionStepLength(const std::string& vehID) {
1066}
1067
1068
1069double Vehicle::getLastActionTime(const std::string& vehID) {
1070 MSBaseVehicle* veh = Helper::getVehicle(vehID);
1071 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
1072 if (microVeh != nullptr) {
1073 return STEPS2TIME(microVeh->getLastActionTime());
1074 } else {
1075 MEVehicle* mesoVeh = dynamic_cast<MEVehicle*>(veh);
1076 return STEPS2TIME(mesoVeh->getEventTime());
1077 }
1078}
1079
1080
1081double
1082Vehicle::getTau(const std::string& vehID) {
1084}
1085
1086
1087double
1088Vehicle::getImperfection(const std::string& vehID) {
1090}
1091
1092
1093double
1094Vehicle::getSpeedDeviation(const std::string& vehID) {
1096}
1097
1098
1099std::string
1100Vehicle::getVehicleClass(const std::string& vehID) {
1101 return toString(Helper::getVehicleType(vehID).getVehicleClass());
1102}
1103
1104
1105double
1106Vehicle::getMinGap(const std::string& vehID) {
1107 return Helper::getVehicleType(vehID).getMinGap();
1108}
1109
1110
1111double
1112Vehicle::getMinGapLat(const std::string& vehID) {
1113 try {
1114 return StringUtils::toDouble(getParameter(vehID, "laneChangeModel.minGapLat"));
1115 } catch (const TraCIException&) {
1116 // legacy behavior
1117 return Helper::getVehicleType(vehID).getMinGapLat();
1118 }
1119}
1120
1121
1122double
1123Vehicle::getMaxSpeed(const std::string& vehID) {
1124 return Helper::getVehicleType(vehID).getMaxSpeed();
1125}
1126
1127
1128double
1129Vehicle::getMaxSpeedLat(const std::string& vehID) {
1130 return Helper::getVehicleType(vehID).getMaxSpeedLat();
1131}
1132
1133
1134std::string
1135Vehicle::getLateralAlignment(const std::string& vehID) {
1136 return toString(Helper::getVehicleType(vehID).getPreferredLateralAlignment());
1137}
1138
1139
1140double
1141Vehicle::getWidth(const std::string& vehID) {
1142 return Helper::getVehicleType(vehID).getWidth();
1143}
1144
1145
1146double
1147Vehicle::getHeight(const std::string& vehID) {
1148 return Helper::getVehicleType(vehID).getHeight();
1149}
1150
1151
1152double
1153Vehicle::getMass(const std::string& vehID) {
1154 return Helper::getVehicleType(vehID).getMass();
1155}
1156
1157
1158void
1159Vehicle::setStop(const std::string& vehID,
1160 const std::string& edgeID,
1161 double pos,
1162 int laneIndex,
1163 double duration,
1164 int flags,
1165 double startPos,
1166 double until) {
1167 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1169 pos, laneIndex, startPos, flags, duration, until);
1170 std::string error;
1171 if (!vehicle->addTraciStop(stopPars, error)) {
1172 throw TraCIException(error);
1173 }
1174}
1175
1176
1177void
1178Vehicle::replaceStop(const std::string& vehID,
1179 int nextStopIndex,
1180 const std::string& edgeID,
1181 double pos,
1182 int laneIndex,
1183 double duration,
1184 int flags,
1185 double startPos,
1186 double until,
1187 int teleport) {
1188 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1189 std::string error;
1190 if (edgeID == "") {
1191 // only remove stop
1192 const bool ok = vehicle->abortNextStop(nextStopIndex);
1193 if (teleport != 0) {
1194 if (!vehicle->rerouteBetweenStops(nextStopIndex, "traci:replaceStop", (teleport & 1), error)) {
1195 throw TraCIException("Stop replacement failed for vehicle '" + vehID + "' (" + error + ").");
1196 }
1197 } else {
1198 MSVehicle* msVeh = dynamic_cast<MSVehicle*>(vehicle);
1199 if (msVeh->getLane() != nullptr) {
1200 msVeh->updateBestLanes(true);
1201 }
1202 }
1203 if (!ok) {
1204 throw TraCIException("Stop replacement failed for vehicle '" + vehID + "' (invalid nextStopIndex).");
1205 }
1206 } else {
1208 pos, laneIndex, startPos, flags, duration, until);
1209
1210 if (!vehicle->replaceStop(nextStopIndex, stopPars, "traci:replaceStop", teleport != 0, error)) {
1211 throw TraCIException("Stop replacement failed for vehicle '" + vehID + "' (" + error + ").");
1212 }
1213 }
1214}
1215
1216
1217void
1218Vehicle::insertStop(const std::string& vehID,
1219 int nextStopIndex,
1220 const std::string& edgeID,
1221 double pos,
1222 int laneIndex,
1223 double duration,
1224 int flags,
1225 double startPos,
1226 double until,
1227 int teleport) {
1228 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1230 pos, laneIndex, startPos, flags, duration, until);
1231
1232 std::string error;
1233 if (!vehicle->insertStop(nextStopIndex, stopPars, "traci:insertStop", teleport != 0, error)) {
1234 throw TraCIException("Stop insertion failed for vehicle '" + vehID + "' (" + error + ").");
1235 }
1236}
1237
1238
1239std::string
1240Vehicle::getStopParameter(const std::string& vehID, int nextStopIndex, const std::string& param, bool customParam) {
1241 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1242 try {
1243 if (nextStopIndex >= (int)vehicle->getStops().size() || (nextStopIndex < 0 && -nextStopIndex > (int)vehicle->getPastStops().size())) {
1244 throw ProcessError("Invalid stop index " + toString(nextStopIndex)
1245 + " (has " + toString(vehicle->getPastStops().size()) + " past stops and " + toString(vehicle->getStops().size()) + " remaining stops)");
1246
1247 }
1248 const SUMOVehicleParameter::Stop& pars = (nextStopIndex >= 0
1249 ? vehicle->getStop(nextStopIndex).pars
1250 : vehicle->getPastStops()[(int)vehicle->getPastStops().size() + nextStopIndex]);
1251 if (customParam) {
1252 // custom user parameter
1253 return pars.getParameter(param, "");
1254 }
1255
1256 if (param == toString(SUMO_ATTR_EDGE)) {
1257 return pars.edge;
1258 } else if (param == toString(SUMO_ATTR_LANE)) {
1260 } else if (param == toString(SUMO_ATTR_BUS_STOP)
1261 || param == toString(SUMO_ATTR_TRAIN_STOP)) {
1262 return pars.busstop;
1263 } else if (param == toString(SUMO_ATTR_CONTAINER_STOP)) {
1264 return pars.containerstop;
1265 } else if (param == toString(SUMO_ATTR_CHARGING_STATION)) {
1266 return pars.chargingStation;
1267 } else if (param == toString(SUMO_ATTR_PARKING_AREA)) {
1268 return pars.parkingarea;
1269 } else if (param == toString(SUMO_ATTR_STARTPOS)) {
1270 return toString(pars.startPos);
1271 } else if (param == toString(SUMO_ATTR_ENDPOS)) {
1272 return toString(pars.endPos);
1273 } else if (param == toString(SUMO_ATTR_POSITION_LAT)) {
1274 return toString(pars.posLat == INVALID_DOUBLE ? INVALID_DOUBLE_VALUE : pars.posLat);
1275 } else if (param == toString(SUMO_ATTR_ARRIVAL)) {
1276 return pars.arrival < 0 ? "-1" : time2string(pars.arrival);
1277 } else if (param == toString(SUMO_ATTR_DURATION)) {
1278 return pars.duration < 0 ? "-1" : time2string(pars.duration);
1279 } else if (param == toString(SUMO_ATTR_UNTIL)) {
1280 return pars.until < 0 ? "-1" : time2string(pars.until);
1281 } else if (param == toString(SUMO_ATTR_EXTENSION)) {
1282 return pars.extension < 0 ? "-1" : time2string(pars.extension);
1283 } else if (param == toString(SUMO_ATTR_INDEX)) {
1284 return toString(nextStopIndex + (int)vehicle->getPastStops().size());
1285 } else if (param == toString(SUMO_ATTR_PARKING)) {
1286 return toString(pars.parking);
1287 } else if (param == toString(SUMO_ATTR_TRIGGERED)) {
1288 return joinToString(pars.getTriggers(), " ");
1289 } else if (param == toString(SUMO_ATTR_EXPECTED)) {
1290 return joinToString(pars.awaitedPersons, " ");
1291 } else if (param == toString(SUMO_ATTR_EXPECTED_CONTAINERS)) {
1292 return joinToString(pars.awaitedContainers, " ");
1293 } else if (param == toString(SUMO_ATTR_PERMITTED)) {
1294 return joinToString(pars.permitted, " ");
1295 } else if (param == toString(SUMO_ATTR_ACTTYPE)) {
1296 return pars.actType;
1297 } else if (param == toString(SUMO_ATTR_TRIP_ID)) {
1298 return pars.tripId;
1299 } else if (param == toString(SUMO_ATTR_SPLIT)) {
1300 return pars.split;
1301 } else if (param == toString(SUMO_ATTR_JOIN)) {
1302 return pars.join;
1303 } else if (param == toString(SUMO_ATTR_LINE)) {
1304 return pars.line;
1305 } else if (param == toString(SUMO_ATTR_SPEED)) {
1306 return toString(pars.speed);
1307 } else if (param == toString(SUMO_ATTR_STARTED)) {
1308 return pars.started < 0 ? "-1" : time2string(pars.started);
1309 } else if (param == toString(SUMO_ATTR_ENDED)) {
1310 return pars.ended < 0 ? "-1" : time2string(pars.ended);
1311 } else if (param == toString(SUMO_ATTR_ONDEMAND)) {
1312 return toString(pars.onDemand);
1313 } else if (param == toString(SUMO_ATTR_JUMP)) {
1314 return pars.jump < 0 ? "-1" : time2string(pars.jump);
1315 } else if (param == toString(SUMO_ATTR_JUMP_UNTIL)) {
1316 return pars.jumpUntil < 0 ? "-1" : time2string(pars.jumpUntil);
1317 } else {
1318 throw ProcessError(TLF("Unsupported parameter '%'", param));
1319 }
1320 } catch (ProcessError& e) {
1321 throw TraCIException("Could not get stop parameter for vehicle '" + vehID + "' (" + e.what() + ")");
1322 }
1323}
1324
1325
1326
1327void
1328Vehicle::setStopParameter(const std::string& vehID, int nextStopIndex,
1329 const std::string& param, const std::string& value,
1330 bool customParam) {
1331 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1332 try {
1333 MSStop& stop = vehicle->getStop(nextStopIndex);
1335 if (customParam) {
1336 pars.setParameter(param, value);
1337 return;
1338 }
1339 std::string error;
1340 if (param == toString(SUMO_ATTR_EDGE)
1341 || param == toString(SUMO_ATTR_BUS_STOP)
1342 || param == toString(SUMO_ATTR_TRAIN_STOP)
1345 || param == toString(SUMO_ATTR_PARKING_AREA)
1346 || param == toString(SUMO_ATTR_LANE)
1347 ) {
1348 int laneIndex = stop.lane->getIndex();
1349 int flags = pars.getFlags() & 3;
1350 std::string edgeOrStopID = value;
1351 if (param == toString(SUMO_ATTR_LANE)) {
1352 laneIndex = StringUtils::toInt(value);
1353 edgeOrStopID = pars.edge;
1354 } else if (param == toString(SUMO_ATTR_BUS_STOP)
1355 || param == toString(SUMO_ATTR_TRAIN_STOP)) {
1356 flags |= 8;
1357 } else if (param == toString(SUMO_ATTR_CONTAINER_STOP)) {
1358 flags |= 16;
1359 } else if (param == toString(SUMO_ATTR_CHARGING_STATION)) {
1360 flags |= 32;
1361 } else if (param == toString(SUMO_ATTR_PARKING_AREA)) {
1362 flags |= 64;
1363 }
1364 // special case: replace stop
1365 replaceStop(vehID, nextStopIndex, edgeOrStopID, pars.endPos, laneIndex, STEPS2TIME(pars.duration),
1366 flags, pars.startPos, STEPS2TIME(pars.until), 0);
1367
1368 } else if (param == toString(SUMO_ATTR_STARTPOS)) {
1369 pars.startPos = StringUtils::toDouble(value);
1371 } else if (param == toString(SUMO_ATTR_ENDPOS)) {
1372 pars.endPos = StringUtils::toDouble(value);
1374 } else if (param == toString(SUMO_ATTR_POSITION_LAT)) {
1375 pars.posLat = StringUtils::toDouble(value);
1377 } else if (param == toString(SUMO_ATTR_ARRIVAL)) {
1378 pars.arrival = string2time(value);
1380 } else if (param == toString(SUMO_ATTR_DURATION)) {
1381 pars.duration = string2time(value);
1383 // also update dynamic value
1384 stop.initPars(pars);
1385 } else if (param == toString(SUMO_ATTR_UNTIL)) {
1386 pars.until = string2time(value);
1388 } else if (param == toString(SUMO_ATTR_EXTENSION)) {
1389 pars.extension = string2time(value);
1391 } else if (param == toString(SUMO_ATTR_INDEX)) {
1392 throw TraCIException("Changing stop index is not supported");
1393 } else if (param == toString(SUMO_ATTR_PARKING)) {
1396 } else if (param == toString(SUMO_ATTR_TRIGGERED)) {
1397 if (pars.speed > 0 && value != "") {
1398 throw ProcessError(TLF("Waypoint (speed = %) at index % does not support triggers", pars.speed, nextStopIndex));
1399 }
1400 SUMOVehicleParameter::parseStopTriggers(StringTokenizer(value).getVector(), false, pars);
1402 // also update dynamic value
1403 stop.initPars(pars);
1404 } else if (param == toString(SUMO_ATTR_EXPECTED)) {
1405 pars.awaitedPersons = StringTokenizer(value).getSet();
1407 // also update dynamic value
1408 stop.initPars(pars);
1409 } else if (param == toString(SUMO_ATTR_EXPECTED_CONTAINERS)) {
1412 // also update dynamic value
1413 stop.initPars(pars);
1414 } else if (param == toString(SUMO_ATTR_PERMITTED)) {
1415 pars.permitted = StringTokenizer(value).getSet();
1417 } else if (param == toString(SUMO_ATTR_ACTTYPE)) {
1418 pars.actType = value;
1419 } else if (param == toString(SUMO_ATTR_TRIP_ID)) {
1420 pars.tripId = value;
1422 } else if (param == toString(SUMO_ATTR_SPLIT)) {
1423 pars.split = value;
1425 } else if (param == toString(SUMO_ATTR_JOIN)) {
1426 pars.join = value;
1428 // also update dynamic value
1429 stop.initPars(pars);
1430 } else if (param == toString(SUMO_ATTR_LINE)) {
1431 pars.line = value;
1433 } else if (param == toString(SUMO_ATTR_SPEED)) {
1434 const double speed = StringUtils::toDouble(value);
1435 if (speed > 0 && pars.getTriggers().size() > 0) {
1436 throw ProcessError(TLF("Triggered stop at index % cannot be changed into a waypoint by setting speed to %", nextStopIndex, speed));
1437 }
1438 pars.speed = speed;
1440 } else if (param == toString(SUMO_ATTR_STARTED)) {
1441 pars.started = string2time(value);
1443 } else if (param == toString(SUMO_ATTR_ENDED)) {
1444 pars.ended = string2time(value);
1446 } else if (param == toString(SUMO_ATTR_ONDEMAND)) {
1447 pars.onDemand = StringUtils::toBool(value);
1449 } else if (param == toString(SUMO_ATTR_JUMP)) {
1450 pars.jump = string2time(value);
1452 } else if (param == toString(SUMO_ATTR_JUMP_UNTIL)) {
1453 pars.jumpUntil = string2time(value);
1455 } else {
1456 throw ProcessError(TLF("Unsupported parameter '%'", param));
1457 }
1458 } catch (ProcessError& e) {
1459 throw TraCIException("Could not set stop parameter for vehicle '" + vehID + "' (" + e.what() + ")");
1460 }
1461}
1462
1463
1464void
1465Vehicle::rerouteParkingArea(const std::string& vehID, const std::string& parkingAreaID) {
1466 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1467 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1468 if (veh == nullptr) {
1469 WRITE_WARNING("rerouteParkingArea not yet implemented for meso");
1470 return;
1471 }
1472 std::string error;
1473 // Forward command to vehicle
1474 if (!veh->rerouteParkingArea(parkingAreaID, error)) {
1475 throw TraCIException(error);
1476 }
1477}
1478
1479void
1480Vehicle::resume(const std::string& vehID) {
1481 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1482 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1483 if (veh == nullptr) {
1484 WRITE_WARNING("resume not yet implemented for meso");
1485 return;
1486 }
1487 if (!veh->hasStops()) {
1488 throw TraCIException("Failed to resume vehicle '" + veh->getID() + "', it has no stops.");
1489 }
1490 if (!veh->resumeFromStopping()) {
1491 const MSStop& sto = veh->getNextStop();
1492 std::ostringstream strs;
1493 strs << "reached: " << sto.reached;
1494 strs << ", duration:" << sto.duration;
1495 strs << ", edge:" << (*sto.edge)->getID();
1496 strs << ", startPos: " << sto.pars.startPos;
1497 std::string posStr = strs.str();
1498 throw TraCIException("Failed to resume from stopping for vehicle '" + veh->getID() + "', " + posStr);
1499 }
1500}
1501
1502
1503void
1504Vehicle::changeTarget(const std::string& vehID, const std::string& edgeID) {
1505 MSBaseVehicle* veh = Helper::getVehicle(vehID);
1506 const MSEdge* destEdge = MSEdge::dictionary(edgeID);
1507 const bool onInit = isOnInit(vehID);
1508 if (destEdge == nullptr) {
1509 throw TraCIException("Destination edge '" + edgeID + "' is not known.");
1510 }
1511 // change the final edge of the route and reroute
1512 try {
1513 const bool success = veh->reroute(MSNet::getInstance()->getCurrentTimeStep(), "traci:changeTarget",
1514 veh->getRouterTT(), onInit, false, false, destEdge);
1515 if (!success) {
1516 throw TraCIException("ChangeTarget failed for vehicle '" + veh->getID() + "', destination edge '" + edgeID + "' unreachable.");
1517 }
1518 } catch (ProcessError& e) {
1519 throw TraCIException(e.what());
1520 }
1521}
1522
1523
1524void
1525Vehicle::changeLane(const std::string& vehID, int laneIndex, double duration) {
1526 try {
1527 checkTimeBounds(duration);
1528 } catch (ProcessError&) {
1529 throw TraCIException("Duration parameter exceeds the time value range.");
1530 }
1531 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1532 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1533 if (veh == nullptr) {
1534 WRITE_ERROR("changeLane not applicable for meso");
1535 return;
1536 }
1537
1538 std::vector<std::pair<SUMOTime, int> > laneTimeLine;
1539 laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), laneIndex));
1540 laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep() + TIME2STEPS(duration), laneIndex));
1541 veh->getInfluencer().setLaneTimeLine(laneTimeLine);
1542}
1543
1544void
1545Vehicle::changeLaneRelative(const std::string& vehID, int indexOffset, double duration) {
1546 try {
1547 checkTimeBounds(duration);
1548 } catch (ProcessError&) {
1549 throw TraCIException("Duration parameter exceeds the time value range.");
1550 }
1551 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1552 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1553 if (veh == nullptr) {
1554 WRITE_ERROR("changeLaneRelative not applicable for meso");
1555 return;
1556 }
1557
1558 std::vector<std::pair<SUMOTime, int> > laneTimeLine;
1559 int laneIndex = veh->getLaneIndex() + indexOffset;
1560 if (laneIndex < 0 && !veh->getLaneChangeModel().isOpposite()) {
1561 if (veh->getLaneIndex() == -1) {
1562 WRITE_WARNINGF(TL("Ignoring changeLaneRelative for vehicle '%' that isn't on the road"), vehID);
1563 } else {
1564 WRITE_WARNINGF(TL("Ignoring indexOffset % for vehicle '%' on laneIndex %."), indexOffset, vehID, veh->getLaneIndex());
1565 }
1566 } else {
1567 laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), laneIndex));
1568 laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep() + TIME2STEPS(duration), laneIndex));
1569 veh->getInfluencer().setLaneTimeLine(laneTimeLine);
1570 }
1571}
1572
1573
1574void
1575Vehicle::changeSublane(const std::string& vehID, double latDist) {
1576 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1577 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1578 if (veh == nullptr) {
1579 WRITE_ERROR("changeSublane not applicable for meso");
1580 return;
1581 }
1582
1583 veh->getInfluencer().setSublaneChange(latDist);
1584}
1585
1586
1587void
1588Vehicle::add(const std::string& vehID,
1589 const std::string& routeID,
1590 const std::string& typeID,
1591 const std::string& depart,
1592 const std::string& departLane,
1593 const std::string& departPos,
1594 const std::string& departSpeed,
1595 const std::string& arrivalLane,
1596 const std::string& arrivalPos,
1597 const std::string& arrivalSpeed,
1598 const std::string& fromTaz,
1599 const std::string& toTaz,
1600 const std::string& line,
1601 int /*personCapacity*/,
1602 int personNumber,
1603 const std::string& departPosLat,
1604 const std::string& arrivalPosLat,
1605 double speedFactor,
1606 const std::string& insertionChecks) {
1608 if (veh != nullptr) {
1609 throw TraCIException("The vehicle '" + vehID + "' to add already exists.");
1610 }
1611
1612 SUMOVehicleParameter vehicleParams;
1613 vehicleParams.id = vehID;
1614 MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(typeID);
1615 if (!vehicleType) {
1616 throw TraCIException("Invalid type '" + typeID + "' for vehicle '" + vehID + "'.");
1617 }
1618 if (typeID != "DEFAULT_VEHTYPE") {
1619 vehicleParams.vtypeid = typeID;
1620 vehicleParams.parametersSet |= VEHPARS_VTYPE_SET;
1621 }
1623 WRITE_WARNINGF(TL("Internal routes receive an ID starting with '!' and must not be referenced in other vehicle or flow definitions. Please remove all references to route '%' in case it is internal."), routeID);
1624 }
1625 ConstMSRoutePtr route = MSRoute::dictionary(routeID);
1626 if (!route) {
1627 if (routeID == "") {
1628 // assume, route was intentionally left blank because the caller
1629 // intends to control the vehicle remotely
1630 SUMOVehicleClass vclass = vehicleType->getVehicleClass();
1631 const std::string dummyRouteID = "DUMMY_ROUTE_" + SumoVehicleClassStrings.getString(vclass);
1632 route = MSRoute::dictionary(dummyRouteID);
1633 if (route == nullptr) {
1634 for (MSEdge* e : MSEdge::getAllEdges()) {
1635 if (e->getFunction() == SumoXMLEdgeFunc::NORMAL && (e->getPermissions() & vclass) == vclass) {
1636 std::vector<std::string> edges;
1637 edges.push_back(e->getID());
1638 libsumo::Route::add(dummyRouteID, edges);
1639 break;
1640 }
1641 }
1642 }
1643 route = MSRoute::dictionary(dummyRouteID);
1644 if (!route) {
1645 throw TraCIException("Could not build dummy route for vehicle class: '" + SumoVehicleClassStrings.getString(vehicleType->getVehicleClass()) + "'");
1646 }
1647 } else {
1648 throw TraCIException("Invalid route '" + routeID + "' for vehicle '" + vehID + "'.");
1649 }
1650 }
1651 // check if the route implies a trip
1652 if (route->getEdges().size() == 2) {
1653 const MSEdgeVector& succ = route->getEdges().front()->getSuccessors();
1654 if (std::find(succ.begin(), succ.end(), route->getEdges().back()) == succ.end()) {
1655 vehicleParams.parametersSet |= VEHPARS_FORCE_REROUTE;
1656 }
1657 }
1658 if (fromTaz != "" || toTaz != "") {
1659 vehicleParams.parametersSet |= VEHPARS_FORCE_REROUTE;
1660 }
1661 std::string error;
1662 if (!SUMOVehicleParameter::parseDepart(depart, "vehicle", vehID, vehicleParams.depart, vehicleParams.departProcedure, error)) {
1663 throw TraCIException(error);
1664 }
1665 if (vehicleParams.departProcedure == DepartDefinition::GIVEN && vehicleParams.depart < MSNet::getInstance()->getCurrentTimeStep()) {
1666 vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
1667 WRITE_WARNINGF(TL("Departure time for vehicle '%' is in the past; using current time instead."), vehID);
1668 } else if (vehicleParams.departProcedure == DepartDefinition::NOW) {
1669 vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
1670 }
1671 if (!SUMOVehicleParameter::parseDepartLane(departLane, "vehicle", vehID, vehicleParams.departLane, vehicleParams.departLaneProcedure, error)) {
1672 throw TraCIException(error);
1673 }
1674 if (!SUMOVehicleParameter::parseDepartPos(departPos, "vehicle", vehID, vehicleParams.departPos, vehicleParams.departPosProcedure, error)) {
1675 throw TraCIException(error);
1676 }
1677 if (!SUMOVehicleParameter::parseDepartSpeed(departSpeed, "vehicle", vehID, vehicleParams.departSpeed, vehicleParams.departSpeedProcedure, error)) {
1678 throw TraCIException(error);
1679 }
1680 if (!SUMOVehicleParameter::parseArrivalLane(arrivalLane, "vehicle", vehID, vehicleParams.arrivalLane, vehicleParams.arrivalLaneProcedure, error)) {
1681 throw TraCIException(error);
1682 }
1683 if (!SUMOVehicleParameter::parseArrivalPos(arrivalPos, "vehicle", vehID, vehicleParams.arrivalPos, vehicleParams.arrivalPosProcedure, error)) {
1684 throw TraCIException(error);
1685 }
1686 if (!SUMOVehicleParameter::parseArrivalSpeed(arrivalSpeed, "vehicle", vehID, vehicleParams.arrivalSpeed, vehicleParams.arrivalSpeedProcedure, error)) {
1687 throw TraCIException(error);
1688 }
1689 if (!departPosLat.empty()) {
1690 if (!SUMOVehicleParameter::parseDepartPosLat(departPosLat, "vehicle", vehID, vehicleParams.departPosLat, vehicleParams.departPosLatProcedure, error)) {
1691 throw TraCIException(error);
1692 }
1693 vehicleParams.parametersSet |= VEHPARS_DEPARTPOSLAT_SET;
1694 }
1695 if (!arrivalPosLat.empty()) {
1696 if (!SUMOVehicleParameter::parseArrivalPosLat(arrivalPosLat, "vehicle", vehID, vehicleParams.arrivalPosLat, vehicleParams.arrivalPosLatProcedure, error)) {
1697 throw TraCIException(error);
1698 }
1700 }
1701 if (speedFactor > 0) {
1702 vehicleParams.speedFactor = speedFactor;
1703 vehicleParams.parametersSet |= VEHPARS_SPEEDFACTOR_SET;
1704 }
1705 if (!insertionChecks.empty()) {
1706 try {
1707 vehicleParams.insertionChecks = SUMOVehicleParameter::parseInsertionChecks(insertionChecks);
1709 } catch (const InvalidArgument& e) {
1710 throw TraCIException(e.what());
1711 }
1712 }
1713 // mark non-default attributes
1714 if (departLane != "first") {
1715 vehicleParams.parametersSet |= VEHPARS_DEPARTLANE_SET;
1716 }
1717 if (departPos != "base") {
1718 vehicleParams.parametersSet |= VEHPARS_DEPARTPOS_SET;
1719 }
1720 if (departSpeed != "0") {
1721 vehicleParams.parametersSet |= VEHPARS_DEPARTSPEED_SET;
1722 }
1723 if (arrivalLane != "current") {
1724 vehicleParams.parametersSet |= VEHPARS_ARRIVALLANE_SET;
1725 }
1726 if (arrivalPos != "max") {
1727 vehicleParams.parametersSet |= VEHPARS_ARRIVALPOS_SET;
1728 }
1729 if (arrivalSpeed != "current") {
1730 vehicleParams.parametersSet |= VEHPARS_ARRIVALSPEED_SET;
1731 }
1732 if (fromTaz != "") {
1733 vehicleParams.parametersSet |= VEHPARS_FROM_TAZ_SET;
1734 }
1735 if (toTaz != "") {
1736 vehicleParams.parametersSet |= VEHPARS_TO_TAZ_SET;
1737 }
1738 if (line != "") {
1739 vehicleParams.parametersSet |= VEHPARS_LINE_SET;
1740 }
1741 if (personNumber != 0) {
1743 }
1744 // build vehicle
1745 vehicleParams.fromTaz = fromTaz;
1746 vehicleParams.toTaz = toTaz;
1747 vehicleParams.line = line;
1748 //vehicleParams.personCapacity = personCapacity;
1749 vehicleParams.personNumber = personNumber;
1750
1751 SUMOVehicleParameter* params = new SUMOVehicleParameter(vehicleParams);
1752 SUMOVehicle* vehicle = nullptr;
1753 try {
1755 if (fromTaz == "" && !route->getEdges().front()->validateDepartSpeed(*vehicle)) {
1757 throw TraCIException("Departure speed for vehicle '" + vehID + "' is too high for the departure edge '" + route->getEdges().front()->getID() + "'.");
1758 }
1759 std::string msg;
1760 if (vehicle->getRouteValidity(true, true, &msg) != MSBaseVehicle::ROUTE_VALID) {
1762 throw TraCIException("Vehicle '" + vehID + "' has no valid route (" + msg + "). ");
1763 }
1764 MSNet::getInstance()->getVehicleControl().addVehicle(vehicleParams.id, vehicle);
1767 }
1768 } catch (ProcessError& e) {
1769 if (vehicle != nullptr) {
1771 }
1772 throw TraCIException(e.what());
1773 }
1774}
1775
1776
1777void
1778Vehicle::moveToXY(const std::string& vehID, const std::string& edgeID, const int laneIndex,
1779 const double x, const double y, double angle, const int keepRoute, double matchThreshold) {
1780 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1781 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1782 if (veh == nullptr) {
1783 WRITE_WARNING("moveToXY not yet implemented for meso");
1784 return;
1785 }
1786 const bool doKeepRoute = (keepRoute & 1) != 0 && veh->getID() != "VTD_EGO";
1787 const bool mayLeaveNetwork = (keepRoute & 2) != 0;
1788 const bool ignorePermissions = (keepRoute & 4) != 0;
1789 const bool setLateralPos = (MSGlobals::gLateralResolution > 0 || mayLeaveNetwork);
1790 SUMOVehicleClass vClass = ignorePermissions ? SVC_IGNORING : veh->getVClass();
1791 // process
1792 const std::string origID = edgeID + "_" + toString(laneIndex);
1793 // @todo add an interpretation layer for OSM derived origID values (without lane index)
1794 Position pos(x, y);
1795#ifdef DEBUG_MOVEXY
1796 const double origAngle = angle;
1797#endif
1798 // angle must be in [0,360] because it will be compared against those returned by naviDegree()
1799 // angle set to INVALID_DOUBLE_VALUE is ignored in the evaluated and later set to the angle of the matched lane
1800 if (angle != INVALID_DOUBLE_VALUE) {
1801 while (angle >= 360.) {
1802 angle -= 360.;
1803 }
1804 while (angle < 0.) {
1805 angle += 360.;
1806 }
1807 }
1808
1809#ifdef DEBUG_MOVEXY
1810 std::cout << std::endl << SIMTIME << " moveToXY veh=" << veh->getID() << " vehPos=" << veh->getPosition()
1811 << " lane=" << Named::getIDSecure(veh->getLane()) << " lanePos=" << vehicle->getPositionOnLane() << std::endl;
1812 std::cout << " wantedPos=" << pos << " origID=" << origID << " laneIndex=" << laneIndex << " origAngle=" << origAngle << " angle=" << angle << " keepRoute=" << keepRoute << std::endl;
1813#endif
1814
1815 ConstMSEdgeVector edges;
1816 MSLane* lane = nullptr;
1817 double lanePos;
1818 double lanePosLat = 0;
1819 double bestDistance = std::numeric_limits<double>::max();
1820 int routeOffset = 0;
1821 bool found;
1822 double maxRouteDistance = matchThreshold;
1823 /* EGO vehicle is known to have a fixed route. @todo make this into a parameter of the TraCI call */
1824 if (doKeepRoute) {
1825 // case a): vehicle is on its earlier route
1826 // we additionally assume it is moving forward (SUMO-limit);
1827 // note that the route ("edges") is not changed in this case
1828
1830 veh->getRoute().getEdges(), veh->getRoutePosition(),
1831 vClass, setLateralPos,
1832 bestDistance, &lane, lanePos, routeOffset);
1833 // @note silenty ignoring mapping failure
1834 } else {
1835 const double speed = pos.distanceTo2D(veh->getPosition()); // !!!veh->getSpeed();
1836 found = Helper::moveToXYMap(pos, maxRouteDistance, mayLeaveNetwork, origID, angle,
1837 speed, veh->getRoute().getEdges(), veh->getRoutePosition(), veh->getLane(), veh->getPositionOnLane(), veh->isOnRoad(),
1838 vClass, GeomHelper::naviDegree(veh->getAngle()), setLateralPos,
1839 bestDistance, &lane, lanePos, routeOffset, edges);
1840 }
1841 if ((found && bestDistance <= maxRouteDistance) || mayLeaveNetwork) {
1842 // optionally compute lateral offset
1843 pos.setz(veh->getPosition().z());
1844 if (found && setLateralPos) {
1845 const double perpDist = lane->getShape().distance2D(pos, false);
1846 if (perpDist != GeomHelper::INVALID_OFFSET) {
1847 lanePosLat = perpDist;
1848 if (!mayLeaveNetwork) {
1849 lanePosLat = MIN2(lanePosLat, 0.5 * (lane->getWidth() + veh->getVehicleType().getWidth() - MSGlobals::gLateralResolution));
1850 }
1851 // figure out whether the offset is to the left or to the right
1852 PositionVector tmp = lane->getShape();
1853 try {
1854 tmp.move2side(-lanePosLat); // moved to left
1855 } catch (ProcessError&) {
1856 WRITE_WARNINGF(TL("Could not determine position on lane '%' at lateral position %."), lane->getID(), toString(-lanePosLat));
1857 }
1858 //std::cout << " lane=" << lane->getID() << " posLat=" << lanePosLat << " shape=" << lane->getShape() << " tmp=" << tmp << " tmpDist=" << tmp.distance2D(pos) << "\n";
1859 if (tmp.distance2D(pos) > perpDist) {
1860 lanePosLat = -lanePosLat;
1861 }
1862 }
1863 pos.setz(lane->geometryPositionAtOffset(lanePos).z());
1864 }
1865 if (found && !mayLeaveNetwork && MSGlobals::gLateralResolution < 0) {
1866 // mapped position may differ from pos
1867 pos = lane->geometryPositionAtOffset(lanePos, -lanePosLat);
1868 }
1869 assert((found && lane != 0) || (!found && lane == 0));
1870 assert(!std::isnan(lanePos));
1871 if (angle == INVALID_DOUBLE_VALUE) {
1872 if (lane != nullptr) {
1873 angle = GeomHelper::naviDegree(lane->getShape().rotationAtOffset(lanePos));
1874 } else {
1875 // compute angle outside road network from old and new position
1876 angle = GeomHelper::naviDegree(veh->getPosition().angleTo2D(pos));
1877 }
1878 }
1879 // use the best we have
1880#ifdef DEBUG_MOVEXY
1881 std::cout << SIMTIME << " veh=" << vehID + " moveToXYResult lane='" << Named::getIDSecure(lane) << "' lanePos=" << lanePos << " lanePosLat=" << lanePosLat << "\n";
1882#endif
1883 Helper::setRemoteControlled(veh, pos, lane, lanePos, lanePosLat, angle, routeOffset, edges, MSNet::getInstance()->getCurrentTimeStep());
1884 if (!veh->isOnRoad()) {
1886 }
1887 } else {
1888 if (lane == nullptr) {
1889 throw TraCIException("Could not map vehicle '" + vehID + "', no road found within " + toString(maxRouteDistance) + "m.");
1890 } else {
1891 throw TraCIException("Could not map vehicle '" + vehID + "', distance to road is " + toString(bestDistance) + ".");
1892 }
1893 }
1894}
1895
1896void
1897Vehicle::slowDown(const std::string& vehID, double speed, double duration) {
1898 try {
1899 checkTimeBounds(duration);
1900 } catch (ProcessError&) {
1901 throw TraCIException("Duration parameter exceeds the time value range.");
1902 }
1903 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1904 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1905 if (veh == nullptr) {
1906 WRITE_ERROR("slowDown not applicable for meso");
1907 return;
1908 }
1909
1910 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
1911 speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), veh->getSpeed()));
1912 speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep() + TIME2STEPS(duration), speed));
1913 veh->getInfluencer().setSpeedTimeLine(speedTimeLine);
1914}
1915
1916void
1917Vehicle::openGap(const std::string& vehID, double newTimeHeadway, double newSpaceHeadway, double duration, double changeRate, double maxDecel, const std::string& referenceVehID) {
1918 try {
1919 checkTimeBounds(duration);
1920 } catch (ProcessError&) {
1921 throw TraCIException("Duration parameter exceeds the time value range.");
1922 }
1923 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1924 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1925 if (veh == nullptr) {
1926 WRITE_ERROR("openGap not applicable for meso");
1927 return;
1928 }
1929
1930 MSVehicle* refVeh = nullptr;
1931 if (referenceVehID != "") {
1932 refVeh = dynamic_cast<MSVehicle*>(Helper::getVehicle(referenceVehID));
1933 }
1934 const double originalTau = veh->getVehicleType().getCarFollowModel().getHeadwayTime();
1935 if (newTimeHeadway == -1) {
1936 newTimeHeadway = originalTau;
1937 }
1938 if (originalTau > newTimeHeadway) {
1939 WRITE_WARNING("Ignoring openGap(). New time headway must not be smaller than the original.");
1940 return;
1941 }
1942 veh->getInfluencer().activateGapController(originalTau, newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel, refVeh);
1943}
1944
1945void
1946Vehicle::deactivateGapControl(const std::string& vehID) {
1947 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1948 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1949 if (veh == nullptr) {
1950 WRITE_ERROR("deactivateGapControl not applicable for meso");
1951 return;
1952 }
1953
1954 if (veh->hasInfluencer()) {
1956 }
1957}
1958
1959void
1960Vehicle::requestToC(const std::string& vehID, double leadTime) {
1961 setParameter(vehID, "device.toc.requestToC", toString(leadTime));
1962}
1963
1964void
1965Vehicle::setSpeed(const std::string& vehID, double speed) {
1966 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1967 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1968 if (veh == nullptr) {
1969 WRITE_WARNING("setSpeed not yet implemented for meso");
1970 return;
1971 }
1972
1973 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
1974 if (speed >= 0) {
1975 speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), speed));
1976 speedTimeLine.push_back(std::make_pair(SUMOTime_MAX - DELTA_T, speed));
1977 }
1978 veh->getInfluencer().setSpeedTimeLine(speedTimeLine);
1979}
1980
1981void
1982Vehicle::setAcceleration(const std::string& vehID, double acceleration, double duration) {
1983 try {
1984 checkTimeBounds(duration);
1985 } catch (ProcessError&) {
1986 throw TraCIException("Duration parameter exceeds the time value range.");
1987 }
1988 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1989 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1990 if (veh == nullptr) {
1991 WRITE_WARNING("setAcceleration not yet implemented for meso");
1992 return;
1993 }
1994
1995 double targetSpeed = std::max(veh->getSpeed() + acceleration * duration, 0.0);
1996 std::vector<std::pair<SUMOTime, double>> speedTimeLine;
1997 speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), veh->getSpeed()));
1998 speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep() + TIME2STEPS(duration), targetSpeed));
1999 veh->getInfluencer().setSpeedTimeLine(speedTimeLine);
2000}
2001
2002void
2003Vehicle::setPreviousSpeed(const std::string& vehID, double prevSpeed, double prevAcceleration) {
2004 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
2005 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
2006 if (veh == nullptr) {
2007 WRITE_WARNING("setPreviousSpeed not yet implemented for meso");
2008 return;
2009 }
2010 if (prevAcceleration == INVALID_DOUBLE_VALUE) {
2011 prevAcceleration = std::numeric_limits<double>::min();
2012 }
2013 veh->setPreviousSpeed(prevSpeed, prevAcceleration);
2014}
2015
2016void
2017Vehicle::setSpeedMode(const std::string& vehID, int speedMode) {
2018 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
2019 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
2020 if (veh == nullptr) {
2021 WRITE_WARNING("setSpeedMode not yet implemented for meso");
2022 return;
2023 }
2024
2025 veh->getInfluencer().setSpeedMode(speedMode);
2026}
2027
2028void
2029Vehicle::setLaneChangeMode(const std::string& vehID, int laneChangeMode) {
2030 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
2031 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
2032 if (veh == nullptr) {
2033 WRITE_ERROR("setLaneChangeMode not applicable for meso");
2034 return;
2035 }
2036
2037 veh->getInfluencer().setLaneChangeMode(laneChangeMode);
2038}
2039
2040void
2041Vehicle::setRoutingMode(const std::string& vehID, int routingMode) {
2042 Helper::getVehicle(vehID)->setRoutingMode(routingMode);
2043}
2044
2045void
2046Vehicle::setType(const std::string& vehID, const std::string& typeID) {
2047 MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(typeID);
2048 if (vehicleType == nullptr) {
2049 throw TraCIException("Vehicle type '" + typeID + "' is not known");
2050 }
2051 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2052 veh->replaceVehicleType(vehicleType);
2053 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
2054 if (microVeh != nullptr && microVeh->isOnRoad()) {
2055 microVeh->updateBestLanes(true);
2056 microVeh->updateLaneBruttoSum();
2057 }
2058}
2059
2060void
2061Vehicle::setRouteID(const std::string& vehID, const std::string& routeID) {
2062 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2064 if (r == nullptr) {
2065 throw TraCIException("The route '" + routeID + "' is not known.");
2066 }
2068 WRITE_WARNINGF(TL("Internal routes receive an ID starting with '!' and must not be referenced in other vehicle or flow definitions. Please remove all references to route '%' in case it is internal."), routeID);
2069 }
2070 std::string msg;
2071 if (!veh->hasValidRoute(msg, r)) {
2072 WRITE_WARNINGF(TL("Invalid route replacement for vehicle '%'. %"), veh->getID(), msg);
2074 throw TraCIException("Route replacement failed for " + veh->getID());
2075 }
2076 }
2077
2078 std::string errorMsg;
2079 if (!veh->replaceRoute(r, "traci:setRouteID", veh->getLane() == nullptr, 0, true, true, &errorMsg)) {
2080 throw TraCIException("Route replacement failed for vehicle '" + veh->getID() + "' (" + errorMsg + ").");
2081 }
2082}
2083
2084void
2085Vehicle::setRoute(const std::string& vehID, const std::string& edgeID) {
2086 setRoute(vehID, std::vector<std::string>({edgeID}));
2087}
2088
2089
2090void
2091Vehicle::setRoute(const std::string& vehID, const std::vector<std::string>& edgeIDs) {
2092 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2093 ConstMSEdgeVector edges;
2094 const bool onInit = veh->getLane() == nullptr;
2095 try {
2096 MSEdge::parseEdgesList(edgeIDs, edges, "<unknown>");
2097 if (edges.size() > 0 && edges.front()->isInternal()) {
2098 if (edges.size() == 1) {
2099 // avoid crashing due to lack of normal edges in route (#5390)
2100 edges.push_back(edges.back()->getLanes()[0]->getNextNormal());
2101 } else {
2102 // avoid internal edge in final route
2103 if (edges.front() == &veh->getLane()->getEdge()) {
2104 edges.erase(edges.begin());
2105 }
2106 }
2107 }
2108 } catch (ProcessError& e) {
2109 throw TraCIException("Invalid edge list for vehicle '" + veh->getID() + "' (" + e.what() + ")");
2110 }
2111 std::string errorMsg;
2112 if (!veh->replaceRouteEdges(edges, -1, 0, "traci:setRoute", onInit, true, true, &errorMsg)) {
2113 throw TraCIException("Route replacement failed for vehicle '" + veh->getID() + "' (" + errorMsg + ").");
2114 }
2115}
2116
2117
2118void
2119Vehicle::setLateralLanePosition(const std::string& vehID, double posLat) {
2120 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
2121 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
2122 if (veh != nullptr) {
2123 veh->setLateralPositionOnLane(posLat);
2124 } else {
2125 WRITE_ERROR("setLateralLanePosition not applicable for meso");
2126 }
2127}
2128
2129
2130void
2131Vehicle::updateBestLanes(const std::string& vehID) {
2132 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
2133 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
2134 if (veh == nullptr) {
2135 WRITE_ERROR("updateBestLanes not applicable for meso");
2136 return;
2137 }
2138 if (veh->isOnRoad()) {
2139 veh->updateBestLanes(true);
2140 }
2141}
2142
2143
2144void
2145Vehicle::setAdaptedTraveltime(const std::string& vehID, const std::string& edgeID,
2146 double time, double begSeconds, double endSeconds) {
2147 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2148 MSEdge* edge = MSEdge::dictionary(edgeID);
2149 if (edge == nullptr) {
2150 throw TraCIException("Edge '" + edgeID + "' is not known.");
2151 }
2152 if (time != INVALID_DOUBLE_VALUE) {
2153 // add time
2154 if (begSeconds == 0 && endSeconds == std::numeric_limits<double>::max()) {
2155 // clean up old values before setting whole range
2156 while (veh->getWeightsStorage().knowsTravelTime(edge)) {
2158 }
2159 }
2160 veh->getWeightsStorage().addTravelTime(edge, begSeconds, endSeconds, time);
2161 } else {
2162 // remove time
2163 while (veh->getWeightsStorage().knowsTravelTime(edge)) {
2165 }
2166 }
2167}
2168
2169
2170void
2171Vehicle::setEffort(const std::string& vehID, const std::string& edgeID,
2172 double effort, double begSeconds, double endSeconds) {
2173 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2174 MSEdge* edge = MSEdge::dictionary(edgeID);
2175 if (edge == nullptr) {
2176 throw TraCIException("Edge '" + edgeID + "' is not known.");
2177 }
2178 if (effort != INVALID_DOUBLE_VALUE) {
2179 // add effort
2180 if (begSeconds == 0 && endSeconds == std::numeric_limits<double>::max()) {
2181 // clean up old values before setting whole range
2182 while (veh->getWeightsStorage().knowsEffort(edge)) {
2183 veh->getWeightsStorage().removeEffort(edge);
2184 }
2185 }
2186 veh->getWeightsStorage().addEffort(edge, begSeconds, endSeconds, effort);
2187 } else {
2188 // remove effort
2189 while (veh->getWeightsStorage().knowsEffort(edge)) {
2190 veh->getWeightsStorage().removeEffort(edge);
2191 }
2192 }
2193}
2194
2195
2196void
2197Vehicle::rerouteTraveltime(const std::string& vehID, const bool currentTravelTimes) {
2198 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2199 const int routingMode = veh->getRoutingMode();
2200 if (currentTravelTimes && routingMode == ROUTING_MODE_DEFAULT) {
2202 }
2203 veh->reroute(MSNet::getInstance()->getCurrentTimeStep(), "traci:rerouteTraveltime",
2204 veh->getRouterTT(), isOnInit(vehID));
2205 if (currentTravelTimes && routingMode == ROUTING_MODE_DEFAULT) {
2206 veh->setRoutingMode(routingMode);
2207 }
2208}
2209
2210
2211void
2212Vehicle::rerouteEffort(const std::string& vehID) {
2213 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2214 veh->reroute(MSNet::getInstance()->getCurrentTimeStep(), "traci:rerouteEffort",
2215 MSNet::getInstance()->getRouterEffort(veh->getRNGIndex()), isOnInit(vehID));
2216}
2217
2218
2219void
2220Vehicle::setSignals(const std::string& vehID, int signals) {
2221 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
2222 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
2223 if (veh == nullptr) {
2224 WRITE_ERROR("setSignals not applicable for meso");
2225 return;
2226 }
2227
2228 // set influencer to make the change persistent
2229 veh->getInfluencer().setSignals(signals);
2230 // set them now so that getSignals returns the correct value
2231 veh->switchOffSignal(0x0fffffff);
2232 if (signals >= 0) {
2233 veh->switchOnSignal(signals);
2234 }
2235}
2236
2237
2238void
2239Vehicle::moveTo(const std::string& vehID, const std::string& laneID, double pos, int reason) {
2240 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
2241 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
2242 if (veh == nullptr) {
2243 WRITE_WARNING("moveTo not yet implemented for meso");
2244 return;
2245 }
2246
2247 MSLane* l = MSLane::dictionary(laneID);
2248 if (l == nullptr) {
2249 throw TraCIException("Unknown lane '" + laneID + "'.");
2250 }
2251 if (veh->getLane() == l) {
2253 return;
2254 }
2255 MSEdge* destinationEdge = &l->getEdge();
2256 const MSEdge* destinationRouteEdge = destinationEdge->getNormalBefore();
2257 if (!veh->isOnRoad() && veh->getParameter().wasSet(VEHPARS_FORCE_REROUTE) && veh->getRoute().getEdges().size() == 2) {
2258 // it's a trip that wasn't routeted yet (likely because the vehicle was added in this step. Find a route now
2259 veh->reroute(MSNet::getInstance()->getCurrentTimeStep(), "traci:moveTo-tripInsertion",
2260 veh->getRouterTT(), true);
2261 }
2262 // find edge in the remaining route
2263 MSRouteIterator it = std::find(veh->getCurrentRouteEdge(), veh->getRoute().end(), destinationRouteEdge);
2264 if (it == veh->getRoute().end()) {
2265 // find edge in the edges that were already passed
2266 it = std::find(veh->getRoute().begin(), veh->getRoute().end(), destinationRouteEdge);
2267 }
2268 if (it == veh->getRoute().end() ||
2269 // internal edge must continue the route
2270 (destinationEdge->isInternal() &&
2271 ((it + 1) == veh->getRoute().end()
2272 || l->getNextNormal() != *(it + 1)))) {
2273 throw TraCIException("Lane '" + laneID + "' is not on the route of vehicle '" + vehID + "'.");
2274 }
2275 Position oldPos = vehicle->getPosition();
2277 if (veh->getLane() != nullptr) {
2278 // correct odometer which gets incremented via onRemovalFromNet->leaveLane
2279 veh->addToOdometer(-veh->getLane()->getLength());
2281 } else {
2282 veh->setTentativeLaneAndPosition(l, pos);
2283 }
2284 const int oldRouteIndex = veh->getRoutePosition();
2285 const int newRouteIndex = (int)(it - veh->getRoute().begin());
2286 if (oldRouteIndex > newRouteIndex) {
2287 // more odometer correction needed
2288 veh->addToOdometer(-l->getLength());
2289 }
2290 veh->resetRoutePosition(newRouteIndex, veh->getParameter().departLaneProcedure);
2291 if (!veh->isOnRoad()) {
2294 }
2295 MSMoveReminder::Notification moveReminderReason;
2296 if (veh->hasDeparted()) {
2297 if (reason == MOVE_TELEPORT) {
2298 moveReminderReason = MSMoveReminder::NOTIFICATION_TELEPORT;
2299 } else if (reason == MOVE_NORMAL) {
2300 moveReminderReason = MSMoveReminder::NOTIFICATION_JUNCTION;
2301 } else if (reason == MOVE_AUTOMATIC) {
2302 Position newPos = l->geometryPositionAtOffset(pos);
2303 const double dist = newPos.distanceTo2D(oldPos);
2304 if (dist < SPEED2DIST(veh->getMaxSpeed())) {
2305 moveReminderReason = MSMoveReminder::NOTIFICATION_JUNCTION;
2306 } else {
2307 moveReminderReason = MSMoveReminder::NOTIFICATION_TELEPORT;
2308 }
2309 } else {
2310 throw TraCIException("Invalid moveTo reason '" + toString(reason) + "' for vehicle '" + vehID + "'.");
2311 }
2312 } else {
2313 moveReminderReason = MSMoveReminder::NOTIFICATION_DEPARTED;
2314 }
2315 l->forceVehicleInsertion(veh, pos, moveReminderReason);
2316 if (veh->getLaneChangeModel().isOpposite()) {
2318 }
2319}
2320
2321
2322void
2323Vehicle::setActionStepLength(const std::string& vehID, double actionStepLength, bool resetActionOffset) {
2324 if (actionStepLength < 0.0) {
2325 WRITE_ERROR("Invalid action step length (<0). Ignoring command setActionStepLength().");
2326 return;
2327 }
2328 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
2329 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
2330 if (veh == nullptr) {
2331 WRITE_ERROR("setActionStepLength not applicable for meso");
2332 return;
2333 }
2334
2335 if (actionStepLength == 0.) {
2336 veh->resetActionOffset();
2337 } else {
2338 veh->setActionStepLength(actionStepLength, resetActionOffset);
2339 }
2340}
2341
2342
2343void
2344Vehicle::setBoardingDuration(const std::string& vehID, double boardingDuration) {
2345 try {
2346 checkTimeBounds(boardingDuration);
2347 } catch (ProcessError&) {
2348 throw TraCIException("BoardingDuration parameter exceeds the time value range.");
2349 }
2351}
2352
2353
2354void
2355Vehicle::setImpatience(const std::string& vehID, double impatience) {
2356 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
2357 const double normalImpatience = vehicle->getImpatience();
2358 vehicle->getBaseInfluencer().setExtraImpatience(impatience - normalImpatience);
2359}
2360
2361
2362void
2363Vehicle::remove(const std::string& vehID, char reason) {
2364 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2366 switch (reason) {
2367 case REMOVE_TELEPORT:
2368 // XXX semantics unclear
2369 // n = MSMoveReminder::NOTIFICATION_TELEPORT;
2371 break;
2372 case REMOVE_PARKING:
2373 // XXX semantics unclear
2374 // n = MSMoveReminder::NOTIFICATION_PARKING;
2376 break;
2377 case REMOVE_ARRIVED:
2379 break;
2380 case REMOVE_VAPORIZED:
2382 break;
2385 break;
2386 default:
2387 throw TraCIException("Unknown removal status.");
2388 }
2389 if (veh->hasDeparted()) {
2390 veh->onRemovalFromNet(n);
2391 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
2392 if (microVeh != nullptr) {
2393 if (veh->getLane() != nullptr) {
2394 microVeh->getMutableLane()->removeVehicle(dynamic_cast<MSVehicle*>(veh), n);
2395 }
2397 }
2399 } else {
2402 }
2403}
2404
2405
2406void
2407Vehicle::setColor(const std::string& vehID, const TraCIColor& col) {
2409 p.color.set((unsigned char)col.r, (unsigned char)col.g, (unsigned char)col.b, (unsigned char)col.a);
2411}
2412
2413
2414void
2415Vehicle::setSpeedFactor(const std::string& vehID, double factor) {
2417}
2418
2419
2420void
2421Vehicle::setLine(const std::string& vehID, const std::string& line) {
2422 Helper::getVehicle(vehID)->getParameter().line = line;
2423}
2424
2425
2426void
2427Vehicle::setVia(const std::string& vehID, const std::vector<std::string>& edgeList) {
2428 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2429 try {
2430 // ensure edges exist
2431 ConstMSEdgeVector edges;
2432 MSEdge::parseEdgesList(edgeList, edges, "<via-edges>");
2433 } catch (ProcessError& e) {
2434 throw TraCIException(e.what());
2435 }
2436 veh->getParameter().via = edgeList;
2437}
2438
2439
2440void
2441Vehicle::setLength(const std::string& vehID, double length) {
2443}
2444
2445
2446void
2447Vehicle::setMaxSpeed(const std::string& vehID, double speed) {
2449}
2450
2451
2452void
2453Vehicle::setVehicleClass(const std::string& vehID, const std::string& clazz) {
2454 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2456 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
2457 if (microVeh != nullptr && microVeh->isOnRoad()) {
2458 microVeh->updateBestLanes(true);
2459 }
2460}
2461
2462
2463void
2464Vehicle::setShapeClass(const std::string& vehID, const std::string& clazz) {
2466}
2467
2468
2469void
2470Vehicle::setEmissionClass(const std::string& vehID, const std::string& clazz) {
2472}
2473
2474
2475void
2476Vehicle::setWidth(const std::string& vehID, double width) {
2478}
2479
2480
2481void
2482Vehicle::setHeight(const std::string& vehID, double height) {
2484}
2485
2486
2487void
2488Vehicle::setMass(const std::string& vehID, double mass) {
2490}
2491
2492
2493void
2494Vehicle::setMinGap(const std::string& vehID, double minGap) {
2495 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2496 veh->getSingularType().setMinGap(minGap);
2497 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
2498 if (microVeh != nullptr && microVeh->isOnRoad()) {
2499 microVeh->updateLaneBruttoSum();
2500 }
2501}
2502
2503
2504void
2505Vehicle::setAccel(const std::string& vehID, double accel) {
2507}
2508
2509
2510void
2511Vehicle::setDecel(const std::string& vehID, double decel) {
2512 VehicleType::setDecel(Helper::getVehicle(vehID)->getSingularType().getID(), decel);
2513}
2514
2515
2516void
2517Vehicle::setEmergencyDecel(const std::string& vehID, double decel) {
2518 VehicleType::setEmergencyDecel(Helper::getVehicle(vehID)->getSingularType().getID(), decel);
2519}
2520
2521
2522void
2523Vehicle::setApparentDecel(const std::string& vehID, double decel) {
2525}
2526
2527
2528void
2529Vehicle::setImperfection(const std::string& vehID, double imperfection) {
2530 Helper::getVehicle(vehID)->getSingularType().setImperfection(imperfection);
2531}
2532
2533
2534void
2535Vehicle::setTau(const std::string& vehID, double tau) {
2537}
2538
2539
2540void
2541Vehicle::setMinGapLat(const std::string& vehID, double minGapLat) {
2542 try {
2543 setParameter(vehID, "laneChangeModel.minGapLat", toString(minGapLat));
2544 } catch (TraCIException&) {
2545 // legacy behavior
2546 Helper::getVehicle(vehID)->getSingularType().setMinGapLat(minGapLat);
2547 }
2548}
2549
2550
2551void
2552Vehicle::setMaxSpeedLat(const std::string& vehID, double speed) {
2554}
2555
2556
2557void
2558Vehicle::setLateralAlignment(const std::string& vehID, const std::string& latAlignment) {
2559 double lao;
2561 if (SUMOVTypeParameter::parseLatAlignment(latAlignment, lao, lad)) {
2563 } else {
2564 throw TraCIException("Unknown value '" + latAlignment + "' when setting latAlignment for vehID '" + vehID + "';\n must be one of (\"right\", \"center\", \"arbitrary\", \"nice\", \"compact\", \"left\" or a float)");
2565 }
2566}
2567
2568
2569void
2570Vehicle::setParameter(const std::string& vehID, const std::string& key, const std::string& value) {
2571 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2572 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
2573 if (StringUtils::startsWith(key, "device.")) {
2574 StringTokenizer tok(key, ".");
2575 if (tok.size() < 3) {
2576 throw TraCIException("Invalid device parameter '" + key + "' for vehicle '" + vehID + "'");
2577 }
2578 try {
2579 veh->setDeviceParameter(tok.get(1), key.substr(tok.get(0).size() + tok.get(1).size() + 2), value);
2580 } catch (InvalidArgument& e) {
2581 throw TraCIException("Vehicle '" + vehID + "' does not support device parameter '" + key + "' (" + e.what() + ").");
2582 }
2583 } else if (StringUtils::startsWith(key, "laneChangeModel.")) {
2584 if (microVeh == nullptr) {
2585 throw TraCIException("Meso Vehicle '" + vehID + "' does not support laneChangeModel parameters.");
2586 }
2587 const std::string attrName = key.substr(16);
2588 if (attrName == toString(SUMO_ATTR_LCA_CONTRIGHT)) {
2589 // special case: not used within lcModel
2590 veh->getSingularType().setLcContRight(value);
2591 } else {
2592 try {
2593 microVeh->getLaneChangeModel().setParameter(attrName, value);
2594 } catch (InvalidArgument& e) {
2595 throw TraCIException("Vehicle '" + vehID + "' does not support laneChangeModel parameter '" + key + "' (" + e.what() + ").");
2596 }
2597 }
2598 } else if (StringUtils::startsWith(key, "carFollowModel.")) {
2599 if (microVeh == nullptr) {
2600 throw TraCIException("Meso Vehicle '" + vehID + "' does not support carFollowModel parameters.");
2601 }
2602 try {
2603 veh->setCarFollowModelParameter(key, value);
2604 } catch (InvalidArgument& e) {
2605 throw TraCIException("Vehicle '" + vehID + "' does not support carFollowModel parameter '" + key + "' (" + e.what() + ").");
2606 }
2607 } else if (StringUtils::startsWith(key, "junctionModel.")) {
2608 try {
2609 // use the whole key (including junctionModel prefix)
2610 veh->setJunctionModelParameter(key, value);
2611 } catch (InvalidArgument& e) {
2612 // error message includes id since it is also used for xml input
2613 throw TraCIException(e.what());
2614 }
2615 } else if (StringUtils::startsWith(key, "has.") && StringUtils::endsWith(key, ".device")) {
2616 StringTokenizer tok(key, ".");
2617 if (tok.size() != 3) {
2618 throw TraCIException("Invalid request for device status change. Expected format is 'has.DEVICENAME.device'");
2619 }
2620 const std::string deviceName = tok.get(1);
2621 bool create;
2622 try {
2623 create = StringUtils::toBool(value);
2624 } catch (BoolFormatException&) {
2625 throw TraCIException("Changing device status requires a 'true' or 'false'");
2626 }
2627 if (!create) {
2628 throw TraCIException("Device removal is not supported for device of type '" + deviceName + "'");
2629 }
2630 try {
2631 veh->createDevice(deviceName);
2632 } catch (InvalidArgument& e) {
2633 throw TraCIException("Cannot create vehicle device (" + std::string(e.what()) + ").");
2634 }
2635 } else {
2636 ((SUMOVehicleParameter&)veh->getParameter()).setParameter(key, value);
2637 }
2638}
2639
2640
2641void
2642Vehicle::highlight(const std::string& vehID, const TraCIColor& col, double size, const int alphaMax, const double duration, const int type) {
2643
2644 // NOTE: Code is duplicated in large parts in POI.cpp
2645 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2646
2647 // Center of the highlight circle
2648 Position center = veh->getPosition();
2649 const double l2 = veh->getLength() * 0.5;
2650 center.sub(cos(veh->getAngle())*l2, sin(veh->getAngle())*l2);
2651 // Size of the highlight circle
2652 if (size <= 0) {
2653 size = veh->getLength() * 0.7;
2654 }
2655 // Make polygon shape
2656 const unsigned int nPoints = 34;
2657 const PositionVector circlePV = GeomHelper::makeRing(size, size + 1., center, nPoints);
2658 TraCIPositionVector circle = Helper::makeTraCIPositionVector(circlePV);
2659
2660#ifdef DEBUG_DYNAMIC_SHAPES
2661 std::cout << SIMTIME << " Vehicle::highlight() for vehicle '" << vehID << "'\n"
2662 << " circle: " << circlePV << std::endl;
2663#endif
2664
2665 // Find a free polygon id
2666 int i = 0;
2667 std::string polyID = veh->getID() + "_hl" + toString(i);
2668 while (Polygon::exists(polyID)) {
2669 polyID = veh->getID() + "_hl" + toString(++i);
2670 }
2671 // Line width
2672 double lw = 0.;
2673 // Layer
2674 double lyr = 0.;
2675 if (MSNet::getInstance()->isGUINet()) {
2676 lyr = (double)GLO_VEHICLE + 0.01;
2677 lyr += (type + 1) / 257.;
2678 }
2679 // Make Polygon
2680 Polygon::addHighlightPolygon(vehID, type, polyID, circle, col, true, "highlight", (int)lyr, lw);
2681
2682 // Animation time line
2683 double maxAttack = 1.0; // maximal fade-in time
2684 std::vector<double> timeSpan;
2685 if (duration > 0.) {
2686 timeSpan = {0, MIN2(maxAttack, duration / 3.), 2.*duration / 3., duration};
2687 }
2688 // Alpha time line
2689 std::vector<double> alphaSpan;
2690 if (alphaMax > 0.) {
2691 alphaSpan = {0., (double) alphaMax, (double)(alphaMax) / 3., 0.};
2692 }
2693 // Attach dynamics
2694 Polygon::addDynamics(polyID, vehID, timeSpan, alphaSpan, false, true);
2695}
2696
2697void
2698Vehicle::dispatchTaxi(const std::string& vehID, const std::vector<std::string>& reservations) {
2699 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2700 MSDevice_Taxi* taxi = static_cast<MSDevice_Taxi*>(veh->getDevice(typeid(MSDevice_Taxi)));
2701 if (!veh->hasDeparted()) {
2702 throw TraCIException("Vehicle '" + vehID + "' has not yet departed");
2703 }
2704 if (taxi == nullptr) {
2705 throw TraCIException("Vehicle '" + vehID + "' is not a taxi");
2706 }
2708 if (dispatcher == nullptr) {
2709 throw TraCIException("Cannot dispatch taxi because no reservations have been made");
2710 }
2711 MSDispatch_TraCI* traciDispatcher = dynamic_cast<MSDispatch_TraCI*>(dispatcher);
2712 if (traciDispatcher == nullptr) {
2713 throw TraCIException("device.taxi.dispatch-algorithm 'traci' has not been loaded");
2714 }
2715 if (reservations.size() == 0) {
2716 throw TraCIException("No reservations have been specified for vehicle '" + vehID + "'");
2717 }
2718 try {
2719 traciDispatcher->interpretDispatch(taxi, reservations);
2720 } catch (InvalidArgument& e) {
2721 throw TraCIException("Could not interpret reservations for vehicle '" + vehID + "' (" + e.what() + ").");
2722 }
2723}
2724
2726
2727
2728void
2729Vehicle::subscribeLeader(const std::string& vehID, double dist, double begin, double end) {
2730 subscribe(vehID, std::vector<int>({ libsumo::VAR_LEADER }), begin, end,
2731 libsumo::TraCIResults({ {libsumo::VAR_LEADER, std::make_shared<libsumo::TraCIDouble>(dist)} }));
2732}
2733
2734
2735void
2736Vehicle::addSubscriptionFilterLanes(const std::vector<int>& lanes, bool noOpposite, double downstreamDist, double upstreamDist) {
2738 if (s != nullptr) {
2739 s->filterLanes = lanes;
2740 }
2741 if (noOpposite) {
2742 addSubscriptionFilterNoOpposite();
2743 }
2744 if (downstreamDist != INVALID_DOUBLE_VALUE) {
2745 addSubscriptionFilterDownstreamDistance(downstreamDist);
2746 }
2747 if (upstreamDist != INVALID_DOUBLE_VALUE) {
2748 addSubscriptionFilterUpstreamDistance(upstreamDist);
2749 }
2750}
2751
2752
2753void
2754Vehicle::addSubscriptionFilterNoOpposite() {
2756}
2757
2758
2759void
2760Vehicle::addSubscriptionFilterDownstreamDistance(double dist) {
2762 if (s != nullptr) {
2763 s->filterDownstreamDist = dist;
2764 }
2765}
2766
2767
2768void
2769Vehicle::addSubscriptionFilterUpstreamDistance(double dist) {
2771 if (s != nullptr) {
2772 s->filterUpstreamDist = dist;
2773 }
2774}
2775
2776
2777void
2778Vehicle::addSubscriptionFilterCFManeuver(double downstreamDist, double upstreamDist) {
2779 addSubscriptionFilterLeadFollow(std::vector<int>({0}));
2780 if (downstreamDist != INVALID_DOUBLE_VALUE) {
2781 addSubscriptionFilterDownstreamDistance(downstreamDist);
2782 }
2783 if (upstreamDist != INVALID_DOUBLE_VALUE) {
2784 addSubscriptionFilterUpstreamDistance(upstreamDist);
2785 }
2786
2787}
2788
2789
2790void
2791Vehicle::addSubscriptionFilterLCManeuver(int direction, bool noOpposite, double downstreamDist, double upstreamDist) {
2792 std::vector<int> lanes;
2793 if (direction == INVALID_INT_VALUE) {
2794 // Using default: both directions
2795 lanes = std::vector<int>({-1, 0, 1});
2796 } else if (direction != -1 && direction != 1) {
2797 WRITE_WARNINGF(TL("Ignoring lane change subscription filter with non-neighboring lane offset direction=%."), direction);
2798 } else {
2799 lanes = std::vector<int>({0, direction});
2800 }
2801 addSubscriptionFilterLeadFollow(lanes);
2802 if (noOpposite) {
2803 addSubscriptionFilterNoOpposite();
2804 }
2805 if (downstreamDist != INVALID_DOUBLE_VALUE) {
2806 addSubscriptionFilterDownstreamDistance(downstreamDist);
2807 }
2808 if (upstreamDist != INVALID_DOUBLE_VALUE) {
2809 addSubscriptionFilterUpstreamDistance(upstreamDist);
2810 }
2811}
2812
2813
2814void
2815Vehicle::addSubscriptionFilterLeadFollow(const std::vector<int>& lanes) {
2817 addSubscriptionFilterLanes(lanes);
2818}
2819
2820
2821void
2822Vehicle::addSubscriptionFilterTurn(double downstreamDist, double foeDistToJunction) {
2824 if (downstreamDist != INVALID_DOUBLE_VALUE) {
2825 addSubscriptionFilterDownstreamDistance(downstreamDist);
2826 }
2827 if (foeDistToJunction != INVALID_DOUBLE_VALUE) {
2828 s->filterFoeDistToJunction = foeDistToJunction;
2829 }
2830}
2831
2832
2833void
2834Vehicle::addSubscriptionFilterVClass(const std::vector<std::string>& vClasses) {
2836 if (s != nullptr) {
2837 s->filterVClasses = parseVehicleClasses(vClasses);
2838 }
2839}
2840
2841
2842void
2843Vehicle::addSubscriptionFilterVType(const std::vector<std::string>& vTypes) {
2845 if (s != nullptr) {
2846 s->filterVTypes.insert(vTypes.begin(), vTypes.end());
2847 }
2848}
2849
2850
2851void
2852Vehicle::addSubscriptionFilterFieldOfVision(double openingAngle) {
2854 if (s != nullptr) {
2855 s->filterFieldOfVisionOpeningAngle = openingAngle;
2856 }
2857}
2858
2859
2860void
2861Vehicle::addSubscriptionFilterLateralDistance(double lateralDist, double downstreamDist, double upstreamDist) {
2863 if (s != nullptr) {
2864 s->filterLateralDist = lateralDist;
2865 }
2866 if (downstreamDist != INVALID_DOUBLE_VALUE) {
2867 addSubscriptionFilterDownstreamDistance(downstreamDist);
2868 }
2869 if (upstreamDist != INVALID_DOUBLE_VALUE) {
2870 addSubscriptionFilterUpstreamDistance(upstreamDist);
2871 }
2872}
2873
2874
2875void
2876Vehicle::storeShape(const std::string& id, PositionVector& shape) {
2877 shape.push_back(Helper::getVehicle(id)->getPosition());
2878}
2879
2880
2881std::shared_ptr<VariableWrapper>
2882Vehicle::makeWrapper() {
2883 return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
2884}
2885
2886
2887bool
2888Vehicle::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
2889 switch (variable) {
2890 case TRACI_ID_LIST:
2891 return wrapper->wrapStringList(objID, variable, getIDList());
2892 case ID_COUNT:
2893 return wrapper->wrapInt(objID, variable, getIDCount());
2894 case VAR_POSITION:
2895 return wrapper->wrapPosition(objID, variable, getPosition(objID));
2896 case VAR_POSITION3D:
2897 return wrapper->wrapPosition(objID, variable, getPosition(objID, true));
2898 case VAR_ANGLE:
2899 return wrapper->wrapDouble(objID, variable, getAngle(objID));
2900 case VAR_SPEED:
2901 return wrapper->wrapDouble(objID, variable, getSpeed(objID));
2902 case VAR_SPEED_LAT:
2903 return wrapper->wrapDouble(objID, variable, getLateralSpeed(objID));
2904 case VAR_ROAD_ID:
2905 return wrapper->wrapString(objID, variable, getRoadID(objID));
2907 return wrapper->wrapDouble(objID, variable, getSpeedWithoutTraCI(objID));
2908 case VAR_SLOPE:
2909 return wrapper->wrapDouble(objID, variable, getSlope(objID));
2910 case VAR_LANE_ID:
2911 return wrapper->wrapString(objID, variable, getLaneID(objID));
2912 case VAR_SHADOW_LANE_ID:
2913 return wrapper->wrapString(objID, variable, getShadowLaneID(objID));
2914 case VAR_LANE_INDEX:
2915 return wrapper->wrapInt(objID, variable, getLaneIndex(objID));
2916 case VAR_SEGMENT_ID:
2917 return wrapper->wrapString(objID, variable, getSegmentID(objID));
2918 case VAR_SEGMENT_INDEX:
2919 return wrapper->wrapInt(objID, variable, getSegmentIndex(objID));
2920 case VAR_TYPE:
2921 return wrapper->wrapString(objID, variable, getTypeID(objID));
2922 case VAR_ROUTE_ID:
2923 return wrapper->wrapString(objID, variable, getRouteID(objID));
2924 case VAR_DEPARTURE:
2925 return wrapper->wrapDouble(objID, variable, getDeparture(objID));
2926 case VAR_DEPART_DELAY:
2927 return wrapper->wrapDouble(objID, variable, getDepartDelay(objID));
2928 case VAR_ROUTE_INDEX:
2929 return wrapper->wrapInt(objID, variable, getRouteIndex(objID));
2930 case VAR_COLOR:
2931 return wrapper->wrapColor(objID, variable, getColor(objID));
2932 case VAR_LANEPOSITION:
2933 return wrapper->wrapDouble(objID, variable, getLanePosition(objID));
2934 case VAR_ARRIVALPOS:
2935 return wrapper->wrapDouble(objID, variable, getArrivalPos(objID));
2937 return wrapper->wrapDouble(objID, variable, getLateralLanePosition(objID));
2938 case VAR_CO2EMISSION:
2939 return wrapper->wrapDouble(objID, variable, getCO2Emission(objID));
2940 case VAR_COEMISSION:
2941 return wrapper->wrapDouble(objID, variable, getCOEmission(objID));
2942 case VAR_HCEMISSION:
2943 return wrapper->wrapDouble(objID, variable, getHCEmission(objID));
2944 case VAR_PMXEMISSION:
2945 return wrapper->wrapDouble(objID, variable, getPMxEmission(objID));
2946 case VAR_NOXEMISSION:
2947 return wrapper->wrapDouble(objID, variable, getNOxEmission(objID));
2949 return wrapper->wrapDouble(objID, variable, getFuelConsumption(objID));
2950 case VAR_NOISEEMISSION:
2951 return wrapper->wrapDouble(objID, variable, getNoiseEmission(objID));
2953 return wrapper->wrapDouble(objID, variable, getElectricityConsumption(objID));
2954 case VAR_PERSON_NUMBER:
2955 return wrapper->wrapInt(objID, variable, getPersonNumber(objID));
2957 return wrapper->wrapInt(objID, variable, getPersonCapacity(objID));
2959 return wrapper->wrapDouble(objID, variable, getBoardingDuration(objID));
2961 return wrapper->wrapStringList(objID, variable, getPersonIDList(objID));
2962 case VAR_WAITING_TIME:
2963 return wrapper->wrapDouble(objID, variable, getWaitingTime(objID));
2965 return wrapper->wrapDouble(objID, variable, getAccumulatedWaitingTime(objID));
2966 case VAR_EDGE_TRAVELTIME: {
2967 StoHelp::readCompound(*paramData);
2968 const double time = StoHelp::readTypedDouble(*paramData);
2969 return wrapper->wrapDouble(objID, variable, getAdaptedTraveltime(objID, time, StoHelp::readTypedString(*paramData)));
2970 }
2971 case VAR_EDGE_EFFORT: {
2972 StoHelp::readCompound(*paramData);
2973 const double time = StoHelp::readTypedDouble(*paramData);
2974 return wrapper->wrapDouble(objID, variable, getEffort(objID, time, StoHelp::readTypedString(*paramData)));
2975 }
2976 case VAR_ROUTE_VALID:
2977 return wrapper->wrapInt(objID, variable, isRouteValid(objID));
2978 case VAR_EDGES:
2979 return wrapper->wrapStringList(objID, variable, getRoute(objID));
2980 case VAR_SIGNALS:
2981 return wrapper->wrapInt(objID, variable, getSignals(objID));
2982 case VAR_BEST_LANES:
2983 return wrapper->wrapBestLanesDataVector(objID, variable, getBestLanes(objID));
2984 case VAR_NEXT_LINKS:
2985 return wrapper->wrapConnectionVector(objID, variable, getNextLinks(objID));
2986 case VAR_STOPSTATE:
2987 return wrapper->wrapInt(objID, variable, getStopState(objID));
2988 case VAR_DISTANCE:
2989 return wrapper->wrapDouble(objID, variable, getDistance(objID));
2991 return wrapper->wrapDouble(objID, variable, getReferenceDistance(objID));
2992 case VAR_ALLOWED_SPEED:
2993 return wrapper->wrapDouble(objID, variable, getAllowedSpeed(objID));
2994 case VAR_SPEED_FACTOR:
2995 return wrapper->wrapDouble(objID, variable, getSpeedFactor(objID));
2996 case VAR_SPEEDSETMODE:
2997 return wrapper->wrapInt(objID, variable, getSpeedMode(objID));
2999 return wrapper->wrapInt(objID, variable, getLaneChangeMode(objID));
3000 case VAR_ROUTING_MODE:
3001 return wrapper->wrapInt(objID, variable, getRoutingMode(objID));
3002 case VAR_LINE:
3003 return wrapper->wrapString(objID, variable, getLine(objID));
3004 case VAR_VIA:
3005 return wrapper->wrapStringList(objID, variable, getVia(objID));
3006 case VAR_ACCELERATION:
3007 return wrapper->wrapDouble(objID, variable, getAcceleration(objID));
3008 case VAR_LASTACTIONTIME:
3009 return wrapper->wrapDouble(objID, variable, getLastActionTime(objID));
3010 case VAR_STOP_DELAY:
3011 return wrapper->wrapDouble(objID, variable, getStopDelay(objID));
3012 case VAR_IMPATIENCE:
3013 return wrapper->wrapDouble(objID, variable, getImpatience(objID));
3015 return wrapper->wrapDouble(objID, variable, getStopArrivalDelay(objID));
3016 case VAR_TIMELOSS:
3017 return wrapper->wrapDouble(objID, variable, getTimeLoss(objID));
3018 case VAR_MINGAP_LAT:
3019 return wrapper->wrapDouble(objID, variable, getMinGapLat(objID));
3020 case VAR_LEADER:
3021 return wrapper->wrapStringDoublePair(objID, variable, getLeader(objID, StoHelp::readTypedDouble(*paramData)));
3022 case VAR_FOLLOWER:
3023 return wrapper->wrapStringDoublePair(objID, variable, getFollower(objID, StoHelp::readTypedDouble(*paramData)));
3024 case VAR_LOADED_LIST:
3025 return wrapper->wrapStringList(objID, variable, getLoadedIDList());
3027 return wrapper->wrapStringList(objID, variable, getTeleportingIDList());
3028 case VAR_FOLLOW_SPEED: {
3029 StoHelp::readCompound(*paramData);
3030 const double speed = StoHelp::readTypedDouble(*paramData);
3031 const double gap = StoHelp::readTypedDouble(*paramData);
3032 const double leaderSpeed = StoHelp::readTypedDouble(*paramData);
3033 const double leaderMaxDecel = StoHelp::readTypedDouble(*paramData);
3034 return wrapper->wrapDouble(objID, variable, getFollowSpeed(objID, speed, gap, leaderSpeed, leaderMaxDecel, StoHelp::readTypedString(*paramData)));
3035 }
3036 case VAR_SECURE_GAP: {
3037 StoHelp::readCompound(*paramData);
3038 const double speed = StoHelp::readTypedDouble(*paramData);
3039 const double leaderSpeed = StoHelp::readTypedDouble(*paramData);
3040 const double leaderMaxDecel = StoHelp::readTypedDouble(*paramData);
3041 return wrapper->wrapDouble(objID, variable, getSecureGap(objID, speed, leaderSpeed, leaderMaxDecel, StoHelp::readTypedString(*paramData)));
3042 }
3043 case VAR_STOP_SPEED: {
3044 StoHelp::readCompound(*paramData);
3045 const double speed = StoHelp::readTypedDouble(*paramData);
3046 return wrapper->wrapDouble(objID, variable, getStopSpeed(objID, speed, StoHelp::readTypedDouble(*paramData)));
3047 }
3048 case VAR_FOES:
3049 return wrapper->wrapJunctionFoeVector(objID, variable, getJunctionFoes(objID, StoHelp::readTypedDouble(*paramData)));
3050 case VAR_NEIGHBORS:
3051 return wrapper->wrapStringDoublePairList(objID, variable, getNeighbors(objID, StoHelp::readTypedByte(*paramData)));
3052 case CMD_CHANGELANE:
3053 return wrapper->wrapIntPair(objID, variable, getLaneChangeState(objID, StoHelp::readTypedInt(*paramData)));
3054 case VAR_STOP_PARAMETER: {
3055 const int count = StoHelp::readCompound(*paramData);
3056 const int nextStopIndex = StoHelp::readTypedInt(*paramData);
3057 const std::string param = StoHelp::readTypedString(*paramData);
3058 const bool customParam = count == 3 && StoHelp::readTypedByte(*paramData) != 0;
3059 return wrapper->wrapString(objID, variable, getStopParameter(objID, nextStopIndex, param, customParam));
3060 }
3061 case VAR_NEXT_TLS:
3062 return wrapper->wrapNextTLSDataVector(objID, variable, getNextTLS(objID));
3063 case VAR_NEXT_STOPS:
3064 return wrapper->wrapNextStopDataVector(objID, variable, getNextStops(objID));
3065 case VAR_NEXT_STOPS2:
3066 return wrapper->wrapNextStopDataVector(objID, variable, getStops(objID, StoHelp::readTypedInt(*paramData)));
3067 case DISTANCE_REQUEST: {
3068 TraCIRoadPosition roadPos;
3069 Position pos;
3070 if (Helper::readDistanceRequest(*paramData, roadPos, pos) == libsumo::POSITION_ROADMAP) {
3071 return wrapper->wrapDouble(objID, variable, getDrivingDistance(objID, roadPos.edgeID, roadPos.pos, roadPos.laneIndex));
3072 }
3073 return wrapper->wrapDouble(objID, variable, getDrivingDistance2D(objID, pos.x(), pos.y()));
3074 }
3075 case VAR_TAXI_FLEET:
3076 return wrapper->wrapStringList(objID, variable, getTaxiFleet(StoHelp::readTypedInt(*paramData)));
3077 case VAR_PARAMETER:
3078 return wrapper->wrapString(objID, variable, getParameter(objID, StoHelp::readTypedString(*paramData)));
3080 return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, StoHelp::readTypedString(*paramData)));
3081 default:
3082 return VehicleType::handleVariableWithID(objID, getTypeID(objID), variable, wrapper, paramData);
3083 }
3084}
3085
3086
3087}
3088
3089
3090/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
@ GLO_VEHICLE
a vehicle
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:75
std::vector< MSEdge * > MSEdgeVector
Definition MSEdge.h:74
std::pair< const MSVehicle *, double > CLeaderDist
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition MSRoute.h:57
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:287
#define WRITE_ERROR(msg)
Definition MsgHandler.h:295
#define WRITE_WARNING(msg)
Definition MsgHandler.h:286
#define TL(string)
Definition MsgHandler.h:304
#define TLF(string,...)
Definition MsgHandler.h:306
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.h:32
void checkTimeBounds(const double time)
check the valid SUMOTime range of double input and throw an error if out of bounds
Definition SUMOTime.cpp:188
SUMOTime DELTA_T
Definition SUMOTime.cpp:39
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:47
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 SPEED2DIST(x)
Definition SUMOTime.h:48
constexpr SUMOTime TIME2STEPS(double x)
Definition SUMOTime.h:60
#define SUMOTime_MAX
Definition SUMOTime.h:34
#define SIMTIME
Definition SUMOTime.h:70
LatAlignmentDefinition
Possible ways to choose the lateral alignment, i.e., how vehicles align themselves within their lane.
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
SUMOVehicleShape getVehicleShapeID(const std::string &name)
Returns the class id of the shape class given by its name.
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
std::string getVehicleShapeName(SUMOVehicleShape id)
Returns the class name of the shape class given by its id.
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
const long long int VEHPARS_ARRIVALSPEED_SET
const long long int VEHPARS_DEPARTPOSLAT_SET
const long long int VEHPARS_ARRIVALPOSLAT_SET
const long long int VEHPARS_PERSON_NUMBER_SET
const long long int VEHPARS_DEPARTSPEED_SET
const int STOP_ARRIVAL_SET
const int STOP_DURATION_SET
const int STOP_POSLAT_SET
const int STOP_EXPECTED_SET
const long long int VEHPARS_FORCE_REROUTE
const int STOP_SPEED_SET
const int STOP_JUMP_UNTIL_SET
const int STOP_UNTIL_SET
const int STOP_LINE_SET
const int STOP_PARKING_SET
const int STOP_TRIP_ID_SET
const long long int VEHPARS_COLOR_SET
std::vector< SUMOVehicleParameter::Stop > StopParVector
const int STOP_PERMITTED_SET
const int STOP_SPLIT_SET
const long long int VEHPARS_TO_TAZ_SET
const long long int VEHPARS_ARRIVALLANE_SET
const long long int VEHPARS_DEPARTLANE_SET
const int STOP_START_SET
const long long int VEHPARS_DEPARTPOS_SET
const int STOP_JOIN_SET
const long long int VEHPARS_ARRIVALPOS_SET
const int STOP_EXTENSION_SET
const long long int VEHPARS_FROM_TAZ_SET
const int STOP_ENDED_SET
const long long int VEHPARS_SPEEDFACTOR_SET
const int STOP_TRIGGER_SET
const long long int VEHPARS_VTYPE_SET
const int STOP_JUMP_SET
const int STOP_ONDEMAND_SET
const int STOP_END_SET
const int STOP_STARTED_SET
const int STOP_EXPECTED_CONTAINERS_SET
const long long int VEHPARS_LINE_SET
const long long int VEHPARS_INSERTION_CHECKS_SET
@ GIVEN
The time is given.
@ NOW
The vehicle is discarded if emission fails (not fully implemented yet)
@ CONTAINER_TRIGGERED
The departure is container triggered.
@ TRIGGERED
The departure is person triggered.
@ LCA_UNKNOWN
The action has not been determined.
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_PARKING
@ SUMO_ATTR_EXTENSION
@ SUMO_ATTR_LANE
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_STARTED
@ SUMO_ATTR_CONTAINER_STOP
@ SUMO_ATTR_PARKING_AREA
@ SUMO_ATTR_EDGE
@ SUMO_ATTR_BUS_STOP
@ SUMO_ATTR_TRAIN_STOP
@ SUMO_ATTR_ENDPOS
@ SUMO_ATTR_SPLIT
@ SUMO_ATTR_ACTTYPE
@ SUMO_ATTR_POSITION_LAT
@ SUMO_ATTR_EXPECTED
@ SUMO_ATTR_LINE
@ SUMO_ATTR_CHARGING_STATION
@ SUMO_ATTR_ENDED
@ SUMO_ATTR_ONDEMAND
@ SUMO_ATTR_LCA_CONTRIGHT
@ SUMO_ATTR_INDEX
@ SUMO_ATTR_ARRIVAL
@ SUMO_ATTR_TRIP_ID
@ SUMO_ATTR_PERMITTED
@ SUMO_ATTR_JOIN
@ SUMO_ATTR_JUMP
@ SUMO_ATTR_EXPECTED_CONTAINERS
@ SUMO_ATTR_UNTIL
@ SUMO_ATTR_JUMP_UNTIL
@ SUMO_ATTR_TRIGGERED
@ SUMO_ATTR_DURATION
const double INVALID_DOUBLE
invalid double
Definition StdDefs.h:68
T MIN2(T a, T b)
Definition StdDefs.h:80
T MAX2(T a, T b)
Definition StdDefs.h:86
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition ToString.h:322
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOM)
Definition TraCIDefs.h:77
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition TraCIDefs.h:124
double getParameter(const int index) const
Returns the nth parameter of this distribution.
static PositionVector makeRing(const double radius1, const double radius2, const Position &center, unsigned int nPoints)
static const double INVALID_OFFSET
a value to signify offsets outside the range of [0, Line.length()]
Definition GeomHelper.h:50
static double naviDegree(const double angle)
A vehicle from the mesoscopic point of view.
Definition MEVehicle.h:42
int getQueIndex() const
Returns the index of the que the vehicle is in.
Definition MEVehicle.h:268
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves its current segment.
Definition MEVehicle.h:218
MSLane * getShadowLane() const
Returns the lane the vehicle's shadow is on during continuous/sublane lane change.
virtual double getSafetyFactor() const
return factor for modifying the safety constraints of the car-following model
void changedToOpposite()
called when a vehicle changes between lanes in opposite directions
virtual void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this laneChangeModel. Throw exception for unsupported key
void setExtraImpatience(double value)
Sets routing behavior.
The base class for microscopic and mesoscopic vehicles.
double getMaxSpeed() const
Returns the maximum speed (the minimum of desired and technical maximum speed)
double getImpatience() const
Returns this vehicles impatience.
void resetRoutePosition(int index, DepartLaneDefinition departLaneProcedure)
reset index of edge within route
bool replaceStop(int nextStopIndex, SUMOVehicleParameter::Stop stop, const std::string &info, bool teleport, std::string &errorMsg)
void setChosenSpeedFactor(const double factor)
Returns the precomputed factor by which the driver wants to be faster than the speed limit.
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.
virtual double getStopDelay() const
Returns the estimated public transport stop (departure) delay in seconds.
bool rerouteBetweenStops(int nextStopIndex, const std::string &info, bool teleport, std::string &errorMsg)
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
double getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit.
virtual BaseInfluencer & getBaseInfluencer()=0
Returns the velocity/lane influencer.
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.
virtual double getTimeLossSeconds() const
Returns the time loss in seconds.
double getOdometer() const
Returns the distance that was already driven by this vehicle.
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
const MSRouteIterator & getCurrentRouteEdge() const
Returns an iterator pointing to the current edge in this vehicles route.
bool hasValidRoute(std::string &msg, ConstMSRoutePtr route=0) const
Validates the current or given route.
virtual void onRemovalFromNet(const MSMoveReminder::Notification)
Called when the vehicle is removed from the network.
double getLength() const
Returns the vehicle's length.
bool isParking() const
Returns whether the vehicle is parking.
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.
void setJunctionModelParameter(const std::string &key, const std::string &value)
set individual junction model parameter (not type related)
bool hasDeparted() const
Returns whether this vehicle has already departed.
const std::list< MSStop > & getStops() const
SUMOTime getDeparture() const
Returns this vehicle's real departure time.
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...
virtual std::pair< const MSVehicle *const, double > getLeader(double dist=0, bool considerCrossingFoes=true) const
Returns the leader of the vehicle looking for a fixed distance.
bool hasStops() const
Returns whether the vehicle has to stop somewhere.
void addToOdometer(double value)
Manipulate the odometer.
const MSStop & getNextStop() const
std::string getPrefixedParameter(const std::string &key, std::string &error) const
retrieve parameters of devices, models and the vehicle itself
SUMOVehicleClass getVClass() const
Returns the vehicle's access class.
virtual double getStopArrivalDelay() const
Returns the estimated public transport stop arrival delay in seconds.
MSStop & getStop(int nextStopIndex)
virtual std::pair< const MSVehicle *const, double > getFollower(double dist=0) const
Returns the follower of the vehicle looking for a fixed distance.
bool insertStop(int nextStopIndex, SUMOVehicleParameter::Stop stop, const std::string &info, bool teleport, std::string &errorMsg)
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.
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
const StopParVector & getPastStops() const
double getEmissions() const
Returns emissions of the current state The value is always per 1s, so multiply by step length if nece...
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT() const
returns the router according to the current routing mode of the vehicle
virtual bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
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.
int getRNGIndex() const
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
virtual void replaceVehicleType(const MSVehicleType *type)
Replaces the current vehicle type by the one given.
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.
double getEmergencyDecel() const
Get the vehicle type's maximal physically possible deceleration [m/s^2].
Definition MSCFModel.h:293
@ FUTURE
the return value is used for calculating future speeds
Definition MSCFModel.h:99
virtual double getSecureGap(const MSVehicle *const veh, const MSVehicle *const, const double speed, const double leaderSpeed, const double leaderMaxDecel) const
Returns the minimum gap to reserve if the leader is braking at maximum (>=0)
double getApparentDecel() const
Get the vehicle type's apparent deceleration [m/s^2] (the one regarded by its followers.
Definition MSCFModel.h:301
double getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
Definition MSCFModel.h:277
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time tau (i....
Definition MSCFModel.h:424
virtual double getImperfection() const
Get the driver's imperfection.
Definition MSCFModel.h:347
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
Definition MSCFModel.h:285
virtual double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0, const CalcReason usage=CalcReason::CURRENT) const =0
Computes the vehicle's follow speed (no dawdling)
double stopSpeed(const MSVehicle *const veh, const double speed, double gap, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling)
Definition MSCFModel.h:189
virtual double getHeadwayTime() const
Get the driver's desired headway [s].
Definition MSCFModel.h:355
A device which collects info on the vehicle trip (mainly on departure and arrival)
static const std::vector< MSDevice_Taxi * > & getFleet()
static MSDispatch * getDispatchAlgorithm()
A dispatch algorithm that services customers in reservation order and always sends the closest availa...
void interpretDispatch(MSDevice_Taxi *taxi, const std::vector< std::string > &reservationsIDs)
trigger taxi dispatch.
An algorithm that performs distpach for a taxi fleet.
Definition MSDispatch.h:114
A road/street connecting two junctions.
Definition MSEdge.h:78
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition MSEdge.cpp:1157
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition MSEdge.h:169
static void parseEdgesList(const std::string &desc, ConstMSEdgeVector &into, const std::string &rid)
Parses the given string assuming it contains a list of edge ids divided by spaces.
Definition MSEdge.cpp:1183
const 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
double getLength() const
return the length of the edge
Definition MSEdge.h:695
double getDistanceAt(double pos) const
Returns the kilometrage/mileage at the given offset along the edge.
Definition MSEdge.cpp:1747
bool isInternal() const
return whether this edge is an internal edge
Definition MSEdge.h:270
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary....
Definition MSEdge.cpp:1117
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition MSEdge.cpp:1254
const MSEdge * getNormalBefore() const
if this edge is an internal edge, return its first normal predecessor, otherwise the edge itself
Definition MSEdge.cpp:1007
bool retrieveExistingTravelTime(const MSEdge *const e, const double t, double &value) const
Returns a travel time for an edge and time if stored.
bool knowsTravelTime(const MSEdge *const e) const
Returns the information whether any travel time is known for the given edge.
void addTravelTime(const MSEdge *const e, double begin, double end, double value)
Adds a travel time information for an edge and a time span.
void removeEffort(const MSEdge *const e)
Removes the effort information for an edge.
bool knowsEffort(const MSEdge *const e) const
Returns the information whether any effort is known for the given edge.
void addEffort(const MSEdge *const e, double begin, double end, double value)
Adds an effort information for an edge and a time span.
bool retrieveExistingEffort(const MSEdge *const e, const double t, double &value) const
Returns an effort for an edge and time if stored.
void removeTravelTime(const MSEdge *const e)
Removes the travel time information for an edge.
static bool gCheckRoutes
Definition MSGlobals.h:91
static double gLateralResolution
Definition MSGlobals.h:100
static bool gSemiImplicitEulerUpdate
Definition MSGlobals.h:53
void alreadyDeparted(SUMOVehicle *veh)
stops trying to emit the given vehicle (because it already departed)
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
virtual const MSJunctionLogic * getLogic() const
Definition MSJunction.h:141
virtual const MSLogicJunction::LinkBits & getResponseFor(int linkIndex) const
Returns the response for the given link.
Representation of a lane in the micro simulation.
Definition MSLane.h:84
MSLane * getParallelLane(int offset, bool includeOpposite=true) const
Returns the lane with the given offset parallel to this one or 0 if it does not exist.
Definition MSLane.cpp:2905
virtual MSVehicle * removeVehicle(MSVehicle *remVehicle, MSMoveReminder::Notification notification, bool notify=true)
Definition MSLane.cpp:2887
static std::vector< MSLink * >::const_iterator succLinkSec(const SUMOVehicle &veh, int nRouteSuccs, const MSLane &succLinkSource, const std::vector< MSLane * > &conts)
Definition MSLane.cpp:2750
MSLeaderDistanceInfo getFollowersOnConsecutive(const MSVehicle *ego, double backOffset, bool allSublanes, double searchDist=-1, MinorLinkMode mLinkMode=FOLLOW_ALWAYS, bool maxSearchDist=false) const
return the sublane followers with the largest missing rear gap among all predecessor lanes (within di...
Definition MSLane.cpp:3859
void forceVehicleInsertion(MSVehicle *veh, double pos, MSMoveReminder::Notification notification, double posLat=0)
Inserts the given vehicle at the given position.
Definition MSLane.cpp:1435
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
Definition MSLane.h:602
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
void addLeaders(const MSVehicle *vehicle, double vehPos, MSLeaderDistanceInfo &result, bool oppositeDirection=false)
get leaders for ego on the given lane
Definition MSLane.cpp:4229
double getLength() const
Returns the lane's length.
Definition MSLane.h:632
bool isLinkEnd(std::vector< MSLink * >::const_iterator &i) const
Definition MSLane.h:881
int getIndex() const
Returns the lane's index.
Definition MSLane.h:668
double getOppositePos(double pos) const
return the corresponding position on the opposite lane
Definition MSLane.cpp:4477
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition MSLane.cpp:2538
bool isInternal() const
Definition MSLane.cpp:2669
virtual const PositionVector & getShape(bool) const
Definition MSLane.h:294
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:790
double getWidth() const
Returns the lane's width.
Definition MSLane.h:661
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
Definition MSLane.h:750
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition MSLane.h:561
saves leader/follower vehicles and their distances relative to an ego vehicle
void fixOppositeGaps(bool isFollower)
subtract vehicle length from all gaps if the leader vehicle is driving in the opposite direction
virtual int addLeader(const MSVehicle *veh, double gap, double latOffset=0, int sublane=-1)
int numSublanes() const
bool hasVehicles() const
Notification
Definition of a vehicle state.
@ NOTIFICATION_VAPORIZED_TRACI
The vehicle got removed via TraCI.
@ NOTIFICATION_ARRIVED
The vehicle arrived at its destination (is deleted)
@ NOTIFICATION_TELEPORT_ARRIVED
The vehicle was teleported out of the net.
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
@ NOTIFICATION_TELEPORT
The vehicle is being teleported.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:201
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:334
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition MSNet.h:455
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:402
const ConstMSEdgeVector & getEdges() const
Definition MSRoute.h:128
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition MSRoute.cpp:79
static bool dictionary(const std::string &id, ConstMSRoutePtr route)
Adds a route to the dictionary.
Definition MSRoute.cpp:116
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition MSRoute.cpp:73
double getDistanceBetween(double fromPos, double toPos, const MSLane *fromLane, const MSLane *toLane, int routePosition=0) const
Compute the distance between 2 given edges on this route, optionally including the length of internal...
Definition MSRoute.cpp:323
const MSLane * lane
The lane to stop at (microsim only)
Definition MSStop.h:50
void initPars(const SUMOVehicleParameter::Stop &stopPar)
initialize attributes from the given stop parameters
Definition MSStop.cpp:151
int getStateFlagsOld() const
return flags as used by Vehicle::getStopState
Definition MSStop.cpp:167
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
SUMOTime duration
The stopping duration.
Definition MSStop.h:67
const SUMOVehicleParameter::Stop pars
The stop parameter.
Definition MSStop.h:65
void setLaneChangeMode(int value)
Sets lane changing behavior.
void deactivateGapController()
Deactivates the gap control.
void setSpeedMode(int speedMode)
Sets speed-constraining behaviors.
void setLaneTimeLine(const std::vector< std::pair< SUMOTime, int > > &laneTimeLine)
Sets a new lane timeline.
void setSublaneChange(double latDist)
Sets a new sublane-change request.
void setSignals(int signals)
Definition MSVehicle.h:1599
void setSpeedTimeLine(const std::vector< std::pair< SUMOTime, double > > &speedTimeLine)
Sets a new velocity timeline.
void activateGapController(double originalTau, double newTimeHeadway, double newSpaceHeadway, double duration, double changeRate, double maxDecel, MSVehicle *refVeh=nullptr)
Activates the gap control with the given parameters,.
The class responsible for building and deletion of vehicles.
void removePending()
Removes a vehicle after it has ended.
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, SumoRNG *rng=nullptr, bool readOnly=false)
Returns the named vehicle type or a sample from the named distribution.
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, ConstMSRoutePtr route, MSVehicleType *type, const bool ignoreStopErrors, const VehicleDefinitionSource source=ROUTEFILE, bool addRouteStops=true)
Builds a vehicle, increases the number of built vehicles.
void scheduleVehicleRemoval(SUMOVehicle *veh, bool checkDuplicate=false)
Removes a vehicle after it has ended.
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false, bool wasKept=false)
Deletes the vehicle.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
void updateBestLanes(bool forceRebuild=false, const MSLane *startLane=0)
computes the best lanes to use in order to continue the route
const std::vector< const MSLane * > getUpcomingLanesUntil(double distance) const
Returns the upcoming (best followed by default 0) sequence of lanes to continue the route starting at...
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition MSVehicle.h:605
SUMOTime getLastActionTime() const
Returns the time of the vehicle's last action point.
Definition MSVehicle.h:541
void setTentativeLaneAndPosition(MSLane *lane, double pos, double posLat=0)
set tentative lane and position during insertion to ensure that all cfmodels work (some of them requi...
void setPreviousSpeed(double prevSpeed, double prevAcceleration)
Sets the influenced previous speed.
SUMOTime getWaitingTime(const bool accumulated=false) const
Returns the SUMOTime waited (speed was lesser than 0.1m/s)
Definition MSVehicle.h:670
MSAbstractLaneChangeModel & getLaneChangeModel()
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
const std::vector< MSLane * > & getBestLanesContinuation() const
Returns the best sequence of lanes to continue the route starting at myLane.
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
bool resumeFromStopping()
double getBackPositionOnLane(const MSLane *lane) const
Get the vehicle's position relative to the given lane.
Definition MSVehicle.h:398
void resetActionOffset(const SUMOTime timeUntilNextAction=0)
Resets the action offset for the vehicle.
bool rerouteParkingArea(const std::string &parkingAreaID, std::string &errorMsg)
void switchOffSignal(int signal)
Switches the given signal off.
Definition MSVehicle.h:1177
@ VEH_SIGNAL_NONE
Everything is switched off.
Definition MSVehicle.h:1114
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition MSVehicle.h:581
MSLane * getMutableLane() const
Returns the lane the vehicle is on Non const version indicates that something volatile is going on.
Definition MSVehicle.h:589
Influencer & getInfluencer()
void setActionStepLength(double actionStepLength, bool resetActionOffset=true)
Sets the action steplength of the vehicle.
double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
Definition MSVehicle.h:413
double getSpeed() const
Returns the vehicle's current speed.
Definition MSVehicle.h:490
void updateLaneBruttoSum()
Update the lane brutto occupancy after a change in minGap.
const std::vector< LaneQ > & getBestLanes() const
Returns the description of best lanes to use in order to continue the route.
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
Definition MSVehicle.h:973
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition MSVehicle.h:374
double getAngle() const
Returns the vehicle's direction in radians.
Definition MSVehicle.h:735
bool hasInfluencer() const
whether the vehicle is individually influenced (via TraCI or special parameters)
Definition MSVehicle.h:1706
void setLateralPositionOnLane(double posLat)
Definition MSVehicle.h:417
void switchOnSignal(int signal)
Switches the given signal on.
Definition MSVehicle.h:1169
int getLaneIndex() const
static MSVehicleTransfer * getInstance()
Returns the instance of this object.
void remove(MSVehicle *veh)
Remove a vehicle from this transfer object.
The car-following model and parameter.
void setHeight(const double &height)
Set a new value for this type's height.
void setMaxSpeedLat(const double &maxSpeedLat)
Set a new value for this type's maximum lateral speed.
double getMinGapLat() const
Get the minimum lateral gap that vehicles of this type maintain.
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
void setEmissionClass(SUMOEmissionClass eclass)
Set a new value for this type's emission class.
double getMaxSpeed() const
Get vehicle's (technical) maximum speed [m/s].
int getPersonCapacity() const
Get this vehicle type's person capacity.
const std::string & getID() const
Returns the name of the vehicle type.
void setMinGapLat(const double &minGapLat)
Set a new value for this type's minimum lataral gap.
double getMinGap() const
Get the free space in front of vehicles of this class.
void setApparentDecel(double apparentDecel)
Set a new value for this type's apparent deceleration.
double getHeight() const
Get the height which vehicles of this class shall have when being drawn.
void setMaxSpeed(const double &maxSpeed)
Set a new value for this type's maximum speed.
const Distribution_Parameterized & getSpeedFactor() const
Returns this type's speed factor.
void setBoardingDuration(SUMOTime duration, bool isPerson=true)
Set a new value for this type's boardingDuration.
double getActionStepLengthSecs() const
Returns this type's default action step length in seconds.
void setLength(const double &length)
Set a new value for this type's length.
double getMaxSpeedLat() const
Get vehicle's maximum lateral speed [m/s].
void setVClass(SUMOVehicleClass vclass)
Set a new value for this type's vehicle class.
void setAccel(double accel)
Set a new value for this type's acceleration.
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
void setWidth(const double &width)
Set a new value for this type's width.
void setLcContRight(const std::string &value)
Set lcContRight (which is the only lc-attribute not used within the laneChange model)
void setImperfection(double imperfection)
Set a new value for this type's imperfection.
void setPreferredLateralAlignment(const LatAlignmentDefinition &latAlignment, double latAlignmentOffset=0.0)
Set vehicle's preferred lateral alignment.
void setTau(double tau)
Set a new value for this type's headway.
double getLength() const
Get vehicle's length [m].
void setMass(double mass)
Set a new value for this type's mass.
double getMass() const
Get this vehicle type's mass.
void setMinGap(const double &minGap)
Set a new value for this type's minimum gap.
void setShape(SUMOVehicleShape shape)
Set a new value for this type's shape.
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
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
static SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc=SVC_IGNORING)
Checks whether the string describes a known vehicle class.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition Position.h:273
void sub(double dx, double dy)
Subtracts the given position from this one.
Definition Position.h:149
double x() const
Returns the x-position.
Definition Position.h:52
void setz(double z)
set position z
Definition Position.h:77
double z() const
Returns the z-position.
Definition Position.h:62
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position (in radians bet...
Definition Position.h:283
double y() const
Returns the y-position.
Definition Position.h:57
A list of positions.
double rotationAtOffset(double pos) const
Returns the rotation at the given length.
double distance2D(const Position &p, bool perpendicular=false) const
closest 2D-distance to point p (or -1 if perpendicular is true and the point is beyond this vector)
void move2side(double amount, double maxExtension=100)
move position vector to side using certain amount
void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
assigns new values
Definition RGBColor.cpp:102
virtual double getSlope() const =0
Returns the slope of the road at object's position in degrees.
virtual const MSLane * getLane() const =0
Returns the lane the object is currently at.
virtual double getPreviousSpeed() const =0
Returns the object's previous speed.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
static double getDefaultDecel(const SUMOVehicleClass vc=SVC_IGNORING)
Returns the default deceleration for the given vehicle class This needs to be a function because the ...
static bool parseLatAlignment(const std::string &val, double &lao, LatAlignmentDefinition &lad)
Parses and validates a given latAlignment value.
Representation of a vehicle.
Definition SUMOVehicle.h:63
virtual int getRouteValidity(bool update=true, bool silent=false, std::string *msgReturn=nullptr)=0
computes validity attributes for the current route
virtual bool wasRemoteControlled(SUMOTime lookBack=DELTA_T) const =0
Returns the information whether the vehicle is fully controlled via TraCI.
virtual bool hasDeparted() const =0
Returns whether this vehicle has departed.
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
virtual bool isParking() const =0
Returns the information whether the vehicle is parked.
virtual double getAngle() const =0
Get the vehicle's angle.
Definition of vehicle stop (position and duration)
int getFlags() const
return flags as per Vehicle::getStops
SUMOTime started
the time at which this stop was reached
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.
SUMOTime extension
The maximum time extension for boarding / loading.
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
std::string split
the id of the vehicle (train portion) that splits of upon reaching this stop
double startPos
The stopping position start.
std::string line
the new line id of the trip within a cyclical public transport route
double posLat
the lateral offset when stopping
bool onDemand
whether the stop may be skipped
std::string chargingStation
(Optional) charging station if one is assigned to the stop
std::vector< std::string > getTriggers() const
write trigger attribute
std::set< std::string > permitted
IDs of persons or containers that may board/load at this stop.
SUMOTime jumpUntil
earlierst jump end if there shall be a jump from this stop to the next route edge
int parametersSet
Information for the output which parameter were set.
SUMOTime jump
transfer time if there shall be a jump from this stop to the next route edge
std::string join
the id of the vehicle (train portion) to which this vehicle shall be joined
SUMOTime until
The time at which the vehicle may continue its journey.
std::string actType
act Type (only used by Persons) (used by netedit)
SUMOTime ended
the time at which this stop was ended
double endPos
The stopping position end.
std::set< std::string > awaitedPersons
IDs of persons the vehicle has to wait for until departing.
std::set< std::string > awaitedContainers
IDs of containers the vehicle has to wait for until departing.
std::string busstop
(Optional) bus stop if one is assigned to the stop
std::string tripId
id of the trip within a cyclical public transport route
std::string containerstop
(Optional) container stop if one is assigned to the stop
SUMOTime arrival
The (expected) time at which the vehicle reaches the stop.
SUMOTime duration
The stopping duration.
Structure representing possible vehicle parameter.
double departPosLat
(optional) The lateral position the vehicle shall depart from
double arrivalPosLat
(optional) The lateral position the vehicle shall arrive on
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
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.
double speedFactor
individual speedFactor (overriding distribution from vType)
std::vector< std::string > via
List of the via-edges the vehicle must visit.
static bool parseArrivalLane(const std::string &val, const std::string &element, const std::string &id, int &lane, ArrivalLaneDefinition &ald, std::string &error)
Validates a given arrivalLane value.
static bool parseArrivalPosLat(const std::string &val, const std::string &element, const std::string &id, double &pos, ArrivalPosLatDefinition &apd, std::string &error)
Validates a given arrivalPosLat value.
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)
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
static bool parseDepartSpeed(const std::string &val, const std::string &element, const std::string &id, double &speed, DepartSpeedDefinition &dsd, std::string &error)
Validates a given departSpeed value.
static bool parseArrivalPos(const std::string &val, const std::string &element, const std::string &id, double &pos, ArrivalPosDefinition &apd, std::string &error)
Validates a given arrivalPos value.
int personNumber
The static number of persons in the vehicle when it departs (not including boarding persons)
static bool parseArrivalSpeed(const std::string &val, const std::string &element, const std::string &id, double &speed, ArrivalSpeedDefinition &asd, std::string &error)
Validates a given arrivalSpeed value.
DepartPosLatDefinition departPosLatProcedure
Information how the vehicle shall choose the lateral departure position.
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.
RGBColor color
The vehicle's color, TraCI may change this.
double arrivalPos
(optional) The position the vehicle shall arrive on
static int parseInsertionChecks(const std::string &value)
parses insertion checks
static bool parseDepartLane(const std::string &val, const std::string &element, const std::string &id, int &lane, DepartLaneDefinition &dld, std::string &error)
Validates a given departLane value.
std::string id
The vehicle's id.
static bool parseDepart(const std::string &val, const std::string &element, const std::string &id, SUMOTime &depart, DepartDefinition &dd, std::string &error, const std::string &attr="departure")
Validates a given depart value.
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
static bool parseDepartPosLat(const std::string &val, const std::string &element, const std::string &id, double &pos, DepartPosLatDefinition &dpd, std::string &error)
Validates a given departPosLat value.
std::string toTaz
The vehicle's destination zone (district)
double arrivalSpeed
(optional) The final speed of the vehicle (not used yet)
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
static bool parseDepartPos(const std::string &val, const std::string &element, const std::string &id, double &pos, DepartPosDefinition &dpd, std::string &error)
Validates a given departPos value.
int insertionChecks
bitset of InsertionCheck
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)
static ParkingType parseParkingType(const std::string &value)
parses parking type value
static void parseStopTriggers(const std::vector< std::string > &triggers, bool expectTrigger, Stop &stop)
parses stop trigger values
ArrivalPosLatDefinition arrivalPosLatProcedure
Information how the vehicle shall choose the lateral arrival position.
static bool isInternalRouteID(const std::string &id)
Checks whether the route ID uses the syntax of internal routes.
static StringBijection< LinkState > LinkStates
link states
static int getIndexFromLane(const std::string laneID)
return lane index when given the lane ID
static StringBijection< LinkDirection > LinkDirections
link directions
const std::string & getString(const T key) const
get string
std::set< std::string > getSet()
return set of strings
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
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,...
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter
C++ TraCI client API implementation.
static MSEdge * getEdge(const std::string &edgeID)
Definition Helper.cpp:409
static TraCIPosition makeTraCIPosition(const Position &position, const bool includeZ=false)
Definition Helper.cpp:393
static bool moveToXYMap_matchingRoutePosition(const Position &pos, const std::string &origID, const ConstMSEdgeVector &currentRoute, int routeIndex, SUMOVehicleClass vClass, bool setLateralPos, double &bestDistance, MSLane **lane, double &lanePos, int &routeOffset)
Definition Helper.cpp:1759
static TraCIPositionVector makeTraCIPositionVector(const PositionVector &positionVector)
helper functions
Definition Helper.cpp:353
static int readDistanceRequest(tcpip::Storage &data, TraCIRoadPosition &roadPos, Position &pos)
Definition Helper.cpp:1884
static MSBaseVehicle * getVehicle(const std::string &id)
Definition Helper.cpp:494
static TraCIColor makeTraCIColor(const RGBColor &color)
Definition Helper.cpp:376
static TraCINextStopData buildStopData(const SUMOVehicleParameter::Stop &stopPar)
Definition Helper.cpp:660
static void setRemoteControlled(MSVehicle *v, Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, ConstMSEdgeVector route, SUMOTime t)
Definition Helper.cpp:1402
static const MSVehicleType & getVehicleType(const std::string &vehicleID)
Definition Helper.cpp:529
static bool moveToXYMap(const Position &pos, double maxRouteDistance, bool mayLeaveNetwork, const std::string &origID, const double angle, double speed, const ConstMSEdgeVector &currentRoute, const int routePosition, const MSLane *currentLane, double currentLanePos, bool onRoad, SUMOVehicleClass vClass, double currentAngle, bool setLateralPos, double &bestDistance, MSLane **lane, double &lanePos, int &routeOffset, ConstMSEdgeVector &edges)
Definition Helper.cpp:1442
static std::pair< MSLane *, double > convertCartesianToRoadMap(const Position &pos, const SUMOVehicleClass vClass)
Definition Helper.cpp:436
static SUMOVehicleParameter::Stop buildStopParameters(const std::string &edgeOrStoppingPlaceID, double pos, int laneIndex, double startPos, int flags, double duration, double until)
Definition Helper.cpp:554
static Subscription * addSubscriptionFilter(SubscriptionFilterType filter)
Definition Helper.cpp:229
static const MSLane * getLaneChecking(const std::string &edgeID, int laneIndex, double pos)
Definition Helper.cpp:419
static int readTypedByte(tcpip::Storage &ret, const std::string &error="")
static int readCompound(tcpip::Storage &ret, int expectedSize=-1, const std::string &error="")
static int readTypedInt(tcpip::Storage &ret, const std::string &error="")
static std::string readTypedString(tcpip::Storage &ret, const std::string &error="")
static double readTypedDouble(tcpip::Storage &ret, const std::string &error="")
#define CALL_MESO_FUN(veh, fun, microResult)
#define CALL_MICRO_FUN(veh, fun, mesoResult)
#define DEBUG_COND
@ key
the parser read a key of a value in an object
TRACI_CONST double INVALID_DOUBLE_VALUE
TRACI_CONST int VAR_LASTACTIONTIME
TRACI_CONST int VAR_EDGES
TRACI_CONST int POSITION_ROADMAP
TRACI_CONST int VAR_NOXEMISSION
TRACI_CONST int VAR_LANECHANGE_MODE
TRACI_CONST int VAR_REFERENCE_DISTANCE
TRACI_CONST int MOVE_AUTOMATIC
TRACI_CONST int LAST_STEP_PERSON_ID_LIST
TRACI_CONST int TRACI_ID_LIST
TRACI_CONST int VAR_IMPATIENCE
TRACI_CONST int VAR_SEGMENT_ID
TRACI_CONST int VAR_TYPE
TRACI_CONST int VAR_DEPARTURE
TRACI_CONST int VAR_ROUTING_MODE
TRACI_CONST int VAR_SECURE_GAP
TRACI_CONST int VAR_WAITING_TIME
TRACI_CONST int VAR_LINE
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
Definition TraCIDefs.h:384
TRACI_CONST int VAR_EDGE_TRAVELTIME
TRACI_CONST int VAR_ROAD_ID
TRACI_CONST int MOVE_NORMAL
TRACI_CONST int VAR_TIMELOSS
TRACI_CONST int VAR_SPEED_FACTOR
TRACI_CONST int VAR_FOLLOW_SPEED
TRACI_CONST int VAR_STOP_ARRIVALDELAY
TRACI_CONST int VAR_SPEED_LAT
TRACI_CONST int VAR_ANGLE
TRACI_CONST int VAR_NEXT_TLS
TRACI_CONST int VAR_EDGE_EFFORT
TRACI_CONST int VAR_BEST_LANES
TRACI_CONST int VAR_ALLOWED_SPEED
TRACI_CONST int VAR_LANE_INDEX
TRACI_CONST int VAR_PMXEMISSION
TRACI_CONST int VAR_SPEED_WITHOUT_TRACI
TRACI_CONST int VAR_BOARDING_DURATION
TRACI_CONST int MOVE_TELEPORT
TRACI_CONST int VAR_PERSON_NUMBER
TRACI_CONST int VAR_COEMISSION
TRACI_CONST int VAR_COLOR
TRACI_CONST int VAR_POSITION
TRACI_CONST int VAR_PERSON_CAPACITY
TRACI_CONST int VAR_STOP_PARAMETER
TRACI_CONST int VAR_LEADER
TRACI_CONST int VAR_CO2EMISSION
TRACI_CONST int VAR_TELEPORTING_LIST
TRACI_CONST int REMOVE_TELEPORT
TRACI_CONST int VAR_TAXI_FLEET
TRACI_CONST int VAR_ROUTE_VALID
TRACI_CONST int VAR_SPEEDSETMODE
TRACI_CONST int VAR_FUELCONSUMPTION
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition TraCIDefs.h:383
TRACI_CONST int VAR_SLOPE
TRACI_CONST int VAR_HCEMISSION
TRACI_CONST int ID_COUNT
TRACI_CONST int VAR_PARAMETER
TRACI_CONST int VAR_LANEPOSITION
TRACI_CONST int REMOVE_PARKING
TRACI_CONST int VAR_LANE_ID
TRACI_CONST int VAR_STOP_SPEED
TRACI_CONST int VAR_NOISEEMISSION
TRACI_CONST int VAR_ARRIVALPOS
TRACI_CONST int VAR_POSITION3D
TRACI_CONST int VAR_SPEED
TRACI_CONST int VAR_SIGNALS
TRACI_CONST int VAR_PARAMETER_WITH_KEY
TRACI_CONST int VAR_ACCUMULATED_WAITING_TIME
TRACI_CONST int VAR_MINGAP_LAT
TRACI_CONST int INVALID_INT_VALUE
TRACI_CONST int VAR_NEXT_LINKS
TRACI_CONST int VAR_ROUTE_INDEX
TRACI_CONST int VAR_NEXT_STOPS2
TRACI_CONST int VAR_ACCELERATION
TRACI_CONST int VAR_ROUTE_ID
TRACI_CONST int REMOVE_ARRIVED
TRACI_CONST int DISTANCE_REQUEST
@ SUBS_FILTER_LEAD_FOLLOW
@ SUBS_FILTER_UPSTREAM_DIST
@ SUBS_FILTER_VTYPE
@ SUBS_FILTER_LANES
@ SUBS_FILTER_NOOPPOSITE
@ SUBS_FILTER_DOWNSTREAM_DIST
@ SUBS_FILTER_LATERAL_DIST
@ SUBS_FILTER_TURN
@ SUBS_FILTER_VCLASS
@ SUBS_FILTER_FIELD_OF_VISION
TRACI_CONST int VAR_SEGMENT_INDEX
TRACI_CONST int ROUTING_MODE_DEFAULT
TRACI_CONST int VAR_LANEPOSITION_LAT
TRACI_CONST int CMD_CHANGELANE
TRACI_CONST int VAR_STOP_DELAY
TRACI_CONST int REMOVE_TELEPORT_ARRIVED
TRACI_CONST int VAR_NEIGHBORS
TRACI_CONST int REMOVE_VAPORIZED
TRACI_CONST int VAR_STOPSTATE
TRACI_CONST int VAR_FOLLOWER
TRACI_CONST int VAR_LOADED_LIST
TRACI_CONST int VAR_DEPART_DELAY
TRACI_CONST int VAR_SHADOW_LANE_ID
std::map< int, std::shared_ptr< libsumo::TraCIResult > > TraCIResults
{variable->value}
Definition TraCIDefs.h:381
TRACI_CONST int VAR_FOES
TRACI_CONST int VAR_DISTANCE
TRACI_CONST int ROUTING_MODE_AGGREGATED_CUSTOM
TRACI_CONST int VAR_ELECTRICITYCONSUMPTION
TRACI_CONST int VAR_VIA
TRACI_CONST int VAR_NEXT_STOPS
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression, cppcoreguidelines-noexcept-swap, performance-noexcept-swap) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition json.hpp:25297
A structure representing the best lanes for continuing the current route starting at 'lane'.
Definition MSVehicle.h:861