shortestpath

package
v0.0.0-...-8b501b0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Calculator

type Calculator struct {
	// contains filtered or unexported fields
}

Calculator implements a shortest path calculator from a single vertex to all other vertices in a connected graph.

func NewCalculator

func NewCalculator(numWorkers int) (*Calculator, error)

NewCalculator returns a new shortest path calculator instance.

func (*Calculator) AddEdge

func (c *Calculator) AddEdge(srcID, dstID string, cost int) error

AddEdge creates a directed edge from srcID to dstID with the specified cost. An error will be returned if a negative cost value is specified.

func (*Calculator) AddVertex

func (c *Calculator) AddVertex(id string)

AddVertex inserts a new vertex with the specified ID into the graph.

func (*Calculator) CalculateShortestPaths

func (c *Calculator) CalculateShortestPaths(ctx context.Context, srcID string) error

CalculateShortestPaths finds the shortest path costs from srcID to all other vertices in the graph.

func (*Calculator) Close

func (c *Calculator) Close() error

Close cleans up any allocated graph resources.

func (*Calculator) SetExecutorFactory

func (c *Calculator) SetExecutorFactory(factory bspgraph.ExecutorFactory)

SetExecutorFactory configures the calculator to use the a custom executor factory when CalculateShortestPaths is invoked.

func (*Calculator) ShortestPathTo

func (c *Calculator) ShortestPathTo(dstID string) ([]string, int, error)

ShortestPathTo returns the shortest path from the source vertex to the specified destination together with its cost.

type PathCostMessage

type PathCostMessage struct {
	// The ID of the vertex this cost announcement originates from.
	FromID string

	// The cost of the path from this vertex to the source vertex via FromID.
	Cost int
}

PathCostMessage is used to advertise the cost of a path through a vertex.

func (PathCostMessage) Type

func (pc PathCostMessage) Type() string

Type returns the type of this message.

Jump to

Keyboard shortcuts

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