gt

package
v0.0.0-...-e7df020 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2014 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package gt implements graph using adjacency matrix and map data structure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Output2DSlice

func Output2DSlice(mat [][]float64) string

Output2DSlice outputs the matrix in string format.

Types

type Graph

type Graph struct {
	Size   *int
	Matrix [][]float64

	// to look up the index of vertex
	Index map[string]int

	// to look up the string label from index
	Label map[int]string
}

Graph is a graph represented in adjacency matrix.

func JSONGraph

func JSONGraph(filename, graph string) *Graph

JSONGraph parses JSON file to a graph.

func NewGraph

func NewGraph(size int) *Graph

NewGraph returns a new graph in adjacency matrix. It returns the adjacency matrix of the size * size.

func ParseToGraph

func ParseToGraph(str string) *Graph

ParseToGraph parses string data to return a new graph.

func (*Graph) AddEdge

func (g *Graph) AddEdge(A, B string, val float64)

AddEdge adds an edge with the weight value. The edge goes from A to B, not B to A.

func (Graph) GetEdgeWeight

func (g Graph) GetEdgeWeight(A, B string) float64

GetEdgeWeight returns the value of the matrix which is the edge weight value from A to B.

func (Graph) GetEdgesSize

func (g Graph) GetEdgesSize() int

GetEdgesSize returns the size of edges.

func (Graph) GetInVertices

func (g Graph) GetInVertices(A string) []string

GetInVertices returns the vertices that goes into A.

func (Graph) GetOutVertices

func (g Graph) GetOutVertices(A string) []string

GetOutVertices returns the vertices that goes out of A.

func (Graph) GetVertices

func (g Graph) GetVertices() []string

GetVertices returns the slice of vertices.

func (Graph) GetVerticesSize

func (g Graph) GetVerticesSize() int

GetVerticesSize returns the size of vertices.

func (Graph) HasEdge

func (g Graph) HasEdge(A, B string) bool

HasEdge returns true if there is an edge from A to B.

func (*Graph) Initialize

func (g *Graph) Initialize(num float64)

Initialize initializes the elements of matrix with num.

func (Graph) OutputMatrix

func (g Graph) OutputMatrix() string

OutputMatrix outputs the matrix of Graph in string format.

func (*Graph) RemoveEdge

func (g *Graph) RemoveEdge(A, B string)

RemoveEdge removes an edge from A to B, not B to A.

Jump to

Keyboard shortcuts

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