 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
61 FXMutex MSRoutingEngine::myRouteCacheMutex;
81 if (myAdaptationWeight < 1. && myAdaptationInterval > 0) {
84 }
else if (period > 0) {
85 WRITE_WARNING(
"Rerouting is useless if the edge weights do not get updated!");
99 const bool useLoaded = oc.
getBool(
"device.rerouting.init-with-loaded-weights");
100 const double currentSecond =
SIMTIME;
102 while (edge->getNumericalID() >= (
int)
myEdgeSpeeds.size()) {
111 myEdgeSpeeds[edge->getNumericalID()] = edge->getMeanSpeed();
158 std::map<std::pair<const MSEdge*, const MSEdge*>,
const MSRoute*>::iterator it =
myCachedRoutes.begin();
160 it->second->release();
166 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
167 if ((*i)->isDelayed()) {
168 const int id = (*i)->getNumericalID();
169 const double currSpeed = (*i)->getMeanSpeed();
178 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
179 if ((*i)->isDelayed()) {
180 const int id = (*i)->getNumericalID();
181 const double currSpeed = (*i)->getMeanSpeed();
195 for (
const MSEdge* e : edges) {
211 return routeIt->second;
220 const std::string routingAlgorithm = oc.
getString(
"routing-algorithm");
224 if (routingAlgorithm ==
"dijkstra") {
226 }
else if (routingAlgorithm ==
"astar") {
228 std::shared_ptr<const AStar::LookupTable> lookup =
nullptr;
229 if (oc.
isSet(
"astar.all-distances")) {
231 }
else if (oc.
isSet(
"astar.landmark-distances") && vehicle !=
nullptr) {
238 lookup = std::make_shared<const AStar::LMLT>(oc.
getString(
"astar.landmark-distances"),
MSEdge::getAllEdges(), &router, vehicle,
"", oc.
getInt(
"device.rerouting.threads"));
242 }
else if (routingAlgorithm ==
"CH") {
246 }
else if (routingAlgorithm ==
"CHWrapper") {
252 throw ProcessError(
"Unknown routing algorithm '" + routingAlgorithm +
"'!");
256 if (threadPool.
size() > 0) {
257 const std::vector<FXWorkerThread*>& threads = threadPool.
getWorkers();
258 if (
static_cast<MSEdgeControl::WorkerThread*
>(threads.front())->setRouter(
myRouter)) {
259 for (std::vector<FXWorkerThread*>::const_iterator t = threads.begin() + 1; t != threads.end(); ++t) {
260 static_cast<MSEdgeControl::WorkerThread*
>(*t)->setRouter(
myRouter->
clone());
270 const bool onInit,
const bool silent,
const MSEdgeVector& prohibited) {
276 if (threadPool.
size() > 0) {
277 threadPool.
add(
new RoutingTask(vehicle, currentTime, info, onInit, silent, prohibited));
281 if (!prohibited.empty()) {
288 if (!prohibited.empty()) {
294 if (!prohibited.empty()) {
315 if (threadPool.
size() > 0) {
317 router.prohibit(prohibited);
351 MSRoutingEngine::waitForAll() {
353 if (threadPool.
size() > 0) {
365 if (!myProhibited.empty()) {
369 myVehicle.reroute(myTime, myInfo, router, myOnInit, myWithTaz, mySilent);
372 if (!myProhibited.empty()) {
378 if (!myProhibited.empty()) {
381 const MSEdge* source = *myVehicle.getRoute().begin();
382 const MSEdge* dest = myVehicle.getRoute().getLastEdge();
384 const std::pair<const MSEdge*, const MSEdge*> key = std::make_pair(source, dest);
385 FXMutexLock lock(myRouteCacheMutex);
388 myVehicle.getRoute().addReference();
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
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.
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
static double myAdaptationWeight
Information which weight prior edge efforts have.
int getNumericalID() const
Returns the numerical id of the edge.
bool hasBidiEdges() const
return whether the network contains bidirectional rail edges
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
#define WRITE_WARNING(msg)
virtual void setChosenSpeedFactor(const double factor)=0
Static storage of an output device and its base (abstract) implementation.
static Command * myEdgeWeightSettingCommand
The weights adaptation/overwriting command.
static SUMOAbstractRouter< MSEdge, SUMOVehicle > * myRouter
The router to use.
static std::map< std::pair< const MSEdge *, const MSEdge * >, const MSRoute * > myCachedRoutes
The container of pre-calculated routes.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Representation of a vehicle.
static double getAssumedSpeed(const MSEdge *edge)
return current travel speed assumption
static std::vector< double > myEdgeSpeeds
The container of edge speeds.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
virtual SUMOVehicleClass getVClass() const =0
Returns the vehicle's access class.
static OptionsCont & getOptions()
Retrieves the options.
static SUMOTime adaptEdgeEfforts(SUMOTime currentTime)
Adapt edge efforts by the current edge states.
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
double getLength() const
return the length of the edge
static SUMOTime myLastAdaptation
Information when the last edge weight adaptation occurred.
static void setEdgeTravelTime(const MSEdge *const edge, const double travelTime)
adapt the known travel time for an edge
Computes the shortest path through a network using the Dijkstra algorithm.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
int size() const
Returns the number of threads in the pool.
double gWeightsRandomFactor
static void cleanup()
deletes the router instance
@ SUMO_ATTR_BEGIN
weights: time range begin
virtual double getChosenSpeedFactor() const =0
static int gNumThreads
how many threads to use
void waitAll(const bool deleteFinished=true)
waits for all tasks to be finished
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
A wrapper for a Command function.
static void initEdgeWeights()
initialize the edge weights if not done before
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
static void reroute(SUMOVehicle &vehicle, const SUMOTime currentTime, const std::string &info, const bool onInit=false, const bool silent=false, const MSEdgeVector &prohibited=MSEdgeVector())
initiate the rerouting, create router / thread pool on first use
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
static int myAdaptationStepsIndex
The current index in the pastEdgeSpeed ring-buffer.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
bool isTazConnector() const
Computes the shortest path through a contracted network.
static bool myWithTaz
whether taz shall be used at initial rerouting
@ SUMO_TAG_EDGE
begin/end of the description of an edge
static void initRouter(SUMOVehicle *vehicle=nullptr)
const std::vector< FXWorkerThread * > & getWorkers()
static SUMOTime myAdaptationInterval
At which time interval the edge weights get updated.
const MSEdge * getBidiEdge() const
return opposite superposable/congruent edge, if it exist and 0 else
double getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
A storage for options typed value containers)
A road/street connecting two junctions.
SUMOTime string2time(const std::string &r)
virtual void prohibit(const std::vector< E * > &)
static std::vector< std::vector< double > > myPastEdgeSpeeds
The container of edge speeds.
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
static void initWeightUpdate()
intialize period edge weight update
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
virtual SUMOAbstractRouter * clone()=0
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
virtual void reroute(SUMOTime t, const std::string &info, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false, const bool silent=false)=0
Performs a rerouting using the given router.
Computes the shortest path through a contracted network.
static double getEffortExtra(const MSEdge *const e, const SUMOVehicle *const v, double t)
A pool of worker threads which distributes the tasks and collects the results.
Base (microsim) event class.
std::vector< MSEdge * > MSEdgeVector
void add(Task *const t, int index=-1)
Gives a number to the given task and assigns it to the worker with the given index....
Computes the shortest path through a network using the A* algorithm.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
static int myAdaptationSteps
The number of steps for averaging edge speeds (ring-buffer)
@ SUMO_ATTR_END
weights: time range end
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
static SUMOAbstractRouter< MSEdge, SUMOVehicle >::Operation myEffortFunc
MSEdgeControl & getEdgeControl()
Returns the edge control.
static const MSRoute * getCachedRoute(const std::pair< const MSEdge *, const MSEdge * > &key)
return the cached route or nullptr on miss
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
static double getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the travel time to pass an edge.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
const MSEdgeVector & getEdges() const
Returns loaded edges.
A thread repeatingly calculating incoming tasks.