50 #ifdef CHECK_MEMORY_LEAKS
52 #endif // CHECK_MEMORY_LEAKS
59 : myVehicleTypes(), myDefaultVTypeMayBeDeleted(true),
60 myRoutesOutput(0), myRouteAlternativesOutput(0), myTypesOutput(0),
61 myReadRouteNo(0), myDiscardedRouteNo(0), myWrittenRouteNo(0),
62 myHaveRestrictions(false),
63 myNumInternalEdges(0),
64 myErrorHandler(
OptionsCont::getOptions().exists(
"ignore-errors")
98 WRITE_ERROR(
"The TAZ '" +
id +
"' occurs at least twice.");
107 myDistricts[id] = std::make_pair(std::vector<std::string>(), std::vector<std::string>());
115 WRITE_ERROR(
"The TAZ '" + tazID +
"' is unknown.");
120 WRITE_ERROR(
"The edge '" + edgeID +
"' for TAZ '" + tazID +
"' is unknown.");
145 std::map<std::string, SUMOVehicleParameter::Stop*>::const_iterator it =
myBusStops.find(
id);
147 WRITE_ERROR(
"The bus stop '" +
id +
"' occurs at least twice.");
156 std::map<std::string, SUMOVehicleParameter::Stop*>::const_iterator it =
myContainerStops.find(
id);
158 WRITE_ERROR(
"The container stop '" +
id +
"' occurs at least twice.");
172 RONet::openOutput(
const std::string& filename,
const std::string altFilename,
const std::string typeFilename) {
173 if (filename !=
"") {
176 myRoutesOutput->
writeAttr(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance").
writeAttr(
"xsi:noNamespaceSchemaLocation",
"http://sumo.dlr.de/xsd/routes_file.xsd");
178 if (altFilename !=
"") {
183 if (typeFilename !=
"") {
185 myTypesOutput->
writeXMLHeader(
"routes",
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.dlr.de/xsd/routes_file.xsd\"");
206 if (myThreadPool.size() > 0) {
207 myThreadPool.clear();
228 return it2->second->get();
263 WRITE_ERROR(
"The vehicle type '" + type->
id +
"' occurs at least twice.");
288 WRITE_ERROR(
"Another vehicle with the id '" +
id +
"' exists.");
309 myPersons.insert(std::pair<const SUMOTime, const std::string>(depart, desc));
314 myContainers.insert(std::pair<const SUMOTime, const std::string>(depart, desc));
320 const ROVehicle*
const veh,
const bool removeLoops,
322 std::string noRouteMsg =
"The vehicle '" + veh->
getID() +
"' has no valid route.";
326 errorHandler->
inform(noRouteMsg);
330 if (current == 0 || current->
size() == 0) {
332 errorHandler->
inform(noRouteMsg);
339 if (current->
size() == 0) {
341 errorHandler->
inform(noRouteMsg +
" (after removing loops)");
353 std::vector<std::string> toRemove;
357 while (pars->
depart < time) {
359 toRemove.push_back(i->first);
389 if (depart >= time +
DELTA_T) {
413 toRemove.push_back(i->first);
417 for (std::vector<std::string>::const_iterator i = toRemove.begin(); i != toRemove.end(); ++i) {
428 const bool removeLoops = options.
getBool(
"remove-loops");
430 const int maxNumThreads = options.
getInt(
"routing-threads");
434 for (std::map<std::string, ROVehicle*>::const_iterator i = mmap.begin(); i != mmap.end(); ++i) {
435 if (i->second->getDepart() >= time) {
439 i->second->setRoutingSuccess(
false);
442 const int numThreads = (int)myThreadPool.size();
443 if (numThreads < maxNumThreads && myThreadPool.isFull()) {
444 new WorkerThread(myThreadPool, numThreads == 0 ? &router : router.
clone());
447 if (maxNumThreads > 0) {
448 myThreadPool.add(
new RoutingTask(i->second, removeLoops,
myErrorHandler));
455 myThreadPool.waitAll();
463 PersonMap::iterator person =
myPersons.begin();
465 ContainerMap::iterator container =
myContainers.begin();
468 if (vehicleTime >= time && personTime >= time && containerTime >= time) {
469 lastTime =
MIN3(vehicleTime, personTime, containerTime);
472 SUMOTime minTime =
MIN3(vehicleTime, personTime, containerTime);
473 if (vehicleTime == minTime) {
475 if (lastTime != vehicleTime && lastTime != -1) {
477 if (options.
getInt(
"stats-period") >= 0 && ((int) vehicleTime % options.
getInt(
"stats-period")) == 0) {
481 lastTime = vehicleTime;
503 if (personTime == minTime) {
510 if (containerTime == minTime) {
540 const std::map<std::string, ROEdge*>&
564 myVehicle->setRoutingSuccess(
RONet::computeRoute(static_cast<WorkerThread*>(context)->getRouter(), myVehicle, myRemoveLoops, myErrorHandler));
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.
void close()
Closes the device and removes it from the dictionary.
EdgeType getType() const
Returns the type of the edge.
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.
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.
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 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.
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
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
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.
void setType(EdgeType type)
Sets the type of te edge.
bool addRouteDef(RORouteDef *def)
bool myHaveRestrictions
Whether the network contains edges which not all vehicles may pass.
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.
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.
ROVehicleCont myVehicles
Known vehicles.
An edge representing a whole district.
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)
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
bool addDistrict(const std::string id, ROEdge *source, ROEdge *sink)
Structure representing possible vehicle parameter.
void setRestrictionFound()
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)
bool hasRestrictions() const
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.
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.
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.
unsigned int myWrittenRouteNo
The number of written routes.