From a8421abed27605d4ef8fac5b89ae2b477627bf60 Mon Sep 17 00:00:00 2001 From: Dan Ports Date: Sun, 17 May 2020 19:17:52 -0600 Subject: [PATCH] #26: Clean up the path structure a little bit. --- src/graph/apis/graph | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/graph/apis/graph b/src/graph/apis/graph index 992b9c4..2542715 100644 --- a/src/graph/apis/graph +++ b/src/graph/apis/graph @@ -1,6 +1,6 @@ -function formatPath(origin, path) - local result = origin - for k, v in ipairs(path) do +function formatPath(path) + local result = path.origin + for k, v in ipairs(path.edges) do result = result .. " == " .. tostring(v.weight) .. " ==> " .. v.edge.destination end return result @@ -60,9 +60,13 @@ function shortestPath(nodes, route, edgeWeight) end pathData[current].visited = true if (current == route.destination) then - local path = {} - while current ~= origin do - table.insert(path, 1, { + local path = { + origin = route.origin, + destination = route.destination, + edges = {} + } + while current ~= route.origin do + table.insert(path.edges, 1, { edge = pathData[current].edgeUsed, weight = pathData[current].weight })