package graph6

import "gonum.org/v1/gonum/graph/encoding/graph6"

Package graph6 implements graphs specified by graph6 strings.

Index

Examples

Functions

func IsValid

func IsValid(g Graph) bool

IsValid returns whether the graph is a valid graph6 encoding. An invalid Graph behaves as the null graph.

Types

type Graph

type Graph string

Graph is a graph6-represented undirected graph.

See https://users.cecs.anu.edu.au/~bdm/data/formats.txt for details and https://hog.grinvin.org/ for a source of interesting graphs in graph6 format.

Example

Code:play 

package main

import (
	"fmt"

	"gonum.org/v1/gonum/graph"
	"gonum.org/v1/gonum/graph/encoding/graph6"
)

func main() {
	// Construct a graph from HOG graph 32194.
	// https://hog.grinvin.org/ViewGraphInfo.action?id=32194
	g := graph6.Graph("H@BQPS^")

	// Get the nodes of the graph and print
	// an adjacency list.
	nodes := g.Nodes()
	fmt.Printf("Number of nodes: %d\n", nodes.Len())
	fmt.Println("Adjacency:")
	for nodes.Next() {
		fmt.Printf("\t%d: %d\n", nodes.Node().ID(), graph.NodesOf(g.From(nodes.Node().ID())))
	}

}

Output:

Number of nodes: 9
Adjacency:
	0: [5]
	1: [5 6]
	2: [3 7]
	3: [2 5 8]
	4: [6 7 8]
	5: [0 1 3 8]
	6: [1 4 7 8]
	7: [2 4 6 8]
	8: [3 4 5 6 7]

func Encode

func Encode(g graph.Graph) Graph

Encode returns a graph6 encoding of the topology of the given graph using a lexical ordering of the nodes by ID to map them to [0, n).

func (Graph) Edge

func (g Graph) Edge(uid, vid int64) graph.Edge

Edge returns the edge from u to v, with IDs uid and vid, if such an edge exists and nil otherwise. The node v must be directly reachable from u as defined by the From method.

func (Graph) EdgeBetween

func (g Graph) EdgeBetween(xid, yid int64) graph.Edge

EdgeBetween returns the edge between nodes x and y with IDs xid and yid.

func (Graph) From

func (g Graph) From(id int64) graph.Nodes

From returns all nodes that can be reached directly from the node with the given ID.

func (Graph) GoString

func (g Graph) GoString() string

func (Graph) HasEdgeBetween

func (g Graph) HasEdgeBetween(xid, yid int64) bool

HasEdgeBetween returns whether an edge exists between nodes with IDs xid and yid without considering direction.

func (Graph) Node

func (g Graph) Node(id int64) graph.Node

Node returns the node with the given ID if it exists in the graph, and nil otherwise.

func (Graph) Nodes

func (g Graph) Nodes() graph.Nodes

Nodes returns all the nodes in the graph.

Source Files

graph6.go

Version
v0.14.0 (latest)
Published
Aug 19, 2023
Platform
linux/amd64
Imports
7 packages
Last checked
6 days ago

Tools for package owners.