Skip to content

Identifies CH graphs by new CHProfile class instead of Weighting. - #1671

Merged
easbar merged 19 commits into
masterfrom
ch_profile
Aug 27, 2019
Merged

easbar merged 19 commits into
masterfrom
ch_profile

Conversation

@easbar

@easbar easbar commented Jul 29, 2019 •

Copy link
Copy Markdown
Member

Instead of a list of Weightings for edge/node-based preparations GraphHopperStorage now takes a list of CHProfile:

public GraphHopperStorage(List<CHProfile> chProfiles, Directory dir, EncodingManager encodingManager, boolean withElevation, GraphExtension extendedStorage)

To get a CHGraph from GraphHopperStorage we are using now:

graph.getCHGraph(CHProfile);

In contrast to the previous approach where the exact Weighting instance was used to identify a CHGraph the CHProfile now works like a finger-print of a CHGraph and it does not have to be the same object anymore (at least as long as the Weighting derives from AbstractWeighting which provides its own equals method).

Also see discussion in #1652.

public BikeFlagEncoder(PMap properties) {
this((int) properties.getLong("speed_bits", 4),
properties.getLong("speed_factor", 2),
this(properties.getInt("speed_bits", 4),

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.

Right ?

@karussell

Copy link
Copy Markdown
Member

@easbar

easbar commented Aug 13, 2019 •

Copy link
Copy Markdown
Member Author

Is it possible with this PR to make this part cleaner here?

Hmm, I am not sure (I do not understand this comment):

I want to use my own instance of FastestWeighting because it uses its own U-Turn-penalty

How can FastestWeighting use a u-turn penalty ? Or should this read heading-penalty here ? If the heading penalty is meant this is not supported by CH anyway. Since the heading penalty is not included in FastestWeighting#toString it does not affect AbstractWeighting#equals so for CHGraph#getCHGraph with this PR we will get the same CHGraph regardless what heading penalty we are using.

The important thing that changed in this PR is that Weightings are now identified by equals instead of ==. All properties of a Weighting should be included in toString, such that the CH preparation matches the Weighting that we use. For the heading penalty its a special case, because this is not supported for CH.

@easbar

easbar commented Aug 13, 2019

Copy link
Copy Markdown
Member Author

Any idea why the CI build fails for open jdk 12 ?

[ERROR] Failed to execute goal de.thetaphi:forbiddenapis:2.6:check (default-cli) on project graphhopper-tools: Check for forbidden API calls failed while scanning class 'com.graphhopper.ui.MiniGraphUI' (MiniGraphUI.java): java.lang.ClassNotFoundException: com.graphhopper.storage.CHProfile (while looking up details about referenced class 'com.graphhopper.storage.CHProfile') -> [Help 1]

@karussell

Copy link
Copy Markdown
Member

Any idea why the CI build fails for open jdk 12 ?

Strange, can you try to remove the cache?

cache:
  directories:
  - $HOME/.m2

How can FastestWeighting use a u-turn penalty ?

@michaz do you remember what the problem was and why you had to create a separate Weighting instance?

@easbar

easbar commented Aug 14, 2019 •

Copy link
Copy Markdown
Member Author

Hmm, I do not get it. Disabling the cache did not help and adding gh-core as explicit dependency to tools did not help either. Somehow the wrong version of the core (that does not have CHProfile) appears to be pulled in for the forbiddenapis check.

I also tried changing all versions to 0.13-ch_profile-test, but then the Open JDK 12 build fails with another error:

[ERROR] Failed to execute goal on project graphhopper-web-api: Could not resolve dependencies for project com.graphhopper:graphhopper-web-api:jar:0.13-ch_profile-test: Could not find artifact com.graphhopper:graphhopper-api:jar:0.13-ch_profile-test in google-maven-central (https://maven-central.storage-download.googleapis.com/repos/central/data/) -> [Help 1]

So it seems that it is trying to obtain graphhopper module artifacts from maven central instead of using the local ones from the reactor build ?

@karussell

Copy link
Copy Markdown
Member

Really strange.

I got something that seems to works ... don't ask why though ;)
I've just set the in-built "openjdk12" jdk for travis and it works! Although it does the same (downloads the install-jdk script and runs it).

@easbar

easbar commented Aug 14, 2019 •

Copy link
Copy Markdown
Member Author

Thanks! I enabled the cache again and set back the artifact versions and the build passed a second time. No idea what this was..., maybe different versions of install-jdk.sh ?

@michaz

michaz commented Aug 22, 2019 •

Copy link
Copy Markdown
Member

How can FastestWeighting use a u-turn penalty ? Or should this read heading-penalty here ? If the heading penalty is meant this is not supported by CH anyway. Since the heading penalty is not included in FastestWeighting#toString it does not affect AbstractWeighting#equals so for CHGraph#getCHGraph with this PR we will get the same CHGraph regardless what heading penalty we are using.

Yes, it should read heading-penalty. The heading-penalty is used only in the map-matching specific entry/exit phase. As you say, not during CH routing.

The entire comment is basically a complaint/note-to-self that I have to use a weighting that I don't want to route with (((PrepareContractionHierarchies) routingAlgorithmFactory).getWeighting()) as a key, just to get the CHGraph that I want, even though I know which CHGraph I want, and I know that my own weighting will work with it.

Basically I thought the routingAlgorithmFactory was trying to force me to prove to it that I have the weighting for which the CHGraph was constructed, and I thought that's a bit too object-oriented for me. :-) If something is a container for CHGraphs, I should be able to just get any one I want. By name, or something.

And if that's what your change fixes, all is fine, and the ugliness and the comment can go away, thanks a lot!

@michaz

michaz commented Aug 22, 2019 •

Copy link
Copy Markdown
Member

Oh, by the way, this is the exact right moment to change this: In (one step of the) the customizable routing project, we will need to do exactly that: Have a fully dynamic weighting that we create on the fly, and use it on a CHGraph of which we just know that it fits the weighting, because we construct it that way.

@michaz

michaz commented Aug 22, 2019

Copy link
Copy Markdown
Member

(Or is that the idea?) :-)

@michaz

michaz commented Aug 23, 2019

Copy link
Copy Markdown
Member

In the end, I think, profiles will just have names (strings):

  • I will define profiles in cofiguration files, giving them a name
  • Users will say which profile they want by query parameter
  • ... so I should also be able to get a profile, or something pertaining to a profile, by name in Java.

@easbar

easbar commented Aug 23, 2019

Copy link
Copy Markdown
Member Author

In the end, I think, profiles will just have names (strings):

Yes I agree. It is more or less like this at the moment, because CHProfile#equals uses equals from Weighting, which for AbstractWeighting uses toString... So should we add getCHGraph(String) ? This should be easy.

For the customizable scenario I think we should keep two things in mind:

  • The 'definition' of a CH profile can get arbitrarily complex: Its not just about the weighting or node/edge based, but for example when blocking (multiple) areas or even specifying exact speeds for many single edges (think traffic conditions) a lot of information has to go into the 'profile' specification. So it would probably better to use some structured format for the 'profile-string' ?

  • I am not sure if graph.getCHGraph() will be really what we want for customizable CH, because it should also be possible to create the CH graph on the fly (basically create it, run a request and throw it away immediately). So there will be no need to store it in GraphHopperStorage even. At the same time there might be places where it is more like creating a profile and then use it multiple times, in this case it might be best to assign some kind of ID to the profile to retrieve it later (using the full specification of the profile would be too much if, e.g. it includes specifying all traffic conditions etc.).

(Or is that the idea?) :-)

The idea here was mostly that I wanted to be able to specify u-turn costs (#1672), but sure I think its a step in the right direction for more customized stuff as well. The key thing here is that everything that needs to be known at CH preparation time must be included in the CH profile (used to be just the weighting, then edge/node-based and with #1672 also u-turn costs).

@michaz

michaz commented Aug 23, 2019 •

Copy link
Copy Markdown
Member

to assign some kind of ID to the profile to retrieve it later

Yes, exactly. Like a filename, almost. We already have this Directory abstraction -- don't know how far that carries (or could carry), but basically, our "normal" profiles are currently:

/car/fastest
/car/shortest
/bike/fastest
/bike/shortest
.
.

(right?)

But maybe I want to do something outside that structure. Like, create a CH Graph where some parts of the graph are explicitly banned from contraction (so I can customize them). Maybe I want several of those. They would be created / programmed in my code, and I would give them a name in my code, maybe

/car/fastest/withBlockableRoads

so I can get at them (in other parts of my code).

(Just a thought, maybe non-hierarchical names are enough in the end..)

that needs to be known at CH preparation time must be included in the CH profile

Yes, but the responsibility for that must be "outside the framework", outside the code that just stores graphs. Because that code doesn't know what needs to be known for my flavor of CH. I basically want a layer that just stores ChGraph-like things for me and allows me to retrieve them later, without assuming a lot about what I do with it or what it means.

easbar added 2 commits August 23, 2019 18:58
# Conflicts:
#	core/files/changelog.txt
#	core/src/main/java/com/graphhopper/storage/CHGraphImpl.java
#	core/src/test/java/com/graphhopper/storage/GraphHopperStorageCHTest.java
# Conflicts:
#	reader-osm/src/test/java/com/graphhopper/GraphHopperIT.java
@karussell

Copy link
Copy Markdown
Member

to assign some kind of ID to the profile to retrieve it later

I think, this should be another issue and should not be done before the actual code is required.

The flexible work (flex_vehicleprofile and flex_vehicleprofile2) indicates that everything can be weighting based (we do not need FlagEncoders anymore). I.e. we just use a weighting name as ID "mycar/fastest" and a base name "car/fastest" from which we extend behaviour. Customization properties are sent via a json/yaml file either through http or from the file system.

@easbar

easbar commented Aug 27, 2019

Copy link
Copy Markdown
Member Author

I think, this should be another issue

Yes, is there anything that needs to be done for this PR ?

The flexible work (flex_vehicleprofile and flex_vehicleprofile2) indicates that everything can be weighting based (we do not need FlagEncoders anymore). I.e. we just use a weighting name as ID "mycar/fastest" and a base name "car/fastest" from which we extend behaviour.

What do you mean with 'we do not need FlagEncoders anymore' ? Will they be removed entirely ? "car/fastest" still sounds like a FastestWeighting with a CarFlagEncoder ? Is flex_vehicleprofile2 just a more recent version of flex_vehicleprofile or are they something different ? Sorry I did not have a look at these yet.

this.singleCHWeighting = singleCHWeighting;
public GraphBuilder setCHProfiles(List<CHProfile> chProfiles) {
if (chProfiles.size() != new HashSet<>(chProfiles).size()) {
throw new IllegalArgumentException("Duplicate CH profile: " + chProfiles);

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.

The message is slightly confusing and should be "Contains duplicate CH profile:" (?)

@karussell

Copy link
Copy Markdown
Member

"car/fastest" still sounds like a FastestWeighting with a CarFlagEncoder ?

Yes. Still conceptionally the FastestWeighting does not need CarFlagEncoder. In theory it is sufficient to have e.g. roadClassEnc, maxSpeedEnc and a few other EncodedValues that "read the properties of an endge" in the Weighting class. The "CarFlagEncoder-specific stuff" that precalculates e.g. average speed and access for car seems to be required only for performance reasons. Or maybe the otherway around: should we create a separate TruckFlagEncoder to store size and width or should we include this in CarFlagEncoder? But e.g. cargo bikes also need at least the width of an edge. And why should we force a single averageSpeedEnc for car, when in fact there could be many speeds e.g. depending on the time or if it is an electric car?
I do not know yet what a good replacement for FlagEncoder should look like as it is still handy to have some precalculated average speed for foot and car, but still IMO we should try to remove its usage as it is only a specific collection of EncodedValues (?)
(For now EncodedValues handle edges only, later they could handle also nodes and relations.)

Is flex_vehicleprofile2 just a more recent version of flex_vehicleprofile or are they something different ?

Yes, flex_vehicleprofile2 uses a recent master and has no hacks I think, but has also not all features.

@easbar

easbar commented Aug 27, 2019

Copy link
Copy Markdown
Member Author

Ok, thanks for your explanations and I see it is difficult to find replacement for everything FlagEncoder does. To specify a CH profile I think we will eventually only need to define a weight for all edges of the base graph (in fwd&bwd direction) and give this collection of weights some name/id to retrieve the corresponding profile later. Of course for json/yaml configuration etc. specifying these weights needs to be possible on a much higher level (like 'weight=dist/speed', 'block this area', 'use this traffic information' etc.).

Right now Weighting (combined with FlagEncoder) does all these things: It has a calcWeight method, there are different implementations that allow specifying how the weight is calculated from the different edge properties and it is used as identifier of the CH graph (therefore it is still part of CHProfile). Maybe at some point we need to separate these things from each other. For example the CH preparation should not be concerned with any details (encoded values, flag encoders, traffic information sources,...) how the weights are calculated (it only needs a way to retrieve the two weights per edge) and as @michaz pointed out it should be possible to choose an arbitrary name/id of a CH profile, because it will rather be impractical to include the full specification of a weighting (blocked areas etc.) in its name.

@easbar
easbar merged commit d3226fb into master Aug 27, 2019
@karussell

Copy link
Copy Markdown
Member

I see it is difficult to find replacement for everything FlagEncoder does

Yes. This is another problem: it does too many things :)

it only needs a way to retrieve the two weights per edge

Yeah, basically it just needs two EncodedValues. (Maybe a "profile" is like a FlagEncoder: a collection of EncodedValues...)

@easbar

easbar commented Aug 27, 2019 •

Copy link
Copy Markdown
Member Author

Yeah, basically it just needs two EncodedValues.

I was more thinking of two doubles ? I thought every edge has some 'flags', then there are encoded values to give these flags some meaning (like speed or road type), then there is Weighting that uses the encoded values to calculate a weight (just a number). For CH preparation we need this weight, why would we convert the weight (number) into an encoded value at this point ?

(Maybe a "profile" is like a FlagEncoder: a collection of EncodedValues...)

But isn't it more than a collection of encoded values ? It is also about how to combine the encoded values into a weight ?

@karussell

karussell commented Aug 27, 2019 •

Copy link
Copy Markdown
Member

For CH preparation we need this weight, why would we convert the weight (number) into an encoded value at this point ?

An EncodedValue transform some bits in the edge into a value. The same can be done for shortcuts. In fact the only reason we don't use EncodedValues also for the shortcut weights yet is entirely because of performance. Maybe you remember this commit: cb88018 (was reverted or not included)

But isn't it more than a collection of encoded values ?

It is more than that, yes. Like including relations and stuff.

It is also about how to combine the encoded values into a weight ?

Isn't this the task of the Weighting class?

@easbar

easbar commented Aug 27, 2019

Copy link
Copy Markdown
Member Author

The same can be done for shortcuts

Ah ok yes you were thinking about the shortcuts, which need to store some weight (and like you said could be encoded values). I was thinking about the weights of the original/base graph edges that enter the CH preparation.

Isn't this the task of the Weighting class?

Yes, exactly. I was probably more thinking in terms of a CH profile, which is defined by the calculated weights of the edges or at least by the 'method'/weighting how these weights are calculated. This is different to a 'profile', which rather defines the properties of an edge and is needed before the weights are calculated.

@easbar
easbar deleted the ch_profile branch August 27, 2019 08:15
@easbar easbar mentioned this pull request Aug 27, 2019
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