49 bool eagerInsertionCheck,
53 myMaxDepartDelay(maxDepartDelay),
54 myEagerInsertionCheck(eagerInsertionCheck),
55 myMaxVehicleNumber(maxVehicleNumber),
81 const bool loadingFromState = index >= 0;
86 flow.pars->repetitionsDone--;
89 myFlowIDs.insert(std::make_pair(pars->
id, flow.index));
102 result = t->getParameter().scale;
103 }
else if (result != t->getParameter().scale) {
119 if (f.pars->vtypeid == vtypeid) {
141 MSVehicleContainer::VehicleVector::const_iterator veh;
144 refusedEmits.push_back(*veh);
146 numEmitted +=
tryInsert(time, *veh, refusedEmits);
184 refusedEmits.push_back(veh);
199 MSVehicleContainer::VehicleVector::const_iterator veh;
207 if (dev !=
nullptr) {
220 for (std::vector<Flow>::iterator i =
myFlows.begin(); i !=
myFlows.end();) {
223 double typeScale = i->scale;
229 double scale = vehControl.
getScale() * typeScale;
240 tryEmitByProb =
false;
250 if (vtype ==
nullptr) {
263 while (--quota > 0) {
335 MSVehicleContainer::VehicleVector::iterator veh;
337 if ((*veh)->getRoute().getID() == route || route ==
"") {
353 const MSLane*
const vlane = veh->getLane();
354 if (vlane !=
nullptr) {
359 for (
const MSLane*
const l : veh->getEdge()->getLanes()) {
374 if (f.pars->line !=
"") {
391 if (flow.pars->repetitionProbability > 0) {
393 }
else if (flow.pars->poissonRate > 0) {
442 if (f.pars->id ==
id) {
454 const std::string vehID =
id +
"." +
toString(it->second);
std::shared_ptr< const MSRoute > ConstMSRoutePtr
const std::string DEFAULT_VTYPE_ID
const long long int VEHPARS_FORCE_REROUTE
@ BEGIN
The departure is at simulation start.
@ GIVEN
The time is given.
@ SPLIT
The departure is triggered by a train split.
@ SUMO_TAG_FLOWSTATE
a flow state definition (used when saving and loading simulatino state)
@ SUMO_ATTR_NEXT
succesor phase index
@ SUMO_ATTR_END
weights: time range end
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
void addSchedule(const SUMOVehicleParameter &pars, const std::vector< SUMOVehicleParameter::Stop > *addStops=nullptr)
Network * getNetwork() const
@ ROUTE_START_INVALID_LANE
@ ROUTE_START_INVALID_PERMISSIONS
A device that performs vehicle rerouting based on current edge speeds.
void skipRouting(const SUMOTime currentTime)
Labels the current time step as "unroutable".
A road/street connecting two junctions.
bool isVaporizing() const
Returns whether vehicles on this edge shall be vaporized.
bool insertVehicle(SUMOVehicle &v, SUMOTime time, const bool checkOnly=false, const bool forceCheck=false) const
Tries to insert the given vehicle into the network.
void setLastFailedInsertionTime(SUMOTime time) const
Sets the last time a vehicle could not be inserted.
static bool gStateLoaded
Information whether a state has been loaded.
std::vector< Flow > myFlows
Container for periodical vehicle parameters.
void adaptIntermodalRouter(MSTransportableRouter &router) const
int getWaitingVehicleNo() const
Returns the number of waiting vehicles.
void clearPendingVehicles(const std::string &route)
clears out all pending vehicles from a route, "" for all routes
std::map< const MSLane *, int > myPendingEmitsForLane
the number of pending emits for each edge in the current time step
int tryInsert(SUMOTime time, SUMOVehicle *veh, MSVehicleContainer::VehicleVector &refusedEmits)
Tries to emit the vehicle.
bool myEagerInsertionCheck
Whether an edge on which a vehicle could not depart should be ignored in the same step.
SUMOVehicle * getLastFlowVehicle(const std::string &id) const
return the last vehicle for the given flow
int emitVehicles(SUMOTime time)
Emits vehicles that want to depart at the given time.
int getPendingEmits(const MSLane *lane)
return the number of pending emits for the given lane
bool addFlow(SUMOVehicleParameter *const pars, int index=-1)
Adds parameter for a vehicle flow for departure.
bool hasFlow(const std::string &id) const
checks whether the given flow still exists
const SUMOVehicleParameter * getFlowPars(const std::string &id) const
return parameters for the given flow
SUMOTime myPendingEmitsUpdateTime
Last time at which pending emits for each edge where counted.
void retractDescheduleDeparture(const SUMOVehicle *veh)
reverts a previous call to descheduleDeparture (only needed for departPos="random_free")
std::set< SUMOVehicle * > myEmitCandidates
Buffer for vehicles that may be inserted in the current step.
void alreadyDeparted(SUMOVehicle *veh)
stops trying to emit the given vehicle (because it already departed)
SUMOTime myMaxRandomDepartOffset
The maximum random offset to be added to vehicles departure times (non-negative)
MSVehicleContainer::VehicleVector myPendingEmits
Buffers for vehicles that could not be inserted.
MSInsertionControl(MSVehicleControl &vc, SUMOTime maxDepartDelay, bool checkEdgesOnce, int maxVehicleNumber, SUMOTime randomDepartOffset)
Constructor.
MSVehicleControl & myVehicleControl
The assigned vehicle control (needed for vehicle re-insertion and deletion)
std::map< std::string, int > myFlowIDs
Cache for periodical vehicle ids and their most recent index for quicker checking.
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
void determineCandidates(SUMOTime time)
Checks for all vehicles whether they can be emitted.
void updateScale(const std::string vtypeid)
updates the flow scale value to keep track of TraCI-induced change
void checkCandidates(SUMOTime time, const bool preCheck)
Adds all vehicles that should have been emitted earlier to the refuse container.
int getPendingFlowCount() const
Returns the number of flows that are still active.
std::set< const SUMOVehicle * > myAbortedEmits
Set of vehicles which shall not be inserted anymore.
void clearState()
Remove all vehicles before quick-loading state.
int myMaxVehicleNumber
Storage for maximum vehicle number.
void saveState(OutputDevice &out)
Saves the current state into the given stream.
SUMOTime myMaxDepartDelay
The maximum waiting time; vehicles waiting longer are deleted (-1: no deletion)
void descheduleDeparture(const SUMOVehicle *veh)
stops trying to emit the given vehicle (and delete it)
MSVehicleContainer myAllVeh
All loaded vehicles sorted by their departure time.
~MSInsertionControl()
Destructor.
SUMOTime computeRandomDepartOffset() const
compute (optional) random offset to the departure time
SumoRNG myFlowRNG
A random number generator for probabilistic flows.
static double initScale(const std::string vtypeid)
init scale value of flow
Representation of a lane in the micro simulation.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
static SumoRNG * getParsingRNG()
get parsing RNG
static bool dictionary(const std::string &id, ConstMSRoutePtr route)
Adds a route to the dictionary.
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
static bool isEnabled()
returns whether any routing actions take place
bool anyWaitingBefore(SUMOTime time) const
Returns the information whether any vehicles want to depart before the given time.
void remove(SUMOVehicle *veh)
Removes a single vehicle.
void add(SUMOVehicle *veh)
Adds a single vehicle.
void pop()
Removes the uppermost vehicle vector.
std::vector< SUMOVehicle * > VehicleVector
definition of a list of vehicles which have the same departure time
void clearState()
Remove all vehicles before quick-loading state.
const VehicleVector & top()
Returns the uppermost vehicle vector.
The class responsible for building and deletion of vehicles.
double getScale() const
sets the demand scaling factor
bool hasVTypeDistribution(const std::string &id) const
Asks for a vehicle type distribution.
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
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" ...
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.
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.
const RandomDistributor< MSVehicleType * > * getVTypeDistribution(const std::string &typeDistID) const
return the vehicle type distribution with the given id
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false, bool wasKept=false)
Deletes the vehicle.
The car-following model and parameter.
const SUMOVTypeParameter & getParameter() const
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
static void initRandGlobal(SumoRNG *which=nullptr)
Reads the given random number options and initialises the random number generator in accordance.
Represents a generic random distribution.
const std::vector< T > & getVals() const
Returns the members of the distribution.
virtual MSDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or nullptr if not.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
virtual const MSEdge * getEdge() const =0
Returns the edge the object is currently at.
double scale
individual scaling factor (-1 for undefined)
Representation of a vehicle.
virtual int getRouteValidity(bool update=true, bool silent=false, std::string *msgReturn=nullptr)=0
computes validity attributes for the current route
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
Structure representing possible vehicle parameter.
double repetitionProbability
The probability for emitting a vehicle per second.
void incrementFlow(double scale, SumoRNG *rng=nullptr)
increment flow
std::string vtypeid
The vehicle's type id.
SUMOTime repetitionOffset
The time offset between vehicle reinsertions.
int repetitionsDone
The number of times the vehicle was already inserted.
SUMOTime repetitionTotalOffset
The offset between depart and the time for the next vehicle insertions.
SUMOTime repetitionEnd
The time at which the flow ends (only needed when using repetitionProbability)
std::string routeid
The vehicle's route id.
std::string id
The vehicle's id.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
Definition of vehicle flow with the current index for vehicle numbering.