1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2001-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 MSTransportableControl.h 11 /// @author Daniel Krajzewicz 12 /// @author Jakob Erdmann 13 /// @author Sascha Krieg 14 /// @author Michael Behrisch 15 /// @date Mon, 9 Jul 2001 16 /// @version $Id$ 17 /// 18 // Stores all persons or containers in the net and handles their waiting for cars. 19 /****************************************************************************/ 20 #ifndef MSTransportableControl_h 21 #define MSTransportableControl_h 22 23 24 // =========================================================================== 25 // included modules 26 // =========================================================================== 27 #include <config.h> 28 29 #include <vector> 30 #include <map> 31 #include "MSTransportable.h" 32 #include "MSVehicle.h" 33 34 35 // =========================================================================== 36 // class declarations 37 // =========================================================================== 38 class MSNet; 39 40 41 // =========================================================================== 42 // class definitions 43 // =========================================================================== 44 /** 45 * 46 * @class MSTransportableControl 47 * The class is used to handle transportables (persons and containers) 48 * who are not using a transportation 49 * system but are walking or waiting. This includes waiting 50 * for the arrival or departure time / the time the waiting is over. 51 */ 52 class MSTransportableControl { 53 public: 54 /// @brief Definition of a list of transportables 55 typedef std::vector<MSTransportable*> TransportableVector; 56 57 /// @brief Definition of the internal transportables map iterator 58 typedef std::map<std::string, MSTransportable*>::const_iterator constVehIt; 59 60 61 public: 62 /// @brief Constructor 63 MSTransportableControl(); 64 65 66 /// @brief Destructor 67 virtual ~MSTransportableControl(); 68 69 70 /** @brief Adds a single transportable, returns false if an id clash occurred 71 * @param[in] transportable The transportable to add 72 * @return Whether the transportable could be added (none with the same id existed before) 73 */ 74 bool add(MSTransportable* transportable); 75 76 77 /** @brief Returns the named transportable, if existing 78 * @param[in] id The id of the transportable 79 * @return The named transportable, if existing, otherwise 0 80 */ 81 MSTransportable* get(const std::string& id) const; 82 83 84 /// removes a single transportable 85 virtual void erase(MSTransportable* transportable); 86 87 /// sets the arrival time for a waiting transportable 88 void setWaitEnd(SUMOTime time, MSTransportable* transportable); 89 90 /// checks whether any transportables waiting time is over 91 void checkWaiting(MSNet* net, const SUMOTime time); 92 93 /// adds a transportable to the list of transportables waiting for a vehicle on the specified edge 94 void addWaiting(const MSEdge* edge, MSTransportable* person); 95 96 /** @brief board any applicable persons 97 * Boards any people who wait on that edge for the given vehicle and removes them from myWaiting 98 * @param[in] the edge on which the boarding should take place 99 * @param[in] the vehicle which is taking on passengers / goods 100 * @param[in] the stop at which the vehicle is stopping 101 * @return Whether any transportables have been boarded 102 */ 103 bool boardAnyWaiting(MSEdge* edge, SUMOVehicle* vehicle, const SUMOVehicleParameter::Stop& stop, SUMOTime& timeToBoardNextPerson, SUMOTime& stopDuration); 104 105 /** @brief load any applicable containers 106 * Loads any container that is waiting on that edge for the given vehicle and removes them from myWaiting 107 * @param[in] the edge on which the loading should take place 108 * @param[in] the vehicle which is taking on containers 109 * @return Whether any containers have been loaded 110 */ 111 bool loadAnyWaiting(MSEdge* edge, SUMOVehicle* vehicle, const SUMOVehicleParameter::Stop& stop, SUMOTime& timeToLoadNextContainer, SUMOTime& stopDuration); 112 113 /// checks whether any transportable waits to finish her plan 114 bool hasTransportables() const; 115 116 /// checks whether any transportable is still engaged in walking / stopping 117 bool hasNonWaiting() const; 118 119 /// @brief return the number of active transportable objects 120 int getActiveCount(); 121 122 /// aborts the plan for any transportable that is still waiting for a ride 123 void abortWaitingForVehicle(); 124 125 /// aborts waiting stage of transportable 126 void abortWaiting(MSTransportable* t); 127 128 /** @brief Builds a new person 129 * @param[in] pars The parameter 130 * @param[in] vtype The type (reusing vehicle type container here) 131 * @param[in] plan This person's plan 132 * @param[in] rng The RNG to compute the optional speed deviation 133 */ 134 virtual MSTransportable* buildPerson(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportable::MSTransportablePlan* plan, 135 std::mt19937* rng) const; 136 137 /** @brief Builds a new container 138 * @param[in] pars The parameter 139 * @param[in] vtype The type (reusing vehicle type container here) 140 * @param[in] plan This container's plan 141 */ 142 virtual MSTransportable* buildContainer(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportable::MSTransportablePlan* plan) const; 143 144 /** @brief Returns the begin of the internal transportables map 145 * @return The begin of the internal transportables map 146 */ loadedBegin()147 constVehIt loadedBegin() const { 148 return myTransportables.begin(); 149 } 150 151 152 /** @brief Returns the end of the internal transportables map 153 * @return The end of the internal transportables map 154 */ loadedEnd()155 constVehIt loadedEnd() const { 156 return myTransportables.end(); 157 } 158 159 160 /** @brief Returns the number of known transportables 161 * @return The number of stored transportables 162 */ size()163 int size() const { 164 return (int)myTransportables.size(); 165 } 166 167 /// @brief register a jammed transportable registerJammed()168 void registerJammed() { 169 myJammedNumber++; 170 } 171 172 /// @name Retrieval of transportable statistics (always accessable) 173 /// @{ 174 175 /** @brief Returns the number of build transportables 176 * @return The number of loaded (build) transportables 177 */ getLoadedNumber()178 int getLoadedNumber() const { 179 return myLoadedNumber; 180 } 181 182 183 /** @brief Returns the number of build and inserted, but not yet deleted transportables 184 * @return The number of simulated transportables 185 */ getRunningNumber()186 int getRunningNumber() const { 187 return myRunningNumber; 188 } 189 190 /** @brief Returns the number of times a transportables was jammed 191 * @return The number of times transportables were jammed 192 */ getJammedNumber()193 int getJammedNumber() const { 194 return myJammedNumber; 195 } 196 197 /** @brief Returns the number of vehicles waiting for a ride 198 */ getWaitingForVehicleNumber()199 int getWaitingForVehicleNumber() const { 200 return myWaitingForVehicleNumber; 201 } 202 203 /// @} 204 205 protected: 206 /// all currently created transportables by id 207 std::map<std::string, MSTransportable*> myTransportables; 208 209 /// @brief Transportables waiting for departure 210 std::map<SUMOTime, TransportableVector> myWaiting4Departure; 211 212 /// the lists of walking / stopping transportables 213 std::map<SUMOTime, TransportableVector> myWaitingUntil; 214 215 /// the lists of waiting transportables 216 std::map<const MSEdge*, TransportableVector> myWaiting4Vehicle; 217 218 /// @brief The number of build transportables 219 int myLoadedNumber; 220 221 /// @brief The number of transportables within the network (build and inserted but not removed) 222 int myRunningNumber; 223 224 /// @brief The number of jammed transportables 225 int myJammedNumber; 226 227 /// @brief The number of transportables waiting for vehicles 228 int myWaitingForVehicleNumber; 229 230 /// @brief whether a new transportable waiting for a vehicle has been added in the last step 231 bool myHaveNewWaiting; 232 233 }; 234 235 236 #endif 237 238 /****************************************************************************/ 239