Skip to content

Makes all tests pass for LM - #1749

Merged
michaz merged 53 commits into
masterfrom
more-lm-bugs
Jan 20, 2020
Merged

michaz merged 53 commits into
masterfrom
more-lm-bugs

Conversation

@michaz

@michaz michaz commented Oct 13, 2019 •

Copy link
Copy Markdown
Member
  1. Sorry, but this reverts Improvement of landmark weight precision, issue 1080 #1376. I just couldn't get it to work. Like others have pointed out, it may be possible, but the numerics involved are totally not clear to me, and in its current state, it's demonstrably wrong.

  2. I also add a treatment of the virtual edge at the target node in the LM-approximator[1]. This is different to what was there before. Before, the current node got a special treatment, which is not necessary.

I now also test unidirectional LM, which catches (2). In bidirectional LM, apparently the stopping criterion is loose enough so (2) doesn't show up.

EDIT (added):

  1. LMApproximator now rounds down, so it always underapproximates.

  2. It also tells the bidirectional A* algorithm that it needs a certain slack for the stopping criterion. This is necessary in addition to 3, because LMApproximator's rounding makes it violate the triangle inequality ("consistency"), and this probably can't be fixed locally in the approximator.

  3. I shifted the BalancedWeightApproximator (which also has a new name) by constants so that both sides are '0' at their destinations. (Recommended by one of the papers, mainly for clarity, doesn't change the algorithm's behavior if the stopping criterion (6.) is also adapted.)

  4. I changed the stopping criterion in A* so it works with 5. (found the new formulation in one of the papers, and couldn't find the previous one; possibly the previous one was correct for the previous approximator, but I suspect it was slightly wrong).

Supercedes #1747.

[1] Goldberg, A.V., Kaplan, H., Werneck, R.F.: Better Landmarks Within Reach. In: Demetrescu, C. (ed.) WEA 2007. LNCS, vol. 4525, pp. 38–51. Springer, Heidelberg (2007)

@michaz

michaz commented Oct 13, 2019 •

Copy link
Copy Markdown
Member Author

This still doesn't mean the rounding errors discussed in #1557 are gone. Maybe, maybe not. But they're not what has been failing the randomized tests.

michaz and others added 3 commits October 13, 2019 14:20
# Conflicts:
#	core/src/main/java/com/graphhopper/routing/lm/LMApproximator.java
@karussell

Copy link
Copy Markdown
Member

I removed the todonow and replaced CarFlagEncoder with MotorcycleFlagEncoder. Then to remove several log warnings I changed the default maximum weight, but still I get exceptions ala:

randomGraph_withQueryGraph seed: 96076558697230
expected: [51, 44, 14, 5, 38, 22, 35, 50]
given:    [51, 44, 14, 8, 17, 32, 35, 50]

java.lang.AssertionError: wrong weight: 51->50, expected: 161.94306753707676, given: 162.04722980980404

	at org.junit.Assert.fail(Assert.java:88)
	at com.graphhopper.routing.weighting.RandomizedRoutingTest.comparePaths(RandomizedRoutingTest.java:322)
	at com.graphhopper.routing.weighting.RandomizedRoutingTest.randomGraph_withQueryGraph(RandomizedRoutingTest.java:280)
	at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)

Is this expected as those errors are not fixed in this PR (e.g. still rounding errors) or is this unexpected?

@michaz

michaz commented Jan 2, 2020

Copy link
Copy Markdown
Member Author

Then to remove several log warnings I changed the default maximum weight

Careful please, I would say that's not really a minor thing when the PR is about landmark precision.

I still stand by this:

This still doesn't mean the rounding errors discussed in #1557 are gone. Maybe, maybe not. But they're not what has been failing the randomized tests.

So the answer is apparently 'not'. But perhaps now the change that is discussed in #1557 can be applied? (I wanted to remove only one rounding error source at a time..)

And I put the unidirectional LM test back in, because

I now also test unidirectional LM, which catches (2). In bidirectional LM, apparently the stopping criterion is loose enough so (2) doesn't show up.

@michaz

michaz commented Jan 2, 2020

Copy link
Copy Markdown
Member Author

Maybe we should remove the warning? A too large "max value" is much worse than a too small one, it will just quietly produce wrong routes.

@michaz

michaz commented Jan 2, 2020 •

Copy link
Copy Markdown
Member Author

We should write an LMApproximatorTest that verifies that the LMApproximator always underestimates the remaining weight, and then go through the code until it does. Then we don't need an extra stopping criterion, and we can actually call ourselves A*. ,-)

@karussell

Copy link
Copy Markdown
Member

Careful please, I would say that's not really a minor thing when the PR is about landmark precision

Isn't the underlying problem here more that the max weight guessing procedure is not good enough? I.e. it relies on some distances instead of the weights? We could try to make this better and e.g. go through the graph "from one end to the other". This could be easily done when selecting the first landmark or first 2 landmarks for example.

encoder = new MotorcycleFlagEncoder(5, 5, 1);
// todonow: make this work with speed_both_directions=true!
encoder = new CarFlagEncoder(5, 5, 1);

I replaced this with the MotorcycleFlagEncoder because it uses speed_both_directions=true and the todonow could be removed. In one branch I made this easy for CarFlagEncoder too, so we could also wait for that change. But in several tests MotorcycleFlagEncoder is already used in this case already.

This still doesn't mean the rounding errors discussed in #1557 are gone. Maybe, maybe not. But they're not what has been failing the randomized tests.

Probably I misunderstood this part. The randomized tests are failing occasionally now. How would applying the fix proposed in #1557 help with them, when you say they are not related to the random test failures?

I think it is a good idea to apply the fix and yes, let's do this in a separate PR.

@michaz

michaz commented Jan 3, 2020 •

Copy link
Copy Markdown
Member Author

The randomized tests are failing occasionally now.

Are they randomly failing on this branch in this state, without setMaxValue?

My current hypothesis is that the remaining random failures are due to #1557, and they don't happen with a low maxValue and happen more often, or always, with a high maxValue, because with a high maxValue, we get rounding errors.

We get fewer warnings the wronger we are. It's a "trade-off" between overflows (warning, just a performance hit), and precision errors (no warning, wrong route).

So when you said:

to remove several log warnings I changed the default maximum weight, but still I get exceptions

The "still" is probably the misunderstanding. Then you get exceptions.

@michaz

michaz commented Jan 3, 2020 •

Copy link
Copy Markdown
Member Author

Isn't the underlying problem here more that the max weight guessing procedure is not good enough?

(EDIT)

The problem I'm having is that the higher the "max value", the lower the probability of warnings, but the higher the probability of errors, perhaps even if guessed in a "tight" way.

@michaz

michaz commented Jan 3, 2020 •

Copy link
Copy Markdown
Member Author

When I put back lm.setMaximumWeight(1000);, which is currently in there on master (not 10000), I can run it a lot of times without failing.

So what I meant was that the troubles that we were having back then (it's already a long time ago, I had to read all the issues and PRs in context to re-understand it) with randomly failing tests on master should be fixed with this PR. Those errors, for which I created this PR, were due to a problem with the "delta-rounding", in addition to those I already fixed in #1745. Not due to #1557. And there was an additional problem (#1532) which I could isolate by testing unidirectional LM, and that was due to a problem with LM+QueryGraph.

If we are still getting random errors on this branch, I would say they are due to #1557.
I think the errors we are getting on this branch when we increase maximumWeight to higher than 1000 are also due to #1557.

easbar and others added 7 commits January 16, 2020 17:37
# Conflicts:
#	core/src/main/java/com/graphhopper/routing/AStarBidirection.java
#	core/src/main/java/com/graphhopper/routing/AbstractBidirAlgo.java
#	core/src/main/java/com/graphhopper/routing/lm/LandmarkStorage.java
#	core/src/test/java/com/graphhopper/routing/weighting/RandomizedRoutingTest.java
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