50 #ifdef CHECK_MEMORY_LEAKS 52 #endif // CHECK_MEMORY_LEAKS 69 throw ProcessError(
"A network was not yet constructed.");
82 throw ProcessError(
"A network was already constructed.");
106 const std::map<SUMOVehicleClass, SUMOReal>*
108 std::map<std::string, std::map<SUMOVehicleClass, SUMOReal> >::const_iterator i =
myRestrictions.find(
id);
133 WRITE_ERROR(
"The TAZ '" +
id +
"' occurs at least twice.");
142 myDistricts[id] = std::make_pair(std::vector<std::string>(), std::vector<std::string>());
150 WRITE_ERROR(
"The TAZ '" + tazID +
"' is unknown.");
155 WRITE_ERROR(
"The edge '" + edgeID +
"' for TAZ '" + tazID +
"' is unknown.");
180 std::map<std::string, SUMOVehicleParameter::Stop*>::const_iterator it =
myBusStops.find(
id);
182 WRITE_ERROR(
"The bus stop '" +
id +
"' occurs at least twice.");
191 std::map<std::string, SUMOVehicleParameter::Stop*>::const_iterator it =
myContainerStops.find(
id);
193 WRITE_ERROR(
"The container stop '" +
id +
"' occurs at least twice.");
207 RONet::openOutput(
const std::string& filename,
const std::string altFilename,
const std::string typeFilename) {
208 if (filename !=
"") {
211 myRoutesOutput->
writeAttr(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance").
writeAttr(
"xsi:noNamespaceSchemaLocation",
"http://sumo.dlr.de/xsd/routes_file.xsd");
213 if (altFilename !=
"") {
218 if (typeFilename !=
"") {
220 myTypesOutput->
writeXMLHeader(
"routes",
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.dlr.de/xsd/routes_file.xsd\"");
241 if (myThreadPool.size() > 0) {
242 myThreadPool.clear();
263 return it2->second->get();
298 WRITE_ERROR(
"The vehicle type '" + type->
id +
"' occurs at least twice.");
323 WRITE_ERROR(
"Another vehicle with the id '" +
id +
"' exists.");
344 myPersons.insert(std::pair<const SUMOTime, const std::string>(depart, desc));
349 myContainers.insert(std::pair<const SUMOTime, const std::string>(depart, desc));
355 const ROVehicle*
const veh,
const bool removeLoops,
357 std::string noRouteMsg =
"The vehicle '" + veh->
getID() +
"' has no valid route.";
361 errorHandler->
inform(noRouteMsg);
365 if (current == 0 || current->
size() == 0) {
367 errorHandler->
inform(noRouteMsg);
374 if (current->
size() == 0) {
376 errorHandler->
inform(noRouteMsg +
" (after removing loops)");
388 std::vector<std::string> toRemove;
392 while (pars->
depart < time) {
394 toRemove.push_back(i->first);
424 if (depart >= time +
DELTA_T) {
448 toRemove.push_back(i->first);
452 for (std::vector<std::string>::const_iterator i = toRemove.begin(); i != toRemove.end(); ++i) {
460 std::map<const unsigned int, std::vector<ROVehicle*> > bulkVehs;
461 for (std::map<std::string, ROVehicle*>::const_iterator i = mmap.begin(); i != mmap.end(); ++i) {
468 WRITE_WARNING(
"Bulking different maximum speeds ('" + first->
getID() +
"' and '" + vehicle->
getID() +
"') may lead to suboptimal routes.");
471 WRITE_WARNING(
"Bulking different vehicle classes ('" + first->
getID() +
"' and '" + vehicle->
getID() +
"') may lead to invalid routes.");
476 for (std::map<
const unsigned int, std::vector<ROVehicle*> >::const_iterator i = bulkVehs.begin(); i != bulkVehs.end(); ++i) {
478 if (myThreadPool.size() > 0) {
479 ROVehicle*
const first = i->second.front();
480 myThreadPool.add(
new RoutingTask(first, removeLoops,
myErrorHandler), workerIndex);
481 myThreadPool.add(
new BulkmodeTask(
true), workerIndex);
482 for (std::vector<ROVehicle*>::const_iterator j = i->second.begin() + 1; j != i->second.end(); ++j) {
483 myThreadPool.add(
new RoutingTask(*j, removeLoops,
myErrorHandler), workerIndex);
485 myThreadPool.add(
new BulkmodeTask(
false), workerIndex);
487 if (workerIndex == (
int)myThreadPool.size()) {
493 for (std::vector<ROVehicle*>::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
507 const bool removeLoops = options.
getBool(
"remove-loops");
509 const int maxNumThreads = options.
getInt(
"routing-threads");
513 if (options.
getBool(
"bulk-routing")) {
515 while ((
int)myThreadPool.size() < maxNumThreads) {
516 new WorkerThread(myThreadPool, myThreadPool.size() == 0 ? &router : router.
clone());
521 for (std::map<std::string, ROVehicle*>::const_iterator i = mmap.begin(); i != mmap.end(); ++i) {
529 if (maxNumThreads > 0) {
532 const int numThreads = (int)myThreadPool.size();
533 if (numThreads < maxNumThreads && myThreadPool.isFull()) {
534 new WorkerThread(myThreadPool, numThreads == 0 ? &router : router.
clone());
536 myThreadPool.add(
new RoutingTask(vehicle, removeLoops,
myErrorHandler));
544 myThreadPool.waitAll();
552 PersonMap::iterator person =
myPersons.begin();
554 ContainerMap::iterator container =
myContainers.begin();
557 if (vehicleTime >= time && personTime >= time && containerTime >= time) {
558 lastTime =
MIN3(vehicleTime, personTime, containerTime);
561 SUMOTime minTime =
MIN3(vehicleTime, personTime, containerTime);
562 if (vehicleTime == minTime) {
564 if (lastTime != vehicleTime && lastTime != -1) {
566 if (options.
getInt(
"stats-period") >= 0 && ((int) vehicleTime % options.
getInt(
"stats-period")) == 0) {
570 lastTime = vehicleTime;
592 if (personTime == minTime) {
599 if (containerTime == minTime) {
629 const std::map<std::string, ROEdge*>&
SUMOTime getDepartureTime() const
Returns the time the vehicle starts at, 0 for triggered vehicles.
const std::string & getID() const
Returns the id of the vehicle.
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.
void setRoutingSuccess(const bool val)
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.
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.
int myNumInternalEdges
The number of internal edges in the dictionary.
void clear()
Deletes all vehicles stored; clears the lists.
size_t getEdgeNo() const
Returns the total number of edges the network contains including internal edges.
unsigned int size() const
Returns the number of edges in this route.
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.
SUMOVehicleClass getVClass() const
Structure representing possible vehicle parameter.
void addAlternative(SUMOAbstractRouter< ROEdge, ROVehicle > &router, const ROVehicle *const, RORoute *current, SUMOTime begin)
Adds an alternative to the list of routes.
void addNode(RONode *node)
RORoute * buildCurrentRoute(SUMOAbstractRouter< ROEdge, ROVehicle > &router, SUMOTime begin, const ROVehicle &veh) const
Triggers building of the complete route (via preComputeCurrentRoute) or returns precomputed route...
virtual SUMOAbstractRouter * clone() const =0
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 createBulkRouteRequests(SUMOAbstractRouter< ROEdge, ROVehicle > &router, const SUMOTime time, const bool removeLoops, const std::map< std::string, ROVehicle * > &mmap)
EdgeFunc getFunc() const
Returns the function of the edge.
SUMOReal getMaxSpeed() const
Returns the vehicle's maximum speed.
void recheckForLoops()
Checks whether this route contains loops and removes such.
NamedObjectCont< ROEdge * > myEdges
Known edges.
SUMOTime getDepart() const
Returns the time the vehicle starts at, -1 for triggered vehicles.
An internal edge which models vehicles driving across a junction. This is currently not used for rout...
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.
SUMOReal repetitionOffset
The time offset between vehicle reinsertions.
const std::string DEFAULT_VTYPE_ID
#define WRITE_WARNING(msg)
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
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).
virtual bool add(const std::string &id, ROVehicle *item)
Adds a vehicle to the container.
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 checkFlows(SUMOTime time)
void clear()
Removes all items from the container (deletes them, too)
bool writeHeader(const SumoXMLTag &rootElement)
void saveTypeAsXML(OutputDevice &os, OutputDevice *const altos, OutputDevice *const typeos) const
Saves the vehicle type if it was not saved before.
const std::string & getID() const
Returns the id.
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter * > *vehTypeDistribution)
Adds a vehicle type distribution.
bool getRoutingSuccess() const
A vehicle as used by router.
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.
const ROVehicle * getTopVehicle() const
Returns the vehicle that departs most early.
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.
void addPerson(const SUMOTime depart, const std::string desc)
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.
unsigned int getNumericalID() const
Returns the index (numeric id) of the edge.
ROVehicleCont myVehicles
Known vehicles.
static RONet * myInstance
Unique instance of RONet.
unsigned int myReadRouteNo
The number of read routes.
bool myDefaultVTypeMayBeDeleted
Whether no vehicle type was loaded.
NamedObjectCont< RORouteDef * > myRoutes
Known routes.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
const ROEdge * getFirst() const
Returns the first edge in the route.
bool erase(const std::string &id)
Tries to remove (and delete) the named vehicle.
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 saveAllAsXML(OutputDevice &os, bool asAlternatives, bool withExitTimes) const
Saves the complete vehicle description.
int getInternalEdgeNumber() const
Returns the number of internal edges the network contains.
const IDMap & getMyMap() const
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.
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
RORouteDef * copy(const std::string &id) const
Returns a deep copy of the route definition.
Definition of vehicle stop (position and duration)
void inform(std::string msg, bool addType=true)
adds a new error to the list
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)
static bool computeRoute(SUMOAbstractRouter< ROEdge, ROVehicle > &router, const ROVehicle *const veh, const bool removeLoops, MsgHandler *errorHandler)
std::set< std::string > myVehIDs
Known vehicle ids.
virtual ~RONet()
Destructor.
const RORoute * getFirstRoute() const
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.
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.
SUMOTime saveAndRemoveRoutesUntil(OptionsCont &options, SUMOAbstractRouter< ROEdge, ROVehicle > &router, SUMOTime time)
Computes routes described by their definitions and saves them.
#define WRITE_MESSAGE(msg)
void cleanup(SUMOAbstractRouter< ROEdge, ROVehicle > *router)
closes the file output for computed routes and deletes routers and associated threads if necessary ...
void addContainerStop(const std::string &id, SUMOVehicleParameter::Stop *stop)
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
vehicles ignoring classes
std::map< std::string, SUMOVehicleParameter::Stop * > myBusStops
Known bus stops.
A complete router's route.
std::string id
The vehicle's id.
void setPermissionsFound()
void setBulkMode(const bool mode)
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.