Eclipse SUMO - Simulation of Urban MObility
MSInsertionControl.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 /****************************************************************************/
21 // Inserts vehicles into the network when their departure time is reached
22 /****************************************************************************/
23 #pragma once
24 #include <config.h>
25 
26 #include <vector>
27 #include <map>
28 #include <string>
29 #include <set>
31 #include <microsim/MSRouterDefs.h>
32 #include "MSVehicleContainer.h"
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class MSVehicle;
39 class MSVehicleControl;
40 class SUMOVehicle;
42 
43 
44 // ===========================================================================
45 // class definitions
46 // ===========================================================================
63 public:
71  MSInsertionControl(MSVehicleControl& vc, SUMOTime maxDepartDelay, bool checkEdgesOnce, int maxVehicleNumber, SUMOTime randomDepartOffset);
72 
73 
76 
77 
94  int emitVehicles(SUMOTime time);
95 
96 
103  void add(SUMOVehicle* veh);
104 
105 
112  bool addFlow(SUMOVehicleParameter* const pars, int index = -1);
113 
114 
122  int getWaitingVehicleNo() const;
123 
126  return myPendingEmits;
127  }
128 
133  int getPendingFlowCount() const;
134 
136  void alreadyDeparted(SUMOVehicle* veh);
137 
139  void descheduleDeparture(const SUMOVehicle* veh);
140 
142  void retractDescheduleDeparture(const SUMOVehicle* veh);
143 
145  void clearPendingVehicles(const std::string& route);
146 
147 
152  void determineCandidates(SUMOTime time);
153 
155  int getPendingEmits(const MSLane* lane);
156 
157  void adaptIntermodalRouter(MSTransportableRouter& router) const;
158 
161 
164  void saveState(OutputDevice& out);
165 
167  void clearState();
168 
171  return &myFlowRNG;
172  }
173 
175  bool hasFlow(const std::string& id) const {
176  return myFlowIDs.count(id) != 0;
177  }
178 
180  const SUMOVehicleParameter* getFlowPars(const std::string& id) const;
181 
183  SUMOVehicle* getLastFlowVehicle(const std::string& id) const;
184 
186  void updateScale(const std::string vtypeid);
187 
188 private:
203  int tryInsert(SUMOTime time, SUMOVehicle* veh,
204  MSVehicleContainer::VehicleVector& refusedEmits);
205 
206 
212  void checkCandidates(SUMOTime time, const bool preCheck);
213 
214 
215 private:
216 
218  static double initScale(const std::string vtypeid);
219 
220 private:
223 
226 
229 
231  std::set<SUMOVehicle*> myEmitCandidates;
232 
234 
235 #ifdef HAVE_FOX
237 #else
238  std::set<const SUMOVehicle*> myAbortedEmits;
239 #endif
240 
244  struct Flow {
248  int index;
250  double scale;
251  };
252 
254  std::vector<Flow> myFlows;
255 
257  std::map<std::string, int> myFlowIDs;
258 
261 
264 
267 
270 
272  std::map<const MSLane*, int> myPendingEmitsForLane;
273 
276 
277 private:
280 
283 
286 
287 };
long long int SUMOTime
Definition: GUI.h:35
Inserts vehicles into the network when their departure time is reached.
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
const MSVehicleContainer::VehicleVector & getPendingVehicles() const
retrieve vehicles waiting for insertion
void checkCandidates(SUMOTime time, const bool preCheck)
Adds all vehicles that should have been emitted earlier to the refuse container.
MSInsertionControl(const MSInsertionControl &)
Invalidated copy constructor.
SumoRNG * getFlowRNG()
retrieve internal RNG
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.
MSInsertionControl & operator=(const MSInsertionControl &)
Invalidated assignment operator.
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.
Definition: MSLane.h:84
std::vector< SUMOVehicle * > VehicleVector
definition of a list of vehicles which have the same departure time
The class responsible for building and deletion of vehicles.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
Representation of a vehicle.
Definition: SUMOVehicle.h:60
Structure representing possible vehicle parameter.
Definition of vehicle flow with the current index for vehicle numbering.
int index
the running index
SUMOVehicleParameter * pars
The parameters.
double scale
the type scaling of this flow. Negative value indicates inhomogenous type distribution