SUMO - Simulation of Urban MObility
RONet.h
Go to the documentation of this file.
1 /****************************************************************************/
10 // The router's network representation
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2002-2015 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 #ifndef RONet_h
24 #define RONet_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <vector>
37 #include "ROEdge.h"
38 #include "RONode.h"
39 #include "ROVehicleCont.h"
40 #include "ROVehicle.h"
41 #include "RORouteDef.h"
46 
47 #ifdef HAVE_FOX
49 #endif
50 
51 
52 // ===========================================================================
53 // class declarations
54 // ===========================================================================
55 class RONode;
56 class RORouteDef;
57 class OptionsCont;
58 class OutputDevice;
59 
60 
61 // ===========================================================================
62 // class definitions
63 // ===========================================================================
72 class RONet {
73 public:
75  RONet();
76 
77 
81  static RONet* getInstance();
82 
83 
85  virtual ~RONet();
86 
87 
93  void addRestriction(const std::string& id, const SUMOVehicleClass svc, const SUMOReal speed);
94 
95 
101  const std::map<SUMOVehicleClass, SUMOReal>* getRestrictions(const std::string& id) const;
102 
103 
105 
106 
107  /* @brief Adds a read edge to the network
108  *
109  * If the edge is already known (another one with the same id exists),
110  * an error is generated and given to msg-error-handler. The edge
111  * is deleted in this case and false is returned.
112  *
113  * @param[in] edge The edge to add
114  * @return Whether the edge was added (if not, it was deleted, too)
115  */
116  virtual bool addEdge(ROEdge* edge);
117 
118 
119  /* @brief Adds a district and connecting edges to the network
120  *
121  * If the district is already known (another one with the same id exists),
122  * an error is generated and given to msg-error-handler. The edges
123  * are deleted in this case and false is returned.
124  *
125  * @param[in] id The district to add
126  * @return Whether the district was added
127  */
128  bool addDistrict(const std::string id, ROEdge* source, ROEdge* sink);
129 
130 
131  /* @brief Adds a district and connecting edges to the network
132  *
133  * If the district is already known (another one with the same id exists),
134  * an error is generated and given to msg-error-handler. The edges
135  * are deleted in this case and false is returned.
136  *
137  * @param[in] id The district to add
138  * @return Whether the district was added
139  */
140  bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource);
141 
146  const std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > >& getDistricts() const {
147  return myDistricts;
148  }
149 
158  ROEdge* getEdge(const std::string& name) const {
159  return myEdges.get(name);
160  }
161 
162 
163  /* @brief Adds a read node to the network
164  *
165  * If the node is already known (another one with the same id exists),
166  * an error is generated and given to msg-error-handler. The node
167  * is deleted in this case
168  *
169  * @param[in] node The node to add
170  */
171  void addNode(RONode* node);
172 
173 
180  RONode* getNode(const std::string& id) const {
181  return myNodes.get(id);
182  }
183 
184 
185  /* @brief Adds a read bus stop to the network
186  *
187  * If the bus stop is already known (another one with the same id exists),
188  * an error is generated and given to msg-error-handler. The stop
189  * is deleted in this case
190  *
191  * @param[in] node The stop to add
192  */
193  void addBusStop(const std::string& id, SUMOVehicleParameter::Stop* stop);
194 
195 
196  /* @brief Adds a read container stop to the network
197  *
198  * If the container stop is already known (another one with the same id exists),
199  * an error is generated and given to msg-error-handler. The stop
200  * is deleted in this case
201  *
202  * @param[in] node The stop to add
203  */
204  void addContainerStop(const std::string& id, SUMOVehicleParameter::Stop* stop);
205 
206 
212  const SUMOVehicleParameter::Stop* getBusStop(const std::string& id) const {
213  std::map<std::string, SUMOVehicleParameter::Stop*>::const_iterator it = myBusStops.find(id);
214  if (it == myBusStops.end()) {
215  return 0;
216  }
217  return it->second;
218  }
219 
220 
226  const SUMOVehicleParameter::Stop* getContainerStop(const std::string& id) const {
227  std::map<std::string, SUMOVehicleParameter::Stop*>::const_iterator it = myContainerStops.find(id);
228  if (it == myContainerStops.end()) {
229  return 0;
230  }
231  return it->second;
232  }
234 
235 
236 
238 
239 
246  bool checkVType(const std::string& id);
247 
248 
258  virtual bool addVehicleType(SUMOVTypeParameter* type);
259 
260 
274  bool addVTypeDistribution(const std::string& id, RandomDistributor<SUMOVTypeParameter*>* vehTypeDistribution);
275 
276 
287  SUMOVTypeParameter* getVehicleTypeSecure(const std::string& id);
288 
289 
290  /* @brief Adds a route definition to the network
291  *
292  * If the route definition is already known (another one with
293  * the same id exists), false is returned, but the route definition
294  * is not deleted.
295  *
296  * @param[in] def The route definition to add
297  * @return Whether the route definition could be added
298  * @todo Rename myRoutes to myRouteDefinitions
299  */
300  bool addRouteDef(RORouteDef* def);
301 
302 
310  RORouteDef* getRouteDef(const std::string& name) const {
311  return myRoutes.get(name);
312  }
313 
314 
315  /* @brief Adds a vehicle to the network
316  *
317  * If the vehicle is already known (another one with the same id
318  * exists), false is returned, but the vehicle is not deleted.
319  *
320  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
321  *
322  * @param[in] id The id of the vehicle to add
323  * @param[in] veh The vehicle to add
324  * @return Whether the vehicle could be added
325  */
326  virtual bool addVehicle(const std::string& id, ROVehicle* veh);
327 
328 
329  /* @brief Adds a flow of vehicles to the network
330  *
331  * If the flow is already known (another one with the same id
332  * exists), false is returned, but the vehicle parameter are not deleted.
333  *
334  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
335  *
336  * @param[in] flow The parameter of the flow to add
337  * @return Whether the flow could be added
338  */
339  bool addFlow(SUMOVehicleParameter* flow, const bool randomize);
340 
341 
342  /* @brief Adds a person to the network
343  *
344  * @param[in] depart The departure time of the person
345  * @param[in] desc The xml description of the person
346  */
347  void addPerson(const SUMOTime depart, const std::string desc);
348 
349 
350  /* @brief Adds a container to the network
351  *
352  * @param[in] depart The departure time of the container
353  * @param[in] desc The xml description of the container
354  */
355  void addContainer(const SUMOTime depart, const std::string desc);
356  // @}
357 
358 
360 
361 
375 
376 
378  virtual bool furtherStored();
380 
381 
382 
383 
384 
395  void openOutput(const std::string& filename, const std::string altFilename, const std::string typeFilename);
396 
397 
400 
401 
403  size_t getEdgeNo() const;
404 
406  int getInternalEdgeNumber() const;
407 
408  const std::map<std::string, ROEdge*>& getEdgeMap() const;
409 
410  bool hasPermissions() const;
411 
412  void setPermissionsFound();
413 
414  OutputDevice* getRouteOutput(const bool alternative = false) {
415  if (alternative) {
417  }
418  return myRoutesOutput;
419  }
420 
421 #ifdef HAVE_FOX
422  void lock() {
423  myThreadPool.lock();
424  }
425 
426  void unlock() {
427  myThreadPool.unlock();
428  }
429 #endif
430 
431 
432 private:
434  const ROVehicle* const veh, const bool removeLoops,
435  MsgHandler* errorHandler);
436 
439  return myVehicles;
440  }
441 
442 
443  void checkFlows(SUMOTime time);
444 
445  void createBulkRouteRequests(SUMOAbstractRouter<ROEdge, ROVehicle>& router, const SUMOTime time, const bool removeLoops, const std::map<std::string, ROVehicle*>& mmap);
446 
447 private:
449  static RONet* myInstance;
450 
452  std::set<std::string> myVehIDs;
453 
456 
459 
461  std::map<std::string, SUMOVehicleParameter::Stop*> myBusStops;
462 
464  std::map<std::string, SUMOVehicleParameter::Stop*> myContainerStops;
465 
468 
470  typedef std::map< std::string, RandomDistributor<SUMOVTypeParameter*>* > VTypeDistDictType;
472  VTypeDistDictType myVTypeDistDict;
473 
476 
479 
482 
485 
487  typedef std::multimap<const SUMOTime, const std::string> PersonMap;
488  PersonMap myPersons;
489 
491  typedef std::multimap<const SUMOTime, const std::string> ContainerMap;
492  ContainerMap myContainers;
493 
495  std::map<std::string, std::vector<SUMOTime> > myDepartures;
496 
498  std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > > myDistricts;
499 
502 
505 
508 
510  unsigned int myReadRouteNo;
511 
513  unsigned int myDiscardedRouteNo;
514 
516  unsigned int myWrittenRouteNo;
517 
520 
522  std::map<std::string, std::map<SUMOVehicleClass, SUMOReal> > myRestrictions;
523 
526 
529 
530 #ifdef HAVE_FOX
531 private:
532  class WorkerThread : public FXWorkerThread {
533  public:
534  WorkerThread(FXWorkerThread::Pool& pool,
536  : FXWorkerThread(pool), myRouter(router) {}
537  SUMOAbstractRouter<ROEdge, ROVehicle>& getRouter() const {
538  return *myRouter;
539  }
540  virtual ~WorkerThread() {
541  stop();
542  delete myRouter;
543  }
544  private:
546  };
547 
548  class RoutingTask : public FXWorkerThread::Task {
549  public:
550  RoutingTask(ROVehicle* v, const bool removeLoops, MsgHandler* errorHandler)
551  : myVehicle(v), myRemoveLoops(removeLoops), myErrorHandler(errorHandler) {}
552  void run(FXWorkerThread* context);
553  private:
554  ROVehicle* const myVehicle;
555  const bool myRemoveLoops;
556  MsgHandler* const myErrorHandler;
557  private:
559  RoutingTask& operator=(const RoutingTask&);
560  };
561 
562  class BulkmodeTask : public FXWorkerThread::Task {
563  public:
564  BulkmodeTask(const bool value) : myValue(value) {}
565  void run(FXWorkerThread* context) {
566  static_cast<WorkerThread*>(context)->getRouter().setBulkMode(myValue);
567  }
568  private:
569  const bool myValue;
570  private:
572  BulkmodeTask& operator=(const BulkmodeTask&);
573  };
574 
575 
576 private:
578  FXWorkerThread::Pool myThreadPool;
579 #endif
580 
581 private:
583  RONet(const RONet& src);
584 
586  RONet& operator=(const RONet& src);
587 
588 };
589 
590 
591 #endif
592 
593 /****************************************************************************/
594 
bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource)
Definition: RONet.cpp:148
OutputDevice * myRouteAlternativesOutput
The file to write the computed route alternatives into.
Definition: RONet.h:504
bool hasPermissions() const
Definition: RONet.cpp:636
long long int SUMOTime
Definition: SUMOTime.h:43
OutputDevice * getRouteOutput(const bool alternative=false)
Definition: RONet.h:414
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:146
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const SUMOReal speed)
Adds a restriction for an edge type.
Definition: RONet.cpp:101
NamedObjectCont< SUMOVehicleParameter * > myFlows
Known flows.
Definition: RONet.h:484
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:498
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
Definition: RONet.h:519
ROVehicleCont & getVehicles()
return vehicles for use by RouteAggregator
Definition: RONet.h:438
int myNumInternalEdges
The number of internal edges in the dictionary.
Definition: RONet.h:525
size_t getEdgeNo() const
Returns the total number of edges the network contains including internal edges.
Definition: RONet.cpp:618
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
Definition: RONet.cpp:276
Structure representing possible vehicle parameter.
void addNode(RONode *node)
Definition: RONet.cpp:170
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:158
void createBulkRouteRequests(SUMOAbstractRouter< ROEdge, ROVehicle > &router, const SUMOTime time, const bool removeLoops, const std::map< std::string, ROVehicle * > &mmap)
Definition: RONet.cpp:459
const SUMOVehicleParameter::Stop * getContainerStop(const std::string &id) const
Retrieves a container stop from the network.
Definition: RONet.h:226
NamedObjectCont< ROEdge * > myEdges
Known edges.
Definition: RONet.h:458
unsigned int myDiscardedRouteNo
The number of discarded routes.
Definition: RONet.h:513
std::map< std::string, std::vector< SUMOTime > > myDepartures
Departure times for randomized flows.
Definition: RONet.h:495
OutputDevice * myTypesOutput
The file to write the vehicle types into.
Definition: RONet.h:507
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
Definition: RONet.cpp:294
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
Definition: RONet.cpp:317
const std::map< std::string, ROEdge * > & getEdgeMap() const
Definition: RONet.cpp:630
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
Definition: RONet.cpp:65
void openOutput(const std::string &filename, const std::string altFilename, const std::string typeFilename)
Opens the output for computed routes.
Definition: RONet.cpp:207
T get(const std::string &id) const
Retrieves an item.
void checkFlows(SUMOTime time)
Definition: RONet.cpp:387
const SUMOVehicleParameter::Stop * getBusStop(const std::string &id) const
Retrieves a bus stop from the network.
Definition: RONet.h:212
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter * > *vehTypeDistribution)
Adds a vehicle type distribution.
Definition: RONet.cpp:307
A vehicle as used by router.
Definition: ROVehicle.h:60
bool addRouteDef(RORouteDef *def)
Definition: RONet.cpp:201
OutputDevice * myRoutesOutput
The file to write the computed routes into.
Definition: RONet.h:501
void addContainer(const SUMOTime depart, const std::string desc)
Definition: RONet.cpp:348
std::map< std::string, SUMOVehicleParameter::Stop * > myContainerStops
Known container stops.
Definition: RONet.h:464
NamedObjectCont< SUMOVTypeParameter * > myVehicleTypes
Known vehicle types.
Definition: RONet.h:467
std::map< std::string, std::map< SUMOVehicleClass, SUMOReal > > myRestrictions
The vehicle class specific speed restrictions.
Definition: RONet.h:522
void addPerson(const SUMOTime depart, const std::string desc)
Definition: RONet.cpp:343
ContainerMap myContainers
Definition: RONet.h:492
virtual bool furtherStored()
Returns the information whether further vehicles, persons or containers are stored.
Definition: RONet.cpp:612
ROVehicleCont myVehicles
Known vehicles.
Definition: RONet.h:481
static RONet * myInstance
Unique instance of RONet.
Definition: RONet.h:449
unsigned int myReadRouteNo
The number of read routes.
Definition: RONet.h:510
bool myDefaultVTypeMayBeDeleted
Whether no vehicle type was loaded.
Definition: RONet.h:475
NamedObjectCont< RORouteDef * > myRoutes
Known routes.
Definition: RONet.h:478
A basic edge for routing applications.
Definition: ROEdge.h:73
int getInternalEdgeNumber() const
Returns the number of internal edges the network contains.
Definition: RONet.cpp:624
A container for vehicles sorted by their departure time.
Definition: ROVehicleCont.h:54
RONet()
Constructor.
Definition: RONet.cpp:73
A pool of worker threads which distributes the tasks and collects the results.
The router&#39;s network representation.
Definition: RONet.h:72
bool addDistrict(const std::string id, ROEdge *source, ROEdge *sink)
Definition: RONet.cpp:131
Structure representing possible vehicle parameter.
Definition of vehicle stop (position and duration)
PersonMap myPersons
Definition: RONet.h:488
std::map< std::string, RandomDistributor< SUMOVTypeParameter * > * > VTypeDistDictType
Vehicle type distribution dictionary type.
Definition: RONet.h:470
A storage for options typed value containers)
Definition: OptionsCont.h:108
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
Definition: RONet.h:472
Base class for a vehicle&#39;s route definition.
Definition: RORouteDef.h:63
void addBusStop(const std::string &id, SUMOVehicleParameter::Stop *stop)
Definition: RONet.cpp:179
RONode * getNode(const std::string &id) const
Retrieves an node from the network.
Definition: RONet.h:180
virtual bool addEdge(ROEdge *edge)
Definition: RONet.cpp:117
static bool computeRoute(SUMOAbstractRouter< ROEdge, ROVehicle > &router, const ROVehicle *const veh, const bool removeLoops, MsgHandler *errorHandler)
Definition: RONet.cpp:354
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:214
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:452
virtual ~RONet()
Destructor.
Definition: RONet.cpp:91
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:252
A thread repeatingly calculating incoming tasks.
MsgHandler * myErrorHandler
handler for ignorable error messages
Definition: RONet.h:528
Base class for nodes used by the router.
Definition: RONode.h:53
std::multimap< const SUMOTime, const std::string > PersonMap
Known persons.
Definition: RONet.h:487
NamedObjectCont< RONode * > myNodes
Known nodes.
Definition: RONet.h:455
std::multimap< const SUMOTime, const std::string > ContainerMap
Known containers.
Definition: RONet.h:491
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition: RONet.cpp:329
SUMOTime saveAndRemoveRoutesUntil(OptionsCont &options, SUMOAbstractRouter< ROEdge, ROVehicle > &router, SUMOTime time)
Computes routes described by their definitions and saves them.
Definition: RONet.cpp:503
void cleanup(SUMOAbstractRouter< ROEdge, ROVehicle > *router)
closes the file output for computed routes and deletes routers and associated threads if necessary ...
Definition: RONet.cpp:226
void addContainerStop(const std::string &id, SUMOVehicleParameter::Stop *stop)
Definition: RONet.cpp:190
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
Definition: RONet.h:310
RONet & operator=(const RONet &src)
Invalidated assignment operator.
std::map< std::string, SUMOVehicleParameter::Stop * > myBusStops
Known bus stops.
Definition: RONet.h:461
void setPermissionsFound()
Definition: RONet.cpp:642
const std::map< SUMOVehicleClass, SUMOReal > * getRestrictions(const std::string &id) const
Returns the restrictions for an edge type If no restrictions are present, 0 is returned.
Definition: RONet.cpp:107
unsigned int myWrittenRouteNo
The number of written routes.
Definition: RONet.h:516