Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional stop clustering by parent station or geography #2383

Merged
merged 7 commits into from
Jan 8, 2017

Conversation

barslett
Copy link
Contributor

As discussed in #2364, this PR introduces the possibility to cluster stops based on parent stations, rather than by geographical proximity. This has proved to work well in our test environment here in Oslo.

@@ -78,6 +78,9 @@

/** maximum distance to walk after leaving transit in Analyst */
public static final int MAX_WALK_METERS = 3500;

/** Should stop clusters be created by parent stations instead of by proximity? */
public static final boolean CLUSTER_BY_PARENT_STATIONS = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems sort of funny - it's a final variable with a fixed value, so all of the other code you're adding is dead. Do you mean to make this configurable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to make it configurable, yes, and took a shortcut by making this constant. But I see now how I can put it in the router-config, so I will do that instead.

cluster.computeCenter();
stopClusterForId.put(cluster.id, cluster);
}
if (!CLUSTER_BY_PARENT_STATIONS) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better to use a separate class with multiple implementations, if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I will move it to a separate class.

for (Stop s0 : stopForId.values()) {
String ps = s0.getParentStation();
parentStopsMap.put(ps, new StopCluster(ps, s0.getName()));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

formatting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will fix.

}
for (Stop s0 : stopForId.values()) {
String ps = s0.getParentStation();
if(!parentStopsMap.containsKey(ps)) continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

formatting

Copy link
Contributor

Choose a reason for hiding this comment

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

Also this if is unnecessary; it will never be true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, will have a look at the logic.

}
for (Map.Entry<String, StopCluster> cluster : parentStopsMap.entrySet()) {
cluster.getValue().computeCenter();
stopClusterForId.put(cluster.getKey(), cluster.getValue());
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this just mean that stopClusterForId is a duplicate of parentStopsMap?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You may be right. I was staring myself blind on the code...

@barslett
Copy link
Contributor Author

barslett commented Jan 2, 2017

The two new commits do the folllowing:

  • Adding parameter to router-config
  • Separating implementations in separate methods
  • Additional refactoring the method clusterStopsByParentStations

Please review!

@barslett
Copy link
Contributor Author

barslett commented Jan 2, 2017

Most of your comments are about issues already corrected in the second commit (c377195). But I'll fix the cluster name (in our data, parent stations always have the same name as their children, but of course that isn't always the case.

Sorry about text formatting. 1: I am used to .NET formatting, 2: Indentation looks OK in Eclipse...

@barslett
Copy link
Contributor Author

barslett commented Jan 2, 2017

I looked a bit more at using the parent stop's name, and it seems a bit difficult to extract it in this context. As using the child stop's name works perfect for us, and most agencies use similar names for child/parent(??), I suggest that we leave it as it is, and fix it later if anyone else has a need for explicitly using the parent's name?

@novalis
Copy link
Contributor

novalis commented Jan 3, 2017

Ok, sorry about the duplicate comments. It's easier to read if you rebase/amend. I'll take a look at the new version soon.

}
}

private void clusterByParentStation() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This indentation is still not right. It's indented by a single tab, while the rest of this file has four spaces. Can you please double-check all of the indentation? Thanks.

cluster.computeCenter();
stopClusterForId.put(cluster.id, cluster);
}
if (graph.clusterByParentStation) clusterByParentStation();
Copy link
Contributor

Choose a reason for hiding this comment

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

newline before clusterByParentStation();

StopCluster cluster;
if (stopClusterForId.containsKey(ps)) {
cluster = stopClusterForId.get(ps);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

No newline between } and else.

}
cluster.children.add(stop);
stopClusterForStop.put(stop, cluster);

Copy link
Contributor

Choose a reason for hiding this comment

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

delete blank line

}
for (Map.Entry<String, StopCluster> cluster : stopClusterForId.entrySet()) {
cluster.getValue().computeCenter();

Copy link
Contributor

Choose a reason for hiding this comment

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

also delete this blank line

cluster.getValue().computeCenter();

}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

fix indent

@@ -151,7 +151,11 @@ public void startup(JsonNode config) {
}
}
}


Copy link
Contributor

Choose a reason for hiding this comment

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

don't replace a blank line with a line containing only trailing whitespace

Copy link
Contributor

Choose a reason for hiding this comment

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

(this one seems to still be there)


JsonNode clusterByParentStation = config.get("clusterByParentStation");
if (clusterByParentStation != null && clusterByParentStation.isBoolean())
graph.clusterByParentStation = clusterByParentStation.asBoolean();
Copy link
Contributor

Choose a reason for hiding this comment

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

... and if it's not a boolean, throw an exception or something.

But actually, it should be a string called something like "clusterMode", with values "parentStation" and "geographic" -- maybe later someone will add something that clusters by name or something.

@barslett
Copy link
Contributor Author

barslett commented Jan 5, 2017

What a hassle with the formatting ;-). At least, I have now installed the preferred text formatter for Eclipse, so I hope these problems will be reduced for the future.

I also added some logging for cases when the parameter is falsely set to a string value. Of course the whole logic could be rewritten to facilitate additional clustering methods, but I would prefer not having to do that at the moment.

@novalis
Copy link
Contributor

novalis commented Jan 6, 2017

I think it would not be hard to do the parameter as a string, and I think it would be much cleaner.

@barslett
Copy link
Contributor Author

barslett commented Jan 6, 2017

OK. Figured it out in the shower. Will update today.

@novalis novalis merged commit f142150 into opentripplanner:master Jan 8, 2017
@novalis
Copy link
Contributor

novalis commented Jan 8, 2017

Thanks for all your hard work on this.

I've gone ahead and merged it even though Travis is failing, since when I test locally, the tests pass.

@barslett
Copy link
Contributor Author

barslett commented Jan 8, 2017

Thanks, I also wonder what happened, as the tests pass locally here as well.

t2gran added a commit to entur/OpenTripPlanner that referenced this pull request Apr 12, 2018
t2gran added a commit to entur/OpenTripPlanner that referenced this pull request Apr 12, 2018
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.

2 participants