Eclipse SUMO - Simulation of Urban MObility
libsumo/Vehicle.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2012-2022 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/****************************************************************************/
18// C++ Vehicle API
19/****************************************************************************/
20#include <config.h>
21
34#include <microsim/MSStop.h>
35#include <microsim/MSVehicle.h>
39#include <microsim/MSNet.h>
40#include <microsim/MSEdge.h>
41#include <microsim/MSLane.h>
45#include <mesosim/MEVehicle.h>
46#include <libsumo/TraCIDefs.h>
48#include "Helper.h"
49#include "Route.h"
50#include "Polygon.h"
51#include "Vehicle.h"
52
53#define CALL_MICRO_FUN(veh, fun, mesoResult) ((dynamic_cast<MSVehicle*>(veh) == nullptr ? (mesoResult) : dynamic_cast<MSVehicle*>(veh)->fun))
54
55
56// ===========================================================================
57// debug defines
58// ===========================================================================
59//#define DEBUG_NEIGHBORS
60//#define DEBUG_DYNAMIC_SHAPES
61//#define DEBUG_MOVEXY
62#define DEBUG_COND (veh->isSelected())
63
64
65
66namespace libsumo {
67// ===========================================================================
68// static member initializations
69// ===========================================================================
70SubscriptionResults Vehicle::mySubscriptionResults;
71ContextSubscriptionResults Vehicle::myContextSubscriptionResults;
72
73
74// ===========================================================================
75// static member definitions
76// ===========================================================================
77bool
78Vehicle::isVisible(const SUMOVehicle* veh) {
79 return veh->isOnRoad() || veh->isParking() || veh->wasRemoteControlled();
80}
81
82
83bool
84Vehicle::isOnInit(const std::string& vehID) {
86 return sumoVehicle == nullptr || sumoVehicle->getLane() == nullptr;
87}
88
89
90std::vector<std::string>
91Vehicle::getIDList() {
92 std::vector<std::string> ids;
94 for (MSVehicleControl::constVehIt i = c.loadedVehBegin(); i != c.loadedVehEnd(); ++i) {
95 if (isVisible((*i).second)) {
96 ids.push_back((*i).first);
97 }
98 }
99 return ids;
100}
101
102int
103Vehicle::getIDCount() {
104 return (int)getIDList().size();
105}
106
107
108double
109Vehicle::getSpeed(const std::string& vehID) {
110 MSBaseVehicle* veh = Helper::getVehicle(vehID);
111 return isVisible(veh) ? veh->getSpeed() : INVALID_DOUBLE_VALUE;
112}
113
114double
115Vehicle::getLateralSpeed(const std::string& vehID) {
116 MSBaseVehicle* veh = Helper::getVehicle(vehID);
117 return isVisible(veh) ? CALL_MICRO_FUN(veh, getLaneChangeModel().getSpeedLat(), 0) : INVALID_DOUBLE_VALUE;
118}
119
120
121double
122Vehicle::getAcceleration(const std::string& vehID) {
123 MSBaseVehicle* veh = Helper::getVehicle(vehID);
124 return isVisible(veh) ? CALL_MICRO_FUN(veh, getAcceleration(), 0) : INVALID_DOUBLE_VALUE;
125}
126
127
128double
129Vehicle::getSpeedWithoutTraCI(const std::string& vehID) {
130 MSBaseVehicle* veh = Helper::getVehicle(vehID);
131 return isVisible(veh) ? CALL_MICRO_FUN(veh, getSpeedWithoutTraciInfluence(), veh->getSpeed()) : INVALID_DOUBLE_VALUE;
132}
133
134
135TraCIPosition
136Vehicle::getPosition(const std::string& vehID, const bool includeZ) {
137 MSBaseVehicle* veh = Helper::getVehicle(vehID);
138 if (isVisible(veh)) {
139 return Helper::makeTraCIPosition(veh->getPosition(), includeZ);
140 }
141 return TraCIPosition();
142}
143
144
145TraCIPosition
146Vehicle::getPosition3D(const std::string& vehID) {
147 return getPosition(vehID, true);
148}
149
150
151double
152Vehicle::getAngle(const std::string& vehID) {
153 MSBaseVehicle* veh = Helper::getVehicle(vehID);
154 return isVisible(veh) ? GeomHelper::naviDegree(veh->getAngle()) : INVALID_DOUBLE_VALUE;
155}
156
157
158double
159Vehicle::getSlope(const std::string& vehID) {
160 MSBaseVehicle* veh = Helper::getVehicle(vehID);
161 return (veh->isOnRoad() || veh->isParking()) ? veh->getSlope() : INVALID_DOUBLE_VALUE;
162}
163
164
165std::string
166Vehicle::getRoadID(const std::string& vehID) {
167 MSBaseVehicle* veh = Helper::getVehicle(vehID);
168 return isVisible(veh) ? CALL_MICRO_FUN(veh, getLane()->getEdge().getID(), veh->getEdge()->getID()) : "";
169}
170
171
172std::string
173Vehicle::getLaneID(const std::string& vehID) {
174 MSBaseVehicle* veh = Helper::getVehicle(vehID);
175 return veh->isOnRoad() ? CALL_MICRO_FUN(veh, getLane()->getID(), "") : "";
176}
177
178
179int
180Vehicle::getLaneIndex(const std::string& vehID) {
181 MSBaseVehicle* veh = Helper::getVehicle(vehID);
182 return veh->isOnRoad() ? CALL_MICRO_FUN(veh, getLane()->getIndex(), INVALID_INT_VALUE) : INVALID_INT_VALUE;
183}
184
185
186std::string
187Vehicle::getTypeID(const std::string& vehID) {
188 return Helper::getVehicleType(vehID).getID();
189}
190
191
192std::string
193Vehicle::getRouteID(const std::string& vehID) {
194 return Helper::getVehicle(vehID)->getRoute().getID();
195}
196
197
198int
199Vehicle::getRouteIndex(const std::string& vehID) {
200 MSBaseVehicle* veh = Helper::getVehicle(vehID);
201 return veh->hasDeparted() ? veh->getRoutePosition() : INVALID_INT_VALUE;
202}
203
204
205TraCIColor
206Vehicle::getColor(const std::string& vehID) {
207 return Helper::makeTraCIColor(Helper::getVehicle(vehID)->getParameter().color);
208}
209
210double
211Vehicle::getLanePosition(const std::string& vehID) {
212 MSBaseVehicle* veh = Helper::getVehicle(vehID);
213 return veh->isOnRoad() ? veh->getPositionOnLane() : INVALID_DOUBLE_VALUE;
214}
215
216double
217Vehicle::getLateralLanePosition(const std::string& vehID) {
218 MSBaseVehicle* veh = Helper::getVehicle(vehID);
219 return veh->isOnRoad() ? CALL_MICRO_FUN(veh, getLateralPositionOnLane(), 0) : INVALID_DOUBLE_VALUE;
220}
221
222double
223Vehicle::getCO2Emission(const std::string& vehID) {
224 MSBaseVehicle* veh = Helper::getVehicle(vehID);
225 return isVisible(veh) ? veh->getEmissions<PollutantsInterface::CO2>() : INVALID_DOUBLE_VALUE;
226}
227
228double
229Vehicle::getCOEmission(const std::string& vehID) {
230 MSBaseVehicle* veh = Helper::getVehicle(vehID);
231 return isVisible(veh) ? veh->getEmissions<PollutantsInterface::CO>() : INVALID_DOUBLE_VALUE;
232}
233
234double
235Vehicle::getHCEmission(const std::string& vehID) {
236 MSBaseVehicle* veh = Helper::getVehicle(vehID);
237 return isVisible(veh) ? veh->getEmissions<PollutantsInterface::HC>() : INVALID_DOUBLE_VALUE;
238}
239
240double
241Vehicle::getPMxEmission(const std::string& vehID) {
242 MSBaseVehicle* veh = Helper::getVehicle(vehID);
243 return isVisible(veh) ? veh->getEmissions<PollutantsInterface::PM_X>() : INVALID_DOUBLE_VALUE;
244}
245
246double
247Vehicle::getNOxEmission(const std::string& vehID) {
248 MSBaseVehicle* veh = Helper::getVehicle(vehID);
249 return isVisible(veh) ? veh->getEmissions<PollutantsInterface::NO_X>() : INVALID_DOUBLE_VALUE;
250}
251
252double
253Vehicle::getFuelConsumption(const std::string& vehID) {
254 MSBaseVehicle* veh = Helper::getVehicle(vehID);
255 return isVisible(veh) ? veh->getEmissions<PollutantsInterface::FUEL>() : INVALID_DOUBLE_VALUE;
256}
257
258double
259Vehicle::getNoiseEmission(const std::string& vehID) {
260 MSBaseVehicle* veh = Helper::getVehicle(vehID);
261 return isVisible(veh) ? veh->getHarmonoise_NoiseEmissions() : INVALID_DOUBLE_VALUE;
262}
263
264double
265Vehicle::getElectricityConsumption(const std::string& vehID) {
266 MSBaseVehicle* veh = Helper::getVehicle(vehID);
267 return isVisible(veh) ? veh->getEmissions<PollutantsInterface::ELEC>() : INVALID_DOUBLE_VALUE;
268}
269
270int
271Vehicle::getPersonNumber(const std::string& vehID) {
272 return Helper::getVehicle(vehID)->getPersonNumber();
273}
274
275int
276Vehicle::getPersonCapacity(const std::string& vehID) {
278}
279
280std::vector<std::string>
281Vehicle::getPersonIDList(const std::string& vehID) {
282 return Helper::getVehicle(vehID)->getPersonIDList();
283}
284
285std::pair<std::string, double>
286Vehicle::getLeader(const std::string& vehID, double dist) {
287 MSBaseVehicle* veh = Helper::getVehicle(vehID);
288 if (veh->isOnRoad()) {
289 std::pair<const MSVehicle* const, double> leaderInfo = veh->getLeader(dist);
290 const std::string leaderID = leaderInfo.first != nullptr ? leaderInfo.first->getID() : "";
291 double gap = leaderInfo.second;
292 if (leaderInfo.first != nullptr
293 && leaderInfo.first->getLane() != nullptr
294 && leaderInfo.first->getLane()->isInternal()
295 && veh->getLane() != nullptr
296 && (!veh->getLane()->isInternal()
297 || (veh->getLane()->getLinkCont().front()->getIndex() != leaderInfo.first->getLane()->getLinkCont().front()->getIndex()))) {
298 // leader is a linkLeader (see MSLink::getLeaderInfo)
299 // avoid internal gap values which may be negative (or -inf)
300 gap = MAX2(0.0, gap);
301 }
302 return std::make_pair(leaderID, gap);
303 } else {
304 return std::make_pair("", -1);
305 }
306}
307
308
309std::pair<std::string, double>
310Vehicle::getFollower(const std::string& vehID, double dist) {
311 MSBaseVehicle* veh = Helper::getVehicle(vehID);
312 if (veh->isOnRoad()) {
313 std::pair<const MSVehicle* const, double> leaderInfo = veh->getFollower(dist);
314 return std::make_pair(
315 leaderInfo.first != nullptr ? leaderInfo.first->getID() : "",
316 leaderInfo.second);
317 } else {
318 return std::make_pair("", -1);
319 }
320}
321
322
323double
324Vehicle::getWaitingTime(const std::string& vehID) {
325 return STEPS2TIME(Helper::getVehicle(vehID)->getWaitingTime());
326}
327
328
329double
330Vehicle::getAccumulatedWaitingTime(const std::string& vehID) {
331 MSBaseVehicle* veh = Helper::getVehicle(vehID);
332 return CALL_MICRO_FUN(veh, getAccumulatedWaitingSeconds(), INVALID_DOUBLE_VALUE);
333}
334
335
336double
337Vehicle::getAdaptedTraveltime(const std::string& vehID, double time, const std::string& edgeID) {
338 MSEdge* edge = Helper::getEdge(edgeID);
339 double value = INVALID_DOUBLE_VALUE;
341 return value;
342}
343
344
345double
346Vehicle::getEffort(const std::string& vehID, double time, const std::string& edgeID) {
347 MSEdge* edge = Helper::getEdge(edgeID);
348 double value = INVALID_DOUBLE_VALUE;
350 return value;
351}
352
353
354bool
355Vehicle::isRouteValid(const std::string& vehID) {
356 std::string msg;
357 return Helper::getVehicle(vehID)->hasValidRoute(msg);
358}
359
360
361std::vector<std::string>
362Vehicle::getRoute(const std::string& vehID) {
363 std::vector<std::string> result;
364 MSBaseVehicle* veh = Helper::getVehicle(vehID);
365 const MSRoute& r = veh->getRoute();
366 for (MSRouteIterator i = r.begin(); i != r.end(); ++i) {
367 result.push_back((*i)->getID());
368 }
369 return result;
370}
371
372
373int
374Vehicle::getSignals(const std::string& vehID) {
375 MSBaseVehicle* veh = Helper::getVehicle(vehID);
376 return CALL_MICRO_FUN(veh, getSignals(), MSVehicle::VEH_SIGNAL_NONE);
377}
378
379
380std::vector<TraCIBestLanesData>
381Vehicle::getBestLanes(const std::string& vehID) {
382 std::vector<TraCIBestLanesData> result;
383 MSVehicle* veh = dynamic_cast<MSVehicle*>(Helper::getVehicle(vehID));
384 if (veh != nullptr && veh->isOnRoad()) {
385 for (const MSVehicle::LaneQ& lq : veh->getBestLanes()) {
386 TraCIBestLanesData bld;
387 bld.laneID = lq.lane->getID();
388 bld.length = lq.length;
389 bld.occupation = lq.nextOccupation;
390 bld.bestLaneOffset = lq.bestLaneOffset;
391 bld.allowsContinuation = lq.allowsContinuation;
392 for (const MSLane* const lane : lq.bestContinuations) {
393 if (lane != nullptr) {
394 bld.continuationLanes.push_back(lane->getID());
395 }
396 }
397 result.emplace_back(bld);
398 }
399 }
400 return result;
401}
402
403
404std::vector<TraCINextTLSData>
405Vehicle::getNextTLS(const std::string& vehID) {
406 std::vector<TraCINextTLSData> result;
407 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
408 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
409 if (!vehicle->isOnRoad()) {
410 return result;
411 }
412 if (veh != nullptr) {
413 const MSLane* lane = veh->getLane();
414 const std::vector<MSLane*>& bestLaneConts = veh->getBestLanesContinuation(lane);
415 double seen = lane->getLength() - veh->getPositionOnLane();
416 int view = 1;
417 std::vector<MSLink*>::const_iterator linkIt = MSLane::succLinkSec(*veh, view, *lane, bestLaneConts);
418 while (!lane->isLinkEnd(linkIt)) {
419 if (!lane->getEdge().isInternal()) {
420 if ((*linkIt)->isTLSControlled()) {
421 TraCINextTLSData ntd;
422 ntd.id = (*linkIt)->getTLLogic()->getID();
423 ntd.tlIndex = (*linkIt)->getTLIndex();
424 ntd.dist = seen;
425 ntd.state = (char)(*linkIt)->getState();
426 result.push_back(ntd);
427 }
428 }
429 lane = (*linkIt)->getViaLaneOrLane();
430 if (!lane->getEdge().isInternal()) {
431 view++;
432 }
433 seen += lane->getLength();
434 linkIt = MSLane::succLinkSec(*veh, view, *lane, bestLaneConts);
435 }
436 // consider edges beyond bestLanes
437 const int remainingEdges = (int)(veh->getRoute().end() - veh->getCurrentRouteEdge()) - view;
438 //std::cout << SIMTIME << "remainingEdges=" << remainingEdges << " seen=" << seen << " view=" << view << " best=" << toString(bestLaneConts) << "\n";
439 for (int i = 0; i < remainingEdges; i++) {
440 const MSEdge* prev = *(veh->getCurrentRouteEdge() + view + i - 1);
441 const MSEdge* next = *(veh->getCurrentRouteEdge() + view + i);
442 const std::vector<MSLane*>* allowed = prev->allowedLanes(*next, veh->getVClass());
443 if (allowed != nullptr && allowed->size() != 0) {
444 for (const MSLink* const link : allowed->front()->getLinkCont()) {
445 if (&link->getLane()->getEdge() == next) {
446 if (link->isTLSControlled()) {
447 TraCINextTLSData ntd;
448 ntd.id = link->getTLLogic()->getID();
449 ntd.tlIndex = link->getTLIndex();
450 ntd.dist = seen;
451 ntd.state = (char)link->getState();
452 result.push_back(ntd);
453 }
454 seen += allowed->front()->getLength();
455 }
456 }
457 } else {
458 // invalid route, cannot determine nextTLS
459 break;
460 }
461 }
462 } else {
463 WRITE_WARNING(TL("getNextTLS not yet implemented for meso"));
464 }
465 return result;
466}
467
468std::vector<TraCINextStopData>
469Vehicle::getNextStops(const std::string& vehID) {
470 return getStops(vehID, 0);
471}
472
473std::vector<TraCINextStopData>
474Vehicle::getStops(const std::string& vehID, int limit) {
475 std::vector<TraCINextStopData> result;
476 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
477 if (limit < 0) {
478 // return past stops up to the given limit
479 const std::vector<SUMOVehicleParameter::Stop>& pastStops = vehicle->getPastStops();
480 const int n = (int)pastStops.size();
481 for (int i = MAX2(0, n + limit); i < n; i++) {
482 result.push_back(Helper::buildStopData(pastStops[i]));
483 }
484 } else {
485 for (const MSStop& stop : vehicle->getStops()) {
486 if (!stop.pars.collision) {
487 TraCINextStopData nsd = Helper::buildStopData(stop.pars);
488 nsd.duration = STEPS2TIME(stop.duration);
489 result.push_back(nsd);
490 if (limit > 0 && (int)result.size() >= limit) {
491 break;
492 }
493 }
494 }
495 }
496 return result;
497}
498
499
500int
501Vehicle::getStopState(const std::string& vehID) {
502 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
503 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
504 if (veh == nullptr) {
505 WRITE_WARNING(TL("getStopState not yet implemented for meso"));
506 return 0;
507 }
508 int result = 0;
509 if (veh->isStopped()) {
510 const MSStop& stop = veh->getNextStop();
511 result = stop.getStateFlagsOld();
512 }
513 return result;
514}
515
516
517double
518Vehicle::getDistance(const std::string& vehID) {
519 MSBaseVehicle* veh = Helper::getVehicle(vehID);
520 if (veh->isOnRoad()) {
521 return veh->getOdometer();
522 } else {
524 }
525}
526
527
528double
529Vehicle::getDrivingDistance(const std::string& vehID, const std::string& edgeID, double position, int /* laneIndex */) {
530 MSBaseVehicle* veh = Helper::getVehicle(vehID);
531 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
532 if (veh->isOnRoad()) {
533 const MSEdge* edge = microVeh != nullptr ? &veh->getLane()->getEdge() : veh->getEdge();
534 double distance = veh->getRoute().getDistanceBetween(veh->getPositionOnLane(), position,
535 edge, Helper::getEdge(edgeID), true, veh->getRoutePosition());
536 if (distance == std::numeric_limits<double>::max()) {
538 }
539 return distance;
540 } else {
542 }
543}
544
545
546double
547Vehicle::getDrivingDistance2D(const std::string& vehID, double x, double y) {
548 MSBaseVehicle* veh = Helper::getVehicle(vehID);
549 if (veh == nullptr) {
551 }
552 if (veh->isOnRoad()) {
553 std::pair<MSLane*, double> roadPos = Helper::convertCartesianToRoadMap(Position(x, y), veh->getVehicleType().getVehicleClass());
554 double distance = veh->getRoute().getDistanceBetween(veh->getPositionOnLane(), roadPos.second,
555 veh->getEdge(), &roadPos.first->getEdge(), true, veh->getRoutePosition());
556 if (distance == std::numeric_limits<double>::max()) {
558 }
559 return distance;
560 } else {
562 }
563}
564
565
566double
567Vehicle::getAllowedSpeed(const std::string& vehID) {
568 MSBaseVehicle* veh = Helper::getVehicle(vehID);
569 return veh->isOnRoad() ? CALL_MICRO_FUN(veh, getLane()->getVehicleMaxSpeed(veh), veh->getEdge()->getVehicleMaxSpeed(veh)) : INVALID_DOUBLE_VALUE;
570}
571
572
573double
574Vehicle::getSpeedFactor(const std::string& vehID) {
576}
577
578
579int
580Vehicle::getSpeedMode(const std::string& vehID) {
581 MSBaseVehicle* veh = Helper::getVehicle(vehID);
582 return CALL_MICRO_FUN(veh, getInfluencer().getSpeedMode(), INVALID_INT_VALUE);
583}
584
585
586int
587Vehicle::getLaneChangeMode(const std::string& vehID) {
588 MSBaseVehicle* veh = Helper::getVehicle(vehID);
589 return CALL_MICRO_FUN(veh, getInfluencer().getLaneChangeMode(), INVALID_INT_VALUE);
590}
591
592
593int
594Vehicle::getRoutingMode(const std::string& vehID) {
596}
597
598
599std::string
600Vehicle::getLine(const std::string& vehID) {
601 return Helper::getVehicle(vehID)->getParameter().line;
602}
603
604
605std::vector<std::string>
606Vehicle::getVia(const std::string& vehID) {
607 return Helper::getVehicle(vehID)->getParameter().via;
608}
609
610
611std::pair<int, int>
612Vehicle::getLaneChangeState(const std::string& vehID, int direction) {
613 MSBaseVehicle* veh = Helper::getVehicle(vehID);
614 auto undefined = std::make_pair((int)LCA_UNKNOWN, (int)LCA_UNKNOWN);
615 return veh->isOnRoad() ? CALL_MICRO_FUN(veh, getLaneChangeModel().getSavedState(direction), undefined) : undefined;
616}
617
618
619std::string
620Vehicle::getParameter(const std::string& vehID, const std::string& key) {
621 MSBaseVehicle* veh = Helper::getVehicle(vehID);
622 std::string error;
623 std::string result = veh->getPrefixedParameter(key, error);
624 if (error != "") {
625 throw TraCIException(error);
626 }
627 return result;
628}
629
630
632
633
634std::vector<std::pair<std::string, double> >
635Vehicle::getNeighbors(const std::string& vehID, const int mode) {
636 int dir = (1 & mode) != 0 ? -1 : 1;
637 bool queryLeaders = (2 & mode) != 0;
638 bool blockersOnly = (4 & mode) != 0;
639 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
640 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
641 std::vector<std::pair<std::string, double> > result;
642 if (veh == nullptr) {
643 return result;
644 }
645#ifdef DEBUG_NEIGHBORS
646 if (DEBUG_COND) {
647 std::cout << "getNeighbors() for veh '" << vehID << "': dir=" << dir
648 << ", queryLeaders=" << queryLeaders
649 << ", blockersOnly=" << blockersOnly << std::endl;
650 }
651#endif
652 if (veh->getLaneChangeModel().isOpposite()) {
653 // getParallelLane works relative to lane forward direction
654 dir *= -1;
655 }
656
657 MSLane* targetLane = veh->getLane()->getParallelLane(dir);
658 if (targetLane == nullptr) {
659 return result;
660 }
661 // need to recompute leaders and followers (#8119)
662 const bool opposite = &veh->getLane()->getEdge() != &targetLane->getEdge();
663 MSLeaderDistanceInfo neighbors(targetLane->getWidth(), nullptr, 0.);
664 if (queryLeaders) {
665 if (opposite) {
666 double pos = targetLane->getOppositePos(veh->getPositionOnLane());
667 neighbors = targetLane->getFollowersOnConsecutive(veh, pos, true);
668 } else {
669 targetLane->addLeaders(veh, veh->getPositionOnLane(), neighbors);
670 }
671 } else {
672 if (opposite) {
673 double pos = targetLane->getOppositePos(veh->getPositionOnLane());
674 targetLane->addLeaders(veh, pos, neighbors);
675 neighbors.fixOppositeGaps(true);
676 } else {
677 neighbors = targetLane->getFollowersOnConsecutive(veh, veh->getBackPositionOnLane(), true);
678 }
679 }
680 if (blockersOnly) {
681 // filter out vehicles that aren't blocking
682 MSLeaderDistanceInfo blockers(targetLane->getWidth(), nullptr, 0.);
683 for (int i = 0; i < neighbors.numSublanes(); i++) {
684 CLeaderDist n = neighbors[i];
685 if (n.first != nullptr) {
686 const MSVehicle* follower = veh;
687 const MSVehicle* leader = n.first;
688 if (!queryLeaders) {
689 std::swap(follower, leader);
690 }
691 const double secureGap = (follower->getCarFollowModel().getSecureGap(
692 follower, leader, follower->getSpeed(), leader->getSpeed(), leader->getCarFollowModel().getMaxDecel())
693 * follower->getLaneChangeModel().getSafetyFactor());
694 if (n.second < secureGap) {
695 blockers.addLeader(n.first, n.second, 0, i);
696 }
697 }
698 }
699 neighbors = blockers;
700 }
701
702 if (neighbors.hasVehicles()) {
703 for (int i = 0; i < neighbors.numSublanes(); i++) {
704 CLeaderDist n = neighbors[i];
705 if (n.first != nullptr &&
706 // avoid duplicates
707 (result.size() == 0 || result.back().first != n.first->getID())) {
708 result.push_back(std::make_pair(n.first->getID(), n.second));
709 }
710 }
711 }
712 return result;
713}
714
715
716double
717Vehicle::getFollowSpeed(const std::string& vehID, double speed, double gap, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) {
718 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
719 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
720 if (veh == nullptr) {
721 WRITE_ERROR(TL("getFollowSpeed not applicable for meso"));
723 }
724 MSVehicle* leader = dynamic_cast<MSVehicle*>(MSNet::getInstance()->getVehicleControl().getVehicle(leaderID));
725 return veh->getCarFollowModel().followSpeed(veh, speed, gap, leaderSpeed, leaderMaxDecel, leader, MSCFModel::CalcReason::FUTURE);
726}
727
728
729double
730Vehicle::getSecureGap(const std::string& vehID, double speed, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) {
731 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
732 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
733 if (veh == nullptr) {
734 WRITE_ERROR(TL("getSecureGap not applicable for meso"));
736 }
737 MSVehicle* leader = dynamic_cast<MSVehicle*>(MSNet::getInstance()->getVehicleControl().getVehicle(leaderID));
738 return veh->getCarFollowModel().getSecureGap(veh, leader, speed, leaderSpeed, leaderMaxDecel);
739}
740
741
742double
743Vehicle::getStopSpeed(const std::string& vehID, const double speed, double gap) {
744 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
745 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
746 if (veh == nullptr) {
747 WRITE_ERROR(TL("getStopSpeed not applicable for meso"));
749 }
750 return veh->getCarFollowModel().stopSpeed(veh, speed, gap, MSCFModel::CalcReason::FUTURE);
751}
752
753double
754Vehicle::getStopDelay(const std::string& vehID) {
755 return Helper::getVehicle(vehID)->getStopDelay();
756}
757
758double
759Vehicle::getStopArrivalDelay(const std::string& vehID) {
760 double result = Helper::getVehicle(vehID)->getStopArrivalDelay();
761 if (result == INVALID_DOUBLE) {
763 } else {
764 return result;
765 }
766}
767
768double
769Vehicle::getTimeLoss(const std::string& vehID) {
770 return Helper::getVehicle(vehID)->getTimeLossSeconds();
771}
772
773std::vector<std::string>
774Vehicle::getTaxiFleet(int taxiState) {
775 std::vector<std::string> result;
776 for (MSDevice_Taxi* taxi : MSDevice_Taxi::getFleet()) {
777 if (taxi->getHolder().hasDeparted()) {
778 if (taxiState == -1
779 || (taxiState == 0 && taxi->getState() == 0)
780 || (taxiState != 0 && (taxi->getState() & taxiState) == taxiState)) {
781 result.push_back(taxi->getHolder().getID());
782 }
783 }
784 }
785 return result;
786}
787
788std::string
789Vehicle::getEmissionClass(const std::string& vehID) {
790 return PollutantsInterface::getName(Helper::getVehicleType(vehID).getEmissionClass());
791}
792
793std::string
794Vehicle::getShapeClass(const std::string& vehID) {
795 return getVehicleShapeName(Helper::getVehicleType(vehID).getGuiShape());
796}
797
798
799double
800Vehicle::getLength(const std::string& vehID) {
801 return Helper::getVehicleType(vehID).getLength();
802}
803
804
805double
806Vehicle::getAccel(const std::string& vehID) {
808}
809
810
811double
812Vehicle::getDecel(const std::string& vehID) {
814}
815
816
817double Vehicle::getEmergencyDecel(const std::string& vehID) {
819}
820
821
822double Vehicle::getApparentDecel(const std::string& vehID) {
824}
825
826
827double Vehicle::getActionStepLength(const std::string& vehID) {
829}
830
831
832double Vehicle::getLastActionTime(const std::string& vehID) {
833 MSBaseVehicle* veh = Helper::getVehicle(vehID);
834 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
835 if (microVeh != nullptr) {
836 return STEPS2TIME(microVeh->getLastActionTime());
837 } else {
838 MEVehicle* mesoVeh = dynamic_cast<MEVehicle*>(veh);
839 return STEPS2TIME(mesoVeh->getEventTime());
840 }
841}
842
843
844double
845Vehicle::getTau(const std::string& vehID) {
847}
848
849
850double
851Vehicle::getImperfection(const std::string& vehID) {
853}
854
855
856double
857Vehicle::getSpeedDeviation(const std::string& vehID) {
859}
860
861
862std::string
863Vehicle::getVehicleClass(const std::string& vehID) {
864 return toString(Helper::getVehicleType(vehID).getVehicleClass());
865}
866
867
868double
869Vehicle::getMinGap(const std::string& vehID) {
870 return Helper::getVehicleType(vehID).getMinGap();
871}
872
873
874double
875Vehicle::getMinGapLat(const std::string& vehID) {
876 try {
877 return StringUtils::toDouble(getParameter(vehID, "laneChangeModel.minGapLat"));
878 } catch (const TraCIException&) {
879 // legacy behavior
880 return Helper::getVehicleType(vehID).getMinGapLat();
881 }
882}
883
884
885double
886Vehicle::getMaxSpeed(const std::string& vehID) {
887 return Helper::getVehicleType(vehID).getMaxSpeed();
888}
889
890
891double
892Vehicle::getMaxSpeedLat(const std::string& vehID) {
894}
895
896
897std::string
898Vehicle::getLateralAlignment(const std::string& vehID) {
899 return toString(Helper::getVehicleType(vehID).getPreferredLateralAlignment());
900}
901
902
903double
904Vehicle::getWidth(const std::string& vehID) {
905 return Helper::getVehicleType(vehID).getWidth();
906}
907
908
909double
910Vehicle::getHeight(const std::string& vehID) {
911 return Helper::getVehicleType(vehID).getHeight();
912}
913
914
915void
916Vehicle::setStop(const std::string& vehID,
917 const std::string& edgeID,
918 double pos,
919 int laneIndex,
920 double duration,
921 int flags,
922 double startPos,
923 double until) {
924 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
926 pos, laneIndex, startPos, flags, duration, until);
927 std::string error;
928 if (!vehicle->addTraciStop(stopPars, error)) {
929 throw TraCIException(error);
930 }
931}
932
933
934void
935Vehicle::replaceStop(const std::string& vehID,
936 int nextStopIndex,
937 const std::string& edgeID,
938 double pos,
939 int laneIndex,
940 double duration,
941 int flags,
942 double startPos,
943 double until,
944 int teleport) {
945 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
946 std::string error;
947 if (edgeID == "") {
948 // only remove stop
949 const bool ok = vehicle->abortNextStop(nextStopIndex);
950 if ((teleport & 2) != 0) {
951 if (!vehicle->rerouteBetweenStops(nextStopIndex, "traci:replaceStop", (teleport & 1), error)) {
952 throw TraCIException("Stop replacement failed for vehicle '" + vehID + "' (" + error + ").");
953 }
954 } else if (teleport != 0) {
955 WRITE_WARNING("Stop replacement parameter 'teleport=" + toString(teleport) + "' ignored for vehicle '" + vehID + "' when only removing stop.");
956 }
957 if (!ok) {
958 throw TraCIException("Stop replacement failed for vehicle '" + vehID + "' (invalid nextStopIndex).");
959 }
960 } else {
962 pos, laneIndex, startPos, flags, duration, until);
963
964 if (!vehicle->replaceStop(nextStopIndex, stopPars, "traci:replaceStop", teleport != 0, error)) {
965 throw TraCIException("Stop replacement failed for vehicle '" + vehID + "' (" + error + ").");
966 }
967 }
968}
969
970
971void
972Vehicle::insertStop(const std::string& vehID,
973 int nextStopIndex,
974 const std::string& edgeID,
975 double pos,
976 int laneIndex,
977 double duration,
978 int flags,
979 double startPos,
980 double until,
981 int teleport) {
982 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
984 pos, laneIndex, startPos, flags, duration, until);
985
986 std::string error;
987 if (!vehicle->insertStop(nextStopIndex, stopPars, "traci:insertStop", teleport != 0, error)) {
988 throw TraCIException("Stop insertion failed for vehicle '" + vehID + "' (" + error + ").");
989 }
990}
991
992
993std::string
994Vehicle::getStopParameter(const std::string& vehID, int nextStopIndex, const std::string& param) {
995 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
996 try {
997 if (nextStopIndex >= (int)vehicle->getStops().size() || (nextStopIndex < 0 && -nextStopIndex > (int)vehicle->getPastStops().size())) {
998 throw ProcessError("Invalid stop index " + toString(nextStopIndex)
999 + " (has " + toString(vehicle->getPastStops().size()) + " past stops and " + toString(vehicle->getStops().size()) + " remaining stops)");
1000
1001 }
1002 const SUMOVehicleParameter::Stop& pars = (nextStopIndex >= 0
1003 ? vehicle->getStop(nextStopIndex).pars
1004 : vehicle->getPastStops()[vehicle->getPastStops().size() + nextStopIndex]);
1005
1006 if (param == toString(SUMO_ATTR_EDGE)) {
1007 return pars.edge;
1008 } else if (param == toString(SUMO_ATTR_LANE)) {
1010 } else if (param == toString(SUMO_ATTR_BUS_STOP)
1011 || param == toString(SUMO_ATTR_TRAIN_STOP)) {
1012 return pars.busstop;
1013 } else if (param == toString(SUMO_ATTR_CONTAINER_STOP)) {
1014 return pars.containerstop;
1015 } else if (param == toString(SUMO_ATTR_CHARGING_STATION)) {
1016 return pars.chargingStation;
1017 } else if (param == toString(SUMO_ATTR_PARKING_AREA)) {
1018 return pars.parkingarea;
1019 } else if (param == toString(SUMO_ATTR_STARTPOS)) {
1020 return toString(pars.startPos);
1021 } else if (param == toString(SUMO_ATTR_ENDPOS)) {
1022 return toString(pars.endPos);
1023 } else if (param == toString(SUMO_ATTR_POSITION_LAT)) {
1024 return toString(pars.posLat == INVALID_DOUBLE ? INVALID_DOUBLE_VALUE : pars.posLat);
1025 } else if (param == toString(SUMO_ATTR_ARRIVAL)) {
1026 return pars.arrival < 0 ? "-1" : time2string(pars.arrival);
1027 } else if (param == toString(SUMO_ATTR_DURATION)) {
1028 return pars.duration < 0 ? "-1" : time2string(pars.duration);
1029 } else if (param == toString(SUMO_ATTR_UNTIL)) {
1030 return pars.until < 0 ? "-1" : time2string(pars.until);
1031 } else if (param == toString(SUMO_ATTR_EXTENSION)) {
1032 return pars.extension < 0 ? "-1" : time2string(pars.extension);
1033 } else if (param == toString(SUMO_ATTR_INDEX)) {
1034 return toString(nextStopIndex + vehicle->getPastStops().size());
1035 } else if (param == toString(SUMO_ATTR_PARKING)) {
1036 return toString(pars.parking);
1037 } else if (param == toString(SUMO_ATTR_TRIGGERED)) {
1038 return joinToString(pars.getTriggers(), " ");
1039 } else if (param == toString(SUMO_ATTR_EXPECTED)) {
1040 return joinToString(pars.awaitedPersons, " ");
1041 } else if (param == toString(SUMO_ATTR_EXPECTED_CONTAINERS)) {
1042 return joinToString(pars.awaitedContainers, " ");
1043 } else if (param == toString(SUMO_ATTR_PERMITTED)) {
1044 return joinToString(pars.permitted, " ");
1045 } else if (param == toString(SUMO_ATTR_ACTTYPE)) {
1046 return pars.actType;
1047 } else if (param == toString(SUMO_ATTR_TRIP_ID)) {
1048 return pars.tripId;
1049 } else if (param == toString(SUMO_ATTR_SPLIT)) {
1050 return pars.split;
1051 } else if (param == toString(SUMO_ATTR_JOIN)) {
1052 return pars.join;
1053 } else if (param == toString(SUMO_ATTR_LINE)) {
1054 return pars.line;
1055 } else if (param == toString(SUMO_ATTR_SPEED)) {
1056 return toString(pars.speed);
1057 } else if (param == toString(SUMO_ATTR_STARTED)) {
1058 return pars.started < 0 ? "-1" : time2string(pars.started);
1059 } else if (param == toString(SUMO_ATTR_ENDED)) {
1060 return pars.ended < 0 ? "-1" : time2string(pars.ended);
1061 } else {
1062 throw ProcessError("Unsupported parameter '" + param + "'");
1063 }
1064 } catch (ProcessError& e) {
1065 throw TraCIException("Could not get stop parameter for vehicle '" + vehID + "' (" + e.what() + ")");
1066 }
1067}
1068
1069
1070
1071void
1072Vehicle::setStopParameter(const std::string& vehID, int nextStopIndex,
1073 const std::string& param, const std::string& value) {
1074 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1075 try {
1076 MSStop& stop = vehicle->getStop(nextStopIndex);
1078 std::string error;
1079 if (param == toString(SUMO_ATTR_EDGE)
1080 || param == toString(SUMO_ATTR_BUS_STOP)
1081 || param == toString(SUMO_ATTR_TRAIN_STOP)
1084 || param == toString(SUMO_ATTR_PARKING_AREA)
1085 || param == toString(SUMO_ATTR_LANE)
1086 ) {
1087 int laneIndex = stop.lane->getIndex();
1088 int flags = pars.getFlags() & 3;
1089 std::string edgeOrStopID = value;
1090 if (param == toString(SUMO_ATTR_LANE)) {
1091 laneIndex = StringUtils::toInt(value);
1092 edgeOrStopID = pars.edge;
1093 } else if (param == toString(SUMO_ATTR_BUS_STOP)
1094 || param == toString(SUMO_ATTR_TRAIN_STOP)) {
1095 flags |= 8;
1096 } else if (param == toString(SUMO_ATTR_CONTAINER_STOP)) {
1097 flags |= 16;
1098 } else if (param == toString(SUMO_ATTR_CHARGING_STATION)) {
1099 flags |= 32;
1100 } else if (param == toString(SUMO_ATTR_PARKING_AREA)) {
1101 flags |= 64;
1102 }
1103 // special case: replace stop
1104 replaceStop(vehID, nextStopIndex, edgeOrStopID, pars.endPos, laneIndex, STEPS2TIME(pars.duration),
1105 flags, pars.startPos, STEPS2TIME(pars.until), 0);
1106
1107 } else if (param == toString(SUMO_ATTR_STARTPOS)) {
1108 pars.startPos = StringUtils::toDouble(value);
1110 } else if (param == toString(SUMO_ATTR_ENDPOS)) {
1111 pars.endPos = StringUtils::toDouble(value);
1113 } else if (param == toString(SUMO_ATTR_POSITION_LAT)) {
1114 pars.posLat = StringUtils::toDouble(value);
1116 } else if (param == toString(SUMO_ATTR_ARRIVAL)) {
1117 pars.arrival = string2time(value);
1119 } else if (param == toString(SUMO_ATTR_DURATION)) {
1120 pars.duration = string2time(value);
1122 } else if (param == toString(SUMO_ATTR_UNTIL)) {
1123 pars.until = string2time(value);
1125 } else if (param == toString(SUMO_ATTR_EXTENSION)) {
1126 pars.extension = string2time(value);
1128 } else if (param == toString(SUMO_ATTR_INDEX)) {
1129 throw TraCIException("Changing stop index is not supported");
1130 } else if (param == toString(SUMO_ATTR_PARKING)) {
1133 } else if (param == toString(SUMO_ATTR_TRIGGERED)) {
1134 SUMOVehicleParameter::parseStopTriggers(StringTokenizer(value).getVector(), false, pars);
1136 } else if (param == toString(SUMO_ATTR_EXPECTED)) {
1137 pars.awaitedPersons = StringTokenizer(value).getSet();
1139 } else if (param == toString(SUMO_ATTR_EXPECTED_CONTAINERS)) {
1142 } else if (param == toString(SUMO_ATTR_PERMITTED)) {
1143 pars.permitted = StringTokenizer(value).getSet();
1145 } else if (param == toString(SUMO_ATTR_ACTTYPE)) {
1146 pars.actType = value;
1147 } else if (param == toString(SUMO_ATTR_TRIP_ID)) {
1148 pars.tripId = value;
1150 } else if (param == toString(SUMO_ATTR_SPLIT)) {
1151 pars.split = value;
1153 } else if (param == toString(SUMO_ATTR_JOIN)) {
1154 pars.join = value;
1156 } else if (param == toString(SUMO_ATTR_LINE)) {
1157 pars.line = value;
1159 } else if (param == toString(SUMO_ATTR_SPEED)) {
1160 pars.speed = StringUtils::toDouble(value);
1162 } else if (param == toString(SUMO_ATTR_STARTED)) {
1163 pars.started = string2time(value);
1165 } else if (param == toString(SUMO_ATTR_ENDED)) {
1166 pars.ended = string2time(value);
1168 } else {
1169 throw ProcessError("Unsupported parameter '" + param + "'");
1170 }
1171 } catch (ProcessError& e) {
1172 throw TraCIException("Could not set stop parameter for vehicle '" + vehID + "' (" + e.what() + ")");
1173 }
1174}
1175
1176
1177void
1178Vehicle::rerouteParkingArea(const std::string& vehID, const std::string& parkingAreaID) {
1179 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1180 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1181 if (veh == nullptr) {
1182 WRITE_WARNING(TL("rerouteParkingArea not yet implemented for meso"));
1183 return;
1184 }
1185 std::string error;
1186 // Forward command to vehicle
1187 if (!veh->rerouteParkingArea(parkingAreaID, error)) {
1188 throw TraCIException(error);
1189 }
1190}
1191
1192void
1193Vehicle::resume(const std::string& vehID) {
1194 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1195 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1196 if (veh == nullptr) {
1197 WRITE_WARNING(TL("resume not yet implemented for meso"));
1198 return;
1199 }
1200 if (!veh->hasStops()) {
1201 throw TraCIException("Failed to resume vehicle '" + veh->getID() + "', it has no stops.");
1202 }
1203 if (!veh->resumeFromStopping()) {
1204 MSStop& sto = veh->getNextStop();
1205 std::ostringstream strs;
1206 strs << "reached: " << sto.reached;
1207 strs << ", duration:" << sto.duration;
1208 strs << ", edge:" << (*sto.edge)->getID();
1209 strs << ", startPos: " << sto.pars.startPos;
1210 std::string posStr = strs.str();
1211 throw TraCIException("Failed to resume from stopping for vehicle '" + veh->getID() + "', " + posStr);
1212 }
1213}
1214
1215
1216void
1217Vehicle::changeTarget(const std::string& vehID, const std::string& edgeID) {
1218 MSBaseVehicle* veh = Helper::getVehicle(vehID);
1219 const MSEdge* destEdge = MSEdge::dictionary(edgeID);
1220 const bool onInit = isOnInit(vehID);
1221 if (destEdge == nullptr) {
1222 throw TraCIException("Destination edge '" + edgeID + "' is not known.");
1223 }
1224 // build a new route between the vehicle's current edge and destination edge
1225 ConstMSEdgeVector newRoute;
1226 const MSEdge* currentEdge = veh->getRerouteOrigin();
1228 currentEdge, destEdge, veh, MSNet::getInstance()->getCurrentTimeStep(), newRoute);
1229 // replace the vehicle's route by the new one (cost is updated by call to reroute())
1230 std::string errorMsg;
1231 if (!veh->replaceRouteEdges(newRoute, -1, 0, "traci:changeTarget", onInit, false, true, &errorMsg)) {
1232 throw TraCIException("Route replacement failed for vehicle '" + veh->getID() + "' (" + errorMsg + ").");
1233 }
1234 // route again to ensure usage of via/stops
1235 try {
1236 veh->reroute(MSNet::getInstance()->getCurrentTimeStep(), "traci:changeTarget",
1237 veh->getBaseInfluencer().getRouterTT(veh->getRNGIndex(), veh->getVClass()), onInit);
1238 } catch (ProcessError& e) {
1239 throw TraCIException(e.what());
1240 }
1241}
1242
1243
1244void
1245Vehicle::changeLane(const std::string& vehID, int laneIndex, double duration) {
1246 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1247 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1248 if (veh == nullptr) {
1249 WRITE_ERROR(TL("changeLane not applicable for meso"));
1250 return;
1251 }
1252
1253 std::vector<std::pair<SUMOTime, int> > laneTimeLine;
1254 laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), laneIndex));
1255 laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep() + TIME2STEPS(duration), laneIndex));
1256 veh->getInfluencer().setLaneTimeLine(laneTimeLine);
1257}
1258
1259void
1260Vehicle::changeLaneRelative(const std::string& vehID, int indexOffset, double duration) {
1261 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1262 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1263 if (veh == nullptr) {
1264 WRITE_ERROR(TL("changeLaneRelative not applicable for meso"));
1265 return;
1266 }
1267
1268 std::vector<std::pair<SUMOTime, int> > laneTimeLine;
1269 int laneIndex = veh->getLaneIndex() + indexOffset;
1270 if (laneIndex < 0 && !veh->getLaneChangeModel().isOpposite()) {
1271 if (veh->getLaneIndex() == -1) {
1272 WRITE_WARNING("Ignoring changeLaneRelative for vehicle '" + vehID + "' that isn't on the road");
1273 } else {
1274 WRITE_WARNING("Ignoring indexOffset " + toString(indexOffset) + " for vehicle '" + vehID + "' on laneIndex " + toString(veh->getLaneIndex()));
1275 }
1276 } else {
1277 laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), laneIndex));
1278 laneTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep() + TIME2STEPS(duration), laneIndex));
1279 veh->getInfluencer().setLaneTimeLine(laneTimeLine);
1280 }
1281}
1282
1283
1284void
1285Vehicle::changeSublane(const std::string& vehID, double latDist) {
1286 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1287 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1288 if (veh == nullptr) {
1289 WRITE_ERROR(TL("changeSublane not applicable for meso"));
1290 return;
1291 }
1292
1293 veh->getInfluencer().setSublaneChange(latDist);
1294}
1295
1296
1297void
1298Vehicle::add(const std::string& vehID,
1299 const std::string& routeID,
1300 const std::string& typeID,
1301 const std::string& depart,
1302 const std::string& departLane,
1303 const std::string& departPos,
1304 const std::string& departSpeed,
1305 const std::string& arrivalLane,
1306 const std::string& arrivalPos,
1307 const std::string& arrivalSpeed,
1308 const std::string& fromTaz,
1309 const std::string& toTaz,
1310 const std::string& line,
1311 int /*personCapacity*/,
1312 int personNumber) {
1314 if (veh != nullptr) {
1315 throw TraCIException("The vehicle '" + vehID + "' to add already exists.");
1316 }
1317
1318 SUMOVehicleParameter vehicleParams;
1319 vehicleParams.id = vehID;
1320 MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(typeID);
1321 if (!vehicleType) {
1322 throw TraCIException("Invalid type '" + typeID + "' for vehicle '" + vehID + "'.");
1323 }
1324 const MSRoute* route = MSRoute::dictionary(routeID);
1325 if (!route) {
1326 if (routeID == "") {
1327 // assume, route was intentionally left blank because the caller
1328 // intends to control the vehicle remotely
1329 SUMOVehicleClass vclass = vehicleType->getVehicleClass();
1330 const std::string dummyRouteID = "DUMMY_ROUTE_" + SumoVehicleClassStrings.getString(vclass);
1331 route = MSRoute::dictionary(dummyRouteID);
1332 if (route == nullptr) {
1333 for (MSEdge* e : MSEdge::getAllEdges()) {
1334 if (e->getFunction() == SumoXMLEdgeFunc::NORMAL && (e->getPermissions() & vclass) == vclass) {
1335 std::vector<std::string> edges;
1336 edges.push_back(e->getID());
1337 libsumo::Route::add(dummyRouteID, edges);
1338 break;
1339 }
1340 }
1341 }
1342 route = MSRoute::dictionary(dummyRouteID);
1343 if (!route) {
1344 throw TraCIException("Could not build dummy route for vehicle class: '" + SumoVehicleClassStrings.getString(vehicleType->getVehicleClass()) + "'");
1345 }
1346 } else {
1347 throw TraCIException("Invalid route '" + routeID + "' for vehicle '" + vehID + "'.");
1348 }
1349 }
1350 // check if the route implies a trip
1351 if (route->getEdges().size() == 2) {
1352 const MSEdgeVector& succ = route->getEdges().front()->getSuccessors();
1353 if (std::find(succ.begin(), succ.end(), route->getEdges().back()) == succ.end()) {
1354 vehicleParams.parametersSet |= VEHPARS_FORCE_REROUTE;
1355 }
1356 }
1357 if (fromTaz != "" || toTaz != "") {
1358 vehicleParams.parametersSet |= VEHPARS_FORCE_REROUTE;
1359 }
1360 std::string error;
1361 if (!SUMOVehicleParameter::parseDepart(depart, "vehicle", vehID, vehicleParams.depart, vehicleParams.departProcedure, error)) {
1362 throw TraCIException(error);
1363 }
1364 if (vehicleParams.departProcedure == DepartDefinition::GIVEN && vehicleParams.depart < MSNet::getInstance()->getCurrentTimeStep()) {
1365 vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
1366 WRITE_WARNING("Departure time for vehicle '" + vehID + "' is in the past; using current time instead.");
1367 } else if (vehicleParams.departProcedure == DepartDefinition::NOW) {
1368 vehicleParams.depart = MSNet::getInstance()->getCurrentTimeStep();
1369 }
1370 if (!SUMOVehicleParameter::parseDepartLane(departLane, "vehicle", vehID, vehicleParams.departLane, vehicleParams.departLaneProcedure, error)) {
1371 throw TraCIException(error);
1372 }
1373 if (!SUMOVehicleParameter::parseDepartPos(departPos, "vehicle", vehID, vehicleParams.departPos, vehicleParams.departPosProcedure, error)) {
1374 throw TraCIException(error);
1375 }
1376 if (!SUMOVehicleParameter::parseDepartSpeed(departSpeed, "vehicle", vehID, vehicleParams.departSpeed, vehicleParams.departSpeedProcedure, error)) {
1377 throw TraCIException(error);
1378 }
1379 if (!SUMOVehicleParameter::parseArrivalLane(arrivalLane, "vehicle", vehID, vehicleParams.arrivalLane, vehicleParams.arrivalLaneProcedure, error)) {
1380 throw TraCIException(error);
1381 }
1382 if (!SUMOVehicleParameter::parseArrivalPos(arrivalPos, "vehicle", vehID, vehicleParams.arrivalPos, vehicleParams.arrivalPosProcedure, error)) {
1383 throw TraCIException(error);
1384 }
1385 if (!SUMOVehicleParameter::parseArrivalSpeed(arrivalSpeed, "vehicle", vehID, vehicleParams.arrivalSpeed, vehicleParams.arrivalSpeedProcedure, error)) {
1386 throw TraCIException(error);
1387 }
1388 // mark non-default attributes
1389 if (departLane != "first") {
1390 vehicleParams.parametersSet |= VEHPARS_DEPARTLANE_SET;
1391 }
1392 if (departPos != "base") {
1393 vehicleParams.parametersSet |= VEHPARS_DEPARTPOS_SET;
1394 }
1395 if (departSpeed != "0") {
1396 vehicleParams.parametersSet |= VEHPARS_DEPARTSPEED_SET;
1397 }
1398 if (arrivalLane != "current") {
1399 vehicleParams.parametersSet |= VEHPARS_ARRIVALLANE_SET;
1400 }
1401 if (arrivalPos != "max") {
1402 vehicleParams.parametersSet |= VEHPARS_ARRIVALPOS_SET;
1403 }
1404 if (arrivalSpeed != "current") {
1405 vehicleParams.parametersSet |= VEHPARS_ARRIVALSPEED_SET;
1406 }
1407 if (fromTaz != "") {
1408 vehicleParams.parametersSet |= VEHPARS_FROM_TAZ_SET;
1409 }
1410 if (toTaz != "") {
1411 vehicleParams.parametersSet |= VEHPARS_TO_TAZ_SET;
1412 }
1413 if (line != "") {
1414 vehicleParams.parametersSet |= VEHPARS_LINE_SET;
1415 }
1416 if (personNumber != 0) {
1418 }
1419 // build vehicle
1420 vehicleParams.fromTaz = fromTaz;
1421 vehicleParams.toTaz = toTaz;
1422 vehicleParams.line = line;
1423 //vehicleParams.personCapacity = personCapacity;
1424 vehicleParams.personNumber = personNumber;
1425
1426 SUMOVehicleParameter* params = new SUMOVehicleParameter(vehicleParams);
1427 SUMOVehicle* vehicle = nullptr;
1428 try {
1429 vehicle = MSNet::getInstance()->getVehicleControl().buildVehicle(params, route, vehicleType, true, false);
1430 if (fromTaz == "" && !route->getEdges().front()->validateDepartSpeed(*vehicle)) {
1432 throw TraCIException("Departure speed for vehicle '" + vehID + "' is too high for the departure edge '" + route->getEdges().front()->getID() + "'.");
1433 }
1434 std::string msg;
1435 if (vehicle->getRouteValidity(true, true, &msg) != MSBaseVehicle::ROUTE_VALID) {
1437 throw TraCIException("Vehicle '" + vehID + "' has no valid route (" + msg + "). ");
1438 }
1439 MSNet::getInstance()->getVehicleControl().addVehicle(vehicleParams.id, vehicle);
1442 }
1443 } catch (ProcessError& e) {
1444 if (vehicle != nullptr) {
1446 }
1447 throw TraCIException(e.what());
1448 }
1449}
1450
1451
1452void
1453Vehicle::moveToXY(const std::string& vehID, const std::string& edgeID, const int laneIndex,
1454 const double x, const double y, double angle, const int keepRoute, double matchThreshold) {
1455 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1456 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1457 if (veh == nullptr) {
1458 WRITE_WARNING(TL("moveToXY not yet implemented for meso"));
1459 return;
1460 }
1461 const bool doKeepRoute = (keepRoute & 1) != 0 && veh->getID() != "VTD_EGO";
1462 const bool mayLeaveNetwork = (keepRoute & 2) != 0;
1463 const bool ignorePermissions = (keepRoute & 4) != 0;
1464 const bool setLateralPos = (MSGlobals::gLateralResolution > 0 || mayLeaveNetwork);
1465 SUMOVehicleClass vClass = ignorePermissions ? SVC_IGNORING : veh->getVClass();
1466 // process
1467 const std::string origID = edgeID + "_" + toString(laneIndex);
1468 // @todo add an interpretation layer for OSM derived origID values (without lane index)
1469 Position pos(x, y);
1470#ifdef DEBUG_MOVEXY
1471 const double origAngle = angle;
1472#endif
1473 // angle must be in [0,360] because it will be compared against those returned by naviDegree()
1474 // angle set to INVALID_DOUBLE_VALUE is ignored in the evaluated and later set to the angle of the matched lane
1475 if (angle != INVALID_DOUBLE_VALUE) {
1476 while (angle >= 360.) {
1477 angle -= 360.;
1478 }
1479 while (angle < 0.) {
1480 angle += 360.;
1481 }
1482 }
1483
1484 Position vehPos = veh->getPosition();
1485#ifdef DEBUG_MOVEXY
1486 std::cout << std::endl << SIMTIME << " moveToXY veh=" << veh->getID() << " vehPos=" << vehPos
1487 << " lane=" << Named::getIDSecure(veh->getLane()) << " lanePos=" << vehicle->getPositionOnLane() << std::endl;
1488 std::cout << " wantedPos=" << pos << " origID=" << origID << " laneIndex=" << laneIndex << " origAngle=" << origAngle << " angle=" << angle << " keepRoute=" << keepRoute << std::endl;
1489#endif
1490
1491 ConstMSEdgeVector edges;
1492 MSLane* lane = nullptr;
1493 double lanePos;
1494 double lanePosLat = 0;
1495 double bestDistance = std::numeric_limits<double>::max();
1496 int routeOffset = 0;
1497 bool found;
1498 double maxRouteDistance = matchThreshold;
1499 /* EGO vehicle is known to have a fixed route. @todo make this into a parameter of the TraCI call */
1500 if (doKeepRoute) {
1501 // case a): vehicle is on its earlier route
1502 // we additionally assume it is moving forward (SUMO-limit);
1503 // note that the route ("edges") is not changed in this case
1504
1506 veh->getRoute().getEdges(), (int)(veh->getCurrentRouteEdge() - veh->getRoute().begin()),
1507 vClass, setLateralPos,
1508 bestDistance, &lane, lanePos, routeOffset);
1509 // @note silenty ignoring mapping failure
1510 } else {
1511 double speed = pos.distanceTo2D(veh->getPosition()); // !!!veh->getSpeed();
1512 found = Helper::moveToXYMap(pos, maxRouteDistance, mayLeaveNetwork, origID, angle,
1513 speed, veh->getRoute().getEdges(), veh->getRoutePosition(), veh->getLane(), veh->getPositionOnLane(), veh->isOnRoad(),
1514 vClass, setLateralPos,
1515 bestDistance, &lane, lanePos, routeOffset, edges);
1516 }
1517 if ((found && bestDistance <= maxRouteDistance) || mayLeaveNetwork) {
1518 // optionally compute lateral offset
1519 pos.setz(veh->getPosition().z());
1520 if (found && setLateralPos) {
1521 const double perpDist = lane->getShape().distance2D(pos, false);
1522 if (perpDist != GeomHelper::INVALID_OFFSET) {
1523 lanePosLat = perpDist;
1524 if (!mayLeaveNetwork) {
1525 lanePosLat = MIN2(lanePosLat, 0.5 * (lane->getWidth() + veh->getVehicleType().getWidth() - MSGlobals::gLateralResolution));
1526 }
1527 // figure out whether the offset is to the left or to the right
1528 PositionVector tmp = lane->getShape();
1529 try {
1530 tmp.move2side(-lanePosLat); // moved to left
1531 } catch (ProcessError&) {
1532 WRITE_WARNING("Could not determine position on lane '" + lane->getID() + "' at lateral position " + toString(-lanePosLat) + ".");
1533 }
1534 //std::cout << " lane=" << lane->getID() << " posLat=" << lanePosLat << " shape=" << lane->getShape() << " tmp=" << tmp << " tmpDist=" << tmp.distance2D(pos) << "\n";
1535 if (tmp.distance2D(pos) > perpDist) {
1536 lanePosLat = -lanePosLat;
1537 }
1538 }
1539 pos.setz(lane->geometryPositionAtOffset(lanePos).z());
1540 }
1541 if (found && !mayLeaveNetwork && MSGlobals::gLateralResolution < 0) {
1542 // mapped position may differ from pos
1543 pos = lane->geometryPositionAtOffset(lanePos, -lanePosLat);
1544 }
1545 assert((found && lane != 0) || (!found && lane == 0));
1546 assert(!ISNAN(lanePos));
1547 if (angle == INVALID_DOUBLE_VALUE) {
1548 if (lane != nullptr) {
1549 angle = GeomHelper::naviDegree(lane->getShape().rotationAtOffset(lanePos));
1550 } else {
1551 // compute angle outside road network from old and new position
1552 angle = GeomHelper::naviDegree(veh->getPosition().angleTo2D(pos));
1553 }
1554 }
1555 // use the best we have
1556#ifdef DEBUG_MOVEXY
1557 std::cout << SIMTIME << " veh=" << vehID + " moveToXYResult lane='" << Named::getIDSecure(lane) << "' lanePos=" << lanePos << " lanePosLat=" << lanePosLat << "\n";
1558#endif
1559 Helper::setRemoteControlled(veh, pos, lane, lanePos, lanePosLat, angle, routeOffset, edges, MSNet::getInstance()->getCurrentTimeStep());
1560 if (!veh->isOnRoad()) {
1562 }
1563 } else {
1564 if (lane == nullptr) {
1565 throw TraCIException("Could not map vehicle '" + vehID + "', no road found within " + toString(maxRouteDistance) + "m.");
1566 } else {
1567 throw TraCIException("Could not map vehicle '" + vehID + "', distance to road is " + toString(bestDistance) + ".");
1568 }
1569 }
1570}
1571
1572void
1573Vehicle::slowDown(const std::string& vehID, double speed, double duration) {
1574 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1575 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1576 if (veh == nullptr) {
1577 WRITE_ERROR(TL("slowDown not applicable for meso"));
1578 return;
1579 }
1580
1581 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
1582 speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), veh->getSpeed()));
1583 speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep() + TIME2STEPS(duration), speed));
1584 veh->getInfluencer().setSpeedTimeLine(speedTimeLine);
1585}
1586
1587void
1588Vehicle::openGap(const std::string& vehID, double newTimeHeadway, double newSpaceHeadway, double duration, double changeRate, double maxDecel, const std::string& referenceVehID) {
1589 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1590 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1591 if (veh == nullptr) {
1592 WRITE_ERROR(TL("openGap not applicable for meso"));
1593 return;
1594 }
1595
1596 MSVehicle* refVeh = nullptr;
1597 if (referenceVehID != "") {
1598 refVeh = dynamic_cast<MSVehicle*>(Helper::getVehicle(referenceVehID));
1599 }
1600 const double originalTau = veh->getVehicleType().getCarFollowModel().getHeadwayTime();
1601 if (newTimeHeadway == -1) {
1602 newTimeHeadway = originalTau;
1603 }
1604 if (originalTau > newTimeHeadway) {
1605 WRITE_WARNING(TL("Ignoring openGap(). New time headway must not be smaller than the original."));
1606 return;
1607 }
1608 veh->getInfluencer().activateGapController(originalTau, newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel, refVeh);
1609}
1610
1611void
1612Vehicle::deactivateGapControl(const std::string& vehID) {
1613 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1614 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1615 if (veh == nullptr) {
1616 WRITE_ERROR(TL("deactivateGapControl not applicable for meso"));
1617 return;
1618 }
1619
1620 if (veh->hasInfluencer()) {
1622 }
1623}
1624
1625void
1626Vehicle::requestToC(const std::string& vehID, double leadTime) {
1627 setParameter(vehID, "device.toc.requestToC", toString(leadTime));
1628}
1629
1630void
1631Vehicle::setSpeed(const std::string& vehID, double speed) {
1632 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1633 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1634 if (veh == nullptr) {
1635 WRITE_WARNING(TL("setSpeed not yet implemented for meso"));
1636 return;
1637 }
1638
1639 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
1640 if (speed >= 0) {
1641 speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), speed));
1642 speedTimeLine.push_back(std::make_pair(SUMOTime_MAX - DELTA_T, speed));
1643 }
1644 veh->getInfluencer().setSpeedTimeLine(speedTimeLine);
1645}
1646
1647void
1648Vehicle::setAcceleration(const std::string& vehID, double accel, double duration) {
1649 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1650 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1651 if (veh == nullptr) {
1652 WRITE_WARNING(TL("setAcceleration not yet implemented for meso"));
1653 return;
1654 }
1655
1656 double targetSpeed = std::max(veh->getSpeed() + accel * duration, 0.0);
1657 std::vector<std::pair<SUMOTime, double>> speedTimeLine;
1658 speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep(), veh->getSpeed()));
1659 speedTimeLine.push_back(std::make_pair(MSNet::getInstance()->getCurrentTimeStep() + TIME2STEPS(duration), targetSpeed));
1660 veh->getInfluencer().setSpeedTimeLine(speedTimeLine);
1661}
1662
1663void
1664Vehicle::setPreviousSpeed(const std::string& vehID, double prevSpeed, double prevAcceleration) {
1665 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1666 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1667 if (veh == nullptr) {
1668 WRITE_WARNING(TL("setPreviousSpeed not yet implemented for meso"));
1669 return;
1670 }
1671 if (prevAcceleration == INVALID_DOUBLE_VALUE) {
1672 prevAcceleration = std::numeric_limits<double>::min();
1673 }
1674 veh->setPreviousSpeed(prevSpeed, prevAcceleration);
1675}
1676
1677void
1678Vehicle::setSpeedMode(const std::string& vehID, int speedMode) {
1679 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1680 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1681 if (veh == nullptr) {
1682 WRITE_WARNING(TL("setSpeedMode not yet implemented for meso"));
1683 return;
1684 }
1685
1686 veh->getInfluencer().setSpeedMode(speedMode);
1687}
1688
1689void
1690Vehicle::setLaneChangeMode(const std::string& vehID, int laneChangeMode) {
1691 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1692 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1693 if (veh == nullptr) {
1694 WRITE_ERROR(TL("setLaneChangeMode not applicable for meso"));
1695 return;
1696 }
1697
1698 veh->getInfluencer().setLaneChangeMode(laneChangeMode);
1699}
1700
1701void
1702Vehicle::setRoutingMode(const std::string& vehID, int routingMode) {
1704}
1705
1706void
1707Vehicle::setType(const std::string& vehID, const std::string& typeID) {
1708 MSVehicleType* vehicleType = MSNet::getInstance()->getVehicleControl().getVType(typeID);
1709 if (vehicleType == nullptr) {
1710 throw TraCIException("Vehicle type '" + typeID + "' is not known");
1711 }
1712 MSBaseVehicle* veh = Helper::getVehicle(vehID);
1713 veh->replaceVehicleType(vehicleType);
1714 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
1715 if (microVeh != nullptr && microVeh->isOnRoad()) {
1716 microVeh->updateBestLanes(true);
1717 }
1718}
1719
1720void
1721Vehicle::setRouteID(const std::string& vehID, const std::string& routeID) {
1722 MSBaseVehicle* veh = Helper::getVehicle(vehID);
1723 const MSRoute* r = MSRoute::dictionary(routeID);
1724 if (r == nullptr) {
1725 throw TraCIException("The route '" + routeID + "' is not known.");
1726 }
1727 std::string msg;
1728 if (!veh->hasValidRoute(msg, r)) {
1729 WRITE_WARNING("Invalid route replacement for vehicle '" + veh->getID() + "'. " + msg);
1731 throw TraCIException("Route replacement failed for " + veh->getID());
1732 }
1733 }
1734
1735 std::string errorMsg;
1736 if (!veh->replaceRoute(r, "traci:setRouteID", veh->getLane() == nullptr, 0, true, true, &errorMsg)) {
1737 throw TraCIException("Route replacement failed for vehicle '" + veh->getID() + "' (" + errorMsg + ").");
1738 }
1739}
1740
1741void
1742Vehicle::setRoute(const std::string& vehID, const std::string& edgeID) {
1743 setRoute(vehID, std::vector<std::string>({edgeID}));
1744}
1745
1746void
1747Vehicle::setRoute(const std::string& vehID, const std::vector<std::string>& edgeIDs) {
1748 MSBaseVehicle* veh = Helper::getVehicle(vehID);
1749 ConstMSEdgeVector edges;
1750 const bool onInit = veh->getLane() == nullptr;
1751 try {
1752 MSEdge::parseEdgesList(edgeIDs, edges, "<unknown>");
1753 if (edges.size() > 0 && edges.front()->isInternal()) {
1754 if (edges.size() == 1) {
1755 // avoid crashing due to lack of normal edges in route (#5390)
1756 edges.push_back(edges.back()->getLanes()[0]->getNextNormal());
1757 } else {
1758 // avoid internal edge in final route
1759 if (edges.front() == &veh->getLane()->getEdge()) {
1760 edges.erase(edges.begin());
1761 }
1762 }
1763 }
1764 } catch (ProcessError& e) {
1765 throw TraCIException("Invalid edge list for vehicle '" + veh->getID() + "' (" + e.what() + ")");
1766 }
1767 std::string errorMsg;
1768 if (!veh->replaceRouteEdges(edges, -1, 0, "traci:setRoute", onInit, true, true, &errorMsg)) {
1769 throw TraCIException("Route replacement failed for vehicle '" + veh->getID() + "' (" + errorMsg + ").");
1770 }
1771}
1772
1773void
1774Vehicle::updateBestLanes(const std::string& vehID) {
1775 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1776 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1777 if (veh == nullptr) {
1778 WRITE_ERROR(TL("updateBestLanes not applicable for meso"));
1779 return;
1780 }
1781 if (veh->isOnRoad()) {
1782 veh->updateBestLanes(true);
1783 }
1784}
1785
1786
1787void
1788Vehicle::setAdaptedTraveltime(const std::string& vehID, const std::string& edgeID,
1789 double time, double begSeconds, double endSeconds) {
1790 MSBaseVehicle* veh = Helper::getVehicle(vehID);
1791 MSEdge* edge = MSEdge::dictionary(edgeID);
1792 if (edge == nullptr) {
1793 throw TraCIException("Edge '" + edgeID + "' is not known.");
1794 }
1795 if (time != INVALID_DOUBLE_VALUE) {
1796 // add time
1797 if (begSeconds == 0 && endSeconds == std::numeric_limits<double>::max()) {
1798 // clean up old values before setting whole range
1799 while (veh->getWeightsStorage().knowsTravelTime(edge)) {
1801 }
1802 }
1803 veh->getWeightsStorage().addTravelTime(edge, begSeconds, endSeconds, time);
1804 } else {
1805 // remove time
1806 while (veh->getWeightsStorage().knowsTravelTime(edge)) {
1808 }
1809 }
1810}
1811
1812
1813void
1814Vehicle::setEffort(const std::string& vehID, const std::string& edgeID,
1815 double effort, double begSeconds, double endSeconds) {
1816 MSBaseVehicle* veh = Helper::getVehicle(vehID);
1817 MSEdge* edge = MSEdge::dictionary(edgeID);
1818 if (edge == nullptr) {
1819 throw TraCIException("Edge '" + edgeID + "' is not known.");
1820 }
1821 if (effort != INVALID_DOUBLE_VALUE) {
1822 // add effort
1823 if (begSeconds == 0 && endSeconds == std::numeric_limits<double>::max()) {
1824 // clean up old values before setting whole range
1825 while (veh->getWeightsStorage().knowsEffort(edge)) {
1826 veh->getWeightsStorage().removeEffort(edge);
1827 }
1828 }
1829 veh->getWeightsStorage().addEffort(edge, begSeconds, endSeconds, effort);
1830 } else {
1831 // remove effort
1832 while (veh->getWeightsStorage().knowsEffort(edge)) {
1833 veh->getWeightsStorage().removeEffort(edge);
1834 }
1835 }
1836}
1837
1838
1839void
1840Vehicle::rerouteTraveltime(const std::string& vehID, const bool currentTravelTimes) {
1841 MSBaseVehicle* veh = Helper::getVehicle(vehID);
1842 const int routingMode = veh->getBaseInfluencer().getRoutingMode();
1843 if (currentTravelTimes && routingMode == ROUTING_MODE_DEFAULT) {
1845 }
1846 veh->reroute(MSNet::getInstance()->getCurrentTimeStep(), "traci:rerouteTraveltime",
1847 veh->getBaseInfluencer().getRouterTT(veh->getRNGIndex(), veh->getVClass()), isOnInit(vehID));
1848 if (currentTravelTimes && routingMode == ROUTING_MODE_DEFAULT) {
1849 veh->getBaseInfluencer().setRoutingMode(routingMode);
1850 }
1851}
1852
1853
1854void
1855Vehicle::rerouteEffort(const std::string& vehID) {
1856 MSBaseVehicle* veh = Helper::getVehicle(vehID);
1857 veh->reroute(MSNet::getInstance()->getCurrentTimeStep(), "traci:rerouteEffort",
1858 MSNet::getInstance()->getRouterEffort(veh->getRNGIndex()), isOnInit(vehID));
1859}
1860
1861
1862void
1863Vehicle::setSignals(const std::string& vehID, int signals) {
1864 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1865 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1866 if (veh == nullptr) {
1867 WRITE_ERROR(TL("setSignals not applicable for meso"));
1868 return;
1869 }
1870
1871 // set influencer to make the change persistent
1872 veh->getInfluencer().setSignals(signals);
1873 // set them now so that getSignals returns the correct value
1874 veh->switchOffSignal(0x0fffffff);
1875 if (signals >= 0) {
1876 veh->switchOnSignal(signals);
1877 }
1878}
1879
1880
1881void
1882Vehicle::moveTo(const std::string& vehID, const std::string& laneID, double position, int reason) {
1883 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1884 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1885 if (veh == nullptr) {
1886 WRITE_WARNING(TL("moveTo not yet implemented for meso"));
1887 return;
1888 }
1889
1890 MSLane* l = MSLane::dictionary(laneID);
1891 if (l == nullptr) {
1892 throw TraCIException("Unknown lane '" + laneID + "'.");
1893 }
1894 if (veh->getLane() == l) {
1895 veh->setTentativeLaneAndPosition(l, position, veh->getLateralPositionOnLane());
1896 return;
1897 }
1898 MSEdge* destinationEdge = &l->getEdge();
1899 const MSEdge* destinationRouteEdge = destinationEdge->getNormalBefore();
1900 if (!veh->isOnRoad() && veh->getParameter().wasSet(VEHPARS_FORCE_REROUTE) && veh->getRoute().getEdges().size() == 2) {
1901 // it's a trip that wasn't routeted yet (likely because the vehicle was added in this step. Find a route now
1902 veh->reroute(MSNet::getInstance()->getCurrentTimeStep(), "traci:moveTo-tripInsertion",
1903 veh->getBaseInfluencer().getRouterTT(veh->getRNGIndex(), veh->getVClass()), true);
1904 }
1905 // find edge in the remaining route
1906 MSRouteIterator it = std::find(veh->getCurrentRouteEdge(), veh->getRoute().end(), destinationRouteEdge);
1907 if (it == veh->getRoute().end()) {
1908 // find edge in the edges that were already passed
1909 it = std::find(veh->getRoute().begin(), veh->getRoute().end(), destinationRouteEdge);
1910 }
1911 if (it == veh->getRoute().end() ||
1912 // internal edge must continue the route
1913 (destinationEdge->isInternal() &&
1914 ((it + 1) == veh->getRoute().end()
1915 || l->getNextNormal() != *(it + 1)))) {
1916 throw TraCIException("Lane '" + laneID + "' is not on the route of vehicle '" + vehID + "'.");
1917 }
1918 Position oldPos = vehicle->getPosition();
1920 if (veh->getLane() != nullptr) {
1921 // correct odometer which gets incremented via onRemovalFromNet->leaveLane
1922 veh->addToOdometer(-veh->getLane()->getLength());
1924 } else {
1925 veh->setTentativeLaneAndPosition(l, position);
1926 }
1927 const int oldRouteIndex = veh->getRoutePosition();
1928 const int newRouteIndex = (int)(it - veh->getRoute().begin());
1929 if (oldRouteIndex > newRouteIndex) {
1930 // more odometer correction needed
1931 veh->addToOdometer(-l->getLength());
1932 }
1933 veh->resetRoutePosition(newRouteIndex, veh->getParameter().departLaneProcedure);
1934 if (!veh->isOnRoad()) {
1936 }
1937 MSMoveReminder::Notification moveReminderReason;
1938 if (veh->hasDeparted()) {
1939 if (reason == MOVE_TELEPORT) {
1940 moveReminderReason = MSMoveReminder::NOTIFICATION_TELEPORT;
1941 } else if (reason == MOVE_NORMAL) {
1942 moveReminderReason = MSMoveReminder::NOTIFICATION_JUNCTION;
1943 } else if (reason == MOVE_AUTOMATIC) {
1944 Position newPos = l->geometryPositionAtOffset(position);
1945 const double dist = newPos.distanceTo2D(oldPos);
1946 if (dist < SPEED2DIST(veh->getMaxSpeed())) {
1947 moveReminderReason = MSMoveReminder::NOTIFICATION_JUNCTION;
1948 } else {
1949 moveReminderReason = MSMoveReminder::NOTIFICATION_TELEPORT;
1950 }
1951 } else {
1952 throw TraCIException("Invalid moveTo reason '" + toString(reason) + "' for vehicle '" + vehID + "'.");
1953 }
1954 } else {
1955 moveReminderReason = MSMoveReminder::NOTIFICATION_DEPARTED;
1956 }
1957 l->forceVehicleInsertion(veh, position, moveReminderReason);
1958}
1959
1960
1961void
1962Vehicle::setActionStepLength(const std::string& vehID, double actionStepLength, bool resetActionOffset) {
1963 if (actionStepLength < 0.0) {
1964 WRITE_ERROR(TL("Invalid action step length (<0). Ignoring command setActionStepLength()."));
1965 return;
1966 }
1967 MSBaseVehicle* vehicle = Helper::getVehicle(vehID);
1968 MSVehicle* veh = dynamic_cast<MSVehicle*>(vehicle);
1969 if (veh == nullptr) {
1970 WRITE_ERROR(TL("setActionStepLength not applicable for meso"));
1971 return;
1972 }
1973
1974 if (actionStepLength == 0.) {
1975 veh->resetActionOffset();
1976 } else {
1977 veh->setActionStepLength(actionStepLength, resetActionOffset);
1978 }
1979}
1980
1981
1982void
1983Vehicle::remove(const std::string& vehID, char reason) {
1984 MSBaseVehicle* veh = Helper::getVehicle(vehID);
1986 switch (reason) {
1987 case REMOVE_TELEPORT:
1988 // XXX semantics unclear
1989 // n = MSMoveReminder::NOTIFICATION_TELEPORT;
1991 break;
1992 case REMOVE_PARKING:
1993 // XXX semantics unclear
1994 // n = MSMoveReminder::NOTIFICATION_PARKING;
1996 break;
1997 case REMOVE_ARRIVED:
1999 break;
2000 case REMOVE_VAPORIZED:
2002 break;
2005 break;
2006 default:
2007 throw TraCIException("Unknown removal status.");
2008 }
2009 if (veh->hasDeparted()) {
2010 veh->onRemovalFromNet(n);
2011 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
2012 if (microVeh != nullptr) {
2013 if (veh->getLane() != nullptr) {
2014 microVeh->getMutableLane()->removeVehicle(dynamic_cast<MSVehicle*>(veh), n);
2015 }
2017 }
2019 } else {
2022 }
2023}
2024
2025
2026void
2027Vehicle::setColor(const std::string& vehID, const TraCIColor& col) {
2029 p.color.set((unsigned char)col.r, (unsigned char)col.g, (unsigned char)col.b, (unsigned char)col.a);
2031}
2032
2033
2034void
2035Vehicle::setSpeedFactor(const std::string& vehID, double factor) {
2037}
2038
2039
2040void
2041Vehicle::setLine(const std::string& vehID, const std::string& line) {
2042 Helper::getVehicle(vehID)->getParameter().line = line;
2043}
2044
2045
2046void
2047Vehicle::setVia(const std::string& vehID, const std::vector<std::string>& via) {
2048 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2049 try {
2050 // ensure edges exist
2051 ConstMSEdgeVector edges;
2052 MSEdge::parseEdgesList(via, edges, "<via-edges>");
2053 } catch (ProcessError& e) {
2054 throw TraCIException(e.what());
2055 }
2056 veh->getParameter().via = via;
2057}
2058
2059
2060void
2061Vehicle::setLength(const std::string& vehID, double length) {
2063}
2064
2065
2066void
2067Vehicle::setMaxSpeed(const std::string& vehID, double speed) {
2069}
2070
2071
2072void
2073Vehicle::setVehicleClass(const std::string& vehID, const std::string& clazz) {
2074 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2076 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
2077 if (microVeh != nullptr && microVeh->isOnRoad()) {
2078 microVeh->updateBestLanes(true);
2079 }
2080}
2081
2082
2083void
2084Vehicle::setShapeClass(const std::string& vehID, const std::string& clazz) {
2086}
2087
2088
2089void
2090Vehicle::setEmissionClass(const std::string& vehID, const std::string& clazz) {
2092}
2093
2094
2095void
2096Vehicle::setWidth(const std::string& vehID, double width) {
2098}
2099
2100
2101void
2102Vehicle::setHeight(const std::string& vehID, double height) {
2104}
2105
2106
2107void
2108Vehicle::setMinGap(const std::string& vehID, double minGap) {
2110}
2111
2112
2113void
2114Vehicle::setAccel(const std::string& vehID, double accel) {
2116}
2117
2118
2119void
2120Vehicle::setDecel(const std::string& vehID, double decel) {
2121 VehicleType::setDecel(Helper::getVehicle(vehID)->getSingularType().getID(), decel);
2122}
2123
2124
2125void
2126Vehicle::setEmergencyDecel(const std::string& vehID, double decel) {
2127 VehicleType::setEmergencyDecel(Helper::getVehicle(vehID)->getSingularType().getID(), decel);
2128}
2129
2130
2131void
2132Vehicle::setApparentDecel(const std::string& vehID, double decel) {
2134}
2135
2136
2137void
2138Vehicle::setImperfection(const std::string& vehID, double imperfection) {
2139 Helper::getVehicle(vehID)->getSingularType().setImperfection(imperfection);
2140}
2141
2142
2143void
2144Vehicle::setTau(const std::string& vehID, double tau) {
2146}
2147
2148
2149void
2150Vehicle::setMinGapLat(const std::string& vehID, double minGapLat) {
2151 try {
2152 setParameter(vehID, "laneChangeModel.minGapLat", toString(minGapLat));
2153 } catch (TraCIException&) {
2154 // legacy behavior
2155 Helper::getVehicle(vehID)->getSingularType().setMinGapLat(minGapLat);
2156 }
2157}
2158
2159
2160void
2161Vehicle::setMaxSpeedLat(const std::string& vehID, double speed) {
2163}
2164
2165
2166void
2167Vehicle::setLateralAlignment(const std::string& vehID, const std::string& latAlignment) {
2168 double lao;
2170 if (SUMOVTypeParameter::parseLatAlignment(latAlignment, lao, lad)) {
2172 } else {
2173 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)");
2174 }
2175}
2176
2177
2178void
2179Vehicle::setParameter(const std::string& vehID, const std::string& key, const std::string& value) {
2180 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2181 MSVehicle* microVeh = dynamic_cast<MSVehicle*>(veh);
2182 if (StringUtils::startsWith(key, "device.")) {
2183 StringTokenizer tok(key, ".");
2184 if (tok.size() < 3) {
2185 throw TraCIException("Invalid device parameter '" + key + "' for vehicle '" + vehID + "'");
2186 }
2187 try {
2188 veh->setDeviceParameter(tok.get(1), key.substr(tok.get(0).size() + tok.get(1).size() + 2), value);
2189 } catch (InvalidArgument& e) {
2190 throw TraCIException("Vehicle '" + vehID + "' does not support device parameter '" + key + "' (" + e.what() + ").");
2191 }
2192 } else if (StringUtils::startsWith(key, "laneChangeModel.")) {
2193 if (microVeh == nullptr) {
2194 throw TraCIException("Meso Vehicle '" + vehID + "' does not support laneChangeModel parameters.");
2195 }
2196 const std::string attrName = key.substr(16);
2197 try {
2198 microVeh->getLaneChangeModel().setParameter(attrName, value);
2199 } catch (InvalidArgument& e) {
2200 throw TraCIException("Vehicle '" + vehID + "' does not support laneChangeModel parameter '" + key + "' (" + e.what() + ").");
2201 }
2202 } else if (StringUtils::startsWith(key, "carFollowModel.")) {
2203 if (microVeh == nullptr) {
2204 throw TraCIException("Meso Vehicle '" + vehID + "' does not support carFollowModel parameters.");
2205 }
2206 const std::string attrName = key.substr(15);
2207 try {
2208 microVeh->getCarFollowModel().setParameter(microVeh, attrName, value);
2209 } catch (InvalidArgument& e) {
2210 throw TraCIException("Vehicle '" + vehID + "' does not support carFollowModel parameter '" + key + "' (" + e.what() + ").");
2211 }
2212 } else if (StringUtils::startsWith(key, "junctionModel.")) {
2213 try {
2214 // use the whole key (including junctionModel prefix)
2215 veh->setJunctionModelParameter(key, value);
2216 } catch (InvalidArgument& e) {
2217 // error message includes id since it is also used for xml input
2218 throw TraCIException(e.what());
2219 }
2220 } else if (StringUtils::startsWith(key, "has.") && StringUtils::endsWith(key, ".device")) {
2221 StringTokenizer tok(key, ".");
2222 if (tok.size() != 3) {
2223 throw TraCIException("Invalid request for device status change. Expected format is 'has.DEVICENAME.device'");
2224 }
2225 const std::string deviceName = tok.get(1);
2226 bool create;
2227 try {
2228 create = StringUtils::toBool(value);
2229 } catch (BoolFormatException&) {
2230 throw TraCIException("Changing device status requires a 'true' or 'false'");
2231 }
2232 if (!create) {
2233 throw TraCIException("Device removal is not supported for device of type '" + deviceName + "'");
2234 }
2235 try {
2236 veh->createDevice(deviceName);
2237 } catch (InvalidArgument& e) {
2238 throw TraCIException("Cannot create vehicle device (" + std::string(e.what()) + ").");
2239 }
2240 } else {
2241 ((SUMOVehicleParameter&)veh->getParameter()).setParameter(key, value);
2242 }
2243}
2244
2245
2246void
2247Vehicle::highlight(const std::string& vehID, const TraCIColor& col, double size, const int alphaMax, const double duration, const int type) {
2248 // NOTE: Code is duplicated in large parts in POI.cpp
2249 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2250
2251 // Center of the highlight circle
2252 Position center = veh->getPosition();
2253 const double l2 = veh->getLength() * 0.5;
2254 center.sub(cos(veh->getAngle())*l2, sin(veh->getAngle())*l2);
2255 // Size of the highlight circle
2256 if (size <= 0) {
2257 size = veh->getLength() * 0.7;
2258 }
2259 // Make polygon shape
2260 const unsigned int nPoints = 34;
2261 const PositionVector circlePV = GeomHelper::makeRing(size, size + 1., center, nPoints);
2262 TraCIPositionVector circle = Helper::makeTraCIPositionVector(circlePV);
2263
2264#ifdef DEBUG_DYNAMIC_SHAPES
2265 std::cout << SIMTIME << " Vehicle::highlight() for vehicle '" << vehID << "'\n"
2266 << " circle: " << circlePV << std::endl;
2267#endif
2268
2269 // Find a free polygon id
2270 int i = 0;
2271 std::string polyID = veh->getID() + "_hl" + toString(i);
2272 while (Polygon::exists(polyID)) {
2273 polyID = veh->getID() + "_hl" + toString(++i);
2274 }
2275 // Line width
2276 double lw = 0.;
2277 // Layer
2278 double lyr = 0.;
2279 if (MSNet::getInstance()->isGUINet()) {
2280 lyr = GLO_VEHICLE + 0.01;
2281 lyr += (type + 1) / 257.;
2282 }
2283 // Make Polygon
2284 Polygon::addHighlightPolygon(vehID, type, polyID, circle, col, true, "highlight", (int)lyr, lw);
2285
2286 // Animation time line
2287 double maxAttack = 1.0; // maximal fade-in time
2288 std::vector<double> timeSpan;
2289 if (duration > 0.) {
2290 timeSpan = {0, MIN2(maxAttack, duration / 3.), 2.*duration / 3., duration};
2291 }
2292 // Alpha time line
2293 std::vector<double> alphaSpan;
2294 if (alphaMax > 0.) {
2295 alphaSpan = {0., (double) alphaMax, (double)(alphaMax) / 3., 0.};
2296 }
2297 // Attach dynamics
2298 Polygon::addDynamics(polyID, vehID, timeSpan, alphaSpan, false, true);
2299}
2300
2301void
2302Vehicle::dispatchTaxi(const std::string& vehID, const std::vector<std::string>& reservations) {
2303 MSBaseVehicle* veh = Helper::getVehicle(vehID);
2304 MSDevice_Taxi* taxi = static_cast<MSDevice_Taxi*>(veh->getDevice(typeid(MSDevice_Taxi)));
2305 if (taxi == nullptr) {
2306 throw TraCIException("Vehicle '" + vehID + "' is not a taxi");
2307 }
2309 if (dispatcher == nullptr) {
2310 throw TraCIException("Cannot dispatch taxi because no reservations have been made");
2311 }
2312 MSDispatch_TraCI* traciDispatcher = dynamic_cast<MSDispatch_TraCI*>(dispatcher);
2313 if (traciDispatcher == nullptr) {
2314 throw TraCIException("device.taxi.dispatch-algorithm 'traci' has not been loaded");
2315 }
2316 if (reservations.size() == 0) {
2317 throw TraCIException("No reservations have been specified for vehicle '" + vehID + "'");
2318 }
2319 try {
2320 traciDispatcher->interpretDispatch(taxi, reservations);
2321 } catch (InvalidArgument& e) {
2322 throw TraCIException("Could not interpret reservations for vehicle '" + vehID + "' (" + e.what() + ").");
2323 }
2324}
2325
2327
2328
2329void
2330Vehicle::subscribeLeader(const std::string& vehID, double dist, double begin, double end) {
2331 subscribe(vehID, std::vector<int>({ libsumo::VAR_LEADER }), begin, end,
2332 libsumo::TraCIResults({ {libsumo::VAR_LEADER, std::make_shared<libsumo::TraCIDouble>(dist)} }));
2333}
2334
2335
2336void
2337Vehicle::addSubscriptionFilterLanes(const std::vector<int>& lanes, bool noOpposite, double downstreamDist, double upstreamDist) {
2339 if (s != nullptr) {
2340 s->filterLanes = lanes;
2341 }
2342 if (noOpposite) {
2343 addSubscriptionFilterNoOpposite();
2344 }
2345 if (downstreamDist != INVALID_DOUBLE_VALUE) {
2346 addSubscriptionFilterDownstreamDistance(downstreamDist);
2347 }
2348 if (upstreamDist != INVALID_DOUBLE_VALUE) {
2349 addSubscriptionFilterUpstreamDistance(upstreamDist);
2350 }
2351}
2352
2353
2354void
2355Vehicle::addSubscriptionFilterNoOpposite() {
2357}
2358
2359
2360void
2361Vehicle::addSubscriptionFilterDownstreamDistance(double dist) {
2363 if (s != nullptr) {
2364 s->filterDownstreamDist = dist;
2365 }
2366}
2367
2368
2369void
2370Vehicle::addSubscriptionFilterUpstreamDistance(double dist) {
2372 if (s != nullptr) {
2373 s->filterUpstreamDist = dist;
2374 }
2375}
2376
2377
2378void
2379Vehicle::addSubscriptionFilterCFManeuver(double downstreamDist, double upstreamDist) {
2380 addSubscriptionFilterLeadFollow(std::vector<int>({0}));
2381 if (downstreamDist != INVALID_DOUBLE_VALUE) {
2382 addSubscriptionFilterDownstreamDistance(downstreamDist);
2383 }
2384 if (upstreamDist != INVALID_DOUBLE_VALUE) {
2385 addSubscriptionFilterUpstreamDistance(upstreamDist);
2386 }
2387
2388}
2389
2390
2391void
2392Vehicle::addSubscriptionFilterLCManeuver(int direction, bool noOpposite, double downstreamDist, double upstreamDist) {
2393 std::vector<int> lanes;
2394 if (direction == INVALID_INT_VALUE) {
2395 // Using default: both directions
2396 lanes = std::vector<int>({-1, 0, 1});
2397 } else if (direction != -1 && direction != 1) {
2398 WRITE_WARNING("Ignoring lane change subscription filter with non-neighboring lane offset direction=" +
2399 toString(direction) + ".");
2400 } else {
2401 lanes = std::vector<int>({0, direction});
2402 }
2403 addSubscriptionFilterLeadFollow(lanes);
2404 if (noOpposite) {
2405 addSubscriptionFilterNoOpposite();
2406 }
2407 if (downstreamDist != INVALID_DOUBLE_VALUE) {
2408 addSubscriptionFilterDownstreamDistance(downstreamDist);
2409 }
2410 if (upstreamDist != INVALID_DOUBLE_VALUE) {
2411 addSubscriptionFilterUpstreamDistance(upstreamDist);
2412 }
2413}
2414
2415
2416void
2417Vehicle::addSubscriptionFilterLeadFollow(const std::vector<int>& lanes) {
2419 addSubscriptionFilterLanes(lanes);
2420}
2421
2422
2423void
2424Vehicle::addSubscriptionFilterTurn(double downstreamDist, double foeDistToJunction) {
2426 if (downstreamDist != INVALID_DOUBLE_VALUE) {
2427 addSubscriptionFilterDownstreamDistance(downstreamDist);
2428 }
2429 if (foeDistToJunction != INVALID_DOUBLE_VALUE) {
2430 s->filterFoeDistToJunction = foeDistToJunction;
2431 }
2432}
2433
2434
2435void
2436Vehicle::addSubscriptionFilterVClass(const std::vector<std::string>& vClasses) {
2438 if (s != nullptr) {
2439 s->filterVClasses = parseVehicleClasses(vClasses);
2440 }
2441}
2442
2443
2444void
2445Vehicle::addSubscriptionFilterVType(const std::vector<std::string>& vTypes) {
2447 if (s != nullptr) {
2448 s->filterVTypes.insert(vTypes.begin(), vTypes.end());
2449 }
2450}
2451
2452
2453void
2454Vehicle::addSubscriptionFilterFieldOfVision(double openingAngle) {
2456 if (s != nullptr) {
2457 s->filterFieldOfVisionOpeningAngle = openingAngle;
2458 }
2459}
2460
2461
2462void
2463Vehicle::addSubscriptionFilterLateralDistance(double lateralDist, double downstreamDist, double upstreamDist) {
2465 if (s != nullptr) {
2466 s->filterLateralDist = lateralDist;
2467 }
2468 if (downstreamDist != INVALID_DOUBLE_VALUE) {
2469 addSubscriptionFilterDownstreamDistance(downstreamDist);
2470 }
2471 if (upstreamDist != INVALID_DOUBLE_VALUE) {
2472 addSubscriptionFilterUpstreamDistance(upstreamDist);
2473 }
2474}
2475
2476
2477void
2478Vehicle::storeShape(const std::string& id, PositionVector& shape) {
2479 shape.push_back(Helper::getVehicle(id)->getPosition());
2480}
2481
2482
2483std::shared_ptr<VariableWrapper>
2484Vehicle::makeWrapper() {
2485 return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
2486}
2487
2488
2489bool
2490Vehicle::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
2491 switch (variable) {
2492 case TRACI_ID_LIST:
2493 return wrapper->wrapStringList(objID, variable, getIDList());
2494 case ID_COUNT:
2495 return wrapper->wrapInt(objID, variable, getIDCount());
2496 case VAR_POSITION:
2497 return wrapper->wrapPosition(objID, variable, getPosition(objID));
2498 case VAR_POSITION3D:
2499 return wrapper->wrapPosition(objID, variable, getPosition(objID, true));
2500 case VAR_ANGLE:
2501 return wrapper->wrapDouble(objID, variable, getAngle(objID));
2502 case VAR_SPEED:
2503 return wrapper->wrapDouble(objID, variable, getSpeed(objID));
2504 case VAR_SPEED_LAT:
2505 return wrapper->wrapDouble(objID, variable, getLateralSpeed(objID));
2506 case VAR_ROAD_ID:
2507 return wrapper->wrapString(objID, variable, getRoadID(objID));
2509 return wrapper->wrapDouble(objID, variable, getSpeedWithoutTraCI(objID));
2510 case VAR_SLOPE:
2511 return wrapper->wrapDouble(objID, variable, getSlope(objID));
2512 case VAR_LANE_ID:
2513 return wrapper->wrapString(objID, variable, getLaneID(objID));
2514 case VAR_LANE_INDEX:
2515 return wrapper->wrapInt(objID, variable, getLaneIndex(objID));
2516 case VAR_TYPE:
2517 return wrapper->wrapString(objID, variable, getTypeID(objID));
2518 case VAR_ROUTE_ID:
2519 return wrapper->wrapString(objID, variable, getRouteID(objID));
2520 case VAR_ROUTE_INDEX:
2521 return wrapper->wrapInt(objID, variable, getRouteIndex(objID));
2522 case VAR_COLOR:
2523 return wrapper->wrapColor(objID, variable, getColor(objID));
2524 case VAR_LANEPOSITION:
2525 return wrapper->wrapDouble(objID, variable, getLanePosition(objID));
2527 return wrapper->wrapDouble(objID, variable, getLateralLanePosition(objID));
2528 case VAR_CO2EMISSION:
2529 return wrapper->wrapDouble(objID, variable, getCO2Emission(objID));
2530 case VAR_COEMISSION:
2531 return wrapper->wrapDouble(objID, variable, getCOEmission(objID));
2532 case VAR_HCEMISSION:
2533 return wrapper->wrapDouble(objID, variable, getHCEmission(objID));
2534 case VAR_PMXEMISSION:
2535 return wrapper->wrapDouble(objID, variable, getPMxEmission(objID));
2536 case VAR_NOXEMISSION:
2537 return wrapper->wrapDouble(objID, variable, getNOxEmission(objID));
2539 return wrapper->wrapDouble(objID, variable, getFuelConsumption(objID));
2540 case VAR_NOISEEMISSION:
2541 return wrapper->wrapDouble(objID, variable, getNoiseEmission(objID));
2543 return wrapper->wrapDouble(objID, variable, getElectricityConsumption(objID));
2544 case VAR_PERSON_NUMBER:
2545 return wrapper->wrapInt(objID, variable, getPersonNumber(objID));
2547 return wrapper->wrapInt(objID, variable, getPersonCapacity(objID));
2549 return wrapper->wrapStringList(objID, variable, getPersonIDList(objID));
2550 case VAR_WAITING_TIME:
2551 return wrapper->wrapDouble(objID, variable, getWaitingTime(objID));
2553 return wrapper->wrapDouble(objID, variable, getAccumulatedWaitingTime(objID));
2554 case VAR_ROUTE_VALID:
2555 return wrapper->wrapInt(objID, variable, isRouteValid(objID));
2556 case VAR_EDGES:
2557 return wrapper->wrapStringList(objID, variable, getRoute(objID));
2558 case VAR_SIGNALS:
2559 return wrapper->wrapInt(objID, variable, getSignals(objID));
2560 case VAR_STOPSTATE:
2561 return wrapper->wrapInt(objID, variable, getStopState(objID));
2562 case VAR_DISTANCE:
2563 return wrapper->wrapDouble(objID, variable, getDistance(objID));
2564 case VAR_ALLOWED_SPEED:
2565 return wrapper->wrapDouble(objID, variable, getAllowedSpeed(objID));
2566 case VAR_SPEED_FACTOR:
2567 return wrapper->wrapDouble(objID, variable, getSpeedFactor(objID));
2568 case VAR_SPEEDSETMODE:
2569 return wrapper->wrapInt(objID, variable, getSpeedMode(objID));
2571 return wrapper->wrapInt(objID, variable, getLaneChangeMode(objID));
2572 case VAR_ROUTING_MODE:
2573 return wrapper->wrapInt(objID, variable, getRoutingMode(objID));
2574 case VAR_LINE:
2575 return wrapper->wrapString(objID, variable, getLine(objID));
2576 case VAR_VIA:
2577 return wrapper->wrapStringList(objID, variable, getVia(objID));
2578 case VAR_ACCELERATION:
2579 return wrapper->wrapDouble(objID, variable, getAcceleration(objID));
2580 case VAR_LASTACTIONTIME:
2581 return wrapper->wrapDouble(objID, variable, getLastActionTime(objID));
2582 case VAR_STOP_DELAY:
2583 return wrapper->wrapDouble(objID, variable, getStopDelay(objID));
2585 return wrapper->wrapDouble(objID, variable, getStopArrivalDelay(objID));
2586 case VAR_TIMELOSS:
2587 return wrapper->wrapDouble(objID, variable, getTimeLoss(objID));
2588 case VAR_MINGAP_LAT:
2589 return wrapper->wrapDouble(objID, variable, getMinGapLat(objID));
2590 case VAR_LEADER: {
2591 paramData->readUnsignedByte();
2592 const double dist = paramData->readDouble();
2593 return wrapper->wrapStringDoublePair(objID, variable, getLeader(objID, dist));
2594 }
2595 case VAR_FOLLOWER: {
2596 paramData->readUnsignedByte();
2597 const double dist = paramData->readDouble();
2598 return wrapper->wrapStringDoublePair(objID, variable, getFollower(objID, dist));
2599 }
2601 paramData->readUnsignedByte();
2602 return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
2604 paramData->readUnsignedByte();
2605 return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
2606 case VAR_TAXI_FLEET:
2607 // we cannot use the general fall through here because we do not have an object id
2608 return false;
2609 default:
2610 return VehicleType::handleVariableWithID(objID, getTypeID(objID), variable, wrapper, paramData);
2611 }
2612}
2613
2614
2615}
2616
2617
2618/****************************************************************************/
@ GLO_VEHICLE
a vehicle
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
std::pair< const MSVehicle *, double > CLeaderDist
Definition: MSLeaderInfo.h:38
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:54
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:274
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:265
#define TL(string)
Definition: MsgHandler.h:282
SUMOTime DELTA_T
Definition: SUMOTime.cpp:37
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:45
#define STEPS2TIME(x)
Definition: SUMOTime.h:54
#define SPEED2DIST(x)
Definition: SUMOTime.h:44
#define SUMOTime_MAX
Definition: SUMOTime.h:33
#define SIMTIME
Definition: SUMOTime.h:61
#define TIME2STEPS(x)
Definition: SUMOTime.h:56
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 int STOP_ARRIVAL_SET
const int STOP_DURATION_SET
const int VEHPARS_COLOR_SET
const int STOP_POSLAT_SET
const int STOP_EXPECTED_SET
const int VEHPARS_TO_TAZ_SET
const int STOP_SPEED_SET
const int STOP_UNTIL_SET
const int STOP_LINE_SET
const int STOP_PARKING_SET
const int STOP_TRIP_ID_SET
const int VEHPARS_DEPARTPOS_SET
const int STOP_PERMITTED_SET
const int VEHPARS_ARRIVALLANE_SET
const int VEHPARS_DEPARTLANE_SET
const int STOP_SPLIT_SET
const int STOP_START_SET
const int VEHPARS_FROM_TAZ_SET
const int STOP_JOIN_SET
const int VEHPARS_ARRIVALSPEED_SET
const int STOP_EXTENSION_SET
const int VEHPARS_FORCE_REROUTE
const int STOP_ENDED_SET
const int STOP_END_SET
const int VEHPARS_LINE_SET
const int STOP_STARTED_SET
const int VEHPARS_PERSON_NUMBER_SET
const int STOP_EXPECTED_CONTAINERS_SET
const int VEHPARS_DEPARTSPEED_SET
const int VEHPARS_ARRIVALPOS_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_INDEX
@ SUMO_ATTR_ARRIVAL
@ SUMO_ATTR_TRIP_ID
@ SUMO_ATTR_PERMITTED
@ SUMO_ATTR_JOIN
@ SUMO_ATTR_EXPECTED_CONTAINERS
@ SUMO_ATTR_UNTIL
@ SUMO_ATTR_TRIGGERED
@ SUMO_ATTR_DURATION
const double INVALID_DOUBLE
Definition: StdDefs.h:60
T MIN2(T a, T b)
Definition: StdDefs.h:71
T ISNAN(T a)
Definition: StdDefs.h:112
T MAX2(T a, T b)
Definition: StdDefs.h:77
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:282
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOM)
Definition: TraCIDefs.h:76
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition: TraCIDefs.h:123
std::vector< double > & getParameter()
Returns the parameters of this distribution.
static PositionVector makeRing(const double radius1, const double radius2, const Position &center, unsigned int nPoints)
Definition: GeomHelper.cpp:253
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)
Definition: GeomHelper.cpp:192
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:42
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:221
virtual double getSafetyFactor() const
return factor for modifying the safety constraints of the car-following model
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
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const int rngIndex, SUMOVehicleClass svc) const
void setRoutingMode(int value)
Sets routing behavior.
int getRoutingMode() const
return the current routing mode
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:55
double getMaxSpeed() const
Returns the maximum speed (the minimum of desired and technical maximum speed)
MSVehicleDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
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)
virtual const MSEdge * getRerouteOrigin() const
Returns the starting point for reroutes (usually the current edge)
void setChosenSpeedFactor(const double factor)
Returns the precomputed factor by which the driver wants to be faster than the speed limit.
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 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.
virtual void replaceVehicleType(MSVehicleType *type)
Replaces the current vehicle type by the one given.
const MSRouteIterator & getCurrentRouteEdge() const
Returns an iterator pointing to the current edge in this vehicles 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.
bool hasValidRoute(std::string &msg, const MSRoute *route=0) const
Validates the current or given route.
int getPersonNumber() const
Returns the number of persons.
void setJunctionModelParameter(const std::string &key, const std::string &value)
set individual junction model paramete (not type related)
bool hasDeparted() const
Returns whether this vehicle has already departed.
MSStop & getNextStop()
const std::list< MSStop > & getStops() const
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...
bool hasStops() const
Returns whether the vehicle has to stop somewhere.
void addToOdometer(double value)
Manipulate the odometer.
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.
virtual bool replaceRoute(const MSRoute *route, const std::string &info, bool onInit=false, int offset=0, bool addStops=true, bool removeStops=true, std::string *msgReturn=nullptr)
Replaces the current route by the given one.
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.
const std::vector< SUMOVehicleParameter::Stop > & getPastStops() const
virtual bool addTraciStop(SUMOVehicleParameter::Stop stop, std::string &errorMsg)
const MSRoute & getRoute() const
Returns the current route.
int getRoutePosition() const
return index of edge within route
double getEmissions() const
Returns emissions of the current state The value is always per 1s, so multiply by step length if nece...
virtual bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
void reroute(SUMOTime t, const std::string &info, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false, const bool silent=false)
Performs a rerouting using the given router.
virtual std::pair< const MSVehicle *const, double > getLeader(double dist=0) const
Returns the leader of the vehicle looking for a fixed distance.
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.
bool abortNextStop(int nextStopIndex=0)
deletes the next stop at the given index if it exists
bool replaceRouteEdges(ConstMSEdgeVector &edges, double cost, double savings, const std::string &info, bool onInit=false, bool check=false, bool removeStops=true, std::string *msgReturn=nullptr)
Replaces the current route by the given edges.
virtual double getSecureGap(const MSVehicle *const, 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)
Definition: MSCFModel.h:390
double getEmergencyDecel() const
Get the vehicle type's maximal phisically possible deceleration [m/s^2].
Definition: MSCFModel.h:270
double getApparentDecel() const
Get the vehicle type's apparent deceleration [m/s^2] (the one regarded by its followers.
Definition: MSCFModel.h:278
double getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
Definition: MSCFModel.h:254
virtual double getImperfection() const
Get the driver's imperfection.
Definition: MSCFModel.h:301
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:262
virtual void setParameter(MSVehicle *veh, const std::string &key, const std::string &value) const
try to set the given parameter for this carFollowingModel
Definition: MSCFModel.h:652
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:168
virtual double getHeadwayTime() const
Get the driver's desired headway [s].
Definition: MSCFModel.h:309
A device which collects info on the vehicle trip (mainly on departure and arrival)
Definition: MSDevice_Taxi.h:49
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:102
A road/street connecting two junctions.
Definition: MSEdge.h:77
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition: MSEdge.cpp:984
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:1008
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_IGNORING) const
Get the allowed lanes to reach the destination-edge.
Definition: MSEdge.cpp:439
bool isInternal() const
return whether this edge is an internal edge
Definition: MSEdge.h:265
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:945
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:1068
const MSEdge * getNormalBefore() const
if this edge is an internal edge, return its first normal predecessor, otherwise the edge itself
Definition: MSEdge.cpp:835
bool retrieveExistingTravelTime(const MSEdge *const e, const double t, double &value) const
Returns a travel time for an edge and time if stored.
bool knowsTravelTime(const MSEdge *const e) const
Returns the information whether any travel time is known for the given edge.
void addTravelTime(const MSEdge *const e, double begin, double end, double value)
Adds a travel time information for an edge and a time span.
void removeEffort(const MSEdge *const e)
Removes the effort information for an edge.
bool knowsEffort(const MSEdge *const e) const
Returns the information whether any effort is known for the given edge.
void addEffort(const MSEdge *const e, double begin, double end, double value)
Adds an effort information for an edge and a time span.
bool retrieveExistingEffort(const MSEdge *const e, const double t, double &value) const
Returns an effort for an edge and time if stored.
void removeTravelTime(const MSEdge *const e)
Removes the travel time information for an edge.
static bool gCheckRoutes
Definition: MSGlobals.h:88
static double gLateralResolution
Definition: MSGlobals.h:97
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.
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:2521
virtual MSVehicle * removeVehicle(MSVehicle *remVehicle, MSMoveReminder::Notification notification, bool notify=true)
Definition: MSLane.cpp:2503
static std::vector< MSLink * >::const_iterator succLinkSec(const SUMOVehicle &veh, int nRouteSuccs, const MSLane &succLinkSource, const std::vector< MSLane * > &conts)
Definition: MSLane.cpp:2379
void forceVehicleInsertion(MSVehicle *veh, double pos, MSMoveReminder::Notification notification, double posLat=0)
Inserts the given vehicle at the given position.
Definition: MSLane.cpp:1259
const MSEdge * getNextNormal() const
Returns the lane's follower if it is an internal lane, the edge of the lane otherwise.
Definition: MSLane.cpp:2175
void addLeaders(const MSVehicle *vehicle, double vehPos, MSLeaderDistanceInfo &result, bool oppositeDirection=false)
get leaders for ego on the given lane
Definition: MSLane.cpp:3771
double getLength() const
Returns the lane's length.
Definition: MSLane.h:575
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:506
bool isLinkEnd(std::vector< MSLink * >::const_iterator &i) const
Definition: MSLane.h:802
int getIndex() const
Returns the lane's index.
Definition: MSLane.h:597
double getOppositePos(double pos) const
return the corresponding position on the opposite lane
Definition: MSLane.cpp:4017
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition: MSLane.cpp:2199
bool isInternal() const
Definition: MSLane.cpp:2330
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:713
MSLeaderDistanceInfo getFollowersOnConsecutive(const MSVehicle *ego, double backOffset, bool allSublanes, double searchDist=-1, MinorLinkMode mLinkMode=FOLLOW_ALWAYS) const
return the sublane followers with the largest missing rear gap among all predecessor lanes (within di...
Definition: MSLane.cpp:3446
double getWidth() const
Returns the lane's width.
Definition: MSLane.h:590
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.h:675
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:533
saves leader/follower vehicles and their distances relative to an ego vehicle
Definition: MSLeaderInfo.h:144
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
Definition: MSLeaderInfo.h:86
bool hasVehicles() const
Definition: MSLeaderInfo.h:94
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:183
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:321
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:432
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:379
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:124
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:80
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:118
double getDistanceBetween(double fromPos, double toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true, int routePosition=0) const
Compute the distance between 2 given edges on this route, including the length of internal lanes....
Definition: MSRoute.cpp:316
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:74
Definition: MSStop.h:44
const MSLane * lane
The lane to stop at (microsim only)
Definition: MSStop.h:50
int getStateFlagsOld() const
return flags as used by Vehicle::getStopState
Definition: MSStop.cpp:127
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.
Definition: MSVehicle.cpp:781
void deactivateGapController()
Deactivates the gap control.
Definition: MSVehicle.cpp:409
void setSpeedMode(int speedMode)
Sets speed-constraining behaviors.
Definition: MSVehicle.cpp:770
void setLaneTimeLine(const std::vector< std::pair< SUMOTime, int > > &laneTimeLine)
Sets a new lane timeline.
Definition: MSVehicle.cpp:416
void setSublaneChange(double latDist)
Sets a new sublane-change request.
Definition: MSVehicle.cpp:430
void setSignals(int signals)
Definition: MSVehicle.h:1591
void setSpeedTimeLine(const std::vector< std::pair< SUMOTime, double > > &speedTimeLine)
Sets a new velocity timeline.
Definition: MSVehicle.cpp:395
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,.
Definition: MSVehicle.cpp:401
The class responsible for building and deletion of vehicles.
void removePending()
Removes a vehicle after it has ended.
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
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.
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, const MSRoute *route, MSVehicleType *type, const bool ignoreStopErrors, const bool fromRouteFile=true, bool addRouteStops=true)
Builds a vehicle, increases the number of built vehicles.
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.
void scheduleVehicleRemoval(SUMOVehicle *veh, bool checkDuplicate=false)
Removes a vehicle after it has ended.
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
Definition: MSVehicle.cpp:5391
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:599
SUMOTime getLastActionTime() const
Returns the time of the vehicle's last action point.
Definition: MSVehicle.h:537
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...
Definition: MSVehicle.cpp:6239
void setPreviousSpeed(double prevSpeed, double prevAcceleration)
Sets the influenced previous speed.
Definition: MSVehicle.cpp:7167
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:5367
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MSVehicle.cpp:1208
const std::vector< MSLane * > & getBestLanesContinuation() const
Returns the best sequence of lanes to continue the route starting at myLane.
Definition: MSVehicle.cpp:5848
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
Definition: MSVehicle.cpp:1015
bool resumeFromStopping()
Definition: MSVehicle.cpp:6715
double getBackPositionOnLane(const MSLane *lane) const
Get the vehicle's position relative to the given lane.
Definition: MSVehicle.h:401
void resetActionOffset(const SUMOTime timeUntilNextAction=0)
Resets the action offset for the vehicle.
Definition: MSVehicle.cpp:1989
bool rerouteParkingArea(const std::string &parkingAreaID, std::string &errorMsg)
Definition: MSVehicle.cpp:6601
void switchOffSignal(int signal)
Switches the given signal off.
Definition: MSVehicle.h:1182
@ VEH_SIGNAL_NONE
Everything is switched off.
Definition: MSVehicle.h:1119
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:577
MSLane * getMutableLane() const
Returns the lane the vehicle is on Non const version indicates that something volatile is going on.
Definition: MSVehicle.h:585
BaseInfluencer & getBaseInfluencer()
Returns the velocity/lane influencer.
Definition: MSVehicle.cpp:6781
Influencer & getInfluencer()
Definition: MSVehicle.cpp:6773
void setActionStepLength(double actionStepLength, bool resetActionOffset=true)
Sets the action steplength of the vehicle.
Definition: MSVehicle.cpp:1376
double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
Definition: MSVehicle.h:416
double getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:486
const std::vector< LaneQ > & getBestLanes() const
Returns the description of best lanes to use in order to continue the route.
Definition: MSVehicle.cpp:5385
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
Definition: MSVehicle.h:966
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:377
bool hasInfluencer() const
whether the vehicle is individually influenced (via TraCI or special parameters)
Definition: MSVehicle.h:1690
void switchOnSignal(int signal)
Switches the given signal on.
Definition: MSVehicle.h:1174
int getLaneIndex() const
Definition: MSVehicle.cpp:6233
The car-following model and parameter.
Definition: MSVehicleType.h:63
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.
Definition: MSVehicleType.h:91
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.
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 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 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:67
const std::string & getID() const
Returns the id.
Definition: Named.h:74
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:252
void sub(double dx, double dy)
Substracts the given position from this one.
Definition: Position.h:145
void setz(double z)
set position z
Definition: Position.h:80
double z() const
Returns the z-position.
Definition: Position.h:65
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position
Definition: Position.h:262
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 ammount
void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
assigns new values
Definition: RGBColor.cpp:98
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E * > &into, bool silent=false)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
virtual double 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 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 bool parseLatAlignment(const std::string &val, double &lao, LatAlignmentDefinition &lad)
Parses and validates a given latAlignment value.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
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 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 (used only in NETEDIT)
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
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.
int parametersSet
Information for the output which parameter were set.
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.
int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
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::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.
ArrivalLaneDefinition arrivalLaneProcedure
Information how the vehicle shall choose the lane to arrive on.
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.
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 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.
bool wasSet(int what) const
Returns whether the given parameter was set.
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
std::string toTaz
The vehicle's destination zone (district)
double arrivalSpeed
(optional) The final speed of the vehicle (not used yet)
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
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.
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
static int getIndexFromLane(const std::string laneID)
return lane index when given the lane ID
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:390
static TraCIPosition makeTraCIPosition(const Position &position, const bool includeZ=false)
Definition: Helper.cpp:374
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:1706
static TraCIPositionVector makeTraCIPositionVector(const PositionVector &positionVector)
helper functions
Definition: Helper.cpp:334
static MSBaseVehicle * getVehicle(const std::string &id)
Definition: Helper.cpp:474
static TraCIColor makeTraCIColor(const RGBColor &color)
Definition: Helper.cpp:357
static TraCINextStopData buildStopData(const SUMOVehicleParameter::Stop &stopPar)
Definition: Helper.cpp:634
static void setRemoteControlled(MSVehicle *v, Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, ConstMSEdgeVector route, SUMOTime t)
Definition: Helper.cpp:1373
static const MSVehicleType & getVehicleType(const std::string &vehicleID)
Definition: Helper.cpp:509
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, bool setLateralPos, double &bestDistance, MSLane **lane, double &lanePos, int &routeOffset, ConstMSEdgeVector &edges)
Definition: Helper.cpp:1413
static std::pair< MSLane *, double > convertCartesianToRoadMap(const Position &pos, const SUMOVehicleClass vClass)
Definition: Helper.cpp:417
static SUMOVehicleParameter::Stop buildStopParameters(const std::string &edgeOrStoppingPlaceID, double pos, int laneIndex, double startPos, int flags, double duration, double until)
Definition: Helper.cpp:534
static Subscription * addSubscriptionFilter(SubscriptionFilterType filter)
Definition: Helper.cpp:207
virtual std::string readString()
Definition: storage.cpp:180
virtual int readUnsignedByte()
Definition: storage.cpp:155
virtual double readDouble()
Definition: storage.cpp:362
#define CALL_MICRO_FUN(veh, fun, mesoResult)
#define DEBUG_COND
TRACI_CONST double INVALID_DOUBLE_VALUE
TRACI_CONST int VAR_LASTACTIONTIME
TRACI_CONST int VAR_EDGES
TRACI_CONST int VAR_NOXEMISSION
TRACI_CONST int VAR_LANECHANGE_MODE
TRACI_CONST int MOVE_AUTOMATIC
TRACI_CONST int LAST_STEP_PERSON_ID_LIST
TRACI_CONST int TRACI_ID_LIST
TRACI_CONST int VAR_TYPE
TRACI_CONST int VAR_ROUTING_MODE
TRACI_CONST int VAR_WAITING_TIME
TRACI_CONST int VAR_LINE
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:301
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_STOP_ARRIVALDELAY
TRACI_CONST int VAR_SPEED_LAT
TRACI_CONST int VAR_ANGLE
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 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_LEADER
TRACI_CONST int VAR_CO2EMISSION
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:300
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_NOISEEMISSION
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_ROUTE_INDEX
TRACI_CONST int VAR_ACCELERATION
TRACI_CONST int VAR_ROUTE_ID
TRACI_CONST int REMOVE_ARRIVED
@ SUBS_FILTER_LEAD_FOLLOW
Definition: Subscription.h:48
@ SUBS_FILTER_UPSTREAM_DIST
Definition: Subscription.h:46
@ SUBS_FILTER_VTYPE
Definition: Subscription.h:54
@ SUBS_FILTER_LANES
Definition: Subscription.h:40
@ SUBS_FILTER_NOOPPOSITE
Definition: Subscription.h:42
@ SUBS_FILTER_DOWNSTREAM_DIST
Definition: Subscription.h:44
@ SUBS_FILTER_LATERAL_DIST
Definition: Subscription.h:59
@ SUBS_FILTER_TURN
Definition: Subscription.h:50
@ SUBS_FILTER_VCLASS
Definition: Subscription.h:52
@ SUBS_FILTER_FIELD_OF_VISION
Definition: Subscription.h:57
TRACI_CONST int ROUTING_MODE_DEFAULT
TRACI_CONST int VAR_LANEPOSITION_LAT
TRACI_CONST int VAR_STOP_DELAY
TRACI_CONST int REMOVE_TELEPORT_ARRIVED
TRACI_CONST int REMOVE_VAPORIZED
TRACI_CONST int VAR_STOPSTATE
TRACI_CONST int VAR_FOLLOWER
TRACI_CONST int STOP_TRIGGERED
std::map< int, std::shared_ptr< libsumo::TraCIResult > > TraCIResults
{variable->value}
Definition: TraCIDefs.h:298
TRACI_CONST int VAR_DISTANCE
TRACI_CONST int ROUTING_MODE_AGGREGATED_CUSTOM
TRACI_CONST int VAR_ELECTRICITYCONSUMPTION
TRACI_CONST int VAR_VIA
@ key
the parser read a key of a value in an object
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) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition: json.hpp:21884
A structure representing the best lanes for continuing the current route starting at 'lane'.
Definition: MSVehicle.h:857