LCOV - code coverage report
Current view: top level - src/libtraci - Vehicle.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 98.2 % 651 639
Test Date: 2024-10-24 15:46:30 Functions: 99.5 % 182 181

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2017-2024 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              : /****************************************************************************/
      14              : /// @file    Vehicle.cpp
      15              : /// @author  Jakob Erdmann
      16              : /// @author  Michael Behrisch
      17              : /// @author  Mirko Barthauer
      18              : /// @date    30.05.2012
      19              : ///
      20              : // C++ TraCI client API implementation
      21              : /****************************************************************************/
      22              : #include <config.h>
      23              : #include <sstream>
      24              : 
      25              : #define LIBTRACI 1
      26              : #include <libsumo/StorageHelper.h>
      27              : #include <libsumo/Vehicle.h>
      28              : #include "Domain.h"
      29              : 
      30              : namespace libtraci {
      31              : 
      32              : typedef Domain<libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::CMD_SET_VEHICLE_VARIABLE> Dom;
      33              : 
      34              : 
      35              : // ===========================================================================
      36              : // static member definitions
      37              : // ===========================================================================
      38              : std::vector<std::string>
      39        20918 : Vehicle::getIDList() {
      40        41835 :     return Dom::getStringVector(libsumo::TRACI_ID_LIST, "");
      41              : }
      42              : 
      43              : 
      44              : int
      45           31 : Vehicle::getIDCount() {
      46           62 :     return Dom::getInt(libsumo::ID_COUNT, "");
      47              : }
      48              : 
      49              : 
      50        31775 : LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(Vehicle, VEHICLE)
      51         1048 : LIBTRACI_PARAMETER_IMPLEMENTATION(Vehicle, VEHICLE)
      52              : 
      53              : double
      54         3685 : Vehicle::getSpeed(const std::string& vehID) {
      55         3685 :     return Dom::getDouble(libsumo::VAR_SPEED, vehID);
      56              : }
      57              : 
      58              : double
      59           18 : Vehicle::getLateralSpeed(const std::string& vehID) {
      60           18 :     return Dom::getDouble(libsumo::VAR_SPEED_LAT, vehID);
      61              : }
      62              : 
      63              : double
      64         1176 : Vehicle::getAcceleration(const std::string& vehID) {
      65         1176 :     return Dom::getDouble(libsumo::VAR_ACCELERATION, vehID);
      66              : }
      67              : 
      68              : 
      69              : double
      70         1028 : Vehicle::getSpeedWithoutTraCI(const std::string& vehID) {
      71         1028 :     return Dom::getDouble(libsumo::VAR_SPEED_WITHOUT_TRACI, vehID);
      72              : }
      73              : 
      74              : 
      75              : libsumo::TraCIPosition
      76       331140 : Vehicle::getPosition(const std::string& vehID, const bool includeZ) {
      77       331140 :     return includeZ ? getPosition3D(vehID) : Dom::getPos(libsumo::VAR_POSITION, vehID);
      78              : }
      79              : 
      80              : 
      81              : libsumo::TraCIPosition
      82          399 : Vehicle::getPosition3D(const std::string& vehID) {
      83          399 :     return Dom::getPos3D(libsumo::VAR_POSITION3D, vehID);
      84              : }
      85              : 
      86              : 
      87              : double
      88           98 : Vehicle::getAngle(const std::string& vehID) {
      89           98 :     return Dom::getDouble(libsumo::VAR_ANGLE, vehID);
      90              : }
      91              : 
      92              : 
      93              : double
      94            2 : Vehicle::getSlope(const std::string& vehID) {
      95            2 :     return Dom::getDouble(libsumo::VAR_SLOPE, vehID);
      96              : }
      97              : 
      98              : 
      99              : std::string
     100          914 : Vehicle::getRoadID(const std::string& vehID) {
     101          914 :     return Dom::getString(libsumo::VAR_ROAD_ID, vehID);
     102              : }
     103              : 
     104              : 
     105              : double
     106           18 : Vehicle::getDeparture(const std::string& vehID) {
     107           18 :     return Dom::getDouble(libsumo::VAR_DEPARTURE, vehID);
     108              : }
     109              : 
     110              : 
     111              : double
     112           18 : Vehicle::getDepartDelay(const std::string& vehID) {
     113           18 :     return Dom::getDouble(libsumo::VAR_DEPART_DELAY, vehID);
     114              : }
     115              : 
     116              : 
     117              : std::string
     118         2586 : Vehicle::getLaneID(const std::string& vehID) {
     119         2586 :     return Dom::getString(libsumo::VAR_LANE_ID, vehID);
     120              : }
     121              : 
     122              : 
     123              : int
     124         1258 : Vehicle::getLaneIndex(const std::string& vehID) {
     125         1258 :     return Dom::getInt(libsumo::VAR_LANE_INDEX, vehID);
     126              : }
     127              : 
     128              : 
     129              : std::string
     130           24 : Vehicle::getSegmentID(const std::string& vehID) {
     131           24 :     return Dom::getString(libsumo::VAR_SEGMENT_ID, vehID);
     132              : }
     133              : 
     134              : 
     135              : int
     136           23 : Vehicle::getSegmentIndex(const std::string& vehID) {
     137           23 :     return Dom::getInt(libsumo::VAR_SEGMENT_INDEX, vehID);
     138              : }
     139              : 
     140              : 
     141              : std::string
     142           82 : Vehicle::getTypeID(const std::string& vehID) {
     143           82 :     return Dom::getString(libsumo::VAR_TYPE, vehID);
     144              : }
     145              : 
     146              : 
     147              : std::string
     148           26 : Vehicle::getRouteID(const std::string& vehID) {
     149           26 :     return Dom::getString(libsumo::VAR_ROUTE_ID, vehID);
     150              : }
     151              : 
     152              : 
     153              : int
     154          992 : Vehicle::getRouteIndex(const std::string& vehID) {
     155          992 :     return Dom::getInt(libsumo::VAR_ROUTE_INDEX, vehID);
     156              : }
     157              : 
     158              : 
     159              : libsumo::TraCIColor
     160           40 : Vehicle::getColor(const std::string& vehID) {
     161           40 :     return Dom::getCol(libsumo::VAR_COLOR, vehID);
     162              : }
     163              : 
     164              : double
     165         4013 : Vehicle::getLanePosition(const std::string& vehID) {
     166         4013 :     return Dom::getDouble(libsumo::VAR_LANEPOSITION, vehID);
     167              : }
     168              : 
     169              : double
     170          798 : Vehicle::getLateralLanePosition(const std::string& vehID) {
     171          798 :     return Dom::getDouble(libsumo::VAR_LANEPOSITION_LAT, vehID);
     172              : }
     173              : 
     174              : double
     175           98 : Vehicle::getCO2Emission(const std::string& vehID) {
     176           98 :     return Dom::getDouble(libsumo::VAR_CO2EMISSION, vehID);
     177              : }
     178              : 
     179              : double
     180           18 : Vehicle::getCOEmission(const std::string& vehID) {
     181           18 :     return Dom::getDouble(libsumo::VAR_COEMISSION, vehID);
     182              : }
     183              : 
     184              : double
     185           18 : Vehicle::getHCEmission(const std::string& vehID) {
     186           18 :     return Dom::getDouble(libsumo::VAR_HCEMISSION, vehID);
     187              : }
     188              : 
     189              : double
     190           18 : Vehicle::getPMxEmission(const std::string& vehID) {
     191           18 :     return Dom::getDouble(libsumo::VAR_PMXEMISSION, vehID);
     192              : }
     193              : 
     194              : double
     195           18 : Vehicle::getNOxEmission(const std::string& vehID) {
     196           18 :     return Dom::getDouble(libsumo::VAR_NOXEMISSION, vehID);
     197              : }
     198              : 
     199              : double
     200           18 : Vehicle::getFuelConsumption(const std::string& vehID) {
     201           18 :     return Dom::getDouble(libsumo::VAR_FUELCONSUMPTION, vehID);
     202              : }
     203              : 
     204              : double
     205           18 : Vehicle::getNoiseEmission(const std::string& vehID) {
     206           18 :     return Dom::getDouble(libsumo::VAR_NOISEEMISSION, vehID);
     207              : }
     208              : 
     209              : double
     210           38 : Vehicle::getElectricityConsumption(const std::string& vehID) {
     211           38 :     return Dom::getDouble(libsumo::VAR_ELECTRICITYCONSUMPTION, vehID);
     212              : }
     213              : 
     214              : int
     215           18 : Vehicle::getPersonNumber(const std::string& vehID) {
     216           18 :     return Dom::getInt(libsumo::VAR_PERSON_NUMBER, vehID);
     217              : }
     218              : 
     219              : int
     220           18 : Vehicle::getPersonCapacity(const std::string& vehID) {
     221           18 :     return Dom::getInt(libsumo::VAR_PERSON_CAPACITY, vehID);
     222              : }
     223              : 
     224              : 
     225              : double
     226           18 : Vehicle::getBoardingDuration(const std::string& vehID) {
     227           18 :     return Dom::getDouble(libsumo::VAR_BOARDING_DURATION, vehID);
     228              : }
     229              : 
     230              : 
     231              : double
     232           24 : Vehicle::getImpatience(const std::string& vehID) {
     233           24 :     return Dom::getDouble(libsumo::VAR_IMPATIENCE, vehID);
     234              : }
     235              : 
     236              : 
     237              : std::vector<std::string>
     238           40 : Vehicle::getPersonIDList(const std::string& vehID) {
     239           40 :     return Dom::getStringVector(libsumo::LAST_STEP_PERSON_ID_LIST, vehID);
     240              : }
     241              : 
     242              : std::pair<std::string, double>
     243         6177 : Vehicle::getLeader(const std::string& vehID, double dist) {
     244         6177 :     tcpip::Storage content;
     245              :     StoHelp::writeTypedDouble(content, dist);
     246         6177 :     std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
     247              :     tcpip::Storage& ret = Dom::get(libsumo::VAR_LEADER, vehID, &content);
     248         6177 :     ret.readInt(); // components
     249         6177 :     ret.readUnsignedByte();
     250         6177 :     const std::string leaderID = ret.readString();
     251         6177 :     ret.readUnsignedByte();
     252         6177 :     const double gap = ret.readDouble();
     253         6177 :     return std::make_pair(leaderID, gap);
     254         6177 : }
     255              : 
     256              : 
     257              : std::pair<std::string, double>
     258           59 : Vehicle::getFollower(const std::string& vehID, double dist) {
     259           59 :     tcpip::Storage content;
     260              :     StoHelp::writeTypedDouble(content, dist);
     261           59 :     std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
     262              :     tcpip::Storage& ret = Dom::get(libsumo::VAR_FOLLOWER, vehID, &content);
     263           58 :     ret.readInt(); // components
     264           59 :     const std::string leaderID = StoHelp::readTypedString(ret);
     265          174 :     return std::make_pair(leaderID, StoHelp::readTypedDouble(ret));
     266           59 : }
     267              : 
     268              : 
     269              : std::vector<libsumo::TraCIJunctionFoe>
     270           30 : Vehicle::getJunctionFoes(const std::string& vehID, double dist) {
     271              :     std::vector<libsumo::TraCIJunctionFoe> result;
     272           30 :     tcpip::Storage content;
     273              :     StoHelp::writeTypedDouble(content, dist);
     274           30 :     std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
     275              :     tcpip::Storage& ret = Dom::get(libsumo::VAR_FOES, vehID, &content);
     276           30 :     ret.readInt(); // compound size
     277           30 :     const int n = StoHelp::readTypedInt(ret); // number of foe informations
     278           75 :     for (int i = 0; i < n; ++i) {
     279              :         libsumo::TraCIJunctionFoe info;
     280           45 :         info.foeId = StoHelp::readTypedString(ret);
     281           45 :         info.egoDist = StoHelp::readTypedDouble(ret);
     282           45 :         info.foeDist = StoHelp::readTypedDouble(ret);
     283           45 :         info.egoExitDist = StoHelp::readTypedDouble(ret);
     284           45 :         info.foeExitDist = StoHelp::readTypedDouble(ret);
     285           45 :         info.egoLane = StoHelp::readTypedString(ret);
     286           45 :         info.foeLane = StoHelp::readTypedString(ret);
     287           45 :         info.egoResponse = StoHelp::readBool(ret);
     288           45 :         info.foeResponse = StoHelp::readBool(ret);
     289           45 :         result.emplace_back(info);
     290           45 :     }
     291           30 :     return result;
     292           30 : }
     293              : 
     294              : 
     295              : double
     296           50 : Vehicle::getWaitingTime(const std::string& vehID) {
     297           50 :     return Dom::getDouble(libsumo::VAR_WAITING_TIME, vehID);
     298              : }
     299              : 
     300              : 
     301              : double
     302           25 : Vehicle::getAccumulatedWaitingTime(const std::string& vehID) {
     303           25 :     return Dom::getDouble(libsumo::VAR_ACCUMULATED_WAITING_TIME, vehID);
     304              : }
     305              : 
     306              : 
     307              : double
     308           23 : Vehicle::getAdaptedTraveltime(const std::string& vehID, double time, const std::string& edgeID) {
     309           23 :     tcpip::Storage content;
     310              :     StoHelp::writeCompound(content, 2);
     311              :     StoHelp::writeTypedDouble(content, time);
     312              :     StoHelp::writeTypedString(content, edgeID);
     313           46 :     return Dom::getDouble(libsumo::VAR_EDGE_TRAVELTIME, vehID, &content);
     314           23 : }
     315              : 
     316              : 
     317              : double
     318           22 : Vehicle::getEffort(const std::string& vehID, double time, const std::string& edgeID) {
     319           22 :     tcpip::Storage content;
     320              :     StoHelp::writeCompound(content, 2);
     321              :     StoHelp::writeTypedDouble(content, time);
     322              :     StoHelp::writeTypedString(content, edgeID);
     323           44 :     return Dom::getDouble(libsumo::VAR_EDGE_EFFORT, vehID, &content);
     324           22 : }
     325              : 
     326              : 
     327              : bool
     328           18 : Vehicle::isRouteValid(const std::string& vehID) {
     329           18 :     return Dom::getInt(libsumo::VAR_ROUTE_VALID, vehID) != 0;
     330              : }
     331              : 
     332              : 
     333              : std::vector<std::string>
     334         1045 : Vehicle::getRoute(const std::string& vehID) {
     335         1045 :     return Dom::getStringVector(libsumo::VAR_EDGES, vehID);
     336              : }
     337              : 
     338              : 
     339              : int
     340           18 : Vehicle::getSignals(const std::string& vehID) {
     341           18 :     return Dom::getInt(libsumo::VAR_SIGNALS, vehID);
     342              : }
     343              : 
     344              : 
     345              : std::vector<libsumo::TraCIBestLanesData>
     346           18 : Vehicle::getBestLanes(const std::string& vehID) {
     347           18 :     std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
     348              :     std::vector<libsumo::TraCIBestLanesData> result;
     349              :     tcpip::Storage& ret = Dom::get(libsumo::VAR_BEST_LANES, vehID);
     350           18 :     ret.readInt();
     351           18 :     ret.readUnsignedByte();
     352              : 
     353           18 :     const int n = ret.readInt(); // number of following edge information
     354           30 :     for (int i = 0; i < n; ++i) {
     355              :         libsumo::TraCIBestLanesData info;
     356           12 :         ret.readUnsignedByte();
     357           12 :         info.laneID = ret.readString();
     358              : 
     359           12 :         ret.readUnsignedByte();
     360           12 :         info.length = ret.readDouble();
     361              : 
     362           12 :         ret.readUnsignedByte();
     363           12 :         info.occupation = ret.readDouble();
     364              : 
     365           12 :         ret.readUnsignedByte();
     366           12 :         info.bestLaneOffset = ret.readByte();
     367              : 
     368           12 :         ret.readUnsignedByte();
     369           12 :         info.allowsContinuation = (ret.readUnsignedByte() == 1);
     370              : 
     371           12 :         ret.readUnsignedByte();
     372           12 :         int m = ret.readInt();
     373           56 :         while (m-- > 0) {
     374           88 :             info.continuationLanes.push_back(ret.readString());
     375              :         }
     376           12 :         result.push_back(info);
     377              :     }
     378           18 :     return result;
     379            0 : }
     380              : 
     381              : 
     382              : std::vector<libsumo::TraCINextTLSData>
     383          276 : Vehicle::getNextTLS(const std::string& vehID) {
     384          276 :     std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
     385              :     std::vector<libsumo::TraCINextTLSData> result;
     386              :     tcpip::Storage& ret = Dom::get(libsumo::VAR_NEXT_TLS, vehID);
     387          273 :     ret.readInt(); // components
     388              :     // number of items
     389          273 :     ret.readUnsignedByte();
     390          273 :     const int n = ret.readInt();
     391          624 :     for (int i = 0; i < n; ++i) {
     392              :         libsumo::TraCINextTLSData d;
     393          351 :         ret.readUnsignedByte();
     394          351 :         d.id = ret.readString();
     395              : 
     396          351 :         ret.readUnsignedByte();
     397          351 :         d.tlIndex = ret.readInt();
     398              : 
     399          351 :         ret.readUnsignedByte();
     400          351 :         d.dist = ret.readDouble();
     401              : 
     402          351 :         ret.readUnsignedByte();
     403          351 :         d.state = (char)ret.readByte();
     404              : 
     405          351 :         result.push_back(d);
     406              :     }
     407          273 :     return result;
     408            3 : }
     409              : 
     410              : std::vector<libsumo::TraCINextStopData>
     411           26 : Vehicle::getNextStops(const std::string& vehID) {
     412           26 :     return getStops(vehID, 0);
     413              : }
     414              : 
     415              : std::vector<libsumo::TraCIConnection>
     416            1 : Vehicle::getNextLinks(const std::string& vehID) {
     417            1 :     std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
     418              :     std::vector<libsumo::TraCIConnection> result;
     419              :     tcpip::Storage& ret = Dom::get(libsumo::VAR_NEXT_LINKS, vehID);
     420            1 :     ret.readInt(); // components
     421              :     // number of items
     422            1 :     ret.readUnsignedByte();
     423              : 
     424            1 :     const int linkNo = ret.readInt();
     425            3 :     for (int i = 0; i < linkNo; ++i) {
     426              :         libsumo::TraCIConnection con;
     427            2 :         con.approachedLane = StoHelp::readTypedString(ret);
     428            2 :         con.approachedInternal = StoHelp::readTypedString(ret);
     429            2 :         con.hasPrio = StoHelp::readBool(ret);
     430            2 :         con.isOpen = StoHelp::readBool(ret);
     431            2 :         con.hasFoe = StoHelp::readBool(ret);
     432            2 :         con.state = StoHelp::readTypedString(ret);
     433            2 :         con.direction = StoHelp::readTypedString(ret);
     434            2 :         con.length = StoHelp::readTypedDouble(ret);
     435            2 :         result.emplace_back(con);
     436            2 :     }
     437            1 :     return result;
     438            0 : }
     439              : 
     440              : std::vector<libsumo::TraCINextStopData>
     441          629 : Vehicle::getStops(const std::string& vehID, int limit) {
     442              :     std::vector<libsumo::TraCINextStopData> result;
     443          629 :     tcpip::Storage content;
     444              :     StoHelp::writeTypedInt(content, limit);
     445          629 :     std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
     446              :     tcpip::Storage& ret = Dom::get(libsumo::VAR_NEXT_STOPS2, vehID, &content);
     447          628 :     ret.readInt(); // components
     448              :     // number of items
     449          628 :     const int n = StoHelp::readCompound(ret);
     450         2099 :     for (int i = 0; i < n; ++i) {
     451         2943 :         libsumo::TraCINextStopData s;
     452         1471 :         s.lane = StoHelp::readTypedString(ret);
     453         1471 :         s.endPos = StoHelp::readTypedDouble(ret);
     454         1471 :         s.stoppingPlaceID = StoHelp::readTypedString(ret);
     455         1471 :         s.stopFlags = StoHelp::readTypedInt(ret);
     456         1471 :         s.duration = StoHelp::readTypedDouble(ret);
     457         1471 :         s.until = StoHelp::readTypedDouble(ret);
     458         1471 :         s.startPos = StoHelp::readTypedDouble(ret);
     459         1471 :         s.intendedArrival = StoHelp::readTypedDouble(ret);
     460         1471 :         s.arrival = StoHelp::readTypedDouble(ret);
     461         1471 :         s.depart = StoHelp::readTypedDouble(ret);
     462         1471 :         s.split = StoHelp::readTypedString(ret);
     463         1471 :         s.join = StoHelp::readTypedString(ret);
     464         1471 :         s.actType = StoHelp::readTypedString(ret);
     465         1471 :         s.tripId = StoHelp::readTypedString(ret);
     466         1471 :         s.line = StoHelp::readTypedString(ret);
     467         1471 :         s.speed = StoHelp::readTypedDouble(ret);
     468         1471 :         result.emplace_back(s);
     469         1471 :     }
     470          628 :     return result;
     471          630 : }
     472              : 
     473              : std::string
     474           91 : Vehicle::getStopParameter(const std::string& vehID, int nextStopIndex, const std::string& param, bool customParam) {
     475           91 :     tcpip::Storage content;
     476              :     StoHelp::writeCompound(content, 3);
     477              :     StoHelp::writeTypedInt(content, nextStopIndex);
     478              :     StoHelp::writeTypedString(content, param);
     479           91 :     StoHelp::writeTypedByte(content, customParam);
     480          182 :     return Dom::getString(libsumo::VAR_STOP_PARAMETER, vehID, &content);
     481           91 : }
     482              : 
     483              : int
     484          309 : Vehicle::getStopState(const std::string& vehID) {
     485          309 :     return Dom::getInt(libsumo::VAR_STOPSTATE, vehID);
     486              : }
     487              : 
     488              : 
     489              : double
     490          128 : Vehicle::getDistance(const std::string& vehID) {
     491          128 :     return Dom::getDouble(libsumo::VAR_DISTANCE, vehID);
     492              : }
     493              : 
     494              : 
     495              : double
     496          683 : Vehicle::getDrivingDistance(const std::string& vehID, const std::string& edgeID, double pos, int laneIndex) {
     497          683 :     tcpip::Storage content;
     498              :     StoHelp::writeCompound(content, 2);
     499          683 :     content.writeUnsignedByte(libsumo::POSITION_ROADMAP);
     500          683 :     content.writeString(edgeID);
     501          683 :     content.writeDouble(pos);
     502          683 :     content.writeUnsignedByte(laneIndex);
     503          683 :     content.writeUnsignedByte(libsumo::REQUEST_DRIVINGDIST);
     504         1366 :     return Dom::getDouble(libsumo::DISTANCE_REQUEST, vehID, &content);
     505          683 : }
     506              : 
     507              : 
     508              : double
     509           18 : Vehicle::getDrivingDistance2D(const std::string& vehID, double x, double y) {
     510           18 :     tcpip::Storage content;
     511              :     StoHelp::writeCompound(content, 2);
     512           18 :     content.writeUnsignedByte(libsumo::POSITION_2D);
     513           18 :     content.writeDouble(x);
     514           18 :     content.writeDouble(y);
     515           18 :     content.writeUnsignedByte(libsumo::REQUEST_DRIVINGDIST);
     516           36 :     return Dom::getDouble(libsumo::DISTANCE_REQUEST, vehID, &content);
     517           18 : }
     518              : 
     519              : 
     520              : double
     521           18 : Vehicle::getAllowedSpeed(const std::string& vehID) {
     522           18 :     return Dom::getDouble(libsumo::VAR_ALLOWED_SPEED, vehID);
     523              : }
     524              : 
     525              : 
     526              : double
     527           49 : Vehicle::getSpeedFactor(const std::string& vehID) {
     528           49 :     return Dom::getDouble(libsumo::VAR_SPEED_FACTOR, vehID);
     529              : }
     530              : 
     531              : 
     532              : int
     533           14 : Vehicle::getSpeedMode(const std::string& vehID) {
     534           14 :     return Dom::getInt(libsumo::VAR_SPEEDSETMODE, vehID);
     535              : }
     536              : 
     537              : 
     538              : int
     539           15 : Vehicle::getLaneChangeMode(const std::string& vehID) {
     540           15 :     return Dom::getInt(libsumo::VAR_LANECHANGE_MODE, vehID);
     541              : }
     542              : 
     543              : 
     544              : int
     545           18 : Vehicle::getRoutingMode(const std::string& vehID) {
     546           18 :     return Dom::getInt(libsumo::VAR_ROUTING_MODE, vehID);
     547              : }
     548              : 
     549              : 
     550              : std::string
     551           18 : Vehicle::getLine(const std::string& vehID) {
     552           18 :     return Dom::getString(libsumo::VAR_LINE, vehID);
     553              : }
     554              : 
     555              : 
     556              : 
     557              : std::vector<std::string>
     558           18 : Vehicle::getVia(const std::string& vehID) {
     559           18 :     return Dom::getStringVector(libsumo::VAR_VIA, vehID);
     560              : }
     561              : 
     562              : 
     563              : std::pair<int, int>
     564         3493 : Vehicle::getLaneChangeState(const std::string& vehID, int direction) {
     565         3493 :     tcpip::Storage content;
     566              :     StoHelp::writeTypedInt(content, direction);
     567         3493 :     std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
     568              :     tcpip::Storage& ret = Dom::get(libsumo::CMD_CHANGELANE, vehID, &content);
     569         3493 :     ret.readInt(); // components
     570         3493 :     ret.readUnsignedByte();
     571         3493 :     const int stateWithoutTraCI = ret.readInt();
     572         3493 :     ret.readUnsignedByte();
     573         3493 :     const int state = ret.readInt();
     574         3493 :     return std::make_pair(stateWithoutTraCI, state);
     575         3493 : }
     576              : 
     577              : 
     578              : std::vector<std::pair<std::string, double> >
     579          856 : Vehicle::getNeighbors(const std::string& vehID, const int mode) {
     580              :     std::vector<std::pair<std::string, double> > neighs;
     581          856 :     tcpip::Storage content;
     582          856 :     content.writeUnsignedByte(libsumo::TYPE_UBYTE);
     583          856 :     content.writeUnsignedByte(mode);
     584          856 :     std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
     585              :     tcpip::Storage& ret = Dom::get(libsumo::VAR_NEIGHBORS, vehID, &content);
     586          856 :     const int items = ret.readInt(); // components
     587         1328 :     for (int i = 0; i < items; i++) {
     588          472 :         const std::string neighID = ret.readString();
     589          472 :         neighs.emplace_back(neighID, ret.readDouble());
     590              :     }
     591          856 :     return neighs;
     592          856 : }
     593              : 
     594              : 
     595              : double
     596          177 : Vehicle::getFollowSpeed(const std::string& vehID, double speed, double gap, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) {
     597          177 :     tcpip::Storage content;
     598              :     StoHelp::writeCompound(content, 5);
     599              :     StoHelp::writeTypedDouble(content, speed);
     600              :     StoHelp::writeTypedDouble(content, gap);
     601              :     StoHelp::writeTypedDouble(content, leaderSpeed);
     602              :     StoHelp::writeTypedDouble(content, leaderMaxDecel);
     603              :     StoHelp::writeTypedString(content, leaderID);
     604          354 :     return Dom::getDouble(libsumo::VAR_FOLLOW_SPEED, vehID, &content);
     605          177 : }
     606              : 
     607              : 
     608              : double
     609            2 : Vehicle::getSecureGap(const std::string& vehID, double speed, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) {
     610            2 :     tcpip::Storage content;
     611              :     StoHelp::writeCompound(content, 4);
     612              :     StoHelp::writeTypedDouble(content, speed);
     613              :     StoHelp::writeTypedDouble(content, leaderSpeed);
     614              :     StoHelp::writeTypedDouble(content, leaderMaxDecel);
     615              :     StoHelp::writeTypedString(content, leaderID);
     616            4 :     return Dom::getDouble(libsumo::VAR_SECURE_GAP, vehID, &content);
     617            2 : }
     618              : 
     619              : 
     620              : double
     621            2 : Vehicle::getStopSpeed(const std::string& vehID, const double speed, double gap) {
     622            2 :     tcpip::Storage content;
     623              :     StoHelp::writeCompound(content, 2);
     624              :     StoHelp::writeTypedDouble(content, speed);
     625              :     StoHelp::writeTypedDouble(content, gap);
     626            4 :     return Dom::getDouble(libsumo::VAR_STOP_SPEED, vehID, &content);
     627            2 : }
     628              : 
     629              : double
     630          125 : Vehicle::getStopDelay(const std::string& vehID) {
     631          125 :     return Dom::getDouble(libsumo::VAR_STOP_DELAY, vehID);
     632              : }
     633              : 
     634              : double
     635          125 : Vehicle::getStopArrivalDelay(const std::string& vehID) {
     636          125 :     return Dom::getDouble(libsumo::VAR_STOP_ARRIVALDELAY, vehID);
     637              : }
     638              : 
     639              : double
     640           18 : Vehicle::getTimeLoss(const std::string& vehID) {
     641           18 :     return Dom::getDouble(libsumo::VAR_TIMELOSS, vehID);
     642              : }
     643              : 
     644              : std::vector<std::string>
     645         1821 : Vehicle::getTaxiFleet(int taxiState) {
     646         1821 :     tcpip::Storage content;
     647              :     StoHelp::writeTypedInt(content, taxiState);
     648         3642 :     return Dom::getStringVector(libsumo::VAR_TAXI_FLEET, "", &content);
     649         1821 : }
     650              : 
     651              : std::vector<std::string>
     652           46 : Vehicle::getLoadedIDList() {
     653           92 :     return Dom::getStringVector(libsumo::VAR_LOADED_LIST, "");
     654              : }
     655              : 
     656              : std::vector<std::string>
     657           36 : Vehicle::getTeleportingIDList() {
     658           72 :     return Dom::getStringVector(libsumo::VAR_TELEPORTING_LIST, "");
     659              : }
     660              : 
     661              : std::string
     662           38 : Vehicle::getEmissionClass(const std::string& vehID) {
     663           38 :     return Dom::getString(libsumo::VAR_EMISSIONCLASS, vehID);
     664              : }
     665              : 
     666              : std::string
     667           18 : Vehicle::getShapeClass(const std::string& vehID) {
     668           18 :     return Dom::getString(libsumo::VAR_SHAPECLASS, vehID);
     669              : }
     670              : 
     671              : 
     672              : double
     673           20 : Vehicle::getLength(const std::string& vehID) {
     674           20 :     return Dom::getDouble(libsumo::VAR_LENGTH, vehID);
     675              : }
     676              : 
     677              : 
     678              : double
     679           20 : Vehicle::getAccel(const std::string& vehID) {
     680           20 :     return Dom::getDouble(libsumo::VAR_ACCEL, vehID);
     681              : }
     682              : 
     683              : 
     684              : double
     685          201 : Vehicle::getDecel(const std::string& vehID) {
     686          201 :     return Dom::getDouble(libsumo::VAR_DECEL, vehID);
     687              : }
     688              : 
     689              : 
     690           22 : double Vehicle::getEmergencyDecel(const std::string& vehID) {
     691           22 :     return Dom::getDouble(libsumo::VAR_EMERGENCY_DECEL, vehID);
     692              : }
     693              : 
     694              : 
     695           20 : double Vehicle::getApparentDecel(const std::string& vehID) {
     696           20 :     return Dom::getDouble(libsumo::VAR_APPARENT_DECEL, vehID);
     697              : }
     698              : 
     699              : 
     700           20 : double Vehicle::getActionStepLength(const std::string& vehID) {
     701           20 :     return Dom::getDouble(libsumo::VAR_ACTIONSTEPLENGTH, vehID);
     702              : }
     703              : 
     704              : 
     705           18 : double Vehicle::getLastActionTime(const std::string& vehID) {
     706           18 :     return Dom::getDouble(libsumo::VAR_LASTACTIONTIME, vehID);
     707              : }
     708              : 
     709              : 
     710              : double
     711           20 : Vehicle::getTau(const std::string& vehID) {
     712           20 :     return Dom::getDouble(libsumo::VAR_TAU, vehID);
     713              : }
     714              : 
     715              : 
     716              : double
     717           22 : Vehicle::getImperfection(const std::string& vehID) {
     718           22 :     return Dom::getDouble(libsumo::VAR_IMPERFECTION, vehID);
     719              : }
     720              : 
     721              : 
     722              : double
     723           18 : Vehicle::getSpeedDeviation(const std::string& vehID) {
     724           18 :     return Dom::getDouble(libsumo::VAR_SPEED_DEVIATION, vehID);
     725              : }
     726              : 
     727              : 
     728              : std::string
     729           18 : Vehicle::getVehicleClass(const std::string& vehID) {
     730           18 :     return Dom::getString(libsumo::VAR_VEHICLECLASS, vehID);
     731              : }
     732              : 
     733              : 
     734              : double
     735           60 : Vehicle::getMinGap(const std::string& vehID) {
     736           60 :     return Dom::getDouble(libsumo::VAR_MINGAP, vehID);
     737              : }
     738              : 
     739              : 
     740              : double
     741           18 : Vehicle::getMinGapLat(const std::string& vehID) {
     742           18 :     return Dom::getDouble(libsumo::VAR_MINGAP_LAT, vehID);
     743              : }
     744              : 
     745              : 
     746              : double
     747           20 : Vehicle::getMaxSpeed(const std::string& vehID) {
     748           20 :     return Dom::getDouble(libsumo::VAR_MAXSPEED, vehID);
     749              : }
     750              : 
     751              : 
     752              : double
     753           18 : Vehicle::getMaxSpeedLat(const std::string& vehID) {
     754           18 :     return Dom::getDouble(libsumo::VAR_MAXSPEED_LAT, vehID);
     755              : }
     756              : 
     757              : 
     758              : std::string
     759           18 : Vehicle::getLateralAlignment(const std::string& vehID) {
     760           18 :     return Dom::getString(libsumo::VAR_LATALIGNMENT, vehID);
     761              : }
     762              : 
     763              : 
     764              : double
     765           20 : Vehicle::getWidth(const std::string& vehID) {
     766           20 :     return Dom::getDouble(libsumo::VAR_WIDTH, vehID);
     767              : }
     768              : 
     769              : 
     770              : double
     771           18 : Vehicle::getHeight(const std::string& vehID) {
     772           18 :     return Dom::getDouble(libsumo::VAR_HEIGHT, vehID);
     773              : }
     774              : 
     775              : 
     776              : double
     777           18 : Vehicle::getMass(const std::string& vehID) {
     778           18 :     return Dom::getDouble(libsumo::VAR_MASS, vehID);
     779              : }
     780              : 
     781              : 
     782              : void
     783           42 : Vehicle::setStop(const std::string& vehID,
     784              :                  const std::string& edgeID,
     785              :                  double pos,
     786              :                  int laneIndex,
     787              :                  double duration,
     788              :                  int flags,
     789              :                  double startPos,
     790              :                  double until) {
     791           42 :     tcpip::Storage content;
     792              :     StoHelp::writeCompound(content, 7);
     793              :     StoHelp::writeTypedString(content, edgeID);
     794              :     StoHelp::writeTypedDouble(content, pos);
     795              :     StoHelp::writeTypedByte(content, laneIndex);
     796              :     StoHelp::writeTypedDouble(content, duration);
     797              :     StoHelp::writeTypedByte(content, flags);
     798              :     StoHelp::writeTypedDouble(content, startPos);
     799              :     StoHelp::writeTypedDouble(content, until);
     800           42 :     Dom::set(libsumo::CMD_STOP, vehID, &content);
     801           42 : }
     802              : 
     803              : 
     804              : void
     805           43 : Vehicle::replaceStop(const std::string& vehID,
     806              :                      int nextStopIndex,
     807              :                      const std::string& edgeID,
     808              :                      double pos,
     809              :                      int laneIndex,
     810              :                      double duration,
     811              :                      int flags,
     812              :                      double startPos,
     813              :                      double until,
     814              :                      int teleport) {
     815           43 :     tcpip::Storage content;
     816              :     StoHelp::writeCompound(content, 9);
     817              :     StoHelp::writeTypedString(content, edgeID);
     818              :     StoHelp::writeTypedDouble(content, pos);
     819              :     StoHelp::writeTypedByte(content, laneIndex);
     820              :     StoHelp::writeTypedDouble(content, duration);
     821              :     StoHelp::writeTypedInt(content, flags);
     822              :     StoHelp::writeTypedDouble(content, startPos);
     823              :     StoHelp::writeTypedDouble(content, until);
     824              :     StoHelp::writeTypedInt(content, nextStopIndex);
     825              :     StoHelp::writeTypedByte(content, teleport);
     826           43 :     Dom::set(libsumo::CMD_REPLACE_STOP, vehID, &content);
     827           43 : }
     828              : 
     829              : 
     830              : void
     831           28 : Vehicle::insertStop(const std::string& vehID,
     832              :                     int nextStopIndex,
     833              :                     const std::string& edgeID,
     834              :                     double pos,
     835              :                     int laneIndex,
     836              :                     double duration,
     837              :                     int flags,
     838              :                     double startPos,
     839              :                     double until,
     840              :                     int teleport) {
     841           28 :     tcpip::Storage content;
     842              :     StoHelp::writeCompound(content, 9);
     843              :     StoHelp::writeTypedString(content, edgeID);
     844              :     StoHelp::writeTypedDouble(content, pos);
     845              :     StoHelp::writeTypedByte(content, laneIndex);
     846              :     StoHelp::writeTypedDouble(content, duration);
     847              :     StoHelp::writeTypedInt(content, flags);
     848              :     StoHelp::writeTypedDouble(content, startPos);
     849              :     StoHelp::writeTypedDouble(content, until);
     850              :     StoHelp::writeTypedInt(content, nextStopIndex);
     851              :     StoHelp::writeTypedByte(content, teleport);
     852           28 :     Dom::set(libsumo::CMD_INSERT_STOP, vehID, &content);
     853           28 : }
     854              : 
     855              : 
     856              : void
     857           35 : Vehicle::setStopParameter(const std::string& vehID, int nextStopIndex,
     858              :                           const std::string& param, const std::string& value,
     859              :                           bool customParam) {
     860           35 :     tcpip::Storage content;
     861              :     StoHelp::writeCompound(content, 4);
     862              :     StoHelp::writeTypedInt(content, nextStopIndex);
     863              :     StoHelp::writeTypedString(content, param);
     864              :     StoHelp::writeTypedString(content, value);
     865           35 :     StoHelp::writeTypedByte(content, customParam);
     866           35 :     Dom::set(libsumo::VAR_STOP_PARAMETER, vehID, &content);
     867           35 : }
     868              : 
     869              : 
     870              : void
     871            3 : Vehicle::rerouteParkingArea(const std::string& vehID, const std::string& parkingAreaID) {
     872            3 :     tcpip::Storage content;
     873              :     StoHelp::writeCompound(content, 1);
     874              :     StoHelp::writeTypedString(content, parkingAreaID);
     875            3 :     Dom::set(libsumo::CMD_REROUTE_TO_PARKING, vehID, &content);
     876            3 : }
     877              : 
     878              : 
     879              : void
     880            1 : Vehicle::resume(const std::string& vehID) {
     881            1 :     tcpip::Storage content;
     882              :     StoHelp::writeCompound(content, 0);
     883            1 :     Dom::set(libsumo::CMD_RESUME, vehID, &content);
     884            1 : }
     885              : 
     886              : 
     887              : void
     888            8 : Vehicle::changeTarget(const std::string& vehID, const std::string& edgeID) {
     889            8 :     Dom::setString(libsumo::CMD_CHANGETARGET, vehID, edgeID);
     890            6 : }
     891              : 
     892              : 
     893              : void
     894         2222 : Vehicle::changeLane(const std::string& vehID, int laneIndex, double duration) {
     895         2222 :     tcpip::Storage content;
     896              :     StoHelp::writeCompound(content, 2);
     897              :     StoHelp::writeTypedByte(content, laneIndex);
     898              :     StoHelp::writeTypedDouble(content, duration);
     899         2222 :     Dom::set(libsumo::CMD_CHANGELANE, vehID, &content);
     900         2222 : }
     901              : 
     902              : void
     903           55 : Vehicle::changeLaneRelative(const std::string& vehID, int indexOffset, double duration) {
     904           55 :     tcpip::Storage content;
     905              :     StoHelp::writeCompound(content, 3);
     906              :     StoHelp::writeTypedByte(content, indexOffset);
     907              :     StoHelp::writeTypedDouble(content, duration);
     908              :     StoHelp::writeTypedByte(content, 1);
     909           55 :     Dom::set(libsumo::CMD_CHANGELANE, vehID, &content);
     910           55 : }
     911              : 
     912              : 
     913              : void
     914           75 : Vehicle::changeSublane(const std::string& vehID, double latDist) {
     915           75 :     Dom::setDouble(libsumo::CMD_CHANGESUBLANE, vehID, latDist);
     916           75 : }
     917              : 
     918              : 
     919              : void
     920         7474 : Vehicle::add(const std::string& vehID,
     921              :              const std::string& routeID,
     922              :              const std::string& typeID,
     923              :              const std::string& depart,
     924              :              const std::string& departLane,
     925              :              const std::string& departPos,
     926              :              const std::string& departSpeed,
     927              :              const std::string& arrivalLane,
     928              :              const std::string& arrivalPos,
     929              :              const std::string& arrivalSpeed,
     930              :              const std::string& fromTaz,
     931              :              const std::string& toTaz,
     932              :              const std::string& line,
     933              :              int personCapacity,
     934              :              int personNumber) {
     935         7474 :     tcpip::Storage content;
     936              :     StoHelp::writeCompound(content, 14);
     937              :     StoHelp::writeTypedString(content, routeID);
     938              :     StoHelp::writeTypedString(content, typeID);
     939              :     StoHelp::writeTypedString(content, depart);
     940              :     StoHelp::writeTypedString(content, departLane);
     941              :     StoHelp::writeTypedString(content, departPos);
     942              :     StoHelp::writeTypedString(content, departSpeed);
     943              : 
     944              :     StoHelp::writeTypedString(content, arrivalLane);
     945              :     StoHelp::writeTypedString(content, arrivalPos);
     946              :     StoHelp::writeTypedString(content, arrivalSpeed);
     947              : 
     948              :     StoHelp::writeTypedString(content, fromTaz);
     949              :     StoHelp::writeTypedString(content, toTaz);
     950              :     StoHelp::writeTypedString(content, line);
     951              : 
     952              :     StoHelp::writeTypedInt(content, personCapacity);
     953              :     StoHelp::writeTypedInt(content, personNumber);
     954              : 
     955         7474 :     Dom::set(libsumo::ADD_FULL, vehID, &content);
     956         7474 : }
     957              : 
     958              : 
     959              : void
     960         1011 : Vehicle::moveToXY(const std::string& vehID, const std::string& edgeID, const int laneIndex,
     961              :                   const double x, const double y, double angle, const int keepRoute, double matchThreshold) {
     962         1011 :     tcpip::Storage content;
     963              :     StoHelp::writeCompound(content, 7);
     964              :     StoHelp::writeTypedString(content, edgeID);
     965              :     StoHelp::writeTypedInt(content, laneIndex);
     966              :     StoHelp::writeTypedDouble(content, x);
     967              :     StoHelp::writeTypedDouble(content, y);
     968              :     StoHelp::writeTypedDouble(content, angle);
     969              :     StoHelp::writeTypedByte(content, keepRoute);
     970              :     StoHelp::writeTypedDouble(content, matchThreshold);
     971         1011 :     Dom::set(libsumo::MOVE_TO_XY, vehID, &content);
     972         1011 : }
     973              : 
     974              : void
     975            8 : Vehicle::slowDown(const std::string& vehID, double speed, double duration) {
     976            8 :     tcpip::Storage content;
     977              :     StoHelp::writeCompound(content, 2);
     978              :     StoHelp::writeTypedDouble(content, speed);
     979              :     StoHelp::writeTypedDouble(content, duration);
     980            8 :     Dom::set(libsumo::CMD_SLOWDOWN, vehID, &content);
     981            8 : }
     982              : 
     983              : void
     984           17 : Vehicle::openGap(const std::string& vehID, double newTimeHeadway, double newSpaceHeadway, double duration, double changeRate, double maxDecel, const std::string& referenceVehID) {
     985           17 :     tcpip::Storage content;
     986           17 :     StoHelp::writeCompound(content, referenceVehID != "" ? 6 : 5);
     987              :     StoHelp::writeTypedDouble(content, newTimeHeadway);
     988              :     StoHelp::writeTypedDouble(content, newSpaceHeadway);
     989              :     StoHelp::writeTypedDouble(content, duration);
     990              :     StoHelp::writeTypedDouble(content, changeRate);
     991              :     StoHelp::writeTypedDouble(content, maxDecel);
     992           17 :     if (referenceVehID != "") {
     993              :         StoHelp::writeTypedString(content, referenceVehID);
     994              :     }
     995           17 :     Dom::set(libsumo::CMD_OPENGAP, vehID, &content);
     996           17 : }
     997              : 
     998              : void
     999            2 : Vehicle::deactivateGapControl(const std::string& vehID) {
    1000            2 :     openGap(vehID, -1, -1, -1, -1);
    1001            2 : }
    1002              : 
    1003              : void
    1004            0 : Vehicle::requestToC(const std::string& vehID, double leadTime) {
    1005            0 :     std::ostringstream oss;
    1006              :     oss.setf(std::ios::fixed, std::ios::floatfield);
    1007              :     oss << std::setprecision(2);
    1008              :     oss << leadTime;
    1009            0 :     setParameter(vehID, "device.toc.requestToC", oss.str());
    1010            0 : }
    1011              : 
    1012              : void
    1013          242 : Vehicle::setSpeed(const std::string& vehID, double speed) {
    1014          242 :     Dom::setDouble(libsumo::VAR_SPEED, vehID, speed);
    1015          242 : }
    1016              : 
    1017              : void
    1018            3 : Vehicle::setAcceleration(const std::string& vehID, double acceleration, double duration) {
    1019            3 :     tcpip::Storage content;
    1020              :     StoHelp::writeCompound(content, 2);
    1021              :     StoHelp::writeTypedDouble(content, acceleration);
    1022              :     StoHelp::writeTypedDouble(content, duration);
    1023            3 :     Dom::set(libsumo::VAR_ACCELERATION, vehID, &content);
    1024            3 : }
    1025              : 
    1026              : void
    1027           49 : Vehicle::setPreviousSpeed(const std::string& vehID, double prevSpeed, double prevAcceleration) {
    1028           49 :     tcpip::Storage content;
    1029              :     StoHelp::writeCompound(content, 2);
    1030              :     StoHelp::writeTypedDouble(content, prevSpeed);
    1031              :     StoHelp::writeTypedDouble(content, prevAcceleration);
    1032           49 :     Dom::set(libsumo::VAR_PREV_SPEED, vehID, &content);
    1033           49 : }
    1034              : 
    1035              : void
    1036           27 : Vehicle::setSpeedMode(const std::string& vehID, int speedMode) {
    1037           27 :     Dom::setInt(libsumo::VAR_SPEEDSETMODE, vehID, speedMode);
    1038           27 : }
    1039              : 
    1040              : void
    1041          108 : Vehicle::setLaneChangeMode(const std::string& vehID, int laneChangeMode) {
    1042          108 :     Dom::setInt(libsumo::VAR_LANECHANGE_MODE, vehID, laneChangeMode);
    1043          108 : }
    1044              : 
    1045              : void
    1046           23 : Vehicle::setRoutingMode(const std::string& vehID, int routingMode) {
    1047           23 :     Dom::setInt(libsumo::VAR_ROUTING_MODE, vehID, routingMode);
    1048           23 : }
    1049              : 
    1050              : void
    1051           73 : Vehicle::setType(const std::string& vehID, const std::string& typeID) {
    1052           73 :     Dom::setString(libsumo::VAR_TYPE, vehID, typeID);
    1053           73 : }
    1054              : 
    1055              : void
    1056            5 : Vehicle::setRouteID(const std::string& vehID, const std::string& routeID) {
    1057            5 :     Dom::setString(libsumo::VAR_ROUTE_ID, vehID, routeID);
    1058            5 : }
    1059              : 
    1060              : void
    1061            1 : Vehicle::setRoute(const std::string& vehID, const std::string& edgeID) {
    1062            3 :     setRoute(vehID, std::vector<std::string>({edgeID}));
    1063            0 : }
    1064              : 
    1065              : void
    1066            7 : Vehicle::setRoute(const std::string& vehID, const std::vector<std::string>& edgeIDs) {
    1067            7 :     Dom::setStringVector(libsumo::VAR_ROUTE, vehID, edgeIDs);
    1068            6 : }
    1069              : 
    1070              : void
    1071            2 : Vehicle::setLateralLanePosition(const std::string& vehID, double posLat) {
    1072            2 :     Dom::setDouble(libsumo::VAR_LANEPOSITION_LAT, vehID, posLat);
    1073            2 : }
    1074              : 
    1075              : void
    1076           59 : Vehicle::updateBestLanes(const std::string& vehID) {
    1077           59 :     tcpip::Storage content;
    1078           59 :     Dom::set(libsumo::VAR_UPDATE_BESTLANES, vehID, &content);
    1079           59 : }
    1080              : 
    1081              : 
    1082              : void
    1083           39 : Vehicle::setAdaptedTraveltime(const std::string& vehID, const std::string& edgeID,
    1084              :                               double time, double begSeconds, double endSeconds) {
    1085           39 :     tcpip::Storage content;
    1086           39 :     if (time == libsumo::INVALID_DOUBLE_VALUE) {
    1087              :         // reset
    1088              :         StoHelp::writeCompound(content, 1);
    1089              :         StoHelp::writeTypedString(content, edgeID);
    1090           37 :     } else if (begSeconds == libsumo::INVALID_DOUBLE_VALUE) {
    1091              :         // set value for the whole simulation
    1092              :         StoHelp::writeCompound(content, 2);
    1093              :         StoHelp::writeTypedString(content, edgeID);
    1094              :         StoHelp::writeTypedDouble(content, time);
    1095              :     } else {
    1096              :         StoHelp::writeCompound(content, 4);
    1097              :         StoHelp::writeTypedDouble(content, begSeconds);
    1098              :         StoHelp::writeTypedDouble(content, endSeconds);
    1099              :         StoHelp::writeTypedString(content, edgeID);
    1100              :         StoHelp::writeTypedDouble(content, time);
    1101              :     }
    1102           39 :     Dom::set(libsumo::VAR_EDGE_TRAVELTIME, vehID, &content);
    1103           39 : }
    1104              : 
    1105              : 
    1106              : void
    1107            6 : Vehicle::setEffort(const std::string& vehID, const std::string& edgeID,
    1108              :                    double effort, double begSeconds, double endSeconds) {
    1109            6 :     tcpip::Storage content;
    1110            6 :     if (effort == libsumo::INVALID_DOUBLE_VALUE) {
    1111              :         // reset
    1112              :         StoHelp::writeCompound(content, 1);
    1113              :         StoHelp::writeTypedString(content, edgeID);
    1114            4 :     } else if (begSeconds == libsumo::INVALID_DOUBLE_VALUE) {
    1115              :         // set value for the whole simulation
    1116              :         StoHelp::writeCompound(content, 2);
    1117              :         StoHelp::writeTypedString(content, edgeID);
    1118              :         StoHelp::writeTypedDouble(content, effort);
    1119              :     } else {
    1120              :         StoHelp::writeCompound(content, 4);
    1121              :         StoHelp::writeTypedDouble(content, begSeconds);
    1122              :         StoHelp::writeTypedDouble(content, endSeconds);
    1123              :         StoHelp::writeTypedString(content, edgeID);
    1124              :         StoHelp::writeTypedDouble(content, effort);
    1125              :     }
    1126            6 :     Dom::set(libsumo::VAR_EDGE_EFFORT, vehID, &content);
    1127            6 : }
    1128              : 
    1129              : 
    1130              : void
    1131           73 : Vehicle::rerouteTraveltime(const std::string& vehID, const bool /* currentTravelTimes */) {
    1132           73 :     tcpip::Storage content;
    1133              :     StoHelp::writeCompound(content, 0);
    1134           73 :     Dom::set(libsumo::CMD_REROUTE_TRAVELTIME, vehID, &content);
    1135           73 : }
    1136              : 
    1137              : 
    1138              : void
    1139            2 : Vehicle::rerouteEffort(const std::string& vehID) {
    1140            2 :     tcpip::Storage content;
    1141              :     StoHelp::writeCompound(content, 0);
    1142            2 :     Dom::set(libsumo::CMD_REROUTE_EFFORT, vehID, &content);
    1143            2 : }
    1144              : 
    1145              : 
    1146              : void
    1147            4 : Vehicle::setSignals(const std::string& vehID, int signals) {
    1148            4 :     Dom::setInt(libsumo::VAR_SIGNALS, vehID, signals);
    1149            4 : }
    1150              : 
    1151              : 
    1152              : void
    1153          102 : Vehicle::moveTo(const std::string& vehID, const std::string& laneID, double pos, int reason) {
    1154          102 :     tcpip::Storage content;
    1155              :     StoHelp::writeCompound(content, 3);
    1156              :     StoHelp::writeTypedString(content, laneID);
    1157              :     StoHelp::writeTypedDouble(content, pos);
    1158              :     StoHelp::writeTypedInt(content, reason);
    1159          102 :     Dom::set(libsumo::VAR_MOVE_TO, vehID, &content);
    1160          102 : }
    1161              : 
    1162              : 
    1163              : void
    1164            4 : Vehicle::setActionStepLength(const std::string& vehID, double actionStepLength, bool resetActionOffset) {
    1165              :     //if (actionStepLength < 0) {
    1166              :     //    raise TraCIException("Invalid value for actionStepLength. Given value must be non-negative.")
    1167              :     //{
    1168              :     // Use negative value to indicate resetActionOffset == False
    1169            4 :     if (!resetActionOffset) {
    1170            2 :         actionStepLength *= -1;
    1171              :     }
    1172            4 :     Dom::setDouble(libsumo::VAR_ACTIONSTEPLENGTH, vehID, actionStepLength);
    1173            4 : }
    1174              : 
    1175              : 
    1176              : void
    1177            4 : Vehicle::remove(const std::string& vehID, char reason) {
    1178            4 :     tcpip::Storage content;
    1179            4 :     content.writeUnsignedByte(libsumo::TYPE_BYTE);
    1180            4 :     content.writeUnsignedByte(reason);
    1181            4 :     Dom::set(libsumo::REMOVE, vehID, &content);
    1182            4 : }
    1183              : 
    1184              : 
    1185              : void
    1186           44 : Vehicle::setColor(const std::string& vehID, const libsumo::TraCIColor& color) {
    1187           44 :     Dom::setCol(libsumo::VAR_COLOR, vehID, color);
    1188           44 : }
    1189              : 
    1190              : 
    1191              : void
    1192         2047 : Vehicle::setSpeedFactor(const std::string& vehID, double factor) {
    1193         2047 :     Dom::setDouble(libsumo::VAR_SPEED_FACTOR, vehID, factor);
    1194         2047 : }
    1195              : 
    1196              : 
    1197              : void
    1198            3 : Vehicle::setLine(const std::string& vehID, const std::string& line) {
    1199            3 :     Dom::setString(libsumo::VAR_LINE, vehID, line);
    1200            3 : }
    1201              : 
    1202              : 
    1203              : void
    1204            4 : Vehicle::setVia(const std::string& vehID, const std::vector<std::string>& edgeList) {
    1205            4 :     Dom::setStringVector(libsumo::VAR_VIA, vehID, edgeList);
    1206            4 : }
    1207              : 
    1208              : 
    1209              : void
    1210           23 : Vehicle::setLength(const std::string& vehID, double length) {
    1211           23 :     Dom::setDouble(libsumo::VAR_LENGTH, vehID, length);
    1212           23 : }
    1213              : 
    1214              : 
    1215              : void
    1216            9 : Vehicle::setMaxSpeed(const std::string& vehID, double speed) {
    1217            9 :     Dom::setDouble(libsumo::VAR_MAXSPEED, vehID, speed);
    1218            9 : }
    1219              : 
    1220              : 
    1221              : void
    1222            2 : Vehicle::setVehicleClass(const std::string& vehID, const std::string& clazz) {
    1223            2 :     Dom::setString(libsumo::VAR_VEHICLECLASS, vehID, clazz);
    1224            2 : }
    1225              : 
    1226              : 
    1227              : void
    1228            2 : Vehicle::setShapeClass(const std::string& vehID, const std::string& clazz) {
    1229            2 :     Dom::setString(libsumo::VAR_SHAPECLASS, vehID, clazz);
    1230            2 : }
    1231              : 
    1232              : 
    1233              : void
    1234            4 : Vehicle::setEmissionClass(const std::string& vehID, const std::string& clazz) {
    1235            4 :     Dom::setString(libsumo::VAR_EMISSIONCLASS, vehID, clazz);
    1236            4 : }
    1237              : 
    1238              : 
    1239              : void
    1240            3 : Vehicle::setWidth(const std::string& vehID, double width) {
    1241            3 :     Dom::setDouble(libsumo::VAR_WIDTH, vehID, width);
    1242            3 : }
    1243              : 
    1244              : 
    1245              : void
    1246            2 : Vehicle::setHeight(const std::string& vehID, double height) {
    1247            2 :     Dom::setDouble(libsumo::VAR_HEIGHT, vehID, height);
    1248            2 : }
    1249              : 
    1250              : 
    1251              : void
    1252            2 : Vehicle::setMass(const std::string& vehID, double mass) {
    1253            2 :     Dom::setDouble(libsumo::VAR_MASS, vehID, mass);
    1254            2 : }
    1255              : 
    1256              : 
    1257              : void
    1258            3 : Vehicle::setMinGap(const std::string& vehID, double minGap) {
    1259            3 :     Dom::setDouble(libsumo::VAR_MINGAP, vehID, minGap);
    1260            3 : }
    1261              : 
    1262              : 
    1263              : void
    1264            5 : Vehicle::setAccel(const std::string& vehID, double accel) {
    1265            5 :     Dom::setDouble(libsumo::VAR_ACCEL, vehID, accel);
    1266            5 : }
    1267              : 
    1268              : 
    1269              : void
    1270            3 : Vehicle::setDecel(const std::string& vehID, double decel) {
    1271            3 :     Dom::setDouble(libsumo::VAR_DECEL, vehID, decel);
    1272            3 : }
    1273              : 
    1274              : 
    1275              : void
    1276            5 : Vehicle::setEmergencyDecel(const std::string& vehID, double decel) {
    1277            5 :     Dom::setDouble(libsumo::VAR_EMERGENCY_DECEL, vehID, decel);
    1278            5 : }
    1279              : 
    1280              : 
    1281              : void
    1282            3 : Vehicle::setApparentDecel(const std::string& vehID, double decel) {
    1283            3 :     Dom::setDouble(libsumo::VAR_APPARENT_DECEL, vehID, decel);
    1284            3 : }
    1285              : 
    1286              : 
    1287              : void
    1288            4 : Vehicle::setImperfection(const std::string& vehID, double imperfection) {
    1289            4 :     Dom::setDouble(libsumo::VAR_IMPERFECTION, vehID, imperfection);
    1290            4 : }
    1291              : 
    1292              : 
    1293              : void
    1294            3 : Vehicle::setTau(const std::string& vehID, double tau) {
    1295            3 :     Dom::setDouble(libsumo::VAR_TAU, vehID, tau);
    1296            3 : }
    1297              : 
    1298              : 
    1299              : void
    1300            2 : Vehicle::setMinGapLat(const std::string& vehID, double minGapLat) {
    1301            2 :     Dom::setDouble(libsumo::VAR_MINGAP_LAT, vehID, minGapLat);
    1302            2 : }
    1303              : 
    1304              : 
    1305              : void
    1306            2 : Vehicle::setMaxSpeedLat(const std::string& vehID, double speed) {
    1307            2 :     Dom::setDouble(libsumo::VAR_MAXSPEED_LAT, vehID, speed);
    1308            2 : }
    1309              : 
    1310              : 
    1311              : void
    1312            2 : Vehicle::setLateralAlignment(const std::string& vehID, const std::string& latAlignment) {
    1313            2 :     Dom::setString(libsumo::VAR_LATALIGNMENT, vehID, latAlignment);
    1314            2 : }
    1315              : 
    1316              : 
    1317              : void
    1318            6 : Vehicle::setImpatience(const std::string& vehID, double impatience) {
    1319            6 :     Dom::setDouble(libsumo::VAR_IMPATIENCE, vehID, impatience);
    1320            6 : }
    1321              : 
    1322              : void
    1323            2 : Vehicle::setBoardingDuration(const std::string& vehID, double boardingDuration) {
    1324            2 :     Dom::setDouble(libsumo::VAR_BOARDING_DURATION, vehID, boardingDuration);
    1325            2 : }
    1326              : 
    1327              : 
    1328              : void
    1329           10 : Vehicle::highlight(const std::string& vehID, const libsumo::TraCIColor& col, double size, const int alphaMax, const double duration, const int type) {
    1330           10 :     tcpip::Storage content;
    1331           10 :     StoHelp::writeCompound(content, alphaMax > 0 ? 5 : 2);
    1332           10 :     content.writeUnsignedByte(libsumo::TYPE_COLOR);
    1333           10 :     content.writeUnsignedByte(col.r);
    1334           10 :     content.writeUnsignedByte(col.g);
    1335           10 :     content.writeUnsignedByte(col.b);
    1336           10 :     content.writeUnsignedByte(col.a);
    1337              :     StoHelp::writeTypedDouble(content, size);
    1338           10 :     if (alphaMax > 0) {
    1339            6 :         content.writeUnsignedByte(libsumo::TYPE_UBYTE);
    1340            6 :         content.writeUnsignedByte(alphaMax);
    1341              :         StoHelp::writeTypedDouble(content, duration);
    1342            6 :         content.writeUnsignedByte(libsumo::TYPE_UBYTE);
    1343            6 :         content.writeUnsignedByte(type);
    1344              :     }
    1345           10 :     Dom::set(libsumo::VAR_HIGHLIGHT, vehID, &content);
    1346           10 : }
    1347              : 
    1348              : void
    1349           30 : Vehicle::dispatchTaxi(const std::string& vehID,  const std::vector<std::string>& reservations) {
    1350           30 :     Dom::setStringVector(libsumo::CMD_TAXI_DISPATCH, vehID, reservations);
    1351           28 : }
    1352              : 
    1353              : 
    1354              : void
    1355           17 : Vehicle::subscribeLeader(const std::string& vehID, double dist, double begin, double end) {
    1356           17 :     subscribe(vehID, std::vector<int>({ libsumo::VAR_LEADER }), begin, end,
    1357           51 :     libsumo::TraCIResults({ {libsumo::VAR_LEADER, std::make_shared<libsumo::TraCIDouble>(dist)} }));
    1358           17 : }
    1359              : 
    1360              : 
    1361              : void
    1362           43 : Vehicle::addSubscriptionFilterLanes(const std::vector<int>& lanes, bool noOpposite, double downstreamDist, double upstreamDist) {
    1363           43 :     tcpip::Storage content;
    1364           43 :     content.writeUnsignedByte((int)lanes.size());
    1365          115 :     for (int lane : lanes) {
    1366           72 :         content.writeUnsignedByte(lane < 0 ? lane + 256 : lane);
    1367              :     }
    1368           43 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_LANES, &content);
    1369           43 :     if (noOpposite) {
    1370            1 :         addSubscriptionFilterNoOpposite();
    1371              :     }
    1372           43 :     if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
    1373            2 :         addSubscriptionFilterDownstreamDistance(downstreamDist);
    1374              :     }
    1375           43 :     if (upstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
    1376            2 :         addSubscriptionFilterUpstreamDistance(upstreamDist);
    1377              :     }
    1378           43 : }
    1379              : 
    1380              : 
    1381              : void
    1382           14 : Vehicle::addSubscriptionFilterNoOpposite() {
    1383           14 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_NOOPPOSITE);
    1384           14 : }
    1385              : 
    1386              : 
    1387              : void
    1388           51 : Vehicle::addSubscriptionFilterDownstreamDistance(double dist) {
    1389           51 :     tcpip::Storage content;
    1390              :     StoHelp::writeTypedDouble(content, dist);
    1391           51 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_DOWNSTREAM_DIST, &content);
    1392           51 : }
    1393              : 
    1394              : 
    1395              : void
    1396           43 : Vehicle::addSubscriptionFilterUpstreamDistance(double dist) {
    1397           43 :     tcpip::Storage content;
    1398              :     StoHelp::writeTypedDouble(content, dist);
    1399           43 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_UPSTREAM_DIST, &content);
    1400           43 : }
    1401              : 
    1402              : 
    1403              : void
    1404            1 : Vehicle::addSubscriptionFilterCFManeuver(double downstreamDist, double upstreamDist) {
    1405            1 :     addSubscriptionFilterLeadFollow(std::vector<int>(1));
    1406            1 :     if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
    1407            0 :         addSubscriptionFilterDownstreamDistance(downstreamDist);
    1408              :     }
    1409            1 :     if (upstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
    1410            0 :         addSubscriptionFilterUpstreamDistance(upstreamDist);
    1411              :     }
    1412            1 : }
    1413              : 
    1414              : 
    1415              : void
    1416            4 : Vehicle::addSubscriptionFilterLCManeuver(int direction, bool noOpposite, double downstreamDist, double upstreamDist) {
    1417            4 :     if (direction == libsumo::INVALID_INT_VALUE) {
    1418            1 :         addSubscriptionFilterLeadFollow({ -1, 0, 1 });
    1419            3 :     } else if (direction != -1 && direction != 1) {
    1420              :         // warnings.warn("Ignoring lane change subscription filter with non-neighboring lane offset direction=%s." % direction)
    1421              :         return;
    1422              :     } else {
    1423            3 :         addSubscriptionFilterLeadFollow({ 0, direction });
    1424              :     }
    1425            4 :     if (noOpposite) {
    1426            0 :         addSubscriptionFilterNoOpposite();
    1427              :     }
    1428            4 :     if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
    1429            0 :         addSubscriptionFilterDownstreamDistance(downstreamDist);
    1430              :     }
    1431            4 :     if (upstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
    1432            0 :         addSubscriptionFilterUpstreamDistance(upstreamDist);
    1433              :     }
    1434              : }
    1435              : 
    1436              : 
    1437              : void
    1438            5 : Vehicle::addSubscriptionFilterLeadFollow(const std::vector<int>& lanes) {
    1439            5 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_LEAD_FOLLOW);
    1440            5 :     addSubscriptionFilterLanes(lanes);
    1441            5 : }
    1442              : 
    1443              : 
    1444              : void
    1445            8 : Vehicle::addSubscriptionFilterTurn(double downstreamDist, double foeDistToJunction) {
    1446            8 :     tcpip::Storage content;
    1447              :     StoHelp::writeTypedDouble(content, foeDistToJunction);
    1448            8 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_TURN, &content);
    1449            8 :     if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
    1450            8 :         addSubscriptionFilterDownstreamDistance(downstreamDist);
    1451              :     }
    1452            8 : }
    1453              : 
    1454              : 
    1455              : void
    1456            3 : Vehicle::addSubscriptionFilterVClass(const std::vector<std::string>& vClasses) {
    1457            3 :     tcpip::Storage content;
    1458              :     StoHelp::writeTypedStringList(content, vClasses);
    1459            3 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_VCLASS, &content);
    1460            3 : }
    1461              : 
    1462              : 
    1463              : void
    1464            3 : Vehicle::addSubscriptionFilterVType(const std::vector<std::string>& vTypes) {
    1465            3 :     tcpip::Storage content;
    1466              :     StoHelp::writeTypedStringList(content, vTypes);
    1467            3 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_VTYPE, &content);
    1468            3 : }
    1469              : 
    1470              : 
    1471              : void
    1472            8 : Vehicle::addSubscriptionFilterFieldOfVision(double openingAngle) {
    1473            8 :     tcpip::Storage content;
    1474              :     StoHelp::writeTypedDouble(content, openingAngle);
    1475            8 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_FIELD_OF_VISION, &content);
    1476            8 : }
    1477              : 
    1478              : 
    1479              : void
    1480            8 : Vehicle::addSubscriptionFilterLateralDistance(double lateralDist, double downstreamDist, double upstreamDist) {
    1481            8 :     tcpip::Storage content;
    1482              :     StoHelp::writeTypedDouble(content, lateralDist);
    1483            8 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_LATERAL_DIST, &content);
    1484            7 :     if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
    1485            7 :         addSubscriptionFilterDownstreamDistance(downstreamDist);
    1486              :     }
    1487            7 :     if (upstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
    1488            7 :         addSubscriptionFilterUpstreamDistance(upstreamDist);
    1489              :     }
    1490            8 : }
    1491              : 
    1492              : 
    1493              : }
    1494              : 
    1495              : 
    1496              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1