X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Froute.cpp;h=ace8d0b950812c56a22e23a0ba381f4d389b9f7b;hb=f06c2b89a2601981aae84d0f971c07816dc1bab4;hp=2ff6962fe67551a17be8bde9052595b6933bf171;hpb=9ddcd066e37e4c72685817c042c30897786ece05;p=r2c2.git diff --git a/source/libmarklin/route.cpp b/source/libmarklin/route.cpp index 2ff6962..ace8d0b 100644 --- a/source/libmarklin/route.cpp +++ b/source/libmarklin/route.cpp @@ -19,6 +19,8 @@ namespace { using namespace Marklin; +typedef std::pair Key; + struct Node { const Track *track; @@ -63,8 +65,7 @@ struct TrackInRoute template list dijkstra(const Track &from, unsigned ep, const Pred &goal) { - // XXX Fails to find some routes - should use track+ep as key - map track_nodes; + map track_nodes; priority_queue nodes; Node *final = 0; @@ -75,10 +76,11 @@ list dijkstra(const Track &from, unsigned ep, const Pred &goal) Node lowest = nodes.top(); nodes.pop(); - if(track_nodes.count(lowest.track)) + Key key(lowest.track, lowest.ep); + if(track_nodes.count(key)) continue; - Node &ref = track_nodes[lowest.track] = lowest; + Node &ref = track_nodes[key] = lowest; if(goal(*lowest.track)) { final = &ref; @@ -90,7 +92,11 @@ list dijkstra(const Track &from, unsigned ep, const Pred &goal) const vector &links = lowest.track->get_links(); for(unsigned i=0; iget_endpoint_by_link(*lowest.track); + if(track_nodes.count(Key(links[i], link_ep))) continue; unsigned mask = eps[i].paths&eps[lowest.ep].paths;