35#define PARALLEL_PLAN_MOVE
36#define PARALLEL_EXEC_MOVE
47 myLanes(
MSLane::dictSize()),
48 myWithVehicles2Integrate(
MSGlobals::gNumSimThreads > 1),
49 myLastLaneChange(edges.size()),
50 myInactiveCheckCollisions(
MSGlobals::gNumSimThreads > 1),
51 myMinLengthGeometryFactor(1.),
53 myThreadPool(false,
std::vector<int>(
MSGlobals::gNumThreads, 0)),
58 const std::vector<MSLane*>& lanes = edge->getLanes();
59 if (!edge->hasLaneChanger()) {
60 const int pos = lanes.front()->getNumericalID();
61 myLanes[pos].lane = lanes.front();
63 myLanes[pos].haveNeighbors =
false;
66 for (
MSLane*
const l : lanes) {
67 const int pos = l->getNumericalID();
70 myLanes[pos].haveNeighbors =
true;
80 new WorkerThread(myThreadPool);
94#ifdef PARALLEL_STOPWATCH
97 for (
MSLane*
const l : edge->getLanes()) {
98 wPlan.
add(l->getStopWatch()[0]);
101 std::cout << wPlan.
getHistory().size() <<
" lane planmove calls, average " << wPlan.
getAverage() <<
" ns, total " << wPlan.
getTotal() / double(1e9) <<
" s" << std::endl;
102 std::cout <<
myStopWatch[0].getHistory().size() <<
" planmove calls, average " <<
myStopWatch[0].getAverage() <<
" ns, total " <<
myStopWatch[0].getTotal() / double(1e9) <<
" s" << std::endl;
103 std::cout <<
myStopWatch[1].getHistory().size() <<
" execmove calls, average " <<
myStopWatch[1].getAverage() <<
" ns, total " <<
myStopWatch[1].getTotal() / double(1e9) <<
" s" << std::endl;
110 for (
MSLane* lane : lanes) {
111 myLanes[lane->getNumericalID()].amActive =
true;
120 if (!lu.
amActive && (*i)->getVehicleNumber() > 0) {
136#ifdef PARALLEL_STOPWATCH
140 std::vector<std::future<void>> results;
143 const int vehNum = (*i)->getVehicleNumber();
145 myLanes[(*i)->getNumericalID()].amActive =
false;
150 results.push_back(myThreadPool.executeAsync([i, t](
int) {
151 (*i)->planMovements(t);
159 myThreadPool.add((*i)->getPlanMoveTask(t), (*i)->getRNGIndex() % myThreadPool.size());
165 (*i)->planMovements(t);
170 for (
auto& r : results) {
176 myThreadPool.waitAll(
false);
180#ifdef PARALLEL_STOPWATCH
189 lane->setJunctionApproaches(t);
196#ifdef PARALLEL_STOPWATCH
201#ifdef PARALLEL_EXEC_MOVE
205 myThreadPool.executeAsync([lane, t](
int) {
206 lane->executeMovements(t);
209 myThreadPool.waitAll();
215 myThreadPool.add(lane->getExecuteMoveTask(t), lane->getRNGIndex() % myThreadPool.size());
217 myThreadPool.waitAll(
false);
227 (*i)->getVehicleNumber() > 0) {
228 (*i)->executeMovements(t);
230 if ((*i)->getVehicleNumber() == 0) {
231 myLanes[(*i)->getNumericalID()].amActive =
false;
237 for (
MSLane* lane : wasActive) {
238 lane->updateLengthSum();
248 for (
MSLane*
const lane : toIntegrate) {
249 const bool wasInactive = lane->getVehicleNumber() == 0;
250 lane->integrateNewVehicles();
251 if (wasInactive && lane->getVehicleNumber() > 0) {
263#ifdef PARALLEL_STOPWATCH
271 std::vector<MSLane*> toAdd;
272#ifdef PARALLEL_CHANGE_LANES
273 std::vector<const MSEdge*> recheckLaneUsage;
277 if (
myLanes[l->getNumericalID()].haveNeighbors) {
278 const MSEdge& edge = l->getEdge();
281#ifdef PARALLEL_CHANGE_LANES
284 myThreadPool.add(lane->getLaneChangeTask(t), lane->
getRNGIndex() % myThreadPool.size());
285 recheckLaneUsage.push_back(&edge);
295 if (lane->getVehicleNumber() > 0 && !lu.
amActive) {
296 toAdd.push_back(lane);
300 lane->sortManeuverReservations();
303#ifdef PARALLEL_CHANGE_LANES
312#ifdef PARALLEL_CHANGE_LANES
314 myThreadPool.waitAll(
false);
315 for (
const MSEdge* e : recheckLaneUsage) {
316 for (
MSLane*
const l : e->getLanes()) {
318 if (l->getVehicleNumber() > 0 && !lu.
amActive) {
323 l->sortManeuverReservations();
331 for (std::vector<MSLane*>::iterator i = toAdd.begin(); i != toAdd.end(); ++i) {
341 if (lane->needsCollisionCheck()) {
342 lane->detectCollisions(timestep, stage);
347 lane->detectCollisions(timestep, stage);
369 const std::vector<MSLane*>& lanes = e->getLanes();
370 for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
371 (*j)->initRestrictions();
379 edge->updateMesoType();
#define PARALLEL_EXEC_MOVE
@ SUMO_TAG_EDGECONTROL
the internal state for edge control
Container & getContainer()
Container & getContainer()
void patchActiveLanes()
Resets information whether a lane is active for all lanes.
std::vector< StopWatch< std::chrono::nanoseconds > > myStopWatch
~MSEdgeControl()
Destructor.
void setMesoTypes()
update meso edge type parameters
void setActiveLanes(std::list< MSLane * > lanes)
Reconstruct the current state.
void setAdditionalRestrictions()
apply additional restrictions
std::list< MSLane * > myActiveLanes
The list of active (not empty) lanes.
void detectCollisions(SUMOTime timestep, const std::string &stage)
Detect collisions.
MFXSynchQue< MSLane *, std::vector< MSLane * > > myWithVehicles2Integrate
A storage for lanes which shall be integrated because vehicles have moved onto them.
MSEdgeVector myEdges
Loaded edges.
void setJunctionApproaches(SUMOTime t)
Register junction approaches for all vehicles after velocities have been planned. This is a prerequis...
void executeMovements(SUMOTime t)
Executes planned vehicle movements with regards to right-of-way.
MFXSynchSet< MSLane *, std::set< MSLane *, ComparatorNumericalIdLess > > myInactiveCheckCollisions
Additional lanes for which collision checking must be performed.
LaneUsageVector myLanes
Information about lanes' number of vehicles and neighbors.
void gotActive(MSLane *l)
Informs the control that the given lane got active.
void checkCollisionForInactive(MSLane *l)
trigger collision checking for inactive lane
std::vector< SUMOTime > myLastLaneChange
The list of active (not empty) lanes.
std::set< MSLane *, ComparatorNumericalIdLess > myChangedStateLanes
Lanes which changed the state without informing the control.
void planMovements(SUMOTime t)
Compute safe velocities for all vehicles based on positions and speeds from the last time step....
void saveState(OutputDevice &out)
Saves the current state into the given stream.
void changeLanes(const SUMOTime t)
Moves (precomputes) critical vehicles.
MSEdgeControl(const std::vector< MSEdge * > &edges)
Constructor.
double myMinLengthGeometryFactor
A road/street connecting two junctions.
void changeLanes(SUMOTime t) const
Performs lane changing on this edge.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
int getNumericalID() const
Returns the numerical id of the edge.
static double gLateralResolution
static bool gComputeLC
whether the simulationLoop is in the lane changing phase
static int gNumSimThreads
how many threads to use for simulation
static int gNumThreads
how many threads to use
Representation of a lane in the micro simulation.
int getRNGIndex() const
returns the associated RNG index
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
void removePending()
Removes a vehicle after it has ended.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
long long int getTotal() const
long long int getAverage() const
void add(const StopWatch< TimeT, ClockT > &other)
const std::vector< TimeT > & getHistory() const
Function-object for stable sorting of objects acting like Named without being derived (SUMOVehicle)
A structure holding some basic information about a simulated lane.
bool amActive
Information whether this lane is active.
bool haveNeighbors
Information whether this lane belongs to a multi-lane edge.