Documentation
¶
Overview ¶
Package graph is the contract between a state space and the solver of package hpastar: an Implicit graph, the steps from each state (Transitions, each a Transition) and the estimate of the cost left (Heuristic), with an Index for the fastest dictionary and a Layout placing the states in a plane for HPA*.
A path is the cheapest where the graph keeps to four rules: a Transition's Cost is added to the path's cost and is never negative; the Heuristic never estimates more than the cheapest cost left to the goal, or the path found is not the cheapest; a consistent Heuristic, never more than a step's cost plus the estimate from the step's end, has no state expanded twice, while an inconsistent one may have a closed state opened again, which the search does; a step refused is a Transition not generated. A Heuristic scaled above the cheapest cost left (Weighted A*) expands fewer states and trades the cheapest path for one found sooner.
A graph may serve several classes of search at once (Implicit.Classes): a step some of them cannot take is a Transition with their bits in its Refuses, and a search of class k finds the paths a graph of the steps k takes alone would give.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Heuristic ¶
type Heuristic[T comparable] func(from, to T) float64
Heuristic estimates the cheapest cost left from one state to another. It never estimates more than that, or the path found is not the cheapest; consistent (see the package), it has no state expanded twice.
type Implicit ¶
type Implicit[T comparable] struct { Forward Transitions[T] Heuristic Heuristic[T] // Index gives each state an integer of its own, in [0, Size) for a dictionary of a slot a // state (5 bytes each, an index outside panicking); with no Size the integers key a map, and // with no Index the states do. Index func(T) int Size int // Layout lays the states out in a plane; with one, a path between ends far apart is found by // HPA* over a hierarchy of clusters, nil keeping every path the cheapest, found by A*. Layout *Layout[T] // Classes is how many classes the graph serves, up to 8, each taking the steps whose Refuses // leaves its bit clear, the bits from Classes up unread; 0 and 1 are one class. Classes int }
Implicit is a state space to search, told by the steps from each state rather than listed: its steps and the estimate of the cost left, with an Index for the fastest dictionary and a Layout for HPA* where the states lie in a plane. Its functions are called by every search at once.
type Layout ¶
type Layout[T comparable] struct { // Coords is where a state lies; a state it places nowhere has its paths found by A*. Coords func(T) (x, y int, ok bool) // At appends to buf every state Coords places at x, y, but for the ends a caller makes of // its own, which step only within their cluster. At func(x, y int, buf []T) []T Width, Height int // Backward is Forward seen from where its steps end: the states a step leads from into to, // each at that step's cost and refused to the classes it refuses. Backward Transitions[T] }
Layout is how a graph's states lie in a plane of Width × Height integer coordinates, for HPA*; it needs the graph's Index. Its functions are called by every search at once.
type Transition ¶
type Transition[T comparable] struct { To T Cost float64 // Refuses has bit k set where class k cannot take the step, 0 where every class can; a graph // of one class never reads it. Refuses uint8 }
Transition is one step a search may take: the state it reaches and its Cost, added to the path's and never negative.
type Transitions ¶
type Transitions[T comparable] func(from, prev T, buffer []Transition[T]) []Transition[T]
Transitions appends to buffer every step from from, prev being the state from was reached from (from itself at the start), and returns it; a step refused is one not appended. A larger buffer returned is kept for the next call.