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-2017 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 double speed);
101 
102 
108  const std::map<SUMOVehicleClass, double>* 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 
224  /* @brief Adds a read parking area to the network
225  *
226  * If the parking area is already known (another one with the same id exists),
227  * an error is generated and given to msg-error-handler. The stop
228  * is deleted in this case
229  *
230  * @param[in] node The stop to add
231  */
232  void addParkingArea(const std::string& id, SUMOVehicleParameter::Stop* stop);
233 
239  const SUMOVehicleParameter::Stop* getBusStop(const std::string& id) const {
240  std::map<std::string, SUMOVehicleParameter::Stop*>::const_iterator it = myBusStops.find(id);
241  if (it == myBusStops.end()) {
242  return 0;
243  }
244  return it->second;
245  }
246 
247 
253  const SUMOVehicleParameter::Stop* getContainerStop(const std::string& id) const {
254  std::map<std::string, SUMOVehicleParameter::Stop*>::const_iterator it = myContainerStops.find(id);
255  if (it == myContainerStops.end()) {
256  return 0;
257  }
258  return it->second;
259  }
260 
261 
267  const SUMOVehicleParameter::Stop* getParkingArea(const std::string& id) const {
268  std::map<std::string, SUMOVehicleParameter::Stop*>::const_iterator it = myParkingAreas.find(id);
269  if (it == myParkingAreas.end()) {
270  return 0;
271  }
272  return it->second;
273  }
275 
276 
277 
279 
280 
287  bool checkVType(const std::string& id);
288 
289 
299  virtual bool addVehicleType(SUMOVTypeParameter* type);
300 
301 
315  bool addVTypeDistribution(const std::string& id, RandomDistributor<SUMOVTypeParameter*>* vehTypeDistribution);
316 
317 
328  SUMOVTypeParameter* getVehicleTypeSecure(const std::string& id);
329 
330 
331  /* @brief Adds a route definition to the network
332  *
333  * If the route definition is already known (another one with
334  * the same id exists), false is returned, but the route definition
335  * is not deleted.
336  *
337  * @param[in] def The route definition to add
338  * @return Whether the route definition could be added
339  * @todo Rename myRoutes to myRouteDefinitions
340  */
341  bool addRouteDef(RORouteDef* def);
342 
343 
351  RORouteDef* getRouteDef(const std::string& name) const {
352  return myRoutes.get(name);
353  }
354 
355 
356  /* @brief Adds a vehicle to the network
357  *
358  * If the vehicle is already known (another one with the same id
359  * exists), false is returned, but the vehicle is not deleted.
360  *
361  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
362  *
363  * @param[in] id The id of the vehicle to add
364  * @param[in] veh The vehicle to add
365  * @return Whether the vehicle could be added
366  */
367  virtual bool addVehicle(const std::string& id, ROVehicle* veh);
368 
369 
370  /* @brief Adds a flow of vehicles to the network
371  *
372  * If the flow is already known (another one with the same id
373  * exists), false is returned, but the vehicle parameter are not deleted.
374  *
375  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
376  *
377  * @param[in] flow The parameter of the flow to add
378  * @return Whether the flow could be added
379  */
380  bool addFlow(SUMOVehicleParameter* flow, const bool randomize);
381 
382 
383  /* @brief Adds a person to the network
384  *
385  * @param[in] person The person to add
386  */
387  bool addPerson(ROPerson* person);
388 
389 
390  /* @brief Adds a container to the network
391  *
392  * @param[in] depart The departure time of the container
393  * @param[in] desc The xml description of the container
394  */
395  void addContainer(const SUMOTime depart, const std::string desc);
396  // @}
397 
398 
400 
401 
414  const RORouterProvider& provider, SUMOTime time);
415 
416 
418  virtual bool furtherStored();
420 
421 
422 
423 
424 
434  void openOutput(const OptionsCont& options, const std::string altFilename = "");
435 
436 
438  void cleanup();
439 
440 
442  int getEdgeNo() const;
443 
445  int getInternalEdgeNumber() const;
446 
447  const std::map<std::string, ROEdge*>& getEdgeMap() const;
448 
449  static void adaptIntermodalRouter(ROIntermodalRouter& router);
450 
451  bool hasPermissions() const;
452 
453  void setPermissionsFound();
454 
455  OutputDevice* getRouteOutput(const bool alternative = false) {
456  if (alternative) {
458  }
459  return myRoutesOutput;
460  }
461 
462 #ifdef HAVE_FOX
463  FXWorkerThread::Pool& getThreadPool() {
464  return myThreadPool;
465  }
466 
467  class WorkerThread : public FXWorkerThread, public RORouterProvider {
468  public:
469  WorkerThread(FXWorkerThread::Pool& pool,
470  const RORouterProvider& original)
471  : FXWorkerThread(pool), RORouterProvider(original) {}
472  virtual ~WorkerThread() {
473  stop();
474  }
475  };
476 
477  class BulkmodeTask : public FXWorkerThread::Task {
478  public:
479  BulkmodeTask(const bool value) : myValue(value) {}
480  void run(FXWorkerThread* context) {
481  static_cast<WorkerThread*>(context)->getVehicleRouter().setBulkMode(myValue);
482  }
483  private:
484  const bool myValue;
485  private:
487  BulkmodeTask& operator=(const BulkmodeTask&);
488  };
489 #endif
490 
491 
492 private:
493  void checkFlows(SUMOTime time, MsgHandler* errorHandler);
494 
495  void createBulkRouteRequests(const RORouterProvider& provider, const SUMOTime time, const bool removeLoops);
496 
497 private:
499  static RONet* myInstance;
500 
502  std::set<std::string> myVehIDs;
503 
505  std::set<std::string> myPersonIDs;
506 
509 
512 
514  std::map<std::string, SUMOVehicleParameter::Stop*> myBusStops;
515 
517  std::map<std::string, SUMOVehicleParameter::Stop*> myContainerStops;
518 
520  std::map<std::string, SUMOVehicleParameter::Stop*> myParkingAreas;
521 
524 
526  typedef std::map< std::string, RandomDistributor<SUMOVTypeParameter*>* > VTypeDistDictType;
528  VTypeDistDictType myVTypeDistDict;
529 
532 
535 
538 
540  RoutablesMap myRoutables;
541 
544 
546  typedef std::multimap<const SUMOTime, const std::string> ContainerMap;
547  ContainerMap myContainers;
548 
550  std::map<std::string, std::vector<SUMOTime> > myDepartures;
551 
553  std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > > myDistricts;
554 
557 
560 
563 
566 
569 
572 
575 
577  std::map<std::string, std::map<SUMOVehicleClass, double> > myRestrictions;
578 
581 
584 
585 #ifdef HAVE_FOX
586 private:
587  class RoutingTask : public FXWorkerThread::Task {
588  public:
589  RoutingTask(RORoutable* v, const bool removeLoops, MsgHandler* errorHandler)
590  : myRoutable(v), myRemoveLoops(removeLoops), myErrorHandler(errorHandler) {}
591  void run(FXWorkerThread* context);
592  private:
593  RORoutable* const myRoutable;
594  const bool myRemoveLoops;
595  MsgHandler* const myErrorHandler;
596  private:
598  RoutingTask& operator=(const RoutingTask&);
599  };
600 
601 
602 private:
604  FXWorkerThread::Pool myThreadPool;
605 #endif
606 
607 private:
609  RONet(const RONet& src);
610 
612  RONet& operator=(const RONet& src);
613 
614 };
615 
616 
617 #endif
618 
619 /****************************************************************************/
620 
RONode * getNode(const std::string &id) const
Retrieves an node from the network.
Definition: RONet.h:197
bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource)
Definition: RONet.cpp:167
OutputDevice * myRouteAlternativesOutput
The file to write the computed route alternatives into.
Definition: RONet.h:559
OutputDevice * getRouteOutput(const bool alternative=false)
Definition: RONet.h:455
NamedObjectCont< SUMOVehicleParameter * > myFlows
Known flows.
Definition: RONet.h:543
ROEdge * getEdgeForLaneID(const std::string &laneID) const
Retrieves an edge from the network when the lane id is given.
Definition: RONet.h:175
int getInternalEdgeNumber() const
Returns the number of internal edges the network contains.
Definition: RONet.cpp:653
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:553
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:574
Represents a generic random distribution.
int myNumInternalEdges
The number of internal edges in the dictionary.
Definition: RONet.h:580
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
Definition: RONet.cpp:308
int getEdgeNo() const
Returns the total number of edges the network contains including internal edges.
Definition: RONet.cpp:647
Structure representing possible vehicle parameter.
static void adaptIntermodalRouter(ROIntermodalRouter &router)
Definition: RONet.cpp:665
void addNode(RONode *node)
Definition: RONet.cpp:189
T get(const std::string &id) const
Retrieves an item.
void checkFlows(SUMOTime time, MsgHandler *errorHandler)
Definition: RONet.cpp:401
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
NamedObjectCont< ROEdge * > myEdges
Known edges.
Definition: RONet.h:511
const std::map< SUMOVehicleClass, double > * getRestrictions(const std::string &id) const
Returns the restrictions for an edge type If no restrictions are present, 0 is returned.
Definition: RONet.cpp:126
bool hasPermissions() const
Definition: RONet.cpp:697
int myDiscardedRouteNo
The number of discarded routes.
Definition: RONet.h:568
A map of named object pointers.
std::map< std::string, std::vector< SUMOTime > > myDepartures
Departure times for randomized flows.
Definition: RONet.h:550
OutputDevice * myTypesOutput
The file to write the vehicle types into.
Definition: RONet.h:562
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
Definition: RONet.h:351
int myWrittenRouteNo
The number of written routes.
Definition: RONet.h:571
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
Definition: RONet.cpp:333
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
Definition: RONet.cpp:356
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
Definition: RONet.cpp:62
void openOutput(const OptionsCont &options, const std::string altFilename="")
Opens the output for computed routes.
Definition: RONet.cpp:237
void addParkingArea(const std::string &id, SUMOVehicleParameter::Stop *stop)
Definition: RONet.cpp:220
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter *> *vehTypeDistribution)
Adds a vehicle type distribution.
Definition: RONet.cpp:346
std::set< std::string > myPersonIDs
Known person ids.
Definition: RONet.h:505
A routable thing such as a vehicle or person.
Definition: RORoutable.h:62
RouterProvider< ROEdge, ROLane, RONode, ROVehicle > RORouterProvider
Definition: RORoutable.h:52
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:257
bool addRouteDef(RORouteDef *def)
Definition: RONet.cpp:231
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction for an edge type.
Definition: RONet.cpp:120
OutputDevice * myRoutesOutput
The file to write the computed routes into.
Definition: RONet.h:556
void addContainer(const SUMOTime depart, const std::string desc)
Definition: RONet.cpp:395
std::map< std::string, SUMOVehicleParameter::Stop * > myContainerStops
Known container stops.
Definition: RONet.h:517
RoutablesMap myRoutables
Known routables.
Definition: RONet.h:540
NamedObjectCont< SUMOVTypeParameter * > myVehicleTypes
Known vehicle types.
Definition: RONet.h:523
std::map< std::string, SUMOVehicleParameter::Stop * > myParkingAreas
Known parking areas.
Definition: RONet.h:520
ContainerMap myContainers
Definition: RONet.h:547
virtual bool furtherStored()
Returns the information whether further vehicles, persons or containers are stored.
Definition: RONet.cpp:641
A person as used by router.
Definition: ROPerson.h:58
static RONet * myInstance
Unique instance of RONet.
Definition: RONet.h:499
bool myDefaultVTypeMayBeDeleted
Whether no vehicle type has been loaded yet.
Definition: RONet.h:531
NamedObjectCont< RORouteDef * > myRoutes
Known routes.
Definition: RONet.h:537
void createBulkRouteRequests(const RORouterProvider &provider, const SUMOTime time, const bool removeLoops)
Definition: RONet.cpp:486
A basic edge for routing applications.
Definition: ROEdge.h:77
RONet()
Constructor.
Definition: RONet.cpp:70
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:150
Structure representing possible vehicle parameter.
int myReadRouteNo
The number of read routes.
Definition: RONet.h:565
std::map< std::string, std::map< SUMOVehicleClass, double > > myRestrictions
The vehicle class specific speed restrictions.
Definition: RONet.h:577
Definition of vehicle stop (position and duration)
const SUMOVehicleParameter::Stop * getContainerStop(const std::string &id) const
Retrieves a container stop from the network.
Definition: RONet.h:253
std::map< std::string, RandomDistributor< SUMOVTypeParameter * > *> VTypeDistDictType
Vehicle type distribution dictionary type.
Definition: RONet.h:526
A storage for options typed value containers)
Definition: OptionsCont.h:99
const std::map< std::string, ROEdge * > & getEdgeMap() const
Definition: RONet.cpp:659
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
Definition: RONet.h:528
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:198
virtual bool addEdge(ROEdge *edge)
Definition: RONet.cpp:136
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
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:502
virtual ~RONet()
Destructor.
Definition: RONet.cpp:92
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:281
A thread repeatingly calculating incoming tasks.
MsgHandler * myErrorHandler
handler for ignorable error messages
Definition: RONet.h:583
long long int SUMOTime
Definition: TraCIDefs.h:52
Base class for nodes used by the router.
Definition: RONode.h:53
NamedObjectCont< RONode * > myNodes
Known nodes.
Definition: RONet.h:508
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:165
std::multimap< const SUMOTime, const std::string > ContainerMap
Known containers.
Definition: RONet.h:546
const SUMOVehicleParameter::Stop * getBusStop(const std::string &id) const
Retrieves a bus stop from the network.
Definition: RONet.h:239
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition: RONet.cpp:369
const SUMOVehicleParameter::Stop * getParkingArea(const std::string &id) const
Retrieves a parking area from the network.
Definition: RONet.h:267
void addContainerStop(const std::string &id, SUMOVehicleParameter::Stop *stop)
Definition: RONet.cpp:209
bool addPerson(ROPerson *person)
Definition: RONet.cpp:383
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:533
std::map< std::string, SUMOVehicleParameter::Stop * > myBusStops
Known bus stops.
Definition: RONet.h:514
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:534
void setPermissionsFound()
Definition: RONet.cpp:703