LCOV - code coverage report
Current view: top level - src/libtraci - Vehicle.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 97.9 % 583 571
Test Date: 2026-03-02 16:00:03 Functions: 99.5 % 183 182

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2017-2026 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      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        42371 : Vehicle::getIDList() {
      40        84741 :     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        32963 : LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(Vehicle, VEHICLE)
      51         1209 : LIBTRACI_PARAMETER_IMPLEMENTATION(Vehicle, VEHICLE)
      52              : 
      53              : double
      54         5159 : Vehicle::getSpeed(const std::string& vehID) {
      55         5159 :     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       331143 : Vehicle::getPosition(const std::string& vehID, const bool includeZ) {
      77       331143 :     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          102 : Vehicle::getAngle(const std::string& vehID) {
      89          102 :     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         1019 : Vehicle::getRoadID(const std::string& vehID) {
     101         1019 :     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         3357 : Vehicle::getLaneID(const std::string& vehID) {
     119         3357 :     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           83 : Vehicle::getTypeID(const std::string& vehID) {
     143           83 :     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         4747 : Vehicle::getLanePosition(const std::string& vehID) {
     166         4747 :     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           88 : Vehicle::getFuelConsumption(const std::string& vehID) {
     201           88 :     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           60 :     StoHelp::readJunctionFoeVector(ret, result);
     278           30 :     return result;
     279           30 : }
     280              : 
     281              : 
     282              : double
     283           50 : Vehicle::getWaitingTime(const std::string& vehID) {
     284           50 :     return Dom::getDouble(libsumo::VAR_WAITING_TIME, vehID);
     285              : }
     286              : 
     287              : 
     288              : double
     289           25 : Vehicle::getAccumulatedWaitingTime(const std::string& vehID) {
     290           25 :     return Dom::getDouble(libsumo::VAR_ACCUMULATED_WAITING_TIME, vehID);
     291              : }
     292              : 
     293              : 
     294              : double
     295           23 : Vehicle::getAdaptedTraveltime(const std::string& vehID, double time, const std::string& edgeID) {
     296           23 :     tcpip::Storage content;
     297              :     StoHelp::writeCompound(content, 2);
     298              :     StoHelp::writeTypedDouble(content, time);
     299              :     StoHelp::writeTypedString(content, edgeID);
     300           46 :     return Dom::getDouble(libsumo::VAR_EDGE_TRAVELTIME, vehID, &content);
     301           23 : }
     302              : 
     303              : 
     304              : double
     305           22 : Vehicle::getEffort(const std::string& vehID, double time, const std::string& edgeID) {
     306           22 :     tcpip::Storage content;
     307              :     StoHelp::writeCompound(content, 2);
     308              :     StoHelp::writeTypedDouble(content, time);
     309              :     StoHelp::writeTypedString(content, edgeID);
     310           44 :     return Dom::getDouble(libsumo::VAR_EDGE_EFFORT, vehID, &content);
     311           22 : }
     312              : 
     313              : 
     314              : bool
     315           18 : Vehicle::isRouteValid(const std::string& vehID) {
     316           18 :     return Dom::getInt(libsumo::VAR_ROUTE_VALID, vehID) != 0;
     317              : }
     318              : 
     319              : 
     320              : std::vector<std::string>
     321         1045 : Vehicle::getRoute(const std::string& vehID) {
     322         1045 :     return Dom::getStringVector(libsumo::VAR_EDGES, vehID);
     323              : }
     324              : 
     325              : 
     326              : int
     327           18 : Vehicle::getSignals(const std::string& vehID) {
     328           18 :     return Dom::getInt(libsumo::VAR_SIGNALS, vehID);
     329              : }
     330              : 
     331              : 
     332              : std::vector<libsumo::TraCIBestLanesData>
     333           18 : Vehicle::getBestLanes(const std::string& vehID) {
     334           18 :     std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
     335              :     std::vector<libsumo::TraCIBestLanesData> result;
     336              :     tcpip::Storage& ret = Dom::get(libsumo::VAR_BEST_LANES, vehID);
     337           18 :     ret.readInt();
     338           36 :     StoHelp::readBestLanesVector(ret, result);
     339           18 :     return result;
     340            0 : }
     341              : 
     342              : 
     343              : std::vector<libsumo::TraCINextTLSData>
     344          276 : Vehicle::getNextTLS(const std::string& vehID) {
     345          276 :     std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
     346              :     std::vector<libsumo::TraCINextTLSData> result;
     347              :     tcpip::Storage& ret = Dom::get(libsumo::VAR_NEXT_TLS, vehID);
     348          273 :     ret.readInt(); // components
     349          546 :     StoHelp::readTLSDataVector(ret, result);
     350          273 :     return result;
     351            3 : }
     352              : 
     353              : std::vector<libsumo::TraCINextStopData>
     354           26 : Vehicle::getNextStops(const std::string& vehID) {
     355           26 :     return getStops(vehID, 0);
     356              : }
     357              : 
     358              : std::vector<libsumo::TraCIConnection>
     359            1 : Vehicle::getNextLinks(const std::string& vehID) {
     360            1 :     std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
     361              :     std::vector<libsumo::TraCIConnection> result;
     362              :     tcpip::Storage& ret = Dom::get(libsumo::VAR_NEXT_LINKS, vehID);
     363            1 :     ret.readInt(); // components
     364              :     // number of items
     365            1 :     const int linkNo = StoHelp::readTypedInt(ret);
     366            3 :     for (int i = 0; i < linkNo; ++i) {
     367              :         libsumo::TraCIConnection con;
     368            2 :         StoHelp::readConnection(ret, con);
     369            2 :         result.emplace_back(con);
     370            2 :     }
     371            1 :     return result;
     372            0 : }
     373              : 
     374              : std::vector<libsumo::TraCINextStopData>
     375          734 : Vehicle::getStops(const std::string& vehID, int limit) {
     376              :     std::vector<libsumo::TraCINextStopData> result;
     377          734 :     tcpip::Storage content;
     378              :     StoHelp::writeTypedInt(content, limit);
     379          734 :     std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
     380              :     tcpip::Storage& ret = Dom::get(libsumo::VAR_NEXT_STOPS2, vehID, &content);
     381          733 :     ret.readInt(); // components
     382         1467 :     StoHelp::readStopVector(ret, result);
     383          733 :     return result;
     384          735 : }
     385              : 
     386              : std::string
     387           91 : Vehicle::getStopParameter(const std::string& vehID, int nextStopIndex, const std::string& param, bool customParam) {
     388           91 :     tcpip::Storage content;
     389              :     StoHelp::writeCompound(content, 3);
     390              :     StoHelp::writeTypedInt(content, nextStopIndex);
     391              :     StoHelp::writeTypedString(content, param);
     392           91 :     StoHelp::writeTypedByte(content, customParam);
     393          182 :     return Dom::getString(libsumo::VAR_STOP_PARAMETER, vehID, &content);
     394           91 : }
     395              : 
     396              : int
     397          346 : Vehicle::getStopState(const std::string& vehID) {
     398          346 :     return Dom::getInt(libsumo::VAR_STOPSTATE, vehID);
     399              : }
     400              : 
     401              : 
     402              : double
     403          128 : Vehicle::getDistance(const std::string& vehID) {
     404          128 :     return Dom::getDouble(libsumo::VAR_DISTANCE, vehID);
     405              : }
     406              : 
     407              : 
     408              : double
     409          683 : Vehicle::getDrivingDistance(const std::string& vehID, const std::string& edgeID, double pos, int laneIndex) {
     410          683 :     tcpip::Storage content;
     411              :     StoHelp::writeCompound(content, 2);
     412          683 :     content.writeUnsignedByte(libsumo::POSITION_ROADMAP);
     413          683 :     content.writeString(edgeID);
     414          683 :     content.writeDouble(pos);
     415          683 :     content.writeUnsignedByte(laneIndex);
     416          683 :     content.writeUnsignedByte(libsumo::REQUEST_DRIVINGDIST);
     417         1366 :     return Dom::getDouble(libsumo::DISTANCE_REQUEST, vehID, &content);
     418          683 : }
     419              : 
     420              : 
     421              : double
     422           18 : Vehicle::getDrivingDistance2D(const std::string& vehID, double x, double y) {
     423           18 :     tcpip::Storage content;
     424              :     StoHelp::writeCompound(content, 2);
     425           18 :     content.writeUnsignedByte(libsumo::POSITION_2D);
     426           18 :     content.writeDouble(x);
     427           18 :     content.writeDouble(y);
     428           18 :     content.writeUnsignedByte(libsumo::REQUEST_DRIVINGDIST);
     429           36 :     return Dom::getDouble(libsumo::DISTANCE_REQUEST, vehID, &content);
     430           18 : }
     431              : 
     432              : 
     433              : double
     434           18 : Vehicle::getReferenceDistance(const std::string& vehID) {
     435           18 :     return Dom::getDouble(libsumo::VAR_REFERENCE_DISTANCE, vehID);
     436              : }
     437              : 
     438              : 
     439              : double
     440           18 : Vehicle::getAllowedSpeed(const std::string& vehID) {
     441           18 :     return Dom::getDouble(libsumo::VAR_ALLOWED_SPEED, vehID);
     442              : }
     443              : 
     444              : 
     445              : double
     446           49 : Vehicle::getSpeedFactor(const std::string& vehID) {
     447           49 :     return Dom::getDouble(libsumo::VAR_SPEED_FACTOR, vehID);
     448              : }
     449              : 
     450              : 
     451              : int
     452           15 : Vehicle::getSpeedMode(const std::string& vehID) {
     453           15 :     return Dom::getInt(libsumo::VAR_SPEEDSETMODE, vehID);
     454              : }
     455              : 
     456              : 
     457              : int
     458           15 : Vehicle::getLaneChangeMode(const std::string& vehID) {
     459           15 :     return Dom::getInt(libsumo::VAR_LANECHANGE_MODE, vehID);
     460              : }
     461              : 
     462              : 
     463              : int
     464           18 : Vehicle::getRoutingMode(const std::string& vehID) {
     465           18 :     return Dom::getInt(libsumo::VAR_ROUTING_MODE, vehID);
     466              : }
     467              : 
     468              : 
     469              : std::string
     470           18 : Vehicle::getLine(const std::string& vehID) {
     471           18 :     return Dom::getString(libsumo::VAR_LINE, vehID);
     472              : }
     473              : 
     474              : 
     475              : 
     476              : std::vector<std::string>
     477           18 : Vehicle::getVia(const std::string& vehID) {
     478           18 :     return Dom::getStringVector(libsumo::VAR_VIA, vehID);
     479              : }
     480              : 
     481              : 
     482              : std::pair<int, int>
     483         3493 : Vehicle::getLaneChangeState(const std::string& vehID, int direction) {
     484         3493 :     tcpip::Storage content;
     485              :     StoHelp::writeTypedInt(content, direction);
     486         3493 :     std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
     487              :     tcpip::Storage& ret = Dom::get(libsumo::CMD_CHANGELANE, vehID, &content);
     488         3493 :     ret.readInt(); // components
     489         3493 :     const int stateWithoutTraCI = StoHelp::readTypedInt(ret);
     490         6986 :     const int state = StoHelp::readTypedInt(ret);
     491         3493 :     return std::make_pair(stateWithoutTraCI, state);
     492         3493 : }
     493              : 
     494              : 
     495              : std::vector<std::pair<std::string, double> >
     496          856 : Vehicle::getNeighbors(const std::string& vehID, const int mode) {
     497              :     std::vector<std::pair<std::string, double> > neighs;
     498          856 :     tcpip::Storage content;
     499          856 :     content.writeUnsignedByte(libsumo::TYPE_UBYTE);
     500          856 :     content.writeUnsignedByte(mode);
     501          856 :     std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
     502              :     tcpip::Storage& ret = Dom::get(libsumo::VAR_NEIGHBORS, vehID, &content);
     503          856 :     const int items = ret.readInt(); // components
     504         1328 :     for (int i = 0; i < items; i++) {
     505          472 :         const std::string neighID = ret.readString();
     506          472 :         neighs.emplace_back(neighID, ret.readDouble());
     507              :     }
     508          856 :     return neighs;
     509          856 : }
     510              : 
     511              : 
     512              : double
     513          177 : Vehicle::getFollowSpeed(const std::string& vehID, double speed, double gap, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) {
     514          177 :     tcpip::Storage content;
     515              :     StoHelp::writeCompound(content, 5);
     516              :     StoHelp::writeTypedDouble(content, speed);
     517              :     StoHelp::writeTypedDouble(content, gap);
     518              :     StoHelp::writeTypedDouble(content, leaderSpeed);
     519              :     StoHelp::writeTypedDouble(content, leaderMaxDecel);
     520              :     StoHelp::writeTypedString(content, leaderID);
     521          354 :     return Dom::getDouble(libsumo::VAR_FOLLOW_SPEED, vehID, &content);
     522          177 : }
     523              : 
     524              : 
     525              : double
     526            2 : Vehicle::getSecureGap(const std::string& vehID, double speed, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID) {
     527            2 :     tcpip::Storage content;
     528              :     StoHelp::writeCompound(content, 4);
     529              :     StoHelp::writeTypedDouble(content, speed);
     530              :     StoHelp::writeTypedDouble(content, leaderSpeed);
     531              :     StoHelp::writeTypedDouble(content, leaderMaxDecel);
     532              :     StoHelp::writeTypedString(content, leaderID);
     533            4 :     return Dom::getDouble(libsumo::VAR_SECURE_GAP, vehID, &content);
     534            2 : }
     535              : 
     536              : 
     537              : double
     538            2 : Vehicle::getStopSpeed(const std::string& vehID, const double speed, double gap) {
     539            2 :     tcpip::Storage content;
     540              :     StoHelp::writeCompound(content, 2);
     541              :     StoHelp::writeTypedDouble(content, speed);
     542              :     StoHelp::writeTypedDouble(content, gap);
     543            4 :     return Dom::getDouble(libsumo::VAR_STOP_SPEED, vehID, &content);
     544            2 : }
     545              : 
     546              : double
     547          125 : Vehicle::getStopDelay(const std::string& vehID) {
     548          125 :     return Dom::getDouble(libsumo::VAR_STOP_DELAY, vehID);
     549              : }
     550              : 
     551              : double
     552          125 : Vehicle::getStopArrivalDelay(const std::string& vehID) {
     553          125 :     return Dom::getDouble(libsumo::VAR_STOP_ARRIVALDELAY, vehID);
     554              : }
     555              : 
     556              : double
     557           18 : Vehicle::getTimeLoss(const std::string& vehID) {
     558           18 :     return Dom::getDouble(libsumo::VAR_TIMELOSS, vehID);
     559              : }
     560              : 
     561              : std::vector<std::string>
     562         1962 : Vehicle::getTaxiFleet(int taxiState) {
     563         1962 :     tcpip::Storage content;
     564              :     StoHelp::writeTypedInt(content, taxiState);
     565         3924 :     return Dom::getStringVector(libsumo::VAR_TAXI_FLEET, "", &content);
     566         1962 : }
     567              : 
     568              : std::vector<std::string>
     569           46 : Vehicle::getLoadedIDList() {
     570           92 :     return Dom::getStringVector(libsumo::VAR_LOADED_LIST, "");
     571              : }
     572              : 
     573              : std::vector<std::string>
     574           36 : Vehicle::getTeleportingIDList() {
     575           72 :     return Dom::getStringVector(libsumo::VAR_TELEPORTING_LIST, "");
     576              : }
     577              : 
     578              : std::string
     579           38 : Vehicle::getEmissionClass(const std::string& vehID) {
     580           38 :     return Dom::getString(libsumo::VAR_EMISSIONCLASS, vehID);
     581              : }
     582              : 
     583              : std::string
     584           18 : Vehicle::getShapeClass(const std::string& vehID) {
     585           18 :     return Dom::getString(libsumo::VAR_SHAPECLASS, vehID);
     586              : }
     587              : 
     588              : 
     589              : double
     590           20 : Vehicle::getLength(const std::string& vehID) {
     591           20 :     return Dom::getDouble(libsumo::VAR_LENGTH, vehID);
     592              : }
     593              : 
     594              : 
     595              : double
     596           20 : Vehicle::getAccel(const std::string& vehID) {
     597           20 :     return Dom::getDouble(libsumo::VAR_ACCEL, vehID);
     598              : }
     599              : 
     600              : 
     601              : double
     602          201 : Vehicle::getDecel(const std::string& vehID) {
     603          201 :     return Dom::getDouble(libsumo::VAR_DECEL, vehID);
     604              : }
     605              : 
     606              : 
     607           22 : double Vehicle::getEmergencyDecel(const std::string& vehID) {
     608           22 :     return Dom::getDouble(libsumo::VAR_EMERGENCY_DECEL, vehID);
     609              : }
     610              : 
     611              : 
     612           20 : double Vehicle::getApparentDecel(const std::string& vehID) {
     613           20 :     return Dom::getDouble(libsumo::VAR_APPARENT_DECEL, vehID);
     614              : }
     615              : 
     616              : 
     617           20 : double Vehicle::getActionStepLength(const std::string& vehID) {
     618           20 :     return Dom::getDouble(libsumo::VAR_ACTIONSTEPLENGTH, vehID);
     619              : }
     620              : 
     621              : 
     622           18 : double Vehicle::getLastActionTime(const std::string& vehID) {
     623           18 :     return Dom::getDouble(libsumo::VAR_LASTACTIONTIME, vehID);
     624              : }
     625              : 
     626              : 
     627              : double
     628           20 : Vehicle::getTau(const std::string& vehID) {
     629           20 :     return Dom::getDouble(libsumo::VAR_TAU, vehID);
     630              : }
     631              : 
     632              : 
     633              : double
     634           22 : Vehicle::getImperfection(const std::string& vehID) {
     635           22 :     return Dom::getDouble(libsumo::VAR_IMPERFECTION, vehID);
     636              : }
     637              : 
     638              : 
     639              : double
     640           18 : Vehicle::getSpeedDeviation(const std::string& vehID) {
     641           18 :     return Dom::getDouble(libsumo::VAR_SPEED_DEVIATION, vehID);
     642              : }
     643              : 
     644              : 
     645              : std::string
     646           18 : Vehicle::getVehicleClass(const std::string& vehID) {
     647           18 :     return Dom::getString(libsumo::VAR_VEHICLECLASS, vehID);
     648              : }
     649              : 
     650              : 
     651              : double
     652           59 : Vehicle::getMinGap(const std::string& vehID) {
     653           59 :     return Dom::getDouble(libsumo::VAR_MINGAP, vehID);
     654              : }
     655              : 
     656              : 
     657              : double
     658           18 : Vehicle::getMinGapLat(const std::string& vehID) {
     659           18 :     return Dom::getDouble(libsumo::VAR_MINGAP_LAT, vehID);
     660              : }
     661              : 
     662              : 
     663              : double
     664           20 : Vehicle::getMaxSpeed(const std::string& vehID) {
     665           20 :     return Dom::getDouble(libsumo::VAR_MAXSPEED, vehID);
     666              : }
     667              : 
     668              : 
     669              : double
     670           18 : Vehicle::getMaxSpeedLat(const std::string& vehID) {
     671           18 :     return Dom::getDouble(libsumo::VAR_MAXSPEED_LAT, vehID);
     672              : }
     673              : 
     674              : 
     675              : std::string
     676           18 : Vehicle::getLateralAlignment(const std::string& vehID) {
     677           18 :     return Dom::getString(libsumo::VAR_LATALIGNMENT, vehID);
     678              : }
     679              : 
     680              : 
     681              : double
     682           20 : Vehicle::getWidth(const std::string& vehID) {
     683           20 :     return Dom::getDouble(libsumo::VAR_WIDTH, vehID);
     684              : }
     685              : 
     686              : 
     687              : double
     688           18 : Vehicle::getHeight(const std::string& vehID) {
     689           18 :     return Dom::getDouble(libsumo::VAR_HEIGHT, vehID);
     690              : }
     691              : 
     692              : 
     693              : double
     694           22 : Vehicle::getMass(const std::string& vehID) {
     695           22 :     return Dom::getDouble(libsumo::VAR_MASS, vehID);
     696              : }
     697              : 
     698              : 
     699              : void
     700           49 : Vehicle::setStop(const std::string& vehID,
     701              :                  const std::string& edgeID,
     702              :                  double pos,
     703              :                  int laneIndex,
     704              :                  double duration,
     705              :                  int flags,
     706              :                  double startPos,
     707              :                  double until) {
     708           49 :     tcpip::Storage content;
     709              :     StoHelp::writeCompound(content, 7);
     710              :     StoHelp::writeTypedString(content, edgeID);
     711              :     StoHelp::writeTypedDouble(content, pos);
     712              :     StoHelp::writeTypedByte(content, laneIndex);
     713              :     StoHelp::writeTypedDouble(content, duration);
     714              :     StoHelp::writeTypedByte(content, flags);
     715              :     StoHelp::writeTypedDouble(content, startPos);
     716              :     StoHelp::writeTypedDouble(content, until);
     717           49 :     Dom::set(libsumo::CMD_STOP, vehID, &content);
     718           49 : }
     719              : 
     720              : 
     721              : void
     722           43 : Vehicle::replaceStop(const std::string& vehID,
     723              :                      int nextStopIndex,
     724              :                      const std::string& edgeID,
     725              :                      double pos,
     726              :                      int laneIndex,
     727              :                      double duration,
     728              :                      int flags,
     729              :                      double startPos,
     730              :                      double until,
     731              :                      int teleport) {
     732           43 :     tcpip::Storage content;
     733              :     StoHelp::writeCompound(content, 9);
     734              :     StoHelp::writeTypedString(content, edgeID);
     735              :     StoHelp::writeTypedDouble(content, pos);
     736              :     StoHelp::writeTypedByte(content, laneIndex);
     737              :     StoHelp::writeTypedDouble(content, duration);
     738              :     StoHelp::writeTypedInt(content, flags);
     739              :     StoHelp::writeTypedDouble(content, startPos);
     740              :     StoHelp::writeTypedDouble(content, until);
     741              :     StoHelp::writeTypedInt(content, nextStopIndex);
     742              :     StoHelp::writeTypedByte(content, teleport);
     743           43 :     Dom::set(libsumo::CMD_REPLACE_STOP, vehID, &content);
     744           43 : }
     745              : 
     746              : 
     747              : void
     748           29 : Vehicle::insertStop(const std::string& vehID,
     749              :                     int nextStopIndex,
     750              :                     const std::string& edgeID,
     751              :                     double pos,
     752              :                     int laneIndex,
     753              :                     double duration,
     754              :                     int flags,
     755              :                     double startPos,
     756              :                     double until,
     757              :                     int teleport) {
     758           29 :     tcpip::Storage content;
     759              :     StoHelp::writeCompound(content, 9);
     760              :     StoHelp::writeTypedString(content, edgeID);
     761              :     StoHelp::writeTypedDouble(content, pos);
     762              :     StoHelp::writeTypedByte(content, laneIndex);
     763              :     StoHelp::writeTypedDouble(content, duration);
     764              :     StoHelp::writeTypedInt(content, flags);
     765              :     StoHelp::writeTypedDouble(content, startPos);
     766              :     StoHelp::writeTypedDouble(content, until);
     767              :     StoHelp::writeTypedInt(content, nextStopIndex);
     768              :     StoHelp::writeTypedByte(content, teleport);
     769           29 :     Dom::set(libsumo::CMD_INSERT_STOP, vehID, &content);
     770           29 : }
     771              : 
     772              : 
     773              : void
     774           38 : Vehicle::setStopParameter(const std::string& vehID, int nextStopIndex,
     775              :                           const std::string& param, const std::string& value,
     776              :                           bool customParam) {
     777           38 :     tcpip::Storage content;
     778              :     StoHelp::writeCompound(content, 4);
     779              :     StoHelp::writeTypedInt(content, nextStopIndex);
     780              :     StoHelp::writeTypedString(content, param);
     781              :     StoHelp::writeTypedString(content, value);
     782           38 :     StoHelp::writeTypedByte(content, customParam);
     783           38 :     Dom::set(libsumo::VAR_STOP_PARAMETER, vehID, &content);
     784           38 : }
     785              : 
     786              : 
     787              : void
     788            4 : Vehicle::rerouteParkingArea(const std::string& vehID, const std::string& parkingAreaID) {
     789            4 :     tcpip::Storage content;
     790              :     StoHelp::writeCompound(content, 1);
     791              :     StoHelp::writeTypedString(content, parkingAreaID);
     792            4 :     Dom::set(libsumo::CMD_REROUTE_TO_PARKING, vehID, &content);
     793            4 : }
     794              : 
     795              : 
     796              : void
     797            2 : Vehicle::resume(const std::string& vehID) {
     798            2 :     tcpip::Storage content;
     799              :     StoHelp::writeCompound(content, 0);
     800            2 :     Dom::set(libsumo::CMD_RESUME, vehID, &content);
     801            2 : }
     802              : 
     803              : 
     804              : void
     805            9 : Vehicle::changeTarget(const std::string& vehID, const std::string& edgeID) {
     806            9 :     Dom::setString(libsumo::CMD_CHANGETARGET, vehID, edgeID);
     807            7 : }
     808              : 
     809              : 
     810              : void
     811         2222 : Vehicle::changeLane(const std::string& vehID, int laneIndex, double duration) {
     812         2222 :     tcpip::Storage content;
     813              :     StoHelp::writeCompound(content, 2);
     814              :     StoHelp::writeTypedByte(content, laneIndex);
     815              :     StoHelp::writeTypedDouble(content, duration);
     816         2222 :     Dom::set(libsumo::CMD_CHANGELANE, vehID, &content);
     817         2222 : }
     818              : 
     819              : void
     820           55 : Vehicle::changeLaneRelative(const std::string& vehID, int indexOffset, double duration) {
     821           55 :     tcpip::Storage content;
     822              :     StoHelp::writeCompound(content, 3);
     823              :     StoHelp::writeTypedByte(content, indexOffset);
     824              :     StoHelp::writeTypedDouble(content, duration);
     825              :     StoHelp::writeTypedByte(content, 1);
     826           55 :     Dom::set(libsumo::CMD_CHANGELANE, vehID, &content);
     827           55 : }
     828              : 
     829              : 
     830              : void
     831           75 : Vehicle::changeSublane(const std::string& vehID, double latDist) {
     832           75 :     Dom::setDouble(libsumo::CMD_CHANGESUBLANE, vehID, latDist);
     833           75 : }
     834              : 
     835              : 
     836              : void
     837         7482 : Vehicle::add(const std::string& vehID,
     838              :              const std::string& routeID,
     839              :              const std::string& typeID,
     840              :              const std::string& depart,
     841              :              const std::string& departLane,
     842              :              const std::string& departPos,
     843              :              const std::string& departSpeed,
     844              :              const std::string& arrivalLane,
     845              :              const std::string& arrivalPos,
     846              :              const std::string& arrivalSpeed,
     847              :              const std::string& fromTaz,
     848              :              const std::string& toTaz,
     849              :              const std::string& line,
     850              :              int personCapacity,
     851              :              int personNumber) {
     852         7482 :     tcpip::Storage content;
     853              :     StoHelp::writeCompound(content, 14);
     854              :     StoHelp::writeTypedString(content, routeID);
     855              :     StoHelp::writeTypedString(content, typeID);
     856              :     StoHelp::writeTypedString(content, depart);
     857              :     StoHelp::writeTypedString(content, departLane);
     858              :     StoHelp::writeTypedString(content, departPos);
     859              :     StoHelp::writeTypedString(content, departSpeed);
     860              : 
     861              :     StoHelp::writeTypedString(content, arrivalLane);
     862              :     StoHelp::writeTypedString(content, arrivalPos);
     863              :     StoHelp::writeTypedString(content, arrivalSpeed);
     864              : 
     865              :     StoHelp::writeTypedString(content, fromTaz);
     866              :     StoHelp::writeTypedString(content, toTaz);
     867              :     StoHelp::writeTypedString(content, line);
     868              : 
     869              :     StoHelp::writeTypedInt(content, personCapacity);
     870              :     StoHelp::writeTypedInt(content, personNumber);
     871              : 
     872         7482 :     Dom::set(libsumo::ADD_FULL, vehID, &content);
     873         7482 : }
     874              : 
     875              : 
     876              : void
     877         1015 : Vehicle::moveToXY(const std::string& vehID, const std::string& edgeID, const int laneIndex,
     878              :                   const double x, const double y, double angle, const int keepRoute, double matchThreshold) {
     879         1015 :     tcpip::Storage content;
     880              :     StoHelp::writeCompound(content, 7);
     881              :     StoHelp::writeTypedString(content, edgeID);
     882              :     StoHelp::writeTypedInt(content, laneIndex);
     883              :     StoHelp::writeTypedDouble(content, x);
     884              :     StoHelp::writeTypedDouble(content, y);
     885              :     StoHelp::writeTypedDouble(content, angle);
     886              :     StoHelp::writeTypedByte(content, keepRoute);
     887              :     StoHelp::writeTypedDouble(content, matchThreshold);
     888         1015 :     Dom::set(libsumo::MOVE_TO_XY, vehID, &content);
     889         1015 : }
     890              : 
     891              : void
     892            8 : Vehicle::slowDown(const std::string& vehID, double speed, double duration) {
     893            8 :     tcpip::Storage content;
     894              :     StoHelp::writeCompound(content, 2);
     895              :     StoHelp::writeTypedDouble(content, speed);
     896              :     StoHelp::writeTypedDouble(content, duration);
     897            8 :     Dom::set(libsumo::CMD_SLOWDOWN, vehID, &content);
     898            8 : }
     899              : 
     900              : void
     901           17 : Vehicle::openGap(const std::string& vehID, double newTimeHeadway, double newSpaceHeadway, double duration, double changeRate, double maxDecel, const std::string& referenceVehID) {
     902           17 :     tcpip::Storage content;
     903           17 :     StoHelp::writeCompound(content, referenceVehID != "" ? 6 : 5);
     904              :     StoHelp::writeTypedDouble(content, newTimeHeadway);
     905              :     StoHelp::writeTypedDouble(content, newSpaceHeadway);
     906              :     StoHelp::writeTypedDouble(content, duration);
     907              :     StoHelp::writeTypedDouble(content, changeRate);
     908              :     StoHelp::writeTypedDouble(content, maxDecel);
     909           17 :     if (referenceVehID != "") {
     910              :         StoHelp::writeTypedString(content, referenceVehID);
     911              :     }
     912           17 :     Dom::set(libsumo::CMD_OPENGAP, vehID, &content);
     913           17 : }
     914              : 
     915              : void
     916            2 : Vehicle::deactivateGapControl(const std::string& vehID) {
     917            2 :     openGap(vehID, -1, -1, -1, -1);
     918            2 : }
     919              : 
     920              : void
     921            0 : Vehicle::requestToC(const std::string& vehID, double leadTime) {
     922            0 :     std::ostringstream oss;
     923              :     oss.setf(std::ios::fixed, std::ios::floatfield);
     924              :     oss << std::setprecision(2);
     925              :     oss << leadTime;
     926            0 :     setParameter(vehID, "device.toc.requestToC", oss.str());
     927            0 : }
     928              : 
     929              : void
     930          974 : Vehicle::setSpeed(const std::string& vehID, double speed) {
     931          974 :     Dom::setDouble(libsumo::VAR_SPEED, vehID, speed);
     932          974 : }
     933              : 
     934              : void
     935            3 : Vehicle::setAcceleration(const std::string& vehID, double acceleration, double duration) {
     936            3 :     tcpip::Storage content;
     937              :     StoHelp::writeCompound(content, 2);
     938              :     StoHelp::writeTypedDouble(content, acceleration);
     939              :     StoHelp::writeTypedDouble(content, duration);
     940            3 :     Dom::set(libsumo::VAR_ACCELERATION, vehID, &content);
     941            3 : }
     942              : 
     943              : void
     944           49 : Vehicle::setPreviousSpeed(const std::string& vehID, double prevSpeed, double prevAcceleration) {
     945           49 :     tcpip::Storage content;
     946              :     StoHelp::writeCompound(content, 2);
     947              :     StoHelp::writeTypedDouble(content, prevSpeed);
     948              :     StoHelp::writeTypedDouble(content, prevAcceleration);
     949           49 :     Dom::set(libsumo::VAR_PREV_SPEED, vehID, &content);
     950           49 : }
     951              : 
     952              : void
     953          762 : Vehicle::setSpeedMode(const std::string& vehID, int speedMode) {
     954          762 :     Dom::setInt(libsumo::VAR_SPEEDSETMODE, vehID, speedMode);
     955          762 : }
     956              : 
     957              : void
     958          108 : Vehicle::setLaneChangeMode(const std::string& vehID, int laneChangeMode) {
     959          108 :     Dom::setInt(libsumo::VAR_LANECHANGE_MODE, vehID, laneChangeMode);
     960          108 : }
     961              : 
     962              : void
     963           23 : Vehicle::setRoutingMode(const std::string& vehID, int routingMode) {
     964           23 :     Dom::setInt(libsumo::VAR_ROUTING_MODE, vehID, routingMode);
     965           23 : }
     966              : 
     967              : void
     968           74 : Vehicle::setType(const std::string& vehID, const std::string& typeID) {
     969           74 :     Dom::setString(libsumo::VAR_TYPE, vehID, typeID);
     970           74 : }
     971              : 
     972              : void
     973            5 : Vehicle::setRouteID(const std::string& vehID, const std::string& routeID) {
     974            5 :     Dom::setString(libsumo::VAR_ROUTE_ID, vehID, routeID);
     975            5 : }
     976              : 
     977              : void
     978            1 : Vehicle::setRoute(const std::string& vehID, const std::string& edgeID) {
     979            3 :     setRoute(vehID, std::vector<std::string>({edgeID}));
     980            0 : }
     981              : 
     982              : void
     983            7 : Vehicle::setRoute(const std::string& vehID, const std::vector<std::string>& edgeIDs) {
     984            7 :     Dom::setStringVector(libsumo::VAR_ROUTE, vehID, edgeIDs);
     985            6 : }
     986              : 
     987              : void
     988            2 : Vehicle::setLateralLanePosition(const std::string& vehID, double posLat) {
     989            2 :     Dom::setDouble(libsumo::VAR_LANEPOSITION_LAT, vehID, posLat);
     990            2 : }
     991              : 
     992              : void
     993           56 : Vehicle::updateBestLanes(const std::string& vehID) {
     994           56 :     tcpip::Storage content;
     995           56 :     Dom::set(libsumo::VAR_UPDATE_BESTLANES, vehID, &content);
     996           56 : }
     997              : 
     998              : 
     999              : void
    1000           39 : Vehicle::setAdaptedTraveltime(const std::string& vehID, const std::string& edgeID,
    1001              :                               double time, double begSeconds, double endSeconds) {
    1002           39 :     tcpip::Storage content;
    1003           39 :     if (time == libsumo::INVALID_DOUBLE_VALUE) {
    1004              :         // reset
    1005              :         StoHelp::writeCompound(content, 1);
    1006              :         StoHelp::writeTypedString(content, edgeID);
    1007           37 :     } else if (begSeconds == libsumo::INVALID_DOUBLE_VALUE) {
    1008              :         // set value for the whole simulation
    1009              :         StoHelp::writeCompound(content, 2);
    1010              :         StoHelp::writeTypedString(content, edgeID);
    1011              :         StoHelp::writeTypedDouble(content, time);
    1012              :     } else {
    1013              :         StoHelp::writeCompound(content, 4);
    1014              :         StoHelp::writeTypedDouble(content, begSeconds);
    1015              :         StoHelp::writeTypedDouble(content, endSeconds);
    1016              :         StoHelp::writeTypedString(content, edgeID);
    1017              :         StoHelp::writeTypedDouble(content, time);
    1018              :     }
    1019           39 :     Dom::set(libsumo::VAR_EDGE_TRAVELTIME, vehID, &content);
    1020           39 : }
    1021              : 
    1022              : 
    1023              : void
    1024            6 : Vehicle::setEffort(const std::string& vehID, const std::string& edgeID,
    1025              :                    double effort, double begSeconds, double endSeconds) {
    1026            6 :     tcpip::Storage content;
    1027            6 :     if (effort == libsumo::INVALID_DOUBLE_VALUE) {
    1028              :         // reset
    1029              :         StoHelp::writeCompound(content, 1);
    1030              :         StoHelp::writeTypedString(content, edgeID);
    1031            4 :     } else if (begSeconds == libsumo::INVALID_DOUBLE_VALUE) {
    1032              :         // set value for the whole simulation
    1033              :         StoHelp::writeCompound(content, 2);
    1034              :         StoHelp::writeTypedString(content, edgeID);
    1035              :         StoHelp::writeTypedDouble(content, effort);
    1036              :     } else {
    1037              :         StoHelp::writeCompound(content, 4);
    1038              :         StoHelp::writeTypedDouble(content, begSeconds);
    1039              :         StoHelp::writeTypedDouble(content, endSeconds);
    1040              :         StoHelp::writeTypedString(content, edgeID);
    1041              :         StoHelp::writeTypedDouble(content, effort);
    1042              :     }
    1043            6 :     Dom::set(libsumo::VAR_EDGE_EFFORT, vehID, &content);
    1044            6 : }
    1045              : 
    1046              : 
    1047              : void
    1048           73 : Vehicle::rerouteTraveltime(const std::string& vehID, const bool /* currentTravelTimes */) {
    1049           73 :     tcpip::Storage content;
    1050              :     StoHelp::writeCompound(content, 0);
    1051           73 :     Dom::set(libsumo::CMD_REROUTE_TRAVELTIME, vehID, &content);
    1052           73 : }
    1053              : 
    1054              : 
    1055              : void
    1056            2 : Vehicle::rerouteEffort(const std::string& vehID) {
    1057            2 :     tcpip::Storage content;
    1058              :     StoHelp::writeCompound(content, 0);
    1059            2 :     Dom::set(libsumo::CMD_REROUTE_EFFORT, vehID, &content);
    1060            2 : }
    1061              : 
    1062              : 
    1063              : void
    1064            4 : Vehicle::setSignals(const std::string& vehID, int signals) {
    1065            4 :     Dom::setInt(libsumo::VAR_SIGNALS, vehID, signals);
    1066            4 : }
    1067              : 
    1068              : 
    1069              : void
    1070          102 : Vehicle::moveTo(const std::string& vehID, const std::string& laneID, double pos, int reason) {
    1071          102 :     tcpip::Storage content;
    1072              :     StoHelp::writeCompound(content, 3);
    1073              :     StoHelp::writeTypedString(content, laneID);
    1074              :     StoHelp::writeTypedDouble(content, pos);
    1075              :     StoHelp::writeTypedInt(content, reason);
    1076          102 :     Dom::set(libsumo::VAR_MOVE_TO, vehID, &content);
    1077          102 : }
    1078              : 
    1079              : 
    1080              : void
    1081            4 : Vehicle::setActionStepLength(const std::string& vehID, double actionStepLength, bool resetActionOffset) {
    1082              :     //if (actionStepLength < 0) {
    1083              :     //    raise TraCIException("Invalid value for actionStepLength. Given value must be non-negative.")
    1084              :     //{
    1085              :     // Use negative value to indicate resetActionOffset == False
    1086            4 :     if (!resetActionOffset) {
    1087            2 :         actionStepLength *= -1;
    1088              :     }
    1089            4 :     Dom::setDouble(libsumo::VAR_ACTIONSTEPLENGTH, vehID, actionStepLength);
    1090            4 : }
    1091              : 
    1092              : 
    1093              : void
    1094            4 : Vehicle::remove(const std::string& vehID, char reason) {
    1095            4 :     tcpip::Storage content;
    1096            4 :     content.writeUnsignedByte(libsumo::TYPE_BYTE);
    1097            4 :     content.writeUnsignedByte(reason);
    1098            4 :     Dom::set(libsumo::REMOVE, vehID, &content);
    1099            4 : }
    1100              : 
    1101              : 
    1102              : void
    1103           44 : Vehicle::setColor(const std::string& vehID, const libsumo::TraCIColor& color) {
    1104           44 :     Dom::setCol(libsumo::VAR_COLOR, vehID, color);
    1105           44 : }
    1106              : 
    1107              : 
    1108              : void
    1109         2048 : Vehicle::setSpeedFactor(const std::string& vehID, double factor) {
    1110         2048 :     Dom::setDouble(libsumo::VAR_SPEED_FACTOR, vehID, factor);
    1111         2048 : }
    1112              : 
    1113              : 
    1114              : void
    1115            3 : Vehicle::setLine(const std::string& vehID, const std::string& line) {
    1116            3 :     Dom::setString(libsumo::VAR_LINE, vehID, line);
    1117            3 : }
    1118              : 
    1119              : 
    1120              : void
    1121            4 : Vehicle::setVia(const std::string& vehID, const std::vector<std::string>& edgeList) {
    1122            4 :     Dom::setStringVector(libsumo::VAR_VIA, vehID, edgeList);
    1123            4 : }
    1124              : 
    1125              : 
    1126              : void
    1127           23 : Vehicle::setLength(const std::string& vehID, double length) {
    1128           23 :     Dom::setDouble(libsumo::VAR_LENGTH, vehID, length);
    1129           23 : }
    1130              : 
    1131              : 
    1132              : void
    1133            9 : Vehicle::setMaxSpeed(const std::string& vehID, double speed) {
    1134            9 :     Dom::setDouble(libsumo::VAR_MAXSPEED, vehID, speed);
    1135            9 : }
    1136              : 
    1137              : 
    1138              : void
    1139            2 : Vehicle::setVehicleClass(const std::string& vehID, const std::string& clazz) {
    1140            2 :     Dom::setString(libsumo::VAR_VEHICLECLASS, vehID, clazz);
    1141            2 : }
    1142              : 
    1143              : 
    1144              : void
    1145            2 : Vehicle::setShapeClass(const std::string& vehID, const std::string& clazz) {
    1146            2 :     Dom::setString(libsumo::VAR_SHAPECLASS, vehID, clazz);
    1147            2 : }
    1148              : 
    1149              : 
    1150              : void
    1151            5 : Vehicle::setEmissionClass(const std::string& vehID, const std::string& clazz) {
    1152            5 :     Dom::setString(libsumo::VAR_EMISSIONCLASS, vehID, clazz);
    1153            5 : }
    1154              : 
    1155              : 
    1156              : void
    1157            3 : Vehicle::setWidth(const std::string& vehID, double width) {
    1158            3 :     Dom::setDouble(libsumo::VAR_WIDTH, vehID, width);
    1159            3 : }
    1160              : 
    1161              : 
    1162              : void
    1163            2 : Vehicle::setHeight(const std::string& vehID, double height) {
    1164            2 :     Dom::setDouble(libsumo::VAR_HEIGHT, vehID, height);
    1165            2 : }
    1166              : 
    1167              : 
    1168              : void
    1169            2 : Vehicle::setMass(const std::string& vehID, double mass) {
    1170            2 :     Dom::setDouble(libsumo::VAR_MASS, vehID, mass);
    1171            2 : }
    1172              : 
    1173              : 
    1174              : void
    1175            3 : Vehicle::setMinGap(const std::string& vehID, double minGap) {
    1176            3 :     Dom::setDouble(libsumo::VAR_MINGAP, vehID, minGap);
    1177            3 : }
    1178              : 
    1179              : 
    1180              : void
    1181            5 : Vehicle::setAccel(const std::string& vehID, double accel) {
    1182            5 :     Dom::setDouble(libsumo::VAR_ACCEL, vehID, accel);
    1183            5 : }
    1184              : 
    1185              : 
    1186              : void
    1187            3 : Vehicle::setDecel(const std::string& vehID, double decel) {
    1188            3 :     Dom::setDouble(libsumo::VAR_DECEL, vehID, decel);
    1189            3 : }
    1190              : 
    1191              : 
    1192              : void
    1193            5 : Vehicle::setEmergencyDecel(const std::string& vehID, double decel) {
    1194            5 :     Dom::setDouble(libsumo::VAR_EMERGENCY_DECEL, vehID, decel);
    1195            5 : }
    1196              : 
    1197              : 
    1198              : void
    1199            3 : Vehicle::setApparentDecel(const std::string& vehID, double decel) {
    1200            3 :     Dom::setDouble(libsumo::VAR_APPARENT_DECEL, vehID, decel);
    1201            3 : }
    1202              : 
    1203              : 
    1204              : void
    1205            5 : Vehicle::setImperfection(const std::string& vehID, double imperfection) {
    1206            5 :     Dom::setDouble(libsumo::VAR_IMPERFECTION, vehID, imperfection);
    1207            5 : }
    1208              : 
    1209              : 
    1210              : void
    1211            3 : Vehicle::setTau(const std::string& vehID, double tau) {
    1212            3 :     Dom::setDouble(libsumo::VAR_TAU, vehID, tau);
    1213            3 : }
    1214              : 
    1215              : 
    1216              : void
    1217            2 : Vehicle::setMinGapLat(const std::string& vehID, double minGapLat) {
    1218            2 :     Dom::setDouble(libsumo::VAR_MINGAP_LAT, vehID, minGapLat);
    1219            2 : }
    1220              : 
    1221              : 
    1222              : void
    1223            2 : Vehicle::setMaxSpeedLat(const std::string& vehID, double speed) {
    1224            2 :     Dom::setDouble(libsumo::VAR_MAXSPEED_LAT, vehID, speed);
    1225            2 : }
    1226              : 
    1227              : 
    1228              : void
    1229            2 : Vehicle::setLateralAlignment(const std::string& vehID, const std::string& latAlignment) {
    1230            2 :     Dom::setString(libsumo::VAR_LATALIGNMENT, vehID, latAlignment);
    1231            2 : }
    1232              : 
    1233              : 
    1234              : void
    1235            6 : Vehicle::setImpatience(const std::string& vehID, double impatience) {
    1236            6 :     Dom::setDouble(libsumo::VAR_IMPATIENCE, vehID, impatience);
    1237            6 : }
    1238              : 
    1239              : void
    1240            2 : Vehicle::setBoardingDuration(const std::string& vehID, double boardingDuration) {
    1241            2 :     Dom::setDouble(libsumo::VAR_BOARDING_DURATION, vehID, boardingDuration);
    1242            2 : }
    1243              : 
    1244              : 
    1245              : void
    1246           10 : Vehicle::highlight(const std::string& vehID, const libsumo::TraCIColor& col, double size, const int alphaMax, const double duration, const int type) {
    1247           10 :     tcpip::Storage content;
    1248           10 :     StoHelp::writeCompound(content, alphaMax > 0 ? 5 : 2);
    1249           10 :     content.writeUnsignedByte(libsumo::TYPE_COLOR);
    1250           10 :     content.writeUnsignedByte(col.r);
    1251           10 :     content.writeUnsignedByte(col.g);
    1252           10 :     content.writeUnsignedByte(col.b);
    1253           10 :     content.writeUnsignedByte(col.a);
    1254              :     StoHelp::writeTypedDouble(content, size);
    1255           10 :     if (alphaMax > 0) {
    1256            6 :         content.writeUnsignedByte(libsumo::TYPE_UBYTE);
    1257            6 :         content.writeUnsignedByte(alphaMax);
    1258              :         StoHelp::writeTypedDouble(content, duration);
    1259            6 :         content.writeUnsignedByte(libsumo::TYPE_UBYTE);
    1260            6 :         content.writeUnsignedByte(type);
    1261              :     }
    1262           10 :     Dom::set(libsumo::VAR_HIGHLIGHT, vehID, &content);
    1263           10 : }
    1264              : 
    1265              : void
    1266           36 : Vehicle::dispatchTaxi(const std::string& vehID,  const std::vector<std::string>& reservations) {
    1267           36 :     Dom::setStringVector(libsumo::CMD_TAXI_DISPATCH, vehID, reservations);
    1268           31 : }
    1269              : 
    1270              : 
    1271              : void
    1272           17 : Vehicle::subscribeLeader(const std::string& vehID, double dist, double begin, double end) {
    1273           17 :     subscribe(vehID, std::vector<int>({ libsumo::VAR_LEADER }), begin, end,
    1274           51 :     libsumo::TraCIResults({ {libsumo::VAR_LEADER, std::make_shared<libsumo::TraCIDouble>(dist)} }));
    1275           17 : }
    1276              : 
    1277              : 
    1278              : void
    1279           43 : Vehicle::addSubscriptionFilterLanes(const std::vector<int>& lanes, bool noOpposite, double downstreamDist, double upstreamDist) {
    1280           43 :     tcpip::Storage content;
    1281           43 :     content.writeUnsignedByte((int)lanes.size());
    1282          115 :     for (int lane : lanes) {
    1283           72 :         content.writeUnsignedByte(lane < 0 ? lane + 256 : lane);
    1284              :     }
    1285           43 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_LANES, &content);
    1286           43 :     if (noOpposite) {
    1287            1 :         addSubscriptionFilterNoOpposite();
    1288              :     }
    1289           43 :     if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
    1290            2 :         addSubscriptionFilterDownstreamDistance(downstreamDist);
    1291              :     }
    1292           43 :     if (upstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
    1293            2 :         addSubscriptionFilterUpstreamDistance(upstreamDist);
    1294              :     }
    1295           43 : }
    1296              : 
    1297              : 
    1298              : void
    1299           14 : Vehicle::addSubscriptionFilterNoOpposite() {
    1300           14 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_NOOPPOSITE);
    1301           14 : }
    1302              : 
    1303              : 
    1304              : void
    1305           51 : Vehicle::addSubscriptionFilterDownstreamDistance(double dist) {
    1306           51 :     tcpip::Storage content;
    1307              :     StoHelp::writeTypedDouble(content, dist);
    1308           51 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_DOWNSTREAM_DIST, &content);
    1309           51 : }
    1310              : 
    1311              : 
    1312              : void
    1313           43 : Vehicle::addSubscriptionFilterUpstreamDistance(double dist) {
    1314           43 :     tcpip::Storage content;
    1315              :     StoHelp::writeTypedDouble(content, dist);
    1316           43 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_UPSTREAM_DIST, &content);
    1317           43 : }
    1318              : 
    1319              : 
    1320              : void
    1321            1 : Vehicle::addSubscriptionFilterCFManeuver(double downstreamDist, double upstreamDist) {
    1322            1 :     addSubscriptionFilterLeadFollow(std::vector<int>(1));
    1323            1 :     if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
    1324            0 :         addSubscriptionFilterDownstreamDistance(downstreamDist);
    1325              :     }
    1326            1 :     if (upstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
    1327            0 :         addSubscriptionFilterUpstreamDistance(upstreamDist);
    1328              :     }
    1329            1 : }
    1330              : 
    1331              : 
    1332              : void
    1333            4 : Vehicle::addSubscriptionFilterLCManeuver(int direction, bool noOpposite, double downstreamDist, double upstreamDist) {
    1334            4 :     if (direction == libsumo::INVALID_INT_VALUE) {
    1335            1 :         addSubscriptionFilterLeadFollow({ -1, 0, 1 });
    1336            3 :     } else if (direction != -1 && direction != 1) {
    1337              :         // warnings.warn("Ignoring lane change subscription filter with non-neighboring lane offset direction=%s." % direction)
    1338              :         return;
    1339              :     } else {
    1340            3 :         addSubscriptionFilterLeadFollow({ 0, direction });
    1341              :     }
    1342            4 :     if (noOpposite) {
    1343            0 :         addSubscriptionFilterNoOpposite();
    1344              :     }
    1345            4 :     if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
    1346            0 :         addSubscriptionFilterDownstreamDistance(downstreamDist);
    1347              :     }
    1348            4 :     if (upstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
    1349            0 :         addSubscriptionFilterUpstreamDistance(upstreamDist);
    1350              :     }
    1351              : }
    1352              : 
    1353              : 
    1354              : void
    1355            5 : Vehicle::addSubscriptionFilterLeadFollow(const std::vector<int>& lanes) {
    1356            5 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_LEAD_FOLLOW);
    1357            5 :     addSubscriptionFilterLanes(lanes);
    1358            5 : }
    1359              : 
    1360              : 
    1361              : void
    1362            8 : Vehicle::addSubscriptionFilterTurn(double downstreamDist, double foeDistToJunction) {
    1363            8 :     tcpip::Storage content;
    1364              :     StoHelp::writeTypedDouble(content, foeDistToJunction);
    1365            8 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_TURN, &content);
    1366            8 :     if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
    1367            8 :         addSubscriptionFilterDownstreamDistance(downstreamDist);
    1368              :     }
    1369            8 : }
    1370              : 
    1371              : 
    1372              : void
    1373            3 : Vehicle::addSubscriptionFilterVClass(const std::vector<std::string>& vClasses) {
    1374            3 :     tcpip::Storage content;
    1375              :     StoHelp::writeTypedStringList(content, vClasses);
    1376            3 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_VCLASS, &content);
    1377            3 : }
    1378              : 
    1379              : 
    1380              : void
    1381            3 : Vehicle::addSubscriptionFilterVType(const std::vector<std::string>& vTypes) {
    1382            3 :     tcpip::Storage content;
    1383              :     StoHelp::writeTypedStringList(content, vTypes);
    1384            3 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_VTYPE, &content);
    1385            3 : }
    1386              : 
    1387              : 
    1388              : void
    1389            8 : Vehicle::addSubscriptionFilterFieldOfVision(double openingAngle) {
    1390            8 :     tcpip::Storage content;
    1391              :     StoHelp::writeTypedDouble(content, openingAngle);
    1392            8 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_FIELD_OF_VISION, &content);
    1393            8 : }
    1394              : 
    1395              : 
    1396              : void
    1397            8 : Vehicle::addSubscriptionFilterLateralDistance(double lateralDist, double downstreamDist, double upstreamDist) {
    1398            8 :     tcpip::Storage content;
    1399              :     StoHelp::writeTypedDouble(content, lateralDist);
    1400            8 :     libtraci::Connection::getActive().addFilter(libsumo::FILTER_TYPE_LATERAL_DIST, &content);
    1401            7 :     if (downstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
    1402            7 :         addSubscriptionFilterDownstreamDistance(downstreamDist);
    1403              :     }
    1404            7 :     if (upstreamDist != libsumo::INVALID_DOUBLE_VALUE) {
    1405            7 :         addSubscriptionFilterUpstreamDistance(upstreamDist);
    1406              :     }
    1407            8 : }
    1408              : 
    1409              : 
    1410              : }
    1411              : 
    1412              : 
    1413              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1