51 #ifdef CHECK_MEMORY_LEAKS
53 #endif // CHECK_MEMORY_LEAKS
70 throw ProcessError(
"A network was not yet constructed.");
75 : myVehicleTypes(), myDefaultVTypeMayBeDeleted(true), myDefaultPedTypeMayBeDeleted(true),
76 myRoutesOutput(0), myRouteAlternativesOutput(0), myTypesOutput(0),
77 myReadRouteNo(0), myDiscardedRouteNo(0), myWrittenRouteNo(0),
78 myHavePermissions(false),
79 myNumInternalEdges(0),
80 myErrorHandler(
OptionsCont::getOptions().exists(
"ignore-errors")
83 throw ProcessError(
"A network was already constructed.");
97 for (RoutablesMap::iterator routables =
myRoutables.begin(); routables !=
myRoutables.end(); ++routables) {
98 for (std::deque<RORoutable*>::iterator r = routables->second.begin(); r != routables->second.end(); ++r) {
109 for (std::map<std::string, SUMOVehicleParameter::Stop*>::iterator it =
myBusStops.begin(); it !=
myBusStops.end(); ++it) {
129 const std::map<SUMOVehicleClass, SUMOReal>*
131 std::map<std::string, std::map<SUMOVehicleClass, SUMOReal> >::const_iterator i =
myRestrictions.find(
id);
156 WRITE_ERROR(
"The TAZ '" +
id +
"' occurs at least twice.");
165 myDistricts[id] = std::make_pair(std::vector<std::string>(), std::vector<std::string>());
173 WRITE_ERROR(
"The TAZ '" + tazID +
"' is unknown.");
178 WRITE_ERROR(
"The edge '" + edgeID +
"' for TAZ '" + tazID +
"' is unknown.");
203 std::map<std::string, SUMOVehicleParameter::Stop*>::const_iterator it =
myBusStops.find(
id);
205 WRITE_ERROR(
"The bus stop '" +
id +
"' occurs at least twice.");
214 std::map<std::string, SUMOVehicleParameter::Stop*>::const_iterator it =
myContainerStops.find(
id);
216 WRITE_ERROR(
"The container stop '" +
id +
"' occurs at least twice.");
231 if (options.
isSet(
"output-file") && options.
getString(
"output-file") !=
"") {
235 if (altFilename !=
"") {
240 if (options.
isSet(
"vtype-output") && options.
getString(
"vtype-output") !=
"") {
263 if (myThreadPool.size() > 0) {
264 myThreadPool.clear();
286 return it2->second->get();
328 WRITE_ERROR(
"The vehicle type '" + type->
id +
"' occurs at least twice.");
354 WRITE_ERROR(
"Another vehicle with the id '" +
id +
"' exists.");
380 WRITE_ERROR(
"Another person with the id '" + person->
getID() +
"' exists.");
387 myContainers.insert(std::pair<const SUMOTime, const std::string>(depart, desc));
393 std::vector<std::string> toRemove;
398 while (pars->
depart < time) {
400 toRemove.push_back(i->first);
408 for (std::vector<SUMOVehicleParameter::Stop>::iterator stop = newPars->
stops.begin(); stop != newPars->
stops.end(); ++stop) {
409 if (stop->until >= 0) {
410 stop->until += pars->
depart - origDepart;
436 if (depart >= time +
DELTA_T) {
445 for (std::vector<SUMOVehicleParameter::Stop>::iterator stop = newPars->
stops.begin(); stop != newPars->
stops.end(); ++stop) {
446 if (stop->until >= 0) {
447 stop->until += depart - pars->
depart;
466 toRemove.push_back(i->first);
470 for (std::vector<std::string>::const_iterator i = toRemove.begin(); i != toRemove.end(); ++i) {
478 std::map<const int, std::vector<RORoutable*> > bulkVehs;
480 if (i->first >= time) {
483 for (std::deque<RORoutable*>::const_iterator r = i->second.begin(); r != i->second.end(); ++r) {
489 WRITE_WARNING(
"Bulking different maximum speeds ('" + first->
getID() +
"' and '" + routable->
getID() +
"') may lead to suboptimal routes.");
492 WRITE_WARNING(
"Bulking different vehicle classes ('" + first->
getID() +
"' and '" + routable->
getID() +
"') may lead to invalid routes.");
497 for (std::map<
const int, std::vector<RORoutable*> >::const_iterator i = bulkVehs.begin(); i != bulkVehs.end(); ++i) {
499 if (myThreadPool.size() > 0) {
501 myThreadPool.add(
new RoutingTask(first, removeLoops,
myErrorHandler), workerIndex);
502 myThreadPool.add(
new BulkmodeTask(
true), workerIndex);
503 for (std::vector<RORoutable*>::const_iterator j = i->second.begin() + 1; j != i->second.end(); ++j) {
504 myThreadPool.add(
new RoutingTask(*j, removeLoops,
myErrorHandler), workerIndex);
506 myThreadPool.add(
new BulkmodeTask(
false), workerIndex);
508 if (workerIndex == (
int)myThreadPool.size()) {
514 for (std::vector<RORoutable*>::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
530 const bool removeLoops = options.
getBool(
"remove-loops");
531 const int maxNumThreads = options.
getInt(
"routing-threads");
533 if (options.
getBool(
"bulk-routing")) {
535 while ((
int)myThreadPool.size() < maxNumThreads) {
536 new WorkerThread(myThreadPool, provider);
542 if (i->first >= time) {
545 for (std::deque<RORoutable*>::const_iterator r = i->second.begin(); r != i->second.end(); ++r) {
549 if (maxNumThreads > 0) {
551 const int numThreads = (int)myThreadPool.size();
552 if (numThreads < maxNumThreads && myThreadPool.isFull()) {
553 new WorkerThread(myThreadPool, provider);
555 myThreadPool.add(
new RoutingTask(routable, removeLoops,
myErrorHandler));
564 myThreadPool.waitAll();
570 RoutablesMap::iterator routables =
myRoutables.begin();
572 ContainerMap::iterator container =
myContainers.begin();
575 if (routableTime >= time && containerTime >= time) {
576 lastTime =
MIN2(routableTime, containerTime);
579 const SUMOTime minTime =
MIN2(routableTime, containerTime);
580 if (routableTime == minTime) {
581 const RORoutable*
const r = routables->second.front();
583 if (lastTime != routableTime && lastTime != -1) {
585 if (options.
getInt(
"stats-period") >= 0 && ((int) routableTime % options.
getInt(
"stats-period")) == 0) {
589 lastTime = routableTime;
606 routables->second.pop_front();
607 if (routables->second.empty()) {
612 if (containerTime == minTime) {
642 const std::map<std::string, ROEdge*>&
653 for (std::multimap<std::string, SUMOReal>::const_iterator a = i->second->accessPos.begin(); a != i->second->accessPos.end(); ++a) {
659 if (i->second->line !=
"") {
664 for (std::deque<RORoutable*>::const_iterator r = i->second.begin(); r != i->second.end(); ++r) {
693 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.
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)
void setFunc(EdgeFunc func)
Sets the function of the edge.
int myDiscardedRouteNo
The number of discarded routes.
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
int myWrittenRouteNo
The number of written routes.
#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).
void openOutput(const OptionsCont &options, const std::string altFilename="")
Opens the output for computed routes.
std::vector< Stop > stops
List of the stops the vehicle will make.
T get(const std::string &id) const
Retrieves an item.
void clear()
Removes all items from the container (deletes them, too)
bool writeHeader(const SumoXMLTag &rootElement)
std::set< std::string > myPersonIDs
Known person ids.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
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.
A person as used by router.
static RONet * myInstance
Unique instance of RONet.
SUMOAbstractRouter< E, V > & getVehicleRouter() const
int getEdgeNo() const
Returns the total number of edges the network contains including internal edges.
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.
int myReadRouteNo
The number of read routes.
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.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
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)
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.
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.
int getNumericalID() const
Returns the index (numeric id) of the edge.
std::string id
The vehicle's id.
bool myDefaultPedTypeMayBeDeleted
Whether no pedestrian type has been loaded yet.
void setPermissionsFound()
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
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.
int size() const
Returns the number of items within the container.