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