1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2003-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 MSVehicleTransfer.h 11 /// @author Daniel Krajzewicz 12 /// @author Michael Behrisch 13 /// @author Jakob Erdmann 14 /// @date Sep 2003 15 /// @version $Id$ 16 /// 17 // A mover of vehicles that got stucked due to grid locks 18 // This class also serves as container for parking vehicles 19 /****************************************************************************/ 20 #ifndef MSVehicleTransfer_h 21 #define MSVehicleTransfer_h 22 23 24 // =========================================================================== 25 // included modules 26 // =========================================================================== 27 #include <config.h> 28 29 #include <string> 30 #include <vector> 31 #include <map> 32 #include <set> 33 #include <utils/foxtools/FXSynchQue.h> 34 35 36 // =========================================================================== 37 // class declarations 38 // =========================================================================== 39 class MSEdge; 40 class MSLane; 41 class MSVehicle; 42 class MSVehicleControl; 43 class SUMOSAXAttributes; 44 45 46 // =========================================================================== 47 // class definitions 48 // =========================================================================== 49 /** 50 * @class MSVehicleTransfer 51 * This object (each simulation owns exactly one) is responsible for the 52 * transfer of vehicles that got stuck within the network due to grid locks. 53 * It also manages vehicles that are removed from the network because of stops 54 * with the parking attribute. 55 * 56 * The method add is called by a lane if a vehicle stood to long at this 57 * lane's end. After being added to this transfer object and removed from the 58 * lane, it is moved over the consecutive edges. On each edge, it is tried to 59 * insert the vehicle again. The lanes are of course chosen by examining the 60 * vehicle's real route. 61 * 62 * This object is used as a singleton 63 */ 64 class MSVehicleTransfer { 65 public: 66 /// @brief Destructor 67 virtual ~MSVehicleTransfer(); 68 69 70 /** @brief Adds a vehicle to this transfer object 71 * 72 * The vehicle is removed from the network as it would end the trip. 73 * If the vehicle's next edge is his last one, the vehicle is also 74 * removed from the vehicle control. 75 * 76 * @param[in] veh The vehicle to add 77 */ 78 void add(const SUMOTime t, MSVehicle* veh); 79 80 81 /** @brief Remove a vehicle from this transfer object 82 * 83 * The vehicle is removed from the transfer if present. 84 * This should be necessary only in the context of TraCI removals. 85 * 86 * @param[in] veh The vehicle to remove 87 */ 88 void remove(MSVehicle* veh); 89 90 91 /** @brief Checks "movement" of stored vehicles 92 * 93 * Checks whether one of the stored vehicles may be inserted back into 94 * the network. If not, the vehicle may move virtually to the next lane 95 * of it's route 96 * 97 * @param[in] time The current simulation time 98 */ 99 void checkInsertions(SUMOTime time); 100 101 102 /** @brief Saves the current state into the given stream */ 103 void saveState(OutputDevice& out); 104 105 /** @brief Loads one transfer vehicle state from the given descriptionn */ 106 void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset, MSVehicleControl& vc); 107 108 /** @brief Returns the instance of this object 109 * @return The singleton instance 110 */ 111 static MSVehicleTransfer* getInstance(); 112 113 /// @brief The minimum speed while teleporting 114 static const double TeleportMinSpeed; 115 116 private: 117 /// @brief Constructor 118 MSVehicleTransfer(); 119 120 121 protected: 122 /** 123 * @struct VehicleInformation 124 * @brief Holds the information needed to move the vehicle over the network 125 */ 126 struct VehicleInformation { 127 /// @brief the time at which this vehicle was removed from the network 128 SUMOTime myTransferTime; 129 /// @brief The vehicle itself 130 MSVehicle* myVeh; 131 /// @brief The time at which the vehicle should be moved virtually one edge further 132 SUMOTime myProceedTime; 133 /// @brief whether the vehicle is or was parking 134 bool myParking; 135 136 /** @brief Constructor 137 * @param[in] veh The teleported vehicle 138 * @param[in] insertTime The time the vehicle was inserted at 139 * @param[in] proceedTime The time at which the vehicle should be moved virtually one edge further 140 */ VehicleInformationVehicleInformation141 VehicleInformation(SUMOTime t, MSVehicle* veh, SUMOTime proceedTime, bool parking) 142 : myTransferTime(t), myVeh(veh), myProceedTime(proceedTime), myParking(parking) { } 143 144 /// @brief sort by vehicle ID for repeatable parallel simulation 145 bool operator<(const VehicleInformation& v2) const; 146 }; 147 148 149 /// @brief The information about stored vehicles to move virtually 150 FXSynchQue<VehicleInformation, std::vector<VehicleInformation> > myVehicles; 151 152 /// @brief The static singleton-instance 153 static MSVehicleTransfer* myInstance; 154 155 }; 156 157 158 #endif 159 160 /****************************************************************************/ 161 162