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 /****************************************************************************/
17 // The router's network representation
18 /****************************************************************************/
19 #ifndef RONet_h
20 #define RONet_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <vector>
34 #include "ROLane.h"
35 #include "RORoutable.h"
36 #include "RORouteDef.h"
37 
38 #ifdef HAVE_FOX
40 #endif
41 
42 
43 // ===========================================================================
44 // class declarations
45 // ===========================================================================
46 class ROEdge;
47 class RONode;
48 class ROPerson;
49 class ROVehicle;
50 class OptionsCont;
51 class OutputDevice;
52 
53 
54 // ===========================================================================
55 // class definitions
56 // ===========================================================================
63 class RONet {
64 public:
65 
66  typedef std::map<const SUMOTime, std::vector<RORoutable*> > RoutablesMap;
67 
69  RONet();
70 
71 
75  static RONet* getInstance();
76 
77 
79  virtual ~RONet();
80 
81 
87  void addRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed);
88 
89 
95  const std::map<SUMOVehicleClass, double>* getRestrictions(const std::string& id) const;
96 
97 
99 
100 
101  /* @brief Adds a read edge to the network
102  *
103  * If the edge is already known (another one with the same id exists),
104  * an error is generated and given to msg-error-handler. The edge
105  * is deleted in this case and false is returned.
106  *
107  * @param[in] edge The edge to add
108  * @return Whether the edge was added (if not, it was deleted, too)
109  */
110  virtual bool addEdge(ROEdge* edge);
111 
112 
113  /* @brief Adds a district and connecting edges to the network
114  *
115  * If the district is already known (another one with the same id exists),
116  * an error is generated and given to msg-error-handler. The edges
117  * are deleted in this case and false is returned.
118  *
119  * @param[in] id The district to add
120  * @return Whether the district was added
121  */
122  bool addDistrict(const std::string id, ROEdge* source, ROEdge* sink);
123 
124 
125  /* @brief Adds a district and connecting edges to the network
126  *
127  * If the district is already known (another one with the same id exists),
128  * an error is generated and given to msg-error-handler. The edges
129  * are deleted in this case and false is returned.
130  *
131  * @param[in] id The district to add
132  * @return Whether the district was added
133  */
134  bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource);
135 
140  const std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > >& getDistricts() const {
141  return myDistricts;
142  }
143 
152  ROEdge* getEdge(const std::string& name) const {
153  return myEdges.get(name);
154  }
155 
156 
162  ROEdge* getEdgeForLaneID(const std::string& laneID) const {
163  return getEdge(laneID.substr(0, laneID.rfind("_")));
164  }
165 
166 
167  /* @brief Adds a read node to the network
168  *
169  * If the node is already known (another one with the same id exists),
170  * an error is generated and given to msg-error-handler. The node
171  * is deleted in this case
172  *
173  * @param[in] node The node to add
174  */
175  void addNode(RONode* node);
176 
177 
184  RONode* getNode(const std::string& id) const {
185  return myNodes.get(id);
186  }
187 
188 
189  /* @brief Adds a read stopping place (bus, train, container, parking) to the network
190  *
191  * If the place is already known (another one with the same id and category exists),
192  * an error is generated and given to msg-error-handler. The stop
193  * is deleted in this case
194  *
195  * @param[in] id The name of the stop to add
196  * @param[in] category The type of stop
197  * @param[in] stop The detailed stop description
198  */
199  void addStoppingPlace(const std::string& id, const SumoXMLTag category, SUMOVehicleParameter::Stop* stop);
200 
207  const SUMOVehicleParameter::Stop* getStoppingPlace(const std::string& id, const SumoXMLTag category) const {
208  if (myStoppingPlaces.count(category) > 0) {
209  return myStoppingPlaces.find(category)->second.get(id);
210  }
211  return 0;
212  }
213 
215  const std::string getStoppingPlaceName(const std::string& id) const;
217 
218 
219 
221 
222 
229  bool checkVType(const std::string& id);
230 
231 
241  virtual bool addVehicleType(SUMOVTypeParameter* type);
242 
243 
257  bool addVTypeDistribution(const std::string& id, RandomDistributor<SUMOVTypeParameter*>* vehTypeDistribution);
258 
259 
270  SUMOVTypeParameter* getVehicleTypeSecure(const std::string& id);
271 
272 
273  /* @brief Adds a route definition to the network
274  *
275  * If the route definition is already known (another one with
276  * the same id exists), false is returned, but the route definition
277  * is not deleted.
278  *
279  * @param[in] def The route definition to add
280  * @return Whether the route definition could be added
281  * @todo Rename myRoutes to myRouteDefinitions
282  */
283  bool addRouteDef(RORouteDef* def);
284 
285 
293  RORouteDef* getRouteDef(const std::string& name) const {
294  return myRoutes.get(name);
295  }
296 
297 
298  /* @brief Adds a vehicle to the network
299  *
300  * If the vehicle is already known (another one with the same id
301  * exists), false is returned, but the vehicle is not deleted.
302  *
303  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
304  *
305  * @param[in] id The id of the vehicle to add
306  * @param[in] veh The vehicle to add
307  * @return Whether the vehicle could be added
308  */
309  virtual bool addVehicle(const std::string& id, ROVehicle* veh);
310 
311 
312  /* @brief Adds a flow of vehicles to the network
313  *
314  * If the flow is already known (another one with the same id
315  * exists), false is returned, but the vehicle parameter are not deleted.
316  *
317  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
318  *
319  * @param[in] flow The parameter of the flow to add
320  * @return Whether the flow could be added
321  */
322  bool addFlow(SUMOVehicleParameter* flow, const bool randomize);
323 
324 
325  /* @brief Adds a person to the network
326  *
327  * @param[in] person The person to add
328  */
329  bool addPerson(ROPerson* person);
330 
331 
332  /* @brief Adds a container to the network
333  *
334  * @param[in] depart The departure time of the container
335  * @param[in] desc The xml description of the container
336  */
337  void addContainer(const SUMOTime depart, const std::string desc);
338  // @}
339 
340 
342 
343 
356  const RORouterProvider& provider, SUMOTime time);
357 
358 
360  bool furtherStored();
362 
363 
370  void openOutput(const OptionsCont& options);
371 
372 
379  void writeIntermodal(const OptionsCont& options, ROIntermodalRouter& router) const;
380 
381 
383  void cleanup();
384 
385 
387  int getEdgeNumber() const;
388 
390  int getInternalEdgeNumber() const;
391 
393  return myEdges;
394  }
395 
396  static void adaptIntermodalRouter(ROIntermodalRouter& router);
397 
398  bool hasPermissions() const;
399 
400  void setPermissionsFound();
401 
402  OutputDevice* getRouteOutput(const bool alternative = false) {
403  if (alternative) {
405  }
406  return myRoutesOutput;
407  }
408 
409 #ifdef HAVE_FOX
410  FXWorkerThread::Pool& getThreadPool() {
411  return myThreadPool;
412  }
413 
414  class WorkerThread : public FXWorkerThread, public RORouterProvider {
415  public:
416  WorkerThread(FXWorkerThread::Pool& pool,
417  const RORouterProvider& original)
418  : FXWorkerThread(pool), RORouterProvider(original) {}
419  virtual ~WorkerThread() {
420  stop();
421  }
422  };
423 
424  class BulkmodeTask : public FXWorkerThread::Task {
425  public:
426  BulkmodeTask(const bool value) : myValue(value) {}
427  void run(FXWorkerThread* context) {
428  static_cast<WorkerThread*>(context)->getVehicleRouter().setBulkMode(myValue);
429  }
430  private:
431  const bool myValue;
432  private:
434  BulkmodeTask& operator=(const BulkmodeTask&);
435  };
436 #endif
437 
438 
439 private:
440  void checkFlows(SUMOTime time, MsgHandler* errorHandler);
441 
442  void createBulkRouteRequests(const RORouterProvider& provider, const SUMOTime time, const bool removeLoops);
443 
444 private:
446  static RONet* myInstance;
447 
449  std::set<std::string> myVehIDs;
450 
452  std::set<std::string> myPersonIDs;
453 
456 
459 
461  std::map<SumoXMLTag, NamedObjectCont<SUMOVehicleParameter::Stop*> > myStoppingPlaces;
462 
465 
467  typedef std::map< std::string, RandomDistributor<SUMOVTypeParameter*>* > VTypeDistDictType;
470 
473 
476 
479 
482 
485 
488 
491 
493  typedef std::multimap<const SUMOTime, const std::string> ContainerMap;
495 
497  std::vector<const RORoutable*> myPTVehicles;
498 
500  std::map<std::string, std::vector<SUMOTime> > myDepartures;
501 
503  std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > > myDistricts;
504 
507 
510 
513 
516 
519 
522 
525 
527  std::map<std::string, std::map<SUMOVehicleClass, double> > myRestrictions;
528 
531 
534 
536  const bool myKeepVTypeDist;
537 
538 #ifdef HAVE_FOX
539 private:
540  class RoutingTask : public FXWorkerThread::Task {
541  public:
542  RoutingTask(RORoutable* v, const bool removeLoops, MsgHandler* errorHandler)
543  : myRoutable(v), myRemoveLoops(removeLoops), myErrorHandler(errorHandler) {}
544  void run(FXWorkerThread* context);
545  private:
546  RORoutable* const myRoutable;
547  const bool myRemoveLoops;
548  MsgHandler* const myErrorHandler;
549  private:
551  RoutingTask& operator=(const RoutingTask&);
552  };
553 
554 
555 private:
557  FXWorkerThread::Pool myThreadPool;
558 #endif
559 
560 private:
562  RONet(const RONet& src);
563 
565  RONet& operator=(const RONet& src);
566 
567 };
568 
569 
570 #endif
571 
572 /****************************************************************************/
573 
RONet::getRouteOutput
OutputDevice * getRouteOutput(const bool alternative=false)
Definition: RONet.h:402
SUMOVehicleClass
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
Definition: SUMOVehicleClass.h:133
RONet::myHaveActiveFlows
bool myHaveActiveFlows
whether any flows are still active
Definition: RONet.h:490
RONet::myDiscardedRouteNo
int myDiscardedRouteNo
The number of discarded routes.
Definition: RONet.h:518
RONet::myDepartures
std::map< std::string, std::vector< SUMOTime > > myDepartures
Departure times for randomized flows.
Definition: RONet.h:500
RONet::openOutput
void openOutput(const OptionsCont &options)
Opens the output for computed routes.
Definition: RONet.cpp:214
RONet::getEdgeNumber
int getEdgeNumber() const
Returns the total number of edges the network contains including internal edges.
Definition: RONet.cpp:648
RONet::myHavePermissions
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
Definition: RONet.h:524
RONet::myErrorHandler
MsgHandler * myErrorHandler
handler for ignorable error messages
Definition: RONet.h:533
RONet::addDistrictEdge
bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource)
Definition: RONet.cpp:168
RONet::getNode
RONode * getNode(const std::string &id) const
Retrieves an node from the network.
Definition: RONet.h:184
RONet::myNumInternalEdges
int myNumInternalEdges
The number of internal edges in the dictionary.
Definition: RONet.h:530
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
RONet::getEdge
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:152
IntermodalRouter
Definition: IntermodalRouter.h:54
RONet::myRouteAlternativesOutput
OutputDevice * myRouteAlternativesOutput
The file to write the computed route alternatives into.
Definition: RONet.h:509
MsgHandler.h
RONet::addNode
void addNode(RONode *node)
Definition: RONet.cpp:190
RONet::addEdge
virtual bool addEdge(ROEdge *edge)
Definition: RONet.cpp:137
RONet::hasPermissions
bool hasPermissions() const
Definition: RONet.cpp:692
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
RONet::getRouteDef
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
Definition: RONet.h:293
RONet::myRoutesOutput
OutputDevice * myRoutesOutput
The file to write the computed routes into.
Definition: RONet.h:506
RONet::writeIntermodal
void writeIntermodal(const OptionsCont &options, ROIntermodalRouter &router) const
Writes the intermodal network and weights if requested.
Definition: RONet.cpp:235
RORouteDef
Base class for a vehicle's route definition.
Definition: RORouteDef.h:55
RONet::adaptIntermodalRouter
static void adaptIntermodalRouter(ROIntermodalRouter &router)
Definition: RONet.cpp:660
RONet
The router's network representation.
Definition: RONet.h:63
ROPerson
A person as used by router.
Definition: ROPerson.h:50
RONet::myWrittenRouteNo
int myWrittenRouteNo
The number of written routes.
Definition: RONet.h:521
ROVehicle
A vehicle as used by router.
Definition: ROVehicle.h:52
RORoutable.h
SUMOVehicleParameter
Structure representing possible vehicle parameter.
Definition: SUMOVehicleParameter.h:297
RORouteDef.h
RONet::myPTVehicles
std::vector< const RORoutable * > myPTVehicles
vehicles to keep for public transport routing
Definition: RONet.h:497
RONet::addPerson
bool addPerson(ROPerson *person)
Definition: RONet.cpp:390
RONet::getInstance
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
Definition: RONet.cpp:55
RONet::getInternalEdgeNumber
int getInternalEdgeNumber() const
Returns the number of internal edges the network contains.
Definition: RONet.cpp:654
RONet::addRouteDef
bool addRouteDef(RORouteDef *def)
Definition: RONet.cpp:208
SumoXMLTag
SumoXMLTag
Numbers representing SUMO-XML - element names.
Definition: SUMOXMLDefinitions.h:41
RONet::addRestriction
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction for an edge type.
Definition: RONet.cpp:121
RONet::myEdges
NamedObjectCont< ROEdge * > myEdges
Known edges.
Definition: RONet.h:458
SUMOVehicleParameter.h
RONet::RoutablesMap
std::map< const SUMOTime, std::vector< RORoutable * > > RoutablesMap
Definition: RONet.h:66
RONet::addStoppingPlace
void addStoppingPlace(const std::string &id, const SumoXMLTag category, SUMOVehicleParameter::Stop *stop)
Definition: RONet.cpp:199
RONet::myPersonIDs
std::set< std::string > myPersonIDs
Known person ids.
Definition: RONet.h:452
RONet::myRestrictions
std::map< std::string, std::map< SUMOVehicleClass, double > > myRestrictions
The vehicle class specific speed restrictions.
Definition: RONet.h:527
RONet::myStoppingPlaces
std::map< SumoXMLTag, NamedObjectCont< SUMOVehicleParameter::Stop * > > myStoppingPlaces
Known bus / train / container stops and parking areas.
Definition: RONet.h:461
RONet::getDistricts
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:140
RandomDistributor.h
MsgHandler
Definition: MsgHandler.h:38
NamedObjectCont< ROEdge * >
RONet::myDistricts
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:503
SUMOVTypeParameter
Structure representing possible vehicle parameter.
Definition: SUMOVTypeParameter.h:86
RONet::myTypesOutput
OutputDevice * myTypesOutput
The file to write the vehicle types into.
Definition: RONet.h:512
RONet::addContainer
void addContainer(const SUMOTime depart, const std::string desc)
Definition: RONet.cpp:402
RONet::getStoppingPlace
const SUMOVehicleParameter::Stop * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Retrieves a stopping place from the network.
Definition: RONet.h:207
RONet::createBulkRouteRequests
void createBulkRouteRequests(const RORouterProvider &provider, const SUMOTime time, const bool removeLoops)
Definition: RONet.cpp:488
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
RONet::VTypeDistDictType
std::map< std::string, RandomDistributor< SUMOVTypeParameter * > * > VTypeDistDictType
Vehicle type distribution dictionary type.
Definition: RONet.h:467
FXWorkerThread.h
RONet::myDefaultVTypeMayBeDeleted
bool myDefaultVTypeMayBeDeleted
Whether the default vehicle type was already used or can still be replaced.
Definition: RONet.h:472
RONet::RONet
RONet()
Constructor.
Definition: RONet.cpp:63
RONet::myVehicleTypes
NamedObjectCont< SUMOVTypeParameter * > myVehicleTypes
Known vehicle types.
Definition: RONet.h:464
RouterProvider
Definition: RouterProvider.h:37
RONet::addVehicle
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
Definition: RONet.cpp:356
RONet::addVTypeDistribution
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter * > *vehTypeDistribution)
Adds a vehicle type distribution.
Definition: RONet.cpp:346
RandomDistributor< SUMOVTypeParameter * >
NamedObjectCont.h
RORoutable
A routable thing such as a vehicle or person.
Definition: RORoutable.h:54
RONet::getEdgeMap
const NamedObjectCont< ROEdge * > & getEdgeMap() const
Definition: RONet.h:392
RONet::myVTypeDistDict
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
Definition: RONet.h:469
RONet::cleanup
void cleanup()
closes the file output for computed routes and deletes associated threads if necessary
Definition: RONet.cpp:254
RONet::myNodes
NamedObjectCont< RONode * > myNodes
Known nodes.
Definition: RONet.h:455
RONet::myInstance
static RONet * myInstance
Unique instance of RONet.
Definition: RONet.h:446
FXWorkerThread::Pool
A pool of worker threads which distributes the tasks and collects the results.
Definition: FXWorkerThread.h:88
NamedObjectCont::get
T get(const std::string &id) const
Retrieves an item.
Definition: NamedObjectCont.h:98
RONet::addDistrict
bool addDistrict(const std::string id, ROEdge *source, ROEdge *sink)
Definition: RONet.cpp:151
RONet::myContainers
ContainerMap myContainers
Definition: RONet.h:494
RONet::setPermissionsFound
void setPermissionsFound()
Definition: RONet.cpp:698
RONet::myRoutables
RoutablesMap myRoutables
Known routables.
Definition: RONet.h:484
RONet::~RONet
virtual ~RONet()
Destructor.
Definition: RONet.cpp:93
RONet::myReadRouteNo
int myReadRouteNo
The number of read routes.
Definition: RONet.h:515
ROEdge
A basic edge for routing applications.
Definition: ROEdge.h:72
RONet::furtherStored
bool furtherStored()
Returns the information whether further vehicles, persons or containers are stored.
Definition: RONet.cpp:642
config.h
ROLane.h
RONet::addFlow
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition: RONet.cpp:376
RONet::myRoutes
NamedObjectCont< RORouteDef * > myRoutes
Known routes.
Definition: RONet.h:481
RONet::checkFlows
void checkFlows(SUMOTime time, MsgHandler *errorHandler)
Definition: RONet.cpp:408
RONet::getStoppingPlaceName
const std::string getStoppingPlaceName(const std::string &id) const
return the name for the given stopping place id
Definition: RONet.cpp:703
RONet::myVehIDs
std::set< std::string > myVehIDs
Known vehicle ids.
Definition: RONet.h:449
RONet::myDefaultBikeTypeMayBeDeleted
bool myDefaultBikeTypeMayBeDeleted
Whether the default bicycle type was already used or can still be replaced.
Definition: RONet.h:478
RONet::RONet
RONet(const RONet &src)
Invalidated copy constructor.
RONet::operator=
RONet & operator=(const RONet &src)
Invalidated assignment operator.
RONet::saveAndRemoveRoutesUntil
SUMOTime saveAndRemoveRoutesUntil(OptionsCont &options, const RORouterProvider &provider, SUMOTime time)
Computes routes described by their definitions and saves them.
Definition: RONet.cpp:534
RONet::checkVType
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
Definition: RONet.cpp:308
FXWorkerThread::Task
Abstract superclass of a task to be run with an index to keep track of pending tasks.
Definition: FXWorkerThread.h:55
RONet::getRestrictions
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:127
RONet::getVehicleTypeSecure
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:278
RONode
Base class for nodes used by the router.
Definition: RONode.h:45
SUMOVTypeParameter.h
RONet::myDefaultPedTypeMayBeDeleted
bool myDefaultPedTypeMayBeDeleted
Whether the default pedestrian type was already used or can still be replaced.
Definition: RONet.h:475
RONet::getEdgeForLaneID
ROEdge * getEdgeForLaneID(const std::string &laneID) const
Retrieves an edge from the network when the lane id is given.
Definition: RONet.h:162
RONet::ContainerMap
std::multimap< const SUMOTime, const std::string > ContainerMap
Known containers.
Definition: RONet.h:493
RONet::myFlows
NamedObjectCont< SUMOVehicleParameter * > myFlows
Known flows.
Definition: RONet.h:487
RONet::myKeepVTypeDist
const bool myKeepVTypeDist
whether to keep the the vtype distribution in output
Definition: RONet.h:536
FXWorkerThread
A thread repeatingly calculating incoming tasks.
Definition: FXWorkerThread.h:48
SUMOVehicleParameter::Stop
Definition of vehicle stop (position and duration)
Definition: SUMOVehicleParameter.h:572
RONet::addVehicleType
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
Definition: RONet.cpp:333