diff options
| author | Gustav Sörnäs <gusso230@student.liu.se> | 2020-11-12 15:54:53 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gusso230@student.liu.se> | 2020-11-20 13:39:57 +0100 |
| commit | b88872bc574ccbebf14c922e0204c8c286cbce48 (patch) | |
| tree | 2b6dd9bec6bc686569f438e0a6098a1e4551f327 /server.py | |
| parent | 1527c553eaafa8c813834495cf74f8c3332a739a (diff) | |
| download | tdde25-b88872bc574ccbebf14c922e0204c8c286cbce48.tar.gz | |
show stats
Diffstat (limited to 'server.py')
| -rw-r--r-- | server.py | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -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) |
