Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2026 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 41242 : MSVehicleControl::MSVehicleControl() :
47 41242 : myLoadedVehNo(0),
48 41242 : myRunningVehNo(0),
49 41242 : myEndedVehNo(0),
50 41242 : myDiscarded(0),
51 41242 : myCollisions(0),
52 41242 : myTeleportsCollision(0),
53 41242 : myTeleportsJam(0),
54 41242 : myTeleportsYield(0),
55 41242 : myTeleportsWrongLane(0),
56 41242 : myEmergencyStops(0),
57 41242 : myEmergencyBrakingCount(0),
58 41242 : myStoppedVehicles(0),
59 41242 : myTotalDepartureDelay(0),
60 41242 : myTotalTravelTime(0),
61 41242 : myWaitingForTransportable(0),
62 41242 : myMaxSpeedFactor(1),
63 41242 : myMinDeceleration(SUMOVTypeParameter::getDefaultDecel(SVC_IGNORING)),
64 41242 : myMinDecelerationRail(SUMOVTypeParameter::getDefaultDecel(SVC_RAIL)),
65 82484 : myPendingRemovals(MSGlobals::gNumSimThreads > 1) {
66 :
67 41242 : initDefaultTypes();
68 41242 : myScale = OptionsCont::getOptions().getFloat("scale");
69 41242 : myKeepTime = string2time(OptionsCont::getOptions().getString("keep-after-arrival"));
70 41242 : }
71 :
72 :
73 69679 : MSVehicleControl::~MSVehicleControl() {
74 40631 : clearState(false);
75 69679 : }
76 :
77 :
78 : void
79 41428 : MSVehicleControl::initDefaultTypes() {
80 41428 : SUMOVTypeParameter defType(DEFAULT_VTYPE_ID, SVC_PASSENGER);
81 41428 : myVTypeDict[DEFAULT_VTYPE_ID] = MSVehicleType::build(defType);
82 :
83 41428 : SUMOVTypeParameter defPedType(DEFAULT_PEDTYPE_ID, SVC_PEDESTRIAN);
84 41428 : defPedType.parametersSet |= VTYPEPARS_VEHICLECLASS_SET;
85 41428 : myVTypeDict[DEFAULT_PEDTYPE_ID] = MSVehicleType::build(defPedType);
86 :
87 41428 : SUMOVTypeParameter defBikeType(DEFAULT_BIKETYPE_ID, SVC_BICYCLE);
88 41428 : defBikeType.parametersSet |= VTYPEPARS_VEHICLECLASS_SET;
89 41428 : myVTypeDict[DEFAULT_BIKETYPE_ID] = MSVehicleType::build(defBikeType);
90 :
91 41428 : SUMOVTypeParameter defTaxiType(DEFAULT_TAXITYPE_ID, SVC_TAXI);
92 41428 : defTaxiType.parametersSet |= VTYPEPARS_VEHICLECLASS_SET;
93 41428 : myVTypeDict[DEFAULT_TAXITYPE_ID] = MSVehicleType::build(defTaxiType);
94 :
95 41428 : SUMOVTypeParameter defRailType(DEFAULT_RAILTYPE_ID, SVC_RAIL);
96 41428 : defRailType.parametersSet |= VTYPEPARS_VEHICLECLASS_SET;
97 41428 : myVTypeDict[DEFAULT_RAILTYPE_ID] = MSVehicleType::build(defRailType);
98 :
99 41428 : SUMOVTypeParameter defContainerType(DEFAULT_CONTAINERTYPE_ID, SVC_CONTAINER);
100 41428 : defContainerType.parametersSet |= VTYPEPARS_VEHICLECLASS_SET;
101 41428 : myVTypeDict[DEFAULT_CONTAINERTYPE_ID] = MSVehicleType::build(defContainerType);
102 :
103 : myReplaceableDefaultVTypes = DEFAULT_VTYPES;
104 41428 : }
105 :
106 :
107 : SUMOVehicle*
108 4140620 : MSVehicleControl::buildVehicle(SUMOVehicleParameter* defs,
109 : ConstMSRoutePtr route, MSVehicleType* type,
110 : const bool ignoreStopErrors, const VehicleDefinitionSource source, bool addRouteStops) {
111 4140620 : const double speedFactor = (source == VehicleDefinitionSource::STATE ? 1 :
112 4239312 : type->computeChosenSpeedDeviation(source == VehicleDefinitionSource::ROUTEFILE ? MSRouteHandler::getParsingRNG() : nullptr));
113 8281240 : MSVehicle* built = new MSVehicle(defs, route, type, speedFactor);
114 4140620 : initVehicle(built, ignoreStopErrors, addRouteStops, source);
115 4140564 : return built;
116 : }
117 :
118 :
119 : void
120 5537928 : MSVehicleControl::initVehicle(MSBaseVehicle* built, const bool ignoreStopErrors, bool addRouteStops, const VehicleDefinitionSource source) {
121 5537928 : myLoadedVehNo++;
122 : try {
123 5537928 : built->initDevices();
124 5537889 : if (source != VehicleDefinitionSource::STATE) {
125 5532528 : built->addStops(ignoreStopErrors, nullptr, addRouteStops);
126 : }
127 72 : } catch (ProcessError&) {
128 72 : delete built;
129 72 : throw;
130 72 : }
131 5537855 : MSNet::getInstance()->informVehicleStateListener(built, MSNet::VehicleState::BUILT);
132 5537855 : }
133 :
134 :
135 : void
136 4286210 : MSVehicleControl::scheduleVehicleRemoval(SUMOVehicle* veh, bool checkDuplicate) {
137 : assert(myRunningVehNo > 0);
138 4286210 : if (!checkDuplicate || !isPendingRemoval(veh)) {
139 4286210 : myPendingRemovals.push_back(veh);
140 : }
141 4286210 : }
142 :
143 :
144 : bool
145 17549 : MSVehicleControl::isPendingRemoval(SUMOVehicle* veh) {
146 : #ifdef HAVE_FOX
147 17549 : 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 101034916 : MSVehicleControl::removePending() {
156 117926295 : 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 101034916 : std::sort(vehs.begin(), vehs.end(), ComparatorNumericalIdLess());
163 105321122 : for (SUMOVehicle* const veh : vehs) {
164 4286206 : myTotalTravelTime += STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep() - veh->getDeparture());
165 4286206 : myRunningVehNo--;
166 4286206 : MSNet::getInstance()->informVehicleStateListener(veh, MSNet::VehicleState::ARRIVED);
167 : // vehicle is equipped with tripinfo device (not all vehicles are)
168 4286206 : const bool hasTripinfo = veh->getDevice(typeid(MSDevice_Tripinfo)) != nullptr;
169 7505588 : for (MSVehicleDevice* const dev : veh->getDevices()) {
170 4094783 : dev->generateOutput(hasTripinfo ? tripinfoOut : nullptr);
171 : }
172 4286206 : if (tripinfoOut != nullptr && hasTripinfo) {
173 : // close tag after tripinfo (possibly including emissions from another device) have been written
174 472184 : tripinfoOut->closeTag();
175 : }
176 4286206 : if (myKeepTime == 0) {
177 4286194 : deleteVehicle(veh);
178 : } else {
179 12 : deleteKeptVehicle(veh);
180 : }
181 : }
182 : vehs.clear();
183 101034916 : 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 101034916 : }
191 :
192 :
193 : void
194 15 : MSVehicleControl::deleteKeptVehicle(SUMOVehicle* veh) {
195 15 : myEndedVehNo++;
196 15 : MSNet::getInstance()->getEndOfTimestepEvents()->addEvent(new DeleteKeptVehicle(veh), SIMSTEP + myKeepTime);
197 15 : }
198 :
199 : void
200 4424836 : MSVehicleControl::vehicleDeparted(const SUMOVehicle& v) {
201 4424836 : ++myRunningVehNo;
202 4424836 : myTotalDepartureDelay += STEPS2TIME(v.getDeparture() - STEPFLOOR(v.getParameter().depart));
203 4424836 : MSNet::getInstance()->informVehicleStateListener(&v, MSNet::VehicleState::DEPARTED);
204 4424836 : myMaxSpeedFactor = MAX2(myMaxSpeedFactor, v.getChosenSpeedFactor());
205 4424836 : if ((v.getVClass() & (SVC_PEDESTRIAN | SVC_NON_ROAD)) == 0) {
206 : // only worry about deceleration of road users
207 8635684 : myMinDeceleration = MIN2(myMinDeceleration, v.getVehicleType().getCarFollowModel().getMaxDecel());
208 7631 : } else if ((v.getVClass() & SVC_RAIL_CLASSES) != 0) {
209 13648 : myMinDecelerationRail = MIN2(myMinDecelerationRail, v.getVehicleType().getCarFollowModel().getMaxDecel());
210 : }
211 4424836 : }
212 :
213 :
214 : void
215 431 : MSVehicleControl::setState(int runningVehNo, int loadedVehNo, int endedVehNo, double totalDepartureDelay, double totalTravelTime) {
216 431 : myRunningVehNo = runningVehNo;
217 431 : myLoadedVehNo = loadedVehNo;
218 431 : myEndedVehNo = endedVehNo;
219 431 : myTotalDepartureDelay = totalDepartureDelay;
220 431 : myTotalTravelTime = totalTravelTime;
221 431 : }
222 :
223 :
224 : void
225 479 : MSVehicleControl::saveState(OutputDevice& out) {
226 479 : out.openTag(SUMO_TAG_DELAY);
227 479 : out.writeAttr(SUMO_ATTR_NUMBER, myRunningVehNo);
228 479 : out.writeAttr(SUMO_ATTR_BEGIN, myLoadedVehNo);
229 479 : out.writeAttr(SUMO_ATTR_END, myEndedVehNo);
230 479 : out.writeAttr(SUMO_ATTR_DEPART, myTotalDepartureDelay);
231 958 : out.writeAttr(SUMO_ATTR_TIME, myTotalTravelTime).closeTag();
232 : // save vehicle types
233 4122 : for (const auto& item : myVTypeDict) {
234 3643 : if (myReplaceableDefaultVTypes.count(item.first) == 0) {
235 988 : item.second->getParameter().write(out);
236 : }
237 : }
238 659 : for (const auto& item : myVTypeDistDict) {
239 180 : out.openTag(SUMO_TAG_VTYPE_DISTRIBUTION).writeAttr(SUMO_ATTR_ID, item.first);
240 180 : out.writeAttr(SUMO_ATTR_VTYPES, item.second->getVals());
241 180 : out.writeAttr(SUMO_ATTR_PROBS, item.second->getProbs());
242 360 : out.closeTag();
243 : }
244 : std::vector<SUMOVehicle*> sortedVehs;
245 4744 : for (const auto& item : myVehicleDict) {
246 4265 : sortedVehs.push_back(item.second);
247 : }
248 479 : std::sort(sortedVehs.begin(), sortedVehs.end(), ComparatorNumericalIdLess());
249 4744 : for (SUMOVehicle* veh : sortedVehs) {
250 4265 : veh->saveState(out);
251 : }
252 479 : }
253 :
254 :
255 : void
256 40817 : MSVehicleControl::clearState(const bool reinit) {
257 369538 : for (const auto& item : myVehicleDict) {
258 328721 : delete item.second;
259 : }
260 : myVehicleDict.clear();
261 : // delete vehicle type distributions
262 41269 : for (const auto& item : myVTypeDistDict) {
263 904 : delete item.second;
264 : }
265 : myVTypeDistDict.clear();
266 : // delete vehicle types
267 336605 : for (const auto& item : myVTypeDict) {
268 295788 : delete item.second;
269 : }
270 : myVTypeDict.clear();
271 40817 : myPendingRemovals.clear(); // could be leftovers from MSVehicleTransfer::checkInsertions (teleport beyond arrival)
272 40817 : if (reinit) {
273 186 : initDefaultTypes();
274 : }
275 40817 : myLoadedVehNo = 0;
276 40817 : myRunningVehNo = 0;
277 40817 : myEndedVehNo = 0;
278 40817 : myDiscarded = 0;
279 40817 : myCollisions = 0;
280 40817 : myTeleportsCollision = 0;
281 40817 : myTeleportsJam = 0;
282 40817 : myTeleportsYield = 0;
283 40817 : myTeleportsWrongLane = 0;
284 40817 : myEmergencyStops = 0;
285 40817 : myEmergencyBrakingCount = 0;
286 40817 : myStoppedVehicles = 0;
287 40817 : myTotalDepartureDelay = 0;
288 40817 : myTotalTravelTime = 0;
289 40817 : }
290 :
291 :
292 : bool
293 5432840 : MSVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
294 : VehicleDictType::iterator it = myVehicleDict.find(id);
295 5432840 : if (it == myVehicleDict.end()) {
296 : // id not in myVehicleDict.
297 5432840 : myVehicleDict[id] = v;
298 5432840 : handleTriggeredDepart(v, true);
299 5432840 : const SUMOVehicleParameter& pars = v->getParameter();
300 5432840 : if (v->getVClass() != SVC_TAXI && pars.line != "" && pars.repetitionNumber < 0) {
301 1084 : myPTVehicles.push_back(v);
302 : }
303 5432840 : return true;
304 : }
305 : return false;
306 : }
307 :
308 :
309 : void
310 5437328 : MSVehicleControl::handleTriggeredDepart(SUMOVehicle* v, bool add) {
311 5437328 : const SUMOVehicleParameter& pars = v->getParameter();
312 5437328 : if (pars.departProcedure == DepartDefinition::TRIGGERED || pars.departProcedure == DepartDefinition::CONTAINER_TRIGGERED || pars.departProcedure == DepartDefinition::SPLIT) {
313 4254 : const MSEdge* const firstEdge = v->getRoute().getEdges()[pars.departEdge];
314 4254 : if (add) {
315 2192 : if (!MSGlobals::gUseMesoSim) {
316 : // position will be checked against person position later
317 1805 : static_cast<MSVehicle*>(v)->setTentativeLaneAndPosition(nullptr, v->getParameter().departPos);
318 : }
319 2192 : if (firstEdge->isTazConnector()) {
320 78 : for (MSEdge* out : firstEdge->getSuccessors()) {
321 51 : out->addWaiting(v);
322 : }
323 : } else {
324 2165 : firstEdge->addWaiting(v);
325 : }
326 : registerOneWaiting();
327 : } else {
328 2062 : if (firstEdge->isTazConnector()) {
329 14 : for (MSEdge* out : firstEdge->getSuccessors()) {
330 7 : out->removeWaiting(v);
331 : }
332 : } else {
333 2055 : firstEdge->removeWaiting(v);
334 : }
335 : unregisterOneWaiting();
336 : }
337 : }
338 5437328 : }
339 :
340 :
341 : SUMOVehicle*
342 22699705 : MSVehicleControl::getVehicle(const std::string& id) const {
343 : VehicleDictType::const_iterator it = myVehicleDict.find(id);
344 22699705 : if (it == myVehicleDict.end()) {
345 : return nullptr;
346 : }
347 17085401 : return it->second;
348 : }
349 :
350 :
351 : void
352 5209052 : MSVehicleControl::deleteVehicle(SUMOVehicle* veh, bool discard, bool wasKept) {
353 5209052 : if (!wasKept) {
354 5209040 : myEndedVehNo++;
355 5209040 : if (discard) {
356 922846 : myDiscarded++;
357 : }
358 : }
359 5209052 : if (veh != nullptr) {
360 : myVehicleDict.erase(veh->getID());
361 : }
362 5209052 : auto ptVehIt = std::find(myPTVehicles.begin(), myPTVehicles.end(), veh);
363 5209052 : if (ptVehIt != myPTVehicles.end()) {
364 940 : myPTVehicles.erase(ptVehIt);
365 : }
366 5209052 : delete veh;
367 5209052 : }
368 :
369 :
370 : bool
371 62978 : MSVehicleControl::checkVType(const std::string& id) {
372 62978 : if (myReplaceableDefaultVTypes.erase(id) > 0) {
373 9851 : delete myVTypeDict[id];
374 : myVTypeDict.erase(myVTypeDict.find(id));
375 : } else {
376 53127 : if (myVTypeDict.find(id) != myVTypeDict.end() || myVTypeDistDict.find(id) != myVTypeDistDict.end()) {
377 185 : return false;
378 : }
379 : }
380 : return true;
381 : }
382 :
383 :
384 : bool
385 62526 : MSVehicleControl::addVType(MSVehicleType* vehType) {
386 62526 : if (checkVType(vehType->getID())) {
387 62341 : myVTypeDict[vehType->getID()] = vehType;
388 62341 : return true;
389 : }
390 : return false;
391 : }
392 :
393 :
394 : void
395 1436 : MSVehicleControl::removeVType(const MSVehicleType* vehType) {
396 : assert(vehType != nullptr);
397 : assert(myVTypeDict.find(vehType->getID()) != myVTypeDict.end());
398 : myVTypeDict.erase(vehType->getID());
399 1436 : if (myVTypeToDist.find(vehType->getID()) != myVTypeToDist.end()) {
400 : myVTypeToDist.erase(vehType->getID());
401 : }
402 1436 : delete vehType;
403 1436 : }
404 :
405 :
406 : bool
407 452 : MSVehicleControl::addVTypeDistribution(const std::string& id, RandomDistributor<MSVehicleType*>* vehTypeDistribution) {
408 452 : if (checkVType(id)) {
409 452 : myVTypeDistDict[id] = vehTypeDistribution;
410 452 : std::vector<MSVehicleType*> vehTypes = vehTypeDistribution->getVals();
411 1688 : for (auto vehType : vehTypes) {
412 1236 : if (myVTypeToDist.find(vehType->getID()) != myVTypeToDist.end()) {
413 42 : myVTypeToDist[vehType->getID()].insert(id);
414 : } else {
415 3582 : myVTypeToDist[vehType->getID()] = { id };
416 : }
417 : }
418 : return true;
419 452 : }
420 : return false;
421 : }
422 :
423 :
424 : bool
425 45770 : MSVehicleControl::hasVType(const std::string& id) const {
426 45770 : return myVTypeDict.count(id) > 0 || myVTypeDistDict.count(id) > 0;
427 : }
428 :
429 :
430 : bool
431 18853 : MSVehicleControl::hasVTypeDistribution(const std::string& id) const {
432 18853 : return myVTypeDistDict.count(id) > 0;
433 : }
434 :
435 :
436 : MSVehicleType*
437 10600030 : MSVehicleControl::getVType(const std::string& id, SumoRNG* rng, bool readOnly) {
438 : VTypeDictType::iterator it = myVTypeDict.find(id);
439 10600030 : if (it == myVTypeDict.end()) {
440 : VTypeDistDictType::iterator it2 = myVTypeDistDict.find(id);
441 4398952 : if (it2 == myVTypeDistDict.end()) {
442 : return nullptr;
443 : }
444 86239 : return it2->second->get(rng);
445 : }
446 12378384 : if (!readOnly && myReplaceableDefaultVTypes.erase(id) > 0) {
447 19472 : it->second->check();
448 : }
449 6201078 : return it->second;
450 : }
451 :
452 :
453 : void
454 335 : MSVehicleControl::insertVTypeIDs(std::vector<std::string>& into) const {
455 335 : into.reserve(into.size() + myVTypeDict.size() + myVTypeDistDict.size());
456 2645 : for (VTypeDictType::const_iterator i = myVTypeDict.begin(); i != myVTypeDict.end(); ++i) {
457 2310 : into.push_back((*i).first);
458 : }
459 335 : for (VTypeDistDictType::const_iterator i = myVTypeDistDict.begin(); i != myVTypeDistDict.end(); ++i) {
460 0 : into.push_back((*i).first);
461 : }
462 335 : }
463 :
464 :
465 : const std::set<std::string>
466 144865 : MSVehicleControl::getVTypeDistributionMembership(const std::string& id) const {
467 : std::map<std::string, std::set<std::string>>::const_iterator it = myVTypeToDist.find(id);
468 144865 : if (it == myVTypeToDist.end()) {
469 60114 : return std::set<std::string>();
470 : }
471 : return it->second;
472 : }
473 :
474 :
475 : const RandomDistributor<MSVehicleType*>*
476 134612 : MSVehicleControl::getVTypeDistribution(const std::string& typeDistID) const {
477 : const auto it = myVTypeDistDict.find(typeDistID);
478 134612 : if (it != myVTypeDistDict.end()) {
479 2202 : 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 27510 : MSVehicleControl::abortWaiting() {
498 29342 : for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
499 1832 : SUMOVehicle* veh = i->second;
500 : std::string waitReason;
501 1832 : if (veh->isStoppedTriggered()) {
502 1758 : const MSStop& stop = veh->getNextStop();
503 1758 : if (stop.triggered) {
504 : waitReason = "for a person that will never come";
505 124 : } else if (stop.containerTriggered) {
506 : waitReason = "for a container that will never come";
507 36 : } else if (stop.joinTriggered) {
508 36 : if (stop.pars.join != "") {
509 48 : 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 74 : } else if (!veh->hasDeparted()) {
517 74 : if (veh->getParameter().departProcedure == DepartDefinition::SPLIT) {
518 : waitReason = "for a train from which to split";
519 58 : } else if (veh->getParameter().departProcedure == DepartDefinition::TRIGGERED) {
520 : waitReason = "at insertion for a person that will never come";
521 22 : } 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 5496 : WRITE_WARNINGF(TL("Vehicle '%' aborted waiting %."), i->first, waitReason);
530 : }
531 27510 : }
532 :
533 :
534 : int
535 520101 : MSVehicleControl::getHaltingVehicleNo() const {
536 : int result = 0;
537 75235629 : for (MSVehicleControl::constVehIt it = loadedVehBegin(); it != loadedVehEnd(); ++it) {
538 74715528 : const SUMOVehicle* veh = it->second;
539 74715528 : if ((veh->isOnRoad() || veh->isRemoteControlled()) && veh->getSpeed() < SUMO_const_haltingSpeed) {
540 18838253 : result++;
541 : }
542 : }
543 520101 : return result;
544 : }
545 :
546 :
547 : std::pair<double, double>
548 520101 : MSVehicleControl::getVehicleMeanSpeeds() const {
549 : double speedSum = 0;
550 : double relSpeedSum = 0;
551 : int count = 0;
552 75235629 : for (MSVehicleControl::constVehIt it = loadedVehBegin(); it != loadedVehEnd(); ++it) {
553 74715528 : const SUMOVehicle* veh = it->second;
554 74715528 : if ((veh->isOnRoad() || veh->isRemoteControlled()) && !veh->isStopped()) {
555 41921952 : count++;
556 41921952 : speedSum += veh->getSpeed();
557 41921952 : relSpeedSum += veh->getEdge()->getSpeedLimit() > 0 ? veh->getSpeed() / veh->getEdge()->getSpeedLimit() : 0;
558 : }
559 : }
560 520101 : if (count > 0) {
561 425592 : 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 1367454 : MSVehicleControl::getQuota(double frac, int loaded) const {
570 1367454 : frac = frac < 0 ? myScale : frac;
571 : const int origLoaded = (loaded < 1
572 : // the vehicle in question has already been loaded, hence the '-1'
573 1367454 : ? frac > 1. ? (int)(myLoadedVehNo / frac) : myLoadedVehNo - 1
574 : // given transportable number reflects only previously loaded
575 499064 : : frac > 1. ? (int)(loaded / frac) : loaded);
576 1367454 : return getScalingQuota(frac, origLoaded);
577 : }
578 :
579 :
580 : int
581 549273 : MSVehicleControl::getTeleportCount() const {
582 549273 : return myTeleportsCollision + myTeleportsJam + myTeleportsYield + myTeleportsWrongLane;
583 : }
584 :
585 :
586 : void
587 4857 : MSVehicleControl::adaptIntermodalRouter(MSTransportableRouter& router) const {
588 5091 : for (const SUMOVehicle* const veh : myPTVehicles) {
589 : // add single vehicles with line attribute which are not part of a flow
590 234 : ConstMSRoutePtr const route = MSRoute::dictionary(veh->getParameter().routeid);
591 234 : router.getNetwork()->addSchedule(veh->getParameter(), route == nullptr ? nullptr : &route->getStops());
592 : }
593 4857 : }
594 :
595 : // ===========================================================================
596 : // MSVehicleControl::DeleteKeptVehicle method definitions
597 : // ===========================================================================
598 :
599 : SUMOTime
600 12 : MSVehicleControl::DeleteKeptVehicle::execute(SUMOTime /*currentTime*/) {
601 12 : MSNet::getInstance()->getVehicleControl().deleteVehicle(myVehicle, false, true);
602 12 : return 0;
603 : }
604 :
605 : /****************************************************************************/
|