graph

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 0 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.

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]
}

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.
	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
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL