WeightedGraph

package
v0.3.17 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Graph added in v0.3.7

type Graph[T uc.Objecter] struct {
	// contains filtered or unexported fields
}

Graph represents a graph.

func NewGraph added in v0.3.7

func NewGraph[T uc.Objecter](vertices []T, f WeightFunc[T]) *Graph[T]

NewGraph creates a new graph with the given vertices.

Parameters:

  • vertices: vertices in the graph.

Returns:

  • *WeightedGraph: the new graph.

func (*Graph[T]) AdjacentOf added in v0.3.7

func (g *Graph[T]) AdjacentOf(from T) []T

AdjacentOf returns the adjacent vertices of the given vertex.

Parameters:

  • from: the source vertex.

Returns:

  • []T: the adjacent vertices.

func (*Graph[T]) GetEdge added in v0.3.7

func (g *Graph[T]) GetEdge(from, to T) (float64, bool)

GetEdge returns the weight of the edge between the given vertices.

Parameters:

  • from: the source vertex.
  • to: the destination vertex.

Returns:

  • float64: the weight of the edge.
  • bool: true if the edge exists, otherwise false.

func (*Graph[T]) GetEdges added in v0.3.7

func (g *Graph[T]) GetEdges() [][]*float64

GetEdges returns the edges in the graph.

Returns:

  • [][]*float64: the edges.

func (*Graph[T]) GetVertices added in v0.3.7

func (g *Graph[T]) GetVertices() []T

GetVertices returns the vertices in the graph.

Returns:

  • []T: the vertices.

func (*Graph[T]) IndexOf added in v0.3.7

func (g *Graph[T]) IndexOf(elem T) int

IndexOf returns the index of the given element in the graph.

Parameters:

  • elem: the element to find.

Returns:

  • int: the index of the element, or -1 if not found.

func (*Graph[T]) MakeTree added in v0.3.7

func (g *Graph[T]) MakeTree(root T, info uc.Objecter, f tlt.NextsFunc[T]) (*tr.Tree[T], error)

MakeTree creates a tree of the graph with the given root.

Parameters:

  • root: the root of the tree.
  • f: the nexts function.

Returns:

  • *WeightedGraphTree: the tree of the graph.
  • error: an error if the tree creation fails.

type WeightFunc

type WeightFunc[T uc.Objecter] func(from, to T) (float64, bool)

WeightFunc is a function that calculates the weight of an edge.

Parameters:

  • from: the source vertex.
  • to: the destination vertex.

Returns:

  • float64: the weight of the edge.
  • bool: true if the edge exists, otherwise false.

Jump to

Keyboard shortcuts

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