diff options
Diffstat (limited to 'algorithms.py')
| -rw-r--r-- | algorithms.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/algorithms.py b/algorithms.py index de954f4..cc8d35f 100644 --- a/algorithms.py +++ b/algorithms.py @@ -18,7 +18,16 @@ def length_haversine(p1, p2): def get_closest_node_id(nodes, source_node): """ Search through all nodes and return the id of the node that is closest to 'source_node'. """ - pass + min_node = None + min_value = None + + for node_id, node in nodes.items(): + length = length_haversine(source_node, node) + if min_node == None or length < min_value: + min_node = node_id + min_value = length + + return min_node def find_shortest_path(nodes, source_id, target_id): |
