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-2018 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>
37 #include "ROLane.h"
38 #include "RORoutable.h"
39 #include "RORouteDef.h"
40 
41 #ifdef HAVE_FOX
43 #endif
44 
45 
46 // ===========================================================================
47 // class declarations
48 // ===========================================================================
49 class ROEdge;
50 class ROLane;
51 class RONode;
52 class ROPerson;
53 class RORoutable;
54 class ROVehicle;
55 class OptionsCont;
56 class OutputDevice;
57 
58 
59 // ===========================================================================
60 // class definitions
61 // ===========================================================================
68 class RONet {
69 public:
70 
71  typedef std::map<const SUMOTime, std::vector<RORoutable*> > RoutablesMap;
72 
74  RONet();
75 
76 
80  static RONet* getInstance();
81 
82 
84  virtual ~RONet();
85 
86 
92  void addRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed);
93 
94 
100  const std::map<SUMOVehicleClass, double>* getRestrictions(const std::string& id) const;
101 
102 
104 
105 
106  /* @brief Adds a read edge to the network
107  *
108  * If the edge is already known (another one with the same id exists),
109  * an error is generated and given to msg-error-handler. The edge
110  * is deleted in this case and false is returned.
111  *
112  * @param[in] edge The edge to add
113  * @return Whether the edge was added (if not, it was deleted, too)
114  */
115  virtual bool addEdge(ROEdge* edge);
116 
117 
118  /* @brief Adds a district and connecting edges to the network
119  *
120  * If the district is already known (another one with the same id exists),
121  * an error is generated and given to msg-error-handler. The edges
122  * are deleted in this case and false is returned.
123  *
124  * @param[in] id The district to add
125  * @return Whether the district was added
126  */
127  bool addDistrict(const std::string id, ROEdge* source, ROEdge* sink);
128 
129 
130  /* @brief Adds a district and connecting edges to the network
131  *
132  * If the district is already known (another one with the same id exists),
133  * an error is generated and given to msg-error-handler. The edges
134  * are deleted in this case and false is returned.
135  *
136  * @param[in] id The district to add
137  * @return Whether the district was added
138  */
139  bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource);
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 
316 
317  /* @brief Adds a flow of vehicles to the network
318  *
319  * If the flow is already known (another one with the same id
320  * exists), false is returned, but the vehicle parameter are not deleted.
321  *
322  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
323  *
324  * @param[in] flow The parameter of the flow to add
325  * @return Whether the flow could be added
326  */
327  bool addFlow(SUMOVehicleParameter* flow, const bool randomize);
328 
329 
330  /* @brief Adds a person to the network
331  *
332  * @param[in] person The person to add
333  */
334  bool addPerson(ROPerson* person);
335 
336 
337  /* @brief Adds a container to the network
338  *
339  * @param[in] depart The departure time of the container
340  * @param[in] desc The xml description of the container
341  */
342  void addContainer(const SUMOTime depart, const std::string desc);
343  // @}
344 
345 
347 
348 
361  const RORouterProvider& provider, SUMOTime time);
362 
363 
365  bool furtherStored();
367 
368 
375  void openOutput(const OptionsCont& options);
376 
377 
384  void writeIntermodal(const OptionsCont& options, ROIntermodalRouter& router) const;
385 
386 
388  void cleanup();
389 
390 
392  int getEdgeNumber() const;
393 
395  int getInternalEdgeNumber() const;
396 
398  return myEdges;
399  }
400 
401  static void adaptIntermodalRouter(ROIntermodalRouter& router);
402 
403  bool hasPermissions() const;
404 
405  void setPermissionsFound();
406 
407  OutputDevice* getRouteOutput(const bool alternative = false) {
408  if (alternative) {
410  }
411  return myRoutesOutput;
412  }
413 
414 #ifdef HAVE_FOX
415  FXWorkerThread::Pool& getThreadPool() {
416  return myThreadPool;
417  }
418 
419  class WorkerThread : public FXWorkerThread, public RORouterProvider {
420  public:
421  WorkerThread(FXWorkerThread::Pool& pool,
422  const RORouterProvider& original)
423  : FXWorkerThread(pool), RORouterProvider(original) {}
424  virtual ~WorkerThread() {
425  stop();
426  }
427  };
428 
429  class BulkmodeTask : public FXWorkerThread::Task {
430  public:
431  BulkmodeTask(const bool value) : myValue(value) {}
432  void run(FXWorkerThread* context) {
433  static_cast<WorkerThread*>(context)->getVehicleRouter().setBulkMode(myValue);
434  }
435  private:
436  const bool myValue;
437  private:
439  BulkmodeTask& operator=(const BulkmodeTask&);
440  };
441 #endif
442 
443 
444 private:
445  void checkFlows(SUMOTime time, MsgHandler* errorHandler);
446 
447  void createBulkRouteRequests(const RORouterProvider& provider, const SUMOTime time, const bool removeLoops);
448 
449 private:
451  static RONet* myInstance;
452 
454  std::set<std::string> myVehIDs;
455 
457  std::set<std::string> myPersonIDs;
458 
461 
464 
466  std::map<SumoXMLTag, NamedObjectCont<SUMOVehicleParameter::Stop*> > myStoppingPlaces;
467 
470 
472  typedef std::map< std::string, RandomDistributor<SUMOVTypeParameter*>* > VTypeDistDictType;
474  VTypeDistDictType myVTypeDistDict;
475 
478 
481 
484 
487 
489  RoutablesMap myRoutables;
490 
493 
496 
498  typedef std::multimap<const SUMOTime, const std::string> ContainerMap;
499  ContainerMap myContainers;
500 
502  std::vector<const RORoutable*> myPTVehicles;
503 
505  std::map<std::string, std::vector<SUMOTime> > myDepartures;
506 
508  std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > > myDistricts;
509 
512 
515 
518 
521 
524 
527 
530 
532  std::map<std::string, std::map<SUMOVehicleClass, double> > myRestrictions;
533 
536 
539 
541  const bool myKeepVTypeDist;
542 
543 #ifdef HAVE_FOX
544 private:
545  class RoutingTask : public FXWorkerThread::Task {
546  public:
547  RoutingTask(RORoutable* v, const bool removeLoops, MsgHandler* errorHandler)
548  : myRoutable(v), myRemoveLoops(removeLoops), myErrorHandler(errorHandler) {}
549  void run(FXWorkerThread* context);
550  private:
551  RORoutable* const myRoutable;
552  const bool myRemoveLoops;
553  MsgHandler* const myErrorHandler;
554  private:
556  RoutingTask& operator=(const RoutingTask&);
557  };
558 
559 
560 private:
562  FXWorkerThread::Pool myThreadPool;
563 #endif
564 
565 private:
567  RONet(const RONet& src);
568 
570  RONet& operator=(const RONet& src);
571 
572 };
573 
574 
575 #endif
576 
577 /****************************************************************************/
578 
RONode * getNode(const std::string &id) const
Retrieves an node from the network.
Definition: RONet.h:189
bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource)
Definition: RONet.cpp:168
std::map< SumoXMLTag, NamedObjectCont< SUMOVehicleParameter::Stop * > > myStoppingPlaces
Known bus / train / container stops and parking areas.
Definition: RONet.h:466
OutputDevice * myRouteAlternativesOutput
The file to write the computed route alternatives into.
Definition: RONet.h:514
int getEdgeNumber() const
Returns the total number of edges the network contains including internal edges.
Definition: RONet.cpp:647
SumoXMLTag
Numbers representing SUMO-XML - element names.
long long int SUMOTime
Definition: SUMOTime.h:36
OutputDevice * getRouteOutput(const bool alternative=false)
Definition: RONet.h:407
NamedObjectCont< SUMOVehicleParameter * > myFlows
Known flows.
Definition: RONet.h:492
ROEdge * getEdgeForLaneID(const std::string &laneID) const
Retrieves an edge from the network when the lane id is given.
Definition: RONet.h:167
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:50
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:508
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:234
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
Definition: RONet.h:529
Represents a generic random distribution.
int myNumInternalEdges
The number of internal edges in the dictionary.
Definition: RONet.h:535
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
Definition: RONet.cpp:307
Structure representing possible vehicle parameter.
static void adaptIntermodalRouter(ROIntermodalRouter &router)
Definition: RONet.cpp:659
void addNode(RONode *node)
Definition: RONet.cpp:190
T get(const std::string &id) const
Retrieves an item.
void checkFlows(SUMOTime time, MsgHandler *errorHandler)
Definition: RONet.cpp:407
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
bool myHaveActiveFlows
whether any flows are still active
Definition: RONet.h:495
NamedObjectCont< ROEdge * > myEdges
Known edges.
Definition: RONet.h:463
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
bool hasPermissions() const
Definition: RONet.cpp:691
int myDiscardedRouteNo
The number of discarded routes.
Definition: RONet.h:523
A map of named object pointers.
std::map< std::string, std::vector< SUMOTime > > myDepartures
Departure times for randomized flows.
Definition: RONet.h:505
std::vector< const RORoutable * > myPTVehicles
vehicles to keep for public transport routing
Definition: RONet.h:502
OutputDevice * myTypesOutput
The file to write the vehicle types into.
Definition: RONet.h:517
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
Definition: RONet.h:298
int myWrittenRouteNo
The number of written routes.
Definition: RONet.h:526
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
Definition: RONet.cpp:332
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
Definition: RONet.cpp:355
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
Definition: RONet.cpp:55
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter *> *vehTypeDistribution)
Adds a vehicle type distribution.
Definition: RONet.cpp:345
std::set< std::string > myPersonIDs
Known person ids.
Definition: RONet.h:457
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:214
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:71
void cleanup()
closes the file output for computed routes and deletes associated threads if necessary ...
Definition: RONet.cpp:253
bool addRouteDef(RORouteDef *def)
Definition: RONet.cpp:208
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction for an edge type.
Definition: RONet.cpp:121
OutputDevice * myRoutesOutput
The file to write the computed routes into.
Definition: RONet.h:511
const SUMOVehicleParameter::Stop * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Retrieves a stopping place from the network.
Definition: RONet.h:212
void addContainer(const SUMOTime depart, const std::string desc)
Definition: RONet.cpp:401
RoutablesMap myRoutables
Known routables.
Definition: RONet.h:489
bool myDefaultBikeTypeMayBeDeleted
Whether the default bicycle type was already used or can still be replaced.
Definition: RONet.h:483
NamedObjectCont< SUMOVTypeParameter * > myVehicleTypes
Known vehicle types.
Definition: RONet.h:469
ContainerMap myContainers
Definition: RONet.h:499
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:51
static RONet * myInstance
Unique instance of RONet.
Definition: RONet.h:451
bool myDefaultVTypeMayBeDeleted
Whether the default vehicle type was already used or can still be replaced.
Definition: RONet.h:477
NamedObjectCont< RORouteDef * > myRoutes
Known routes.
Definition: RONet.h:486
void createBulkRouteRequests(const RORouterProvider &provider, const SUMOTime time, const bool removeLoops)
Definition: RONet.cpp:487
const bool myKeepVTypeDist
whether to keep the the vtype distribution in output
Definition: RONet.h:541
A basic edge for routing applications.
Definition: ROEdge.h:72
RONet()
Constructor.
Definition: RONet.cpp:63
A pool of worker threads which distributes the tasks and collects the results.
The router&#39;s network representation.
Definition: RONet.h:68
bool addDistrict(const std::string id, ROEdge *source, ROEdge *sink)
Definition: RONet.cpp:151
Structure representing possible vehicle parameter.
const NamedObjectCont< ROEdge * > & getEdgeMap() const
Definition: RONet.h:397
int myReadRouteNo
The number of read routes.
Definition: RONet.h:520
void addStoppingPlace(const std::string &id, const SumoXMLTag category, SUMOVehicleParameter::Stop *stop)
Definition: RONet.cpp:199
std::map< std::string, std::map< SUMOVehicleClass, double > > myRestrictions
The vehicle class specific speed restrictions.
Definition: RONet.h:532
Definition of vehicle stop (position and duration)
std::map< std::string, RandomDistributor< SUMOVTypeParameter * > *> VTypeDistDictType
Vehicle type distribution dictionary type.
Definition: RONet.h:472
A storage for options typed value containers)
Definition: OptionsCont.h:92
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
Definition: RONet.h:474
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:702
virtual bool addEdge(ROEdge *edge)
Definition: RONet.cpp:137
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:454
virtual ~RONet()
Destructor.
Definition: RONet.cpp:93
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:277
A thread repeatingly calculating incoming tasks.
MsgHandler * myErrorHandler
handler for ignorable error messages
Definition: RONet.h:538
Base class for nodes used by the router.
Definition: RONode.h:46
NamedObjectCont< RONode * > myNodes
Known nodes.
Definition: RONet.h:460
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:157
std::multimap< const SUMOTime, const std::string > ContainerMap
Known containers.
Definition: RONet.h:498
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition: RONet.cpp:375
bool addPerson(ROPerson *person)
Definition: RONet.cpp:389
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
bool myDefaultPedTypeMayBeDeleted
Whether the default pedestrian type was already used or can still be replaced.
Definition: RONet.h:480
void setPermissionsFound()
Definition: RONet.cpp:697