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.org/sumo
3 // Copyright (C) 2001-2022 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 "MSNet.h"
30 #include "MSVehicleContainer.h"
31 
32 
33 // ===========================================================================
34 // class declarations
35 // ===========================================================================
36 class MSVehicle;
37 class MSVehicleControl;
39 
40 
41 // ===========================================================================
42 // class definitions
43 // ===========================================================================
60 public:
68  MSInsertionControl(MSVehicleControl& vc, SUMOTime maxDepartDelay, bool checkEdgesOnce, int maxVehicleNumber, SUMOTime randomDepartOffset);
69 
70 
73 
74 
91  int emitVehicles(SUMOTime time);
92 
93 
100  void add(SUMOVehicle* veh);
101 
102 
109  bool addFlow(SUMOVehicleParameter* const pars, int index = -1);
110 
111 
119  int getWaitingVehicleNo() const;
120 
123  return myPendingEmits;
124  }
125 
130  int getPendingFlowCount() const;
131 
133  void alreadyDeparted(SUMOVehicle* veh);
134 
136  void descheduleDeparture(const SUMOVehicle* veh);
137 
138 
140  void clearPendingVehicles(const std::string& route);
141 
142 
147  void determineCandidates(SUMOTime time);
148 
150  int getPendingEmits(const MSLane* lane);
151 
153 
156 
159  void saveState(OutputDevice& out);
160 
162  void clearState();
163 
166  return &myFlowRNG;
167  }
168 
169 private:
184  int tryInsert(SUMOTime time, SUMOVehicle* veh,
185  MSVehicleContainer::VehicleVector& refusedEmits);
186 
187 
193  void checkCandidates(SUMOTime time, const bool preCheck);
194 
195 
196 
197 private:
200 
203 
206 
208  std::set<SUMOVehicle*> myEmitCandidates;
209 
211  std::set<const SUMOVehicle*> myAbortedEmits;
212 
216  struct Flow {
220  int index;
221  };
222 
224  std::vector<Flow> myFlows;
225 
227  std::set<std::string> myFlowIDs;
228 
231 
234 
237 
240 
242  std::map<const MSLane*, int> myPendingEmitsForLane;
243 
246 
247 private:
250 
253 
256 
257 };
long long int SUMOTime
Definition: SUMOTime.h:32
Inserts vehicles into the network when their departure time is reached.
std::vector< Flow > myFlows
Container for periodical vehicle parameters.
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.
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.
SUMOTime myPendingEmitsUpdateTime
Last time at which pending emits for each edge where counted.
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)
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
void determineCandidates(SUMOTime time)
Checks for all vehicles whether they can be emitted.
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.
std::set< std::string > myFlowIDs
Cache for periodical vehicle ids for quicker checking.
void adaptIntermodalRouter(MSNet::MSIntermodalRouter &router) const
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.
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
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:75
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.