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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
21 // The router's network representation
22 /****************************************************************************/
23 #pragma once
24 #include <config.h>
25 
26 #include <vector>
32 #include "ROLane.h"
33 #include "RORoutable.h"
34 #include "RORouteDef.h"
35 
36 #ifdef HAVE_FOX
38 #endif
39 
40 
41 // ===========================================================================
42 // class declarations
43 // ===========================================================================
44 class ROEdge;
45 class RONode;
46 class ROPerson;
47 class ROVehicle;
49 class OptionsCont;
50 class OutputDevice;
51 
52 
53 // ===========================================================================
54 // class definitions
55 // ===========================================================================
62 class RONet {
63 public:
64 
65  typedef std::map<const SUMOTime, std::vector<RORoutable*> > RoutablesMap;
66 
68  RONet();
69 
70 
74  static RONet* getInstance();
75 
76 
78  virtual ~RONet();
79 
80 
86  void addRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed);
87 
88 
94  const std::map<SUMOVehicleClass, double>* getRestrictions(const std::string& id) const;
95 
96 
98 
99 
100  /* @brief Adds a read edge to the network
101  *
102  * If the edge is already known (another one with the same id exists),
103  * an error is generated and given to msg-error-handler. The edge
104  * is deleted in this case and false is returned.
105  *
106  * @param[in] edge The edge to add
107  * @return Whether the edge was added (if not, it was deleted, too)
108  */
109  virtual bool addEdge(ROEdge* edge);
110 
111 
112  /* @brief Adds a district and connecting edges to the network
113  *
114  * If the district is already known (another one with the same id exists),
115  * an error is generated and given to msg-error-handler. The edges
116  * are deleted in this case and false is returned.
117  *
118  * @param[in] id The district to add
119  * @return Whether the district was added
120  */
121  bool addDistrict(const std::string id, ROEdge* source, ROEdge* sink);
122 
123 
124  /* @brief Adds a district and connecting edges to the network
125  *
126  * If the district is already known (another one with the same id exists),
127  * an error is generated and given to msg-error-handler. The edges
128  * are deleted in this case and false is returned.
129  *
130  * @param[in] id The district to add
131  * @return Whether the district was added
132  */
133  bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource);
134 
137 
139  void setBidiEdges(const std::map<ROEdge*, std::string>& bidiMap);
140 
145  const std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > >& getDistricts() const {
146  return myDistricts;
147  }
148 
157  ROEdge* getEdge(const std::string& name) const {
158  return myEdges.get(name);
159  }
160 
161 
167  ROEdge* getEdgeForLaneID(const std::string& laneID) const {
168  return getEdge(laneID.substr(0, laneID.rfind("_")));
169  }
170 
171 
172  /* @brief Adds a read node to the network
173  *
174  * If the node is already known (another one with the same id exists),
175  * an error is generated and given to msg-error-handler. The node
176  * is deleted in this case
177  *
178  * @param[in] node The node to add
179  */
180  void addNode(RONode* node);
181 
182 
189  RONode* getNode(const std::string& id) const {
190  return myNodes.get(id);
191  }
192 
193 
194  /* @brief Adds a read stopping place (bus, train, container, parking) to the network
195  *
196  * If the place is already known (another one with the same id and category exists),
197  * an error is generated and given to msg-error-handler. The stop
198  * is deleted in this case
199  *
200  * @param[in] id The name of the stop to add
201  * @param[in] category The type of stop
202  * @param[in] stop The detailed stop description
203  */
204  void addStoppingPlace(const std::string& id, const SumoXMLTag category, SUMOVehicleParameter::Stop* stop);
205 
212  const SUMOVehicleParameter::Stop* getStoppingPlace(const std::string& id, const SumoXMLTag category) const {
213  if (myStoppingPlaces.count(category) > 0) {
214  return myStoppingPlaces.find(category)->second.get(id);
215  }
216  return 0;
217  }
218 
220  const std::string getStoppingPlaceName(const std::string& id) const;
222 
223 
224 
226 
227 
234  bool checkVType(const std::string& id);
235 
236 
246  virtual bool addVehicleType(SUMOVTypeParameter* type);
247 
248 
262  bool addVTypeDistribution(const std::string& id, RandomDistributor<SUMOVTypeParameter*>* vehTypeDistribution);
263 
264 
275  SUMOVTypeParameter* getVehicleTypeSecure(const std::string& id);
276 
277 
278  /* @brief Adds a route definition to the network
279  *
280  * If the route definition is already known (another one with
281  * the same id exists), false is returned, but the route definition
282  * is not deleted.
283  *
284  * @param[in] def The route definition to add
285  * @return Whether the route definition could be added
286  * @todo Rename myRoutes to myRouteDefinitions
287  */
288  bool addRouteDef(RORouteDef* def);
289 
290 
298  RORouteDef* getRouteDef(const std::string& name) const {
299  return myRoutes.get(name);
300  }
301 
302 
303  /* @brief Adds a vehicle to the network
304  *
305  * If the vehicle is already known (another one with the same id
306  * exists), false is returned, but the vehicle is not deleted.
307  *
308  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
309  *
310  * @param[in] id The id of the vehicle to add
311  * @param[in] veh The vehicle to add
312  * @return Whether the vehicle could be added
313  */
314  virtual bool addVehicle(const std::string& id, ROVehicle* veh);
315 
317  bool knowsVehicle(const std::string& id);
318 
319  /* @brief Adds a flow of vehicles to the network
320  *
321  * If the flow is already known (another one with the same id
322  * exists), false is returned, but the vehicle parameter are not deleted.
323  *
324  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
325  *
326  * @param[in] flow The parameter of the flow to add
327  * @return Whether the flow could be added
328  */
329  bool addFlow(SUMOVehicleParameter* flow, const bool randomize);
330 
331 
332  /* @brief Adds a person to the network
333  *
334  * @param[in] person The person to add
335  */
336  bool addPerson(ROPerson* person);
337 
338 
339  /* @brief Adds a container to the network
340  *
341  * @param[in] depart The departure time of the container
342  * @param[in] desc The xml description of the container
343  */
344  void addContainer(const SUMOTime depart, const std::string desc);
345  // @}
346 
347 
349 
350 
363  const RORouterProvider& provider, SUMOTime time);
364 
365 
367  bool furtherStored();
369 
370 
377  void openOutput(const OptionsCont& options);
378 
379 
386  void writeIntermodal(const OptionsCont& options, ROIntermodalRouter& router) const;
387 
388 
390  void cleanup();
391 
392 
394  int getEdgeNumber() const;
395 
397  int getInternalEdgeNumber() const;
398 
400  return myEdges;
401  }
402 
403  static void adaptIntermodalRouter(ROIntermodalRouter& router);
404 
405  bool hasPermissions() const;
406 
407  void setPermissionsFound();
408 
410  bool hasBidiEdges() const {
411  return myHasBidiEdges;
412  }
413 
415  bool hasLoadedEffort() const;
416 
417  OutputDevice* getRouteOutput(const bool alternative = false) {
418  if (alternative) {
420  }
421  return myRoutesOutput;
422  }
423 
424 #ifdef HAVE_FOX
425  FXWorkerThread::Pool& getThreadPool() {
426  return myThreadPool;
427  }
428 
429  class WorkerThread : public FXWorkerThread, public RORouterProvider {
430  public:
431  WorkerThread(FXWorkerThread::Pool& pool,
432  const RORouterProvider& original)
433  : FXWorkerThread(pool), RORouterProvider(original) {}
434  virtual ~WorkerThread() {
435  stop();
436  }
437  };
438 
439  class BulkmodeTask : public FXWorkerThread::Task {
440  public:
441  BulkmodeTask(const bool value) : myValue(value) {}
442  void run(FXWorkerThread* context) {
443  static_cast<WorkerThread*>(context)->getVehicleRouter(SVC_IGNORING).setBulkMode(myValue);
444  }
445  private:
446  const bool myValue;
447  private:
449  BulkmodeTask& operator=(const BulkmodeTask&);
450  };
451 #endif
452 
453 
454 private:
455  void checkFlows(SUMOTime time, MsgHandler* errorHandler);
456 
457  void createBulkRouteRequests(const RORouterProvider& provider, const SUMOTime time, const bool removeLoops);
458 
459 private:
461  static RONet* myInstance;
462 
464  std::set<std::string> myVehIDs;
465 
467  std::set<std::string> myPersonIDs;
468 
471 
474 
476  std::map<SumoXMLTag, NamedObjectCont<SUMOVehicleParameter::Stop*> > myStoppingPlaces;
477 
480 
482  typedef std::map< std::string, RandomDistributor<SUMOVTypeParameter*>* > VTypeDistDictType;
485 
488 
491 
494 
497 
500 
503 
506 
508  typedef std::multimap<const SUMOTime, const std::string> ContainerMap;
510 
512  std::vector<const RORoutable*> myPTVehicles;
513 
515  std::map<std::string, std::vector<SUMOTime> > myDepartures;
516 
518  std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > > myDistricts;
519 
522 
525 
528 
531 
534 
537 
540 
542  std::map<std::string, std::map<SUMOVehicleClass, double> > myRestrictions;
543 
546 
549 
551  const bool myKeepVTypeDist;
552 
555 
556 #ifdef HAVE_FOX
557 private:
558  class RoutingTask : public FXWorkerThread::Task {
559  public:
560  RoutingTask(RORoutable* v, const bool removeLoops, MsgHandler* errorHandler)
561  : myRoutable(v), myRemoveLoops(removeLoops), myErrorHandler(errorHandler) {}
562  void run(FXWorkerThread* context);
563  private:
564  RORoutable* const myRoutable;
565  const bool myRemoveLoops;
566  MsgHandler* const myErrorHandler;
567  private:
569  RoutingTask& operator=(const RoutingTask&);
570  };
571 
572 
573 private:
575  FXWorkerThread::Pool myThreadPool;
576 #endif
577 
578 private:
580  RONet(const RONet& src);
581 
583  RONet& operator=(const RONet& src);
584 
585 };
long long int SUMOTime
Definition: SUMOTime.h:31
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
SumoXMLTag
Numbers representing SUMO-XML - element names.
A pool of worker threads which distributes the tasks and collects the results.
Abstract superclass of a task to be run with an index to keep track of pending tasks.
A thread repeatingly calculating incoming tasks.
T get(const std::string &id) const
Retrieves an item.
A storage for options typed value containers)
Definition: OptionsCont.h:89
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
Interface for building instances of router-edges.
A basic edge for routing applications.
Definition: ROEdge.h:70
The router's network representation.
Definition: RONet.h:62
void createBulkRouteRequests(const RORouterProvider &provider, const SUMOTime time, const bool removeLoops)
Definition: RONet.cpp:550
std::set< std::string > myVehIDs
Known vehicle ids.
Definition: RONet.h:464
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:334
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
Definition: RONet.cpp:55
int myNumInternalEdges
The number of internal edges in the dictionary.
Definition: RONet.h:545
bool myDefaultPedTypeMayBeDeleted
Whether the default pedestrian type was already used or can still be replaced.
Definition: RONet.h:490
bool hasBidiEdges() const
return whether the network contains bidirectional rail edges
Definition: RONet.h:410
void setPermissionsFound()
Definition: RONet.cpp:769
const SUMOVehicleParameter::Stop * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Retrieves a stopping place from the network.
Definition: RONet.h:212
std::map< const SUMOTime, std::vector< RORoutable * > > RoutablesMap
Definition: RONet.h:65
bool myDefaultVTypeMayBeDeleted
Whether the default vehicle type was already used or can still be replaced.
Definition: RONet.h:487
void checkFlows(SUMOTime time, MsgHandler *errorHandler)
Definition: RONet.cpp:470
RONet & operator=(const RONet &src)
Invalidated assignment operator.
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:157
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:136
std::map< std::string, RandomDistributor< SUMOVTypeParameter * > * > VTypeDistDictType
Vehicle type distribution dictionary type.
Definition: RONet.h:482
ROEdge * getEdgeForLaneID(const std::string &laneID) const
Retrieves an edge from the network when the lane id is given.
Definition: RONet.h:167
ContainerMap myContainers
Definition: RONet.h:509
std::set< std::string > myPersonIDs
Known person ids.
Definition: RONet.h:467
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:518
bool addRouteDef(RORouteDef *def)
Definition: RONet.cpp:264
int myReadRouteNo
The number of read routes.
Definition: RONet.h:530
void addStoppingPlace(const std::string &id, const SumoXMLTag category, SUMOVehicleParameter::Stop *stop)
Definition: RONet.cpp:255
void cleanup()
closes the file output for computed routes and deletes associated threads if necessary
Definition: RONet.cpp:310
bool myHaveActiveFlows
whether any flows are still active
Definition: RONet.h:505
RONet(const RONet &src)
Invalidated copy constructor.
void openOutput(const OptionsCont &options)
Opens the output for computed routes.
Definition: RONet.cpp:270
NamedObjectCont< SUMOVehicleParameter * > myFlows
Known flows.
Definition: RONet.h:502
OutputDevice * myRouteAlternativesOutput
The file to write the computed route alternatives into.
Definition: RONet.h:524
bool myDefaultBikeTypeMayBeDeleted
Whether the default bicycle type was already used or can still be replaced.
Definition: RONet.h:493
RoutablesMap myRoutables
Known routables.
Definition: RONet.h:499
int getInternalEdgeNumber() const
Returns the number of internal edges the network contains.
Definition: RONet.cpp:716
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
Definition: RONet.cpp:412
bool myHasBidiEdges
whether the network contains bidirectional railway edges
Definition: RONet.h:554
bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource)
Definition: RONet.cpp:179
MsgHandler * myErrorHandler
handler for ignorable error messages
Definition: RONet.h:548
void writeIntermodal(const OptionsCont &options, ROIntermodalRouter &router) const
Writes the intermodal network and weights if requested.
Definition: RONet.cpp:291
RONet()
Constructor.
Definition: RONet.cpp:63
NamedObjectCont< RONode * > myNodes
Known nodes.
Definition: RONet.h:470
void addContainer(const SUMOTime depart, const std::string desc)
Definition: RONet.cpp:464
static void adaptIntermodalRouter(ROIntermodalRouter &router)
Definition: RONet.cpp:722
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction for an edge type.
Definition: RONet.cpp:130
NamedObjectCont< RORouteDef * > myRoutes
Known routes.
Definition: RONet.h:496
bool furtherStored()
Returns the information whether further vehicles, persons or containers are stored.
Definition: RONet.cpp:704
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
Definition: RONet.cpp:364
OutputDevice * myRoutesOutput
The file to write the computed routes into.
Definition: RONet.h:521
bool addPerson(ROPerson *person)
Definition: RONet.cpp:452
int myWrittenRouteNo
The number of written routes.
Definition: RONet.h:536
static RONet * myInstance
Unique instance of RONet.
Definition: RONet.h:461
SUMOTime saveAndRemoveRoutesUntil(OptionsCont &options, const RORouterProvider &provider, SUMOTime time)
Computes routes described by their definitions and saves them.
Definition: RONet.cpp:596
virtual bool addEdge(ROEdge *edge)
Definition: RONet.cpp:146
std::map< std::string, std::map< SUMOVehicleClass, double > > myRestrictions
The vehicle class specific speed restrictions.
Definition: RONet.h:542
std::map< SumoXMLTag, NamedObjectCont< SUMOVehicleParameter::Stop * > > myStoppingPlaces
Known bus / train / container stops and parking areas.
Definition: RONet.h:476
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
Definition: RONet.cpp:389
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
Definition: RONet.h:539
RONode * getNode(const std::string &id) const
Retrieves an node from the network.
Definition: RONet.h:189
bool hasPermissions() const
Definition: RONet.cpp:763
void setBidiEdges(const std::map< ROEdge *, std::string > &bidiMap)
add a taz for every junction unless a taz with the same id already exists
Definition: RONet.cpp:234
bool knowsVehicle(const std::string &id)
returns whether a vehicle with the given id was already loaded
Definition: RONet.cpp:432
std::multimap< const SUMOTime, const std::string > ContainerMap
Known containers.
Definition: RONet.h:508
int myDiscardedRouteNo
The number of discarded routes.
Definition: RONet.h:533
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
Definition: RONet.h:298
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
Definition: RONet.h:484
std::vector< const RORoutable * > myPTVehicles
vehicles to keep for public transport routing
Definition: RONet.h:512
NamedObjectCont< ROEdge * > myEdges
Known edges.
Definition: RONet.h:473
void addNode(RONode *node)
Definition: RONet.cpp:246
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter * > *vehTypeDistribution)
Adds a vehicle type distribution.
Definition: RONet.cpp:402
void addJunctionTaz(ROAbstractEdgeBuilder &eb)
add a taz for every junction unless a taz with the same id already exists
Definition: RONet.cpp:201
OutputDevice * myTypesOutput
The file to write the vehicle types into.
Definition: RONet.h:527
OutputDevice * getRouteOutput(const bool alternative=false)
Definition: RONet.h:417
const bool myKeepVTypeDist
whether to keep the the vtype distribution in output
Definition: RONet.h:551
virtual ~RONet()
Destructor.
Definition: RONet.cpp:102
const std::string getStoppingPlaceName(const std::string &id) const
return the name for the given stopping place id
Definition: RONet.cpp:784
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:145
std::map< std::string, std::vector< SUMOTime > > myDepartures
Departure times for randomized flows.
Definition: RONet.h:515
int getEdgeNumber() const
Returns the total number of edges the network contains including internal edges.
Definition: RONet.cpp:710
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition: RONet.cpp:438
const NamedObjectCont< ROEdge * > & getEdgeMap() const
Definition: RONet.h:399
bool hasLoadedEffort() const
whether efforts were loaded from file
Definition: RONet.cpp:774
NamedObjectCont< SUMOVTypeParameter * > myVehicleTypes
Known vehicle types.
Definition: RONet.h:479
bool addDistrict(const std::string id, ROEdge *source, ROEdge *sink)
Definition: RONet.cpp:160
Base class for nodes used by the router.
Definition: RONode.h:43
A person as used by router.
Definition: ROPerson.h:49
A routable thing such as a vehicle or person.
Definition: RORoutable.h:52
Base class for a vehicle's route definition.
Definition: RORouteDef.h:53
A vehicle as used by router.
Definition: ROVehicle.h:50
Structure representing possible vehicle parameter.
Definition of vehicle stop (position and duration)
Structure representing possible vehicle parameter.