gsdflow

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: 6 Imported by: 0

Documentation

Overview

Package gsdflow implements graph, almost same as package gsd.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SameEdge

func SameEdge(e1, e2 *Edge) bool

SameEdge returns true if two edges are the same.

func SameGraph

func SameGraph(g1, g2 *Graph) bool

SameGraph returns true if two graphs are equal.

func SameVertex

func SameVertex(v1, v2 *Vertex) bool

SameVertex returns true if two vertices are the same.

Types

type Edge

type Edge struct {
	Src    *Vertex // source vertex that this edge starts from
	Dst    *Vertex // destination vertex that this edge goes to
	Weight float64 // Used as capacify
	Flow   float64
}

Edge is an edge(arc) in a graph that has direction from one to another vertex.

func CopyEdge

func CopyEdge(edge *Edge) *Edge

CopyEdge returns the copy of input Edge.

func NewEdge

func NewEdge(src, dst *Vertex, weight float64) *Edge

NewEdge returns a new edge from src to dst.

type Graph

type Graph struct {
	Vertices *slice.Sequence
	Edges    *slice.Sequence
}

Graph is a graph represented in adjacency list, but implemented in slice.

func CopyGraph

func CopyGraph(graph *Graph) *Graph

CopyGraph returns the copy of input Graph.

func JSONGraph

func JSONGraph(filename, graph string) *Graph

JSONGraph parses JSON file to a graph.

func JSONGraphBi

func JSONGraphBi(filename, graph string) *Graph

JSONGraphBi connects the graph bi-directionally.

func JSONGraphT

func JSONGraphT(filename, graph string) *Graph

JSONGraphT parses JSON file to a graph in a reverse order. It returns the tranposed Graph of the original data.

func NewGraph

func NewGraph() *Graph

NewGraph returns a new graph.

func ParseToGraph

func ParseToGraph(str string) *Graph

ParseToGraph parses string data to return a new graph.

func (*Graph) AddEdge

func (g *Graph) AddEdge(e *Edge)

AddEdge adds the edge e to the graph g's Edges.

func (*Graph) AddFlow

func (g *Graph) AddFlow(src, dst *Vertex, value float64)

AddFlow updates the flow value between vertices.

func (*Graph) AddVertex

func (g *Graph) AddVertex(v *Vertex)

AddVertex adds the vertex v to the graph g's Vertices.

func (*Graph) Connect

func (g *Graph) Connect(A, B *Vertex, weight float64)

Connect connects the vertex v to A, not A to v.

func (*Graph) CreateAndAddToGraph

func (g *Graph) CreateAndAddToGraph(id string) *Vertex

CreateAndAddToGrammar finds the vertex with the ID, or create it.

func (*Graph) DeleteEdge

func (g *Graph) DeleteEdge(A, B *Vertex)

DeleteEdge deletes the edge from the vertex A to B. Note that this only delete one direction from A to B.

func (*Graph) DeleteVertex

func (g *Graph) DeleteVertex(A *Vertex)

DeleteVertex removes the input vertex A from the graph g's Vertices.

func (Graph) FindVertexByID

func (g Graph) FindVertexByID(id interface{}) *Vertex

FindVertexByID returns the vertex with input ID , or return nil if it doesn't exist.

func (Graph) GetEdge

func (g Graph) GetEdge(src, dst *Vertex) *Edge

GetEdge returns the Edge from src to dst Vertex. (Assume that there is no duplicate Edge for now.)

func (Graph) GetEdgeFlow

func (g Graph) GetEdgeFlow(src, dst *Vertex) []float64

GetEdgeFlow returns the slice of flow values.

func (Graph) GetEdgeWeight

func (g Graph) GetEdgeWeight(src, dst *Vertex) []float64

GetEdgeWeight returns the slice of weight values of the edge from source to destination vertex. In case we need to allow duplicate edges, we return a slice of weights.

func (Graph) GetEdges

func (g Graph) GetEdges() *slice.Sequence

GetEdges returns the edge slice.

func (Graph) GetEdgesSize

func (g Graph) GetEdgesSize() int

GetEdgesSize returns the size of edge slice in a graph.

func (Graph) GetVertices

func (g Graph) GetVertices() *slice.Sequence

GetVertices returns the vertex slice.

func (Graph) GetVerticesSize

func (g Graph) GetVerticesSize() int

GetVerticesSize returns the size of vertex slice in a graph.

func (Graph) ImmediateDominate

func (g Graph) ImmediateDominate(A, B *Vertex) bool

ImmediateDominate returns true if A immediately dominates B. That is, true if A can go to B with only one edge.

func (*Graph) IsFull

func (g *Graph) IsFull(src, dst *Vertex) bool

IsFull returns true if Flow reaches the capacity(Weight).

func (*Graph) ShowPrev

func (g *Graph) ShowPrev(id interface{}) string

ShowPrev shows the Prev of Vertex. (For debugging Dijkstra algorithm)

func (*Graph) SubFlow

func (g *Graph) SubFlow(src, dst *Vertex, value float64)

SubFlow updates the flow value between vertices.

func (*Graph) Transpose

func (g *Graph) Transpose() *Graph

Transpose transposes the original Graph.

func (*Graph) UpdateFlow

func (g *Graph) UpdateFlow(src, dst *Vertex, value float64)

UpdateFlow updates the flow value between vertices.

func (*Graph) UpdateWeight

func (g *Graph) UpdateWeight(src, dst *Vertex, value float64)

UpdateWeight updates the weight value between vertices.

type Vertex

type Vertex struct {
	ID    string
	Color string

	// slice of vertices that goes into this vertex
	// (vertices that precede this vertex in graph)
	InVertices *slice.Sequence

	// slice of vertices that go out of this vertex
	OutVertices *slice.Sequence

	// time stamp to record the distance
	// from source vertex
	StampD int64

	// another timestamp to be used in other algorithms
	StampF int64

	// By having this empty Sequence,
	// when implementing graph algorithms
	// we do not need to initialize the InVertices
	// with vtx.(*gsd.Vertex).InVertices.Init()
	// and do not modify the original graph
	Prev *slice.Sequence
}

Vertex is a vertex(node) in Graph.

func CopyVertex

func CopyVertex(vtx *Vertex) *Vertex

CopyVertex returns the copy of input Vertex.

func NewVertex

func NewVertex(id string) *Vertex

NewVertex returns a new Vertex.

func (*Vertex) AddInVertex

func (i *Vertex) AddInVertex(v *Vertex)

AddInVertex adds the vertex v to the vertex i's InVertices.

func (*Vertex) AddOutVertex

func (o *Vertex) AddOutVertex(v *Vertex)

AddOutVertex adds the vertex v to the vertex o's OutVertices.

func (*Vertex) DeleteInVertex

func (i *Vertex) DeleteInVertex(v *Vertex)

DeleteInVertex removes the input vertex v from the vertex i's InVertices.

func (*Vertex) DeleteOutVertex

func (o *Vertex) DeleteOutVertex(v *Vertex)

DeleteOutVertex removes the input vertex v from the vertex o's OutVertices.

func (Vertex) GetInVertices

func (v Vertex) GetInVertices() *slice.Sequence

GetInVertices returns a slice of adjacent vertices that goes to vertex v.

func (Vertex) GetInVerticesSize

func (v Vertex) GetInVerticesSize() int

GetInVerticesSize returns the size of the vertex v's InVertices.

func (Vertex) GetOutVertices

func (v Vertex) GetOutVertices() *slice.Sequence

GetOutVertices returns a slice of adjacent vertices from vertex v.

func (Vertex) GetOutVerticesSize

func (v Vertex) GetOutVerticesSize() int

GetOutVerticesSize returns the size of the vertex v's OutVertices

func (Vertex) GetPrev

func (v Vertex) GetPrev() *slice.Sequence

GetPrev returns a slice of Prev.

func (Vertex) GetPrevSize

func (v Vertex) GetPrevSize() int

GetPrevSize returns the size of the vertex v's Prev.

Jump to

Keyboard shortcuts

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