summaryrefslogtreecommitdiffstats
path: root/server.py
diff options
context:
space:
mode:
Diffstat (limited to 'server.py')
-rw-r--r--server.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/server.py b/server.py
index 6a93018..bfe5b0f 100644
--- a/server.py
+++ b/server.py
@@ -2,6 +2,7 @@ import json
import algorithms
import store
+import time
from lib import run_server, get, post, read_html
@@ -29,10 +30,21 @@ def shortest_path(body):
source_id = algorithms.get_closest_node_id(nodes, store.Node(-1, body['lat1'], body['lng1']))
target_id = algorithms.get_closest_node_id(nodes, store.Node(-1, body['lat2'], body['lng2']))
- path = algorithms.find_shortest_path(nodes, source_id, target_id)
- print(path)
- response = {"path": [(nodes[node].lat, nodes[node].lng) for node in path]}
-
+ start = time.time()
+ astar = algorithms.find_shortest_path_astar(nodes,
+ source_id,
+ target_id)
+ stop = time.time()
+ print(f"A* {stop-start:.4f}s {algorithms.path_length(nodes, astar)}")
+
+ start = time.time()
+ dijkstra = algorithms.find_shortest_path_dijkstra(nodes,
+ source_id,
+ target_id)
+ stop = time.time()
+ print(f"Dij {stop-start:.4f}s {algorithms.path_length(nodes, dijkstra)}")
+
+ response = {"path": [(nodes[node].lat, nodes[node].lng) for node in astar]}
return json.dumps(response)