Skip to content

Only update the location if it was empty - #1492

Closed
efranqueiro wants to merge 3 commits into
graphhopper:masterfrom
efranqueiro:master
Closed

efranqueiro wants to merge 3 commits into
graphhopper:masterfrom
efranqueiro:master

Conversation

@efranqueiro

Copy link
Copy Markdown

No description provided.

@karussell

karussell commented Oct 26, 2018 •

Copy link
Copy Markdown
Member

The assumption is that init overwrites all local variables. So instead of changing this, we should better document that init should be called before calling setGraphHopperLocation (or break API at some point and implement a builder pattern). Would this help in your case too?

@efranqueiro

Copy link
Copy Markdown
Author

For my specific case, I can use setMinNetworkSize(), but in general, a builder pattern would be much better.
Your suggestion also works for me, but it should also mention that it must be called after setDataReaderFile(), then (see below).
But I don't really like that. There shouldn't be a dependency in the order you call the setters and init() (other than perhaps init() being the first or last call, but not in between 2 specific setters).

This works

			GraphHopper graphHopper = new GraphHopperOSM()
					.setDataReaderFile(osmFile)
					.setEncodingManager(new EncodingManager(profile))
					.init(new CmdArgs().
							put("prepare.min_network_size", "200").
							put("prepare.min_one_way_network_size", "200"))
					.setGraphHopperLocation(workDir)
					.forServer();

These don't

			GraphHopper graphHopper = new GraphHopperOSM()
					.setDataReaderFile(osmFile)
					.setGraphHopperLocation(workDir)
					.setEncodingManager(new EncodingManager(profile))
					.init(new CmdArgs().
							put("prepare.min_network_size", "200").
							put("prepare.min_one_way_network_size", "200"))
					.forServer();
			GraphHopper graphHopper = new GraphHopperOSM()
					.setEncodingManager(new EncodingManager(profile))
					.init(new CmdArgs().
							put("prepare.min_network_size", "200").
							put("prepare.min_one_way_network_size", "200"))
					.setDataReaderFile(osmFile)
					.setGraphHopperLocation(workDir)
					.forServer();
			GraphHopper graphHopper = new GraphHopperOSM()
					.setGraphHopperLocation(workDir)
					.setEncodingManager(new EncodingManager(profile))
					.init(new CmdArgs().
							put("prepare.min_network_size", "200").
							put("prepare.min_one_way_network_size", "200"))
					.setDataReaderFile(osmFile)
					.forServer();

We could be to force init() to be the first by not throwing an error if there's no location data set, and leave that to the validation in importOrLoad(). But this wouldn't be fail-fast though. Or force it to be the last call but keeping sane values if they are present.

@karussell

Copy link
Copy Markdown
Member

Yes, too ugly. We probably need a breaking change here to make this clean. And use this chance to reduce the code line count in the GraphHopper class :)

What would you propose? Something like a separate configuration object?

@efranqueiro

Copy link
Copy Markdown
Author

A config object with sane defaults when possible, and some sort of validation, seems like a sensible solution to me. Same with a builder.

@Azbesciak

Copy link
Copy Markdown
Contributor

Just a note - if you are going to make a Builder for graphhopper, just remember about their subclasses - maybe it is a good moment to prefer composition over inheritance (for data readers for example)? IMO this Builder should be generic and return given subclass to allow Inheritance also.

@karussell

Copy link
Copy Markdown
Member

prefer composition over inheritance

Yes, this would be another goal and related to #1370

this Builder should be generic and return given subclass to allow Inheritance also

Isn't this the opposite of what you requested?

@Azbesciak

Copy link
Copy Markdown
Contributor

Isn't this the opposite of what you requested?

Yeah, I am aware of it, but there is a need (as I think) for extending functionality of gh over route only.
So, there are two ways:

  • make gh some kind of dto which will accumulate graph, algs etc, and extract route outside of it, to allow extensions.
  • keep gh open and make it in some kind immutable from outside.

I think second option will be easier (also in use-some kind of API) and maybe cleaner, but it requires Inheritance - users will get some prepared base and add what their want. It is better than current solution, because now you can't just add your functionality ahead of graph processing (from shp/pbf etc).

Those are just a quick thoughts so...

@karussell

Copy link
Copy Markdown
Member

Will be done via #1895.

@karussell karussell closed this Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants