Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSVehicleControl.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 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#pragma once
23#include <config.h>
24
25#include <cmath>
26#include <string>
27#include <map>
28#include <set>
29#ifdef HAVE_FOX
32#endif
38
39
40// ===========================================================================
41// class declarations
42// ===========================================================================
43class SUMOVehicle;
45class MSBaseVehicle;
46class MSVehicle;
47class MSRoute;
48class MSVehicleType;
49class OutputDevice;
50class MSEdge;
51
52
53// ===========================================================================
54// class definitions
55// ===========================================================================
72public:
74 typedef std::map<std::string, SUMOVehicle*>::const_iterator constVehIt;
75
84
85public:
88
89
91 virtual ~MSVehicleControl();
92
95
109 MSVehicleType* type,
110 const bool ignoreStopErrors, const VehicleDefinitionSource source = ROUTEFILE,
111 bool addRouteStops = true);
113
114
115
118
132 virtual bool addVehicle(const std::string& id, SUMOVehicle* v);
133
134
143 SUMOVehicle* getVehicle(const std::string& id) const;
144
145
152 virtual void deleteVehicle(SUMOVehicle* v, bool discard = false, bool wasKept = false);
153
156
159 myEndedVehNo++;
160 myDiscarded++;
161 }
162
174 void scheduleVehicleRemoval(SUMOVehicle* veh, bool checkDuplicate = false);
175
176
188 void removePending();
189
190
195 return myVehicleDict.begin();
196 }
197
198
203 return myVehicleDict.end();
204 }
206
207
209 void handleTriggeredDepart(SUMOVehicle* v, bool add);
210
213
221 void vehicleDeparted(const SUMOVehicle& v);
223
224
225
228
232 int getLoadedVehicleNo() const {
233 return myLoadedVehNo;
234 }
235
236
240 virtual int getHaltingVehicleNo() const;
241
243 virtual std::pair<double, double> getVehicleMeanSpeeds() const;
244 double getVehicleMeanSpeed() const {
245 return getVehicleMeanSpeeds().first;
246 }
248 return getVehicleMeanSpeeds().second;
249 }
250
254 int getEndedVehicleNo() const {
255 return myEndedVehNo;
256 }
257
262 return myEndedVehNo - myDiscarded;
263 }
264
269 return myDiscarded;
270 }
271
272
277 return myRunningVehNo;
278 }
279
280
286 }
287
288
296 int getQuota(double frac = -1, int loaded = -1) const;
297
298
306
311
312
314 int getCollisionCount() const {
315 return myCollisions;
316 }
317
321 }
322
324 int getTeleportsJam() const {
325 return myTeleportsJam;
326 }
327
329 int getTeleportsYield() const {
330 return myTeleportsYield;
331 }
332
336 }
337
339 int getTeleportCount() const;
340
342 int getEmergencyStops() const {
343 return myEmergencyStops;
344 }
345
349 }
350
353 return myStoppedVehicles;
354 }
355
359 double getTotalDepartureDelay() const {
361 }
362
363
367 double getTotalTravelTime() const {
368 return myTotalTravelTime;
369 }
371
372
373
376
389 bool addVType(MSVehicleType* vehType);
390
391 /*
392 * @param[in] vehType The vehicle type to remove
393 * @return Whether the vehicle type could be removed
394 */
395 void removeVType(const MSVehicleType* vehType);
396
397
411 bool addVTypeDistribution(const std::string& id, RandomDistributor<MSVehicleType*>* vehTypeDistribution);
412
413
421 bool hasVType(const std::string& id) const;
422
423
431 bool hasVTypeDistribution(const std::string& id) const;
432
433
438 MSVehicleType* getVType(const std::string& id = DEFAULT_VTYPE_ID, SumoRNG* rng = nullptr, bool readOnly = false);
439
440
444 void insertVTypeIDs(std::vector<std::string>& into) const;
445
446
450 const std::set<std::string> getVTypeDistributionMembership(const std::string& id) const;
451
453 const RandomDistributor<MSVehicleType*>* getVTypeDistribution(const std::string& typeDistID) const;
454
456 const std::vector<MSVehicleType*> getPedestrianTypes(void) const;
457
459
465
471
473 void registerCollision(bool teleport) {
474 myCollisions++;
475 if (teleport) {
477 }
478 }
479
483 }
484
489
494
499
504
509
514
517
520 void setState(int runningVehNo, int loadedVehNo, int endedVehNo, double totalDepartureDelay, double totalTravelTime);
521
524 void saveState(OutputDevice& out);
525
527 void clearState(const bool reinit);
529
532 myRunningVehNo -= n;
533 myDiscarded += n;
534 myEndedVehNo += n;
535 }
536
537
540 void abortWaiting();
541
543 double getMaxSpeedFactor() const {
544 return myMaxSpeedFactor;
545 }
546
548 double getMinDeceleration() const {
549 return myMinDeceleration;
550 }
551
553 double getMinDecelerationRail() const {
555 }
556
558
560 void setScale(double scale) {
561 myScale = scale;
562 }
563
565 double getScale() const {
566 return myScale;
567 }
568
569private:
571 void initDefaultTypes();
572
579 bool checkVType(const std::string& id);
580
582 bool isPendingRemoval(SUMOVehicle* veh);
583
584protected:
585 void initVehicle(MSBaseVehicle* built, const bool ignoreStopErrors, bool addRouteStops, const VehicleDefinitionSource source);
586
587private:
590
593
596
599
602
605
608
611
614
617
620
623
627
628
631
634
638
639
640protected:
643
645 typedef std::map< std::string, SUMOVehicle* > VehicleDictType;
649
650
651private:
652 class DeleteKeptVehicle : public Command {
653 public:
656 SUMOTime execute(SUMOTime currentTime);
657 private:
659 private:
662 };
663
666
668 typedef std::map< std::string, MSVehicleType* > VTypeDictType;
671
673 typedef std::map< std::string, RandomDistributor<MSVehicleType*>* > VTypeDistDictType;
676
678 std::map<std::string, std::set<std::string>> myVTypeToDist;
679
681 std::set<std::string> myReplaceableDefaultVTypes;
682
685
687 double myScale;
688
690
693
698
700 std::vector<SUMOVehicle*> myPTVehicles;
701
703#ifdef HAVE_FOX
705#else
706 std::vector<SUMOVehicle*> myPendingRemovals;
707#endif
708
709private:
712
715
716
717};
long long int SUMOTime
Definition GUI.h:36
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.h:32
const std::string DEFAULT_VTYPE_ID
Base (microsim) event class.
Definition Command.h:50
The base class for microscopic and mesoscopic vehicles.
A road/street connecting two junctions.
Definition MSEdge.h:77
DeleteKeptVehicle & operator=(const DeleteKeptVehicle &)=delete
Invalidated assignment operator.
SUMOTime execute(SUMOTime currentTime)
Executes the command.
The class responsible for building and deletion of vehicles.
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.
std::map< std::string, SUMOVehicle * > VehicleDictType
Vehicle dictionary type.
bool addVType(MSVehicleType *vehType)
Adds a vehicle type.
void setState(int runningVehNo, int loadedVehNo, int endedVehNo, double totalDepartureDelay, double totalTravelTime)
Sets the current state variables as loaded from the stream.
int getRunningVehicleNo() const
Returns the number of build and inserted, but not yet deleted vehicles.
VehicleDefinitionSource
possible origins of a vehicle definition
double getScale() const
sets the demand scaling factor
void registerEmergencyStop()
register emergency stop
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
double getTotalTravelTime() const
Returns the total travel time.
void setScale(double scale)
sets the demand scaling factor
std::vector< SUMOVehicle * > myPendingRemovals
List of vehicles which are going to be removed.
int getTriggeredVehicleCount() const
return the number of vehicles that are waiting for a transportable or a join
int myLoadedVehNo
The number of build vehicles.
void registerTeleportYield()
register one non-collision-related teleport
void discountStateRemoved(int n)
discount vehicles that were removed during state loading
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.
int getLoadedVehicleNo() const
Returns the number of build vehicles.
double getMinDeceleration() const
return the minimum deceleration capability for all road vehicles that ever entered the network
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 getCollisionCount() const
return the number of collisions
int getTeleportsWrongLane() const
return the number of teleports due to vehicles stuck on the wrong lane
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.
int getStoppedVehiclesCount() const
return the number of vehicles that are currently stopped
double getVehicleMeanSpeed() const
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
int getTeleportsYield() const
return the number of teleports due to vehicles stuck on a minor road
void clearState(const bool reinit)
Remove all vehicles before quick-loading state.
int getEmergencyBrakingCount() const
return the number of emergency stops
std::map< std::string, std::set< std::string > > myVTypeToDist
Inverse lookup from vehicle type to distributions it is a member of.
int getEmergencyStops() const
return the number of emergency stops
double myMinDeceleration
The minimum deceleration capability for all road vehicles in the network.
void registerTeleportJam()
register one non-collision-related teleport
void registerStopEnded()
register emergency stop
double getTotalDepartureDelay() const
Returns the total departure delay.
void registerEmergencyBraking()
register emergency stop
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...
int myWaitingForTransportable
the number of vehicles waiting for persons or containers contained in myWaiting which can only contin...
std::map< std::string, MSVehicleType * > VTypeDictType
Vehicle type dictionary type.
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 getDepartedVehicleNo() const
Returns the number of inserted vehicles.
int getArrivedVehicleNo() const
Returns the number of arrived vehicles.
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.
MSVehicleControl(const MSVehicleControl &s)=delete
invalidated copy constructor
bool addVTypeDistribution(const std::string &id, RandomDistributor< MSVehicleType * > *vehTypeDistribution)
Adds a vehicle type distribution.
int myTeleportsJam
The number of teleports due to jam.
int getActiveVehicleCount() const
Returns the number of build vehicles that have not been removed or need to wait for a passenger or a ...
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
MSVehicleControl & operator=(const MSVehicleControl &s)=delete
invalidated assignment operator
void insertVTypeIDs(std::vector< std::string > &into) const
Inserts ids of all known vehicle types and vehicle type distributions to the given vector.
int getTeleportsJam() const
return the number of teleports due to jamming
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)
int getEndedVehicleNo() const
Returns the number of removed vehicles.
VTypeDictType myVTypeDict
Dictionary of vehicle types.
double getMaxSpeedFactor() const
return the maximum speed factor for all vehicles that ever entered the network
double getMinDecelerationRail() const
return the minimum deceleration capability for all ral vehicles that ever entered the network
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.
int getTeleportsCollisions() const
return the number of collisions
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 aacomplish 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)
std::map< std::string, RandomDistributor< MSVehicleType * > * > VTypeDistDictType
Vehicle type distribution dictionary 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.
double getVehicleMeanSpeedRelative() const
void registerTeleportWrongLane()
register one non-collision-related teleport
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 registerCollision(bool teleport)
registers one collision-related teleport
int getDiscardedVehicleNo() const
Returns the number of discarded vehicles.
void registerStopStarted()
register emergency stop
VehicleDictType myVehicleDict
Dictionary of vehicles.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
The car-following model and parameter.
Static storage of an output device and its base (abstract) implementation.
Represents a generic random distribution.
Representation of a vehicle.
Definition SUMOVehicle.h:62
Structure representing possible vehicle parameter.