Skip to content

ALT algorithm for a more dynamic speed up - #780

Merged
karussell merged 43 commits into
masterfrom
landmarks
Feb 22, 2017
Merged

karussell merged 43 commits into
masterfrom
landmarks

Conversation

@karussell

@karussell karussell commented Aug 26, 2016 •

Copy link
Copy Markdown
Member

I've developed over the last months a new speed up algorithm (actually the initial prototype was done in a day ;))

Enable with:

  • prepare.lm.weightings=fastest in the config.properties
  • append &ch.disable=true if CH is enabled

The speedup is 17x faster compared to the fastest flexible algorithm (A* with a distance estimate) for German wide random requests and 16 landmarks. It is 25x faster with 32 landmarks.

The per-request memory improvements are in a similar range i.e. ~X times faster means ~X times less visited nodes. The static memory requirements are comparable to CH for world wide case and 16 landmarks. More memory for more landmarks.

Some other good properties are:

  • Optimal routes. 'heuristical nature' can be introduced but yields only a minor speedup (e=1.3) and if epsilon similar chosen like suggested in Speed comparison for A* #506 (e=1.6) it is even much worse.
  • The LM preparation can be parallelized and should be possible within a few minutes even for world wide coverage
  • A recalculation of the preparation is not strictly necessary if e.g. traffic jams ("slow downs" only)
  • Works with edged_based and also with turn costs and restrictions
  • Works for all other properties like pass_through etc or if you would want to exclude ferries or motorways
  • Could be used for time-dependent edge properties
  • A "fastest car" preparation could be re-used for motorcycles (but not the otherway around, property of underestimation most hold)

There are only a few remaining TODOs:

  • for larger areas like Europe we need: calculate factor to scale weight better into one short (e.g. currently truncated at 65K making it ugly for larger areas)
  • for world wide we need: make subnetworks working via landmark mapping and just select e.g. the largest 32 subnetworks. This is also easy and I'm glad I found this memory efficient solution. Also every node will get a subnetwork id and we can easily decide before a request if the route will be found.
  • add integration tests
  • fallback to beeline approximation if weight is too big. This could boost performance for large areas, test this.
  • force picking the landmarks location being always accessible in both directions => not necessary if we find subnetworks via Tarjan algo and still keeps e.g. norway and UK connected
  • Print warning if too many (>10%) entries maxed out.
  • use ConnectionNotFoundException instead of runtime exception
  • test with edge based & turn costs
  • make alternatives working with landmarks
  • better heuristic for landmark picking, currently some landmarks are too close to be efficiently used. This will boost performance and hopefully reduce the boost factor variation
  • clean up spatial index integration but merge specific PR before web/src/main/java/com/graphhopper/http/DefaultModule.java
  • use landmarks from a file

Hint: use graph.do_sort=true for 5-10% better routing and preparation performance

Later

  • faster and parallel landmark finding
  • avoid searching for every profile via reusing landmarks of previous weighting?
  • test and make "cross weighting usage" working (e.g. motorcycle uses precalculated car weights)
  • although CH and LM are combineable LM actually slows down CH. Investigate this.
  • use ALT for faster CH preparation

@karussell karussell added this to the 0.8 milestone Aug 26, 2016
@karussell karussell changed the title ALT algorithm for alternate, more dynamic speed up ALT algorithm for a more dynamic speed up Aug 26, 2016
@devemux86

Copy link
Copy Markdown
Contributor

@karussell impressive stats and properties!

@karussell karussell removed this from the 0.8 milestone Oct 10, 2016
@karussell karussell mentioned this pull request Oct 14, 2016
@karussell karussell added this to the 0.9 milestone Dec 10, 2016
@karussell

karussell commented Dec 10, 2016 •

Copy link
Copy Markdown
Member Author

This is now rebased to latest master. (A bit ugly that too many unrelated changes were made due to code formatting changes in-between, but fixing this is not that important here IMO)

It finally works for EU-wide queries and should work world wide, so that we can include this in 0.9 after some TODOs are solved (updated them above)

The main things I've fiddling with were related with subnetwork issues, which are now covered in the tests.

Now we detect if two nodes are in the same subnetwork and only then proceed with this landmark-approach otherwise use the beeline algorithm. And so we have to store the subnetwork ID per node, which made the SubnetworkStorage necessary. Furthermore we need a special landmark-mapping (2) so that we know which node IDs the landmarks have in which subnetwork, so that we can still use only one large array, where we store all the weights of the landmarks (1). So the data structures are as follows:

SubnetworkStorage.da: just a large byte array storing the subnetwork ID for every node

LandmarkStorage.landmarkWeightDA: (1) the first bytes of this DataAccess store the landmark weights:

      |  from weight lm1 | to weight lm1 | from lm2    | to lm2 | ...
--------------------------------------------------------------------------------------
node1 |  short value     | short value   | short value |
--------------------------------------------------------------------------------------
node2 | ...

and (2) then the landmark-subnetwork mapping follows:

            |  landmark1   | landmark2    | ...
--------------------------------------------------------------------------------------
subnetwork1 |  int node id | int node id  | ...
--------------------------------------------------------------------------------------
subnetwork2 | ...

@karussell

karussell commented Dec 11, 2016 •

Copy link
Copy Markdown
Member Author

It is interesting how the visited nodes area (yellow) varies with only minor changes to the start&end location (route is blue). There is probably potential to improve this or some bug - maybe related to some overflow or too imprecise storage of the weights (using only short)?

alt-visited-nodes

The subnetworks still make problems for world wide import :(

@boldtrn

boldtrn commented Dec 11, 2016

Copy link
Copy Markdown
Member

Excellent progress @karussell.

It is interesting how the visited nodes area (yellow) varies with only minor changes to the start&end location (route is blue). There is probably potential to improve this or some bug - maybe related to some overflow or too imprecise storage of the weights (using only short)?

Do you think this is a bug? My first impression (really just an impression, I have nothing to support this) is that you placed the points in the upper picture at a location that might be valid for taking two possible "good highways". When looking at the right point in the upper picture you can see how the other reasonable good highway was followed for some time (the yellow line going north/east). It is hard to explain :). But maybe I am wrong?

@karussell

Copy link
Copy Markdown
Member Author

I do not know if this is a bug, have not much investigated yet. Before I thought the starting and ending area looked strange as there were sometimes many yellow nodes, but now the more I think about it it is probably how the algo works ...

@karussell

karussell commented Dec 15, 2016 •

Copy link
Copy Markdown
Member Author

Finally it 'works' world wide. The remaining problem is that the landmark count for EU+Asia+Africa is too small (when using 16) as those areas are connected via 'landline' and ferries, see this. Not sure about the perfect solution. We could disconnect those via introducing border restrictions, increase the landmarks (will try now), artificially introduce subnetworks for the landmarks or something.

5 subnetworks were created: EU+Asia+Africa; Australia; Northern America; Southern America; Malaysia. Strange, where is Japan? One big enough subnetwork near Malaysia (>500K nodes) still has problems to create the landmarks: "next start node not found in big enough network of size 806392, first element is 103853491, 5.515810225512316,95.84255935644863"

BTW: creating the landmark weights takes ~70 minutes for car with 16 landmarks, i.e. roughly 5min per landmark. Including subnetwork calculation, landmark assignment and finally the weight calculation for every subnetwork.

@karussell

Copy link
Copy Markdown
Member Author

As we need more separated areas e.g. to split EU/Asia/Africa into its parts we could also need #926

// 1a) pick landmarks via shortest weighting for a better geographical spreading
// 'fastest' has big problems with ferries (slow&very long) and allowing arbitrary weighting is too dangerous
Weighting initWeighting = lmSelectionWeighting;
Explorer explorer = new Explorer(graph, this, initWeighting, traversalMode);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought at first this would be the EdgeExplorer. Maybe explicitly call this LandmarkExplorer?

}

public boolean setSubnetworks(final byte[] subnetworks, final int subnetworkId) {
if (subnetworkId > 127)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this in a variable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not variable ;(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, put it in a constant, sorry ;).

@karussell

Copy link
Copy Markdown
Member Author

Thanks for the review will do what you said and also try to be more descriptive in code and with more javadocs.

@boldtrn

boldtrn commented Feb 2, 2017

Copy link
Copy Markdown
Member

Thanks for the review will do what you said and also try to be more descriptive in code and with more javadocs.

Sorry I was really picky with the naming this time. I tried to understand what was happening and just saw that in some cases the names didn't reflected the logic :).

@karussell

karussell commented Feb 20, 2017 •

Copy link
Copy Markdown
Member Author

I've added the possibility to use hand picked landmarks instead of calculated once per subnetwork, which is not only faster but >2 times faster for country sized areas.

Will change as requested now and include the spatial index stuff to split the area in smaller subnetworks (only for world wide scenario) for better speed of landmarks.

* This method calculates the landmarks and initial weightings to & from them.
*/
public void createLandmarks() {
public void createLandmarksForSubnetwork() {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, it looks like intelliJ has renamed this at the same time ;)

@karussell

Copy link
Copy Markdown
Member Author

BTW: I found that the spatial index json (map.geo.json) had lots of IDs "-99". Now that we throw exceptions in those duplicative cases I had to edit this field and stumbled over e.g. France where this was obviously incorrect (FRA) and also for Norway (NOR). For the others I've just put an increasing counter before the -99 ...

@karussell

karussell commented Feb 20, 2017 •

Copy link
Copy Markdown
Member Author

Three last steps to make this mergable (if no other objections :))

  • unit tests for splitting the areas according to the SpatialRuleLookup
  • run again world wide and test if flexible mode is able to cross some of the "special area" border which will fail for the landmark routing via 'connection not found'.

@boldtrn

boldtrn commented Feb 20, 2017

Copy link
Copy Markdown
Member

BTW: I found that the spatial index json (map.geo.json) had lots of IDs "-99". Now that we throw exceptions in those duplicative cases I had to edit this field and stumbled over e.g. France where this was obviously incorrect (FRA) and also for Norway (NOR).

Oh, I missed that. There is actually an issue open for that. Sorry for the troubles. datasets/geo-countries#5

@karussell

Copy link
Copy Markdown
Member Author

I've added the possibility to use hand picked landmarks instead of calculated once per subnetwork, which is not only faster but >2 times faster for country sized areas.

This is no longer true - I've tuned autopicking landmarks with a simple trick using no 'fastest' or 'shortest' weighting but just use BFS and return 1 as weighting which leads to 5% faster landmarks than handpicked and roughly 22x faster response times for Germany (22x faster on average!).

@karussell

karussell commented Feb 21, 2017 •

Copy link
Copy Markdown
Member Author

Oh, I missed that. There is actually an issue open for that. Sorry for the troubles.

No trouble at all - it was detected & fixed in <5min :)

… using weight==1 instead distance; split area only for LM preparation and add unit test; fix factor calculation for small areas; make it possible to load split area geojson from file
@karussell

Copy link
Copy Markdown
Member Author

Nice, everything works, also world wide with even better response times after the recent weighting change. Will merge after a few cosmetics.

@karussell
karussell merged commit e085c0b into master Feb 22, 2017
@karussell

Copy link
Copy Markdown
Member Author

Merge now.

I had to made a few minor changes to the spatialrule lookup @boldtrn please have a look if this is ok.

@boldtrn

boldtrn commented Feb 22, 2017

Copy link
Copy Markdown
Member

Awesome! Happy to see this feature merged.

I had to made a few minor changes to the spatialrule lookup @boldtrn please have a look if this is ok.

Looks good to me. The factory is a good idea. So it's easy to inject custom SpatialRules 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants