Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2025 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 MSVehicleControl.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Jakob Erdmann
17 : /// @author Michael Behrisch
18 : /// @date Wed, 10. Dec 2003
19 : ///
20 : // The class responsible for building and deletion of vehicles
21 : /****************************************************************************/
22 : #include <config.h>
23 :
24 : #include "MSVehicleControl.h"
25 : #include "MSVehicle.h"
26 : #include "MSLane.h"
27 : #include "MSEdge.h"
28 : #include "MSNet.h"
29 : #include "MSRouteHandler.h"
30 : #include "MSEventControl.h"
31 : #include "MSStop.h"
32 : #include <microsim/devices/MSVehicleDevice.h>
33 : #include <microsim/devices/MSDevice_Tripinfo.h>
34 : #include <utils/common/FileHelpers.h>
35 : #include <utils/common/Named.h>
36 : #include <utils/common/RGBColor.h>
37 : #include <utils/vehicle/SUMOVTypeParameter.h>
38 : #include <utils/iodevices/OutputDevice.h>
39 : #include <utils/options/OptionsCont.h>
40 : #include <utils/router/IntermodalRouter.h>
41 :
42 :
43 : // ===========================================================================
44 : // member method definitions
45 : // ===========================================================================
46 39025 : MSVehicleControl::MSVehicleControl() :
47 39025 : myLoadedVehNo(0),
48 39025 : myRunningVehNo(0),
49 39025 : myEndedVehNo(0),
50 39025 : myDiscarded(0),
51 39025 : myCollisions(0),
52 39025 : myTeleportsCollision(0),
53 39025 : myTeleportsJam(0),
54 39025 : myTeleportsYield(0),
55 39025 : myTeleportsWrongLane(0),
56 39025 : myEmergencyStops(0),
57 39025 : myEmergencyBrakingCount(0),
58 39025 : myStoppedVehicles(0),
59 39025 : myTotalDepartureDelay(0),
60 39025 : myTotalTravelTime(0),
61 39025 : myWaitingForTransportable(0),
62 39025 : myMaxSpeedFactor(1),
63 39025 : myMinDeceleration(SUMOVTypeParameter::getDefaultDecel(SVC_IGNORING)),
64 39025 : myMinDecelerationRail(SUMOVTypeParameter::getDefaultDecel(SVC_RAIL)),
65 78050 : myPendingRemovals(MSGlobals::gNumSimThreads > 1) {
66 :
67 39025 : initDefaultTypes();
68 39025 : myScale = OptionsCont::getOptions().getFloat("scale");
69 39025 : myKeepTime = string2time(OptionsCont::getOptions().getString("keep-after-arrival"));
70 39025 : }
71 :
72 :
73 65777 : MSVehicleControl::~MSVehicleControl() {
74 38415 : clearState(false);
75 65777 : }
76 :
77 :
78 : void
79 39212 : MSVehicleControl::initDefaultTypes() {
80 39212 : SUMOVTypeParameter defType(DEFAULT_VTYPE_ID, SVC_PASSENGER);
81 39212 : myVTypeDict[DEFAULT_VTYPE_ID] = MSVehicleType::build(defType);
82 :
83 39212 : SUMOVTypeParameter defPedType(DEFAULT_PEDTYPE_ID, SVC_PEDESTRIAN);
84 39212 : defPedType.parametersSet |= VTYPEPARS_VEHICLECLASS_SET;
85 39212 : myVTypeDict[DEFAULT_PEDTYPE_ID] = MSVehicleType::build(defPedType);
86 :
87 39212 : SUMOVTypeParameter defBikeType(DEFAULT_BIKETYPE_ID, SVC_BICYCLE);
88 39212 : defBikeType.parametersSet |= VTYPEPARS_VEHICLECLASS_SET;
89 39212 : myVTypeDict[DEFAULT_BIKETYPE_ID] = MSVehicleType::build(defBikeType);
90 :
91 39212 : SUMOVTypeParameter defTaxiType(DEFAULT_TAXITYPE_ID, SVC_TAXI);
92 39212 : defTaxiType.parametersSet |= VTYPEPARS_VEHICLECLASS_SET;
93 39212 : myVTypeDict[DEFAULT_TAXITYPE_ID] = MSVehicleType::build(defTaxiType);
94 :
95 39212 : SUMOVTypeParameter defRailType(DEFAULT_RAILTYPE_ID, SVC_RAIL);
96 39212 : defRailType.parametersSet |= VTYPEPARS_VEHICLECLASS_SET;
97 39212 : myVTypeDict[DEFAULT_RAILTYPE_ID] = MSVehicleType::build(defRailType);
98 :
99 39212 : SUMOVTypeParameter defContainerType(DEFAULT_CONTAINERTYPE_ID, SVC_CONTAINER);
100 39212 : defContainerType.parametersSet |= VTYPEPARS_VEHICLECLASS_SET;
101 39212 : myVTypeDict[DEFAULT_CONTAINERTYPE_ID] = MSVehicleType::build(defContainerType);
102 :
103 : myReplaceableDefaultVTypes = DEFAULT_VTYPES;
104 39212 : }
105 :
106 :
107 : SUMOVehicle*
108 4133841 : MSVehicleControl::buildVehicle(SUMOVehicleParameter* defs,
109 : ConstMSRoutePtr route, MSVehicleType* type,
110 : const bool ignoreStopErrors, const VehicleDefinitionSource source, bool addRouteStops) {
111 4133841 : const double speedFactor = (source == VehicleDefinitionSource::STATE ? 1 :
112 4232029 : type->computeChosenSpeedDeviation(source == VehicleDefinitionSource::ROUTEFILE ? MSRouteHandler::getParsingRNG() : nullptr));
113 8267682 : MSVehicle* built = new MSVehicle(defs, route, type, speedFactor);
114 4133841 : initVehicle(built, ignoreStopErrors, addRouteStops, source);
115 4133785 : return built;
116 : }
117 :
118 :
119 : void
120 5371078 : MSVehicleControl::initVehicle(MSBaseVehicle* built, const bool ignoreStopErrors, bool addRouteStops, const VehicleDefinitionSource source) {
121 5371078 : myLoadedVehNo++;
122 : try {
123 5371078 : built->initDevices();
124 5371039 : if (source != VehicleDefinitionSource::STATE) {
125 5365496 : built->addStops(ignoreStopErrors, nullptr, addRouteStops);
126 : }
127 72 : } catch (ProcessError&) {
128 72 : delete built;
129 72 : throw;
130 72 : }
131 5371005 : MSNet::getInstance()->informVehicleStateListener(built, MSNet::VehicleState::BUILT);
132 5371005 : }
133 :
134 :
135 : void
136 3596187 : MSVehicleControl::scheduleVehicleRemoval(SUMOVehicle* veh, bool checkDuplicate) {
137 : assert(myRunningVehNo > 0);
138 3596187 : if (!checkDuplicate || !isPendingRemoval(veh)) {
139 3596187 : myPendingRemovals.push_back(veh);
140 : }
141 3596187 : }
142 :
143 :
144 : bool
145 17338 : MSVehicleControl::isPendingRemoval(SUMOVehicle* veh) {
146 : #ifdef HAVE_FOX
147 17338 : return myPendingRemovals.contains(veh);
148 : #else
149 : return std::find(myPendingRemovals.begin(), myPendingRemovals.end(), veh) == myPendingRemovals.end();
150 : #endif
151 : }
152 :
153 :
154 : void
155 119454398 : MSVehicleControl::removePending() {
156 130882491 : OutputDevice* const tripinfoOut = OptionsCont::getOptions().isSet("tripinfo-output") ? &OutputDevice::getDeviceByOption("tripinfo-output") : nullptr;
157 : #ifdef HAVE_FOX
158 : std::vector<SUMOVehicle*>& vehs = myPendingRemovals.getContainer();
159 : #else
160 : std::vector<SUMOVehicle*>& vehs = myPendingRemovals;
161 : #endif
162 119454398 : std::sort(vehs.begin(), vehs.end(), ComparatorNumericalIdLess());
163 123050581 : for (SUMOVehicle* const veh : vehs) {
164 3596183 : myTotalTravelTime += STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep() - veh->getDeparture());
165 3596183 : myRunningVehNo--;
166 3596183 : MSNet::getInstance()->informVehicleStateListener(veh, MSNet::VehicleState::ARRIVED);
167 : // vehicle is equipped with tripinfo device (not all vehicles are)
168 3596183 : const bool hasTripinfo = veh->getDevice(typeid(MSDevice_Tripinfo)) != nullptr;
169 6349075 : for (MSVehicleDevice* const dev : veh->getDevices()) {
170 3326046 : dev->generateOutput(hasTripinfo ? tripinfoOut : nullptr);
171 : }
172 3596183 : if (tripinfoOut != nullptr && hasTripinfo) {
173 : // close tag after tripinfo (possibly including emissions from another device) have been written
174 465306 : tripinfoOut->closeTag();
175 : }
176 3596183 : if (myKeepTime == 0) {
177 3596169 : deleteVehicle(veh);
178 : } else {
179 14 : deleteKeptVehicle(veh);
180 : }
181 : }
182 : vehs.clear();
183 119454398 : if (tripinfoOut != nullptr) {
184 : // there seem to be people who think reading an unfinished xml is a good idea ;-)
185 : tripinfoOut->flush();
186 : }
187 : #ifdef HAVE_FOX
188 : myPendingRemovals.unlock();
189 : #endif
190 119454398 : }
191 :
192 :
193 : void
194 18 : MSVehicleControl::deleteKeptVehicle(SUMOVehicle* veh) {
195 18 : myEndedVehNo++;
196 18 : MSNet::getInstance()->getEndOfTimestepEvents()->addEvent(new DeleteKeptVehicle(veh), SIMSTEP + myKeepTime);
197 18 : }
198 :
199 : void
200 3737243 : MSVehicleControl::vehicleDeparted(const SUMOVehicle& v) {
201 3737243 : ++myRunningVehNo;
202 3737243 : myTotalDepartureDelay += STEPS2TIME(v.getDeparture() - STEPFLOOR(v.getParameter().depart));
203 3737243 : MSNet::getInstance()->informVehicleStateListener(&v, MSNet::VehicleState::DEPARTED);
204 3737243 : myMaxSpeedFactor = MAX2(myMaxSpeedFactor, v.getChosenSpeedFactor());
205 3737243 : if ((v.getVClass() & (SVC_PEDESTRIAN | SVC_NON_ROAD)) == 0) {
206 : // only worry about deceleration of road users
207 7261602 : myMinDeceleration = MIN2(myMinDeceleration, v.getVehicleType().getCarFollowModel().getMaxDecel());
208 7323 : } else if ((v.getVClass() & SVC_RAIL_CLASSES) != 0) {
209 13092 : myMinDecelerationRail = MIN2(myMinDecelerationRail, v.getVehicleType().getCarFollowModel().getMaxDecel());
210 : }
211 3737243 : }
212 :
213 :
214 : void
215 428 : MSVehicleControl::setState(int runningVehNo, int loadedVehNo, int endedVehNo, double totalDepartureDelay, double totalTravelTime) {
216 428 : myRunningVehNo = runningVehNo;
217 428 : myLoadedVehNo = loadedVehNo;
218 428 : myEndedVehNo = endedVehNo;
219 428 : myTotalDepartureDelay = totalDepartureDelay;
220 428 : myTotalTravelTime = totalTravelTime;
221 428 : }
222 :
223 :
224 : void
225 476 : MSVehicleControl::saveState(OutputDevice& out) {
226 476 : out.openTag(SUMO_TAG_DELAY);
227 476 : out.writeAttr(SUMO_ATTR_NUMBER, myRunningVehNo);
228 476 : out.writeAttr(SUMO_ATTR_BEGIN, myLoadedVehNo);
229 476 : out.writeAttr(SUMO_ATTR_END, myEndedVehNo);
230 476 : out.writeAttr(SUMO_ATTR_DEPART, myTotalDepartureDelay);
231 952 : out.writeAttr(SUMO_ATTR_TIME, myTotalTravelTime).closeTag();
232 : // save vehicle types
233 4098 : for (const auto& item : myVTypeDict) {
234 3622 : if (myReplaceableDefaultVTypes.count(item.first) == 0) {
235 984 : item.second->getParameter().write(out);
236 : }
237 : }
238 654 : for (const auto& item : myVTypeDistDict) {
239 178 : out.openTag(SUMO_TAG_VTYPE_DISTRIBUTION).writeAttr(SUMO_ATTR_ID, item.first);
240 178 : out.writeAttr(SUMO_ATTR_VTYPES, item.second->getVals());
241 178 : out.writeAttr(SUMO_ATTR_PROBS, item.second->getProbs());
242 356 : out.closeTag();
243 : }
244 : std::vector<SUMOVehicle*> sortedVehs;
245 4743 : for (const auto& item : myVehicleDict) {
246 4267 : sortedVehs.push_back(item.second);
247 : }
248 476 : std::sort(sortedVehs.begin(), sortedVehs.end(), ComparatorNumericalIdLess());
249 4743 : for (SUMOVehicle* veh : sortedVehs) {
250 4267 : veh->saveState(out);
251 : }
252 476 : }
253 :
254 :
255 : void
256 38602 : MSVehicleControl::clearState(const bool reinit) {
257 910061 : for (const auto& item : myVehicleDict) {
258 871459 : delete item.second;
259 : }
260 : myVehicleDict.clear();
261 : // delete vehicle type distributions
262 39048 : for (const auto& item : myVTypeDistDict) {
263 892 : delete item.second;
264 : }
265 : myVTypeDistDict.clear();
266 : // delete vehicle types
267 320734 : for (const auto& item : myVTypeDict) {
268 282132 : delete item.second;
269 : }
270 : myVTypeDict.clear();
271 38602 : myPendingRemovals.clear(); // could be leftovers from MSVehicleTransfer::checkInsertions (teleport beyond arrival)
272 38602 : if (reinit) {
273 187 : initDefaultTypes();
274 : }
275 38602 : myLoadedVehNo = 0;
276 38602 : myRunningVehNo = 0;
277 38602 : myEndedVehNo = 0;
278 38602 : myDiscarded = 0;
279 38602 : myCollisions = 0;
280 38602 : myTeleportsCollision = 0;
281 38602 : myTeleportsJam = 0;
282 38602 : myTeleportsYield = 0;
283 38602 : myTeleportsWrongLane = 0;
284 38602 : myEmergencyStops = 0;
285 38602 : myEmergencyBrakingCount = 0;
286 38602 : myStoppedVehicles = 0;
287 38602 : myTotalDepartureDelay = 0;
288 38602 : myTotalTravelTime = 0;
289 38602 : }
290 :
291 :
292 : bool
293 5266236 : MSVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
294 : VehicleDictType::iterator it = myVehicleDict.find(id);
295 5266236 : if (it == myVehicleDict.end()) {
296 : // id not in myVehicleDict.
297 5266236 : myVehicleDict[id] = v;
298 5266236 : handleTriggeredDepart(v, true);
299 5266236 : const SUMOVehicleParameter& pars = v->getParameter();
300 5266236 : if (v->getVClass() != SVC_TAXI && pars.line != "" && pars.repetitionNumber < 0) {
301 1078 : myPTVehicles.push_back(v);
302 : }
303 5266236 : return true;
304 : }
305 : return false;
306 : }
307 :
308 :
309 : void
310 5270764 : MSVehicleControl::handleTriggeredDepart(SUMOVehicle* v, bool add) {
311 5270764 : const SUMOVehicleParameter& pars = v->getParameter();
312 5270764 : if (pars.departProcedure == DepartDefinition::TRIGGERED || pars.departProcedure == DepartDefinition::CONTAINER_TRIGGERED || pars.departProcedure == DepartDefinition::SPLIT) {
313 4210 : const MSEdge* const firstEdge = v->getRoute().getEdges()[pars.departEdge];
314 4210 : if (add) {
315 2170 : if (!MSGlobals::gUseMesoSim) {
316 : // position will be checked against person position later
317 1785 : static_cast<MSVehicle*>(v)->setTentativeLaneAndPosition(nullptr, v->getParameter().departPos);
318 : }
319 2170 : if (firstEdge->isTazConnector()) {
320 78 : for (MSEdge* out : firstEdge->getSuccessors()) {
321 51 : out->addWaiting(v);
322 : }
323 : } else {
324 2143 : firstEdge->addWaiting(v);
325 : }
326 : registerOneWaiting();
327 : } else {
328 2040 : if (firstEdge->isTazConnector()) {
329 14 : for (MSEdge* out : firstEdge->getSuccessors()) {
330 7 : out->removeWaiting(v);
331 : }
332 : } else {
333 2033 : firstEdge->removeWaiting(v);
334 : }
335 : unregisterOneWaiting();
336 : }
337 : }
338 5270764 : }
339 :
340 :
341 : SUMOVehicle*
342 22190408 : MSVehicleControl::getVehicle(const std::string& id) const {
343 : VehicleDictType::const_iterator it = myVehicleDict.find(id);
344 22190408 : if (it == myVehicleDict.end()) {
345 : return nullptr;
346 : }
347 16751150 : return it->second;
348 : }
349 :
350 :
351 : void
352 4499470 : MSVehicleControl::deleteVehicle(SUMOVehicle* veh, bool discard, bool wasKept) {
353 4499470 : if (!wasKept) {
354 4499456 : myEndedVehNo++;
355 4499456 : if (discard) {
356 903287 : myDiscarded++;
357 : }
358 : }
359 4499470 : if (veh != nullptr) {
360 : myVehicleDict.erase(veh->getID());
361 : }
362 4499470 : auto ptVehIt = std::find(myPTVehicles.begin(), myPTVehicles.end(), veh);
363 4499470 : if (ptVehIt != myPTVehicles.end()) {
364 942 : myPTVehicles.erase(ptVehIt);
365 : }
366 4499470 : delete veh;
367 4499470 : }
368 :
369 :
370 : bool
371 62334 : MSVehicleControl::checkVType(const std::string& id) {
372 62334 : if (myReplaceableDefaultVTypes.erase(id) > 0) {
373 9598 : delete myVTypeDict[id];
374 : myVTypeDict.erase(myVTypeDict.find(id));
375 : } else {
376 52736 : if (myVTypeDict.find(id) != myVTypeDict.end() || myVTypeDistDict.find(id) != myVTypeDistDict.end()) {
377 186 : return false;
378 : }
379 : }
380 : return true;
381 : }
382 :
383 :
384 : bool
385 61888 : MSVehicleControl::addVType(MSVehicleType* vehType) {
386 61888 : if (checkVType(vehType->getID())) {
387 61702 : myVTypeDict[vehType->getID()] = vehType;
388 61702 : return true;
389 : }
390 : return false;
391 : }
392 :
393 :
394 : void
395 1432 : MSVehicleControl::removeVType(const MSVehicleType* vehType) {
396 : assert(vehType != nullptr);
397 : assert(myVTypeDict.find(vehType->getID()) != myVTypeDict.end());
398 : myVTypeDict.erase(vehType->getID());
399 1432 : if (myVTypeToDist.find(vehType->getID()) != myVTypeToDist.end()) {
400 : myVTypeToDist.erase(vehType->getID());
401 : }
402 1432 : delete vehType;
403 1432 : }
404 :
405 :
406 : bool
407 446 : MSVehicleControl::addVTypeDistribution(const std::string& id, RandomDistributor<MSVehicleType*>* vehTypeDistribution) {
408 446 : if (checkVType(id)) {
409 446 : myVTypeDistDict[id] = vehTypeDistribution;
410 446 : std::vector<MSVehicleType*> vehTypes = vehTypeDistribution->getVals();
411 1670 : for (auto vehType : vehTypes) {
412 1224 : if (myVTypeToDist.find(vehType->getID()) != myVTypeToDist.end()) {
413 42 : myVTypeToDist[vehType->getID()].insert(id);
414 : } else {
415 3546 : myVTypeToDist[vehType->getID()] = { id };
416 : }
417 : }
418 : return true;
419 446 : }
420 : return false;
421 : }
422 :
423 :
424 : bool
425 44010 : MSVehicleControl::hasVType(const std::string& id) const {
426 44010 : return myVTypeDict.count(id) > 0 || myVTypeDistDict.count(id) > 0;
427 : }
428 :
429 :
430 : bool
431 18252 : MSVehicleControl::hasVTypeDistribution(const std::string& id) const {
432 18252 : return myVTypeDistDict.count(id) > 0;
433 : }
434 :
435 :
436 : MSVehicleType*
437 7443443 : MSVehicleControl::getVType(const std::string& id, SumoRNG* rng, bool readOnly) {
438 : VTypeDictType::iterator it = myVTypeDict.find(id);
439 7443443 : if (it == myVTypeDict.end()) {
440 : VTypeDistDictType::iterator it2 = myVTypeDistDict.find(id);
441 1408381 : if (it2 == myVTypeDistDict.end()) {
442 : return nullptr;
443 : }
444 85935 : return it2->second->get(rng);
445 : }
446 12047616 : if (!readOnly && myReplaceableDefaultVTypes.erase(id) > 0) {
447 17707 : it->second->check();
448 : }
449 6035062 : return it->second;
450 : }
451 :
452 :
453 : void
454 333 : MSVehicleControl::insertVTypeIDs(std::vector<std::string>& into) const {
455 333 : into.reserve(into.size() + myVTypeDict.size() + myVTypeDistDict.size());
456 2621 : for (VTypeDictType::const_iterator i = myVTypeDict.begin(); i != myVTypeDict.end(); ++i) {
457 2288 : into.push_back((*i).first);
458 : }
459 333 : for (VTypeDistDictType::const_iterator i = myVTypeDistDict.begin(); i != myVTypeDistDict.end(); ++i) {
460 0 : into.push_back((*i).first);
461 : }
462 333 : }
463 :
464 :
465 : const std::set<std::string>
466 145439 : MSVehicleControl::getVTypeDistributionMembership(const std::string& id) const {
467 : std::map<std::string, std::set<std::string>>::const_iterator it = myVTypeToDist.find(id);
468 145439 : if (it == myVTypeToDist.end()) {
469 60989 : return std::set<std::string>();
470 : }
471 : return it->second;
472 : }
473 :
474 :
475 : const RandomDistributor<MSVehicleType*>*
476 133770 : MSVehicleControl::getVTypeDistribution(const std::string& typeDistID) const {
477 : const auto it = myVTypeDistDict.find(typeDistID);
478 133770 : if (it != myVTypeDistDict.end()) {
479 2184 : return it->second;
480 : }
481 : return nullptr;
482 : }
483 :
484 :
485 : const std::vector<MSVehicleType*>
486 0 : MSVehicleControl::getPedestrianTypes(void) const {
487 : std::vector<MSVehicleType*> pedestrianTypes;
488 0 : for (auto const& e : myVTypeDict)
489 0 : if (e.second->getVehicleClass() == SUMOVehicleClass::SVC_PEDESTRIAN) {
490 0 : pedestrianTypes.push_back(e.second);
491 : }
492 0 : return pedestrianTypes;
493 0 : }
494 :
495 :
496 : void
497 17763 : MSVehicleControl::abortWaiting() {
498 18688 : for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
499 925 : SUMOVehicle* veh = i->second;
500 : std::string waitReason;
501 925 : if (veh->isStoppedTriggered()) {
502 897 : const MSStop& stop = veh->getNextStop();
503 897 : if (stop.triggered) {
504 : waitReason = "for a person that will never come";
505 100 : } else if (stop.containerTriggered) {
506 : waitReason = "for a container that will never come";
507 12 : } else if (stop.joinTriggered) {
508 12 : if (stop.pars.join != "") {
509 18 : waitReason = "to be joined to vehicle '" + stop.pars.join + "'";
510 : } else {
511 : waitReason = "for a joining vehicle that will never come";
512 : }
513 : } else {
514 : waitReason = "for an unknown trigger";
515 : }
516 28 : } else if (!veh->hasDeparted()) {
517 28 : if (veh->getParameter().departProcedure == DepartDefinition::SPLIT) {
518 : waitReason = "for a train from which to split";
519 12 : } else if (veh->getParameter().departProcedure == DepartDefinition::TRIGGERED) {
520 : waitReason = "at insertion for a person that will never come";
521 0 : } else if (veh->getParameter().departProcedure == DepartDefinition::CONTAINER_TRIGGERED) {
522 : waitReason = "at insertion for a container that will never come";
523 : } else {
524 : waitReason = "for an unknown departure trigger";
525 : }
526 : } else {
527 : waitReason = "for an unknown reason";
528 : }
529 2775 : WRITE_WARNINGF(TL("Vehicle '%' aborted waiting %."), i->first, waitReason);
530 : }
531 17763 : }
532 :
533 :
534 : int
535 519951 : MSVehicleControl::getHaltingVehicleNo() const {
536 : int result = 0;
537 75199916 : for (MSVehicleControl::constVehIt it = loadedVehBegin(); it != loadedVehEnd(); ++it) {
538 74679965 : const SUMOVehicle* veh = it->second;
539 74679965 : if ((veh->isOnRoad() || veh->isRemoteControlled()) && veh->getSpeed() < SUMO_const_haltingSpeed) {
540 18831710 : result++;
541 : }
542 : }
543 519951 : return result;
544 : }
545 :
546 :
547 : std::pair<double, double>
548 519951 : MSVehicleControl::getVehicleMeanSpeeds() const {
549 : double speedSum = 0;
550 : double relSpeedSum = 0;
551 : int count = 0;
552 75199916 : for (MSVehicleControl::constVehIt it = loadedVehBegin(); it != loadedVehEnd(); ++it) {
553 74679965 : const SUMOVehicle* veh = it->second;
554 74679965 : if ((veh->isOnRoad() || veh->isRemoteControlled()) && !veh->isStopped()) {
555 41922592 : count++;
556 41922592 : speedSum += veh->getSpeed();
557 41922592 : relSpeedSum += veh->getEdge()->getSpeedLimit() > 0 ? veh->getSpeed() / veh->getEdge()->getSpeedLimit() : 0;
558 : }
559 : }
560 519951 : if (count > 0) {
561 425442 : return std::make_pair(speedSum / count, relSpeedSum / count);
562 : } else {
563 94509 : return std::make_pair(-1, -1);
564 : }
565 : }
566 :
567 :
568 : int
569 1342124 : MSVehicleControl::getQuota(double frac, int loaded) const {
570 1342124 : frac = frac < 0 ? myScale : frac;
571 : const int origLoaded = (loaded < 1
572 : // the vehicle in question has already been loaded, hence the '-1'
573 1342124 : ? frac > 1. ? (int)(myLoadedVehNo / frac) : myLoadedVehNo - 1
574 : // given transportable number reflects only previously loaded
575 504919 : : frac > 1. ? (int)(loaded / frac) : loaded);
576 1342124 : return getScalingQuota(frac, origLoaded);
577 : }
578 :
579 :
580 : int
581 548872 : MSVehicleControl::getTeleportCount() const {
582 548872 : return myTeleportsCollision + myTeleportsJam + myTeleportsYield + myTeleportsWrongLane;
583 : }
584 :
585 :
586 : void
587 4538 : MSVehicleControl::adaptIntermodalRouter(MSTransportableRouter& router) const {
588 4771 : for (const SUMOVehicle* const veh : myPTVehicles) {
589 : // add single vehicles with line attribute which are not part of a flow
590 233 : ConstMSRoutePtr const route = MSRoute::dictionary(veh->getParameter().routeid);
591 233 : router.getNetwork()->addSchedule(veh->getParameter(), route == nullptr ? nullptr : &route->getStops());
592 : }
593 4538 : }
594 :
595 : // ===========================================================================
596 : // MSVehicleControl::DeleteKeptVehicle method definitions
597 : // ===========================================================================
598 :
599 : SUMOTime
600 14 : MSVehicleControl::DeleteKeptVehicle::execute(SUMOTime /*currentTime*/) {
601 14 : MSNet::getInstance()->getVehicleControl().deleteVehicle(myVehicle, false, true);
602 14 : return 0;
603 : }
604 :
605 : /****************************************************************************/
|