fix shortestPath function
shortestPath function now converts all dict keys to ints
This commit is contained in:
parent
9422d6f45f
commit
0521035af3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -3,6 +3,7 @@ from django.http import HttpResponse
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
import json
|
||||
import math
|
||||
|
||||
# Create your views here.
|
||||
|
||||
@ -15,10 +16,19 @@ def index(request):
|
||||
def classify(request):
|
||||
return HttpResponse(json.load(request))
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
def shortestPath(request):
|
||||
graph = json.load(request)["graph"]
|
||||
start_node = json.load(request)["start_node"]
|
||||
dest_node = json.load(request)["dest_node"]
|
||||
loaded_request = json.load(request)
|
||||
|
||||
graph = loaded_request["graph"]
|
||||
graph = {int(k): v for k, v in graph.items()}
|
||||
for node in graph:
|
||||
graph[node] = {
|
||||
int(k): v for k, v in graph[node].items()}
|
||||
|
||||
start_node = loaded_request["start_node"]
|
||||
dest_node = loaded_request["dest_node"]
|
||||
|
||||
distance = {}
|
||||
predecessor = {}
|
||||
@ -47,7 +57,7 @@ def shortestPath(request):
|
||||
current = node
|
||||
p = [current + 1]
|
||||
while current != start_node:
|
||||
p.append(predecessor[current] + 1)
|
||||
p.append(predecessor[current])
|
||||
current = predecessor[current]
|
||||
path[node] = p[::-1]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user