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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // The router's network representation
21 /****************************************************************************/
22 #ifndef RONet_h
23 #define RONet_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <vector>
43 #include "ROLane.h"
44 #include "RORoutable.h"
45 #include "RORouteDef.h"
46 
47 #ifdef HAVE_FOX
49 #endif
50 
51 
52 // ===========================================================================
53 // class declarations
54 // ===========================================================================
55 class ROEdge;
56 class ROLane;
57 class RONode;
58 class ROPerson;
59 class RORoutable;
60 class ROVehicle;
61 class OptionsCont;
62 class OutputDevice;
63 
64 
65 // ===========================================================================
66 // class definitions
67 // ===========================================================================
74 class RONet {
75 public:
76 
77  typedef std::map<const SUMOTime, std::vector<RORoutable*> > RoutablesMap;
78 
80  RONet();
81 
82 
86  static RONet* getInstance();
87 
88 
90  virtual ~RONet();
91 
92 
98  void addRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed);
99 
100 
106  const std::map<SUMOVehicleClass, double>* getRestrictions(const std::string& id) const;
107 
108 
110 
111 
112  /* @brief Adds a read edge to the network
113  *
114  * If the edge is already known (another one with the same id exists),
115  * an error is generated and given to msg-error-handler. The edge
116  * is deleted in this case and false is returned.
117  *
118  * @param[in] edge The edge to add
119  * @return Whether the edge was added (if not, it was deleted, too)
120  */
121  virtual bool addEdge(ROEdge* edge);
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 addDistrict(const std::string id, ROEdge* source, ROEdge* sink);
134 
135 
136  /* @brief Adds a district and connecting edges to the network
137  *
138  * If the district is already known (another one with the same id exists),
139  * an error is generated and given to msg-error-handler. The edges
140  * are deleted in this case and false is returned.
141  *
142  * @param[in] id The district to add
143  * @return Whether the district was added
144  */
145  bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource);
146 
151  const std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > >& getDistricts() const {
152  return myDistricts;
153  }
154 
163  ROEdge* getEdge(const std::string& name) const {
164  return myEdges.get(name);
165  }
166 
167 
173  ROEdge* getEdgeForLaneID(const std::string& laneID) const {
174  return getEdge(laneID.substr(0, laneID.rfind("_")));
175  }
176 
177 
178  /* @brief Adds a read node to the network
179  *
180  * If the node is already known (another one with the same id exists),
181  * an error is generated and given to msg-error-handler. The node
182  * is deleted in this case
183  *
184  * @param[in] node The node to add
185  */
186  void addNode(RONode* node);
187 
188 
195  RONode* getNode(const std::string& id) const {
196  return myNodes.get(id);
197  }
198 
199 
200  /* @brief Adds a read stopping place (bus, train, container, parking) to the network
201  *
202  * If the place is already known (another one with the same id and category exists),
203  * an error is generated and given to msg-error-handler. The stop
204  * is deleted in this case
205  *
206  * @param[in] id The name of the stop to add
207  * @param[in] category The type of stop
208  * @param[in] stop The detailed stop description
209  */
210  void addStoppingPlace(const std::string& id, const SumoXMLTag category, SUMOVehicleParameter::Stop* stop);
211 
218  const SUMOVehicleParameter::Stop* getStoppingPlace(const std::string& id, const SumoXMLTag category) const {
219  if (myStoppingPlaces.count(category) > 0) {
220  return myStoppingPlaces.find(category)->second.get(id);
221  }
222  return 0;
223  }
225 
226 
227 
229 
230 
237  bool checkVType(const std::string& id);
238 
239 
249  virtual bool addVehicleType(SUMOVTypeParameter* type);
250 
251 
265  bool addVTypeDistribution(const std::string& id, RandomDistributor<SUMOVTypeParameter*>* vehTypeDistribution);
266 
267 
278  SUMOVTypeParameter* getVehicleTypeSecure(const std::string& id);
279 
280 
281  /* @brief Adds a route definition to the network
282  *
283  * If the route definition is already known (another one with
284  * the same id exists), false is returned, but the route definition
285  * is not deleted.
286  *
287  * @param[in] def The route definition to add
288  * @return Whether the route definition could be added
289  * @todo Rename myRoutes to myRouteDefinitions
290  */
291  bool addRouteDef(RORouteDef* def);
292 
293 
301  RORouteDef* getRouteDef(const std::string& name) const {
302  return myRoutes.get(name);
303  }
304 
305 
306  /* @brief Adds a vehicle to the network
307  *
308  * If the vehicle is already known (another one with the same id
309  * exists), false is returned, but the vehicle is not deleted.
310  *
311  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
312  *
313  * @param[in] id The id of the vehicle to add
314  * @param[in] veh The vehicle to add
315  * @return Whether the vehicle could be added
316  */
317  virtual bool addVehicle(const std::string& id, ROVehicle* veh);
318 
319 
320  /* @brief Adds a flow of vehicles to the network
321  *
322  * If the flow is already known (another one with the same id
323  * exists), false is returned, but the vehicle parameter are not deleted.
324  *
325  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
326  *
327  * @param[in] flow The parameter of the flow to add
328  * @return Whether the flow could be added
329  */
330  bool addFlow(SUMOVehicleParameter* flow, const bool randomize);
331 
332 
333  /* @brief Adds a person to the network
334  *
335  * @param[in] person The person to add
336  */
337  bool addPerson(ROPerson* person);
338 
339 
340  /* @brief Adds a container to the network
341  *
342  * @param[in] depart The departure time of the container
343  * @param[in] desc The xml description of the container
344  */
345  void addContainer(const SUMOTime depart, const std::string desc);
346  // @}
347 
348 
350 
351 
364  const RORouterProvider& provider, SUMOTime time);
365 
366 
368  virtual bool furtherStored();
370 
371 
378  void openOutput(const OptionsCont& options);
379 
380 
387  void writeIntermodal(const OptionsCont& options, ROIntermodalRouter& router) const;
388 
389 
391  void cleanup();
392 
393 
395  int getEdgeNumber() const;
396 
398  int getInternalEdgeNumber() const;
399 
401  return myEdges;
402  }
403 
404  static void adaptIntermodalRouter(ROIntermodalRouter& router);
405 
406  bool hasPermissions() const;
407 
408  void setPermissionsFound();
409 
410  OutputDevice* getRouteOutput(const bool alternative = false) {
411  if (alternative) {
413  }
414  return myRoutesOutput;
415  }
416 
417 #ifdef HAVE_FOX
418  FXWorkerThread::Pool& getThreadPool() {
419  return myThreadPool;
420  }
421 
422  class WorkerThread : public FXWorkerThread, public RORouterProvider {
423  public:
424  WorkerThread(FXWorkerThread::Pool& pool,
425  const RORouterProvider& original)
426  : FXWorkerThread(pool), RORouterProvider(original) {}
427  virtual ~WorkerThread() {
428  stop();
429  }
430  };
431 
432  class BulkmodeTask : public FXWorkerThread::Task {
433  public:
434  BulkmodeTask(const bool value) : myValue(value) {}
435  void run(FXWorkerThread* context) {
436  static_cast<WorkerThread*>(context)->getVehicleRouter().setBulkMode(myValue);
437  }
438  private:
439  const bool myValue;
440  private:
442  BulkmodeTask& operator=(const BulkmodeTask&);
443  };
444 #endif
445 
446 
447 private:
448  void checkFlows(SUMOTime time, MsgHandler* errorHandler, const bool keepPT);
449 
450  void createBulkRouteRequests(const RORouterProvider& provider, const SUMOTime time, const bool removeLoops);
451 
452 private:
454  static RONet* myInstance;
455 
457  std::set<std::string> myVehIDs;
458 
460  std::set<std::string> myPersonIDs;
461 
464 
467 
469  std::map<SumoXMLTag, NamedObjectCont<SUMOVehicleParameter::Stop*> > myStoppingPlaces;
470 
473 
475  typedef std::map< std::string, RandomDistributor<SUMOVTypeParameter*>* > VTypeDistDictType;
477  VTypeDistDictType myVTypeDistDict;
478 
481 
484 
487 
489  RoutablesMap myRoutables;
490 
493 
495  typedef std::multimap<const SUMOTime, const std::string> ContainerMap;
496  ContainerMap myContainers;
497 
499  std::vector<const RORoutable*> myPTVehicles;
500 
502  std::map<std::string, std::vector<SUMOTime> > myDepartures;
503 
505  std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > > myDistricts;
506 
509 
512 
515 
518 
521 
524 
527 
529  std::map<std::string, std::map<SUMOVehicleClass, double> > myRestrictions;
530 
533 
536 
538  const bool myKeepVTypeDist;
539 
540 #ifdef HAVE_FOX
541 private:
542  class RoutingTask : public FXWorkerThread::Task {
543  public:
544  RoutingTask(RORoutable* v, const bool removeLoops, MsgHandler* errorHandler)
545  : myRoutable(v), myRemoveLoops(removeLoops), myErrorHandler(errorHandler) {}
546  void run(FXWorkerThread* context);
547  private:
548  RORoutable* const myRoutable;
549  const bool myRemoveLoops;
550  MsgHandler* const myErrorHandler;
551  private:
553  RoutingTask& operator=(const RoutingTask&);
554  };
555 
556 
557 private:
559  FXWorkerThread::Pool myThreadPool;
560 #endif
561 
562 private:
564  RONet(const RONet& src);
565 
567  RONet& operator=(const RONet& src);
568 
569 };
570 
571 
572 #endif
573 
574 /****************************************************************************/
575 
RONode * getNode(const std::string &id) const
Retrieves an node from the network.
Definition: RONet.h:195
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:469
OutputDevice * myRouteAlternativesOutput
The file to write the computed route alternatives into.
Definition: RONet.h:511
int getEdgeNumber() const
Returns the total number of edges the network contains including internal edges.
Definition: RONet.cpp:645
SumoXMLTag
Numbers representing SUMO-XML - element names.
OutputDevice * getRouteOutput(const bool alternative=false)
Definition: RONet.h:410
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:173
int getInternalEdgeNumber() const
Returns the number of internal edges the network contains.
Definition: RONet.cpp:651
A single lane the router may use.
Definition: ROLane.h:56
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:505
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:526
Represents a generic random distribution.
int myNumInternalEdges
The number of internal edges in the dictionary.
Definition: RONet.h:532
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
Definition: RONet.cpp:304
Structure representing possible vehicle parameter.
static void adaptIntermodalRouter(ROIntermodalRouter &router)
Definition: RONet.cpp:657
void addNode(RONode *node)
Definition: RONet.cpp:190
T get(const std::string &id) const
Retrieves an item.
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:151
NamedObjectCont< ROEdge * > myEdges
Known edges.
Definition: RONet.h:466
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:688
int myDiscardedRouteNo
The number of discarded routes.
Definition: RONet.h:520
A map of named object pointers.
std::map< std::string, std::vector< SUMOTime > > myDepartures
Departure times for randomized flows.
Definition: RONet.h:502
std::vector< const RORoutable * > myPTVehicles
vehicles to keep for public transport routing
Definition: RONet.h:499
OutputDevice * myTypesOutput
The file to write the vehicle types into.
Definition: RONet.h:514
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
Definition: RONet.h:301
int myWrittenRouteNo
The number of written routes.
Definition: RONet.h:523
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
Definition: RONet.cpp:329
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
Definition: RONet.cpp:352
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
Definition: RONet.cpp:61
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter *> *vehTypeDistribution)
Adds a vehicle type distribution.
Definition: RONet.cpp:342
std::set< std::string > myPersonIDs
Known person ids.
Definition: RONet.h:460
A routable thing such as a vehicle or person.
Definition: RORoutable.h:61
void openOutput(const OptionsCont &options)
Opens the output for computed routes.
Definition: RONet.cpp:214
RouterProvider< ROEdge, ROLane, RONode, ROVehicle > RORouterProvider
Definition: RORoutable.h:51
A vehicle as used by router.
Definition: ROVehicle.h:59
std::map< const SUMOTime, std::vector< RORoutable * > > RoutablesMap
Definition: RONet.h:77
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:508
const SUMOVehicleParameter::Stop * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Retrieves a stopping place from the network.
Definition: RONet.h:218
void addContainer(const SUMOTime depart, const std::string desc)
Definition: RONet.cpp:398
RoutablesMap myRoutables
Known routables.
Definition: RONet.h:489
NamedObjectCont< SUMOVTypeParameter * > myVehicleTypes
Known vehicle types.
Definition: RONet.h:472
ContainerMap myContainers
Definition: RONet.h:496
virtual bool furtherStored()
Returns the information whether further vehicles, persons or containers are stored.
Definition: RONet.cpp:639
A person as used by router.
Definition: ROPerson.h:57
static RONet * myInstance
Unique instance of RONet.
Definition: RONet.h:454
bool myDefaultVTypeMayBeDeleted
Whether no vehicle type has been loaded yet.
Definition: RONet.h:480
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:538
A basic edge for routing applications.
Definition: ROEdge.h:77
RONet()
Constructor.
Definition: RONet.cpp:69
A pool of worker threads which distributes the tasks and collects the results.
The router&#39;s network representation.
Definition: RONet.h:74
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:400
int myReadRouteNo
The number of read routes.
Definition: RONet.h:517
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:529
Definition of vehicle stop (position and duration)
std::map< std::string, RandomDistributor< SUMOVTypeParameter * > *> VTypeDistDictType
Vehicle type distribution dictionary type.
Definition: RONet.h:475
A storage for options typed value containers)
Definition: OptionsCont.h:98
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
Definition: RONet.h:477
Base class for a vehicle&#39;s route definition.
Definition: RORouteDef.h:62
virtual bool addEdge(ROEdge *edge)
Definition: RONet.cpp:137
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
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:457
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:535
long long int SUMOTime
Definition: TraCIDefs.h:51
Base class for nodes used by the router.
Definition: RONode.h:52
NamedObjectCont< RONode * > myNodes
Known nodes.
Definition: RONet.h:463
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:163
std::multimap< const SUMOTime, const std::string > ContainerMap
Known containers.
Definition: RONet.h:495
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition: RONet.cpp:372
bool addPerson(ROPerson *person)
Definition: RONet.cpp:386
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
void checkFlows(SUMOTime time, MsgHandler *errorHandler, const bool keepPT)
Definition: RONet.cpp:404
bool myDefaultPedTypeMayBeDeleted
Whether no pedestrian type has been loaded yet.
Definition: RONet.h:483
void setPermissionsFound()
Definition: RONet.cpp:694