59 throw ProcessError(
"A network was not yet constructed.");
64 myVehicleTypes(), myDefaultVTypeMayBeDeleted(true),
65 myDefaultPedTypeMayBeDeleted(true), myDefaultBikeTypeMayBeDeleted(true),
66 myHaveActiveFlows(true),
67 myRoutesOutput(nullptr), myRouteAlternativesOutput(nullptr), myTypesOutput(nullptr),
68 myReadRouteNo(0), myDiscardedRouteNo(0), myWrittenRouteNo(0),
69 myHavePermissions(false),
70 myNumInternalEdges(0),
71 myErrorHandler(
OptionsCont::getOptions().exists(
"ignore-errors")
73 myKeepVTypeDist(
OptionsCont::getOptions().exists(
"keep-vtype-distributions")
74 &&
OptionsCont::getOptions().getBool(
"keep-vtype-distributions")),
75 myHasBidiEdges(false) {
77 throw ProcessError(
"A network was already constructed.");
103 for (RoutablesMap::iterator routables =
myRoutables.begin(); routables !=
myRoutables.end(); ++routables) {
104 for (
RORoutable*
const r : routables->second) {
135 const std::map<SUMOVehicleClass, double>*
137 std::map<std::string, std::map<SUMOVehicleClass, double> >::const_iterator i =
myRestrictions.find(
id);
162 WRITE_ERROR(
"The TAZ '" +
id +
"' occurs at least twice.");
173 myDistricts[id] = std::make_pair(std::vector<std::string>(), std::vector<std::string>());
181 WRITE_ERROR(
"The TAZ '" + tazID +
"' is unknown.");
185 if (edge ==
nullptr) {
186 WRITE_ERROR(
"The edge '" + edgeID +
"' for TAZ '" + tazID +
"' is unknown.");
203 const std::string tazID = item.first;
205 WRITE_WARNINGF(
"A TAZ with id '%' already exists. Not building junction TAZ.", tazID);
208 const std::string sourceID = tazID +
"-source";
209 const std::string sinkID = tazID +
"-sink";
217 const RONode* junction = item.second;
219 if (!edge->isInternal()) {
220 const_cast<ROEdge*
>(edge)->addSuccessor(sink);
221 district.second.push_back(edge->getID());
225 if (!edge->isInternal()) {
227 district.first.push_back(edge->getID());
235 for (
const auto& item : bidiMap) {
237 if (bidi ==
nullptr) {
238 WRITE_ERROR(
"The bidi edge '" + item.second +
"' is not known.");
240 item.first->setBidiEdge(bidi);
271 if (options.
isSet(
"output-file") && options.
getString(
"output-file") !=
"") {
274 myRoutesOutput->
writeAttr(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance").
writeAttr(
"xsi:noNamespaceSchemaLocation",
"http://sumo.dlr.de/xsd/routes_file.xsd");
276 if (options.
exists(
"alternatives-output") && options.
isSet(
"alternatives-output")
277 && !(options.
exists(
"write-trips") && options.
getBool(
"write-trips"))) {
282 if (options.
isSet(
"vtype-output")) {
285 myTypesOutput->
writeAttr(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance").
writeAttr(
"xsi:noNamespaceSchemaLocation",
"http://sumo.dlr.de/xsd/routes_file.xsd");
292 if (options.
exists(
"intermodal-network-output") && options.
isSet(
"intermodal-network-output")) {
296 if (options.
exists(
"intermodal-weight-output") && options.
isSet(
"intermodal-weight-output")) {
325 if (myThreadPool.size() > 0) {
326 myThreadPool.clear();
346 if (type !=
nullptr) {
351 return it2->second->get();
393 WRITE_ERROR(
"The vehicle type '" + type->
id +
"' occurs at least twice.");
426 WRITE_ERROR(
"Another vehicle with the id '" +
id +
"' exists.");
458 WRITE_ERROR(
"Another person with the id '" + person->
getID() +
"' exists.");
465 myContainers.insert(std::pair<const SUMOTime, const std::string>(depart, desc));
472 for (
const auto& i :
myFlows) {
479 while (pars->
depart < time) {
488 for (std::vector<SUMOVehicleParameter::Stop>::iterator stop = newPars->
stops.begin(); stop != newPars->
stops.end(); ++stop) {
489 if (stop->until >= 0) {
490 stop->until += pars->
depart - origDepart;
515 if (depart >= time +
DELTA_T) {
524 for (std::vector<SUMOVehicleParameter::Stop>::iterator stop = newPars->
stops.begin(); stop != newPars->
stops.end(); ++stop) {
525 if (stop->until >= 0) {
526 stop->until += depart - pars->
depart;
532 if (type ==
nullptr) {
551 std::map<const int, std::vector<RORoutable*> > bulkVehs;
553 if (i->first >= time) {
556 for (
RORoutable*
const routable : i->second) {
561 WRITE_WARNING(
"Bulking different maximum speeds ('" + first->
getID() +
"' and '" + routable->
getID() +
"') may lead to suboptimal routes.");
564 WRITE_WARNING(
"Bulking different vehicle classes ('" + first->
getID() +
"' and '" + routable->
getID() +
"') may lead to invalid routes.");
569 for (std::map<
const int, std::vector<RORoutable*> >::const_iterator i = bulkVehs.begin(); i != bulkVehs.end(); ++i) {
571 if (myThreadPool.size() > 0) {
573 myThreadPool.add(
new RoutingTask(first, removeLoops,
myErrorHandler), workerIndex);
574 myThreadPool.add(
new BulkmodeTask(
true), workerIndex);
575 for (std::vector<RORoutable*>::const_iterator j = i->second.begin() + 1; j != i->second.end(); ++j) {
576 myThreadPool.add(
new RoutingTask(*j, removeLoops,
myErrorHandler), workerIndex);
578 myThreadPool.add(
new BulkmodeTask(
false), workerIndex);
580 if (workerIndex == (
int)myThreadPool.size()) {
586 for (std::vector<RORoutable*>::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
604 const bool removeLoops = options.
getBool(
"remove-loops");
605 const int maxNumThreads = options.
getInt(
"routing-threads");
607 if (options.
getBool(
"bulk-routing")) {
609 while ((
int)myThreadPool.size() < maxNumThreads) {
610 new WorkerThread(myThreadPool, provider);
616 if (i->first >= time) {
619 for (
RORoutable*
const routable : i->second) {
622 if (maxNumThreads > 0) {
623 const int numThreads = (int)myThreadPool.size();
624 if (numThreads == 0) {
628 new WorkerThread(myThreadPool, provider);
631 if (numThreads < maxNumThreads && myThreadPool.isFull()) {
632 new WorkerThread(myThreadPool, provider);
634 myThreadPool.add(
new RoutingTask(routable, removeLoops,
myErrorHandler));
644 myThreadPool.waitAll();
650 RoutablesMap::iterator routables =
myRoutables.begin();
652 ContainerMap::iterator container =
myContainers.begin();
655 if (routableTime >= time && containerTime >= time) {
656 lastTime =
MIN2(routableTime, containerTime);
659 const SUMOTime minTime =
MIN2(routableTime, containerTime);
660 if (routableTime == minTime) {
662 if (lastTime != routableTime && lastTime != -1) {
664 if (options.
getInt(
"stats-period") >= 0 && ((
int)routableTime % options.
getInt(
"stats-period")) == 0) {
668 lastTime = routableTime;
669 for (
const RORoutable*
const r : routables->second) {
691 if (containerTime == minTime) {
731 for (
const auto& a : stop.second->accessPos) {
737 if (i.second->line !=
"") {
739 const std::vector<SUMOVehicleParameter::Stop>* addStops =
nullptr;
775 for (
const auto& item :
myEdges) {
776 if (item.second->hasStoredEffort()) {
787 if (stop !=
nullptr) {
801 myRoutable->computeRoute(*
static_cast<WorkerThread*
>(context), myRemoveLoops, myErrorHandler);
#define WRITE_WARNINGF(...)
#define WRITE_MESSAGE(msg)
#define WRITE_WARNING(msg)
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
const int VTYPEPARS_VEHICLECLASS_SET
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_TAXI
vehicle is a taxi
@ SVC_PEDESTRIAN
pedestrian
const std::string DEFAULT_TAXITYPE_ID
const std::string DEFAULT_PEDTYPE_ID
const std::string DEFAULT_VTYPE_ID
const std::string DEFAULT_BIKETYPE_ID
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_TAG_ROUTES
root element of a route file
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_TAG_TRAIN_STOP
A train stop (alias for bus stop)
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
A thread repeatingly calculating incoming tasks.
void addCarAccess(const E *edge, SUMOVehicleClass svc, double traveltime)
Adds access edges for transfering from walking to vehicle use.
void addAccess(const std::string &stopId, const E *stopEdge, const double pos, const double length, const SumoXMLTag category, bool isAccess, double taxiWait)
Adds access edges for stopping places to the intermodal network.
@ TAXI_PICKUP_ANYWHERE
taxi customer may be picked up anywhere
void addSchedule(const SUMOVehicleParameter &pars, const std::vector< SUMOVehicleParameter::Stop > *addStops=nullptr)
Network * getNetwork() const
void writeWeights(OutputDevice &dev)
int getCarWalkTransfer() const
void writeNetwork(OutputDevice &dev)
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
const std::string & getID() const
Returns the id.
T get(const std::string &id) const
Retrieves an item.
int size() const
Returns the number of stored items within the container.
bool remove(const std::string &id, const bool del=true)
Removes an item.
bool add(const std::string &id, T item)
Adds an item.
A storage for options typed value containers)
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool exists(const std::string &name) const
Returns the information whether the named option is known.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writePreformattedTag(const std::string &val)
writes a preformatted tag to the device but ensures that any pending tags are closed
void close()
Closes the device and removes it from the dictionary.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
static bool createDeviceByOption(const std::string &optionName, const std::string &rootElement="", const std::string &schemaFile="")
Creates the device using the output definition stored in the named option.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
bool writeHeader(const SumoXMLTag &rootElement)
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
Interface for building instances of router-edges.
virtual ROEdge * buildEdge(const std::string &name, RONode *from, RONode *to, const int priority)=0
Builds an edge with the given name.
A basic edge for routing applications.
int getNumericalID() const
Returns the index (numeric id) of the edge.
void setFunction(SumoXMLEdgeFunc func)
Sets the function of the edge.
bool isInternal() const
return whether this edge is an internal edge
void setOtherTazConnector(const ROEdge *edge)
virtual void addSuccessor(ROEdge *s, ROEdge *via=nullptr, std::string dir="")
Adds information about a connected edge.
static const ROEdgeVector & getAllEdges()
Returns all ROEdges.
The router's network representation.
void createBulkRouteRequests(const RORouterProvider &provider, const SUMOTime time, const bool removeLoops)
std::set< std::string > myVehIDs
Known vehicle ids.
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
int myNumInternalEdges
The number of internal edges in the dictionary.
bool myDefaultPedTypeMayBeDeleted
Whether the default pedestrian type was already used or can still be replaced.
void setPermissionsFound()
bool myDefaultVTypeMayBeDeleted
Whether the default vehicle type was already used or can still be replaced.
void checkFlows(SUMOTime time, MsgHandler *errorHandler)
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
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.
ROEdge * getEdgeForLaneID(const std::string &laneID) const
Retrieves an edge from the network when the lane id is given.
ContainerMap myContainers
std::set< std::string > myPersonIDs
Known person ids.
std::map< std::string, std::pair< std::vector< std::string >, std::vector< std::string > > > myDistricts
traffic assignment zones with sources and sinks
bool addRouteDef(RORouteDef *def)
void addStoppingPlace(const std::string &id, const SumoXMLTag category, SUMOVehicleParameter::Stop *stop)
void cleanup()
closes the file output for computed routes and deletes associated threads if necessary
bool myHaveActiveFlows
whether any flows are still active
void openOutput(const OptionsCont &options)
Opens the output for computed routes.
NamedObjectCont< SUMOVehicleParameter * > myFlows
Known flows.
OutputDevice * myRouteAlternativesOutput
The file to write the computed route alternatives into.
bool myDefaultBikeTypeMayBeDeleted
Whether the default bicycle type was already used or can still be replaced.
RoutablesMap myRoutables
Known routables.
int getInternalEdgeNumber() const
Returns the number of internal edges the network contains.
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
bool myHasBidiEdges
whether the network contains bidirectional railway edges
bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource)
MsgHandler * myErrorHandler
handler for ignorable error messages
void writeIntermodal(const OptionsCont &options, ROIntermodalRouter &router) const
Writes the intermodal network and weights if requested.
NamedObjectCont< RONode * > myNodes
Known nodes.
void addContainer(const SUMOTime depart, const std::string desc)
static void adaptIntermodalRouter(ROIntermodalRouter &router)
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction for an edge type.
NamedObjectCont< RORouteDef * > myRoutes
Known routes.
bool furtherStored()
Returns the information whether further vehicles, persons or containers are stored.
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
OutputDevice * myRoutesOutput
The file to write the computed routes into.
bool addPerson(ROPerson *person)
int myWrittenRouteNo
The number of written routes.
static RONet * myInstance
Unique instance of RONet.
SUMOTime saveAndRemoveRoutesUntil(OptionsCont &options, const RORouterProvider &provider, SUMOTime time)
Computes routes described by their definitions and saves them.
virtual bool addEdge(ROEdge *edge)
std::map< std::string, std::map< SUMOVehicleClass, double > > myRestrictions
The vehicle class specific speed restrictions.
std::map< SumoXMLTag, NamedObjectCont< SUMOVehicleParameter::Stop * > > myStoppingPlaces
Known bus / train / container stops and parking areas.
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
bool hasPermissions() const
void setBidiEdges(const std::map< ROEdge *, std::string > &bidiMap)
add a taz for every junction unless a taz with the same id already exists
bool knowsVehicle(const std::string &id)
returns whether a vehicle with the given id was already loaded
int myDiscardedRouteNo
The number of discarded routes.
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
std::vector< const RORoutable * > myPTVehicles
vehicles to keep for public transport routing
NamedObjectCont< ROEdge * > myEdges
Known edges.
void addNode(RONode *node)
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter * > *vehTypeDistribution)
Adds a vehicle type distribution.
void addJunctionTaz(ROAbstractEdgeBuilder &eb)
add a taz for every junction unless a taz with the same id already exists
OutputDevice * myTypesOutput
The file to write the vehicle types into.
const bool myKeepVTypeDist
whether to keep the the vtype distribution in output
virtual ~RONet()
Destructor.
const std::string getStoppingPlaceName(const std::string &id) const
return the name for the given stopping place id
std::map< std::string, std::vector< SUMOTime > > myDepartures
Departure times for randomized flows.
int getEdgeNumber() const
Returns the total number of edges the network contains including internal edges.
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
bool hasLoadedEffort() const
whether efforts were loaded from file
NamedObjectCont< SUMOVTypeParameter * > myVehicleTypes
Known vehicle types.
bool addDistrict(const std::string id, ROEdge *source, ROEdge *sink)
Base class for nodes used by the router.
const ConstROEdgeVector & getIncoming() const
const ConstROEdgeVector & getOutgoing() const
A person as used by router.
A routable thing such as a vehicle or person.
bool getRoutingSuccess() const
void write(OutputDevice &os, OutputDevice *const altos, OutputDevice *const typeos, OptionsCont &options) const
Saves the routable including the vehicle type (if it was not saved before).
const SUMOVehicleParameter & getParameter() const
Returns the definition of the vehicle / person parameter.
const std::string & getID() const
Returns the id of the routable.
SUMOVehicleClass getVClass() const
bool isPublicTransport() const
bool isPartOfFlow() const
virtual void computeRoute(const RORouterProvider &provider, const bool removeLoops, MsgHandler *errorHandler)=0
SUMOTime getDepart() const
Returns the time the vehicle starts at, -1 for triggered vehicles.
virtual const ROEdge * getDepartEdge() const =0
double getMaxSpeed() const
Returns the vehicle's maximum speed.
Base class for a vehicle's route definition.
const RORoute * getFirstRoute() const
RORouteDef * copy(const std::string &id, const SUMOTime stopOffset) const
Returns a deep copy of the route definition.
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the list of stops this route contains.
A vehicle as used by router.
RORouteDef * getRouteDefinition() const
Returns the definition of the route the vehicle takes.
static double rand(std::mt19937 *rng=nullptr)
Returns a random real number in [0, 1)
SUMOAbstractRouter< E, V > & getVehicleRouter(SUMOVehicleClass svc) const
Structure representing possible vehicle parameter.
bool onlyReferenced
Information whether this is a type-stub, being only referenced but not defined (needed by routers)
int parametersSet
Information for the router which parameter were set.
std::string id
The vehicle type's id.
Definition of vehicle stop (position and duration)
std::string busstop
(Optional) bus stop if one is assigned to the stop
Structure representing possible vehicle parameter.
double repetitionProbability
The probability for emitting a vehicle per second.
std::string vtypeid
The vehicle's type id.
SUMOTime repetitionOffset
The time offset between vehicle reinsertions.
int repetitionsDone
The number of times the vehicle was already inserted.
SUMOTime repetitionEnd
The time at which the flow ends (only needed when using repetitionProbability)
std::string routeid
The vehicle's route id.
std::string id
The vehicle's id.
std::vector< Stop > stops
List of the stops the vehicle will make, TraCI may add entries here.