Documentation ¶
Index ¶
- func AStar[N comparable, E any, W Weight](g Weighted[N, E, W], start N, goal func(N) bool, h func(N) W) []E
- func BreadthFirstSearch[N comparable, E any](g Graph[N, E], start N, goal func(N) bool) []E
- func Dijkstra[N comparable, E any, W Weight](g Weighted[N, E, W], start N, goal func(N) bool) []E
- func MinimumCut[N, E comparable, W Weight](g UndirectedWeighted[N, E, W], a, b N) (cut W, edges iter.Seq[E], reachable iter.Seq[N])
- func WalkDepthFirst[N comparable, E any](g Graph[N, E], start N) iter.Seq[N]
- type Dense
- type Edge
- type Graph
- type Sparse
- type Undirected
- type UndirectedWeighted
- type Weight
- type Weighted
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AStar ¶
func AStar[N comparable, E any, W Weight](g Weighted[N, E, W], start N, goal func(N) bool, h func(N) W) []E
AStar calculates the shortest path from start to a node satisfying goal using the A* algorithm.
func BreadthFirstSearch ¶
func BreadthFirstSearch[N comparable, E any](g Graph[N, E], start N, goal func(N) bool) []E
BreadthFirstSearch calculates the shortest path from start to a node satisfying goal.
func Dijkstra ¶
func Dijkstra[N comparable, E any, W Weight](g Weighted[N, E, W], start N, goal func(N) bool) []E
Dijkstra calculates the shortest path from start to a node satisfying goal using Dijkstra's algorithm.
func MinimumCut ¶
func MinimumCut[N, E comparable, W Weight](g UndirectedWeighted[N, E, W], a, b N) (cut W, edges iter.Seq[E], reachable iter.Seq[N])
MinimumCut returns a minimal cut separating a and b, an iterator over the edges to cut and the nodes of the sub graphs containing a.
func WalkDepthFirst ¶
func WalkDepthFirst[N comparable, E any](g Graph[N, E], start N) iter.Seq[N]
WalkDepthFirst returns an iterator over a depth-first walk of g from start. Every reachable node is yielded exactly once.
Types ¶
type Dense ¶
type Dense[W constraints.Integer | constraints.Float] struct { N int // Number of nodes W []W // Weight of edge i->j at i•N+j }
Dense is a weighted graph represented by an adjacency matrix. It implements Weighted[int, [2]int, W].
func NewDense ¶
func NewDense[W constraints.Integer | constraints.Float](n int) *Dense[W]
NewDense creates a Dense graph with n nodes.
type Sparse ¶
type Sparse[W constraints.Integer | constraints.Float] struct { N int // contains filtered or unexported fields }
Sparse is a weighted graph represented by an adjacency list. It implements Weighted[int, [2]int, W].
func NewSparse ¶
func NewSparse[W constraints.Integer | constraints.Float](n int) *Sparse[W]
func (*Sparse[W]) Edges ¶
Edges returns the edges adjacent to i. The returned slice must not be modified.
type Undirected ¶
Undirected graph. Every edge must be reversible.
type UndirectedWeighted ¶
type UndirectedWeighted[N, E, W any] interface { Undirected[N, E] Weight(E) W }
Undirected weighted graph. It must be Weight(Revers(e)) == Weight(e) for all edges.
func MaximumFlow ¶
func MaximumFlow[N, E comparable, W Weight](g UndirectedWeighted[N, E, W], source, sink N) (W, iter.Seq2[E, W], UndirectedWeighted[N, E, W])
MaximumFlow returns the maximum flow from source to sink, an iterator over one maximizing flow and the residual graph of that flow.
type Weight ¶
type Weight interface { constraints.Integer | constraints.Float }