Skip to content

Improvement of landmark weight precision, issue 1080 - #1376

Merged
karussell merged 14 commits into
graphhopper:masterfrom
baumboi:issue_1080
Sep 14, 2018
Merged

karussell merged 14 commits into
graphhopper:masterfrom
baumboi:issue_1080

Conversation

@baumboi

@baumboi baumboi commented May 21, 2018 •

Copy link
Copy Markdown
Contributor

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

baumboi added 2 commits May 21, 2018 16:12
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
karussell self-requested a review May 22, 2018 18:58

@karussell karussell left a comment

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.

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);
}

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.

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;

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.

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

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.

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

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.

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.

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.

Ah, thanks for the reminder that delta can be pos+neg unlike the forward value 👍

@karussell karussell changed the title Issue 1080 Improvement of landmark weight precision, issue 1080 May 23, 2018
@baumboi

baumboi commented May 23, 2018

Copy link
Copy Markdown
Contributor Author

I updated the files at the lines you marked :)

Did you test the performance and average precision improvement e.g. for German area?

Hm I don't really know how to test this

@karussell

karussell commented May 23, 2018 •

Copy link
Copy Markdown
Member

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

./graphhopper.sh measurement downloaded-germany.osm.pbf

Or the equivalent java main class Measurement.java with programm arguments like here

graph.location=measurement-gh datareader.file=berlin-latest.osm.pbf prepare.ch.weightings=fastest prepare.lm.weightings=fastest graph.flag_encoders=car prepare.min_network_size=10000 prepare.min_oneway_network_size=10000

and then the properties file contains routingLM4.mean which means the mean time for LM routing with 4 active landmarks like here. But it looks like we do not yet index the time it takes to create the landmarks like we do with prepare.ch.time for CH. Will fix this.

@baumboi

baumboi commented May 25, 2018

Copy link
Copy Markdown
Contributor Author

I ran both versions twice for Germany and got these results:

old:
prepare.lm.time=342045
prepare.lm.time=343976
routingLM4.mean=78.3398418488
routingLM4.mean=75.99576999119999

new:
prepare.lm.time=355327
prepare.lm.time=350337
routingLM4.mean=67.7551219
routingLM4.mean=68.0320597584

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.

@karussell

Copy link
Copy Markdown
Member

This sounds really good. Will try. Why do you think could it be over 10% faster? Because instead of fetching two shorts from DataAccess we fetch just one int?

@baumboi

baumboi commented May 26, 2018

Copy link
Copy Markdown
Contributor Author

This sounds really good. Will try. Why do you think could it be over 10% faster? Because instead of fetching two shorts from DataAccess we fetch just one int?

I'm not sure if this is the reason, because the new version also fetches two ints (1 for getFromWeight and 1 for getToWeight seperatly). Maybe the convertation from short to int takes some time and fetching an int is faster than fetching a short. Both functions have pretty much the same operations as before, getToWeight is even a bit longer, so I'm surprised that it's such a big improvement.

@boldtrn

boldtrn commented May 26, 2018

Copy link
Copy Markdown
Member

Why do you think could it be over 10% faster?

Is this improvement reproducible? Could be just a random anomaly?

@easbar

easbar commented May 27, 2018

Copy link
Copy Markdown
Member

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.

@baumboi

baumboi commented May 27, 2018

Copy link
Copy Markdown
Contributor Author

I ran both another 8 times with these results:

old:
routingLM4.mean=79.8826709984
routingLM4.mean=79.7894196064
routingLM4.mean=72.8586727184
routingLM4.mean=82.17932466479999
routingLM4.mean=79.23005568800001
routingLM4.mean=80.3595968472
routingLM4.mean=78.9029193504
routingLM4.mean=71.5291511544

new:
routingLM4.mean=76.31359076640001
routingLM4.mean=64.7755447112
routingLM4.mean=81.274656928
routingLM4.mean=81.1376535216
routingLM4.mean=72.4896060752
routingLM4.mean=70.0979023784
routingLM4.mean=72.3667225016
routingLM4.mean=70.8192831368

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^^

@karussell karussell added this to the 0.11 milestone May 28, 2018
@karussell

Copy link
Copy Markdown
Member

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 mvn clean test or IntelliJ->select all modules->right click->Run all tests, the failing test class is com.graphhopper.routing.RoutingAlgorithmWithOSMIT)

@karussell

Copy link
Copy Markdown
Member

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.

@karussell

Copy link
Copy Markdown
Member

@baumboi do you have an updated version where the tests run through?

@baumboi

baumboi commented Sep 12, 2018 •

Copy link
Copy Markdown
Contributor Author

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 Integer.MAX_VALUE (this also occured in RoutingAlgorithmWithOSMIT)
However now it seems to fail with DefaultEdgeFilter(FlagEncoder,boolean,boolean) and I don't really know why this is the case. It works perfectly in my repository in IntelliJ.

@karussell

Copy link
Copy Markdown
Member

Thanks a lot!

I don't really know why this is the case. It works perfectly in my repository in IntelliJ

Will fix in this branch.

@karussell

Copy link
Copy Markdown
Member

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?

@karussell

karussell commented Sep 12, 2018 •

Copy link
Copy Markdown
Member

The warning regarding "maxed out" values is somehow wrong.

Is the following correct?

  • for maxed out delta values one should increase the maximum to make deltas smaller
  • for maxed out from values one should decrease the maximum (i.e. increase the factor)

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.

@baumboi

baumboi commented Sep 12, 2018

Copy link
Copy Markdown
Contributor Author

Couldn't we increase the PRECISION now to 18 or even more bits?

Basically yes, but this would also mean, that more weights get maxed out. With PRECISION = 16 we have the same accuracy and factor we had in the old system with two shorts, but less weightings maxed out (which means more precision on long distances). With PRECISION = 18 we'd get better precision on short and normal distances, but have at least as many weights maxed out as before (probably even more because of the quite small size of the delta values). I can't really say which of these options will perform better, but i could do some tests (e.g. for Germany).

Is the following correct?

for maxed out delta values one should increase the maximum to make deltas smaller
for maxed out from values one should decrease the maximum (i.e. increase the factor)

I think for both cases we need to decrease the precision (--> increasing the factor), in order to reduce the value we store.

@karussell

Copy link
Copy Markdown
Member

but have at least as many weights maxed out as before (probably even more because of the quite small size of the delta values)

Thanks, makes sense!

I can't really say which of these options will perform better, but i could do some tests (e.g. for Germany)

No problem. Currently doing a world wide import again and will report about PRECISION=16

I think for both cases we need to decrease the precision (--> increasing the factor), in order to reduce the value we store.

Thanks for the clarification, will fix this in the code

@karussell
karussell merged commit d29555a into graphhopper:master Sep 14, 2018
@boldtrn

boldtrn commented Feb 12, 2019

Copy link
Copy Markdown
Member

Thanks for the nice improvement @baumboi.

No problem. Currently doing a world wide import again and will report about PRECISION=16

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?

@karussell

Copy link
Copy Markdown
Member

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

@boldtrn

boldtrn commented Feb 12, 2019

Copy link
Copy Markdown
Member

Thanks for reporting your findings :)

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.

more precise landmark routing

4 participants