ai4er-cdt / geograph

GeoGraph provides a tool for analysing habitat fragmentation and related problems in landscape ecology. GeoGraph builds a geospatially referenced graph from land cover or field survey data and enables graph-based landscape ecology analysis as well as interactive visualizations.
https://geograph.readthedocs.io
MIT License
39 stars 10 forks source link

Rewrite `merge_classes` to traverse through the graph. #72

Open herbiebradley opened 3 years ago

herbiebradley commented 3 years ago

Nice - I agree with your analysis, thank you for clarifying!

Regarding the proposed solution: Yes I think that works! (: How intensive is the merge operation? Does the sequential merging take much time? If so, we might be able to optimize it by leveraging the graph structure (forgive the pseudo code):

(1) Creating a set of all nodes with this class label (I'll call it _node_set, _ indicating that it's temporary ) (2) While _node_set is non-empty: (2.0) Pop the first node in current_node = _node_set.pop() (2.1) From current_node, do a graph traversal (e.g. bfs) along the nearest neighbors to find all nodes that can be reached from current_node by going through nodes with the same class label. Add those nodes to a list called nodes_to_merge. This will be one cluster of nodes that will be merged into a larger one. (2.2) Merge all nodes in nodes_to_merge, with the final index of current_node (2.2) Remove nodes_to_merge from _node_set

This way we'd be doing one "merge" per cluster of nodes (one in the above example), rather than one per neighbors (3 in the above example)

_Originally posted by @Croydon-Brixton in https://github.com/ai4er-cdt/geograph/pull/70#discussion_r634486539_