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 double getPreference(const std::string& routingType, const SUMOVTypeParameter& pars) const;
103
105 void addPreference(const std::string& routingType, SUMOVehicleClass svc, double prio);
107 void addPreference(const std::string& routingType, std::string vType, double prio);
108
110
111
112 /* @brief Adds a read edge to the network
113 *
114 * If the edge is already known (another one with the same id exists),
115 * an error is generated and given to msg-error-handler. The edge
116 * is deleted in this case and false is returned.
117 *
118 * @param[in] edge The edge to add
119 * @return Whether the edge was added (if not, it was deleted, too)
120 */
121 virtual bool addEdge(ROEdge* edge);
122
123
124 /* @brief Adds a district and connecting edges to the network
125 *
126 * If the district is already known (another one with the same id exists),
127 * an error is generated and given to msg-error-handler. The edges
128 * are deleted in this case and false is returned.
129 *
130 * @param[in] id The district to add
131 * @return Whether the district was added
132 */
133 bool addDistrict(const std::string id, ROEdge* source, ROEdge* sink);
134
135
136 /* @brief Adds a district and connecting edges to the network
137 *
138 * If the district is already known (another one with the same id exists),
139 * an error is generated and given to msg-error-handler. The edges
140 * are deleted in this case and false is returned.
141 *
142 * @param[in] id The district to add
143 * @return Whether the district was added
144 */
145 bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource);
146
149
151 void setBidiEdges(const std::map<ROEdge*, std::string>& bidiMap);
152
157 const std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > >& getDistricts() const {
158 return myDistricts;
159 }
160
169 ROEdge* getEdge(const std::string& name) const {
170 return myEdges.get(name);
171 }
172
173
179 ROEdge* getEdgeForLaneID(const std::string& laneID) const;
180
186 ROLane* getLane(const std::string& laneID) const;
187
188 /* @brief Adds a read node to the network
189 *
190 * If the node is already known (another one with the same id exists),
191 * an error is generated and given to msg-error-handler. The node
192 * is deleted in this case
193 *
194 * @param[in] node The node to add
195 */
196 void addNode(RONode* node);
197
198
205 RONode* getNode(const std::string& id) const {
206 return myNodes.get(id);
207 }
208
209
210 /* @brief Adds a read stopping place (bus, train, container, parking) to the network
211 *
212 * If the place is already known (another one with the same id and category exists),
213 * an error is generated and given to msg-error-handler. The stop
214 * is deleted in this case
215 *
216 * @param[in] id The name of the stop to add
217 * @param[in] category The type of stop
218 * @param[in] stop The detailed stop description
219 */
220 void addStoppingPlace(const std::string& id, const SumoXMLTag category, SUMOVehicleParameter::Stop* stop);
221
228 const SUMOVehicleParameter::Stop* getStoppingPlace(const std::string& id, const SumoXMLTag category) const {
229 if (myStoppingPlaces.count(category) > 0) {
230 return myStoppingPlaces.find(category)->second.get(id);
231 }
232 return 0;
233 }
234
236 const std::string getStoppingPlaceName(const std::string& id) const;
237
239 const std::string getStoppingPlaceElement(const std::string& id) const;
241
242
243
245
246
253 bool checkVType(const std::string& id);
254
255
265 virtual bool addVehicleType(SUMOVTypeParameter* type);
266
267
281 bool addVTypeDistribution(const std::string& id, RandomDistributor<SUMOVTypeParameter*>* vehTypeDistribution);
282
283
293 const auto it = myVTypeDistDict.find(id);
294 return it != myVTypeDistDict.end() ? it ->second : nullptr;
295 }
296
297
307 SUMOVTypeParameter* getVehicleTypeSecure(const std::string& id);
308
309
310 /* @brief Adds a route definition to the network
311 *
312 * If the route definition is already known (another one with
313 * the same id exists), false is returned, but the route definition
314 * is not deleted.
315 *
316 * @param[in] def The route definition to add
317 * @return Whether the route definition could be added
318 * @todo Rename myRoutes to myRouteDefinitions
319 */
320 bool addRouteDef(RORouteDef* def);
321
322
330 RORouteDef* getRouteDef(const std::string& name) const {
331 return myRoutes.get(name);
332 }
333
334
335 /* @brief Adds a vehicle to the network
336 *
337 * If the vehicle is already known (another one with the same id
338 * exists), false is returned, but the vehicle is not deleted.
339 *
340 * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
341 *
342 * @param[in] id The id of the vehicle to add
343 * @param[in] veh The vehicle to add
344 * @return Whether the vehicle could be added
345 */
346 virtual bool addVehicle(const std::string& id, ROVehicle* veh);
347
349 bool knowsVehicle(const std::string& id) const;
350
352 SUMOTime getDeparture(const std::string& vehID) const;
353
354 /* @brief Adds a flow of vehicles to the network
355 *
356 * If the flow is already known (another one with the same id
357 * exists), false is returned, but the vehicle parameter are not deleted.
358 *
359 * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
360 *
361 * @param[in] flow The parameter of the flow to add
362 * @return Whether the flow could be added
363 */
364 bool addFlow(SUMOVehicleParameter* flow, const bool randomize);
365
366
367 /* @brief Adds a person to the network
368 *
369 * @param[in] person The person to add
370 */
371 bool addPerson(ROPerson* person);
372
373
374 /* @brief Adds a container to the network
375 *
376 * @param[in] depart The departure time of the container
377 * @param[in] desc The xml description of the container
378 */
379 void addContainer(const SUMOTime depart, const std::string desc);
380 // @}
381
382
384
385
398 const RORouterProvider& provider, SUMOTime time);
399
400
402 bool furtherStored();
404
405
412 void openOutput(const OptionsCont& options);
413
414
421 void writeIntermodal(const OptionsCont& options, ROIntermodalRouter& router) const;
422
423
425 void cleanup();
426
427
429 int getEdgeNumber() const;
430
432 int getInternalEdgeNumber() const;
433
435 return myEdges;
436 }
437
438 static void adaptIntermodalRouter(ROIntermodalRouter& router);
439
440 bool hasPermissions() const;
441
442 void setPermissionsFound();
443
445 bool hasBidiEdges() const {
446 return myHasBidiEdges;
447 }
448
450 bool hasLoadedEffort() const;
451
452 OutputDevice* getRouteOutput(const bool alternative = false) {
453 if (alternative) {
455 }
456 return myRoutesOutput;
457 }
458
459#ifdef HAVE_FOX
460 MFXWorkerThread::Pool& getThreadPool() {
461 return myThreadPool;
462 }
463
464 class WorkerThread : public MFXWorkerThread, public RORouterProvider {
465 public:
466 WorkerThread(MFXWorkerThread::Pool& pool,
467 const RORouterProvider& original)
468 : MFXWorkerThread(pool), RORouterProvider(original) {}
469 virtual ~WorkerThread() {
470 stop();
471 }
472 };
473
474 class BulkmodeTask : public MFXWorkerThread::Task {
475 public:
476 BulkmodeTask(const bool value) : myValue(value) {}
477 void run(MFXWorkerThread* context) {
478 static_cast<WorkerThread*>(context)->setBulkMode(myValue);
479 }
480 private:
481 const bool myValue;
482 private:
484 BulkmodeTask& operator=(const BulkmodeTask&);
485 };
486#endif
487
488
489private:
490 void checkFlows(SUMOTime time, MsgHandler* errorHandler);
491
492 void createBulkRouteRequests(const RORouterProvider& provider, const SUMOTime time, const bool removeLoops);
493
494private:
497
499 std::map<std::string, SUMOTime> myVehIDs;
500
502 std::set<std::string> myPersonIDs;
503
506
509
511 std::map<SumoXMLTag, NamedObjectCont<SUMOVehicleParameter::Stop*> > myStoppingPlaces;
512
515
517 typedef std::map< std::string, RandomDistributor<SUMOVTypeParameter*>* > VTypeDistDictType;
520
523
526
529
532
535
538
541
544
547
549 typedef std::multimap<const SUMOTime, const std::string> ContainerMap;
551
553 std::vector<const RORoutable*> myPTVehicles;
554
556 std::map<std::string, std::vector<SUMOTime> > myDepartures;
557
559 std::map<std::string, std::pair<std::vector<std::string>, std::vector<std::string> > > myDistricts;
560
563
566
569
572
575
578
581
583 std::map<std::string, std::map<SUMOVehicleClass, double> > myRestrictions;
584
586 std::map<SUMOVehicleClass, std::map<std::string, double> > myVClassPreferences;
587 std::map<std::string, std::map<std::string, double> > myVTypePreferences;
588
591
594
596 const bool myKeepVTypeDist;
597
599 const bool myDoPTRouting;
600
602 const bool myKeepFlows;
603
606
607#ifdef HAVE_FOX
608private:
609 class RoutingTask : public MFXWorkerThread::Task {
610 public:
611 RoutingTask(RORoutable* v, const bool removeLoops, MsgHandler* errorHandler)
612 : myRoutable(v), myRemoveLoops(removeLoops), myErrorHandler(errorHandler) {}
613 void run(MFXWorkerThread* context);
614 private:
615 RORoutable* const myRoutable;
616 const bool myRemoveLoops;
617 MsgHandler* const myErrorHandler;
618 private:
620 RoutingTask& operator=(const RoutingTask&);
621 };
622
623
624private:
626 MFXWorkerThread::Pool myThreadPool;
627#endif
628
629private:
631 RONet(const RONet& src);
632
634 RONet& operator=(const RONet& src);
635
636};
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:687
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition RONet.cpp:408
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:590
bool myDefaultPedTypeMayBeDeleted
Whether the default pedestrian type was already used or can still be replaced.
Definition RONet.h:525
bool hasBidiEdges() const
return whether the network contains bidirectional rail edges
Definition RONet.h:445
void setPermissionsFound()
Definition RONet.cpp:932
bool myDefaultRailTypeMayBeDeleted
Whether the default rail type was already used or can still be replaced.
Definition RONet.h:534
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:522
void checkFlows(SUMOTime time, MsgHandler *errorHandler)
Definition RONet.cpp:584
std::map< SUMOVehicleClass, std::map< std::string, double > > myVClassPreferences
Preferences for routing.
Definition RONet.h:586
RONode * getNode(const std::string &id) const
Retrieves an node from the network.
Definition RONet.h:205
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:197
std::map< std::string, RandomDistributor< SUMOVTypeParameter * > * > VTypeDistDictType
Vehicle type distribution dictionary type.
Definition RONet.h:517
const RandomDistributor< SUMOVTypeParameter * > * getVTypeDistribution(const std::string &id)
Retrieves the named vehicle type distribution.
Definition RONet.h:292
double getPreference(const std::string &routingType, const SUMOVTypeParameter &pars) const
retriefe edge type specific routing preference
Definition RONet.cpp:152
ContainerMap myContainers
Definition RONet.h:550
std::set< std::string > myPersonIDs
Known person ids.
Definition RONet.h:502
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:559
bool addRouteDef(RORouteDef *def)
Definition RONet.cpp:333
int myReadRouteNo
The number of read routes.
Definition RONet.h:571
void addStoppingPlace(const std::string &id, const SumoXMLTag category, SUMOVehicleParameter::Stop *stop)
Definition RONet.cpp:324
bool knowsVehicle(const std::string &id) const
returns whether a vehicle with the given id was already loaded
Definition RONet.cpp:532
void cleanup()
closes the file output for computed routes and deletes associated threads if necessary
Definition RONet.cpp:384
bool myHaveActiveFlows
whether any flows are still active
Definition RONet.h:546
RONet(const RONet &src)
Invalidated copy constructor.
std::map< std::string, SUMOTime > myVehIDs
Known vehicle ids and their departure.
Definition RONet.h:499
void openOutput(const OptionsCont &options)
Opens the output for computed routes.
Definition RONet.cpp:339
NamedObjectCont< SUMOVehicleParameter * > myFlows
Known flows.
Definition RONet.h:543
OutputDevice * myRouteAlternativesOutput
The file to write the computed route alternatives into.
Definition RONet.h:565
bool myDefaultBikeTypeMayBeDeleted
Whether the default bicycle type was already used or can still be replaced.
Definition RONet.h:528
RoutablesMap myRoutables
Known routables.
Definition RONet.h:540
int getInternalEdgeNumber() const
Returns the number of internal edges the network contains.
Definition RONet.cpp:862
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
Definition RONet.cpp:510
SUMOTime getDeparture(const std::string &vehID) const
returns departure time for the given vehicle id
Definition RONet.cpp:537
OutputDevice * getRouteOutput(const bool alternative=false)
Definition RONet.h:452
bool myHasBidiEdges
whether the network contains bidirectional railway edges
Definition RONet.h:605
bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource)
Definition RONet.cpp:244
MsgHandler * myErrorHandler
handler for ignorable error messages
Definition RONet.h:593
void writeIntermodal(const OptionsCont &options, ROIntermodalRouter &router) const
Writes the intermodal network and weights if requested.
Definition RONet.cpp:365
RONet()
Constructor.
Definition RONet.cpp:64
NamedObjectCont< RONode * > myNodes
Known nodes.
Definition RONet.h:505
const std::string getStoppingPlaceElement(const std::string &id) const
return the element name for the given stopping place id
Definition RONet.cpp:959
const SUMOVehicleParameter::Stop * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Retrieves a stopping place from the network.
Definition RONet.h:228
void addContainer(const SUMOTime depart, const std::string desc)
Definition RONet.cpp:578
static void adaptIntermodalRouter(ROIntermodalRouter &router)
Definition RONet.cpp:881
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition RONet.h:169
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction for an edge type.
Definition RONet.cpp:146
NamedObjectCont< RORouteDef * > myRoutes
Known routes.
Definition RONet.h:537
bool furtherStored()
Returns the information whether further vehicles, persons or containers are stored.
Definition RONet.cpp:850
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
Definition RONet.cpp:440
OutputDevice * myRoutesOutput
The file to write the computed routes into.
Definition RONet.h:562
bool addPerson(ROPerson *person)
Definition RONet.cpp:566
int myWrittenRouteNo
The number of written routes.
Definition RONet.h:577
static RONet * myInstance
Unique instance of RONet.
Definition RONet.h:496
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
Definition RONet.h:330
SUMOTime saveAndRemoveRoutesUntil(OptionsCont &options, const RORouterProvider &provider, SUMOTime time)
Computes routes described by their definitions and saves them.
Definition RONet.cpp:737
virtual bool addEdge(ROEdge *edge)
Definition RONet.cpp:207
bool myDefaultTaxiTypeMayBeDeleted
Whether the default taxi type was already used or can still be replaced.
Definition RONet.h:531
std::map< std::string, std::map< SUMOVehicleClass, double > > myRestrictions
The vehicle class specific speed restrictions.
Definition RONet.h:583
std::map< SumoXMLTag, NamedObjectCont< SUMOVehicleParameter::Stop * > > myStoppingPlaces
Known bus / train / container stops and parking areas.
Definition RONet.h:511
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
Definition RONet.cpp:486
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
Definition RONet.h:580
bool hasPermissions() const
Definition RONet.cpp:926
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:302
ROLane * getLane(const std::string &laneID) const
Retrieves a lane rom the network given its id.
Definition RONet.cpp:874
std::multimap< const SUMOTime, const std::string > ContainerMap
Known containers.
Definition RONet.h:549
int myDiscardedRouteNo
The number of discarded routes.
Definition RONet.h:574
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:157
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
Definition RONet.h:519
std::vector< const RORoutable * > myPTVehicles
vehicles to keep for public transport routing
Definition RONet.h:553
NamedObjectCont< ROEdge * > myEdges
Known edges.
Definition RONet.h:508
void addNode(RONode *node)
Definition RONet.cpp:315
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter * > *vehTypeDistribution)
Adds a vehicle type distribution.
Definition RONet.cpp:499
void addJunctionTaz(ROAbstractEdgeBuilder &eb)
add a taz for every junction unless a taz with the same id already exists
Definition RONet.cpp:266
OutputDevice * myTypesOutput
The file to write the vehicle types into.
Definition RONet.h:568
const bool myKeepFlows
whether to preserve flows
Definition RONet.h:602
const bool myDoPTRouting
whether to calculate routes for public transport
Definition RONet.h:599
const bool myKeepVTypeDist
whether to keep the vtype distribution in output
Definition RONet.h:596
virtual ~RONet()
Destructor.
Definition RONet.cpp:115
const std::string getStoppingPlaceName(const std::string &id) const
return the name for the given stopping place id
Definition RONet.cpp:947
std::map< std::string, std::vector< SUMOTime > > myDepartures
Departure times for randomized flows.
Definition RONet.h:556
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:856
const NamedObjectCont< ROEdge * > & getEdgeMap() const
Definition RONet.h:434
ROEdge * getEdgeForLaneID(const std::string &laneID) const
Retrieves an edge from the network when the lane id is given.
Definition RONet.cpp:868
std::map< std::string, std::map< std::string, double > > myVTypePreferences
Definition RONet.h:587
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition RONet.cpp:548
bool hasLoadedEffort() const
whether efforts were loaded from file
Definition RONet.cpp:937
void addPreference(const std::string &routingType, SUMOVehicleClass svc, double prio)
add edge type specific routing preference
Definition RONet.cpp:182
NamedObjectCont< SUMOVTypeParameter * > myVehicleTypes
Known vehicle types.
Definition RONet.h:514
bool addDistrict(const std::string id, ROEdge *source, ROEdge *sink)
Definition RONet.cpp:221
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