Skip to content

Allowing multiple weightings/vehicle using CH - #623

Closed
boldtrn wants to merge 1 commit into
graphhopper:masterfrom
boldtrn:feature_multiple_ch_weightings
Closed

boldtrn wants to merge 1 commit into
graphhopper:masterfrom
boldtrn:feature_multiple_ch_weightings

Conversation

@boldtrn

@boldtrn boldtrn commented Dec 30, 2015

Copy link
Copy Markdown
Member

This PR allows users to setup multiple weightings using CH. You have to define the weightings in the properties file like:
prepare.chWeighting=fastest, shortest

@karussell

Copy link
Copy Markdown
Member

Thanks! This is indeed a very minor change - nice :) !

We could even avoid breaking the Java API when offering the old method setCHWeighting(String).

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.

we should throw an exception here saying at least one weighting is required.

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.

You are right. I will update the PR

@karussell

Copy link
Copy Markdown
Member

Ah, okay the method public List<String> getCHWeighting() breaks the Java API and should be added to core/files/changelog.txt

Comment thread config-example.properties

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably comma separated without spaces ?

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.

for the encoders we accept also spaces I think, trimming is easy and should be done before calling setCHWeighting. But for now I would be even okay with trimming inside the setter, not sure.

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.

I thought about that as well. What is the downside of trimming? We do not allow weighting names like " name" or "name ". The benefit is that our config files are not sensible to whitespace.

I would not expect a config file to be sensible to whitespaces.

trimming inside the setter

Do you think adding logic to a setter is bad?

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.

Do you think adding logic to a setter is bad?

Yeah. That is the only thing I don't like about it. But when reading the config file we should trim and then set with the array which is then used 'as it'. Maybe even do not do toLowerCase but throw exception if upper case?

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.

I actually don't think that adding logic to getters/setter is a bad practice. As long as we are trying to improve the quality of the "seted" value. And not doing anything unrelated to setting the value.

The pro of doing it in the setter is that we have a central/unique place to execute the correction of weighting values.

@karussell karussell added this to the 0.6 milestone Dec 30, 2015
@boldtrn

boldtrn commented Dec 31, 2015

Copy link
Copy Markdown
Member Author

We could even avoid breaking the Java API when offering the old method setCHWeighting(String).

How about creating a setCHWeighting method that uses varargs. This would not break the setter.

public List getCHWeighting()

How about providing a String getCHWeighting() method and add a @deprecated. The method would return the first element of list. This method could be also used in the getWeightingForCH method. We could remove that method in the future.

Therefore, this would be a pure feature that does not break the api and could be merged soon (since I'd like to see that feature in the master branch ;)).

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 I vote for just 'getCHWeightings'

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.

Me too, but overloading of methods is only valid if you use different parameters. Same method name with different return type is not valid.

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, ups, you're right. You wanted to keep the old method, hmmh. I think we should break the API here as the new method should also have a nice name and the old method is probably not that often used.

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.

Ok, so I will change the name from getAllCHWeightings to getCHWeightings and change the name of getCHWeighting to getFallbackCHWeighting to be used in the getWeightingForCH method.

After writing the above I just realized, that getWeightingForCH and getCHWeighting is probably irritating.

Maybe we refactor the getAllCHWeightings to getCHWeightingNames?

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.

After writing the above I just realized, that getWeightingForCH and getCHWeighting is probably irritating.

Hmmh, that is right. I would get rid of it and just keep getCHWeightings and getWeightingForCH. Currently new GH versions broke the Java API and if it is properly documented in the changelog.txt there was no problem or even questions in the forum.

BTW: Maybe we should rename getWeightingForCH to findCHWeighting to indicate the small overhead? But would be a different issue

@karussell

Copy link
Copy Markdown
Member

Perfect ideas!

Just for the toLowerCase and trimming I would like to know your oppinion e.g. if just doing it or throwing exceptions etc

@boldtrn

boldtrn commented Jan 2, 2016

Copy link
Copy Markdown
Member Author

Ok everything should be fixed now. I added the renaming to the changelog.txt. What do you think, can we merge this branch?

@karussell

Copy link
Copy Markdown
Member

Thanks! One minor thing now is that the setter and getter of the List<String> are slightly 'misnamed'. Would you rename public GraphHopper setCHWeighting( List<String> weightingList ) to setCHWeightings and then squash your changes to one commit?

@boldtrn

boldtrn commented Jan 2, 2016

Copy link
Copy Markdown
Member Author

Ok sure, I can do that. But I would leave the fallback method using varargs without the s? To not break the API at this point.

@karussell

Copy link
Copy Markdown
Member

But I would leave the fallback method using varargs without the s? To not break the API at this point.

Hmmh, good question. Or keep setCHWeighting with one string and do setCHWeightings with the varargs? As I would mark the old setCHWeighting method as deprecated and remove it at some point (?)

@boldtrn

boldtrn commented Jan 2, 2016

Copy link
Copy Markdown
Member Author

Hmmh, good question. Or keep setCHWeighting with one string and do setCHWeightings with the varargs? As I would mark the old setCHWeighting method as deprecated and remove it at some point (?)

Ok this sounds reasonable. Change both List+Varargs to setCHWeightings and add a setCHWeighting method that is set deprecated?

@karussell

Copy link
Copy Markdown
Member

Ok!

Added Comments in properties file

Created Wrapper Methods to not break the API

Removed getCHWeighting and added Information to changelog

Updated setCHWeighting
@boldtrn
boldtrn force-pushed the feature_multiple_ch_weightings branch from 599ba57 to d7f7702 Compare January 2, 2016 11:54
@boldtrn

boldtrn commented Jan 2, 2016

Copy link
Copy Markdown
Member Author

PR is squashed. Thanks.

@karussell

Copy link
Copy Markdown
Member

PR is squashed. Thanks.

Oh, I have to thank: thanks :) !

One thing which I will do in another change:
String tmpCHWeighting = args.get("prepare.chWeighting", "fastest");

This should be renamed to prepare.chWeightings with a fallback to prepare.chWeighting which will be also removed later.

@karussell

Copy link
Copy Markdown
Member

Merged with a few changes in the GraphHopper class. 641d222

@karussell karussell closed this Jan 2, 2016
@karussell

Copy link
Copy Markdown
Member

Thanks!

@boldtrn
boldtrn deleted the feature_multiple_ch_weightings branch October 6, 2017 01:14
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