1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2012-2019 German Aerospace Center (DLR) and others. 4 // This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v2.0 6 // which accompanies this distribution, and is available at 7 // http://www.eclipse.org/legal/epl-v20.html 8 // SPDX-License-Identifier: EPL-2.0 9 /****************************************************************************/ 10 /// @file Simulation.h 11 /// @author Robert Hilbrich 12 /// @date 15.09.2017 13 /// @version $Id$ 14 /// 15 // C++ TraCI client API implementation 16 /****************************************************************************/ 17 #ifndef Simulation_h 18 #define Simulation_h 19 20 21 // =========================================================================== 22 // included modules 23 // =========================================================================== 24 #include <config.h> 25 26 #include <vector> 27 #include <libsumo/TraCIDefs.h> 28 #include <libsumo/TraCIConstants.h> 29 30 31 // =========================================================================== 32 // class declarations 33 // =========================================================================== 34 namespace libsumo { 35 class VariableWrapper; 36 } 37 38 39 // =========================================================================== 40 // class definitions 41 // =========================================================================== 42 /** 43 * @class Simulation 44 * @brief C++ TraCI client API implementation 45 */ 46 namespace libsumo { 47 class Simulation { 48 public: 49 /// @brief load a simulation with the given arguments 50 static void load(const std::vector<std::string>& args); 51 52 /// @brief return whether a simulation (network) is present 53 static bool isLoaded(); 54 55 /// @brief close simulation 56 static void close(); 57 58 /// @brief Advances by one step (or up to the given time) 59 static void step(const double time = 0.); 60 61 static int getCurrentTime(); 62 static double getTime(); 63 64 static int getLoadedNumber(); 65 static std::vector<std::string> getLoadedIDList(); 66 static int getDepartedNumber(); 67 static std::vector<std::string> getDepartedIDList(); 68 static int getArrivedNumber(); 69 static std::vector<std::string> getArrivedIDList(); 70 static int getParkingStartingVehiclesNumber(); 71 static std::vector<std::string> getParkingStartingVehiclesIDList(); 72 static int getParkingEndingVehiclesNumber(); 73 static std::vector<std::string> getParkingEndingVehiclesIDList(); 74 static int getStopStartingVehiclesNumber(); 75 static std::vector<std::string> getStopStartingVehiclesIDList(); 76 static int getStopEndingVehiclesNumber(); 77 static std::vector<std::string> getStopEndingVehiclesIDList(); 78 static int getCollidingVehiclesNumber(); 79 static std::vector<std::string> getCollidingVehiclesIDList(); 80 static int getEmergencyStoppingVehiclesNumber(); 81 static std::vector<std::string> getEmergencyStoppingVehiclesIDList(); 82 static int getStartingTeleportNumber(); 83 static std::vector<std::string> getStartingTeleportIDList(); 84 static int getEndingTeleportNumber(); 85 static std::vector<std::string> getEndingTeleportIDList(); 86 87 static int getBusStopWaiting(const std::string& id); 88 89 static double getDeltaT(); 90 91 static TraCIPositionVector getNetBoundary(); 92 93 static TraCIPosition convert2D(const std::string& edgeID, double pos, int laneIndex = 0, bool toGeo = false); 94 95 static TraCIPosition convert3D(const std::string& edgeID, double pos, int laneIndex = 0, bool toGeo = false); 96 97 static TraCIRoadPosition convertRoad(double x, double y, bool isGeo = false, const std::string& vClass = "ignoring"); 98 99 static TraCIPosition convertGeo(double x, double y, bool fromGeo = false); 100 101 static double getDistance2D(double x1, double y1, double x2, double y2, bool isGeo = false, bool isDriving = false); 102 static double getDistanceRoad(const std::string& edgeID1, double pos1, const std::string& edgeID2, double pos2, bool isDriving = false); 103 104 static int getMinExpectedNumber(); 105 106 static TraCIStage findRoute(const std::string& fromEdge, const std::string& toEdge, const std::string& vType = "", const double depart = -1., const int routingMode = 0); 107 108 /* @note: default arrivalPos is not -1 because this would lead to very short walks when moving against the edge direction, 109 * instead the middle of the edge is used. DepartPos is treated differently so that 1-edge walks do not have length 0. 110 */ 111 static std::vector<TraCIStage> findIntermodalRoute(const std::string& fromEdge, const std::string& toEdge, const std::string& modes = "", 112 double depart = -1., const int routingMode = 0, double speed = -1., double walkFactor = -1., 113 double departPos = 0, double arrivalPos = INVALID_DOUBLE_VALUE, const double departPosLat = 0, 114 const std::string& pType = "", const std::string& vType = "", const std::string& destStop = ""); 115 116 static std::string getParameter(const std::string& objectID, const std::string& key); 117 118 static void clearPending(const std::string& routeID = ""); 119 static void saveState(const std::string& fileName); 120 121 LIBSUMO_SUBSCRIPTION_API 122 static void subscribe(const std::vector<int>& vars = std::vector<int>(), double beginTime = INVALID_DOUBLE_VALUE, double endTime = INVALID_DOUBLE_VALUE); 123 static const TraCIResults getSubscriptionResults(); 124 125 static std::shared_ptr<VariableWrapper> makeWrapper(); 126 127 static bool handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper); 128 129 private: 130 static SubscriptionResults mySubscriptionResults; 131 static ContextSubscriptionResults myContextSubscriptionResults; 132 133 /// @brief invalidated standard constructor 134 Simulation() = delete; 135 }; 136 137 138 } 139 140 141 #endif 142 143 /****************************************************************************/ 144