SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  friend class RORouteAggregator;
74 
75 public:
77  RONet();
78 
79 
81  virtual ~RONet();
82 
83 
85 
86 
87  /* @brief Adds a read edge to the network
88  *
89  * If the edge is already known (another one with the same id exists),
90  * an error is generated and given to msg-error-handler. The edge
91  * is deleted in this case and false is returned.
92  *
93  * @param[in] edge The edge to add
94  * @return Whether the edge was added (if not, it was deleted, too)
95  */
96  virtual bool addEdge(ROEdge* edge);
97 
98 
99  /* @brief Adds a district and connecting edges to the network
100  *
101  * If the district is already known (another one with the same id exists),
102  * an error is generated and given to msg-error-handler. The edges
103  * are deleted in this case and false is returned.
104  *
105  * @param[in] id The district to add
106  * @return Whether the district was added
107  */
108  bool addDistrict(const std::string id, ROEdge* source, ROEdge* sink);
109 
110 
111  /* @brief Adds a district and connecting edges to the network
112  *
113  * If the district is already known (another one with the same id exists),
114  * an error is generated and given to msg-error-handler. The edges
115  * are deleted in this case and false is returned.
116  *
117  * @param[in] id The district to add
118  * @return Whether the district was added
119  */
120  bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource);
121 
126  const std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > >& getDistricts() const {
127  return myDistricts;
128  }
129 
138  ROEdge* getEdge(const std::string& name) const {
139  return myEdges.get(name);
140  }
141 
142 
143  /* @brief Adds a read node to the network
144  *
145  * If the node is already known (another one with the same id exists),
146  * an error is generated and given to msg-error-handler. The node
147  * is deleted in this case
148  *
149  * @param[in] node The node to add
150  */
151  void addNode(RONode* node);
152 
153 
160  RONode* getNode(const std::string& id) const {
161  return myNodes.get(id);
162  }
163 
164 
165  /* @brief Adds a read bus stop to the network
166  *
167  * If the bus stop is already known (another one with the same id exists),
168  * an error is generated and given to msg-error-handler. The stop
169  * is deleted in this case
170  *
171  * @param[in] node The stop to add
172  */
173  void addBusStop(const std::string& id, SUMOVehicleParameter::Stop* stop);
174 
175 
176  /* @brief Adds a read container stop to the network
177  *
178  * If the container stop is already known (another one with the same id exists),
179  * an error is generated and given to msg-error-handler. The stop
180  * is deleted in this case
181  *
182  * @param[in] node The stop to add
183  */
184  void addContainerStop(const std::string& id, SUMOVehicleParameter::Stop* stop);
185 
186 
192  const SUMOVehicleParameter::Stop* getBusStop(const std::string& id) const {
193  std::map<std::string, SUMOVehicleParameter::Stop*>::const_iterator it = myBusStops.find(id);
194  if (it == myBusStops.end()) {
195  return 0;
196  }
197  return it->second;
198  }
199 
200 
206  const SUMOVehicleParameter::Stop* getContainerStop(const std::string& id) const {
207  std::map<std::string, SUMOVehicleParameter::Stop*>::const_iterator it = myContainerStops.find(id);
208  if (it == myContainerStops.end()) {
209  return 0;
210  }
211  return it->second;
212  }
214 
215 
216 
218 
219 
226  bool checkVType(const std::string& id);
227 
228 
238  virtual bool addVehicleType(SUMOVTypeParameter* type);
239 
240 
254  bool addVTypeDistribution(const std::string& id, RandomDistributor<SUMOVTypeParameter*>* vehTypeDistribution);
255 
256 
267  SUMOVTypeParameter* getVehicleTypeSecure(const std::string& id);
268 
269 
270  /* @brief Adds a route definition to the network
271  *
272  * If the route definition is already known (another one with
273  * the same id exists), false is returned, but the route definition
274  * is not deleted.
275  *
276  * @param[in] def The route definition to add
277  * @return Whether the route definition could be added
278  * @todo Rename myRoutes to myRouteDefinitions
279  */
280  bool addRouteDef(RORouteDef* def);
281 
282 
290  RORouteDef* getRouteDef(const std::string& name) const {
291  return myRoutes.get(name);
292  }
293 
294 
295  /* @brief Adds a vehicle to the network
296  *
297  * If the vehicle is already known (another one with the same id
298  * exists), false is returned, but the vehicle is not deleted.
299  *
300  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
301  *
302  * @param[in] id The id of the vehicle to add
303  * @param[in] veh The vehicle to add
304  * @return Whether the vehicle could be added
305  */
306  virtual bool addVehicle(const std::string& id, ROVehicle* veh);
307 
308 
309  /* @brief Adds a flow of vehicles to the network
310  *
311  * If the flow is already known (another one with the same id
312  * exists), false is returned, but the vehicle parameter are not deleted.
313  *
314  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
315  *
316  * @param[in] flow The parameter of the flow to add
317  * @return Whether the flow could be added
318  */
319  bool addFlow(SUMOVehicleParameter* flow, const bool randomize);
320 
321 
322  /* @brief Adds a person to the network
323  *
324  * @param[in] depart The departure time of the person
325  * @param[in] desc The xml description of the person
326  */
327  void addPerson(const SUMOTime depart, const std::string desc);
328 
329 
330  /* @brief Adds a container to the network
331  *
332  * @param[in] depart The departure time of the container
333  * @param[in] desc The xml description of the container
334  */
335  void addContainer(const SUMOTime depart, const std::string desc);
336  // @}
337 
338 
340 
341 
355 
356 
358  virtual bool furtherStored();
360 
361 
362 
363 
364 
375  void openOutput(const std::string& filename, const std::string altFilename, const std::string typeFilename);
376 
377 
380 
381 
383  size_t getEdgeNo() const;
384 
386  int getInternalEdgeNumber() const;
387 
388  const std::map<std::string, ROEdge*>& getEdgeMap() const;
389 
390  bool hasRestrictions() const;
391 
392  void setRestrictionFound();
393 
394  OutputDevice* getRouteOutput(const bool alternative = false) {
395  if (alternative) {
397  }
398  return myRoutesOutput;
399  }
400 
401 protected:
403  const ROVehicle* const veh, const bool removeLoops,
404  MsgHandler* errorHandler);
405 
408  return myVehicles;
409  }
410 
411 
412  void checkFlows(SUMOTime time);
413 
414 
415 protected:
417  std::set<std::string> myVehIDs;
418 
421 
424 
426  std::map<std::string, SUMOVehicleParameter::Stop*> myBusStops;
427 
429  std::map<std::string, SUMOVehicleParameter::Stop*> myContainerStops;
430 
433 
435  typedef std::map< std::string, RandomDistributor<SUMOVTypeParameter*>* > VTypeDistDictType;
437  VTypeDistDictType myVTypeDistDict;
438 
441 
444 
447 
450 
452  typedef std::multimap<const SUMOTime, const std::string> PersonMap;
453  PersonMap myPersons;
454 
456  typedef std::multimap<const SUMOTime, const std::string> ContainerMap;
457  ContainerMap myContainers;
458 
460  std::map<std::string, std::vector<SUMOTime> > myDepartures;
461 
463  std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > > myDistricts;
464 
467 
470 
473 
475  unsigned int myReadRouteNo;
476 
478  unsigned int myDiscardedRouteNo;
479 
481  unsigned int myWrittenRouteNo;
482 
485 
488 
491 
492 #ifdef HAVE_FOX
493  FXWorkerThread::Pool myThreadPool;
494 
495 private:
496  class WorkerThread : public FXWorkerThread {
497  public:
498  WorkerThread(FXWorkerThread::Pool& pool,
500  : FXWorkerThread(pool), myRouter(router) {}
501  SUMOAbstractRouter<ROEdge, ROVehicle>& getRouter() const {
502  return *myRouter;
503  }
504  virtual ~WorkerThread() {
505  stop();
506  delete myRouter;
507  }
508  private:
510  };
511 
512  class RoutingTask : public FXWorkerThread::Task {
513  public:
514  RoutingTask(ROVehicle* v, const bool removeLoops, MsgHandler* errorHandler)
515  : myVehicle(v), myRemoveLoops(removeLoops), myErrorHandler(errorHandler) {}
516  void run(FXWorkerThread* context);
517  private:
518  ROVehicle* const myVehicle;
519  const bool myRemoveLoops;
520  MsgHandler* const myErrorHandler;
521  private:
523  RoutingTask& operator=(const RoutingTask&);
524  };
525 #endif
526 
527 private:
529  RONet(const RONet& src);
530 
532  RONet& operator=(const RONet& src);
533 
534 };
535 
536 
537 #endif
538 
539 /****************************************************************************/
540 
bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource)
Definition: RONet.cpp:113
OutputDevice * myRouteAlternativesOutput
The file to write the computed route alternatives into.
Definition: RONet.h:469
OutputDevice * getRouteOutput(const bool alternative=false)
Definition: RONet.h:394
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:126
NamedObjectCont< SUMOVehicleParameter * > myFlows
Known flows.
Definition: RONet.h:449
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:463
ROVehicleCont & getVehicles()
return vehicles for use by RouteAggregator
Definition: RONet.h:407
int myNumInternalEdges
The number of internal edges in the dictionary.
Definition: RONet.h:487
size_t getEdgeNo() const
Returns the total number of edges the network contains including internal edges.
Definition: RONet.cpp:529
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
Definition: RONet.cpp:241
Structure representing possible vehicle parameter.
void addNode(RONode *node)
Definition: RONet.cpp:135
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:138
const SUMOVehicleParameter::Stop * getContainerStop(const std::string &id) const
Retrieves a container stop from the network.
Definition: RONet.h:206
NamedObjectCont< ROEdge * > myEdges
Known edges.
Definition: RONet.h:423
unsigned int myDiscardedRouteNo
The number of discarded routes.
Definition: RONet.h:478
std::map< std::string, std::vector< SUMOTime > > myDepartures
Departure times for randomized flows.
Definition: RONet.h:460
OutputDevice * myTypesOutput
The file to write the vehicle types into.
Definition: RONet.h:472
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
Definition: RONet.cpp:259
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
Definition: RONet.cpp:282
const std::map< std::string, ROEdge * > & getEdgeMap() const
Definition: RONet.cpp:541
void openOutput(const std::string &filename, const std::string altFilename, const std::string typeFilename)
Opens the output for computed routes.
Definition: RONet.cpp:172
T get(const std::string &id) const
Retrieves an item.
void checkFlows(SUMOTime time)
Definition: RONet.cpp:352
const SUMOVehicleParameter::Stop * getBusStop(const std::string &id) const
Retrieves a bus stop from the network.
Definition: RONet.h:192
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter * > *vehTypeDistribution)
Adds a vehicle type distribution.
Definition: RONet.cpp:272
A vehicle as used by router.
Definition: ROVehicle.h:60
bool addRouteDef(RORouteDef *def)
Definition: RONet.cpp:166
bool myHaveRestrictions
Whether the network contains edges which not all vehicles may pass.
Definition: RONet.h:484
OutputDevice * myRoutesOutput
The file to write the computed routes into.
Definition: RONet.h:466
void addContainer(const SUMOTime depart, const std::string desc)
Definition: RONet.cpp:313
std::map< std::string, SUMOVehicleParameter::Stop * > myContainerStops
Known container stops.
Definition: RONet.h:429
NamedObjectCont< SUMOVTypeParameter * > myVehicleTypes
Known vehicle types.
Definition: RONet.h:432
void addPerson(const SUMOTime depart, const std::string desc)
Definition: RONet.cpp:308
ContainerMap myContainers
Definition: RONet.h:457
virtual bool furtherStored()
Returns the information whether further vehicles, persons or containers are stored.
Definition: RONet.cpp:523
ROVehicleCont myVehicles
Known vehicles.
Definition: RONet.h:446
unsigned int myReadRouteNo
The number of read routes.
Definition: RONet.h:475
bool myDefaultVTypeMayBeDeleted
Whether no vehicle type was loaded.
Definition: RONet.h:440
NamedObjectCont< RORouteDef * > myRoutes
Known routes.
Definition: RONet.h:443
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:535
A container for vehicles sorted by their departure time.
Definition: ROVehicleCont.h:54
RONet()
Constructor.
Definition: RONet.cpp:58
A pool of worker threads which distributes the tasks and collects the results.
The router's network representation.
Definition: RONet.h:72
bool addDistrict(const std::string id, ROEdge *source, ROEdge *sink)
Definition: RONet.cpp:96
Structure representing possible vehicle parameter.
void setRestrictionFound()
Definition: RONet.cpp:553
Definition of vehicle stop (position and duration)
PersonMap myPersons
Definition: RONet.h:453
std::map< std::string, RandomDistributor< SUMOVTypeParameter * > * > VTypeDistDictType
Vehicle type distribution dictionary type.
Definition: RONet.h:435
A storage for options typed value containers)
Definition: OptionsCont.h:108
bool hasRestrictions() const
Definition: RONet.cpp:547
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
Definition: RONet.h:437
Base class for a vehicle's route definition.
Definition: RORouteDef.h:63
void addBusStop(const std::string &id, SUMOVehicleParameter::Stop *stop)
Definition: RONet.cpp:144
int SUMOTime
Definition: SUMOTime.h:43
RONode * getNode(const std::string &id) const
Retrieves an node from the network.
Definition: RONet.h:160
virtual bool addEdge(ROEdge *edge)
Definition: RONet.cpp:82
static bool computeRoute(SUMOAbstractRouter< ROEdge, ROVehicle > &router, const ROVehicle *const veh, const bool removeLoops, MsgHandler *errorHandler)
Definition: RONet.cpp:319
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
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:417
virtual ~RONet()
Destructor.
Definition: RONet.cpp:72
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:217
A thread repeatingly calculating incoming tasks.
MsgHandler * myErrorHandler
handler for ignorable error messages
Definition: RONet.h:490
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:452
NamedObjectCont< RONode * > myNodes
Known nodes.
Definition: RONet.h:420
std::multimap< const SUMOTime, const std::string > ContainerMap
Known containers.
Definition: RONet.h:456
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition: RONet.cpp:294
SUMOTime saveAndRemoveRoutesUntil(OptionsCont &options, SUMOAbstractRouter< ROEdge, ROVehicle > &router, SUMOTime time)
Computes routes described by their definitions and saves them.
Definition: RONet.cpp:424
void cleanup(SUMOAbstractRouter< ROEdge, ROVehicle > *router)
closes the file output for computed routes and deletes routers and associated threads if necessary ...
Definition: RONet.cpp:191
void addContainerStop(const std::string &id, SUMOVehicleParameter::Stop *stop)
Definition: RONet.cpp:155
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
Definition: RONet.h:290
RONet & operator=(const RONet &src)
Invalidated assignment operator.
std::map< std::string, SUMOVehicleParameter::Stop * > myBusStops
Known bus stops.
Definition: RONet.h:426
unsigned int myWrittenRouteNo
The number of written routes.
Definition: RONet.h:481