49 #define UNREACHABLE (std::numeric_limits<double>::max() / 1000.0) 76 template<
class E,
class V,
class BASE>
93 traveltime(std::numeric_limits<double>::max()),
116 traveltime = std::numeric_limits<double>::max();
131 return nod1->
edge->getNumericalID() > nod2->
edge->getNumericalID();
138 AStarRouter(
const std::vector<E*>& edges,
bool unbuildIsWarning,
typename BASE::Operation operation,
const LookupTable*
const lookup = 0) :
139 BASE(
"AStarRouter", operation),
143 for (
typename std::vector<E*>::const_iterator i = edges.begin(); i != edges.end(); ++i) {
149 AStarRouter(
const std::vector<EdgeInfo>& edgeInfos,
bool unbuildIsWarning,
typename BASE::Operation operation,
const LookupTable*
const lookup = 0) :
150 BASE(
"AStarRouter", operation),
154 for (
typename std::vector<EdgeInfo>::const_iterator i = edgeInfos.begin(); i != edgeInfos.end(); ++i) {
173 for (
typename std::vector<EdgeInfo*>::iterator i =
myFound.begin(); i !=
myFound.end(); i++) {
181 virtual bool compute(
const E* from,
const E* to,
const V*
const vehicle,
182 SUMOTime msTime, std::vector<const E*>& into) {
183 assert(from != 0 && to != 0);
185 if (this->isProhibited(from, vehicle)) {
186 myErrorMsgHandler->
inform(
"Vehicle '" + vehicle->getID() +
"' is not allowed on source edge '" + from->getID() +
"'.");
189 if (this->isProhibited(to, vehicle)) {
190 myErrorMsgHandler->
inform(
"Vehicle '" + vehicle->getID() +
"' is not allowed on destination edge '" + to->getID() +
"'.");
194 #ifdef ASTAR_DEBUG_QUERY 195 std::cout <<
"DEBUG: starting search for '" << vehicle->getID() <<
"' speed: " <<
MIN2(vehicle->getMaxSpeed(),
myMaxSpeed * vehicle->getChosenSpeedFactor()) <<
" time: " <<
STEPS2TIME(msTime) <<
"\n";
199 if (this->myBulkMode) {
201 if (toInfo.visited) {
210 fromInfo->traveltime = 0;
217 const double speed = vehicle ==
nullptr ?
myMaxSpeed :
MIN2(vehicle->getMaxSpeed(),
myMaxSpeed * vehicle->getChosenSpeedFactor());
222 const E*
const minEdge = minimumInfo->edge;
226 this->endQuery(num_visited);
227 #ifdef ASTAR_DEBUG_QUERY_PERF 228 std::cout <<
"visited " +
toString(num_visited) +
" edges (final path length=" +
toString(into.size())
229 +
" time=" +
toString(recomputeCosts(into, vehicle, msTime))
230 +
" edges=" +
toString(into) +
")\n";
232 #ifdef ASTAR_DEBUG_VISITED 234 for (
typename std::vector<EdgeInfo>::const_iterator i =
myEdgeInfos.begin(); i !=
myEdgeInfos.end(); ++i) {
236 dev <<
"edge:" << i->edge->getID() <<
"\n";
245 myFound.push_back(minimumInfo);
246 minimumInfo->visited =
true;
247 #ifdef ASTAR_DEBUG_QUERY 248 std::cout <<
"DEBUG: hit=" << minEdge->getID()
249 <<
" TT=" << minimumInfo->traveltime
250 <<
" EF=" << this->getEffort(minEdge, vehicle, time + minimumInfo->traveltime)
251 <<
" HT=" << minimumInfo->heuristicTime
252 <<
" Q(TT,HT,Edge)=";
254 std::cout << (*it)->traveltime <<
"," << (*it)->heuristicTime <<
"," << (*it)->edge->getID() <<
" ";
258 const double traveltime = minimumInfo->traveltime + this->getEffort(minEdge, vehicle, time + minimumInfo->traveltime);
260 const double heuristic_remaining = (
myLookupTable == 0 ? minEdge->getDistanceTo(to) / speed :
261 myLookupTable->
lowerBound(minEdge, to, speed, vehicle->getChosenSpeedFactor(), minEdge->getMinimumTravelTime(0), to->getMinimumTravelTime(0)));
266 const std::vector<E*>& successors = minEdge->getSuccessors(vClass);
267 for (
typename std::vector<E*>::const_iterator it = successors.begin(); it != successors.end(); ++it) {
268 const E*
const follower = *it;
271 if (this->isProhibited(follower, vehicle)) {
274 const double oldEffort = followerInfo->traveltime;
275 if ((!followerInfo->visited || mayRevisit) && traveltime < oldEffort) {
277 followerInfo->heuristicTime = traveltime + heuristic_remaining;
289 #ifdef ASTAR_DEBUG_QUERY_FOLLOWERS 290 std::cout <<
" follower=" << followerInfo->edge->getID() <<
" OEF=" << oldEffort <<
" TT=" << traveltime <<
" HR=" << heuristic_remaining <<
" HT=" << followerInfo->heuristicTime <<
"\n";
292 followerInfo->prev = minimumInfo;
293 if (oldEffort == std::numeric_limits<double>::max()) {
309 this->endQuery(num_visited);
310 #ifdef ASTAR_DEBUG_QUERY_PERF 311 std::cout <<
"visited " +
toString(num_visited) +
" edges (unsuccesful path length: " +
toString(into.size()) +
")\n";
313 myErrorMsgHandler->
inform(
"No connection between edge '" + from->getID() +
"' and edge '" + to->getID() +
"' found.");
320 std::vector<const E*> tmp;
321 while (rbegin != 0) {
322 tmp.push_back(rbegin->edge);
323 rbegin = rbegin->prev;
325 std::copy(tmp.rbegin(), tmp.rend(), std::back_inserter(edges));
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
void close()
Closes the device and removes it from the dictionary.
AStarRouter(const std::vector< E *> &edges, bool unbuildIsWarning, typename BASE::Operation operation, const LookupTable *const lookup=0)
Constructor.
const E * edge
The current edge.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
FullLookupTable< E, V > FLT
std::vector< EdgeInfo > myEdgeInfos
The container of edge information.
double traveltime
Effort to reach the edge.
std::string time2string(SUMOTime t)
Computes the shortest path through a network using the A* algorithm.
std::vector< EdgeInfo * > myFrontierList
A container for reusage of the min edge heap.
const LookupTable *const myLookupTable
the lookup table for travel time heuristics
void buildPathFrom(const EdgeInfo *rbegin, std::vector< const E *> &edges)
Builds the path from marked edges.
bool operator()(const EdgeInfo *nod1, const EdgeInfo *nod2) const
Comparing method.
virtual ~AStarRouter()
Destructor.
MsgHandler *const myErrorMsgHandler
the handler for routing errors
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
double myMaxSpeed
maximum speed in the network
EdgeInfo * prev
The previous edge.
virtual bool consistent() const =0
whether the heuristic ist consistent (found nodes are always visited on the shortest path the first t...
virtual SUMOAbstractRouter< E, V > * clone()
double heuristicTime
Estimated time to reach the edge (traveltime + lower bound on remaining time)
AStarRouter(const std::vector< EdgeInfo > &edgeInfos, bool unbuildIsWarning, typename BASE::Operation operation, const LookupTable *const lookup=0)
EdgeInfo(const E *e)
Constructor.
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E *> &into)
Builds the route between the given edges using the minimum travel time.
AbstractLookupTable< E, V > LookupTable
virtual double lowerBound(const E *from, const E *to, double speed, double speedFactor, double fromEffort, double toEffort) const =0
provide a lower bound on the distance between from and to (excluding traveltime of both edges) ...
std::vector< EdgeInfo * > myFound
list of visited Edges (for resetting)
EdgeInfoComparator myComparator
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
void inform(std::string msg, bool addType=true)
adds a new error to the list
Static storage of an output device and its base (abstract) implementation.
Computes the shortest path through a network using the A* algorithm.
LandmarkLookupTable< E, V > LMLT
vehicles ignoring classes
bool visited
The previous edge.