37#define PARALLEL_PLAN_MOVE
38#define PARALLEL_EXEC_MOVE
49 myLanes(
MSLane::dictSize()),
50 myWithVehicles2Integrate(
MSGlobals::gNumSimThreads > 1),
51 myLastLaneChange(edges.size()),
52 myInactiveCheckCollisions(
MSGlobals::gNumSimThreads > 1),
53 myMinLengthGeometryFactor(1.),
55 myThreadPool(false,
std::vector<int>(
MSGlobals::gNumThreads, 0)),
60 const std::vector<MSLane*>& lanes = edge->getLanes();
61 if (!edge->hasLaneChanger()) {
62 const int pos = lanes.front()->getNumericalID();
63 myLanes[pos].lane = lanes.front();
65 myLanes[pos].haveNeighbors =
false;
68 for (
MSLane*
const l : lanes) {
69 const int pos = l->getNumericalID();
72 myLanes[pos].haveNeighbors =
true;
82 new WorkerThread(myThreadPool);
96#ifdef PARALLEL_STOPWATCH
99 for (
MSLane*
const l : edge->getLanes()) {
100 wPlan.
add(l->getStopWatch()[0]);
103 std::cout << wPlan.
getHistory().size() <<
" lane planmove calls, average " << wPlan.
getAverage() <<
" ns, total " << wPlan.
getTotal() / double(1e9) <<
" s" << std::endl;
104 std::cout <<
myStopWatch[0].getHistory().size() <<
" planmove calls, average " <<
myStopWatch[0].getAverage() <<
" ns, total " <<
myStopWatch[0].getTotal() / double(1e9) <<
" s" << std::endl;
105 std::cout <<
myStopWatch[1].getHistory().size() <<
" execmove calls, average " <<
myStopWatch[1].getAverage() <<
" ns, total " <<
myStopWatch[1].getTotal() / double(1e9) <<
" s" << std::endl;
112 for (
MSLane* lane : lanes) {
113 myLanes[lane->getNumericalID()].amActive =
true;
122 if (!lu.
amActive && (*i)->getVehicleNumber() > 0) {
138#ifdef PARALLEL_STOPWATCH
142 std::vector<std::future<void>> results;
145 const int vehNum = (*i)->getVehicleNumber();
147 myLanes[(*i)->getNumericalID()].amActive =
false;
152 results.push_back(myThreadPool.executeAsync([i, t](
int) {
153 (*i)->planMovements(t);
161 myThreadPool.add((*i)->getPlanMoveTask(t), (*i)->getRNGIndex() % myThreadPool.size());
167 (*i)->planMovements(t);
172 for (
auto& r : results) {
178 myThreadPool.waitAll(
false);
182#ifdef PARALLEL_STOPWATCH
193 std::vector<std::future<void>> results;
195 results.push_back(myThreadPool.executeAsync([lane](
int) {
196 lane->setJunctionApproaches();
199 for (
auto& r : results) {
208 myThreadPool.add(lane->getJunctionApproachTask(0), lane->getRNGIndex() % myThreadPool.size());
210 myThreadPool.waitAll(
false);
216 lane->setJunctionApproaches();
223#ifdef PARALLEL_STOPWATCH
228#ifdef PARALLEL_EXEC_MOVE
232 myThreadPool.executeAsync([lane, t](
int) {
233 lane->executeMovements(t);
236 myThreadPool.waitAll();
242 myThreadPool.add(lane->getExecuteMoveTask(t), lane->getRNGIndex() % myThreadPool.size());
244 myThreadPool.waitAll(
false);
254 (*i)->getVehicleNumber() > 0) {
255 (*i)->executeMovements(t);
257 if ((*i)->getVehicleNumber() == 0) {
258 myLanes[(*i)->getNumericalID()].amActive =
false;
264 for (
MSLane* lane : wasActive) {
265 lane->updateLengthSum();
275 for (
MSLane*
const lane : toIntegrate) {
276 const bool wasInactive = lane->getVehicleNumber() == 0;
277 lane->integrateNewVehicles();
278 if (wasInactive && lane->getVehicleNumber() > 0) {
290#ifdef PARALLEL_STOPWATCH
298 std::vector<MSLane*> toAdd;
299#ifdef PARALLEL_CHANGE_LANES
300 std::vector<const MSEdge*> recheckLaneUsage;
304 if (
myLanes[l->getNumericalID()].haveNeighbors) {
305 const MSEdge& edge = l->getEdge();
308#ifdef PARALLEL_CHANGE_LANES
311 myThreadPool.add(lane->getLaneChangeTask(t), lane->
getRNGIndex() % myThreadPool.size());
312 recheckLaneUsage.push_back(&edge);
322 if (lane->getVehicleNumber() > 0 && !lu.
amActive) {
323 toAdd.push_back(lane);
327 lane->sortManeuverReservations();
330#ifdef PARALLEL_CHANGE_LANES
339#ifdef PARALLEL_CHANGE_LANES
341 myThreadPool.waitAll(
false);
342 for (
const MSEdge* e : recheckLaneUsage) {
343 for (
MSLane*
const l : e->getLanes()) {
345 if (l->getVehicleNumber() > 0 && !lu.
amActive) {
350 l->sortManeuverReservations();
358 for (std::vector<MSLane*>::iterator i = toAdd.begin(); i != toAdd.end(); ++i) {
368 if (lane->needsCollisionCheck()) {
369 lane->detectCollisions(timestep, stage);
374 lane->detectCollisions(timestep, stage);
396 const std::vector<MSLane*>& lanes = e->getLanes();
397 for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
398 (*j)->initRestrictions();
407 if (!edge->getLanes().empty()) {
#define PARALLEL_EXEC_MOVE
@ SUMO_TAG_EDGECONTROL
the internal state for edge control
void buildSegmentsFor(const MSEdge &e, const OptionsCont &oc)
Build the segments for a given edge.
Container & getContainer()
Container & getContainer()
void setJunctionApproaches()
Register junction approaches for all vehicles after velocities have been planned. This is a prerequis...
void patchActiveLanes()
Resets information whether a lane is active for all lanes.
std::vector< StopWatch< std::chrono::nanoseconds > > myStopWatch
~MSEdgeControl()
Destructor.
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 buildMesoSegments()
build meso segments after meso edge types are loaded
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 MELoop * gMesoNet
mesoscopic simulation infrastructure
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.
A storage for options typed value containers)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
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.