SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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-2014 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 
107  ROEdge* getEdge(const std::string& name) const {
108  return myEdges.get(name);
109  }
110 
111 
112  /* @brief Adds a read node to the network
113  *
114  * If the node is already known (another one with the same id exists),
115  * an error is generated and given to msg-error-handler. The node
116  * is deleted in this case
117  *
118  * @param[in] node The node to add
119  */
120  void addNode(RONode* node);
121 
122 
129  RONode* getNode(const std::string& id) const {
130  return myNodes.get(id);
131  }
132 
133 
134  /* @brief Adds a read bus stop to the network
135  *
136  * If the bus stop is already known (another one with the same id exists),
137  * an error is generated and given to msg-error-handler. The stop
138  * is deleted in this case
139  *
140  * @param[in] node The stop to add
141  */
142  void addBusStop(const std::string& id, SUMOVehicleParameter::Stop* stop);
143 
144 
150  const SUMOVehicleParameter::Stop* getBusStop(const std::string& id) const {
151  std::map<std::string, SUMOVehicleParameter::Stop*>::const_iterator it = myBusStops.find(id);
152  if (it == myBusStops.end()) {
153  return 0;
154  }
155  return it->second;
156  }
158 
159 
160 
162 
163 
170  bool checkVType(const std::string& id);
171 
172 
182  virtual bool addVehicleType(SUMOVTypeParameter* type);
183 
184 
198  bool addVTypeDistribution(const std::string& id, RandomDistributor<SUMOVTypeParameter*>* vehTypeDistribution);
199 
200 
213  SUMOVTypeParameter* getVehicleTypeSecure(const std::string& id);
214 
215 
216  /* @brief Adds a route definition to the network
217  *
218  * If the route definition is already known (another one with
219  * the same id exists), false is returned, but the route definition
220  * is not deleted.
221  *
222  * @param[in] def The route definition to add
223  * @return Whether the route definition could be added
224  * @todo Rename myRoutes to myRouteDefinitions
225  */
226  bool addRouteDef(RORouteDef* def);
227 
228 
236  RORouteDef* getRouteDef(const std::string& name) const {
237  return myRoutes.get(name);
238  }
239 
240 
241  /* @brief Adds a vehicle to the network
242  *
243  * If the vehicle is already known (another one with the same id
244  * exists), false is returned, but the vehicle is not deleted.
245  *
246  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
247  *
248  * @param[in] id The id of the vehicle to add
249  * @param[in] veh The vehicle to add
250  * @return Whether the vehicle could be added
251  */
252  virtual bool addVehicle(const std::string& id, ROVehicle* veh);
253 
254 
255  /* @brief Adds a flow of vehicles to the network
256  *
257  * If the flow is already known (another one with the same id
258  * exists), false is returned, but the vehicle parameter are not deleted.
259  *
260  * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
261  *
262  * @param[in] flow The parameter of the flow to add
263  * @return Whether the flow could be added
264  */
265  bool addFlow(SUMOVehicleParameter* flow, const bool randomize);
266 
267 
268  /* @brief Adds a person to the network
269  *
270  * @param[in] depart The departure time of the person
271  * @param[in] desc The xml description of the person
272  */
273  void addPerson(const SUMOTime depart, const std::string desc);
274  // @}
275 
276 
278 
279 
293 
294 
296  virtual bool furtherStored();
298 
299 
300 
301 
302 
313  void openOutput(const std::string& filename, const std::string altFilename, const std::string typeFilename);
314 
315 
318 
319 
321  size_t getEdgeNo() const;
322 
324  int getInternalEdgeNumber() const;
325 
326  const std::map<std::string, ROEdge*>& getEdgeMap() const;
327 
328  bool hasRestrictions() const;
329 
330  void setRestrictionFound();
331 
332  OutputDevice* getRouteOutput(const bool alternative = false) {
333  if (alternative) {
335  }
336  return myRoutesOutput;
337  }
338 
339 protected:
341  const ROVehicle* const veh, const bool removeLoops,
342  MsgHandler* errorHandler);
343 
346  return myVehicles;
347  }
348 
349 
350  void checkFlows(SUMOTime time);
351 
352 
353 protected:
355  std::set<std::string> myVehIDs;
356 
359 
362 
364  std::map<std::string, SUMOVehicleParameter::Stop*> myBusStops;
365 
368 
370  typedef std::map< std::string, RandomDistributor<SUMOVTypeParameter*>* > VTypeDistDictType;
373 
376 
379 
382 
385 
387  typedef std::multimap<const SUMOTime, const std::string> PersonMap;
389 
391  std::map<std::string, std::vector<SUMOTime> > myDepartures;
392 
395 
398 
401 
403  unsigned int myReadRouteNo;
404 
406  unsigned int myDiscardedRouteNo;
407 
409  unsigned int myWrittenRouteNo;
410 
413 
416 
419 
420 #ifdef HAVE_FOX
421  FXWorkerThread::Pool myThreadPool;
422 
423 private:
424  class WorkerThread : public FXWorkerThread {
425  public:
426  WorkerThread(FXWorkerThread::Pool& pool,
428  : FXWorkerThread(pool), myRouter(router) {}
429  SUMOAbstractRouter<ROEdge, ROVehicle>& getRouter() const {
430  return *myRouter;
431  }
432  virtual ~WorkerThread() {
433  stop();
434  delete myRouter;
435  }
436  private:
438  };
439 
440  class RoutingTask : public FXWorkerThread::Task {
441  public:
442  RoutingTask(ROVehicle* v, const bool removeLoops, MsgHandler* errorHandler)
443  : myVehicle(v), myRemoveLoops(removeLoops), myErrorHandler(errorHandler) {}
444  void run(FXWorkerThread* context);
445  private:
446  ROVehicle* const myVehicle;
447  const bool myRemoveLoops;
448  MsgHandler* const myErrorHandler;
449  private:
451  RoutingTask& operator=(const RoutingTask&);
452  };
453 #endif
454 
455 private:
457  RONet(const RONet& src);
458 
460  RONet& operator=(const RONet& src);
461 
462 };
463 
464 
465 #endif
466 
467 /****************************************************************************/
468 
OutputDevice * myRouteAlternativesOutput
The file to write the computed route alternatives into.
Definition: RONet.h:397
OutputDevice * getRouteOutput(const bool alternative=false)
Definition: RONet.h:332
NamedObjectCont< SUMOVehicleParameter * > myFlows
Known flows.
Definition: RONet.h:384
ROVehicleCont & getVehicles()
return vehicles for use by RouteAggregator
Definition: RONet.h:345
int myNumInternalEdges
The number of internal edges in the dictionary.
Definition: RONet.h:415
size_t getEdgeNo() const
Returns the total number of edges the network contains including internal edges.
Definition: RONet.cpp:448
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
Definition: RONet.cpp:191
Structure representing possible vehicle parameter.
void addNode(RONode *node)
Definition: RONet.cpp:96
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:107
NamedObjectCont< ROEdge * > myEdges
Known edges.
Definition: RONet.h:361
unsigned int myDiscardedRouteNo
The number of discarded routes.
Definition: RONet.h:406
std::map< std::string, std::vector< SUMOTime > > myDepartures
Departure times for randomized flows.
Definition: RONet.h:391
OutputDevice * myTypesOutput
The file to write the vehicle types into.
Definition: RONet.h:400
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
Definition: RONet.cpp:209
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
Definition: RONet.cpp:232
const std::map< std::string, ROEdge * > & getEdgeMap() const
Definition: RONet.cpp:460
void openOutput(const std::string &filename, const std::string altFilename, const std::string typeFilename)
Opens the output for computed routes.
Definition: RONet.cpp:122
T get(const std::string &id) const
Retrieves an item.
void checkFlows(SUMOTime time)
Definition: RONet.cpp:297
const SUMOVehicleParameter::Stop * getBusStop(const std::string &id) const
Retrieves a bus stop from the network.
Definition: RONet.h:150
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter * > *vehTypeDistribution)
Adds a vehicle type distribution.
Definition: RONet.cpp:222
A vehicle as used by router.
Definition: ROVehicle.h:59
bool addRouteDef(RORouteDef *def)
Definition: RONet.cpp:116
bool myHaveRestrictions
Whether the network contains edges which not all vehicles may pass.
Definition: RONet.h:412
OutputDevice * myRoutesOutput
The file to write the computed routes into.
Definition: RONet.h:394
NamedObjectCont< SUMOVTypeParameter * > myVehicleTypes
Known vehicle types.
Definition: RONet.h:367
void addPerson(const SUMOTime depart, const std::string desc)
Definition: RONet.cpp:258
virtual bool furtherStored()
Returns the information whether further vehicles are stored.
Definition: RONet.cpp:442
ROVehicleCont myVehicles
Known vehicles.
Definition: RONet.h:381
unsigned int myReadRouteNo
The number of read routes.
Definition: RONet.h:403
bool myDefaultVTypeMayBeDeleted
Whether no vehicle type was loaded.
Definition: RONet.h:375
NamedObjectCont< RORouteDef * > myRoutes
Known routes.
Definition: RONet.h:378
A basic edge for routing applications.
Definition: ROEdge.h:70
int getInternalEdgeNumber() const
Returns the number of internal edges the network contains.
Definition: RONet.cpp:454
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&#39;s network representation.
Definition: RONet.h:72
Structure representing possible vehicle parameter.
void setRestrictionFound()
Definition: RONet.cpp:472
Definition of vehicle stop (position and duration)
PersonMap myPersons
Definition: RONet.h:388
std::map< std::string, RandomDistributor< SUMOVTypeParameter * > * > VTypeDistDictType
Vehicle type distribution dictionary type.
Definition: RONet.h:370
A storage for options typed value containers)
Definition: OptionsCont.h:108
bool hasRestrictions() const
Definition: RONet.cpp:466
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability-&gt;vehicle type)
Definition: RONet.h:372
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:105
int SUMOTime
Definition: SUMOTime.h:43
RONode * getNode(const std::string &id) const
Retrieves an node from the network.
Definition: RONet.h:129
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:264
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:355
virtual ~RONet()
Destructor.
Definition: RONet.cpp:72
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:167
A thread repeatingly calculating incoming tasks.
MsgHandler * myErrorHandler
handler for ignorable error messages
Definition: RONet.h:418
Base class for nodes used by the router.
Definition: RONode.h:51
std::multimap< const SUMOTime, const std::string > PersonMap
Known persons.
Definition: RONet.h:387
NamedObjectCont< RONode * > myNodes
Known nodes.
Definition: RONet.h:358
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition: RONet.cpp:244
SUMOTime saveAndRemoveRoutesUntil(OptionsCont &options, SUMOAbstractRouter< ROEdge, ROVehicle > &router, SUMOTime time)
Computes routes described by their definitions and saves them.
Definition: RONet.cpp:358
void cleanup(SUMOAbstractRouter< ROEdge, ROVehicle > *router)
closes the file output for computed routes and deletes routers and associated threads if necessary ...
Definition: RONet.cpp:141
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
Definition: RONet.h:236
RONet & operator=(const RONet &src)
Invalidated assignment operator.
std::map< std::string, SUMOVehicleParameter::Stop * > myBusStops
Known bus stops.
Definition: RONet.h:364
unsigned int myWrittenRouteNo
The number of written routes.
Definition: RONet.h:409