Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
RONet.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2002-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
21// The router's network representation
22/****************************************************************************/
23#pragma once
24#include <config.h>
25
26#include <vector>
32#include "ROLane.h"
33#include "RORoutable.h"
34#include "RORouteDef.h"
35
36#ifdef HAVE_FOX
38#endif
39
40
41// ===========================================================================
42// class declarations
43// ===========================================================================
44class ROEdge;
45class RONode;
46class ROPerson;
47class ROVehicle;
49class OptionsCont;
50class OutputDevice;
51
53
54// ===========================================================================
55// class definitions
56// ===========================================================================
63class RONet {
64public:
65
66 typedef std::map<const SUMOTime, std::vector<RORoutable*> > RoutablesMap;
67
69 RONet();
70
71
75 static RONet* getInstance();
76
77
79 virtual ~RONet();
80
81
87 void addRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed);
88
89
95 const std::map<SUMOVehicleClass, double>* getRestrictions(const std::string& id) const;
96
97 bool hasRestrictions() const {
98 return !myRestrictions.empty();
99 }
100
102
103
104 /* @brief Adds a read edge to the network
105 *
106 * If the edge is already known (another one with the same id exists),
107 * an error is generated and given to msg-error-handler. The edge
108 * is deleted in this case and false is returned.
109 *
110 * @param[in] edge The edge to add
111 * @return Whether the edge was added (if not, it was deleted, too)
112 */
113 virtual bool addEdge(ROEdge* edge);
114
115
116 /* @brief Adds a district and connecting edges to the network
117 *
118 * If the district is already known (another one with the same id exists),
119 * an error is generated and given to msg-error-handler. The edges
120 * are deleted in this case and false is returned.
121 *
122 * @param[in] id The district to add
123 * @return Whether the district was added
124 */
125 bool addDistrict(const std::string id, ROEdge* source, ROEdge* sink);
126
127
128 /* @brief Adds a district and connecting edges to the network
129 *
130 * If the district is already known (another one with the same id exists),
131 * an error is generated and given to msg-error-handler. The edges
132 * are deleted in this case and false is returned.
133 *
134 * @param[in] id The district to add
135 * @return Whether the district was added
136 */
137 bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource);
138
141
143 void setBidiEdges(const std::map<ROEdge*, std::string>& bidiMap);
144
149 const std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > >& getDistricts() const {
150 return myDistricts;
151 }
152
161 ROEdge* getEdge(const std::string& name) const {
162 return myEdges.get(name);
163 }
164
165
171 ROEdge* getEdgeForLaneID(const std::string& laneID) const;
172
178 ROLane* getLane(const std::string& laneID) const;
179
180 /* @brief Adds a read node to the network
181 *
182 * If the node is already known (another one with the same id exists),
183 * an error is generated and given to msg-error-handler. The node
184 * is deleted in this case
185 *
186 * @param[in] node The node to add
187 */
188 void addNode(RONode* node);
189
190
197 RONode* getNode(const std::string& id) const {
198 return myNodes.get(id);
199 }
200
201
202 /* @brief Adds a read stopping place (bus, train, container, parking) to the network
203 *
204 * If the place is already known (another one with the same id and category exists),
205 * an error is generated and given to msg-error-handler. The stop
206 * is deleted in this case
207 *
208 * @param[in] id The name of the stop to add
209 * @param[in] category The type of stop
210 * @param[in] stop The detailed stop description
211 */
212 void addStoppingPlace(const std::string& id, const SumoXMLTag category, SUMOVehicleParameter::Stop* stop);
213
220 const SUMOVehicleParameter::Stop* getStoppingPlace(const std::string& id, const SumoXMLTag category) const {
221 if (myStoppingPlaces.count(category) > 0) {
222 return myStoppingPlaces.find(category)->second.get(id);
223 }
224 return 0;
225 }
226
228 const std::string getStoppingPlaceName(const std::string& id) const;
229
231 const std::string getStoppingPlaceElement(const std::string& id) const;
233
234
235
237
238
245 bool checkVType(const std::string& id);
246
247
257 virtual bool addVehicleType(SUMOVTypeParameter* type);
258
259
273 bool addVTypeDistribution(const std::string& id, RandomDistributor<SUMOVTypeParameter*>* vehTypeDistribution);
274
275
285 const auto it = myVTypeDistDict.find(id);
286 return it != myVTypeDistDict.end() ? it ->second : nullptr;
287 }
288
289
299 SUMOVTypeParameter* getVehicleTypeSecure(const std::string& id);
300
301
302 /* @brief Adds a route definition to the network
303 *
304 * If the route definition is already known (another one with
305 * the same id exists), false is returned, but the route definition
306 * is not deleted.
307 *
308 * @param[in] def The route definition to add
309 * @return Whether the route definition could be added
310 * @todo Rename myRoutes to myRouteDefinitions
311 */
312 bool addRouteDef(RORouteDef* def);
313
314
322 RORouteDef* getRouteDef(const std::string& name) const {
323 return myRoutes.get(name);
324 }
325
326
327 /* @brief Adds a vehicle to the network
328 *
329 * If the vehicle is already known (another one with the same id
330 * exists), false is returned, but the vehicle is not deleted.
331 *
332 * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
333 *
334 * @param[in] id The id of the vehicle to add
335 * @param[in] veh The vehicle to add
336 * @return Whether the vehicle could be added
337 */
338 virtual bool addVehicle(const std::string& id, ROVehicle* veh);
339
341 bool knowsVehicle(const std::string& id) const;
342
344 SUMOTime getDeparture(const std::string& vehID) const;
345
346 /* @brief Adds a flow of vehicles to the network
347 *
348 * If the flow is already known (another one with the same id
349 * exists), false is returned, but the vehicle parameter are not deleted.
350 *
351 * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
352 *
353 * @param[in] flow The parameter of the flow to add
354 * @return Whether the flow could be added
355 */
356 bool addFlow(SUMOVehicleParameter* flow, const bool randomize);
357
358
359 /* @brief Adds a person to the network
360 *
361 * @param[in] person The person to add
362 */
363 bool addPerson(ROPerson* person);
364
365
366 /* @brief Adds a container to the network
367 *
368 * @param[in] depart The departure time of the container
369 * @param[in] desc The xml description of the container
370 */
371 void addContainer(const SUMOTime depart, const std::string desc);
372 // @}
373
374
376
377
390 const RORouterProvider& provider, SUMOTime time);
391
392
394 bool furtherStored();
396
397
404 void openOutput(const OptionsCont& options);
405
406
413 void writeIntermodal(const OptionsCont& options, ROIntermodalRouter& router) const;
414
415
417 void cleanup();
418
419
421 int getEdgeNumber() const;
422
424 int getInternalEdgeNumber() const;
425
427 return myEdges;
428 }
429
430 static void adaptIntermodalRouter(ROIntermodalRouter& router);
431
432 bool hasPermissions() const;
433
434 void setPermissionsFound();
435
437 bool hasBidiEdges() const {
438 return myHasBidiEdges;
439 }
440
442 bool hasLoadedEffort() const;
443
444 OutputDevice* getRouteOutput(const bool alternative = false) {
445 if (alternative) {
447 }
448 return myRoutesOutput;
449 }
450
451#ifdef HAVE_FOX
452 MFXWorkerThread::Pool& getThreadPool() {
453 return myThreadPool;
454 }
455
456 class WorkerThread : public MFXWorkerThread, public RORouterProvider {
457 public:
458 WorkerThread(MFXWorkerThread::Pool& pool,
459 const RORouterProvider& original)
460 : MFXWorkerThread(pool), RORouterProvider(original) {}
461 virtual ~WorkerThread() {
462 stop();
463 }
464 };
465
466 class BulkmodeTask : public MFXWorkerThread::Task {
467 public:
468 BulkmodeTask(const bool value) : myValue(value) {}
469 void run(MFXWorkerThread* context) {
470 static_cast<WorkerThread*>(context)->setBulkMode(myValue);
471 }
472 private:
473 const bool myValue;
474 private:
476 BulkmodeTask& operator=(const BulkmodeTask&);
477 };
478#endif
479
480
481private:
482 void checkFlows(SUMOTime time, MsgHandler* errorHandler);
483
484 void createBulkRouteRequests(const RORouterProvider& provider, const SUMOTime time, const bool removeLoops);
485
486private:
489
491 std::map<std::string, SUMOTime> myVehIDs;
492
494 std::set<std::string> myPersonIDs;
495
498
501
503 std::map<SumoXMLTag, NamedObjectCont<SUMOVehicleParameter::Stop*> > myStoppingPlaces;
504
507
509 typedef std::map< std::string, RandomDistributor<SUMOVTypeParameter*>* > VTypeDistDictType;
512
515
518
521
524
527
530
533
536
539
541 typedef std::multimap<const SUMOTime, const std::string> ContainerMap;
543
545 std::vector<const RORoutable*> myPTVehicles;
546
548 std::map<std::string, std::vector<SUMOTime> > myDepartures;
549
551 std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > > myDistricts;
552
555
558
561
564
567
570
573
575 std::map<std::string, std::map<SUMOVehicleClass, double> > myRestrictions;
576
579
582
584 const bool myKeepVTypeDist;
585
587 const bool myDoPTRouting;
588
591
592#ifdef HAVE_FOX
593private:
594 class RoutingTask : public MFXWorkerThread::Task {
595 public:
596 RoutingTask(RORoutable* v, const bool removeLoops, MsgHandler* errorHandler)
597 : myRoutable(v), myRemoveLoops(removeLoops), myErrorHandler(errorHandler) {}
598 void run(MFXWorkerThread* context);
599 private:
600 RORoutable* const myRoutable;
601 const bool myRemoveLoops;
602 MsgHandler* const myErrorHandler;
603 private:
605 RoutingTask& operator=(const RoutingTask&);
606 };
607
608
609private:
611 MFXWorkerThread::Pool myThreadPool;
612#endif
613
614private:
616 RONet(const RONet& src);
617
619 RONet& operator=(const RONet& src);
620
621};
long long int SUMOTime
Definition GUI.h:36
MapMatcher< ROEdge, ROLane, RONode > ROMapMatcher
Definition RONet.h:52
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
SumoXMLTag
Numbers representing SUMO-XML - element names.
A pool of worker threads which distributes the tasks and collects the results.
Abstract superclass of a task to be run with an index to keep track of pending tasks.
A thread repeatingly calculating incoming tasks.
Provides utility functions for matching locations to edges (during route parsing)
Definition MapMatcher.h:45
A map of named object pointers.
T get(const std::string &id) const
Retrieves an item.
A storage for options typed value containers)
Definition OptionsCont.h:89
Static storage of an output device and its base (abstract) implementation.
Interface for building instances of router-edges.
A basic edge for routing applications.
Definition ROEdge.h:72
A single lane the router may use.
Definition ROLane.h:48
The router's network representation.
Definition RONet.h:63
void createBulkRouteRequests(const RORouterProvider &provider, const SUMOTime time, const bool removeLoops)
Definition RONet.cpp:623
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition RONet.cpp:361
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
Definition RONet.cpp:56
int myNumInternalEdges
The number of internal edges in the dictionary.
Definition RONet.h:578
bool myDefaultPedTypeMayBeDeleted
Whether the default pedestrian type was already used or can still be replaced.
Definition RONet.h:517
bool hasBidiEdges() const
return whether the network contains bidirectional rail edges
Definition RONet.h:437
void setPermissionsFound()
Definition RONet.cpp:868
bool myDefaultRailTypeMayBeDeleted
Whether the default rail type was already used or can still be replaced.
Definition RONet.h:526
std::map< const SUMOTime, std::vector< RORoutable * > > RoutablesMap
Definition RONet.h:66
bool myDefaultVTypeMayBeDeleted
Whether the default vehicle type was already used or can still be replaced.
Definition RONet.h:514
void checkFlows(SUMOTime time, MsgHandler *errorHandler)
Definition RONet.cpp:537
RONode * getNode(const std::string &id) const
Retrieves an node from the network.
Definition RONet.h:197
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:150
std::map< std::string, RandomDistributor< SUMOVTypeParameter * > * > VTypeDistDictType
Vehicle type distribution dictionary type.
Definition RONet.h:509
const RandomDistributor< SUMOVTypeParameter * > * getVTypeDistribution(const std::string &id)
Retrieves the named vehicle type distribution.
Definition RONet.h:284
ContainerMap myContainers
Definition RONet.h:542
std::set< std::string > myPersonIDs
Known person ids.
Definition RONet.h:494
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:551
bool addRouteDef(RORouteDef *def)
Definition RONet.cpp:286
int myReadRouteNo
The number of read routes.
Definition RONet.h:563
void addStoppingPlace(const std::string &id, const SumoXMLTag category, SUMOVehicleParameter::Stop *stop)
Definition RONet.cpp:277
bool knowsVehicle(const std::string &id) const
returns whether a vehicle with the given id was already loaded
Definition RONet.cpp:485
void cleanup()
closes the file output for computed routes and deletes associated threads if necessary
Definition RONet.cpp:337
bool myHaveActiveFlows
whether any flows are still active
Definition RONet.h:538
RONet(const RONet &src)
Invalidated copy constructor.
std::map< std::string, SUMOTime > myVehIDs
Known vehicle ids and their departure.
Definition RONet.h:491
void openOutput(const OptionsCont &options)
Opens the output for computed routes.
Definition RONet.cpp:292
NamedObjectCont< SUMOVehicleParameter * > myFlows
Known flows.
Definition RONet.h:535
OutputDevice * myRouteAlternativesOutput
The file to write the computed route alternatives into.
Definition RONet.h:557
bool myDefaultBikeTypeMayBeDeleted
Whether the default bicycle type was already used or can still be replaced.
Definition RONet.h:520
RoutablesMap myRoutables
Known routables.
Definition RONet.h:532
int getInternalEdgeNumber() const
Returns the number of internal edges the network contains.
Definition RONet.cpp:798
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
Definition RONet.cpp:463
SUMOTime getDeparture(const std::string &vehID) const
returns departure time for the given vehicle id
Definition RONet.cpp:490
OutputDevice * getRouteOutput(const bool alternative=false)
Definition RONet.h:444
bool myHasBidiEdges
whether the network contains bidirectional railway edges
Definition RONet.h:590
bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource)
Definition RONet.cpp:197
MsgHandler * myErrorHandler
handler for ignorable error messages
Definition RONet.h:581
void writeIntermodal(const OptionsCont &options, ROIntermodalRouter &router) const
Writes the intermodal network and weights if requested.
Definition RONet.cpp:318
RONet()
Constructor.
Definition RONet.cpp:64
NamedObjectCont< RONode * > myNodes
Known nodes.
Definition RONet.h:497
const std::string getStoppingPlaceElement(const std::string &id) const
return the element name for the given stopping place id
Definition RONet.cpp:895
const SUMOVehicleParameter::Stop * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Retrieves a stopping place from the network.
Definition RONet.h:220
void addContainer(const SUMOTime depart, const std::string desc)
Definition RONet.cpp:531
static void adaptIntermodalRouter(ROIntermodalRouter &router)
Definition RONet.cpp:817
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition RONet.h:161
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction for an edge type.
Definition RONet.cpp:144
NamedObjectCont< RORouteDef * > myRoutes
Known routes.
Definition RONet.h:529
bool furtherStored()
Returns the information whether further vehicles, persons or containers are stored.
Definition RONet.cpp:786
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
Definition RONet.cpp:393
OutputDevice * myRoutesOutput
The file to write the computed routes into.
Definition RONet.h:554
bool addPerson(ROPerson *person)
Definition RONet.cpp:519
int myWrittenRouteNo
The number of written routes.
Definition RONet.h:569
static RONet * myInstance
Unique instance of RONet.
Definition RONet.h:488
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
Definition RONet.h:322
SUMOTime saveAndRemoveRoutesUntil(OptionsCont &options, const RORouterProvider &provider, SUMOTime time)
Computes routes described by their definitions and saves them.
Definition RONet.cpp:673
virtual bool addEdge(ROEdge *edge)
Definition RONet.cpp:160
bool myDefaultTaxiTypeMayBeDeleted
Whether the default taxi type was already used or can still be replaced.
Definition RONet.h:523
std::map< std::string, std::map< SUMOVehicleClass, double > > myRestrictions
The vehicle class specific speed restrictions.
Definition RONet.h:575
std::map< SumoXMLTag, NamedObjectCont< SUMOVehicleParameter::Stop * > > myStoppingPlaces
Known bus / train / container stops and parking areas.
Definition RONet.h:503
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
Definition RONet.cpp:439
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
Definition RONet.h:572
bool hasPermissions() const
Definition RONet.cpp:862
void setBidiEdges(const std::map< ROEdge *, std::string > &bidiMap)
add a taz for every junction unless a taz with the same id already exists
Definition RONet.cpp:255
ROLane * getLane(const std::string &laneID) const
Retrieves a lane rom the network given its id.
Definition RONet.cpp:810
std::multimap< const SUMOTime, const std::string > ContainerMap
Known containers.
Definition RONet.h:541
int myDiscardedRouteNo
The number of discarded routes.
Definition RONet.h:566
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:149
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
Definition RONet.h:511
std::vector< const RORoutable * > myPTVehicles
vehicles to keep for public transport routing
Definition RONet.h:545
NamedObjectCont< ROEdge * > myEdges
Known edges.
Definition RONet.h:500
void addNode(RONode *node)
Definition RONet.cpp:268
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter * > *vehTypeDistribution)
Adds a vehicle type distribution.
Definition RONet.cpp:452
void addJunctionTaz(ROAbstractEdgeBuilder &eb)
add a taz for every junction unless a taz with the same id already exists
Definition RONet.cpp:219
OutputDevice * myTypesOutput
The file to write the vehicle types into.
Definition RONet.h:560
const bool myDoPTRouting
whether to calculate routes for public transport
Definition RONet.h:587
const bool myKeepVTypeDist
whether to keep the vtype distribution in output
Definition RONet.h:584
virtual ~RONet()
Destructor.
Definition RONet.cpp:113
const std::string getStoppingPlaceName(const std::string &id) const
return the name for the given stopping place id
Definition RONet.cpp:883
std::map< std::string, std::vector< SUMOTime > > myDepartures
Departure times for randomized flows.
Definition RONet.h:548
RONet & operator=(const RONet &src)
Invalidated assignment operator.
int getEdgeNumber() const
Returns the total number of edges the network contains including internal edges.
Definition RONet.cpp:792
const NamedObjectCont< ROEdge * > & getEdgeMap() const
Definition RONet.h:426
ROEdge * getEdgeForLaneID(const std::string &laneID) const
Retrieves an edge from the network when the lane id is given.
Definition RONet.cpp:804
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition RONet.cpp:501
bool hasLoadedEffort() const
whether efforts were loaded from file
Definition RONet.cpp:873
NamedObjectCont< SUMOVTypeParameter * > myVehicleTypes
Known vehicle types.
Definition RONet.h:506
bool addDistrict(const std::string id, ROEdge *source, ROEdge *sink)
Definition RONet.cpp:174
bool hasRestrictions() const
Definition RONet.h:97
Base class for nodes used by the router.
Definition RONode.h:46
A person as used by router.
Definition ROPerson.h:50
A routable thing such as a vehicle or person.
Definition RORoutable.h:52
Base class for a vehicle's route definition.
Definition RORouteDef.h:53
A vehicle as used by router.
Definition ROVehicle.h:50
Represents a generic random distribution.
Structure representing possible vehicle parameter.
Definition of vehicle stop (position and duration)
Structure representing possible vehicle parameter.
@ value
the parser finished reading a JSON value