// Route takes a created graph object and finds the shortest path from start to end, returning // that path as a list of edges. func Route(graph *m.Graph) []*m.Edge { if graph.StartNode() == nil || graph.EndNode() == nil { return nil } addMinPathLeft(graph) startPath := m.CreatePath() startPath.AddRewards(graph.StartNode().Rewards()) pq := &m.PrioQueue{} heap.Init(pq) addNodeEdgesToPrioQueue(pq, graph.StartNode(), startPath) for path := prioPath(pq); path != nil; path = prioPath(pq) { node := path.Edges()[len(path.Edges())-1].To() if node == graph.EndNode() { return path.Edges() } addNodeEdgesToPrioQueue(pq, node, path) } return nil }