I have added the following lines in the implementation while looping through the nodes of the lowestCostNode and it seems to now be working but I am not certain if that's the best approach or otherwise.
for lowestCostNode != "" {
for node, cost := range graph[lowestCostNode] {
// The following three lines have been added
if _, isSet := costs[node]; !isSet {
costs[node] = cost
}
newCost := costs[lowestCostNode] + cost
if newCost < costs[node] {
costs[node] = newCost
parents[node] = lowestCostNode
}
}
processed[lowestCostNode] = true
lowestCostNode = findLowestCostNode(costs, processed)
}
Hi guys, I am trying to run the Golang implementation on the graph below and the cost to the stop is the MaxInt set in the beginning.
I have added the following lines in the implementation while looping through the nodes of the lowestCostNode and it seems to now be working but I am not certain if that's the best approach or otherwise.