Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSVehicleControl.cpp
Go to the documentation of this file.
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/****************************************************************************/
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"
35#include <utils/common/Named.h>
41
42
43// ===========================================================================
44// member method definitions
45// ===========================================================================
47 myLoadedVehNo(0),
48 myRunningVehNo(0),
49 myEndedVehNo(0),
50 myDiscarded(0),
51 myCollisions(0),
52 myTeleportsCollision(0),
53 myTeleportsJam(0),
54 myTeleportsYield(0),
55 myTeleportsWrongLane(0),
56 myEmergencyStops(0),
57 myEmergencyBrakingCount(0),
58 myStoppedVehicles(0),
59 myTotalDepartureDelay(0),
60 myTotalTravelTime(0),
61 myWaitingForTransportable(0),
62 myMaxSpeedFactor(1),
63 myMinDeceleration(SUMOVTypeParameter::getDefaultDecel(SVC_IGNORING)),
64 myMinDecelerationRail(SUMOVTypeParameter::getDefaultDecel(SVC_RAIL)),
65 myMaxMinGap(0),
66 myPendingRemovals(MSGlobals::gNumSimThreads > 1) {
67
70 myKeepTime = string2time(OptionsCont::getOptions().getString("keep-after-arrival"));
71}
72
73
77
78
79void
106
107
110 ConstMSRoutePtr route, MSVehicleType* type,
111 const bool ignoreStopErrors, const VehicleDefinitionSource source, bool addRouteStops) {
112 const double speedFactor = type->computeChosenSpeedDeviation(defs->speedFactor, source == VehicleDefinitionSource::ROUTEFILE ? MSRouteHandler::getParsingRNG() : nullptr);
113 MSVehicle* built = new MSVehicle(defs, route, type, speedFactor);
114 initVehicle(built, ignoreStopErrors, addRouteStops, source);
115 return built;
116}
117
118
119void
120MSVehicleControl::initVehicle(MSBaseVehicle* built, const bool ignoreStopErrors, bool addRouteStops, const VehicleDefinitionSource source) {
122 try {
123 built->initDevices();
124 if (source != VehicleDefinitionSource::STATE) {
125 built->addStops(ignoreStopErrors, nullptr, addRouteStops);
126 }
127 } catch (ProcessError&) {
128 delete built;
129 throw;
130 }
132}
133
134
135void
137 assert(myRunningVehNo > 0);
138 if (!checkDuplicate || !isPendingRemoval(veh)) {
139 myPendingRemovals.push_back(veh);
140 }
141}
142
143
144bool
146#ifdef HAVE_FOX
147 return myPendingRemovals.contains(veh);
148#else
149 return std::find(myPendingRemovals.begin(), myPendingRemovals.end(), veh) == myPendingRemovals.end();
150#endif
151}
152
153
154void
156 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 std::sort(vehs.begin(), vehs.end(), ComparatorNumericalIdLess());
163 for (SUMOVehicle* const veh : vehs) {
164 myTotalTravelTime += STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep() - veh->getDeparture());
167 // vehicle is equipped with tripinfo device (not all vehicles are)
168 const bool hasTripinfo = veh->getDevice(typeid(MSDevice_Tripinfo)) != nullptr;
169 for (MSVehicleDevice* const dev : veh->getDevices()) {
170 dev->generateOutput(hasTripinfo ? tripinfoOut : nullptr);
171 }
172 if (tripinfoOut != nullptr && hasTripinfo) {
173 // close tag after tripinfo (possibly including emissions from another device) have been written
174 tripinfoOut->closeTag();
175 }
176 if (myKeepTime == 0) {
177 deleteVehicle(veh);
178 } else {
180 }
181 }
182 vehs.clear();
183 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}
191
192
193void
198
199void
206 const double maxDecel = v.getVehicleType().getCarFollowModel().getMaxDecel();
207 if ((v.getVClass() & (SVC_PEDESTRIAN | SVC_NON_ROAD)) == 0) {
208 // only worry about deceleration of road users
210 } else if ((v.getVClass() & SVC_RAIL_CLASSES) != 0) {
212 if ((v.getEdge()->getPermissions() & SVC_ROAD_MOTOR_CLASSES) != 0) {
213 // shared rail/road
215 }
216 }
217}
218
219
220void
221MSVehicleControl::setState(int runningVehNo, int loadedVehNo, int endedVehNo, double totalDepartureDelay, double totalTravelTime, double maxSpeedFactor, double minDecel) {
222 myRunningVehNo = runningVehNo;
223 myLoadedVehNo = loadedVehNo;
224 myEndedVehNo = endedVehNo;
225 myTotalDepartureDelay = totalDepartureDelay;
226 myTotalTravelTime = totalTravelTime;
227 myMaxSpeedFactor = maxSpeedFactor;
228 myMinDeceleration = minDecel;
229}
230
231
232void
242 const SUMOTime loaderTime = MSNet::getInstance()->getLoaderTime();
243 if (loaderTime > 0 && loaderTime != SUMOTime_MAX) {
244 out.writeAttr(SUMO_ATTR_LOADERTIME, MSNet::getInstance()->getLoaderTime());
245 }
246 out.closeTag();
247 // save vehicle types
248 for (const auto& item : myVTypeDict) {
249 if (myReplaceableDefaultVTypes.count(item.first) == 0) {
250 item.second->getParameter().write(out);
251 }
252 }
253 for (const auto& item : myVTypeDistDict) {
255 out.writeAttr(SUMO_ATTR_VTYPES, item.second->getVals());
256 out.writeAttr(SUMO_ATTR_PROBS, item.second->getProbs());
257 out.closeTag();
258 }
259 std::vector<SUMOVehicle*> sortedVehs;
260 for (const auto& item : myVehicleDict) {
261 sortedVehs.push_back(item.second);
262 }
263 std::sort(sortedVehs.begin(), sortedVehs.end(), ComparatorNumericalIdLess());
264 for (SUMOVehicle* veh : sortedVehs) {
265 veh->saveState(out);
266 }
267}
268
269
270void
272 for (const auto& item : myVehicleDict) {
273 delete item.second;
274 }
275 myVehicleDict.clear();
276 // delete vehicle type distributions
277 for (const auto& item : myVTypeDistDict) {
278 delete item.second;
279 }
280 myVTypeDistDict.clear();
281 // delete vehicle types
282 for (const auto& item : myVTypeDict) {
283 delete item.second;
284 }
285 myVTypeDict.clear();
286 myPendingRemovals.clear(); // could be leftovers from MSVehicleTransfer::checkInsertions (teleport beyond arrival)
287 if (reinit) {
289 }
290 myLoadedVehNo = 0;
291 myRunningVehNo = 0;
292 myEndedVehNo = 0;
293 myDiscarded = 0;
294 myCollisions = 0;
296 myTeleportsJam = 0;
304}
305
306
307bool
308MSVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
309 VehicleDictType::iterator it = myVehicleDict.find(id);
310 if (it == myVehicleDict.end()) {
311 // id not in myVehicleDict.
312 myVehicleDict[id] = v;
313 handleTriggeredDepart(v, true);
314 const SUMOVehicleParameter& pars = v->getParameter();
315 if (v->getVClass() != SVC_TAXI && pars.line != "" && pars.repetitionNumber < 0) {
316 myPTVehicles.push_back(v);
317 }
318 return true;
319 }
320 return false;
321}
322
323
324void
326 const SUMOVehicleParameter& pars = v->getParameter();
328 const MSEdge* const firstEdge = v->getRoute().getEdges()[pars.departEdge];
329 if (add) {
331 // position will be checked against person position later
332 static_cast<MSVehicle*>(v)->setTentativeLaneAndPosition(nullptr, v->getParameter().departPos);
333 }
334 if (firstEdge->isTazConnector()) {
335 for (MSEdge* out : firstEdge->getSuccessors()) {
336 out->addWaiting(v);
337 }
338 } else {
339 firstEdge->addWaiting(v);
340 }
342 } else {
343 if (firstEdge->isTazConnector()) {
344 for (MSEdge* out : firstEdge->getSuccessors()) {
345 out->removeWaiting(v);
346 }
347 } else {
348 firstEdge->removeWaiting(v);
349 }
351 }
352 }
353}
354
355
357MSVehicleControl::getVehicle(const std::string& id) const {
358 VehicleDictType::const_iterator it = myVehicleDict.find(id);
359 if (it == myVehicleDict.end()) {
360 return nullptr;
361 }
362 return it->second;
363}
364
365
366void
367MSVehicleControl::deleteVehicle(SUMOVehicle* veh, bool discard, bool wasKept) {
368 if (!wasKept) {
369 myEndedVehNo++;
370 if (discard) {
371 myDiscarded++;
372 }
373 }
374 if (veh != nullptr) {
375 myVehicleDict.erase(veh->getID());
376 }
377 auto ptVehIt = std::find(myPTVehicles.begin(), myPTVehicles.end(), veh);
378 if (ptVehIt != myPTVehicles.end()) {
379 myPTVehicles.erase(ptVehIt);
380 }
381 delete veh;
382}
383
384
385bool
386MSVehicleControl::checkVType(const std::string& id) {
387 if (myReplaceableDefaultVTypes.erase(id) > 0) {
388 delete myVTypeDict[id];
389 myVTypeDict.erase(myVTypeDict.find(id));
390 } else {
391 if (myVTypeDict.find(id) != myVTypeDict.end() || myVTypeDistDict.find(id) != myVTypeDistDict.end()) {
392 return false;
393 }
394 }
395 return true;
396}
397
398
399bool
401 if (checkVType(vehType->getID())) {
402 myVTypeDict[vehType->getID()] = vehType;
403 return true;
404 }
405 return false;
406}
407
408
409void
411 assert(vehType != nullptr);
412 assert(myVTypeDict.find(vehType->getID()) != myVTypeDict.end());
413 myVTypeDict.erase(vehType->getID());
414 if (myVTypeToDist.find(vehType->getID()) != myVTypeToDist.end()) {
415 myVTypeToDist.erase(vehType->getID());
416 }
417 delete vehType;
418}
419
420
421bool
423 if (checkVType(id)) {
424 myVTypeDistDict[id] = vehTypeDistribution;
425 std::vector<MSVehicleType*> vehTypes = vehTypeDistribution->getVals();
426 for (auto vehType : vehTypes) {
427 if (myVTypeToDist.find(vehType->getID()) != myVTypeToDist.end()) {
428 myVTypeToDist[vehType->getID()].insert(id);
429 } else {
430 myVTypeToDist[vehType->getID()] = { id };
431 }
432 }
433 return true;
434 }
435 return false;
436}
437
438
439bool
440MSVehicleControl::hasVType(const std::string& id) const {
441 return myVTypeDict.count(id) > 0 || myVTypeDistDict.count(id) > 0;
442}
443
444
445bool
446MSVehicleControl::hasVTypeDistribution(const std::string& id) const {
447 return myVTypeDistDict.count(id) > 0;
448}
449
450
452MSVehicleControl::getVType(const std::string& id, SumoRNG* rng, bool readOnly) {
453 VTypeDictType::iterator it = myVTypeDict.find(id);
454 if (it == myVTypeDict.end()) {
455 VTypeDistDictType::iterator it2 = myVTypeDistDict.find(id);
456 if (it2 == myVTypeDistDict.end()) {
457 return nullptr;
458 }
459 return it2->second->get(rng);
460 }
461 if (!readOnly && myReplaceableDefaultVTypes.erase(id) > 0) {
462 it->second->check();
463 }
464 return it->second;
465}
466
467
468void
469MSVehicleControl::insertVTypeIDs(std::vector<std::string>& into) const {
470 into.reserve(into.size() + myVTypeDict.size() + myVTypeDistDict.size());
471 for (VTypeDictType::const_iterator i = myVTypeDict.begin(); i != myVTypeDict.end(); ++i) {
472 into.push_back((*i).first);
473 }
474 for (VTypeDistDictType::const_iterator i = myVTypeDistDict.begin(); i != myVTypeDistDict.end(); ++i) {
475 into.push_back((*i).first);
476 }
477}
478
479
480const std::set<std::string>
482 std::map<std::string, std::set<std::string>>::const_iterator it = myVTypeToDist.find(id);
483 if (it == myVTypeToDist.end()) {
484 return std::set<std::string>();
485 }
486 return it->second;
487}
488
489
491MSVehicleControl::getVTypeDistribution(const std::string& typeDistID) const {
492 const auto it = myVTypeDistDict.find(typeDistID);
493 if (it != myVTypeDistDict.end()) {
494 return it->second;
495 }
496 return nullptr;
497}
498
499
500const std::vector<MSVehicleType*>
502 std::vector<MSVehicleType*> pedestrianTypes;
503 for (auto const& e : myVTypeDict)
504 if (e.second->getVehicleClass() == SUMOVehicleClass::SVC_PEDESTRIAN) {
505 pedestrianTypes.push_back(e.second);
506 }
507 return pedestrianTypes;
508}
509
510
511void
513 for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
514 SUMOVehicle* veh = i->second;
515 std::string waitReason;
516 if (veh->isStoppedTriggered()) {
517 const MSStop& stop = veh->getNextStop();
518 if (stop.triggered) {
519 waitReason = "for a person that will never come";
520 } else if (stop.containerTriggered) {
521 waitReason = "for a container that will never come";
522 } else if (stop.joinTriggered) {
523 if (stop.pars.join != "") {
524 waitReason = "to be joined to vehicle '" + stop.pars.join + "'";
525 } else {
526 waitReason = "for a joining vehicle that will never come";
527 }
528 } else {
529 waitReason = "for an unknown trigger";
530 }
531 } else if (!veh->hasDeparted()) {
533 waitReason = "for a train from which to split";
535 waitReason = "at insertion for a person that will never come";
537 waitReason = "at insertion for a container that will never come";
538 } else {
539 waitReason = "for an unknown departure trigger";
540 }
541 } else {
542 waitReason = "for an unknown reason";
543 }
544 WRITE_WARNINGF(TL("Vehicle '%' aborted waiting %."), i->first, waitReason);
545 }
546}
547
548
549int
551 int result = 0;
552 for (MSVehicleControl::constVehIt it = loadedVehBegin(); it != loadedVehEnd(); ++it) {
553 const SUMOVehicle* veh = it->second;
554 if ((veh->isOnRoad() || veh->isRemoteControlled()) && veh->getSpeed() < SUMO_const_haltingSpeed) {
555 result++;
556 }
557 }
558 return result;
559}
560
561
562std::pair<double, double>
564 double speedSum = 0;
565 double relSpeedSum = 0;
566 int count = 0;
567 for (MSVehicleControl::constVehIt it = loadedVehBegin(); it != loadedVehEnd(); ++it) {
568 const SUMOVehicle* veh = it->second;
569 if ((veh->isOnRoad() || veh->isRemoteControlled()) && !veh->isStopped()) {
570 count++;
571 speedSum += veh->getSpeed();
572 relSpeedSum += veh->getEdge()->getSpeedLimit() > 0 ? veh->getSpeed() / veh->getEdge()->getSpeedLimit() : 0;
573 }
574 }
575 if (count > 0) {
576 return std::make_pair(speedSum / count, relSpeedSum / count);
577 } else {
578 return std::make_pair(-1, -1);
579 }
580}
581
582
583int
584MSVehicleControl::getQuota(double frac, int loaded) const {
585 frac = frac < 0 ? myScale : frac;
586 const int origLoaded = (loaded < 1
587 // the vehicle in question has already been loaded, hence the '-1'
588 ? frac > 1. ? (int)(myLoadedVehNo / frac) : myLoadedVehNo - 1
589 // given transportable number reflects only previously loaded
590 : frac > 1. ? (int)(loaded / frac) : loaded);
591 return getScalingQuota(frac, origLoaded);
592}
593
594
595int
599
600
601void
603 for (const SUMOVehicle* const veh : myPTVehicles) {
604 // add single vehicles with line attribute which are not part of a flow
605 ConstMSRoutePtr const route = MSRoute::dictionary(veh->getParameter().routeid);
606 router.getNetwork()->addSchedule(veh->getParameter(), route == nullptr ? nullptr : &route->getStops());
607 }
608}
609
610// ===========================================================================
611// MSVehicleControl::DeleteKeptVehicle method definitions
612// ===========================================================================
613
619
620/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:287
#define TL(string)
Definition MsgHandler.h:304
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.h:32
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
#define STEPS2TIME(x)
Definition SUMOTime.h:58
#define STEPFLOOR(x)
Definition SUMOTime.h:61
#define SIMSTEP
Definition SUMOTime.h:64
#define SUMOTime_MAX
Definition SUMOTime.h:34
const long long int VTYPEPARS_VEHICLECLASS_SET
const std::string DEFAULT_TAXITYPE_ID
const std::string DEFAULT_RAILTYPE_ID
const std::string DEFAULT_PEDTYPE_ID
const std::set< std::string > DEFAULT_VTYPES
const std::string DEFAULT_VTYPE_ID
const std::string DEFAULT_CONTAINERTYPE_ID
@ SVC_IGNORING
vehicles ignoring classes
@ SVC_RAIL
vehicle is a not electrified rail
@ SVC_RAIL_CLASSES
classes which drive on tracks
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_CONTAINER
@ SVC_NON_ROAD
@ SVC_ROAD_MOTOR_CLASSES
classes which drive on roads
@ SVC_TAXI
vehicle is a taxi
@ SVC_PEDESTRIAN
pedestrian
const std::string DEFAULT_BIKETYPE_ID
@ SPLIT
The departure is triggered by a train split.
@ CONTAINER_TRIGGERED
The departure is container triggered.
@ TRIGGERED
The departure is person triggered.
@ SUMO_TAG_DELAY
@ SUMO_TAG_VTYPE_DISTRIBUTION
distribution of a vehicle type
@ SUMO_ATTR_NUMBER
@ SUMO_ATTR_DEPART
@ SUMO_ATTR_PROBS
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_DECEL
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_SPEEDFACTOR
@ SUMO_ATTR_ID
@ SUMO_ATTR_LOADERTIME
@ SUMO_ATTR_TIME
trigger: the time of the step
int getScalingQuota(double frac, long long int loaded)
Returns the number of instances of the current object that shall be emitted given the number of loade...
Definition StdDefs.cpp:73
T MIN2(T a, T b)
Definition StdDefs.h:80
const double SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
Definition StdDefs.h:62
T MAX2(T a, T b)
Definition StdDefs.h:86
void addSchedule(const SUMOVehicleParameter &pars, const StopParVector *addStops=nullptr)
Network * getNetwork() const
The base class for microscopic and mesoscopic vehicles.
virtual void initDevices()
void addStops(const bool ignoreStopErrors, MSRouteIterator *searchStart=nullptr, bool addRouteStops=true)
Adds stops to the built vehicle.
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
Definition MSCFModel.h:269
A device which collects info on the vehicle trip (mainly on departure and arrival)
A road/street connecting two junctions.
Definition MSEdge.h:77
SVCPermissions getPermissions() const
Returns the combined permissions of all lanes of this edge.
Definition MSEdge.h:658
double getSpeedLimit() const
Returns the speed limit of the edge @caution The speed limit of the first lane is retured; should pro...
Definition MSEdge.cpp:1192
bool isTazConnector() const
Definition MSEdge.h:292
void addWaiting(SUMOVehicle *vehicle) const
Adds a vehicle to the list of waiting vehicles.
Definition MSEdge.cpp:1485
void removeWaiting(const SUMOVehicle *vehicle) const
Removes a vehicle from the list of waiting vehicles.
Definition MSEdge.cpp:1494
const MSEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
Definition MSEdge.cpp:1292
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
static bool gUseMesoSim
Definition MSGlobals.h:106
@ BUILT
The vehicle was built, but has not yet departed.
@ ARRIVED
The vehicle arrived at his destination (is deleted)
@ DEPARTED
The vehicle has departed (was inserted into the network)
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:199
SUMOTime getLoaderTime() const
Definition MSNet.cpp:1122
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition MSNet.h:505
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to, const std::string &info="")
Informs all added listeners about a vehicle's state change.
Definition MSNet.cpp:1371
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:402
static SumoRNG * getParsingRNG()
get parsing RNG
const ConstMSEdgeVector & getEdges() const
Definition MSRoute.h:128
static bool dictionary(const std::string &id, ConstMSRoutePtr route)
Adds a route to the dictionary.
Definition MSRoute.cpp:116
bool triggered
whether an arriving person lets the vehicle continue
Definition MSStop.h:69
bool containerTriggered
whether an arriving container lets the vehicle continue
Definition MSStop.h:71
bool joinTriggered
whether coupling another vehicle (train) the vehicle continue
Definition MSStop.h:73
const SUMOVehicleParameter::Stop pars
The stop parameter.
Definition MSStop.h:65
SUMOTime execute(SUMOTime currentTime)
Executes the command.
void adaptIntermodalRouter(MSTransportableRouter &router) const
int myTeleportsCollision
The number of teleports due to collision.
double myScale
The scaling factor (especially for inc-dua)
bool hasVType(const std::string &id) const
Asks for existence of a vehicle type.
const std::vector< MSVehicleType * > getPedestrianTypes(void) const
Return all pedestrian vehicle types.
bool addVType(MSVehicleType *vehType)
Adds a vehicle type.
VehicleDefinitionSource
possible origins of a vehicle definition
void removePending()
Removes a vehicle after it has ended.
void initVehicle(MSBaseVehicle *built, const bool ignoreStopErrors, bool addRouteStops, const VehicleDefinitionSource source)
std::set< std::string > myReplaceableDefaultVTypes
the default vehicle types which may still be replaced
std::vector< SUMOVehicle * > myPendingRemovals
List of vehicles which are going to be removed.
int myLoadedVehNo
The number of build vehicles.
bool hasVTypeDistribution(const std::string &id) const
Asks for a vehicle type distribution.
void vehicleDeparted(const SUMOVehicle &v)
Informs this control about a vehicle's departure.
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
void initDefaultTypes()
create default types
int myTeleportsYield
The number of teleports due to vehicles stuck on a minor road.
int myTeleportsWrongLane
The number of teleports due to vehicles stuck on the wrong lane.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
void clearState(const bool reinit)
Remove all vehicles before quick-loading state.
std::map< std::string, std::set< std::string > > myVTypeToDist
Inverse lookup from vehicle type to distributions it is a member of.
double myMaxMinGap
The maximum minGap value encountered in the simulation.
double myMinDeceleration
The minimum deceleration capability for all road vehicles in the network.
bool isPendingRemoval(SUMOVehicle *veh)
whether the given vehicle is scheduled for removal
double myMinDecelerationRail
The minimum deceleration capability for all rail vehicles in the network.
virtual ~MSVehicleControl()
Destructor.
void removeVType(const MSVehicleType *vehType)
int myEmergencyBrakingCount
The number of emergency stops.
int myStoppedVehicles
The number of stopped vehicles.
void deleteKeptVehicle(SUMOVehicle *veh)
when a vehicle is kept after arrival, schedule later deletion
void registerOneWaiting()
increases the count of vehicles waiting for a transport to allow recognition of person / container re...
void unregisterOneWaiting()
decreases the count of vehicles waiting for a transport to allow recognition of person / container re...
virtual std::pair< double, double > getVehicleMeanSpeeds() const
get current absolute and relative mean vehicle speed in the network
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
int myCollisions
The number of collisions.
int myEmergencyStops
The number of emergency stops.
int getQuota(double frac=-1, int loaded=-1) const
Returns the number of instances of the current vehicle that shall be emitted considering that "frac" ...
MSVehicleControl()
Constructor.
double myMaxSpeedFactor
The maximum speed factor for all vehicles in the network.
int myDiscarded
The number of vehicles which were discarded while loading.
int myEndedVehNo
The number of removed vehicles.
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, SumoRNG *rng=nullptr, bool readOnly=false)
Returns the named vehicle type or a sample from the named distribution.
bool addVTypeDistribution(const std::string &id, RandomDistributor< MSVehicleType * > *vehTypeDistribution)
Adds a vehicle type distribution.
int myTeleportsJam
The number of teleports due to jam.
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
void insertVTypeIDs(std::vector< std::string > &into) const
Inserts ids of all known vehicle types and vehicle type distributions to the given vector.
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, ConstMSRoutePtr route, MSVehicleType *type, const bool ignoreStopErrors, const VehicleDefinitionSource source=ROUTEFILE, bool addRouteStops=true)
Builds a vehicle, increases the number of built vehicles.
double myTotalDepartureDelay
The aggregated time vehicles had to wait for departure (in seconds)
VTypeDictType myVTypeDict
Dictionary of vehicle types.
const RandomDistributor< MSVehicleType * > * getVTypeDistribution(const std::string &typeDistID) const
return the vehicle type distribution with the given id
virtual int getHaltingVehicleNo() const
Returns the number of halting vehicles.
void scheduleVehicleRemoval(SUMOVehicle *veh, bool checkDuplicate=false)
Removes a vehicle after it has ended.
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false, bool wasKept=false)
Deletes the vehicle.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
double myTotalTravelTime
The aggregated time vehicles needed to accomplish their route (in seconds)
std::vector< SUMOVehicle * > myPTVehicles
List of vehicles which belong to public transport.
int getTeleportCount() const
return the number of teleports (including collisions)
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
void handleTriggeredDepart(SUMOVehicle *v, bool add)
register / unregister depart-triggered vehicles with edges
void abortWaiting()
informes about all waiting vehicles (deletion in destructor)
void saveState(OutputDevice &out)
Saves the current state into the given stream.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
const std::set< std::string > getVTypeDistributionMembership(const std::string &id) const
Return the distribution IDs the vehicle type is a member of.
int myRunningVehNo
The number of vehicles within the network (build and inserted but not removed)
void setState(int runningVehNo, int loadedVehNo, int endedVehNo, double totalDepartureDelay, double totalTravelTime, double maxSpeedFactor, double minDecel)
Sets the current state variables as loaded from the stream.
VehicleDictType myVehicleDict
Dictionary of vehicles.
Abstract in-vehicle device.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
The car-following model and parameter.
const std::string & getID() const
Returns the name of the vehicle type.
double getMinGap() const
Get the free space in front of vehicles of this class.
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
static MSVehicleType * build(SUMOVTypeParameter &from, const std::string &fileName="")
Builds the microsim vehicle type described by the given parameter.
double computeChosenSpeedDeviation(double speedFactorOverride, SumoRNG *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
void check()
Checks whether vehicle type parameters may be problematic (Currently, only the value for the action s...
const std::string & getID() const
Returns the id.
Definition Named.h:74
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false)
writes a named attribute
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Represents a generic random distribution.
const std::vector< T > & getVals() const
Returns the members of the distribution.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual double getChosenSpeedFactor() const =0
virtual double getSpeed() const =0
Returns the object's current speed.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
virtual SUMOVehicleClass getVClass() const =0
Returns the object's access class.
virtual const MSEdge * getEdge() const =0
Returns the (normal) route edge the object is currently at.
Structure representing possible vehicle parameter.
long long int parametersSet
Information for the router which parameter were set.
Representation of a vehicle.
Definition SUMOVehicle.h:63
virtual bool isStopped() const =0
Returns whether the vehicle is at a stop and waiting for a person or container to continue.
virtual SUMOTime getDeparture() const =0
Returns this vehicle's real departure time.
virtual bool hasDeparted() const =0
Returns whether this vehicle has departed.
virtual bool isStoppedTriggered() const =0
Returns whether the vehicle is at a stop and waiting for a person or container to continue.
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
virtual bool isRemoteControlled() const =0
Returns the information whether the vehicle is fully controlled via TraCI.
virtual const MSStop & getNextStop() const =0
virtual const MSRoute & getRoute() const =0
Returns the current route.
std::string join
the id of the vehicle (train portion) to which this vehicle shall be joined
Structure representing possible vehicle parameter.
double speedFactor
individual speedFactor (overriding distribution from vType)
double departPos
(optional) The position the vehicle shall depart from
int departEdge
(optional) The initial edge within the route of the vehicle
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
std::string line
The vehicle's line (mainly for public transport)
Function-object for stable sorting of objects with numerical ids.
Definition Named.h:39