46#define UNREACHABLE (std::numeric_limits<double>::max() / 1000.0)
75template<
class E,
class V>
91 return nod1->
edge->getNumericalID() > nod2->
edge->getNumericalID();
99 const bool havePermissions =
false,
const bool haveRestrictions =
false) :
100 SUMOAbstractRouter<E, V>(
"AStarRouter", unbuildIsWarning, operation, nullptr, havePermissions, haveRestrictions),
103 for (
const E*
const edge : edges) {
110 const bool havePermissions =
false,
const bool haveRestrictions =
false) :
111 SUMOAbstractRouter<E, V>(
"AStarRouter", unbuildIsWarning, operation, nullptr, havePermissions, haveRestrictions),
114 for (
const auto& edgeInfo : edgeInfos) {
129 bool compute(
const E* from,
const E* to,
const V*
const vehicle,
130 SUMOTime msTime, std::vector<const E*>& into,
bool silent =
false) {
131 assert(from !=
nullptr && to !=
nullptr);
133 if (this->
myEdgeInfos[from->getNumericalID()].prohibited || this->isProhibited(from, vehicle)) {
139 if (this->
myEdgeInfos[to->getNumericalID()].prohibited || this->isProhibited(to, vehicle)) {
147#ifdef ASTAR_DEBUG_QUERY
148 if (ASTAR_DEBUG_COND) {
149 std::cout <<
"DEBUG: starting search for '" <<
Named::getIDSecure(vehicle) <<
"' speed: " <<
MIN2(vehicle->getMaxSpeed(),
myMaxSpeed * vehicle->getChosenSpeedFactor()) <<
" time: " <<
STEPS2TIME(msTime) <<
"\n";
155 const auto& toInfo = this->
myEdgeInfos[to->getNumericalID()];
156 if (toInfo.visited) {
162 this->
init(from->getNumericalID(), msTime);
168 const double speed = vehicle ==
nullptr ?
myMaxSpeed :
MIN2(vehicle->getMaxSpeed(),
myMaxSpeed * vehicle->getChosenSpeedFactor());
173 const E*
const minEdge = minimumInfo->edge;
174#ifdef ASTAR_DEBUG_QUERY
175 if (ASTAR_DEBUG_COND) {
176 std::cout <<
"DEBUG: hit=" << minEdge->getID()
177 <<
" TT=" << minimumInfo->effort
178 <<
" EF=" << this->
getEffort(minEdge, vehicle, minimumInfo->leaveTime)
179 <<
" HT=" << minimumInfo->heuristicEffort
180 <<
" Q(TT,HT,Edge)=";
182 std::cout <<
"\n " << edgeInfo->effort <<
"," << edgeInfo->heuristicEffort <<
"," << edgeInfo->edge->getID();
191#ifdef ASTAR_DEBUG_QUERY_PERF
192 if (ASTAR_DEBUG_COND) {
193 std::cout <<
"visited " +
toString(num_visited) +
" edges (final path length=" +
toString(into.size())
195 +
" edges=" +
toString(into) +
")\n";
198#ifdef ASTAR_DEBUG_VISITED
199 if (ASTAR_DEBUG_COND) {
203 dev <<
"edge:" << i.edge->getID() <<
"\n";
213 this->
myFound.push_back(minimumInfo);
214 minimumInfo->visited =
true;
215 const double effortDelta = this->
getEffort(minEdge, vehicle, minimumInfo->leaveTime);
216 const double leaveTime = minimumInfo->leaveTime + this->
getTravelTime(minEdge, vehicle, minimumInfo->leaveTime, effortDelta);
220 const double heuristic_remaining = (
myLookupTable ==
nullptr ? minEdge->getDistanceTo(to) / speed :
221 myLookupTable->lowerBound(minEdge, to, speed, vehicle->getChosenSpeedFactor(),
222 minEdge->getMinimumTravelTime(
nullptr), to->getMinimumTravelTime(
nullptr)));
226 const double heuristicEffort = minimumInfo->effort + effortDelta + heuristic_remaining;
228 for (
const std::pair<const E*, const E*>& follower : minEdge->getViaSuccessors(vClass)) {
229 auto& followerInfo = this->
myEdgeInfos[follower.first->getNumericalID()];
231 if (followerInfo.prohibited || this->isProhibited(follower.first, vehicle)) {
234 double effort = minimumInfo->effort + effortDelta;
235 double time = leaveTime;
237 const double oldEffort = followerInfo.effort;
238 if ((!followerInfo.visited || mayRevisit) && effort < oldEffort) {
239 followerInfo.effort = effort;
242 followerInfo.heuristicEffort =
MAX2(
MIN2(heuristicEffort, followerInfo.heuristicEffort), effort);
243 followerInfo.leaveTime = time;
244 followerInfo.prev = minimumInfo;
245#ifdef ASTAR_DEBUG_QUERY_FOLLOWERS
246 if (ASTAR_DEBUG_COND) {
247 std::cout <<
" follower=" << followerInfo.edge->getID()
248 <<
" OEF=" << (oldEffort == std::numeric_limits<double>::max() ?
"inf" :
toString(oldEffort))
249 <<
" TT=" << effort <<
" HR=" << heuristic_remaining <<
" HT=" << followerInfo.heuristicEffort <<
"\n";
252 if (oldEffort == std::numeric_limits<double>::max()) {
256 auto fi = std::find(this->
myFrontierList.begin(), this->myFrontierList.end(), &followerInfo);
269#ifdef ASTAR_DEBUG_QUERY_PERF
270 if (ASTAR_DEBUG_COND) {
271 std::cout <<
"visited " +
toString(num_visited) +
" edges (unsuccessful path length: " +
toString(into.size()) +
")\n";
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
bool operator()(const typename SUMOAbstractRouter< E, V >::EdgeInfo *nod1, const typename SUMOAbstractRouter< E, V >::EdgeInfo *nod2) const
Comparing method.
Computes the shortest path through a network using the A* algorithm.
double myMaxSpeed
maximum speed in the network
EdgeInfoComparator myComparator
FullLookupTable< E, V > FLT
virtual ~AStarRouter()
Destructor.
bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E * > &into, bool silent=false)
Builds the route between the given edges using the minimum travel time.
AStarRouter(const std::vector< E * > &edges, bool unbuildIsWarning, typename SUMOAbstractRouter< E, V >::Operation operation, const std::shared_ptr< const LookupTable > lookup=nullptr, const bool havePermissions=false, const bool haveRestrictions=false)
Constructor.
AStarRouter(const std::vector< typename SUMOAbstractRouter< E, V >::EdgeInfo > &edgeInfos, bool unbuildIsWarning, typename SUMOAbstractRouter< E, V >::Operation operation, const std::shared_ptr< const LookupTable > lookup=nullptr, const bool havePermissions=false, const bool haveRestrictions=false)
LandmarkLookupTable< E, V > LMLT
AbstractLookupTable< E, V > LookupTable
virtual SUMOAbstractRouter< E, V > * clone()
const std::shared_ptr< const LookupTable > myLookupTable
the lookup table for travel time heuristics
Computes the shortest path through a network using the A* algorithm.
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
void informf(const std::string &format, T value, Targs... Fargs)
adds a new formatted message
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
Static storage of an output device and its base (abstract) implementation.
void close()
Closes the device and removes it from the dictionary.
static OutputDevice & getDevice(const std::string &name, bool usePrefix=true)
Returns the described OutputDevice.
const E *const edge
The current edge.
double heuristicEffort
Estimated effort to reach the edge (effort + lower bound on remaining effort)
MsgHandler *const myErrorMsgHandler
the handler for routing errors
const bool myHavePermissions
whether edge permissions need to be considered
bool myBulkMode
whether we are currently operating several route queries in a bulk
std::vector< typename SUMOAbstractRouter< E, V >::EdgeInfo > myEdgeInfos
The container of edge information.
Operation myOperation
The object's operation to perform.
double getTravelTime(const E *const e, const V *const v, const double t, const double effort) const
double getEffort(const E *const e, const V *const v, double t) const
void updateViaEdgeCost(const E *viaEdge, const V *const v, double &time, double &effort, double &length) const
void init(const int edgeID, const SUMOTime msTime)
bool myAmClean
whether we are already initialized
const bool myHaveRestrictions
whether edge restrictions need to be considered
void buildPathFrom(const typename SUMOAbstractRouter< E, V >::EdgeInfo *rbegin, std::vector< const E * > &edges)
Builds the path from marked edges.
virtual double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
void endQuery(int visits)
std::vector< typename SUMOAbstractRouter< E, V >::EdgeInfo * > myFrontierList
A container for reusage of the min edge heap.
std::vector< typename SUMOAbstractRouter< E, V >::EdgeInfo * > myFound
list of visited Edges (for resetting)
static std::string replace(std::string str, const std::string &what, const std::string &by)
Replaces all occurrences of the second string by the third string within the first string.