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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Inserts vehicles into the network when their departure time is reached
18 /****************************************************************************/
19 #ifndef MSInsertionControl_h
20 #define MSInsertionControl_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <vector>
29 #include <map>
30 #include <string>
31 #include "MSNet.h"
32 #include "MSVehicleContainer.h"
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class MSVehicle;
39 class MSVehicleControl;
41 
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
62 public:
70  MSInsertionControl(MSVehicleControl& vc, SUMOTime maxDepartDelay, bool checkEdgesOnce, int maxVehicleNumber, SUMOTime randomDepartOffset);
71 
72 
75 
76 
93  int emitVehicles(SUMOTime time);
94 
95 
102  void add(SUMOVehicle* veh);
103 
104 
111  bool addFlow(SUMOVehicleParameter* const pars, int index = -1);
112 
113 
121  int getWaitingVehicleNo() const;
122 
123 
128  int getPendingFlowCount() const;
129 
131  void alreadyDeparted(SUMOVehicle* veh);
132 
134  void descheduleDeparture(const SUMOVehicle* veh);
135 
136 
138  void clearPendingVehicles(const std::string& route);
139 
140 
145  void determineCandidates(SUMOTime time);
146 
148  int getPendingEmits(const MSLane* lane);
149 
151 
154 
157  void saveState(OutputDevice& out);
158 
160  std::mt19937* getFlowRNG() {
161  return &myFlowRNG;
162  }
163 
164 private:
179  int tryInsert(SUMOTime time, SUMOVehicle* veh,
180  MSVehicleContainer::VehicleVector& refusedEmits);
181 
182 
188  void checkCandidates(SUMOTime time, const bool preCheck);
189 
190 
191 
192 private:
195 
198 
201 
203  std::set<SUMOVehicle*> myEmitCandidates;
204 
206  std::set<const SUMOVehicle*> myAbortedEmits;
207 
211  struct Flow {
215  int index;
216  };
217 
219  std::vector<Flow> myFlows;
220 
222  std::set<std::string> myFlowIDs;
223 
226 
229 
232 
235 
237  std::map<const MSLane*, int> myPendingEmitsForLane;
238 
241 
242 private:
245 
248 
250  std::mt19937 myFlowRNG;
251 
252 };
253 
254 
255 #endif
256 
257 /****************************************************************************/
258 
MSInsertionControl::myFlows
std::vector< Flow > myFlows
Container for periodical vehicle parameters.
Definition: MSInsertionControl.h:219
MSInsertionControl::myMaxDepartDelay
SUMOTime myMaxDepartDelay
The maximum waiting time; vehicles waiting longer are deleted (-1: no deletion)
Definition: MSInsertionControl.h:225
MSInsertionControl::Flow::pars
SUMOVehicleParameter * pars
The parameters.
Definition: MSInsertionControl.h:213
MSVehicleContainer.h
MSInsertionControl::myEagerInsertionCheck
bool myEagerInsertionCheck
Whether an edge on which a vehicle could not depart should be ignored in the same step.
Definition: MSInsertionControl.h:228
MSNet.h
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
MSInsertionControl::emitVehicles
int emitVehicles(SUMOTime time)
Emits vehicles that want to depart at the given time.
Definition: MSInsertionControl.cpp:109
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
MSInsertionControl::getPendingFlowCount
int getPendingFlowCount() const
Returns the number of flows that are still active.
Definition: MSInsertionControl.cpp:265
MSInsertionControl::myPendingEmits
MSVehicleContainer::VehicleVector myPendingEmits
Buffers for vehicles that could not be inserted.
Definition: MSInsertionControl.h:200
IntermodalRouter
Definition: IntermodalRouter.h:54
MSInsertionControl::myPendingEmitsUpdateTime
SUMOTime myPendingEmitsUpdateTime
Last time at which pending emits for each edge where counted.
Definition: MSInsertionControl.h:234
MSInsertionControl::MSInsertionControl
MSInsertionControl(const MSInsertionControl &)
Invalidated copy constructor.
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:60
MSInsertionControl::myVehicleControl
MSVehicleControl & myVehicleControl
The assigned vehicle control (needed for vehicle re-insertion and deletion)
Definition: MSInsertionControl.h:194
MSInsertionControl::myEmitCandidates
std::set< SUMOVehicle * > myEmitCandidates
Buffer for vehicles that may be inserted in the current step.
Definition: MSInsertionControl.h:203
SUMOVehicleParameter
Structure representing possible vehicle parameter.
Definition: SUMOVehicleParameter.h:297
MSInsertionControl::getWaitingVehicleNo
int getWaitingVehicleNo() const
Returns the number of waiting vehicles.
Definition: MSInsertionControl.cpp:259
MSInsertionControl::myFlowRNG
std::mt19937 myFlowRNG
A random number generator for probabilistic flows.
Definition: MSInsertionControl.h:250
MSInsertionControl::myMaxVehicleNumber
int myMaxVehicleNumber
Storage for maximum vehicle number.
Definition: MSInsertionControl.h:231
MSInsertionControl::computeRandomDepartOffset
SUMOTime computeRandomDepartOffset() const
compute (optional) random offset to the departure time
Definition: MSInsertionControl.cpp:349
MSInsertionControl::adaptIntermodalRouter
void adaptIntermodalRouter(MSNet::MSIntermodalRouter &router) const
Definition: MSInsertionControl.cpp:322
MSInsertionControl::getFlowRNG
std::mt19937 * getFlowRNG()
retrieve internal RNG
Definition: MSInsertionControl.h:160
MSInsertionControl::MSInsertionControl
MSInsertionControl(MSVehicleControl &vc, SUMOTime maxDepartDelay, bool checkEdgesOnce, int maxVehicleNumber, SUMOTime randomDepartOffset)
Constructor.
Definition: MSInsertionControl.cpp:47
MSInsertionControl::Flow::index
int index
the running index
Definition: MSInsertionControl.h:215
MSInsertionControl::saveState
void saveState(OutputDevice &out)
Saves the current state into the given stream.
Definition: MSInsertionControl.cpp:334
MSInsertionControl::myFlowIDs
std::set< std::string > myFlowIDs
Cache for periodical vehicle ids for quicker checking.
Definition: MSInsertionControl.h:222
MSInsertionControl
Inserts vehicles into the network when their departure time is reached.
Definition: MSInsertionControl.h:61
MSInsertionControl::myAbortedEmits
std::set< const SUMOVehicle * > myAbortedEmits
Set of vehicles which shall not be inserted anymore.
Definition: MSInsertionControl.h:206
MSInsertionControl::getPendingEmits
int getPendingEmits(const MSLane *lane)
return the number of pending emits for the given lane
Definition: MSInsertionControl.cpp:299
MSInsertionControl::descheduleDeparture
void descheduleDeparture(const SUMOVehicle *veh)
stops trying to emit the given vehicle (and delete it)
Definition: MSInsertionControl.cpp:271
MSInsertionControl::determineCandidates
void determineCandidates(SUMOTime time)
Checks for all vehicles whether they can be emitted.
Definition: MSInsertionControl.cpp:195
MSInsertionControl::myPendingEmitsForLane
std::map< const MSLane *, int > myPendingEmitsForLane
the number of pending emits for each edge in the current time step
Definition: MSInsertionControl.h:237
MSVehicleContainer::VehicleVector
std::vector< SUMOVehicle * > VehicleVector
definition of a list of vehicles which have the same departure time
Definition: MSVehicleContainer.h:49
MSInsertionControl::operator=
MSInsertionControl & operator=(const MSInsertionControl &)
Invalidated assignment operator.
MSInsertionControl::add
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
Definition: MSInsertionControl.cpp:70
MSInsertionControl::checkCandidates
void checkCandidates(SUMOTime time, const bool preCheck)
Adds all vehicles that should have been emitted earlier to the refuse container.
Definition: MSInsertionControl.cpp:170
MSVehicleContainer
Definition: MSVehicleContainer.h:46
MSInsertionControl::clearPendingVehicles
void clearPendingVehicles(const std::string &route)
clears out all pending vehicles from a route, "" for all routes
Definition: MSInsertionControl.cpp:284
MSInsertionControl::addFlow
bool addFlow(SUMOVehicleParameter *const pars, int index=-1)
Adds parameter for a vehicle flow for departure.
Definition: MSInsertionControl.cpp:76
config.h
MSVehicleControl
The class responsible for building and deletion of vehicles.
Definition: MSVehicleControl.h:71
MSInsertionControl::myMaxRandomDepartOffset
SUMOTime myMaxRandomDepartOffset
The maximum random offset to be added to vehicles departure times (non-negative)
Definition: MSInsertionControl.h:240
MSInsertionControl::myAllVeh
MSVehicleContainer myAllVeh
All loaded vehicles sorted by their departure time.
Definition: MSInsertionControl.h:197
MSInsertionControl::Flow
Definition of vehicle flow with the current index for vehicle numbering.
Definition: MSInsertionControl.h:211
MSInsertionControl::tryInsert
int tryInsert(SUMOTime time, SUMOVehicle *veh, MSVehicleContainer::VehicleVector &refusedEmits)
Tries to emit the vehicle.
Definition: MSInsertionControl.cpp:138
MSInsertionControl::~MSInsertionControl
~MSInsertionControl()
Destructor.
Definition: MSInsertionControl.cpp:62
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
MSInsertionControl::alreadyDeparted
void alreadyDeparted(SUMOVehicle *veh)
stops trying to emit the given vehicle (because it already departed)
Definition: MSInsertionControl.cpp:277