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 /****************************************************************************/
18 // Inserts vehicles into the network when their departure time is reached
19 /****************************************************************************/
20 #ifndef MSInsertionControl_h
21 #define MSInsertionControl_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <vector>
30 #include <map>
31 #include <string>
32 #include "MSNet.h"
33 #include "MSVehicleContainer.h"
34 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 class MSVehicle;
40 class MSVehicleControl;
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 
124 
129  int getPendingFlowCount() const;
130 
132  void alreadyDeparted(SUMOVehicle* veh);
133 
135  void descheduleDeparture(const SUMOVehicle* veh);
136 
137 
139  void clearPendingVehicles(const std::string& route);
140 
141 
146  void determineCandidates(SUMOTime time);
147 
149  int getPendingEmits(const MSLane* lane);
150 
152 
155 
158  void saveState(OutputDevice& out);
159 
161  std::mt19937* getFlowRNG() {
162  return &myFlowRNG;
163  }
164 
165 private:
180  int tryInsert(SUMOTime time, SUMOVehicle* veh,
181  MSVehicleContainer::VehicleVector& refusedEmits);
182 
183 
189  void checkCandidates(SUMOTime time, const bool preCheck);
190 
191 
192 
193 private:
196 
199 
202 
204  std::set<SUMOVehicle*> myEmitCandidates;
205 
207  std::set<const SUMOVehicle*> myAbortedEmits;
208 
212  struct Flow {
216  int index;
217  };
218 
220  std::vector<Flow> myFlows;
221 
223  std::set<std::string> myFlowIDs;
224 
227 
230 
233 
236 
238  std::map<const MSLane*, int> myPendingEmitsForLane;
239 
242 
243 private:
246 
249 
251  std::mt19937 myFlowRNG;
252 
253 };
254 
255 
256 #endif
257 
258 /****************************************************************************/
259 
MSInsertionControl::myFlows
std::vector< Flow > myFlows
Container for periodical vehicle parameters.
Definition: MSInsertionControl.h:220
MSInsertionControl::myMaxDepartDelay
SUMOTime myMaxDepartDelay
The maximum waiting time; vehicles waiting longer are deleted (-1: no deletion)
Definition: MSInsertionControl.h:226
MSInsertionControl::Flow::pars
SUMOVehicleParameter * pars
The parameters.
Definition: MSInsertionControl.h:214
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:229
MSNet.h
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
MSInsertionControl::emitVehicles
int emitVehicles(SUMOTime time)
Emits vehicles that want to depart at the given time.
Definition: MSInsertionControl.cpp:110
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
MSInsertionControl::getPendingFlowCount
int getPendingFlowCount() const
Returns the number of flows that are still active.
Definition: MSInsertionControl.cpp:266
MSInsertionControl::myPendingEmits
MSVehicleContainer::VehicleVector myPendingEmits
Buffers for vehicles that could not be inserted.
Definition: MSInsertionControl.h:201
IntermodalRouter
Definition: MSNet.h:80
MSInsertionControl::myPendingEmitsUpdateTime
SUMOTime myPendingEmitsUpdateTime
Last time at which pending emits for each edge where counted.
Definition: MSInsertionControl.h:235
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:61
MSInsertionControl::myVehicleControl
MSVehicleControl & myVehicleControl
The assigned vehicle control (needed for vehicle re-insertion and deletion)
Definition: MSInsertionControl.h:195
MSInsertionControl::myEmitCandidates
std::set< SUMOVehicle * > myEmitCandidates
Buffer for vehicles that may be inserted in the current step.
Definition: MSInsertionControl.h:204
SUMOVehicleParameter
Structure representing possible vehicle parameter.
Definition: SUMOVehicleParameter.h:291
MSInsertionControl::getWaitingVehicleNo
int getWaitingVehicleNo() const
Returns the number of waiting vehicles.
Definition: MSInsertionControl.cpp:260
MSInsertionControl::myFlowRNG
std::mt19937 myFlowRNG
A random number generator for probabilistic flows.
Definition: MSInsertionControl.h:251
MSInsertionControl::myMaxVehicleNumber
int myMaxVehicleNumber
Storage for maximum vehicle number.
Definition: MSInsertionControl.h:232
MSInsertionControl::computeRandomDepartOffset
SUMOTime computeRandomDepartOffset() const
compute (optional) random offset to the departure time
Definition: MSInsertionControl.cpp:352
MSInsertionControl::adaptIntermodalRouter
void adaptIntermodalRouter(MSNet::MSIntermodalRouter &router) const
Definition: MSInsertionControl.cpp:325
MSInsertionControl::getFlowRNG
std::mt19937 * getFlowRNG()
retrieve internal RNG
Definition: MSInsertionControl.h:161
MSInsertionControl::MSInsertionControl
MSInsertionControl(MSVehicleControl &vc, SUMOTime maxDepartDelay, bool checkEdgesOnce, int maxVehicleNumber, SUMOTime randomDepartOffset)
Constructor.
Definition: MSInsertionControl.cpp:48
MSInsertionControl::Flow::index
int index
the running index
Definition: MSInsertionControl.h:216
MSInsertionControl::saveState
void saveState(OutputDevice &out)
Saves the current state into the given stream.
Definition: MSInsertionControl.cpp:337
MSInsertionControl::myFlowIDs
std::set< std::string > myFlowIDs
Cache for periodical vehicle ids for quicker checking.
Definition: MSInsertionControl.h:223
MSInsertionControl
Inserts vehicles into the network when their departure time is reached.
Definition: MSInsertionControl.h:62
MSInsertionControl::myAbortedEmits
std::set< const SUMOVehicle * > myAbortedEmits
Set of vehicles which shall not be inserted anymore.
Definition: MSInsertionControl.h:207
MSInsertionControl::getPendingEmits
int getPendingEmits(const MSLane *lane)
return the number of pending emits for the given lane
Definition: MSInsertionControl.cpp:300
MSInsertionControl::descheduleDeparture
void descheduleDeparture(const SUMOVehicle *veh)
stops trying to emit the given vehicle (and delete it)
Definition: MSInsertionControl.cpp:272
MSInsertionControl::determineCandidates
void determineCandidates(SUMOTime time)
Checks for all vehicles whether they can be emitted.
Definition: MSInsertionControl.cpp:196
MSInsertionControl::myPendingEmitsForLane
std::map< const MSLane *, int > myPendingEmitsForLane
the number of pending emits for each edge in the current time step
Definition: MSInsertionControl.h:238
MSVehicleContainer::VehicleVector
std::vector< SUMOVehicle * > VehicleVector
definition of a list of vehicles which have the same departure time
Definition: MSVehicleContainer.h:50
MSInsertionControl::operator=
MSInsertionControl & operator=(const MSInsertionControl &)
Invalidated assignment operator.
MSInsertionControl::add
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
Definition: MSInsertionControl.cpp:71
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:171
MSVehicleContainer
Definition: MSVehicleContainer.h:47
MSInsertionControl::clearPendingVehicles
void clearPendingVehicles(const std::string &route)
clears out all pending vehicles from a route, "" for all routes
Definition: MSInsertionControl.cpp:285
MSInsertionControl::addFlow
bool addFlow(SUMOVehicleParameter *const pars, int index=-1)
Adds parameter for a vehicle flow for departure.
Definition: MSInsertionControl.cpp:77
config.h
MSVehicleControl
The class responsible for building and deletion of vehicles.
Definition: MSVehicleControl.h:72
MSInsertionControl::myMaxRandomDepartOffset
SUMOTime myMaxRandomDepartOffset
The maximum random offset to be added to vehicles departure times (non-negative)
Definition: MSInsertionControl.h:241
MSInsertionControl::myAllVeh
MSVehicleContainer myAllVeh
All loaded vehicles sorted by their departure time.
Definition: MSInsertionControl.h:198
MSInsertionControl::Flow
Definition of vehicle flow with the current index for vehicle numbering.
Definition: MSInsertionControl.h:212
MSInsertionControl::tryInsert
int tryInsert(SUMOTime time, SUMOVehicle *veh, MSVehicleContainer::VehicleVector &refusedEmits)
Tries to emit the vehicle.
Definition: MSInsertionControl.cpp:139
MSInsertionControl::~MSInsertionControl
~MSInsertionControl()
Destructor.
Definition: MSInsertionControl.cpp:63
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
MSInsertionControl::alreadyDeparted
void alreadyDeparted(SUMOVehicle *veh)
stops trying to emit the given vehicle (because it already departed)
Definition: MSInsertionControl.cpp:278