Documentation
¶
Overview ¶
Graph abstraction and associated algorithms
Index ¶
- type Edge
- type Graph
- func (g *Graph) AddEdge(tail, head *Vertex, weight int)
- func (g *Graph) AddVertex(label string) *Vertex
- func (g *Graph) BellmanFordShortestPath(source *Vertex) (map[string]int, error)
- func (g *Graph) DijkstrasShortestPath(source *Vertex) map[string]int
- func (g *Graph) FloydWarshallAllShortestPath() (map[string]map[string]int, error)
- func (g *Graph) JohnsonsAllShortestPath() (map[string]map[string]int, error)
- type Vertex
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Graph ¶
func (*Graph) BellmanFordShortestPath ¶
An implementation of Bellman-Ford shortest path distance algorithm. The algorithm uses a variation of dynamic programming to produce a shortest path weight for each vertex relative to the given source. In the event of a negative cycle it returns nil with an error of a negative cycle.
func (*Graph) DijkstrasShortestPath ¶
"A blazingly fast shortest path algorithm" as Tim Roughgarden would put it, Dijkstra's Algorithm computes the shortest path from a given source vertex and all vertices within the graph. A value of math.MaxInt32 is used to represent infinity when a vertex is not reachable from the given source vertex.
func (*Graph) FloydWarshallAllShortestPath ¶
func (*Graph) JohnsonsAllShortestPath ¶
Johnsons algorithm is an all shortest path algorithm which provides weights of shortest paths from all vertices within the graph. The function returns a map vertex labels as keys and their sink maps keyed by sink labels. If the graph contains a negative cycle the function will return a nil result with an appropriate error.