NAME

Graph::Writer::Matrix - write Graph as a matrix

SYNOPSIS

use Graph::Writer::Matrix;
my $writer = Graph::Writer::Matrix->new;
$writer->write_graph($graph, 'filename.txt');
$writer->write_graph($graph, $filehandle);

DESCRIPTION

Graph::Writer::Matrix writes a Graph.pm graph to a file as a matrix. The output is rows and columns of the matrix. There are no vertex names or attributes in the output. In the current implementation $graph->vertices() is sorted alphabetically (sort) to give a consistent (though slightly arbitrary) matrix.

Format gp

format => "gp" is the matrix syntax of Pari/GP, including surrounding brackets,

[0,0,1;1,1,1;0,1,1]

There is no final newline, so the matrix can be printed somewhere in a bigger expression.

Format amtog

format => "amtog" is the matrix format read by the nauty tools amtog program.

This a vertex count followed by adjacency matrix. Matrix entry i,j is 0 or 1 according to whether there is an edge from i to j. For an undirected graph with no self-loops the "t" upper triangle form is written.

n=5
t
1000
110
10
1
q

For a directed graph or if there are self-loops the "m" form is written. (Though most of the nauty tools only operate on undirected graphs.)

n=5
m
01000
00100
00010
01000
00010
q

Matrix Type adjacency

matrix_type => "adjacency" selects an adjacency matrix. This is the default. Entry i,j is 1 or 0 according as there is or is not an edge from i to j. Diagonal entries i,i are likewise 1 or 0, according to whether there is a self-loop i to i.

For an undirected graph this matrix is a symmetric M[i,j]=M[j,i]. For a directed graph the entries are edge directions from i to j.

Matrix Type Laplacian

matrix_type => "Laplacian" selects the Laplacian matrix. This is a diagonal where entry i,i is the degree of vertex i, then subtract the adjacency matrix described above. If there are self-loops then they subtract from the diagonal entries.

The eigenvalues of the Laplacian have various properties. For a tree of n vertices the Wiener index = n * sum 1/eigenvalue[i], where the sum excludes the zero eigenvalue.

Matrix Type Seidel

matrix_type => "Seidel" selects the Seidel matrix. Entry i,j is -1 if an edge i to j, +1 if no edge, and 0 on the diagonal i,i.

FUNCTIONS

$writer = Graph::Writer::Graph6->new (key => value, ...)

Create and return a new writer object. The only key/value option is

format       => string
matrix_type  => string

format can be

"amtog" (the default)
"gp"

matrix_type can be

"adjacency"      1=edge, 0=not  (the default)
"Laplacian"      degree - adjacency 0,1
"Seidel"         adjacency -1=edge, +1=not, 0 on diagonal
$writer->write_graph($graph, $filename_or_fh)

Write $graph to $filename_or_fh as a matrix of the selected format and matrix_type.

SEE ALSO

Graph, Graph::Writer, nauty-amtog(1)

Graph::Writer::Graph6, Graph::Writer::Sparse6

HOME PAGE

http://user42.tuxfamily.org/graph-graph6/index.html

LICENSE

Copyright 2015, 2016, 2017, 2018 Kevin Ryde

Graph-Graph6 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Graph-Graph6 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Graph-Graph6. If not, see http://www.gnu.org/licenses/.