summaryrefslogtreecommitdiffstats
path: root/algorithms.py
diff options
context:
space:
mode:
authorStefan Hansson <steha708@edu.liu.se>2020-11-05 15:10:55 +0100
committerNewbyte <steha708@liu.se>2020-11-05 15:10:55 +0100
commitd429f09e7e3bc8173e765aba8a91f2440c99a324 (patch)
treedf0d6466bad2fabc4412b0e352fc197f97a343fa /algorithms.py
parent6054b37c778ba6ea9d816bb9885513c19917a372 (diff)
downloadtdde25-d429f09e7e3bc8173e765aba8a91f2440c99a324.tar.gz
Implement finding nearest nodes to start and end positions
Diffstat (limited to 'algorithms.py')
-rw-r--r--algorithms.py11
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):