Eclipse SUMO - Simulation of Urban MObility
MSEdgeControl.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-2020 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 /****************************************************************************/
23 // Stores edges and lanes, performs moving of vehicle
24 /****************************************************************************/
25 #pragma once
26 #include <config.h>
27 
28 #include <vector>
29 #include <map>
30 #include <string>
31 #include <iostream>
32 #include <list>
33 #include <set>
34 #include <queue>
35 #include <utils/common/SUMOTime.h>
36 #include <utils/common/Named.h>
37 #include <utils/common/StopWatch.h>
41 
44 //#define THREAD_POOL
45 #ifdef THREAD_POOL
47 #else
48 #ifdef HAVE_FOX
50 #endif
51 #endif
52 
53 
54 // ===========================================================================
55 // class declarations
56 // ===========================================================================
57 class MSEdge;
58 class MSLane;
59 class MSJunction;
60 class OutputDevice;
61 
62 typedef std::vector<MSEdge*> MSEdgeVector;
63 
64 // ===========================================================================
65 // class definitions
66 // ===========================================================================
82 
83 public:
85 
93  MSEdgeControl(const std::vector< MSEdge* >& edges);
94 
95 
98 
99 
106  void patchActiveLanes();
107 
108 
111 
119  void planMovements(SUMOTime t);
120 
127 
128 
141  void executeMovements(SUMOTime t);
142 
145  }
147 
148 
157  void changeLanes(const SUMOTime t);
158 
159 
170  void detectCollisions(SUMOTime timestep, const std::string& stage);
171 
172 
178  const MSEdgeVector& getEdges() const {
179  return myEdges;
180  }
181 
182 
188  void gotActive(MSLane* l);
189 
192 
195 
197  void setMesoTypes();
198 
199 #ifndef THREAD_POOL
200 #ifdef HAVE_FOX
201  FXWorkerThread::Pool& getThreadPool() {
202  return myThreadPool;
203  }
204 #endif
205 #endif
206 
207 public:
219  struct LaneUsage {
223  bool amActive;
226  };
227 
228 #ifdef HAVE_FOX
233  class WorkerThread : public FXWorkerThread {
234  public:
235  WorkerThread(FXWorkerThread::Pool& pool)
236  : FXWorkerThread(pool), myRouterProvider(nullptr) {}
237 
238  bool setRouterProvider(MSRouterProvider* routerProvider) {
239  if (myRouterProvider == nullptr) {
240  myRouterProvider = routerProvider;
241  return true;
242  }
243  return false;
244  }
246  return myRouterProvider->getVehicleRouter(svc);
247  }
248  virtual ~WorkerThread() {
249  stop();
250  delete myRouterProvider;
251  }
252  private:
253  MSRouterProvider* myRouterProvider;
254  };
255 #endif
256 
257 private:
260 
262  typedef std::vector<LaneUsage> LaneUsageVector;
263 
266 
268  std::list<MSLane*> myActiveLanes;
269 
272 
274  std::set<MSLane*, ComparatorNumericalIdLess> myChangedStateLanes;
275 
277  std::vector<SUMOTime> myLastLaneChange;
278 
281 
283 
284 #ifdef THREAD_POOL
285  WorkStealingThreadPool<> myThreadPool;
286 #else
287 #ifdef HAVE_FOX
288  FXWorkerThread::Pool myThreadPool;
289 #endif
290 #endif
291 
292  std::vector<StopWatch<std::chrono::nanoseconds> > myStopWatch;
293 
294 private:
297 
300 
301 };
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdgeControl.h:60
long long int SUMOTime
Definition: SUMOTime.h:31
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
void push_back(T what)
Definition: FXSynchQue.h:114
A pool of worker threads which distributes the tasks and collects the results.
A thread repeatingly calculating incoming tasks.
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:81
MSEdgeControl & operator=(const MSEdgeControl &)
Assignment operator.
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 setAdditionalRestrictions()
apply additional restrictions
MSEdgeControl(const MSEdgeControl &)
Copy constructor.
FXSynchSet< MSLane *, std::set< MSLane *, ComparatorNumericalIdLess > > myInactiveCheckCollisions
Additional lanes for which collision checking must be performed.
std::list< MSLane * > myActiveLanes
The list of active (not empty) lanes.
void detectCollisions(SUMOTime timestep, const std::string &stage)
Detect collisions.
std::vector< LaneUsage > LaneUsageVector
Definition of a container about a lane's number of vehicles and neighbors.
MSEdgeVector myEdges
Loaded edges.
RouterProvider< MSEdge, MSLane, MSJunction, SUMOVehicle > MSRouterProvider
Definition: MSEdgeControl.h:84
const MSEdgeVector & getEdges() const
Returns 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.
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....
FXSynchQue< MSLane *, std::vector< MSLane * > > myWithVehicles2Integrate
A storage for lanes which shall be integrated because vehicles have moved onto them.
void changeLanes(const SUMOTime t)
Moves (precomputes) critical vehicles.
MSEdgeControl(const std::vector< MSEdge * > &edges)
Constructor.
void needsVehicleIntegration(MSLane *const l)
double myMinLengthGeometryFactor
A road/street connecting two junctions.
Definition: MSEdge.h:77
The base class for an intersection.
Definition: MSJunction.h:58
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
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.
MSLane * lane
The described lane.