Eclipse SUMO - Simulation of Urban MObility
RONet.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
18 // The router's network representation
19 /****************************************************************************/
20 #ifndef RONet_h
21 #define RONet_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <vector>
35 #include "ROLane.h"
36 #include "RORoutable.h"
37 #include "RORouteDef.h"
38 
39 #ifdef HAVE_FOX
41 #endif
42 
43 
44 // ===========================================================================
45 // class declarations
46 // ===========================================================================
47 class ROEdge;
48 class RONode;
49 class ROPerson;
50 class ROVehicle;
51 class OptionsCont;
52 class OutputDevice;
53 
54 
55 // ===========================================================================
56 // class definitions
57 // ===========================================================================
64 class RONet {
65 public:
66 
67  typedef std::map<const SUMOTime, std::vector<RORoutable*> > RoutablesMap;
68 
70  RONet();
71 
72 
76  static RONet* getInstance();
77 
78 
80  virtual ~RONet();
81 
82 
88  void addRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed);
89 
90 
96  const std::map<SUMOVehicleClass, double>* getRestrictions(const std::string& id) const;
97 
98 
100 
101 
102  /* @brief Adds a read edge to the network
103  *
104  * If the edge is already known (another one with the same id exists),
105  * an error is generated and given to msg-error-handler. The edge
106  * is deleted in this case and false is returned.
107  *
108  * @param[in] edge The edge to add
109  * @return Whether the edge was added (if not, it was deleted, too)
110  */
111  virtual bool addEdge(ROEdge* edge);
112 
113 
114  /* @brief Adds a district and connecting edges to the network
115  *
116  * If the district is already known (another one with the same id exists),
117  * an error is generated and given to msg-error-handler. The edges
118  * are deleted in this case and false is returned.
119  *
120  * @param[in] id The district to add
121  * @return Whether the district was added
122  */
123  bool addDistrict(const std::string id, ROEdge* source, ROEdge* sink);
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 addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource);
136 
141  const std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > >& getDistricts() const {
142  return myDistricts;
143  }
144 
153  ROEdge* getEdge(const std::string& name) const {
154  return myEdges.get(name);
155  }
156 
157 
163  ROEdge* getEdgeForLaneID(const std::string& laneID) const {
164  return getEdge(laneID.substr(0, laneID.rfind("_")));
165  }
166 
167 
168  /* @brief Adds a read node to the network
169  *
170  * If the node is already known (another one with the same id exists),
171  * an error is generated and given to msg-error-handler. The node
172  * is deleted in this case
173  *
174  * @param[in] node The node to add
175  */
176  void addNode(RONode* node);
177 
178 
185  RONode* getNode(const std::string& id) const {
186  return myNodes.get(id);
187  }
188 
189 
190  /* @brief Adds a read stopping place (bus, train, container, parking) to the network
191  *
192  * If the place is already known (another one with the same id and category exists),
193  * an error is generated and given to msg-error-handler. The stop
194  * is deleted in this case
195  *
196  * @param[in] id The name of the stop to add
197  * @param[in] category The type of stop
198  * @param[in] stop The detailed stop description
199  */
200  void addStoppingPlace(const std::string& id, const SumoXMLTag category, SUMOVehicleParameter::Stop* stop);
201 
208  const SUMOVehicleParameter::Stop* getStoppingPlace(const std::string& id, const SumoXMLTag category) const {
209  if (myStoppingPlaces.count(category) > 0) {
210  return myStoppingPlaces.find(category)->second.get(id);
211  }
212  return 0;
213  }
214 
216  const std::string getStoppingPlaceName(const std::string& id) const;
218 
219 
220 
222 
223 
230  bool checkVType(const std::string& id);
231 
232 
242  virtual bool addVehicleType(SUMOVTypeParameter* type);
243 
244 
258  bool addVTypeDistribution(const std::string& id, RandomDistributor<SUMOVTypeParameter*>* vehTypeDistribution);
259 
260 
271  SUMOVTypeParameter* getVehicleTypeSecure(const std::string& id);
272 
273 
274  /* @brief Adds a route definition to the network
275  *
276  * If the route definition is already known (another one with
277  * the same id exists), false is returned, but the route definition
278  * is not deleted.
279  *
280  * @param[in] def The route definition to add
281  * @return Whether the route definition could be added
282  * @todo Rename myRoutes to myRouteDefinitions
283  */
284  bool addRouteDef(RORouteDef* def);
285 
286 
294  RORouteDef* getRouteDef(const std::string& name) const {
295  return myRoutes.get(name);
296  }
297 
298 
299  /* @brief Adds a vehicle to the network
300  *
301  * If the vehicle is already known (another one with the same id
302  * exists), false is returned, but the vehicle is not deleted.
303  *
304  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
305  *
306  * @param[in] id The id of the vehicle to add
307  * @param[in] veh The vehicle to add
308  * @return Whether the vehicle could be added
309  */
310  virtual bool addVehicle(const std::string& id, ROVehicle* veh);
311 
312 
313  /* @brief Adds a flow of vehicles to the network
314  *
315  * If the flow is already known (another one with the same id
316  * exists), false is returned, but the vehicle parameter are not deleted.
317  *
318  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
319  *
320  * @param[in] flow The parameter of the flow to add
321  * @return Whether the flow could be added
322  */
323  bool addFlow(SUMOVehicleParameter* flow, const bool randomize);
324 
325 
326  /* @brief Adds a person to the network
327  *
328  * @param[in] person The person to add
329  */
330  bool addPerson(ROPerson* person);
331 
332 
333  /* @brief Adds a container to the network
334  *
335  * @param[in] depart The departure time of the container
336  * @param[in] desc The xml description of the container
337  */
338  void addContainer(const SUMOTime depart, const std::string desc);
339  // @}
340 
341 
343 
344 
357  const RORouterProvider& provider, SUMOTime time);
358 
359 
361  bool furtherStored();
363 
364 
371  void openOutput(const OptionsCont& options);
372 
373 
380  void writeIntermodal(const OptionsCont& options, ROIntermodalRouter& router) const;
381 
382 
384  void cleanup();
385 
386 
388  int getEdgeNumber() const;
389 
391  int getInternalEdgeNumber() const;
392 
394  return myEdges;
395  }
396 
397  static void adaptIntermodalRouter(ROIntermodalRouter& router);
398 
399  bool hasPermissions() const;
400 
401  void setPermissionsFound();
402 
403  OutputDevice* getRouteOutput(const bool alternative = false) {
404  if (alternative) {
406  }
407  return myRoutesOutput;
408  }
409 
410 #ifdef HAVE_FOX
411  FXWorkerThread::Pool& getThreadPool() {
412  return myThreadPool;
413  }
414 
415  class WorkerThread : public FXWorkerThread, public RORouterProvider {
416  public:
417  WorkerThread(FXWorkerThread::Pool& pool,
418  const RORouterProvider& original)
419  : FXWorkerThread(pool), RORouterProvider(original) {}
420  virtual ~WorkerThread() {
421  stop();
422  }
423  };
424 
425  class BulkmodeTask : public FXWorkerThread::Task {
426  public:
427  BulkmodeTask(const bool value) : myValue(value) {}
428  void run(FXWorkerThread* context) {
429  static_cast<WorkerThread*>(context)->getVehicleRouter().setBulkMode(myValue);
430  }
431  private:
432  const bool myValue;
433  private:
435  BulkmodeTask& operator=(const BulkmodeTask&);
436  };
437 #endif
438 
439 
440 private:
441  void checkFlows(SUMOTime time, MsgHandler* errorHandler);
442 
443  void createBulkRouteRequests(const RORouterProvider& provider, const SUMOTime time, const bool removeLoops);
444 
445 private:
447  static RONet* myInstance;
448 
450  std::set<std::string> myVehIDs;
451 
453  std::set<std::string> myPersonIDs;
454 
457 
460 
462  std::map<SumoXMLTag, NamedObjectCont<SUMOVehicleParameter::Stop*> > myStoppingPlaces;
463 
466 
468  typedef std::map< std::string, RandomDistributor<SUMOVTypeParameter*>* > VTypeDistDictType;
470  VTypeDistDictType myVTypeDistDict;
471 
474 
477 
480 
483 
485  RoutablesMap myRoutables;
486 
489 
492 
494  typedef std::multimap<const SUMOTime, const std::string> ContainerMap;
495  ContainerMap myContainers;
496 
498  std::vector<const RORoutable*> myPTVehicles;
499 
501  std::map<std::string, std::vector<SUMOTime> > myDepartures;
502 
504  std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > > myDistricts;
505 
508 
511 
514 
517 
520 
523 
526 
528  std::map<std::string, std::map<SUMOVehicleClass, double> > myRestrictions;
529 
532 
535 
537  const bool myKeepVTypeDist;
538 
539 #ifdef HAVE_FOX
540 private:
541  class RoutingTask : public FXWorkerThread::Task {
542  public:
543  RoutingTask(RORoutable* v, const bool removeLoops, MsgHandler* errorHandler)
544  : myRoutable(v), myRemoveLoops(removeLoops), myErrorHandler(errorHandler) {}
545  void run(FXWorkerThread* context);
546  private:
547  RORoutable* const myRoutable;
548  const bool myRemoveLoops;
549  MsgHandler* const myErrorHandler;
550  private:
552  RoutingTask& operator=(const RoutingTask&);
553  };
554 
555 
556 private:
558  FXWorkerThread::Pool myThreadPool;
559 #endif
560 
561 private:
563  RONet(const RONet& src);
564 
566  RONet& operator=(const RONet& src);
567 
568 };
569 
570 
571 #endif
572 
573 /****************************************************************************/
574 
RONode * getNode(const std::string &id) const
Retrieves an node from the network.
Definition: RONet.h:185
bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource)
Definition: RONet.cpp:169
std::map< SumoXMLTag, NamedObjectCont< SUMOVehicleParameter::Stop * > > myStoppingPlaces
Known bus / train / container stops and parking areas.
Definition: RONet.h:462
OutputDevice * myRouteAlternativesOutput
The file to write the computed route alternatives into.
Definition: RONet.h:510
int getEdgeNumber() const
Returns the total number of edges the network contains including internal edges.
Definition: RONet.cpp:649
SumoXMLTag
Numbers representing SUMO-XML - element names.
long long int SUMOTime
Definition: SUMOTime.h:35
OutputDevice * getRouteOutput(const bool alternative=false)
Definition: RONet.h:403
NamedObjectCont< SUMOVehicleParameter * > myFlows
Known flows.
Definition: RONet.h:488
ROEdge * getEdgeForLaneID(const std::string &laneID) const
Retrieves an edge from the network when the lane id is given.
Definition: RONet.h:163
int getInternalEdgeNumber() const
Returns the number of internal edges the network contains.
Definition: RONet.cpp:655
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:504
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
void writeIntermodal(const OptionsCont &options, ROIntermodalRouter &router) const
Writes the intermodal network and weights if requested.
Definition: RONet.cpp:236
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
Definition: RONet.h:525
Represents a generic random distribution.
int myNumInternalEdges
The number of internal edges in the dictionary.
Definition: RONet.h:531
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
Definition: RONet.cpp:309
Structure representing possible vehicle parameter.
static void adaptIntermodalRouter(ROIntermodalRouter &router)
Definition: RONet.cpp:661
void addNode(RONode *node)
Definition: RONet.cpp:191
T get(const std::string &id) const
Retrieves an item.
void checkFlows(SUMOTime time, MsgHandler *errorHandler)
Definition: RONet.cpp:409
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:141
bool myHaveActiveFlows
whether any flows are still active
Definition: RONet.h:491
NamedObjectCont< ROEdge * > myEdges
Known edges.
Definition: RONet.h:459
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:128
bool hasPermissions() const
Definition: RONet.cpp:693
int myDiscardedRouteNo
The number of discarded routes.
Definition: RONet.h:519
A map of named object pointers.
std::map< std::string, std::vector< SUMOTime > > myDepartures
Departure times for randomized flows.
Definition: RONet.h:501
std::vector< const RORoutable * > myPTVehicles
vehicles to keep for public transport routing
Definition: RONet.h:498
OutputDevice * myTypesOutput
The file to write the vehicle types into.
Definition: RONet.h:513
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
Definition: RONet.h:294
int myWrittenRouteNo
The number of written routes.
Definition: RONet.h:522
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
Definition: RONet.cpp:334
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
Definition: RONet.cpp:357
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
Definition: RONet.cpp:56
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter *> *vehTypeDistribution)
Adds a vehicle type distribution.
Definition: RONet.cpp:347
std::set< std::string > myPersonIDs
Known person ids.
Definition: RONet.h:453
A routable thing such as a vehicle or person.
Definition: RORoutable.h:55
void openOutput(const OptionsCont &options)
Opens the output for computed routes.
Definition: RONet.cpp:215
RouterProvider< ROEdge, ROLane, RONode, ROVehicle > RORouterProvider
Definition: RORoutable.h:45
A vehicle as used by router.
Definition: ROVehicle.h:53
std::map< const SUMOTime, std::vector< RORoutable * > > RoutablesMap
Definition: RONet.h:67
void cleanup()
closes the file output for computed routes and deletes associated threads if necessary ...
Definition: RONet.cpp:255
bool addRouteDef(RORouteDef *def)
Definition: RONet.cpp:209
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction for an edge type.
Definition: RONet.cpp:122
OutputDevice * myRoutesOutput
The file to write the computed routes into.
Definition: RONet.h:507
const SUMOVehicleParameter::Stop * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Retrieves a stopping place from the network.
Definition: RONet.h:208
void addContainer(const SUMOTime depart, const std::string desc)
Definition: RONet.cpp:403
RoutablesMap myRoutables
Known routables.
Definition: RONet.h:485
bool myDefaultBikeTypeMayBeDeleted
Whether the default bicycle type was already used or can still be replaced.
Definition: RONet.h:479
NamedObjectCont< SUMOVTypeParameter * > myVehicleTypes
Known vehicle types.
Definition: RONet.h:465
ContainerMap myContainers
Definition: RONet.h:495
bool furtherStored()
Returns the information whether further vehicles, persons or containers are stored.
Definition: RONet.cpp:643
A person as used by router.
Definition: ROPerson.h:51
static RONet * myInstance
Unique instance of RONet.
Definition: RONet.h:447
bool myDefaultVTypeMayBeDeleted
Whether the default vehicle type was already used or can still be replaced.
Definition: RONet.h:473
NamedObjectCont< RORouteDef * > myRoutes
Known routes.
Definition: RONet.h:482
void createBulkRouteRequests(const RORouterProvider &provider, const SUMOTime time, const bool removeLoops)
Definition: RONet.cpp:489
const bool myKeepVTypeDist
whether to keep the the vtype distribution in output
Definition: RONet.h:537
A basic edge for routing applications.
Definition: ROEdge.h:73
Definition of vehicle stop (position and duration)
RONet()
Constructor.
Definition: RONet.cpp:64
A pool of worker threads which distributes the tasks and collects the results.
The router&#39;s network representation.
Definition: RONet.h:64
bool addDistrict(const std::string id, ROEdge *source, ROEdge *sink)
Definition: RONet.cpp:152
Structure representing possible vehicle parameter.
const NamedObjectCont< ROEdge * > & getEdgeMap() const
Definition: RONet.h:393
int myReadRouteNo
The number of read routes.
Definition: RONet.h:516
void addStoppingPlace(const std::string &id, const SumoXMLTag category, SUMOVehicleParameter::Stop *stop)
Definition: RONet.cpp:200
std::map< std::string, std::map< SUMOVehicleClass, double > > myRestrictions
The vehicle class specific speed restrictions.
Definition: RONet.h:528
std::map< std::string, RandomDistributor< SUMOVTypeParameter * > *> VTypeDistDictType
Vehicle type distribution dictionary type.
Definition: RONet.h:468
A storage for options typed value containers)
Definition: OptionsCont.h:90
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
Definition: RONet.h:470
Base class for a vehicle&#39;s route definition.
Definition: RORouteDef.h:56
const std::string getStoppingPlaceName(const std::string &id) const
return the name for the given stopping place id
Definition: RONet.cpp:704
virtual bool addEdge(ROEdge *edge)
Definition: RONet.cpp:138
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
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:450
virtual ~RONet()
Destructor.
Definition: RONet.cpp:94
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:279
A thread repeatingly calculating incoming tasks.
MsgHandler * myErrorHandler
handler for ignorable error messages
Definition: RONet.h:534
Base class for nodes used by the router.
Definition: RONode.h:46
NamedObjectCont< RONode * > myNodes
Known nodes.
Definition: RONet.h:456
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:153
std::multimap< const SUMOTime, const std::string > ContainerMap
Known containers.
Definition: RONet.h:494
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition: RONet.cpp:377
bool addPerson(ROPerson *person)
Definition: RONet.cpp:391
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:535
bool myDefaultPedTypeMayBeDeleted
Whether the default pedestrian type was already used or can still be replaced.
Definition: RONet.h:476
void setPermissionsFound()
Definition: RONet.cpp:699