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 typedef std::map<const ROEdge*, RouterProhibition> Prohibitions;
68
70 RONet();
71
72
76 static RONet* getInstance();
77
78
80 virtual ~RONet();
81
82
88 void addSpeedRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed);
89
90
96 const std::map<SUMOVehicleClass, double>* getRestrictions(const std::string& id) const;
97
98 bool hasSpeedRestrictions() const {
99 return !mySpeedRestrictions.empty();
100 }
101
102 bool hasParamRestrictions() const {
104 }
105
109
111 double getPreference(const std::string& routingType, const SUMOVTypeParameter& pars) const;
112
114 void addPreference(const std::string& routingType, SUMOVehicleClass svc, double prio);
116 void addPreference(const std::string& routingType, std::string vType, double prio);
117
119
120
121 /* @brief Adds a read edge to the network
122 *
123 * If the edge is already known (another one with the same id exists),
124 * an error is generated and given to msg-error-handler. The edge
125 * is deleted in this case and false is returned.
126 *
127 * @param[in] edge The edge to add
128 * @return Whether the edge was added (if not, it was deleted, too)
129 */
130 virtual bool addEdge(ROEdge* edge);
131
132
133 /* @brief Adds a district and connecting edges to the network
134 *
135 * If the district is already known (another one with the same id exists),
136 * an error is generated and given to msg-error-handler. The edges
137 * are deleted in this case and false is returned.
138 *
139 * @param[in] id The district to add
140 * @return Whether the district was added
141 */
142 bool addDistrict(const std::string id, ROEdge* source, ROEdge* sink);
143
144
145 /* @brief Adds a district and connecting edges to the network
146 *
147 * If the district is already known (another one with the same id exists),
148 * an error is generated and given to msg-error-handler. The edges
149 * are deleted in this case and false is returned.
150 *
151 * @param[in] id The district to add
152 * @return Whether the district was added
153 */
154 bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource);
155
158
160 void setBidiEdges(const std::map<ROEdge*, std::string>& bidiMap);
161
166 const std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > >& getDistricts() const {
167 return myDistricts;
168 }
169
178 ROEdge* getEdge(const std::string& name) const {
179 return myEdges.get(name);
180 }
181
182
188 ROEdge* getEdgeForLaneID(const std::string& laneID) const;
189
195 ROLane* getLane(const std::string& laneID) const;
196
197 /* @brief Adds a read node to the network
198 *
199 * If the node is already known (another one with the same id exists),
200 * an error is generated and given to msg-error-handler. The node
201 * is deleted in this case
202 *
203 * @param[in] node The node to add
204 */
205 void addNode(RONode* node);
206
207
214 RONode* getNode(const std::string& id) const {
215 return myNodes.get(id);
216 }
217
218
219 /* @brief Adds a read stopping place (bus, train, container, parking) to the network
220 *
221 * If the place is already known (another one with the same id and category exists),
222 * an error is generated and given to msg-error-handler. The stop
223 * is deleted in this case
224 *
225 * @param[in] id The name of the stop to add
226 * @param[in] category The type of stop
227 * @param[in] stop The detailed stop description
228 */
229 void addStoppingPlace(const std::string& id, const SumoXMLTag category, SUMOVehicleParameter::Stop* stop);
230
237 const SUMOVehicleParameter::Stop* getStoppingPlace(const std::string& id, const SumoXMLTag category) const {
238 if (myStoppingPlaces.count(category) > 0) {
239 return myStoppingPlaces.find(category)->second.get(id);
240 }
241 return 0;
242 }
243
245 const std::string getStoppingPlaceName(const std::string& id) const;
246
248 const std::string getStoppingPlaceElement(const std::string& id) const;
250
251
252
254
255
262 bool checkVType(const std::string& id);
263
264
274 virtual bool addVehicleType(SUMOVTypeParameter* type);
275
276
290 bool addVTypeDistribution(const std::string& id, RandomDistributor<SUMOVTypeParameter*>* vehTypeDistribution);
291
292
302 const auto it = myVTypeDistDict.find(id);
303 return it != myVTypeDistDict.end() ? it ->second : nullptr;
304 }
305
306
316 SUMOVTypeParameter* getVehicleTypeSecure(const std::string& id);
317
318
319 /* @brief Adds a route definition to the network
320 *
321 * If the route definition is already known (another one with
322 * the same id exists), false is returned, but the route definition
323 * is not deleted.
324 *
325 * @param[in] def The route definition to add
326 * @return Whether the route definition could be added
327 * @todo Rename myRoutes to myRouteDefinitions
328 */
329 bool addRouteDef(RORouteDef* def);
330
331
339 RORouteDef* getRouteDef(const std::string& name) const {
340 return myRoutes.get(name);
341 }
342
343
344 /* @brief Adds a vehicle to the network
345 *
346 * If the vehicle is already known (another one with the same id
347 * exists), false is returned, but the vehicle is not deleted.
348 *
349 * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
350 *
351 * @param[in] id The id of the vehicle to add
352 * @param[in] veh The vehicle to add
353 * @return Whether the vehicle could be added
354 */
355 virtual bool addVehicle(const std::string& id, ROVehicle* veh);
356
358 bool knowsVehicle(const std::string& id) const;
359
361 SUMOTime getDeparture(const std::string& vehID) const;
362
363 /* @brief Adds a flow of vehicles to the network
364 *
365 * If the flow is already known (another one with the same id
366 * exists), false is returned, but the vehicle parameter are not deleted.
367 *
368 * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
369 *
370 * @param[in] flow The parameter of the flow to add
371 * @return Whether the flow could be added
372 */
373 bool addFlow(SUMOVehicleParameter* flow, const bool randomize);
374
375
376 /* @brief Adds a person to the network
377 *
378 * @param[in] person The person to add
379 */
380 bool addPerson(ROPerson* person);
381
382
383 /* @brief Adds a container to the network
384 *
385 * @param[in] depart The departure time of the container
386 * @param[in] desc The xml description of the container
387 */
388 void addContainer(const SUMOTime depart, const std::string desc);
389 // @}
390
391
393
394
407 const RORouterProvider& provider, SUMOTime time);
408
409
411 bool furtherStored();
413
414
421 void openOutput(const OptionsCont& options);
422
423
430 void writeIntermodal(const OptionsCont& options, ROIntermodalRouter& router) const;
431
432
434 void cleanup();
435
436
438 int getEdgeNumber() const;
439
441 int getInternalEdgeNumber() const;
442
444 return myEdges;
445 }
446
447 static void adaptIntermodalRouter(ROIntermodalRouter& router);
448
449 bool hasPermissions() const;
450
451 void setPermissionsFound();
452
454 bool hasBidiEdges() const {
455 return myHasBidiEdges;
456 }
457
459 bool hasLoadedEffort() const;
460
462 return myMaxTraveltime;
463 }
464
466 return myProhibitions;
467 }
468
469 void addProhibition(const ROEdge* edge, const RouterProhibition& prohibition);
470
471 OutputDevice* getRouteOutput(const bool alternative = false) {
472 if (alternative) {
474 }
475 return myRoutesOutput;
476 }
477
478#ifdef HAVE_FOX
479 MFXWorkerThread::Pool& getThreadPool() {
480 return myThreadPool;
481 }
482
483 class WorkerThread : public MFXWorkerThread, public RORouterProvider {
484 public:
485 WorkerThread(MFXWorkerThread::Pool& pool,
486 const RORouterProvider& original)
487 : MFXWorkerThread(pool), RORouterProvider(original) {}
488 virtual ~WorkerThread() {
489 stop();
490 }
491 };
492
493 class BulkmodeTask : public MFXWorkerThread::Task {
494 public:
495 BulkmodeTask(const bool value) : myValue(value) {}
496 void run(MFXWorkerThread* context) {
497 static_cast<WorkerThread*>(context)->setBulkMode(myValue);
498 }
499 private:
500 const bool myValue;
501 private:
503 BulkmodeTask& operator=(const BulkmodeTask&);
504 };
505#endif
506
507
508private:
509 void checkFlows(SUMOTime time, MsgHandler* errorHandler);
510
511 void createBulkRouteRequests(const RORouterProvider& provider, const SUMOTime time, const bool removeLoops);
512
513private:
516
518 std::map<std::string, SUMOTime> myVehIDs;
519
521 std::set<std::string> myPersonIDs;
522
525
528
530 std::map<SumoXMLTag, NamedObjectCont<SUMOVehicleParameter::Stop*> > myStoppingPlaces;
531
534
536 typedef std::map< std::string, RandomDistributor<SUMOVTypeParameter*>* > VTypeDistDictType;
539
542
545
548
551
554
557
560
563
566
568 typedef std::multimap<const SUMOTime, const std::string> ContainerMap;
570
572 std::vector<const RORoutable*> myPTVehicles;
573
575 std::map<std::string, std::vector<SUMOTime> > myDepartures;
576
578 std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > > myDistricts;
579
582
585
588
591
594
597
600
602 std::map<std::string, std::map<SUMOVehicleClass, double> > mySpeedRestrictions;
603
606
608 std::map<SUMOVehicleClass, std::map<std::string, double> > myVClassPreferences;
609 std::map<std::string, std::map<std::string, double> > myVTypePreferences;
610
613
616
618 const bool myKeepVTypeDist;
619
621 const bool myDoPTRouting;
622
624 const bool myKeepFlows;
625
628
631
634
635#ifdef HAVE_FOX
636private:
637 class RoutingTask : public MFXWorkerThread::Task {
638 public:
639 RoutingTask(RORoutable* v, const bool removeLoops, MsgHandler* errorHandler)
640 : myRoutable(v), myRemoveLoops(removeLoops), myErrorHandler(errorHandler) {}
641 void run(MFXWorkerThread* context);
642 private:
643 RORoutable* const myRoutable;
644 const bool myRemoveLoops;
645 MsgHandler* const myErrorHandler;
646 private:
648 RoutingTask& operator=(const RoutingTask&);
649 };
650
651
652private:
654 MFXWorkerThread::Pool myThreadPool;
655#endif
656
657private:
659 RONet(const RONet& src);
660
662 RONet& operator=(const RONet& src);
663
664};
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:73
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:690
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition RONet.cpp:411
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:612
bool myDefaultPedTypeMayBeDeleted
Whether the default pedestrian type was already used or can still be replaced.
Definition RONet.h:544
bool hasBidiEdges() const
return whether the network contains bidirectional rail edges
Definition RONet.h:454
void setPermissionsFound()
Definition RONet.cpp:940
bool myDefaultRailTypeMayBeDeleted
Whether the default rail type was already used or can still be replaced.
Definition RONet.h:553
std::map< const ROEdge *, RouterProhibition > Prohibitions
Definition RONet.h:67
std::map< std::string, std::map< SUMOVehicleClass, double > > mySpeedRestrictions
The vehicle class specific speed restrictions.
Definition RONet.h:602
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:541
void checkFlows(SUMOTime time, MsgHandler *errorHandler)
Definition RONet.cpp:587
double myMaxTraveltime
the maximum traveltime beyond which routing is considered a failure
Definition RONet.h:630
std::map< SUMOVehicleClass, std::map< std::string, double > > myVClassPreferences
Preferences for routing.
Definition RONet.h:608
RONode * getNode(const std::string &id) const
Retrieves an node from the network.
Definition RONet.h:214
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:200
std::map< std::string, RandomDistributor< SUMOVTypeParameter * > * > VTypeDistDictType
Vehicle type distribution dictionary type.
Definition RONet.h:536
const RandomDistributor< SUMOVTypeParameter * > * getVTypeDistribution(const std::string &id)
Retrieves the named vehicle type distribution.
Definition RONet.h:301
double getPreference(const std::string &routingType, const SUMOVTypeParameter &pars) const
retriefe edge type specific routing preference
Definition RONet.cpp:155
ContainerMap myContainers
Definition RONet.h:569
std::set< std::string > myPersonIDs
Known person ids.
Definition RONet.h:521
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:578
bool addRouteDef(RORouteDef *def)
Definition RONet.cpp:336
int myReadRouteNo
The number of read routes.
Definition RONet.h:590
void addStoppingPlace(const std::string &id, const SumoXMLTag category, SUMOVehicleParameter::Stop *stop)
Definition RONet.cpp:327
bool knowsVehicle(const std::string &id) const
returns whether a vehicle with the given id was already loaded
Definition RONet.cpp:535
void cleanup()
closes the file output for computed routes and deletes associated threads if necessary
Definition RONet.cpp:387
bool myHaveActiveFlows
whether any flows are still active
Definition RONet.h:565
RONet(const RONet &src)
Invalidated copy constructor.
std::map< std::string, SUMOTime > myVehIDs
Known vehicle ids and their departure.
Definition RONet.h:518
void openOutput(const OptionsCont &options)
Opens the output for computed routes.
Definition RONet.cpp:342
NamedObjectCont< SUMOVehicleParameter * > myFlows
Known flows.
Definition RONet.h:562
OutputDevice * myRouteAlternativesOutput
The file to write the computed route alternatives into.
Definition RONet.h:584
bool myDefaultBikeTypeMayBeDeleted
Whether the default bicycle type was already used or can still be replaced.
Definition RONet.h:547
RoutablesMap myRoutables
Known routables.
Definition RONet.h:559
int getInternalEdgeNumber() const
Returns the number of internal edges the network contains.
Definition RONet.cpp:870
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
Definition RONet.cpp:513
SUMOTime getDeparture(const std::string &vehID) const
returns departure time for the given vehicle id
Definition RONet.cpp:540
OutputDevice * getRouteOutput(const bool alternative=false)
Definition RONet.h:471
bool myHasBidiEdges
whether the network contains bidirectional railway edges
Definition RONet.h:627
bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource)
Definition RONet.cpp:247
void addSpeedRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction for an edge type.
Definition RONet.cpp:149
MsgHandler * myErrorHandler
handler for ignorable error messages
Definition RONet.h:615
void writeIntermodal(const OptionsCont &options, ROIntermodalRouter &router) const
Writes the intermodal network and weights if requested.
Definition RONet.cpp:368
RONet()
Constructor.
Definition RONet.cpp:64
NamedObjectCont< RONode * > myNodes
Known nodes.
Definition RONet.h:524
const std::string getStoppingPlaceElement(const std::string &id) const
return the element name for the given stopping place id
Definition RONet.cpp:967
const SUMOVehicleParameter::Stop * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Retrieves a stopping place from the network.
Definition RONet.h:237
void addContainer(const SUMOTime depart, const std::string desc)
Definition RONet.cpp:581
bool hasParamRestrictions() const
Definition RONet.h:102
void addProhibition(const ROEdge *edge, const RouterProhibition &prohibition)
Definition RONet.cpp:980
static void adaptIntermodalRouter(ROIntermodalRouter &router)
Definition RONet.cpp:889
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition RONet.h:178
NamedObjectCont< RORouteDef * > myRoutes
Known routes.
Definition RONet.h:556
bool hasSpeedRestrictions() const
Definition RONet.h:98
bool furtherStored()
Returns the information whether further vehicles, persons or containers are stored.
Definition RONet.cpp:858
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
Definition RONet.cpp:443
OutputDevice * myRoutesOutput
The file to write the computed routes into.
Definition RONet.h:581
bool addPerson(ROPerson *person)
Definition RONet.cpp:569
int myWrittenRouteNo
The number of written routes.
Definition RONet.h:596
static RONet * myInstance
Unique instance of RONet.
Definition RONet.h:515
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
Definition RONet.h:339
void setParamRestrictions()
Definition RONet.h:106
SUMOTime saveAndRemoveRoutesUntil(OptionsCont &options, const RORouterProvider &provider, SUMOTime time)
Computes routes described by their definitions and saves them.
Definition RONet.cpp:745
virtual bool addEdge(ROEdge *edge)
Definition RONet.cpp:210
bool myDefaultTaxiTypeMayBeDeleted
Whether the default taxi type was already used or can still be replaced.
Definition RONet.h:550
std::map< SumoXMLTag, NamedObjectCont< SUMOVehicleParameter::Stop * > > myStoppingPlaces
Known bus / train / container stops and parking areas.
Definition RONet.h:530
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
Definition RONet.cpp:489
bool myHaveParamRestrictions
whether parameter-based access restrictions are configured
Definition RONet.h:605
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
Definition RONet.h:599
bool hasPermissions() const
Definition RONet.cpp:934
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:305
ROLane * getLane(const std::string &laneID) const
Retrieves a lane rom the network given its id.
Definition RONet.cpp:882
std::multimap< const SUMOTime, const std::string > ContainerMap
Known containers.
Definition RONet.h:568
int myDiscardedRouteNo
The number of discarded routes.
Definition RONet.h:593
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:166
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
Definition RONet.h:538
std::vector< const RORoutable * > myPTVehicles
vehicles to keep for public transport routing
Definition RONet.h:572
NamedObjectCont< ROEdge * > myEdges
Known edges.
Definition RONet.h:527
void addNode(RONode *node)
Definition RONet.cpp:318
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter * > *vehTypeDistribution)
Adds a vehicle type distribution.
Definition RONet.cpp:502
void addJunctionTaz(ROAbstractEdgeBuilder &eb)
add a taz for every junction unless a taz with the same id already exists
Definition RONet.cpp:269
OutputDevice * myTypesOutput
The file to write the vehicle types into.
Definition RONet.h:587
const Prohibitions & getProhibitions() const
Definition RONet.h:465
SUMOTime getMaxTraveltime() const
Definition RONet.h:461
const bool myKeepFlows
whether to preserve flows
Definition RONet.h:624
const bool myDoPTRouting
whether to calculate routes for public transport
Definition RONet.h:621
Prohibitions myProhibitions
temporary edge closing (rerouters)
Definition RONet.h:633
const bool myKeepVTypeDist
whether to keep the vtype distribution in output
Definition RONet.h:618
virtual ~RONet()
Destructor.
Definition RONet.cpp:118
const std::string getStoppingPlaceName(const std::string &id) const
return the name for the given stopping place id
Definition RONet.cpp:955
std::map< std::string, std::vector< SUMOTime > > myDepartures
Departure times for randomized flows.
Definition RONet.h:575
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:864
const NamedObjectCont< ROEdge * > & getEdgeMap() const
Definition RONet.h:443
ROEdge * getEdgeForLaneID(const std::string &laneID) const
Retrieves an edge from the network when the lane id is given.
Definition RONet.cpp:876
std::map< std::string, std::map< std::string, double > > myVTypePreferences
Definition RONet.h:609
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition RONet.cpp:551
bool hasLoadedEffort() const
whether efforts were loaded from file
Definition RONet.cpp:945
void addPreference(const std::string &routingType, SUMOVehicleClass svc, double prio)
add edge type specific routing preference
Definition RONet.cpp:185
NamedObjectCont< SUMOVTypeParameter * > myVehicleTypes
Known vehicle types.
Definition RONet.h:533
bool addDistrict(const std::string id, ROEdge *source, ROEdge *sink)
Definition RONet.cpp:224
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:53
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
Prohibitions and their estimated end time.