LCOV - code coverage report
Current view: top level - src/utils/traci - TraCIAPI.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 95.7 % 47 45
Test Date: 2024-12-21 15:45:41 Functions: 7.9 % 38 3

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2012-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    TraCIAPI.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Mario Krumnow
      17              : /// @author  Michael Behrisch
      18              : /// @date    30.05.2012
      19              : ///
      20              : // C++ TraCI client API implementation
      21              : /****************************************************************************/
      22              : #pragma once
      23              : #include <config.h>
      24              : #include <vector>
      25              : #include <limits>
      26              : #include <string>
      27              : #include <sstream>
      28              : #include <iomanip>
      29              : #include <foreign/tcpip/socket.h>
      30              : #include <libsumo/TraCIConstants.h>
      31              : #include <libsumo/TraCIDefs.h>
      32              : 
      33              : // ===========================================================================
      34              : // global definitions
      35              : // ===========================================================================
      36              : #define DEFAULT_VIEW "View #0"
      37              : #define PRECISION 2
      38              : 
      39              : // ===========================================================================
      40              : // class definitions
      41              : // ===========================================================================
      42              : /**
      43              :  * @class TraCIAPI
      44              :  * @brief C++ TraCI client API implementation
      45              :  */
      46              : 
      47              : 
      48              : class TraCIAPI {
      49              : public:
      50              :     /** @brief Constructor
      51              :      */
      52              :     TraCIAPI();
      53              : 
      54              :     /// @brief Destructor
      55              :     ~TraCIAPI();
      56              : 
      57              :     /// @name Connection handling
      58              :     /// @{
      59              : 
      60              :     /** @brief Connects to the specified SUMO server
      61              :      * @param[in] host The name of the host to connect to
      62              :      * @param[in] port The port to connect to
      63              :      * @exception tcpip::SocketException if the connection fails
      64              :      */
      65              :     void connect(const std::string& host, int port);
      66              : 
      67              :     /// @brief set priority (execution order) for the client
      68              :     void setOrder(int order);
      69              : 
      70              :     /// @brief ends the simulation and closes the connection
      71              :     void close();
      72              :     /// @}
      73              : 
      74              :     /// @brief Advances by one step (or up to the given time)
      75              :     void simulationStep(double time = 0);
      76              : 
      77              :     /// @brief Let sumo load a simulation using the given command line like options.
      78              :     void load(const std::vector<std::string>& args);
      79              : 
      80              :     /// @brief return TraCI API and SUMO version
      81              :     std::pair<int, std::string> getVersion();
      82              : 
      83              :     /** @class TraCIScopeWrapper
      84              :      * @brief An abstract interface for accessing type-dependent values
      85              :      *
      86              :      * Must be derived by interfaces which implement access methods to certain object types
      87              :      */
      88              :     class TraCIScopeWrapper {
      89              :     public:
      90              :         /** @brief Constructor
      91              :          * @param[in] parent The parent TraCI client which offers the connection
      92              :          */
      93         1248 :         TraCIScopeWrapper(TraCIAPI& parent, int cmdGetID, int cmdSetID, int subscribeID, int contextSubscribeID) :
      94         1248 :             myParent(parent),
      95         1248 :             myCmdGetID(cmdGetID),
      96         1248 :             myCmdSetID(cmdSetID),
      97         1248 :             mySubscribeID(subscribeID),
      98         1248 :             myContextSubscribeID(contextSubscribeID) {
      99              :         }
     100              : 
     101              :         /// @brief Destructor
     102        21216 :         virtual ~TraCIScopeWrapper() {}
     103              : 
     104              :         std::vector<std::string> getIDList() const;
     105              :         int getIDCount() const;
     106              : 
     107              :         /// @brief retrieve generic parameter
     108              :         std::string getParameter(const std::string& objectID, const std::string& key) const;
     109              : 
     110              :         /// @brief retrieve generic parameter and return (key, value) tuple
     111              :         std::pair<std::string, std::string> getParameterWithKey(const std::string& objectID, const std::string& key) const;
     112              : 
     113              :         /// @brief set generic paramter
     114              :         void setParameter(const std::string& objectID, const std::string& key, const std::string& value) const;
     115              : 
     116              :         void subscribe(const std::string& objID, const std::vector<int>& vars, double beginTime, double endTime) const;
     117              :         void subscribeContext(const std::string& objID, int domain, double range, const std::vector<int>& vars, double beginTime, double endTime) const;
     118              : 
     119              :         const libsumo::SubscriptionResults getAllSubscriptionResults() const;
     120              :         const libsumo::TraCIResults getSubscriptionResults(const std::string& objID) const;
     121              : 
     122              :         const libsumo::ContextSubscriptionResults getAllContextSubscriptionResults() const;
     123              :         const libsumo::SubscriptionResults getContextSubscriptionResults(const std::string& objID) const;
     124              : 
     125              :         // the following are only for internal use
     126              :         void clearSubscriptionResults();
     127              :         libsumo::SubscriptionResults& getModifiableSubscriptionResults();
     128              :         libsumo::SubscriptionResults& getModifiableContextSubscriptionResults(const std::string& objID);
     129              : 
     130              :     protected:
     131              :         int getUnsignedByte(int var, const std::string& id, tcpip::Storage* add = 0) const;
     132              :         int getByte(int var, const std::string& id, tcpip::Storage* add = 0) const;
     133              :         int getInt(int var, const std::string& id, tcpip::Storage* add = 0) const;
     134              :         double getDouble(int var, const std::string& id, tcpip::Storage* add = 0) const;
     135              :         libsumo::TraCIPositionVector getPolygon(int var, const std::string& id, tcpip::Storage* add = 0) const;
     136              :         libsumo::TraCIPosition getPos(int var, const std::string& id, tcpip::Storage* add = 0) const;
     137              :         libsumo::TraCIPosition getPos3D(int var, const std::string& id, tcpip::Storage* add = 0) const;
     138              :         std::string getString(int var, const std::string& id, tcpip::Storage* add = 0) const;
     139              :         std::vector<std::string> getStringVector(int var, const std::string& id, tcpip::Storage* add = 0) const;
     140              :         std::vector<double> getDoubleVector(int var, const std::string& id, tcpip::Storage* add = 0) const;
     141              :         libsumo::TraCIColor getCol(int var, const std::string& id, tcpip::Storage* add = 0) const;
     142              :         libsumo::TraCIStage getTraCIStage(int var, const std::string& id, tcpip::Storage* add = 0) const;
     143              : 
     144              :         void setInt(int var, const std::string& id, int value) const;
     145              :         void setDouble(int var, const std::string& id, double value) const;
     146              :         void setString(int var, const std::string& id, const std::string& value) const;
     147              :         void setStringVector(int var, const std::string& id, const std::vector<std::string>& value) const;
     148              : 
     149              :     protected:
     150              :         /// @brief The parent TraCI client which offers the connection
     151              :         TraCIAPI& myParent;
     152              : 
     153              :     private:
     154              :         int myCmdGetID;
     155              :         int myCmdSetID;
     156              :         int mySubscribeID;
     157              :         int myContextSubscribeID;
     158              :         libsumo::SubscriptionResults mySubscriptionResults;
     159              :         libsumo::ContextSubscriptionResults myContextSubscriptionResults;
     160              : 
     161              : 
     162              :     private:
     163              :         /// @brief invalidated assignment operator
     164              :         TraCIScopeWrapper& operator=(const TraCIScopeWrapper& src) = delete;
     165              :     };
     166              : 
     167              : 
     168              :     /** @class EdgeScope
     169              :      * @brief Scope for interaction with edges
     170              :      */
     171              :     class EdgeScope : public TraCIScopeWrapper {
     172              :     public:
     173         1248 :         EdgeScope(TraCIAPI& parent) : TraCIScopeWrapper(parent, libsumo::CMD_GET_EDGE_VARIABLE, libsumo::CMD_SET_EDGE_VARIABLE, libsumo::CMD_SUBSCRIBE_EDGE_VARIABLE, libsumo::CMD_SUBSCRIBE_EDGE_CONTEXT) {}
     174            0 :         virtual ~EdgeScope() {}
     175              : 
     176              :         double getAdaptedTraveltime(const std::string& edgeID, double time) const;
     177              :         double getEffort(const std::string& edgeID, double time) const;
     178              :         double getCO2Emission(const std::string& edgeID) const;
     179              :         double getCOEmission(const std::string& edgeID) const;
     180              :         double getHCEmission(const std::string& edgeID) const;
     181              :         double getPMxEmission(const std::string& edgeID) const;
     182              :         double getNOxEmission(const std::string& edgeID) const;
     183              :         double getFuelConsumption(const std::string& edgeID) const;
     184              :         double getNoiseEmission(const std::string& edgeID) const;
     185              :         double getElectricityConsumption(const std::string& edgeID) const;
     186              :         double getLastStepMeanSpeed(const std::string& edgeID) const;
     187              :         double getLastStepOccupancy(const std::string& edgeID) const;
     188              :         double getLastStepLength(const std::string& edgeID) const;
     189              :         double getTraveltime(const std::string& edgeID) const;
     190              :         int getLastStepVehicleNumber(const std::string& edgeID) const;
     191              :         double getLastStepHaltingNumber(const std::string& edgeID) const;
     192              :         std::vector<std::string> getLastStepVehicleIDs(const std::string& edgeID) const;
     193              :         int getLaneNumber(const std::string& edgeID) const;
     194              :         std::string getStreetName(const std::string& id) const;
     195              : 
     196              :         void adaptTraveltime(const std::string& edgeID, double time, double beginSeconds = 0., double endSeconds = std::numeric_limits<double>::max()) const;
     197              :         void setEffort(const std::string& edgeID, double effort, double beginSeconds = 0., double endSeconds = std::numeric_limits<double>::max()) const;
     198              :         void setMaxSpeed(const std::string& edgeID, double speed) const;
     199              :     };
     200              : 
     201              : 
     202              :     /** @class GUIScope
     203              :      * @brief Scope for interaction with the gui
     204              :      */
     205              :     class GUIScope : public TraCIScopeWrapper {
     206              :     public:
     207         1248 :         GUIScope(TraCIAPI& parent) : TraCIScopeWrapper(parent, libsumo::CMD_GET_GUI_VARIABLE, libsumo::CMD_SET_GUI_VARIABLE, libsumo::CMD_SUBSCRIBE_GUI_VARIABLE, libsumo::CMD_SUBSCRIBE_GUI_CONTEXT) {}
     208         1248 :         virtual ~GUIScope() {}
     209              : 
     210              :         double getZoom(const std::string& viewID = DEFAULT_VIEW) const;
     211              :         libsumo::TraCIPosition getOffset(const std::string& viewID = DEFAULT_VIEW) const;
     212              :         std::string getSchema(const std::string& viewID = DEFAULT_VIEW) const;
     213              :         libsumo::TraCIPositionVector getBoundary(const std::string& viewID = DEFAULT_VIEW) const;
     214              :         void setZoom(const std::string& viewID, double zoom) const;
     215              :         void setOffset(const std::string& viewID, double x, double y) const;
     216              :         void setSchema(const std::string& viewID, const std::string& schemeName) const;
     217              :         void setBoundary(const std::string& viewID, double xmin, double ymin, double xmax, double ymax) const;
     218              :         void screenshot(const std::string& viewID, const std::string& filename, const int width = -1, const int height = -1) const;
     219              :         void trackVehicle(const std::string& viewID, const std::string& vehID) const;
     220              :     };
     221              : 
     222              : 
     223              :     /** @class InductionLoopScope
     224              :      * @brief Scope for interaction with inductive loops
     225              :      */
     226              :     class InductionLoopScope : public TraCIScopeWrapper {
     227              :     public:
     228         1248 :         InductionLoopScope(TraCIAPI& parent) : TraCIScopeWrapper(parent, libsumo::CMD_GET_INDUCTIONLOOP_VARIABLE, -1, libsumo::CMD_SUBSCRIBE_INDUCTIONLOOP_VARIABLE, libsumo::CMD_SUBSCRIBE_INDUCTIONLOOP_CONTEXT) {}
     229         1248 :         virtual ~InductionLoopScope() {}
     230              : 
     231              :         /**
     232              :          * @param loopID The ID of the Induction Loop
     233              :          * @return the number of vehicles that passed the detector during the current interval
     234              :          */
     235              :         int getIntervalVehicleNumber(const std::string& loopID) const;
     236              :         double  getPosition(const std::string& loopID) const;
     237              :         std::string getLaneID(const std::string& loopID) const;
     238              :         int getLastStepVehicleNumber(const std::string& loopID) const;
     239              :         double getLastStepMeanSpeed(const std::string& loopID) const;
     240              :         std::vector<std::string> getLastStepVehicleIDs(const std::string& loopID) const;
     241              :         double getLastStepOccupancy(const std::string& loopID) const;
     242              :         double getLastStepMeanLength(const std::string& loopID) const;
     243              :         double getTimeSinceDetection(const std::string& loopID) const;
     244              :         std::vector<libsumo::TraCIVehicleData> getVehicleData(const std::string& loopID) const;
     245              :     };
     246              : 
     247              : 
     248              :     /** @class JunctionScope
     249              :      * @brief Scope for interaction with junctions
     250              :      */
     251              :     class JunctionScope : public TraCIScopeWrapper {
     252              :     public:
     253         1248 :         JunctionScope(TraCIAPI& parent) : TraCIScopeWrapper(parent, libsumo::CMD_GET_JUNCTION_VARIABLE, libsumo::CMD_SET_JUNCTION_VARIABLE, libsumo::CMD_SUBSCRIBE_JUNCTION_VARIABLE, libsumo::CMD_SUBSCRIBE_JUNCTION_CONTEXT) {}
     254         1248 :         virtual ~JunctionScope() {}
     255              : 
     256              :         libsumo::TraCIPosition getPosition(const std::string& junctionID) const;
     257              :         libsumo::TraCIPositionVector getShape(const std::string& junctionID) const;
     258              :     };
     259              : 
     260              : 
     261              :     /** @class LaneScope
     262              :      * @brief Scope for interaction with lanes
     263              :      */
     264              :     class LaneScope : public TraCIScopeWrapper {
     265              :     public:
     266         1248 :         LaneScope(TraCIAPI& parent) : TraCIScopeWrapper(parent, libsumo::CMD_GET_LANE_VARIABLE, libsumo::CMD_SET_LANE_VARIABLE, libsumo::CMD_SUBSCRIBE_LANE_VARIABLE, libsumo::CMD_SUBSCRIBE_LANE_CONTEXT) {}
     267         1248 :         virtual ~LaneScope() {}
     268              : 
     269              :         double getLength(const std::string& laneID) const;
     270              :         double getMaxSpeed(const std::string& laneID) const;
     271              :         double getWidth(const std::string& laneID) const;
     272              :         std::vector<std::string> getAllowed(const std::string& laneID) const;
     273              :         std::vector<std::string> getDisallowed(const std::string& laneID) const;
     274              :         int getLinkNumber(const std::string& laneID) const;
     275              :         std::vector<libsumo::TraCIConnection> getLinks(const std::string& laneID) const;
     276              :         libsumo::TraCIPositionVector getShape(const std::string& laneID) const;
     277              :         std::string getEdgeID(const std::string& laneID) const;
     278              :         double getCO2Emission(const std::string& laneID) const;
     279              :         double getCOEmission(const std::string& laneID) const;
     280              :         double getHCEmission(const std::string& laneID) const;
     281              :         double getPMxEmission(const std::string& laneID) const;
     282              :         double getNOxEmission(const std::string& laneID) const;
     283              :         double getFuelConsumption(const std::string& laneID) const;
     284              :         double getNoiseEmission(const std::string& laneID) const;
     285              :         double getElectricityConsumption(const std::string& laneID) const;
     286              :         double getLastStepMeanSpeed(const std::string& laneID) const;
     287              :         double getLastStepOccupancy(const std::string& laneID) const;
     288              :         double getLastStepLength(const std::string& laneID) const;
     289              :         double getTraveltime(const std::string& laneID) const;
     290              :         int getLastStepVehicleNumber(const std::string& laneID) const;
     291              :         int getLastStepHaltingNumber(const std::string& laneID) const;
     292              :         std::vector<std::string> getLastStepVehicleIDs(const std::string& laneID) const;
     293              :         std::vector<std::string> getFoes(const std::string& laneID, const std::string& toLaneID) const;
     294              :         std::vector<std::string> getInternalFoes(const std::string& laneID) const;
     295              : 
     296              :         void setAllowed(const std::string& laneID, const std::vector<std::string>& allowedClasses) const;
     297              :         void setDisallowed(const std::string& laneID, const std::vector<std::string>& disallowedClasses) const;
     298              :         void setMaxSpeed(const std::string& laneID, double speed) const;
     299              :         void setLength(const std::string& laneID, double length) const;
     300              :     };
     301              : 
     302              : 
     303              :     /** @class LaneAreaScope
     304              :     * @brief Scope for interaction with lane area detectors
     305              :     */
     306              :     class LaneAreaScope : public TraCIScopeWrapper {
     307              :     public:
     308         1248 :         LaneAreaScope(TraCIAPI& parent) : TraCIScopeWrapper(parent, libsumo::CMD_GET_LANEAREA_VARIABLE, -1, libsumo::CMD_SUBSCRIBE_LANEAREA_VARIABLE, libsumo::CMD_SUBSCRIBE_LANEAREA_CONTEXT) {}
     309         1248 :         virtual ~LaneAreaScope() {}
     310              :     };
     311              : 
     312              : 
     313              :     /** @class MeMeScope
     314              :      * @brief Scope for interaction with multi entry/-exit detectors
     315              :      */
     316              :     class MeMeScope : public TraCIScopeWrapper {
     317              :     public:
     318         1248 :         MeMeScope(TraCIAPI& parent) : TraCIScopeWrapper(parent, libsumo::CMD_GET_MULTIENTRYEXIT_VARIABLE, -1, libsumo::CMD_SUBSCRIBE_MULTIENTRYEXIT_VARIABLE, libsumo::CMD_SUBSCRIBE_MULTIENTRYEXIT_CONTEXT) {}
     319         1248 :         virtual ~MeMeScope() {}
     320              : 
     321              :         int getLastStepVehicleNumber(const std::string& detID) const;
     322              :         double getLastStepMeanSpeed(const std::string& detID) const;
     323              :         std::vector<std::string> getLastStepVehicleIDs(const std::string& detID) const;
     324              :         int getLastStepHaltingNumber(const std::string& detID) const;
     325              :         std::vector<std::string> getEntryLanes(const std::string& detID) const;
     326              :         std::vector<std::string> getExitLanes(const std::string& detID) const;
     327              :         std::vector<double> getEntryPositions(const std::string& detID) const;
     328              :         std::vector<double> getExitPositions(const std::string& detID) const;
     329              :     };
     330              : 
     331              : 
     332              :     /** @class POIScope
     333              :      * @brief Scope for interaction with POIs
     334              :      */
     335              :     class POIScope : public TraCIScopeWrapper {
     336              :     public:
     337         1248 :         POIScope(TraCIAPI& parent) : TraCIScopeWrapper(parent, libsumo::CMD_GET_POI_VARIABLE, libsumo::CMD_SET_POI_VARIABLE, libsumo::CMD_SUBSCRIBE_POI_VARIABLE, libsumo::CMD_SUBSCRIBE_POI_CONTEXT) {}
     338            0 :         virtual ~POIScope() {}
     339              : 
     340              :         std::string getType(const std::string& poiID) const;
     341              :         libsumo::TraCIPosition getPosition(const std::string& poiID) const;
     342              :         libsumo::TraCIColor getColor(const std::string& poiID) const;
     343              :         double getWidth(const std::string& poiID) const;
     344              :         double getHeight(const std::string& poiID) const;
     345              :         double getAngle(const std::string& poiID) const;
     346              :         std::string getImageFile(const std::string& poiID) const;
     347              : 
     348              :         void setType(const std::string& poiID, const std::string& setType) const;
     349              :         void setPosition(const std::string& poiID, double x, double y) const;
     350              :         void setColor(const std::string& poiID, const libsumo::TraCIColor& c) const;
     351              :         void setWidth(const std::string& poiID, double width) const;
     352              :         void setHeight(const std::string& poiID, double height) const;
     353              :         void setAngle(const std::string& poiID, double angle) const;
     354              :         void setImageFile(const std::string& poiID, const std::string& imageFile) const;
     355              :         void add(const std::string& poiID, double x, double y, const libsumo::TraCIColor& c, const std::string& type, int layer, const std::string& imgFile, double width, double height, double angle) const;
     356              :         void remove(const std::string& poiID, int layer = 0) const;
     357              :     };
     358              : 
     359              : 
     360              :     /** @class PolygonScope
     361              :      * @brief Scope for interaction with polygons
     362              :      */
     363              :     class PolygonScope : public TraCIScopeWrapper {
     364              :     public:
     365         1248 :         PolygonScope(TraCIAPI& parent) : TraCIScopeWrapper(parent, libsumo::CMD_GET_POLYGON_VARIABLE, libsumo::CMD_SET_POLYGON_VARIABLE, libsumo::CMD_SUBSCRIBE_POLYGON_VARIABLE, libsumo::CMD_SUBSCRIBE_POLYGON_CONTEXT) {}
     366         1248 :         virtual ~PolygonScope() {}
     367              : 
     368              :         double getLineWidth(const std::string& polygonID) const;
     369              :         bool getFilled(const std::string& polygonID) const;
     370              :         std::string getType(const std::string& polygonID) const;
     371              :         libsumo::TraCIPositionVector getShape(const std::string& polygonID) const;
     372              :         libsumo::TraCIColor getColor(const std::string& polygonID) const;
     373              :         void setType(const std::string& polygonID, const std::string& setType) const;
     374              :         void setShape(const std::string& polygonID, const libsumo::TraCIPositionVector& shape) const;
     375              :         void setColor(const std::string& polygonID, const libsumo::TraCIColor& c) const;
     376              :         void setLineWidth(const std::string& polygonID, const double lineWidth) const;
     377              :         void add(const std::string& polygonID, const libsumo::TraCIPositionVector& shape, const libsumo::TraCIColor& c, bool fill, const std::string& type, int layer) const;
     378              :         void remove(const std::string& polygonID, int layer = 0) const;
     379              :     };
     380              : 
     381              : 
     382              :     /** @class RerouterScope
     383              :      * @brief Scope for interaction with rerouters
     384              :      */
     385              :     class RerouterScope : public TraCIScopeWrapper {
     386              :     public:
     387         1248 :         RerouterScope(TraCIAPI& parent) : TraCIScopeWrapper(parent, libsumo::CMD_GET_REROUTER_VARIABLE, libsumo::CMD_SET_REROUTER_VARIABLE, libsumo::CMD_SUBSCRIBE_REROUTER_VARIABLE, libsumo::CMD_SUBSCRIBE_REROUTER_CONTEXT) {}
     388         1248 :         virtual ~RerouterScope() {}
     389              :     };
     390              : 
     391              : 
     392              :     /** @class RouteScope
     393              :      * @brief Scope for interaction with routes
     394              :      */
     395              :     class RouteScope : public TraCIScopeWrapper {
     396              :     public:
     397         1248 :         RouteScope(TraCIAPI& parent) : TraCIScopeWrapper(parent, libsumo::CMD_GET_ROUTE_VARIABLE, libsumo::CMD_SET_ROUTE_VARIABLE, libsumo::CMD_SUBSCRIBE_ROUTE_VARIABLE, libsumo::CMD_SUBSCRIBE_ROUTE_CONTEXT) {}
     398         1248 :         virtual ~RouteScope() {}
     399              : 
     400              :         std::vector<std::string> getEdges(const std::string& routeID) const;
     401              : 
     402              :         void add(const std::string& routeID, const std::vector<std::string>& edges) const;
     403              :     };
     404              : 
     405              : 
     406              :     /** @class RouteProbeScope
     407              :      * @brief Scope for interaction with route probes
     408              :      */
     409              :     class RouteProbeScope : public TraCIScopeWrapper {
     410              :     public:
     411         1248 :         RouteProbeScope(TraCIAPI& parent) : TraCIScopeWrapper(parent, libsumo::CMD_GET_ROUTEPROBE_VARIABLE, libsumo::CMD_SET_ROUTEPROBE_VARIABLE, libsumo::CMD_SUBSCRIBE_ROUTEPROBE_VARIABLE, libsumo::CMD_SUBSCRIBE_ROUTEPROBE_CONTEXT) {}
     412         1248 :         virtual ~RouteProbeScope() {}
     413              :     };
     414              : 
     415              : 
     416              :     /** @class SimulationScope
     417              :      * @brief Scope for interaction with the simulation
     418              :      */
     419              :     class SimulationScope : public TraCIScopeWrapper {
     420              :     public:
     421         1248 :         SimulationScope(TraCIAPI& parent) : TraCIScopeWrapper(parent, libsumo::CMD_GET_SIM_VARIABLE, libsumo::CMD_SET_SIM_VARIABLE, libsumo::CMD_SUBSCRIBE_SIM_VARIABLE, libsumo::CMD_SUBSCRIBE_SIM_CONTEXT) {}
     422         1248 :         virtual ~SimulationScope() {}
     423              : 
     424              :         int getCurrentTime() const;
     425              :         double getTime() const;
     426              :         int getLoadedNumber() const;
     427              :         std::vector<std::string> getLoadedIDList() const;
     428              :         int getDepartedNumber() const;
     429              :         std::vector<std::string> getDepartedIDList() const;
     430              :         int getArrivedNumber() const;
     431              :         std::vector<std::string> getArrivedIDList() const;
     432              :         int getStartingTeleportNumber() const;
     433              :         std::vector<std::string> getStartingTeleportIDList() const;
     434              :         int getEndingTeleportNumber() const;
     435              :         std::vector<std::string> getEndingTeleportIDList() const;
     436              :         double getDeltaT() const;
     437              :         libsumo::TraCIPositionVector getNetBoundary() const;
     438              :         int getMinExpectedNumber() const;
     439              :         std::string getOption(const std::string& option) const;
     440              : 
     441              :         int getDepartedPersonNumber() const;
     442              :         std::vector<std::string> getDepartedPersonIDList() const;
     443              :         int getArrivedPersonNumber() const;
     444              :         std::vector<std::string> getArrivedPersonIDList() const;
     445              : 
     446              :         int getBusStopWaiting(const std::string& stopID) const;
     447              :         std::vector<std::string> getBusStopWaitingIDList(const std::string& stopID) const;
     448              : 
     449              :         libsumo::TraCIPosition convert2D(const std::string& edgeID, double pos, int laneIndex = 0, bool toGeo = false) const;
     450              :         libsumo::TraCIPosition convert3D(const std::string& edgeID, double pos, int laneIndex = 0, bool toGeo = false) const;
     451              :         libsumo::TraCIRoadPosition convertRoad(double x, double y, bool isGeo = false, const std::string& vClass = "ignoring") const;
     452              :         libsumo::TraCIPosition convertGeo(double x, double y, bool fromGeo = false) const;
     453              : 
     454              :         double getDistance2D(double x1, double y1, double x2, double y2, bool isGeo = false, bool isDriving = false);
     455              :         double getDistanceRoad(const std::string& edgeID1, double pos1, const std::string& edgeID2, double pos2, bool isDriving = false);
     456              :         libsumo::TraCIStage findRoute(const std::string& fromEdge, const std::string& toEdge, const std::string& vType = "", double pos = -1., int routingMode = 0) const;
     457              :         void loadState(const std::string& path) const;
     458              :         void saveState(const std::string& destination) const;
     459              :         void writeMessage(const std::string msg);
     460              :     };
     461              : 
     462              : 
     463              :     /** @class TrafficLightScope
     464              :      * @brief Scope for interaction with traffic lights
     465              :      */
     466              :     class TrafficLightScope : public TraCIScopeWrapper {
     467              :     public:
     468         1248 :         TrafficLightScope(TraCIAPI& parent) : TraCIScopeWrapper(parent, libsumo::CMD_GET_TL_VARIABLE, libsumo::CMD_SET_TL_VARIABLE, libsumo::CMD_SUBSCRIBE_TL_VARIABLE, libsumo::CMD_SUBSCRIBE_TL_CONTEXT) {}
     469         1248 :         virtual ~TrafficLightScope() {}
     470              : 
     471              :         std::string getRedYellowGreenState(const std::string& tlsID) const;
     472              :         std::vector<libsumo::TraCILogic> getAllProgramLogics(const std::string& tlsID) const;
     473              :         std::vector<std::string> getControlledLanes(const std::string& tlsID) const;
     474              :         std::vector<std::vector<libsumo::TraCILink> > getControlledLinks(const std::string& tlsID) const;
     475              :         std::string getProgram(const std::string& tlsID) const;
     476              :         int getPhase(const std::string& tlsID) const;
     477              :         double getPhaseDuration(const std::string& tlsID) const;
     478              :         double getNextSwitch(const std::string& tlsID) const;
     479              :         int getServedPersonCount(const std::string& tlsID, int index) const;
     480              :         std::string getPhaseName(const std::string& tlsID) const;
     481              : 
     482              :         void setRedYellowGreenState(const std::string& tlsID, const std::string& state) const;
     483              :         void setPhase(const std::string& tlsID, int index) const;
     484              :         void setPhaseName(const std::string& tlsID, const std::string& name) const;
     485              :         void setProgram(const std::string& tlsID, const std::string& programID) const;
     486              :         void setPhaseDuration(const std::string& tlsID, double phaseDuration) const;
     487              :         void setProgramLogic(const std::string& tlsID, const libsumo::TraCILogic& logic) const;
     488              : 
     489              :         // aliases for backward compatibility
     490              :         inline std::vector<libsumo::TraCILogic> getCompleteRedYellowGreenDefinition(const std::string& tlsID) const {
     491              :             return getAllProgramLogics(tlsID);
     492              :         }
     493              :         void setCompleteRedYellowGreenDefinition(const std::string& tlsID, const libsumo::TraCILogic& logic) const {
     494              :             setProgramLogic(tlsID, logic);
     495              :         }
     496              :     };
     497              : 
     498              : 
     499              :     /** @class VehicleTypeScope
     500              :      * @brief Scope for interaction with vehicle types
     501              :      */
     502              :     class VehicleTypeScope : public TraCIScopeWrapper {
     503              :     public:
     504         1248 :         VehicleTypeScope(TraCIAPI& parent) : TraCIScopeWrapper(parent, libsumo::CMD_GET_VEHICLETYPE_VARIABLE, libsumo::CMD_SET_VEHICLETYPE_VARIABLE, libsumo::CMD_SUBSCRIBE_VEHICLETYPE_VARIABLE, libsumo::CMD_SUBSCRIBE_VEHICLETYPE_CONTEXT) {}
     505         1248 :         virtual ~VehicleTypeScope() {}
     506              : 
     507              :         double getLength(const std::string& typeID) const;
     508              :         double getMaxSpeed(const std::string& typeID) const;
     509              :         double getSpeedFactor(const std::string& typeID) const;
     510              :         double getSpeedDeviation(const std::string& typeID) const;
     511              :         double getAccel(const std::string& typeID) const;
     512              :         double getDecel(const std::string& typeID) const;
     513              :         double getEmergencyDecel(const std::string& typeID) const;
     514              :         double getApparentDecel(const std::string& typeID) const;
     515              :         double getImperfection(const std::string& typeID) const;
     516              :         double getTau(const std::string& typeID) const;
     517              :         std::string getVehicleClass(const std::string& typeID) const;
     518              :         std::string getEmissionClass(const std::string& typeID) const;
     519              :         std::string getShapeClass(const std::string& typeID) const;
     520              :         double getMinGap(const std::string& typeID) const;
     521              :         double getWidth(const std::string& typeID) const;
     522              :         double getHeight(const std::string& typeID) const;
     523              :         libsumo::TraCIColor getColor(const std::string& typeID) const;
     524              :         double getMinGapLat(const std::string& typeID) const;
     525              :         double getMaxSpeedLat(const std::string& typeID) const;
     526              :         std::string getLateralAlignment(const std::string& typeID) const;
     527              :         int getPersonCapacity(const std::string& typeID) const;
     528              : 
     529              :         void setLength(const std::string& typeID, double length) const;
     530              :         void setMaxSpeed(const std::string& typeID, double speed) const;
     531              :         void setVehicleClass(const std::string& typeID, const std::string& clazz) const;
     532              :         void setSpeedFactor(const std::string& typeID, double factor) const;
     533              :         void setSpeedDeviation(const std::string& typeID, double deviation) const;
     534              :         void setEmissionClass(const std::string& typeID, const std::string& clazz) const;
     535              :         void setShapeClass(const std::string& typeID, const std::string& shapeClass) const;
     536              :         void setWidth(const std::string& typeID, double width) const;
     537              :         void setHeight(const std::string& typeID, double height) const;
     538              :         void setMinGap(const std::string& typeID, double minGap) const;
     539              :         void setAccel(const std::string& typeID, double accel) const;
     540              :         void setDecel(const std::string& typeID, double decel) const;
     541              :         void setEmergencyDecel(const std::string& typeID, double decel) const;
     542              :         void setApparentDecel(const std::string& typeID, double decel) const;
     543              :         void setImperfection(const std::string& typeID, double imperfection) const;
     544              :         void setTau(const std::string& typeID, double tau) const;
     545              :         void setColor(const std::string& typeID, const libsumo::TraCIColor& c) const;
     546              :         void setMinGapLat(const std::string& typeID, double minGapLat) const;
     547              :         void setMaxSpeedLat(const std::string& typeID, double speed) const;
     548              :         void setLateralAlignment(const std::string& typeID, const std::string& latAlignment) const;
     549              :         void copy(const std::string& origTypeID, const std::string& newTypeID) const;
     550              :     };
     551              : 
     552              : 
     553              :     /** @class VehicleScope
     554              :      * @brief Scope for interaction with vehicles
     555              :      */
     556              :     class VehicleScope : public TraCIScopeWrapper {
     557              :     public:
     558         1248 :         VehicleScope(TraCIAPI& parent) : TraCIScopeWrapper(parent, libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::CMD_SUBSCRIBE_VEHICLE_VARIABLE, libsumo::CMD_SUBSCRIBE_VEHICLE_CONTEXT) {}
     559         1248 :         virtual ~VehicleScope() {}
     560              : 
     561              :         enum VehicleSignal {
     562              :             SIGNAL_BLINKER_RIGHT = 1,
     563              :             SIGNAL_BLINKER_LEFT = 2,
     564              :             SIGNAL_BLINKER_EMERGENCY = 4,
     565              :             SIGNAL_BRAKELIGHT = 8,
     566              :             SIGNAL_FRONTLIGHT = 16,
     567              :             SIGNAL_FOGLIGHT = 32,
     568              :             SIGNAL_HIGHBEAM = 64,
     569              :             SIGNAL_BACKDRIVE = 128,
     570              :             SIGNAL_WIPER = 256,
     571              :             SIGNAL_DOOR_OPEN_LEFT = 512,
     572              :             SIGNAL_DOOR_OPEN_RIGHT = 1024,
     573              :             SIGNAL_EMERGENCY_BLUE = 2048,
     574              :             SIGNAL_EMERGENCY_RED = 4096,
     575              :             SIGNAL_EMERGENCY_YELLOW = 8192,
     576              :             SIGNAL_RESET = -1, /*< sending a negative signal resets all signals to their computed values immediately */
     577              :         };
     578              : 
     579              :         /// @name vehicle value retrieval
     580              :         /// @{
     581              :         double getSpeed(const std::string& vehicleID) const;
     582              :         double getLateralSpeed(const std::string& vehicleID) const;
     583              :         double getAcceleration(const std::string& vehicleID) const;
     584              :         double getFollowSpeed(const std::string& vehicleID, double speed, double gap, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID = "") const;
     585              :         double getSecureGap(const std::string& vehicleID, double speed, double leaderSpeed, double leaderMaxDecel, const std::string& leaderID = "") const;
     586              :         double getStopSpeed(const std::string& vehicleID, double speed, double gap) const;
     587              :         libsumo::TraCIPosition getPosition(const std::string& vehicleID) const;
     588              :         libsumo::TraCIPosition getPosition3D(const std::string& vehicleID) const;
     589              :         double getAngle(const std::string& vehicleID) const;
     590              :         std::string getRoadID(const std::string& vehicleID) const;
     591              :         std::string getLaneID(const std::string& vehicleID) const;
     592              :         int getLaneIndex(const std::string& vehicleID) const;
     593              :         std::string getTypeID(const std::string& vehicleID) const;
     594              :         std::string getRouteID(const std::string& vehicleID) const;
     595              :         int getRouteIndex(const std::string& vehicleID) const;
     596              :         std::vector<std::string> getRoute(const std::string& vehicleID) const;
     597              :         libsumo::TraCIColor getColor(const std::string& vehicleID) const;
     598              :         double getLanePosition(const std::string& vehicleID) const;
     599              :         double getDistance(const std::string& vehicleID) const;
     600              :         int getSignals(const std::string& vehicleID) const;
     601              :         double getCO2Emission(const std::string& vehicleID) const;
     602              :         double getCOEmission(const std::string& vehicleID) const;
     603              :         double getHCEmission(const std::string& vehicleID) const;
     604              :         double getPMxEmission(const std::string& vehicleID) const;
     605              :         double getNOxEmission(const std::string& vehicleID) const;
     606              :         double getFuelConsumption(const std::string& vehicleID) const;
     607              :         double getNoiseEmission(const std::string& vehicleID) const;
     608              :         double getElectricityConsumption(const std::string& vehicleID) const;
     609              :         int getStopState(const std::string& vehicleID) const;
     610              :         double getWaitingTime(const std::string& vehicleID) const;
     611              :         double getAccumulatedWaitingTime(const std::string& vehicleID) const;
     612              :         int getLaneChangeMode(const std::string& vehicleID) const;
     613              :         int getSpeedMode(const std::string& vehicleID) const;
     614              :         double getSlope(const std::string& vehicleID) const;
     615              :         double getAllowedSpeed(const std::string& vehicleID) const;
     616              :         int getPersonNumber(const std::string& vehicleID) const;
     617              :         std::vector<std::string> getPersonIDList(const std::string& vehicleID) const;
     618              :         double getSpeedWithoutTraCI(const std::string& vehicleID) const;
     619              :         bool isRouteValid(const std::string& vehicleID) const;
     620              :         double getLateralLanePosition(const std::string& vehicleID) const;
     621              :         double getSpeedFactor(const std::string& vehicleID) const;
     622              :         std::string getLine(const std::string& vehicleID) const;
     623              :         std::vector<std::string> getVia(const std::string& vehicleID) const;
     624              :         std::vector<libsumo::TraCINextTLSData> getNextTLS(const std::string& vehID) const;
     625              :         std::vector<libsumo::TraCIBestLanesData> getBestLanes(const std::string& vehicleID) const;
     626              :         std::pair<std::string, double> getLeader(const std::string& vehicleID, double dist) const;
     627              :         std::pair<std::string, double> getFollower(const std::string& vehicleID, double dist) const;
     628              :         int getRoutingMode(const std::string& vehicleID) const;
     629              :         double getStopDelay(const std::string& vehicleID) const;
     630              :         double getStopArrivalDelay(const std::string& vehicleID) const;
     631              :         std::pair<int, int> getLaneChangeState(const std::string& vehicleID, int direction) const;
     632              :         /// @}
     633              : 
     634              :         /// @name vehicle type value retrieval shortcuts
     635              :         /// @{
     636              :         double getLength(const std::string& vehicleID) const;
     637              :         double getMaxSpeed(const std::string& vehicleID) const;
     638              :         double getAccel(const std::string& vehicleID) const;
     639              :         double getDecel(const std::string& vehicleID) const;
     640              :         double getEmergencyDecel(const std::string& vehicleID) const;
     641              :         double getApparentDecel(const std::string& vehicleID) const;
     642              :         double getTau(const std::string& vehicleID) const;
     643              :         double getImperfection(const std::string& vehicleID) const;
     644              :         double getSpeedDeviation(const std::string& vehicleID) const;
     645              :         double getMinGap(const std::string& vehicleID) const;
     646              :         double getWidth(const std::string& vehicleID) const;
     647              :         double getHeight(const std::string& veihcleID) const;
     648              :         double getMaxSpeedLat(const std::string& vehicleID) const;
     649              :         double getMinGapLat(const std::string& vehicleID) const;
     650              :         int getPersonCapacity(const std::string& vehicleID) const;
     651              :         std::string getVehicleClass(const std::string& vehicleID) const;
     652              :         std::string getEmissionClass(const std::string& vehicleID) const;
     653              :         std::string getShapeClass(const std::string& vehicleID) const;
     654              :         std::string getLateralAlignment(const std::string& vehicleID) const;
     655              :         /// @}
     656              : 
     657              :         /// @name vehicle state changing
     658              :         /// @{
     659              :         void add(const std::string& vehicleID,
     660              :                  const std::string& routeID,
     661              :                  const std::string& typeID = "DEFAULT_VEHTYPE",
     662              :                  std::string depart = "-1",
     663              :                  const std::string& departLane = "first",
     664              :                  const std::string& departPos = "base",
     665              :                  const std::string& departSpeed = "0",
     666              :                  const std::string& arrivalLane = "current",
     667              :                  const std::string& arrivalPos = "max",
     668              :                  const std::string& arrivalSpeed = "current",
     669              :                  const std::string& fromTaz = "",
     670              :                  const std::string& toTaz = "",
     671              :                  const std::string& line = "",
     672              :                  int personCapacity = 0,
     673              :                  int personNumber = 0) const;
     674              : 
     675              :         void changeTarget(const std::string& vehicleID, const std::string& edgeID) const;
     676              :         void changeLane(const std::string& vehicleID, int laneIndex, double duration) const;
     677              :         void changeLaneRelative(const std::string& vehicleID, int laneChange, double duration) const;
     678              :         void changeSublane(const std::string& vehicleID, double latDist) const;
     679              :         void setRouteID(const std::string& vehicleID, const std::string& routeID) const;
     680              :         void setRoute(const std::string& vehicleID, const std::vector<std::string>& edge) const;
     681              :         void rerouteTraveltime(const std::string& vehicleID, bool currentTravelTimes = true) const;
     682              :         void moveTo(const std::string& vehicleID, const std::string& laneID, double position, int reason = libsumo::MOVE_TELEPORT) const;
     683              :         void moveToXY(const std::string& vehicleID, const std::string& edgeID, const int lane, const double x, const double y, const double angle, const int keepRoute) const;
     684              :         void slowDown(const std::string& vehicleID, double speed, double duration) const;
     685              :         void openGap(const std::string& vehicleID, double newTau, double duration, double changeRate, double maxDecel) const;
     686              :         void setSpeed(const std::string& vehicleID, double speed) const;
     687              :         void setAcceleration(const std::string& vehicleID, double accel, double duration) const;
     688              :         void setPreviousSpeed(const std::string& vehicleID, double prevSpeed, double prevAcceleration = std::numeric_limits<int>::min()) const;
     689              :         void setLaneChangeMode(const std::string& vehicleID, int mode) const;
     690              :         void setSpeedMode(const std::string& vehicleID, int mode) const;
     691              :         void setStop(const std::string vehicleID, const std::string edgeID, const double endPos = 1.,
     692              :                      const int laneIndex = 0, const double duration = std::numeric_limits<double>::max(),
     693              :                      const int flags = 0, const double startPos = std::numeric_limits<int>::min(),
     694              :                      const double until = -1) const;
     695              :         void setType(const std::string& vehicleID, const std::string& typeID) const;
     696              :         void remove(const std::string& vehicleID, char reason = libsumo::REMOVE_VAPORIZED) const;
     697              :         void setColor(const std::string& vehicleID, const libsumo::TraCIColor& c) const;
     698              :         void setLine(const std::string& vehicleID, const std::string& line) const;
     699              :         void setVia(const std::string& vehicleID, const std::vector<std::string>& via) const;
     700              :         void setSignals(const std::string& vehicleID, int signals) const;
     701              :         void setRoutingMode(const std::string& vehicleID, int routingMode) const;
     702              :         /// @}
     703              : 
     704              :         /// @name vehicle type attribute changing shortcuts
     705              :         /// @{
     706              :         void setShapeClass(const std::string& vehicleID, const std::string& clazz) const;
     707              :         void setEmissionClass(const std::string& vehicleID, const std::string& clazz) const;
     708              :         void setSpeedFactor(const std::string& vehicleID, double factor) const;
     709              :         void setMinGap(const std::string& vehicleID, double minGap) const;
     710              :         void setMaxSpeed(const std::string& vehicleID, double speed) const;
     711              :         /// @}
     712              : 
     713              :         /// @name subscription filtering
     714              :         /* @brief Filters are added to the last modified vehicle context
     715              :          *  subscription (call these fucntions right after subscribing) */
     716              :         /// @{
     717              : 
     718              :         /* @brief Adds a lane-filter, lanes is a list of relative lane indices (-1 -> right neighboring lane of the ego, 0 -> ego lane, etc.)
     719              :          * noOpposite specifies whether vehicles on opposite direction lanes shall be returned
     720              :          * downstreamDist and upstreamDist specify the range of the search for surrounding vehicles along the road net. */
     721              :         void addSubscriptionFilterLanes(const std::vector<int>& lanes,
     722              :                                         bool noOpposite = false, double downstreamDist = -1, double upstreamDist = -1) const;
     723              : 
     724              :         /* @brief Omits vehicles on other edges than the ego's */
     725              :         void addSubscriptionFilterNoOpposite() const;
     726              : 
     727              :         /* @brief Limits the downstream distance for resulting vehicles */
     728              :         void addSubscriptionFilterDownstreamDistance(double dist) const;
     729              : 
     730              :         /* @brief Limits the updstream distance for resulting vehicles */
     731              :         void addSubscriptionFilterUpstreamDistance(double dist) const;
     732              : 
     733              :         /* @brief Restricts vehicles returned by the last modified vehicle context subscription to leader and follower of the ego.
     734              :          * downstreamDist and upstreamDist specify the range of the search for leader and follower along the road net. */
     735              :         void addSubscriptionFilterCFManeuver(double downstreamDist = -1, double upstreamDist = -1) const;
     736              : 
     737              :         /* @brief Restricts returned vehicles to neighbor and ego-lane leader
     738              :          *  and follower of the ego in the given direction
     739              :          * noOpposite specifies whether vehicles on opposite direction lanes shall be returned
     740              :          * downstreamDist and upstreamDist specify the range of the search for leader and follower along the road net.
     741              :          * Combine with: distance filters; vClass/vType filter. */
     742              :         void addSubscriptionFilterLCManeuver(int direction, bool noOpposite = false, double downstreamDist = -1, double upstreamDist = -1) const;
     743              : 
     744              :         /* @brief Restricts returned vehicles to neighbor and ego-lane leader and follower of the ego.
     745              :          * Combine with: lanes-filter to restrict to one direction; distance filters; vClass/vType filter. */
     746              :         void addSubscriptionFilterLeadFollow(const std::vector<int>& lanes) const;
     747              : 
     748              :         /* @brief Restricts returned vehicles to foes on an upcoming junction */
     749              :         void addSubscriptionFilterTurn(double downstreamDist = -1, double upstreamDist = -1) const;
     750              : 
     751              :         /* @brief Restricts returned vehicles to the given classes */
     752              :         void addSubscriptionFilterVClass(const std::vector<std::string>& vClasses) const;
     753              : 
     754              :         /* @brief Restricts returned vehicles to the given types */
     755              :         void addSubscriptionFilterVType(const std::vector<std::string>& vTypes) const;
     756              : 
     757              :         /* @brief Restricts returned vehicles to the given FOV-angle */
     758              :         void addSubscriptionFilterFieldOfVision(double angle) const;
     759              : 
     760              :         /* @brief Restricts returned vehicles to the given lateral distance */
     761              :         void addSubscriptionFilterLateralDistance(double lateralDist, double downstreamDist = -1, double foeDistToJunction = -1) const;
     762              : 
     763              :         /// @}
     764              : 
     765              :     private:
     766              :         void addSubscriptionFilterEmpty(int filterType) const;
     767              :         void addSubscriptionFilterFloat(int filterType, double val) const;
     768              :         void addSubscriptionFilterStringList(int filterType, const std::vector<std::string>& vals) const;
     769              :         void addSubscriptionFilterByteList(int filterType, const std::vector<int>& vals) const;
     770              :     };
     771              : 
     772              : 
     773              :     /** @class PersonScope
     774              :      * * @brief Scope for interaction with vehicles
     775              :      * */
     776              :     class PersonScope : public TraCIScopeWrapper {
     777              :     public:
     778         1248 :         PersonScope(TraCIAPI& parent) : TraCIScopeWrapper(parent, libsumo::CMD_GET_PERSON_VARIABLE, libsumo::CMD_SET_PERSON_VARIABLE, libsumo::CMD_SUBSCRIBE_PERSON_VARIABLE, libsumo::CMD_SUBSCRIBE_PERSON_CONTEXT) {}
     779         1248 :         virtual ~PersonScope() {}
     780              : 
     781              :         double getSpeed(const std::string& personID) const;
     782              :         libsumo::TraCIPosition getPosition(const std::string& personID) const;
     783              :         libsumo::TraCIPosition getPosition3D(const std::string& personID) const;
     784              :         std::string getRoadID(const std::string& personID) const;
     785              :         std::string getLaneID(const std::string& personID) const;
     786              :         std::string getTypeID(const std::string& personID) const;
     787              :         double getSpeedFactor(const std::string& personID) const;
     788              :         double getWaitingTime(const std::string& personID) const;
     789              :         std::string getNextEdge(const std::string& personID) const;
     790              :         std::string getVehicle(const std::string& personID) const;
     791              :         int getRemainingStages(const std::string& personID) const;
     792              :         libsumo::TraCIStage getStage(const std::string& personID, int nextStageIndex = 0) const;
     793              :         std::vector<std::string> getEdges(const std::string& personID, int nextStageIndex = 0) const;
     794              :         double getAngle(const std::string& personID) const;
     795              :         double getSlope(const std::string& personID) const;
     796              :         double getLanePosition(const std::string& personID) const;
     797              :         libsumo::TraCIColor getColor(const std::string& personID) const;
     798              : 
     799              :         /// @name vehicle type value retrieval shortcuts
     800              :         /// @{
     801              :         double getLength(const std::string& personID) const;
     802              :         /// @}
     803              : 
     804              : 
     805              :         void removeStages(const std::string& personID) const;
     806              :         void add(const std::string& personID, const std::string& edgeID, double pos, double depart = libsumo::DEPARTFLAG_NOW, const std::string typeID = "DEFAULT_PEDTYPE");
     807              :         void appendStage(const std::string& personID, const libsumo::TraCIStage& stage);
     808              :         void appendWaitingStage(const std::string& personID, double duration, const std::string& description = "waiting", const std::string& stopID = "");
     809              :         void appendWalkingStage(const std::string& personID, const std::vector<std::string>& edges, double arrivalPos, double duration = -1, double speed = -1, const std::string& stopID = "");
     810              :         void appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID = "");
     811              :         void removeStage(const std::string& personID, int nextStageIndex) const;
     812              :         void rerouteTraveltime(const std::string& personID) const;
     813              :         void moveTo(const std::string& personID, const std::string& edgeID, double position) const;
     814              :         void moveToXY(const std::string& personID, const std::string& edgeID, const double x, const double y, double angle, const int keepRoute) const;
     815              :         void setSpeed(const std::string& personID, double speed) const;
     816              :         void setType(const std::string& personID, const std::string& typeID) const;
     817              :         void setSpeedFactor(const std::string& personID, double factor) const;
     818              :         void setLength(const std::string& personID, double length) const;
     819              :         void setWidth(const std::string& personID, double width) const;
     820              :         void setHeight(const std::string& personID, double height) const;
     821              :         void setMinGap(const std::string& personID, double minGap) const;
     822              :         void setColor(const std::string& personID, const libsumo::TraCIColor& c) const;
     823              :     };
     824              : 
     825              : 
     826              : 
     827              : public:
     828              :     /// @brief Scope for interaction with edges
     829              :     EdgeScope edge;
     830              :     /// @brief Scope for interaction with the gui
     831              :     GUIScope gui;
     832              :     /// @brief Scope for interaction with inductive loops
     833              :     InductionLoopScope inductionloop;
     834              :     /// @brief Scope for interaction with junctions
     835              :     JunctionScope junction;
     836              :     /// @brief Scope for interaction with lanes
     837              :     LaneScope lane;
     838              :     /// @brief Scope for interaction with lanes
     839              :     LaneAreaScope lanearea;
     840              :     /// @brief Scope for interaction with multi-entry/-exit detectors
     841              :     MeMeScope multientryexit;
     842              :     /// @brief Scope for interaction with persons
     843              :     PersonScope person;
     844              :     /// @brief Scope for interaction with POIs
     845              :     POIScope poi;
     846              :     /// @brief Scope for interaction with polygons
     847              :     PolygonScope polygon;
     848              :     /// @brief Scope for interaction with rerouters
     849              :     RerouterScope rerouter;
     850              :     /// @brief Scope for interaction with routes
     851              :     RouteScope route;
     852              :     /// @brief Scope for interaction with route probes
     853              :     RouteProbeScope routeprobe;
     854              :     /// @brief Scope for interaction with the simulation
     855              :     SimulationScope simulation;
     856              :     /// @brief Scope for interaction with traffic lights
     857              :     TrafficLightScope trafficlights;
     858              :     /// @brief Scope for interaction with vehicles
     859              :     VehicleScope vehicle;
     860              :     /// @brief Scope for interaction with vehicle types
     861              :     VehicleTypeScope vehicletype;
     862              : 
     863              : 
     864              : protected:
     865              :     /// @name Command sending methods
     866              :     /// @{
     867              : 
     868              :     /** @brief Sends a SimulationStep command
     869              :      */
     870              :     void send_commandSimulationStep(double time) const;
     871              : 
     872              : 
     873              :     /** @brief Sends a Close command
     874              :      */
     875              :     void send_commandClose() const;
     876              : 
     877              : 
     878              :     /** @brief Sends a SetOrder command
     879              :      */
     880              :     void send_commandSetOrder(int order) const;
     881              : 
     882              :     /** @brief Sends a GetVariable / SetVariable request if mySocket is connected.
     883              :      * Otherwise writes to myOutput only.
     884              :      * @param[in] cmdID The command and domain of the variable
     885              :      * @param[in] varID The variable to retrieve
     886              :      * @param[in] objID The object to retrieve the variable from
     887              :      * @param[in] add Optional additional parameter
     888              :      */
     889              :     void createCommand(int cmdID, int varID, const std::string& objID, tcpip::Storage* add = nullptr) const;
     890              :     void createFilterCommand(int cmdID, int varID, tcpip::Storage* add = nullptr) const;
     891              : 
     892              : 
     893              :     /** @brief Sends a SubscribeVariable request
     894              :      * @param[in] domID The domain of the variable
     895              :      * @param[in] objID The object to subscribe the variables from
     896              :      * @param[in] beginTime The begin time step of subscriptions
     897              :      * @param[in] endTime The end time step of subscriptions
     898              :      * @param[in] vars The variables to subscribe
     899              :      */
     900              :     void send_commandSubscribeObjectVariable(int domID, const std::string& objID, double beginTime, double endTime, const std::vector<int>& vars) const;
     901              : 
     902              : 
     903              :     /** @brief Sends a SubscribeContext request
     904              :      * @param[in] domID The domain of the variable
     905              :      * @param[in] objID The object to subscribe the variables from
     906              :      * @param[in] beginTime The begin time step of subscriptions
     907              :      * @param[in] endTime The end time step of subscriptions
     908              :      * @param[in] domain The domain of the objects which values shall be returned
     909              :      * @param[in] range The range around the obj to investigate
     910              :      * @param[in] vars The variables to subscribe
     911              :      */
     912              :     void send_commandSubscribeObjectContext(int domID, const std::string& objID, double beginTime, double endTime,
     913              :                                             int domain, double range, const std::vector<int>& vars) const;
     914              :     /// @}
     915              : 
     916              : 
     917              :     /// @name Command sending methods
     918              :     /// @{
     919              : 
     920              :     /** @brief Validates the result state of a command
     921              :      * @param[in] inMsg The buffer to read the message from
     922              :      * @param[in] command The original command id
     923              :      * @param[in] ignoreCommandId Whether the returning command id shall be validated
     924              :      * @param[in] acknowledgement Pointer to an existing string into which the acknowledgement message shall be inserted
     925              :      */
     926              :     void check_resultState(tcpip::Storage& inMsg, int command, bool ignoreCommandId = false, std::string* acknowledgement = 0) const;
     927              : 
     928              :     /** @brief Validates the result state of a command
     929              :      * @return The command Id
     930              :      */
     931              :     int check_commandGetResult(tcpip::Storage& inMsg, int command, int expectedType = -1, bool ignoreCommandId = false) const;
     932              : 
     933              :     bool processGet(int command, int expectedType, bool ignoreCommandId = false);
     934              :     bool processSet(int command);
     935              :     /// @}
     936              : 
     937              :     void readVariableSubscription(int cmdId, tcpip::Storage& inMsg);
     938              :     void readContextSubscription(int cmdId, tcpip::Storage& inMsg);
     939              :     void readVariables(tcpip::Storage& inMsg, const std::string& objectID, int variableCount, libsumo::SubscriptionResults& into);
     940              : 
     941              :     template <class T>
     942         7295 :     static inline std::string toString(const T& t, std::streamsize accuracy = PRECISION) {
     943         7295 :         std::ostringstream oss;
     944              :         oss.setf(std::ios::fixed, std::ios::floatfield);
     945         7295 :         oss << std::setprecision(accuracy);
     946         7295 :         oss << t;
     947         7295 :         return oss.str();
     948         7295 :     }
     949              : 
     950              :     /// @brief Closes the connection
     951              :     void closeSocket();
     952              : 
     953              : protected:
     954              :     std::map<int, TraCIScopeWrapper*> myDomains;
     955              :     /// @brief The socket
     956              :     tcpip::Socket* mySocket;
     957              :     /// @brief The reusable output storage
     958              :     mutable tcpip::Storage myOutput;
     959              :     /// @brief The reusable input storage
     960              :     mutable tcpip::Storage myInput;
     961              : };
        

Generated by: LCOV version 2.0-1