github.com/gopherd/gonum@v0.0.4/graph/encoding/graph6/graph6_example_test.go (about)

     1  // Copyright ©2018 The Gonum Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package graph6_test
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"github.com/gopherd/gonum/graph"
    11  	"github.com/gopherd/gonum/graph/encoding/graph6"
    12  )
    13  
    14  func ExampleGraph() {
    15  	// Construct a graph from HOG graph 32194.
    16  	// https://hog.grinvin.org/ViewGraphInfo.action?id=32194
    17  	g := graph6.Graph("H@BQPS^")
    18  
    19  	// Get the nodes of the graph and print
    20  	// an adjacency list.
    21  	nodes := g.Nodes()
    22  	fmt.Printf("Number of nodes: %d\n", nodes.Len())
    23  	fmt.Println("Adjacency:")
    24  	for nodes.Next() {
    25  		fmt.Printf("\t%d: %d\n", nodes.Node().ID(), graph.NodesOf(g.From(nodes.Node().ID())))
    26  	}
    27  
    28  	// Output:
    29  	//
    30  	// Number of nodes: 9
    31  	// Adjacency:
    32  	// 	0: [5]
    33  	// 	1: [5 6]
    34  	// 	2: [3 7]
    35  	// 	3: [2 5 8]
    36  	// 	4: [6 7 8]
    37  	// 	5: [0 1 3 8]
    38  	// 	6: [1 4 7 8]
    39  	// 	7: [2 4 6 8]
    40  	// 	8: [3 4 5 6 7]
    41  }