Repository navigation
Improvement of landmark weight precision, issue 1080 - #1376
Conversation
I changed the way the landmark weights are stored from having two shorts (one for the forward and one for the backward value) to having 18 bits for the backward value and 14 bits for the difference between theese two.
karussell
left a comment
There was a problem hiding this comment.
Cool - thanks a lot! This looks good already.
Did you test the performance and average precision improvement e.g. for German area?
Also please apply the Java formatting via e.g. Ctrl+Alt+L (Code->Reformat Code)
| LOGGER.warn("landmark " + lmIdx + " (" + nodeAccess.getLatitude(lmNodeId) + "," + nodeAccess.getLongitude(lmNodeId) + "): " + | ||
| "too many delta weights were maxed out (" + maxedout.get() + "/" + map.size() + "). Use a bigger factor than " + lms.factor | ||
| + ". For example use the following in the config.properties: weighting=" + weighting.getName() + "|maximum=" + finalMaxWeight.getValue() * 1.2); | ||
| } |
There was a problem hiding this comment.
Here probably it can make sense to use the short "if-then-else" form within the string like
LOGGER.warn("blup" + (from? "too many backward weights" : "too many delta weights")
| int res = landmarkWeightDA.getInt((long) node * LM_ROW_LENGTH + landmarkIndex * 4); | ||
|
|
||
| //the right bits of "res" store the backward value | ||
| int from = res & FROM_WEIGHT_INF; |
There was a problem hiding this comment.
This statement could be moved after the if to avoid this in case of the specific delta (?)
| ghStorage.edge(14, 15, distance, true); | ||
|
|
||
| LandmarkStorage storage = new LandmarkStorage(ghStorage, new RAMDirectory(), new FastestWeighting(encoder), 2); | ||
| storage.createLandmarks(); //landmarks: 15, 9 |
There was a problem hiding this comment.
Instead of a comment it would be better to assert the actual landmark node ids (?)
| ghStorage.edge(11, 12, distance, true); | ||
|
|
||
| LandmarkStorage storage = new LandmarkStorage(ghStorage, new RAMDirectory(), new FastestWeighting(encoder), 2); | ||
| storage.createLandmarks(); //landmarks: 12, 9 |
There was a problem hiding this comment.
Here we should assert something :)
The logging statement cannot be checked automatically but maybe the maxed out value and the actual landmark nodeIDs?
|
|
||
| /* FROM_WEIGHT_BITS = 18 --> remaining bits: 32-18 = 14 | ||
| The delta value is signed and will therefore go from -2^(14-1) to 2^(14-1). | ||
| Now 2^13-1 is used for infinity, 2^13-2 as maximum and -2^13 as minimum. |
There was a problem hiding this comment.
Ah, thanks for the reminder that delta can be pos+neg unlike the forward value 👍
|
I updated the files at the lines you marked :)
Hm I don't really know how to test this |
Ups, sorry. I should have mentioned this. You can create a measurement properties file if you run Or the equivalent java main class Measurement.java with programm arguments like here and then the properties file contains |
|
I ran both versions twice for Germany and got these results: old: new: This makes on average 343 s for the old version and 352 s for the new one to prepare the landmarks, which is about 3% slower. However, the routing is about 12% faster, taking only 68 ms instead on 77 ms. |
|
This sounds really good. Will try. Why do you think could it be over 10% faster? Because instead of fetching two |
I'm not sure if this is the reason, because the new version also fetches two |
Is this improvement reproducible? Could be just a random anomaly? |
You can run the measurement multiple (maybe 10 or so) times and print a table of the results with the new flags in the measurement class: #1366 to get a better picture. |
|
I ran both another 8 times with these results: old: new: Now the values vary much more than before. On average I got 78 ms for the old and 74 ms for the new which makes a (much more realistic) improvement of about 5%. Looks like I had two lucky rounds before^^ |
|
I merged the master but it seems that also before the merge the tests were failing. Can you run the tests and see what went wrong? (Either command line |
|
Sorry this took a bit too long here to merge, but we really needed to test this out on a large scale setup and compare this to the very recent versions. Now, this is a massive improvement in terms of visited nodes and therefore speed and maximum possible travel distance for continental requests with ch.disable=true. I'll try to merge this fast ... I'll just include a version number so that previous data imports are not possible to load. |
|
@baumboi do you have an updated version where the tests run through? |
|
With this new file all tests should run correctly. I added a minimal factor of 0.1 which prevents the weightings from being too large in small graphs (e.g. Monaco in RoutingAlgorithmWithOSMIT). I also changed the default weighting to infinity. Therefore weightings to unreachable nodes will return |
|
Thanks a lot!
Will fix in this branch. |
|
I have now fixed the compiling issue, but it seems it creates much more of those warnings for the test cases now with the limitation of the factor to 0.1 Couldn't we increase the PRECISION now to 18 or even more bits? |
|
The warning regarding "maxed out" values is somehow wrong. Is the following correct?
Have a look at my next commit that also avoids a global limit at 0.1 Maybe this is also the reason PRECISION can stay at 16. |
Basically yes, but this would also mean, that more weights get maxed out. With
I think for both cases we need to decrease the precision (--> increasing the factor), in order to reduce the value we store. |
Thanks, makes sense!
No problem. Currently doing a world wide import again and will report about PRECISION=16
Thanks for the clarification, will fix this in the code |
|
Thanks for the nice improvement @baumboi.
Did you find out anything about the precision @karussell? If I understand this correctly, there is no need to adjust an already set maximum in the config? But due to the increased precision the A* heuristic will work better and also this will reduce the Likelihood of rounding errors when two almost similar weights are stored, because a better precision and lower factor? |
|
Yes, 16 works better in the sense that we have less maxed out weights leading to a performance improvement as less nodes will be visited due to the improved heuristic |
|
Thanks for reporting your findings :) |
I changed the storage of landmark heuristics from two shorts (one for the forward and one for the backward weight) to one integer with 18 bits storing the backward weight and 14 bits storing the difference between theese values. Therefore the maximum value which can be stored rises from 65534 (=2^16-2) to 262142 (=2^18-2). You can also use other bit combinations like 20/12 which would allow to store values of up to 1048574 (=2^20-2) at the expense of reducing the range of the delta value.
However, the new getToWeight function may be slightly slower since it has to get both, the backward and delta weight, and add them together.
I also added some tests to prove the correctness of the landmark storage. Please note that testSetGetWeight and testDelta will only work with the current bit combination 18/14 and need to be edited if you change it.
Fixes #1080