51 #ifdef CHECK_MEMORY_LEAKS 53 #endif // CHECK_MEMORY_LEAKS 70 throw ProcessError(
"A network was not yet constructed.");
83 throw ProcessError(
"A network was already constructed.");
111 const std::map<SUMOVehicleClass, SUMOReal>*
113 std::map<std::string, std::map<SUMOVehicleClass, SUMOReal> >::const_iterator i =
myRestrictions.find(
id);
138 WRITE_ERROR(
"The TAZ '" +
id +
"' occurs at least twice.");
147 myDistricts[id] = std::make_pair(std::vector<std::string>(), std::vector<std::string>());
155 WRITE_ERROR(
"The TAZ '" + tazID +
"' is unknown.");
160 WRITE_ERROR(
"The edge '" + edgeID +
"' for TAZ '" + tazID +
"' is unknown.");
185 std::map<std::string, SUMOVehicleParameter::Stop*>::const_iterator it =
myBusStops.find(
id);
187 WRITE_ERROR(
"The bus stop '" +
id +
"' occurs at least twice.");
196 std::map<std::string, SUMOVehicleParameter::Stop*>::const_iterator it =
myContainerStops.find(
id);
198 WRITE_ERROR(
"The container stop '" +
id +
"' occurs at least twice.");
212 RONet::openOutput(
const std::string& filename,
const std::string altFilename,
const std::string typeFilename) {
213 if (filename !=
"") {
216 myRoutesOutput->
writeAttr(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance").
writeAttr(
"xsi:noNamespaceSchemaLocation",
"http://sumo.dlr.de/xsd/routes_file.xsd");
218 if (altFilename !=
"") {
223 if (typeFilename !=
"") {
225 myTypesOutput->
writeXMLHeader(
"routes",
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.dlr.de/xsd/routes_file.xsd\"");
246 if (myThreadPool.size() > 0) {
247 myThreadPool.clear();
269 return it2->second->get();
311 WRITE_ERROR(
"The vehicle type '" + type->
id +
"' occurs at least twice.");
337 WRITE_ERROR(
"Another vehicle with the id '" +
id +
"' exists.");
363 WRITE_ERROR(
"Another person with the id '" + person->
getID() +
"' exists.");
370 myContainers.insert(std::pair<const SUMOTime, const std::string>(depart, desc));
376 std::vector<std::string> toRemove;
381 while (pars->
depart < time) {
383 toRemove.push_back(i->first);
391 for (std::vector<SUMOVehicleParameter::Stop>::iterator stop = newPars->
stops.begin(); stop != newPars->
stops.end(); ++stop) {
392 if (stop->until >= 0) {
393 stop->until += pars->
depart - origDepart;
419 if (depart >= time +
DELTA_T) {
428 for (std::vector<SUMOVehicleParameter::Stop>::iterator stop = newPars->
stops.begin(); stop != newPars->
stops.end(); ++stop) {
429 if (stop->until >= 0) {
430 stop->until += depart - pars->
depart;
449 toRemove.push_back(i->first);
453 for (std::vector<std::string>::const_iterator i = toRemove.begin(); i != toRemove.end(); ++i) {
461 std::map<const unsigned int, std::vector<RORoutable*> > bulkVehs;
463 if (i->first >= time) {
466 for (std::deque<RORoutable*>::const_iterator r = i->second.begin(); r != i->second.end(); ++r) {
472 WRITE_WARNING(
"Bulking different maximum speeds ('" + first->
getID() +
"' and '" + routable->
getID() +
"') may lead to suboptimal routes.");
475 WRITE_WARNING(
"Bulking different vehicle classes ('" + first->
getID() +
"' and '" + routable->
getID() +
"') may lead to invalid routes.");
480 for (std::map<
const unsigned int, std::vector<RORoutable*> >::const_iterator i = bulkVehs.begin(); i != bulkVehs.end(); ++i) {
482 if (myThreadPool.size() > 0) {
484 myThreadPool.add(
new RoutingTask(first, removeLoops,
myErrorHandler), workerIndex);
485 myThreadPool.add(
new BulkmodeTask(
true), workerIndex);
486 for (std::vector<RORoutable*>::const_iterator j = i->second.begin() + 1; j != i->second.end(); ++j) {
487 myThreadPool.add(
new RoutingTask(*j, removeLoops,
myErrorHandler), workerIndex);
489 myThreadPool.add(
new BulkmodeTask(
false), workerIndex);
491 if (workerIndex == (
int)myThreadPool.size()) {
497 for (std::vector<RORoutable*>::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
513 const bool removeLoops = options.
getBool(
"remove-loops");
514 const int maxNumThreads = options.
getInt(
"routing-threads");
516 if (options.
getBool(
"bulk-routing")) {
518 while ((
int)myThreadPool.size() < maxNumThreads) {
519 new WorkerThread(myThreadPool, provider);
525 if (i->first >= time) {
528 for (std::deque<RORoutable*>::const_iterator r = i->second.begin(); r != i->second.end(); ++r) {
532 if (maxNumThreads > 0) {
534 const int numThreads = (int)myThreadPool.size();
535 if (numThreads < maxNumThreads && myThreadPool.isFull()) {
536 new WorkerThread(myThreadPool, provider);
538 myThreadPool.add(
new RoutingTask(routable, removeLoops,
myErrorHandler));
547 myThreadPool.waitAll();
553 RoutablesMap::iterator routables =
myRoutables.begin();
555 ContainerMap::iterator container =
myContainers.begin();
558 if (routableTime >= time && containerTime >= time) {
559 lastTime =
MIN2(routableTime, containerTime);
562 const SUMOTime minTime =
MIN2(routableTime, containerTime);
563 if (routableTime == minTime) {
564 const RORoutable*
const r = routables->second.front();
566 if (lastTime != routableTime && lastTime != -1) {
568 if (options.
getInt(
"stats-period") >= 0 && ((int) routableTime % options.
getInt(
"stats-period")) == 0) {
572 lastTime = routableTime;
589 routables->second.pop_front();
590 if (routables->second.empty()) {
594 if (containerTime == minTime) {
624 const std::map<std::string, ROEdge*>&
635 for (std::multimap<std::string, SUMOReal>::const_iterator a = i->second->accessPos.begin(); a != i->second->accessPos.end(); ++a) {
641 if (i->second->line !=
"") {
646 for (std::deque<RORoutable*>::const_iterator r = i->second.begin(); r != i->second.end(); ++r) {
675 myRoutable->computeRoute(*static_cast<WorkerThread*>(context), myRemoveLoops,
myErrorHandler);
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
SUMOTime getDepart() const
Returns the time the vehicle starts at, -1 for triggered vehicles.
SUMOTime repetitionEnd
The time at which the flow ends (only needed when using repetitionProbability)
bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource)
SUMOReal repetitionProbability
The probability for emitting a vehicle per second.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice * myRouteAlternativesOutput
The file to write the computed route alternatives into.
bool hasPermissions() const
void close()
Closes the device and removes it from the dictionary.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const SUMOReal speed)
Adds a restriction for an edge type.
NamedObjectCont< SUMOVehicleParameter * > myFlows
Known flows.
int repetitionNumber
The number of times the vehicle shall be repeatedly inserted.
virtual const ROEdge * getDepartEdge() const =0
std::map< std::string, std::pair< std::vector< std::string >, std::vector< std::string > > > myDistricts
traffic assignment zones with sources and sinks
std::string vtypeid
The vehicle's type id.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
bool getRoutingSuccess() const
int myNumInternalEdges
The number of internal edges in the dictionary.
size_t getEdgeNo() const
Returns the total number of edges the network contains including internal edges.
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
bool erase(const std::string &id)
Removes the named item from the container.
virtual bool add(const std::string &id, T item)
Adds an item.
Structure representing possible vehicle parameter.
static void adaptIntermodalRouter(ROIntermodalRouter &router)
void addNode(RONode *node)
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
OutputDevice & writePreformattedTag(const std::string &val)
writes a preformatted tag to the device but ensures that any pending tags are closed ...
static SUMOReal rand()
Returns a random real number in [0, 1)
int repetitionsDone
The number of times the vehicle was already inserted.
void checkFlows(SUMOTime time, MsgHandler *errorHandler)
EdgeFunc getFunc() const
Returns the function of the edge.
NamedObjectCont< ROEdge * > myEdges
Known edges.
An internal edge which models vehicles driving across a junction. This is currently not used for rout...
void addAccess(const std::string &stopId, const E *stopEdge, const SUMOReal pos)
unsigned int myDiscardedRouteNo
The number of discarded routes.
void setFunc(EdgeFunc func)
Sets the function of the edge.
A map of named object pointers.
std::map< std::string, std::vector< SUMOTime > > myDepartures
Departure times for randomized flows.
OutputDevice * myTypesOutput
The file to write the vehicle types into.
const std::string DEFAULT_VTYPE_ID
#define WRITE_WARNING(msg)
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
SUMOTime repetitionOffset
The time offset between vehicle reinsertions.
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
const std::map< std::string, ROEdge * > & getEdgeMap() const
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
std::vector< Stop > stops
List of the stops the vehicle will make.
void openOutput(const std::string &filename, const std::string altFilename, const std::string typeFilename)
Opens the output for computed routes.
T get(const std::string &id) const
Retrieves an item.
bool writeXMLHeader(const std::string &rootElement, const std::string &attrs="", const std::string &comment="")
Writes an XML header with optional configuration.
void clear()
Removes all items from the container (deletes them, too)
bool writeHeader(const SumoXMLTag &rootElement)
std::set< std::string > myPersonIDs
Known person ids.
A routable thing such as a vehicle or person.
const std::string & getID() const
Returns the id.
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter * > *vehTypeDistribution)
Adds a vehicle type distribution.
SUMOReal getMaxSpeed() const
Returns the vehicle's maximum speed.
A vehicle as used by router.
void cleanup()
closes the file output for computed routes and deletes associated threads if necessary ...
bool addRouteDef(RORouteDef *def)
std::string routeid
The vehicle's route id.
OutputDevice * myRoutesOutput
The file to write the computed routes into.
void addContainer(const SUMOTime depart, const std::string desc)
std::map< std::string, SUMOVehicleParameter::Stop * > myContainerStops
Known container stops.
virtual bool remove(const std::string &id)
Removes an item.
RoutablesMap myRoutables
Known routables.
NamedObjectCont< SUMOVTypeParameter * > myVehicleTypes
Known vehicle types.
SUMOTime depart
The vehicle's departure time.
std::map< std::string, std::map< SUMOVehicleClass, SUMOReal > > myRestrictions
The vehicle class specific speed restrictions.
ContainerMap myContainers
virtual bool furtherStored()
Returns the information whether further vehicles, persons or containers are stored.
unsigned int size() const
Returns the number of items within the container.
A person as used by router.
unsigned int getNumericalID() const
Returns the index (numeric id) of the edge.
static RONet * myInstance
Unique instance of RONet.
SUMOAbstractRouter< E, V > & getVehicleRouter() const
unsigned int myReadRouteNo
The number of read routes.
bool myDefaultVTypeMayBeDeleted
Whether no vehicle type has been loaded yet.
NamedObjectCont< RORouteDef * > myRoutes
Known routes.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
void createBulkRouteRequests(const RORouterProvider &provider, const SUMOTime time, const bool removeLoops)
A basic edge for routing applications.
bool onlyReferenced
Information whether this is a type-stub, being only referenced but not defined (needed by routers) ...
void addSchedule(const SUMOVehicleParameter &pars)
std::string line
The vehicle's line (mainly for public transport)
int getInternalEdgeNumber() const
Returns the number of internal edges the network contains.
virtual void computeRoute(const RORouterProvider &provider, const bool removeLoops, MsgHandler *errorHandler)=0
const IDMap & getMyMap() const
ROEdge * getEdgeForLaneID(const std::string &laneID) const
Retrieves an edge from the network when the lane id is given.
int setParameter
Information for the router which parameter were set.
The router's network representation.
bool addDistrict(const std::string id, ROEdge *source, ROEdge *sink)
Structure representing possible vehicle parameter.
virtual void addSuccessor(ROEdge *s, std::string dir="")
Adds information about a connected edge.
RORouteDef * copy(const std::string &id, const SUMOTime stopOffset) const
Returns a deep copy of the route definition.
const std::string DEFAULT_PEDTYPE_ID
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
const std::string & getID() const
Returns the id of the vehicle.
Definition of vehicle stop (position and duration)
A storage for options typed value containers)
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
Base class for a vehicle's route definition.
std::string id
The vehicle type's id.
void addBusStop(const std::string &id, SUMOVehicleParameter::Stop *stop)
virtual bool addEdge(ROEdge *edge)
std::set< std::string > myVehIDs
Known vehicle ids.
virtual ~RONet()
Destructor.
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
A thread repeatingly calculating incoming tasks.
MsgHandler * myErrorHandler
handler for ignorable error messages
Base class for nodes used by the router.
NamedObjectCont< RONode * > myNodes
Known nodes.
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).
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
RORouteDef * getRouteDefinition() const
Returns the definition of the route the vehicle takes.
An edge representing a whole district.
#define WRITE_MESSAGE(msg)
const int VTYPEPARS_VEHICLECLASS_SET
void addContainerStop(const std::string &id, SUMOVehicleParameter::Stop *stop)
const SUMOVehicleParameter & getParameter() const
Returns the definition of the vehicle parameter.
SUMOVehicleClass getVClass() const
bool addPerson(ROPerson *person)
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
vehicles ignoring classes
SUMOTime saveAndRemoveRoutesUntil(OptionsCont &options, const RORouterProvider &provider, SUMOTime time)
Computes routes described by their definitions and saves them.
std::map< std::string, SUMOVehicleParameter::Stop * > myBusStops
Known bus stops.
std::string id
The vehicle's id.
bool myDefaultPedTypeMayBeDeleted
Whether no pedestrian type has been loaded yet.
void setPermissionsFound()
const std::map< SUMOVehicleClass, SUMOReal > * getRestrictions(const std::string &id) const
Returns the restrictions for an edge type If no restrictions are present, 0 is returned.
unsigned int myWrittenRouteNo
The number of written routes.