graph

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EdgeView

type EdgeView struct {
	From  int     `json:"from"`
	To    int     `json:"to"`
	Value float32 `json:"value,omitempty"`
}

type Graph

type Graph[S comparable, T any] struct {
	Vertices map[S]T             `json:"vertices,omitempty"`
	Edges    map[S]map[S]float32 `json:"edges,omitempty"`
}

func NewGraph

func NewGraph[S comparable, T any]() *Graph[S, T]

func (*Graph[S, T]) ConnectedGraph

func (g *Graph[S, T]) ConnectedGraph(seed S) *Graph[S, T]

func (*Graph[S, T]) MinimumSpanningTree

func (g *Graph[S, T]) MinimumSpanningTree(seed S, negate bool) *Graph[S, T]

MinimumSpanningTree

  • MinimumSpanningTree returns a minimum spanning tree of the graph.
  • The seed is the starting point of the tree.
  • If negate is true, the maximum spanning tree is returned.

func (*Graph[S, T]) PutEdge added in v0.2.2

func (g *Graph[S, T]) PutEdge(tail, head S, weight float32)

func (*Graph[S, T]) PutVertex added in v0.2.2

func (g *Graph[S, T]) PutVertex(key S, value T)

func (*Graph[S, T]) Render

func (g *Graph[S, T]) Render(key2int func(k S) int, value2string func(v T) string) GraphView

func (*Graph[S, T]) ShortestPathTree added in v0.2.2

func (g *Graph[S, T]) ShortestPathTree(seed S, costFunc func(x float32) float32) *Graph[S, T]

ShortestPathTree

  • ShortestPathTree returns a shortest path tree of the graph from the seed.
  • The costFunc is a function that returns the cost of the edge.
  • Typically, if the weight means like `importance`, the costFunc is a function that returns the 1 / weight.
  • It is calculated by Dijkstra's algorithm, so the costFunc must return a positive value.

type GraphView

type GraphView struct {
	Vertices []VertexView `json:"nodes"`
	Edges    []EdgeView   `json:"edges"`
}

type VertexView

type VertexView struct {
	ID    int    `json:"id"`
	Label string `json:"label"`
	Value string `json:"value,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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