Skip to content

Commit

Permalink
#26: Clean up the path structure a little bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
danports committed May 18, 2020
1 parent f1a80f3 commit a8421ab
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/graph/apis/graph
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
})
Expand Down

0 comments on commit a8421ab

Please sign in to comment.