62 template<
class E,
class V,
class BASE>
67 typedef double(*
Operation)(
const E*
const,
const V*
const, double);
79 traveltime(std::numeric_limits<double>::max()),
97 traveltime = std::numeric_limits<double>::max();
104 typedef std::pair<const EdgeInfo*, const EdgeInfo*>
Meeting;
114 myAmForward(forward),
116 for (
typename std::vector<E*>::const_iterator i = edges.begin(); i != edges.end(); ++i) {
117 myEdgeInfos.push_back(
EdgeInfo(*i));
122 return myFound.count(edge) > 0;
126 return &(myEdgeInfos[edge->getNumericalID()]);
130 return &(myEdgeInfos[edge->getNumericalID()]);
142 return nod1->
edge->getNumericalID() > nod2->
edge->getNumericalID();
149 void init(
const E*
const start,
const V*
const vehicle) {
150 assert(vehicle != 0);
152 for (
typename std::vector<EdgeInfo*>::iterator i = myFrontier.begin(); i != myFrontier.end(); i++) {
156 for (
typename std::set<const E*>::const_iterator i = myFound.begin(); i != myFound.end(); i++) {
157 getEdgeInfo(*i)->reset();
161 EdgeInfo* startInfo = getEdgeInfo(start);
164 myFrontier.push_back(startInfo);
173 bool step(
const std::vector<ConnectionVector>& uplinks,
const Unidirectional& otherSearch,
double& minTTSeen, Meeting& meeting) {
175 EdgeInfo*
const minimumInfo = myFrontier.front();
176 pop_heap(myFrontier.begin(), myFrontier.end(), myComparator);
177 myFrontier.pop_back();
179 const E*
const minEdge = minimumInfo->
edge;
180 #ifdef CHRouter_DEBUG_QUERY 181 std::cout <<
"DEBUG: " << (myAmForward ?
"Forward" :
"Backward") <<
" hit '" << minEdge->getID() <<
"' Q: ";
182 for (
typename std::vector<EdgeInfo*>::iterator it = myFrontier.begin(); it != myFrontier.end(); it++) {
183 std::cout << (*it)->traveltime <<
"," << (*it)->edge->getID() <<
" ";
187 if (otherSearch.
found(minEdge)) {
190 #ifdef CHRouter_DEBUG_QUERY 191 std::cout <<
"DEBUG: " << (myAmForward ?
"Forward" :
"Backward") <<
"-Search hit other search at '" << minEdge->getID() <<
"', tt: " << ttSeen <<
" \n";
193 if (ttSeen < minTTSeen) {
196 meeting.first = minimumInfo;
197 meeting.second = otherInfo;
199 meeting.first = otherInfo;
200 meeting.second = minimumInfo;
207 myFound.insert(minimumInfo->
edge);
208 const ConnectionVector& upward = uplinks[minEdge->getNumericalID()];
209 for (
typename ConnectionVector::const_iterator it = upward.begin(); it != upward.end(); it++) {
210 EdgeInfo* upwardInfo = &myEdgeInfos[it->target];
214 if ((it->permissions & svc) != svc) {
217 const double oldTraveltime = upwardInfo->
traveltime;
218 if (!upwardInfo->
visited && traveltime < oldTraveltime) {
220 upwardInfo->
prev = minimumInfo;
221 if (oldTraveltime == std::numeric_limits<double>::max()) {
222 myFrontier.push_back(upwardInfo);
223 push_heap(myFrontier.begin(), myFrontier.end(), myComparator);
225 push_heap(myFrontier.begin(),
226 find(myFrontier.begin(), myFrontier.end(), upwardInfo) + 1,
236 return !myFrontier.empty() && myFrontier.front()->traveltime < minTTSeen;
260 CHRouter(
const std::vector<E*>& edges,
bool unbuildIsWarning,
typename BASE::Operation operation,
263 bool validatePermissions):
264 BASE(
"CHRouter", operation),
278 CHRouter(
const std::vector<E*>& edges,
bool unbuildIsWarning,
typename BASE::Operation operation,
282 BASE(
"CHRouterClone", operation),
315 virtual bool compute(
const E* from,
const E* to,
const V*
const vehicle,
316 SUMOTime msTime, std::vector<const E*>& into) {
317 assert(from != 0 && to != 0);
330 double minTTSeen = std::numeric_limits<double>::max();
331 Meeting meeting(static_cast<EdgeInfo*>(0), static_cast<EdgeInfo*>(0));
332 bool continueForward =
true;
333 bool continueBackward =
true;
334 int num_visited_fw = 0;
335 int num_visited_bw = 0;
337 while (continueForward || continueBackward) {
338 if (continueForward) {
342 if (continueBackward) {
347 if (minTTSeen < std::numeric_limits<double>::max()) {
350 myErrorMsgHandler->
inform(
"No connection between edge '" + from->getID() +
"' and edge '" + to->getID() +
"' found.");
353 #ifdef CHRouter_DEBUG_QUERY_PERF 354 std::cout <<
"visited " << num_visited_fw + num_visited_bw <<
" edges (" << num_visited_fw <<
"," << num_visited_bw <<
") ,final path length: " +
toString(into.size()) +
")\n";
356 this->endQuery(num_visited_bw + num_visited_fw);
364 std::deque<const E*> tmp;
365 const EdgeInfo* backtrack = meeting.first;
366 while (backtrack != 0) {
367 tmp.push_front((E*) backtrack->
edge);
368 backtrack = backtrack->
prev;
370 backtrack = meeting.second->
prev;
371 while (backtrack != 0) {
372 tmp.push_back((E*) backtrack->
edge);
373 backtrack = backtrack->
prev;
377 while (!tmp.empty()) {
378 const E* cur = tmp.front();
384 const E* via =
getVia(prev, cur);
411 const E*
getVia(
const E* forwardFrom,
const E* forwardTo)
const {
Computes the shortest path through a contracted network.
const SUMOVehicleClass mySVC
the permissions for which the hierarchy was constructed
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
SUMOTime myValidUntil
the validity duration of the current hierarchy (exclusive)
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
bool operator()(const EdgeInfo *nod1, const EdgeInfo *nod2) const
Comparing method.
std::vector< typename CHBuilder< E, V >::Connection > ConnectionVector
void buildContractionHierarchy(SUMOTime time, const V *const vehicle)
std::string time2string(SUMOTime t)
void init(const E *const start, const V *const vehicle)
EdgeInfo * prev
The previous edge.
void buildPathFromMeeting(Meeting meeting, std::vector< const E *> &into) const
normal routing methods
virtual ~CHRouter()
Destructor.
std::vector< EdgeInfo * > myFrontier
the min edge heap
CHRouter(const std::vector< E *> &edges, bool unbuildIsWarning, typename BASE::Operation operation, const SUMOVehicleClass svc, SUMOTime weightPeriod, bool validatePermissions)
Constructor.
Unidirectional myBackwardSearch
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
const CHBuilder< E, V >::Hierarchy * myHierarchy
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 traveltime in the contracted graph...
std::vector< EdgeInfo > myEdgeInfos
The container of edge information.
double traveltime
Effort to reach the edge.
const E * getVia(const E *forwardFrom, const E *forwardTo) const
bool visited
Whether the shortest path to this edge is already found.
const std::vector< E * > & myEdges
all edges with numerical ids
MsgHandler *const myErrorMsgHandler
the handler for routing errors
std::pair< const E *, const E * > ConstEdgePair
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
EdgeInfo(const E *e)
Constructor.
std::set< const E * > myFound
the set of visited (settled) Edges
const SUMOTime myWeightPeriod
the validity duration of one weight interval
const E * edge
The current edge.
void inform(std::string msg, bool addType=true)
adds a new error to the list
double(* Operation)(const E *const, const V *const, double)
Type of the function that is used to retrieve the edge effort.
std::pair< const EdgeInfo *, const EdgeInfo * > Meeting
A meeting point of the two search scopes.
EdgeInfo * getEdgeInfo(const E *const edge)
Unidirectional(const std::vector< E *> &edges, bool forward)
Constructor.
Unidirectional myForwardSearch
the unidirectional search queues
virtual SUMOAbstractRouter< E, V > * clone()
bool myAmForward
the role of this search
bool found(const E *edge) const
#define WRITE_MESSAGE(msg)
const EdgeInfo * getEdgeInfo(const E *const edge) const
EdgeInfoByTTComparator myComparator
bool step(const std::vector< ConnectionVector > &uplinks, const Unidirectional &otherSearch, double &minTTSeen, Meeting &meeting)
explore on element from the frontier,update minTTSeen and meeting if an EdgeInfo found by the otherSe...
CHBuilder< E, V > * myHierarchyBuilder
CHRouter(const std::vector< E *> &edges, bool unbuildIsWarning, typename BASE::Operation operation, const SUMOVehicleClass svc, SUMOTime weightPeriod, const typename CHBuilder< E, V >::Hierarchy *hierarchy)
Cloning constructor.