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 
411  void openOutput(const std::string& filename, const std::string altFilename, const std::string typeFilename);
412 
413 
415  void cleanup();
416 
417 
419  size_t getEdgeNo() const;
420 
422  int getInternalEdgeNumber() const;
423 
424  const std::map<std::string, ROEdge*>& getEdgeMap() const;
425 
426  static void adaptIntermodalRouter(ROIntermodalRouter& router);
427 
428  bool hasPermissions() const;
429 
430  void setPermissionsFound();
431 
432  OutputDevice* getRouteOutput(const bool alternative = false) {
433  if (alternative) {
435  }
436  return myRoutesOutput;
437  }
438 
439 #ifdef HAVE_FOX
440  FXWorkerThread::Pool& getThreadPool() {
441  return myThreadPool;
442  }
443 
444  class WorkerThread : public FXWorkerThread, public RORouterProvider {
445  public:
446  WorkerThread(FXWorkerThread::Pool& pool,
447  const RORouterProvider& original)
448  : FXWorkerThread(pool), RORouterProvider(original) {}
449  virtual ~WorkerThread() {
450  stop();
451  }
452  };
453 
454  class BulkmodeTask : public FXWorkerThread::Task {
455  public:
456  BulkmodeTask(const bool value) : myValue(value) {}
457  void run(FXWorkerThread* context) {
458  static_cast<WorkerThread*>(context)->getVehicleRouter().setBulkMode(myValue);
459  }
460  private:
461  const bool myValue;
462  private:
464  BulkmodeTask& operator=(const BulkmodeTask&);
465  };
466 #endif
467 
468 
469 private:
470  void checkFlows(SUMOTime time, MsgHandler* errorHandler);
471 
472  void createBulkRouteRequests(const RORouterProvider& provider, const SUMOTime time, const bool removeLoops);
473 
474 private:
476  static RONet* myInstance;
477 
479  std::set<std::string> myVehIDs;
480 
482  std::set<std::string> myPersonIDs;
483 
486 
489 
491  std::map<std::string, SUMOVehicleParameter::Stop*> myBusStops;
492 
494  std::map<std::string, SUMOVehicleParameter::Stop*> myContainerStops;
495 
498 
500  typedef std::map< std::string, RandomDistributor<SUMOVTypeParameter*>* > VTypeDistDictType;
502  VTypeDistDictType myVTypeDistDict;
503 
506 
509 
512 
514  RoutablesMap myRoutables;
515 
518 
520  typedef std::multimap<const SUMOTime, const std::string> ContainerMap;
521  ContainerMap myContainers;
522 
524  std::map<std::string, std::vector<SUMOTime> > myDepartures;
525 
527  std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > > myDistricts;
528 
531 
534 
537 
539  unsigned int myReadRouteNo;
540 
542  unsigned int myDiscardedRouteNo;
543 
545  unsigned int myWrittenRouteNo;
546 
549 
551  std::map<std::string, std::map<SUMOVehicleClass, SUMOReal> > myRestrictions;
552 
555 
558 
559 #ifdef HAVE_FOX
560 private:
561  class RoutingTask : public FXWorkerThread::Task {
562  public:
563  RoutingTask(RORoutable* v, const bool removeLoops, MsgHandler* errorHandler)
564  : myRoutable(v), myRemoveLoops(removeLoops), myErrorHandler(errorHandler) {}
565  void run(FXWorkerThread* context);
566  private:
567  RORoutable* const myRoutable;
568  const bool myRemoveLoops;
569  MsgHandler* const myErrorHandler;
570  private:
572  RoutingTask& operator=(const RoutingTask&);
573  };
574 
575 
576 private:
578  FXWorkerThread::Pool myThreadPool;
579 #endif
580 
581 private:
583  RONet(const RONet& src);
584 
586  RONet& operator=(const RONet& src);
587 
588 };
589 
590 
591 #endif
592 
593 /****************************************************************************/
594 
bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource)
Definition: RONet.cpp:153
OutputDevice * myRouteAlternativesOutput
The file to write the computed route alternatives into.
Definition: RONet.h:533
bool hasPermissions() const
Definition: RONet.cpp:658
long long int SUMOTime
Definition: SUMOTime.h:43
OutputDevice * getRouteOutput(const bool alternative=false)
Definition: RONet.h:432
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:106
NamedObjectCont< SUMOVehicleParameter * > myFlows
Known flows.
Definition: RONet.h:517
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:527
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:548
int myNumInternalEdges
The number of internal edges in the dictionary.
Definition: RONet.h:554
size_t getEdgeNo() const
Returns the total number of edges the network contains including internal edges.
Definition: RONet.cpp:613
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
Definition: RONet.cpp:282
Structure representing possible vehicle parameter.
static void adaptIntermodalRouter(ROIntermodalRouter &router)
Definition: RONet.cpp:631
void addNode(RONode *node)
Definition: RONet.cpp:175
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:375
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:488
unsigned int myDiscardedRouteNo
The number of discarded routes.
Definition: RONet.h:542
std::map< std::string, std::vector< SUMOTime > > myDepartures
Departure times for randomized flows.
Definition: RONet.h:524
OutputDevice * myTypesOutput
The file to write the vehicle types into.
Definition: RONet.h:536
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
Definition: RONet.cpp:307
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
Definition: RONet.cpp:330
const std::map< std::string, ROEdge * > & getEdgeMap() const
Definition: RONet.cpp:625
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
Definition: RONet.cpp:66
void openOutput(const std::string &filename, const std::string altFilename, const std::string typeFilename)
Opens the output for computed routes.
Definition: RONet.cpp:212
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:482
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:320
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:231
bool addRouteDef(RORouteDef *def)
Definition: RONet.cpp:206
OutputDevice * myRoutesOutput
The file to write the computed routes into.
Definition: RONet.h:530
void addContainer(const SUMOTime depart, const std::string desc)
Definition: RONet.cpp:369
std::map< std::string, SUMOVehicleParameter::Stop * > myContainerStops
Known container stops.
Definition: RONet.h:494
RoutablesMap myRoutables
Known routables.
Definition: RONet.h:514
NamedObjectCont< SUMOVTypeParameter * > myVehicleTypes
Known vehicle types.
Definition: RONet.h:497
std::map< std::string, std::map< SUMOVehicleClass, SUMOReal > > myRestrictions
The vehicle class specific speed restrictions.
Definition: RONet.h:551
ContainerMap myContainers
Definition: RONet.h:521
virtual bool furtherStored()
Returns the information whether further vehicles, persons or containers are stored.
Definition: RONet.cpp:607
A person as used by router.
Definition: ROPerson.h:57
static RONet * myInstance
Unique instance of RONet.
Definition: RONet.h:476
unsigned int myReadRouteNo
The number of read routes.
Definition: RONet.h:539
bool myDefaultVTypeMayBeDeleted
Whether no vehicle type has been loaded yet.
Definition: RONet.h:505
NamedObjectCont< RORouteDef * > myRoutes
Known routes.
Definition: RONet.h:511
void createBulkRouteRequests(const RORouterProvider &provider, const SUMOTime time, const bool removeLoops)
Definition: RONet.cpp:460
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:619
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:136
Structure representing possible vehicle parameter.
Definition of vehicle stop (position and duration)
std::map< std::string, RandomDistributor< SUMOVTypeParameter * > * > VTypeDistDictType
Vehicle type distribution dictionary type.
Definition: RONet.h:500
A storage for options typed value containers)
Definition: OptionsCont.h:108
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
Definition: RONet.h:502
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:184
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:122
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:479
virtual ~RONet()
Destructor.
Definition: RONet.cpp:96
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:255
A thread repeatingly calculating incoming tasks.
MsgHandler * myErrorHandler
handler for ignorable error messages
Definition: RONet.h:557
Base class for nodes used by the router.
Definition: RONode.h:53
NamedObjectCont< RONode * > myNodes
Known nodes.
Definition: RONet.h:485
std::multimap< const SUMOTime, const std::string > ContainerMap
Known containers.
Definition: RONet.h:520
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition: RONet.cpp:343
void addContainerStop(const std::string &id, SUMOVehicleParameter::Stop *stop)
Definition: RONet.cpp:195
bool addPerson(ROPerson *person)
Definition: RONet.cpp:357
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:507
std::map< std::string, SUMOVehicleParameter::Stop * > myBusStops
Known bus stops.
Definition: RONet.h:491
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:508
void setPermissionsFound()
Definition: RONet.cpp:664
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:112
unsigned int myWrittenRouteNo
The number of written routes.
Definition: RONet.h:545