graphprac

package module
v0.0.0-...-7d1a4bf Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: BSD-3-Clause Imports: 16 Imported by: 0

README

graphprac

The graphprac package is a simple graph analysis tutorial package.

To start Binder

Documentation

Overview

Package graphprac provides helper routines for short practical in graph analysis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Betweenness

func Betweenness(g *Graph)

Betweenness performs a betweenness centrality analysis on g.

The betweenness centrality value is written into the "betweenness" attribute of each node.

func Clique

func Clique(g *Graph, k int)

Clique performs a maximal clique analysis on g where cliques must be k-cliques or larger.

The clique membership values are written as a comma-separated list into the "clique" attribute of each node and the number of cliques a node is a member of is written into "clique_count".

func Closeness

func Closeness(g *Graph)

Closeness performs a closeness centrality analysis on g.

The closeness centrality value is written into the "closeness" attribute of each node.

func Communities

func Communities(g *Graph, resolution float64)

Communities performs a community modularisation of the graph g at the specified resolution.

The community identity value is written into the "community" attribute of each node.

func DOT

func DOT(g graph.Graph) string

DOT renders the graph as a DOT language representation.

func Draw

func Draw(g graph.Graph, format string) (string, error)

Draw renders the graph as an SVG using the GraphViz command in format. The format parameter can be one of "dot", "neato", "fdp" and "sfdp". See https://www.graphviz.org/ for a description of these commands.

func EdgeBetweenness

func EdgeBetweenness(g *Graph)

EdgeBetweenness performs an edge betweenness centrality analysis on g.

The edge betweenness centrality value is written into the "edge_betweenness" attribute of each edge.

func Farness

func Farness(g *Graph)

Farness performs a farness centrality analysis on g.

The farness centrality value is written into the "farness" attribute of each node.

func Induce

func Induce(g *Graph, by []*Node) graph.Graph

Induce returns a subgraph based on g that contains only the nodes in by, and edges that have both ends in by.

func PageRank

func PageRank(g *Graph, damp, tol float64)

PageRank performs a PageRank analysis on g using the provided damping and tolerance parameters.

The PageRank value is written into the "rank" attribute of each node.

Types

type Attributes

type Attributes []encoding.Attribute

Attributes is a type to help handle DOT attributes.

func (Attributes) Attributes

func (a Attributes) Attributes() []encoding.Attribute

Attributes returns the complete list of attributes.

func (Attributes) DOTAttributes

func (a Attributes) DOTAttributes() []encoding.Attribute

DOTAttributes returns the DOT attributes for the receiver.

func (Attributes) Get

func (a Attributes) Get(attr string) string

Get returns the value of the given attribute. If the attribute is not set, the empty string is returned.

func (*Attributes) SetAttribute

func (a *Attributes) SetAttribute(attr encoding.Attribute) error

Set sets the given attribute to the specified value. If the attr Value field is the empty string, the attribute is unset.

type Edge

type Edge struct {
	F, T *Node
	Attributes
}

Edge is a graph edge able to handle DOT attributes.

func EdgesByAttribute

func EdgesByAttribute(attr string, g *Graph) ([]*Edge, error)

EdgesByAttribute return a slice of edges sorted descending by the given attribute.

func (*Edge) From

func (e *Edge) From() graph.Node

From returns the 'from' node of an edge.

func (*Edge) ReversedEdge

func (e *Edge) ReversedEdge() graph.Edge

ReversedEdge returns a copy of the edge with the 'from' and 'to' nodes swapped.

func (*Edge) To

func (e *Edge) To() graph.Node

To returns the 'to' node of an edge.

type Graph

type Graph struct {
	*simple.UndirectedGraph
	GraphAttrs, NodeAttrs, EdgeAttrs Attributes
}

Graph is a general undirected graph with node and edge attributes.

func NewGraph

func NewGraph(file string) (*Graph, error)

ReadGraph reads a DOT file and returns the encoded graph.

func (*Graph) DOTAttributers

func (g *Graph) DOTAttributers() (graph, node, edge encoding.Attributer)

DOTAttributers returns the global DOT attributes for the graph.

func (*Graph) NewEdge

func (g *Graph) NewEdge(from, to graph.Node) graph.Edge

NewEdge adds a new edge from the source to the destination node to the graph, or returns the existing edge if already present.

func (*Graph) NewNode

func (g *Graph) NewNode() graph.Node

NewNode adds a new node with a unique node ID to the graph.

func (*Graph) NodeMap

func (g *Graph) NodeMap() map[int64]*Node

NodeMap returns a mapping of ID integers to nodes in the graph.

type Node

type Node struct {
	NodeID int64
	Name   string
	Attributes
}

Node is a graph node able to handle DOT attributes.

func NodesByAttribute

func NodesByAttribute(attr string, g *Graph) ([]*Node, error)

NodesByAttribute return a slice of nodes sorted descending by the given attribute. Only float64 attributes are handled by this function.

func NodesOf

func NodesOf(g *Graph) []*Node

NodesOf returns the nodes in g asserted to be type graphprac.Node so that attributes can be accessed.

nodes := graphprac.NodesOf(g)
fmt.Println(nodes[i].Attributes.Get(attr))

func (*Node) DOTID

func (n *Node) DOTID() string

DOTID returns the node's DOT ID.

func (*Node) ID

func (n *Node) ID() int64

ID returns the ID of a node.

func (*Node) SetDOTID

func (n *Node) SetDOTID(id string)

SetDOTID sets the node's DOT ID.

Jump to

Keyboard shortcuts

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