SUMO - Simulation of Urban MObility
RONet.h
Go to the documentation of this file.
1 /****************************************************************************/
10 // The router's network representation
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2002-2016 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 #ifndef RONet_h
24 #define RONet_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <queue>
37 #include <vector>
45 #include "ROLane.h"
46 #include "RORoutable.h"
47 #include "RORouteDef.h"
48 
49 #ifdef HAVE_FOX
51 #endif
52 
53 
54 // ===========================================================================
55 // class declarations
56 // ===========================================================================
57 class ROEdge;
58 class ROLane;
59 class RONode;
60 class ROPerson;
61 class RORoutable;
62 class ROVehicle;
63 class OptionsCont;
64 class OutputDevice;
65 
66 
67 // ===========================================================================
68 // class definitions
69 // ===========================================================================
76 class RONet {
77 public:
78 
79  typedef std::map<const SUMOTime, std::deque<RORoutable*> > RoutablesMap;
80 
82  RONet();
83 
84 
88  static RONet* getInstance();
89 
90 
92  virtual ~RONet();
93 
94 
100  void addRestriction(const std::string& id, const SUMOVehicleClass svc, const SUMOReal speed);
101 
102 
108  const std::map<SUMOVehicleClass, SUMOReal>* getRestrictions(const std::string& id) const;
109 
110 
112 
113 
114  /* @brief Adds a read edge to the network
115  *
116  * If the edge is already known (another one with the same id exists),
117  * an error is generated and given to msg-error-handler. The edge
118  * is deleted in this case and false is returned.
119  *
120  * @param[in] edge The edge to add
121  * @return Whether the edge was added (if not, it was deleted, too)
122  */
123  virtual bool addEdge(ROEdge* edge);
124 
125 
126  /* @brief Adds a district and connecting edges to the network
127  *
128  * If the district is already known (another one with the same id exists),
129  * an error is generated and given to msg-error-handler. The edges
130  * are deleted in this case and false is returned.
131  *
132  * @param[in] id The district to add
133  * @return Whether the district was added
134  */
135  bool addDistrict(const std::string id, ROEdge* source, ROEdge* sink);
136 
137 
138  /* @brief Adds a district and connecting edges to the network
139  *
140  * If the district is already known (another one with the same id exists),
141  * an error is generated and given to msg-error-handler. The edges
142  * are deleted in this case and false is returned.
143  *
144  * @param[in] id The district to add
145  * @return Whether the district was added
146  */
147  bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource);
148 
153  const std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > >& getDistricts() const {
154  return myDistricts;
155  }
156 
165  ROEdge* getEdge(const std::string& name) const {
166  return myEdges.get(name);
167  }
168 
169 
175  ROEdge* getEdgeForLaneID(const std::string& laneID) const {
176  return getEdge(laneID.substr(0, laneID.rfind("_")));
177  }
178 
179 
180  /* @brief Adds a read node to the network
181  *
182  * If the node is already known (another one with the same id exists),
183  * an error is generated and given to msg-error-handler. The node
184  * is deleted in this case
185  *
186  * @param[in] node The node to add
187  */
188  void addNode(RONode* node);
189 
190 
197  RONode* getNode(const std::string& id) const {
198  return myNodes.get(id);
199  }
200 
201 
202  /* @brief Adds a read bus stop to the network
203  *
204  * If the bus stop is already known (another one with the same id exists),
205  * an error is generated and given to msg-error-handler. The stop
206  * is deleted in this case
207  *
208  * @param[in] node The stop to add
209  */
210  void addBusStop(const std::string& id, SUMOVehicleParameter::Stop* stop);
211 
212 
213  /* @brief Adds a read container stop to the network
214  *
215  * If the container stop is already known (another one with the same id exists),
216  * an error is generated and given to msg-error-handler. The stop
217  * is deleted in this case
218  *
219  * @param[in] node The stop to add
220  */
221  void addContainerStop(const std::string& id, SUMOVehicleParameter::Stop* stop);
222 
223 
229  const SUMOVehicleParameter::Stop* getBusStop(const std::string& id) const {
230  std::map<std::string, SUMOVehicleParameter::Stop*>::const_iterator it = myBusStops.find(id);
231  if (it == myBusStops.end()) {
232  return 0;
233  }
234  return it->second;
235  }
236 
237 
243  const SUMOVehicleParameter::Stop* getContainerStop(const std::string& id) const {
244  std::map<std::string, SUMOVehicleParameter::Stop*>::const_iterator it = myContainerStops.find(id);
245  if (it == myContainerStops.end()) {
246  return 0;
247  }
248  return it->second;
249  }
251 
252 
253 
255 
256 
263  bool checkVType(const std::string& id);
264 
265 
275  virtual bool addVehicleType(SUMOVTypeParameter* type);
276 
277 
291  bool addVTypeDistribution(const std::string& id, RandomDistributor<SUMOVTypeParameter*>* vehTypeDistribution);
292 
293 
304  SUMOVTypeParameter* getVehicleTypeSecure(const std::string& id);
305 
306 
307  /* @brief Adds a route definition to the network
308  *
309  * If the route definition is already known (another one with
310  * the same id exists), false is returned, but the route definition
311  * is not deleted.
312  *
313  * @param[in] def The route definition to add
314  * @return Whether the route definition could be added
315  * @todo Rename myRoutes to myRouteDefinitions
316  */
317  bool addRouteDef(RORouteDef* def);
318 
319 
327  RORouteDef* getRouteDef(const std::string& name) const {
328  return myRoutes.get(name);
329  }
330 
331 
332  /* @brief Adds a vehicle to the network
333  *
334  * If the vehicle is already known (another one with the same id
335  * exists), false is returned, but the vehicle is not deleted.
336  *
337  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
338  *
339  * @param[in] id The id of the vehicle to add
340  * @param[in] veh The vehicle to add
341  * @return Whether the vehicle could be added
342  */
343  virtual bool addVehicle(const std::string& id, ROVehicle* veh);
344 
345 
346  /* @brief Adds a flow of vehicles to the network
347  *
348  * If the flow is already known (another one with the same id
349  * exists), false is returned, but the vehicle parameter are not deleted.
350  *
351  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
352  *
353  * @param[in] flow The parameter of the flow to add
354  * @return Whether the flow could be added
355  */
356  bool addFlow(SUMOVehicleParameter* flow, const bool randomize);
357 
358 
359  /* @brief Adds a person to the network
360  *
361  * @param[in] person The person to add
362  */
363  bool addPerson(ROPerson* person);
364 
365 
366  /* @brief Adds a container to the network
367  *
368  * @param[in] depart The departure time of the container
369  * @param[in] desc The xml description of the container
370  */
371  void addContainer(const SUMOTime depart, const std::string desc);
372  // @}
373 
374 
376 
377 
390  const RORouterProvider& provider, SUMOTime time);
391 
392 
394  virtual bool furtherStored();
396 
397 
398 
399 
400 
410  void openOutput(const OptionsCont& options, const std::string altFilename = "");
411 
412 
414  void cleanup();
415 
416 
418  int getEdgeNo() const;
419 
421  int getInternalEdgeNumber() const;
422 
423  const std::map<std::string, ROEdge*>& getEdgeMap() const;
424 
425  static void adaptIntermodalRouter(ROIntermodalRouter& router);
426 
427  bool hasPermissions() const;
428 
429  void setPermissionsFound();
430 
431  OutputDevice* getRouteOutput(const bool alternative = false) {
432  if (alternative) {
434  }
435  return myRoutesOutput;
436  }
437 
438 #ifdef HAVE_FOX
439  FXWorkerThread::Pool& getThreadPool() {
440  return myThreadPool;
441  }
442 
443  class WorkerThread : public FXWorkerThread, public RORouterProvider {
444  public:
445  WorkerThread(FXWorkerThread::Pool& pool,
446  const RORouterProvider& original)
447  : FXWorkerThread(pool), RORouterProvider(original) {}
448  virtual ~WorkerThread() {
449  stop();
450  }
451  };
452 
453  class BulkmodeTask : public FXWorkerThread::Task {
454  public:
455  BulkmodeTask(const bool value) : myValue(value) {}
456  void run(FXWorkerThread* context) {
457  static_cast<WorkerThread*>(context)->getVehicleRouter().setBulkMode(myValue);
458  }
459  private:
460  const bool myValue;
461  private:
463  BulkmodeTask& operator=(const BulkmodeTask&);
464  };
465 #endif
466 
467 
468 private:
469  void checkFlows(SUMOTime time, MsgHandler* errorHandler);
470 
471  void createBulkRouteRequests(const RORouterProvider& provider, const SUMOTime time, const bool removeLoops);
472 
473 private:
475  static RONet* myInstance;
476 
478  std::set<std::string> myVehIDs;
479 
481  std::set<std::string> myPersonIDs;
482 
485 
488 
490  std::map<std::string, SUMOVehicleParameter::Stop*> myBusStops;
491 
493  std::map<std::string, SUMOVehicleParameter::Stop*> myContainerStops;
494 
497 
499  typedef std::map< std::string, RandomDistributor<SUMOVTypeParameter*>* > VTypeDistDictType;
501  VTypeDistDictType myVTypeDistDict;
502 
505 
508 
511 
513  RoutablesMap myRoutables;
514 
517 
519  typedef std::multimap<const SUMOTime, const std::string> ContainerMap;
520  ContainerMap myContainers;
521 
523  std::map<std::string, std::vector<SUMOTime> > myDepartures;
524 
526  std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > > myDistricts;
527 
530 
533 
536 
539 
542 
545 
548 
550  std::map<std::string, std::map<SUMOVehicleClass, SUMOReal> > myRestrictions;
551 
554 
557 
558 #ifdef HAVE_FOX
559 private:
560  class RoutingTask : public FXWorkerThread::Task {
561  public:
562  RoutingTask(RORoutable* v, const bool removeLoops, MsgHandler* errorHandler)
563  : myRoutable(v), myRemoveLoops(removeLoops), myErrorHandler(errorHandler) {}
564  void run(FXWorkerThread* context);
565  private:
566  RORoutable* const myRoutable;
567  const bool myRemoveLoops;
568  MsgHandler* const myErrorHandler;
569  private:
571  RoutingTask& operator=(const RoutingTask&);
572  };
573 
574 
575 private:
577  FXWorkerThread::Pool myThreadPool;
578 #endif
579 
580 private:
582  RONet(const RONet& src);
583 
585  RONet& operator=(const RONet& src);
586 
587 };
588 
589 
590 #endif
591 
592 /****************************************************************************/
593 
bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource)
Definition: RONet.cpp:171
OutputDevice * myRouteAlternativesOutput
The file to write the computed route alternatives into.
Definition: RONet.h:532
bool hasPermissions() const
Definition: RONet.cpp:676
long long int SUMOTime
Definition: SUMOTime.h:43
OutputDevice * getRouteOutput(const bool alternative=false)
Definition: RONet.h:431
const std::map< std::string, std::pair< std::vector< std::string >, std::vector< std::string > > > & getDistricts() const
Retrieves all TAZ (districts) from the network.
Definition: RONet.h:153
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const SUMOReal speed)
Adds a restriction for an edge type.
Definition: RONet.cpp:124
NamedObjectCont< SUMOVehicleParameter * > myFlows
Known flows.
Definition: RONet.h:516
A single lane the router may use.
Definition: ROLane.h:57
std::map< std::string, std::pair< std::vector< std::string >, std::vector< std::string > > > myDistricts
traffic assignment zones with sources and sinks
Definition: RONet.h:526
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
Definition: RONet.h:547
int myNumInternalEdges
The number of internal edges in the dictionary.
Definition: RONet.h:553
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
Definition: RONet.cpp:299
Structure representing possible vehicle parameter.
static void adaptIntermodalRouter(ROIntermodalRouter &router)
Definition: RONet.cpp:649
void addNode(RONode *node)
Definition: RONet.cpp:193
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:165
void checkFlows(SUMOTime time, MsgHandler *errorHandler)
Definition: RONet.cpp:392
const SUMOVehicleParameter::Stop * getContainerStop(const std::string &id) const
Retrieves a container stop from the network.
Definition: RONet.h:243
NamedObjectCont< ROEdge * > myEdges
Known edges.
Definition: RONet.h:487
int myDiscardedRouteNo
The number of discarded routes.
Definition: RONet.h:541
std::map< std::string, std::vector< SUMOTime > > myDepartures
Departure times for randomized flows.
Definition: RONet.h:523
OutputDevice * myTypesOutput
The file to write the vehicle types into.
Definition: RONet.h:535
int myWrittenRouteNo
The number of written routes.
Definition: RONet.h:544
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
Definition: RONet.cpp:324
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
Definition: RONet.cpp:347
const std::map< std::string, ROEdge * > & getEdgeMap() const
Definition: RONet.cpp:643
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
Definition: RONet.cpp:66
void openOutput(const OptionsCont &options, const std::string altFilename="")
Opens the output for computed routes.
Definition: RONet.cpp:230
T get(const std::string &id) const
Retrieves an item.
const SUMOVehicleParameter::Stop * getBusStop(const std::string &id) const
Retrieves a bus stop from the network.
Definition: RONet.h:229
std::set< std::string > myPersonIDs
Known person ids.
Definition: RONet.h:481
A routable thing such as a vehicle or person.
Definition: RORoutable.h:62
RouterProvider< ROEdge, ROLane, RONode, ROVehicle > RORouterProvider
Definition: RORoutable.h:52
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter * > *vehTypeDistribution)
Adds a vehicle type distribution.
Definition: RONet.cpp:337
A vehicle as used by router.
Definition: ROVehicle.h:60
void cleanup()
closes the file output for computed routes and deletes associated threads if necessary ...
Definition: RONet.cpp:248
bool addRouteDef(RORouteDef *def)
Definition: RONet.cpp:224
OutputDevice * myRoutesOutput
The file to write the computed routes into.
Definition: RONet.h:529
void addContainer(const SUMOTime depart, const std::string desc)
Definition: RONet.cpp:386
std::map< std::string, SUMOVehicleParameter::Stop * > myContainerStops
Known container stops.
Definition: RONet.h:493
RoutablesMap myRoutables
Known routables.
Definition: RONet.h:513
NamedObjectCont< SUMOVTypeParameter * > myVehicleTypes
Known vehicle types.
Definition: RONet.h:496
std::map< std::string, std::map< SUMOVehicleClass, SUMOReal > > myRestrictions
The vehicle class specific speed restrictions.
Definition: RONet.h:550
ContainerMap myContainers
Definition: RONet.h:520
virtual bool furtherStored()
Returns the information whether further vehicles, persons or containers are stored.
Definition: RONet.cpp:625
A person as used by router.
Definition: ROPerson.h:58
static RONet * myInstance
Unique instance of RONet.
Definition: RONet.h:475
int getEdgeNo() const
Returns the total number of edges the network contains including internal edges.
Definition: RONet.cpp:631
bool myDefaultVTypeMayBeDeleted
Whether no vehicle type has been loaded yet.
Definition: RONet.h:504
NamedObjectCont< RORouteDef * > myRoutes
Known routes.
Definition: RONet.h:510
void createBulkRouteRequests(const RORouterProvider &provider, const SUMOTime time, const bool removeLoops)
Definition: RONet.cpp:477
A basic edge for routing applications.
Definition: ROEdge.h:77
int getInternalEdgeNumber() const
Returns the number of internal edges the network contains.
Definition: RONet.cpp:637
ROEdge * getEdgeForLaneID(const std::string &laneID) const
Retrieves an edge from the network when the lane id is given.
Definition: RONet.h:175
RONet()
Constructor.
Definition: RONet.cpp:74
A pool of worker threads which distributes the tasks and collects the results.
The router&#39;s network representation.
Definition: RONet.h:76
bool addDistrict(const std::string id, ROEdge *source, ROEdge *sink)
Definition: RONet.cpp:154
Structure representing possible vehicle parameter.
int myReadRouteNo
The number of read routes.
Definition: RONet.h:538
Definition of vehicle stop (position and duration)
std::map< std::string, RandomDistributor< SUMOVTypeParameter * > * > VTypeDistDictType
Vehicle type distribution dictionary type.
Definition: RONet.h:499
A storage for options typed value containers)
Definition: OptionsCont.h:99
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
Definition: RONet.h:501
Base class for a vehicle&#39;s route definition.
Definition: RORouteDef.h:63
void addBusStop(const std::string &id, SUMOVehicleParameter::Stop *stop)
Definition: RONet.cpp:202
RONode * getNode(const std::string &id) const
Retrieves an node from the network.
Definition: RONet.h:197
virtual bool addEdge(ROEdge *edge)
Definition: RONet.cpp:140
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:213
Abstract superclass of a task to be run with an index to keep track of pending tasks.
std::set< std::string > myVehIDs
Known vehicle ids.
Definition: RONet.h:478
virtual ~RONet()
Destructor.
Definition: RONet.cpp:96
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:272
A thread repeatingly calculating incoming tasks.
MsgHandler * myErrorHandler
handler for ignorable error messages
Definition: RONet.h:556
Base class for nodes used by the router.
Definition: RONode.h:53
NamedObjectCont< RONode * > myNodes
Known nodes.
Definition: RONet.h:484
std::multimap< const SUMOTime, const std::string > ContainerMap
Known containers.
Definition: RONet.h:519
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition: RONet.cpp:360
void addContainerStop(const std::string &id, SUMOVehicleParameter::Stop *stop)
Definition: RONet.cpp:213
bool addPerson(ROPerson *person)
Definition: RONet.cpp:374
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
Definition: RONet.h:327
RONet & operator=(const RONet &src)
Invalidated assignment operator.
SUMOTime saveAndRemoveRoutesUntil(OptionsCont &options, const RORouterProvider &provider, SUMOTime time)
Computes routes described by their definitions and saves them.
Definition: RONet.cpp:524
std::map< std::string, SUMOVehicleParameter::Stop * > myBusStops
Known bus stops.
Definition: RONet.h:490
std::map< const SUMOTime, std::deque< RORoutable * > > RoutablesMap
Definition: RONet.h:79
bool myDefaultPedTypeMayBeDeleted
Whether no pedestrian type has been loaded yet.
Definition: RONet.h:507
void setPermissionsFound()
Definition: RONet.cpp:682
const std::map< SUMOVehicleClass, SUMOReal > * getRestrictions(const std::string &id) const
Returns the restrictions for an edge type If no restrictions are present, 0 is returned.
Definition: RONet.cpp:130