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
- type Dense
- type Edge
- type Graph
- type Sparse
- 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.
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 Graph ¶
type Graph[Node, Edge any] interface { Edges(Node) []Edge From(Edge) Node To(Edge) Node }
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 Weight ¶
type Weight interface { constraints.Integer | constraints.Float }
Click to show internal directories.
Click to hide internal directories.