NAME

Graph::Writer::Graph6 - write Graph.pm in graph6, sparse6 or digraph6 format

SYNOPSIS

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

CLASS HIERARCHY

Graph::Writer::Graph6 is a subclass of Graph::Writer.

Graph::Writer
  Graph::Writer::Graph6

DESCRIPTION

Graph::Writer::Graph6 writes a Graph.pm graph to a file in graph6, sparse6 or digraph6 format. These formats are per

graph6 represents an undirected graph with no self-loops or multi-edges. Any self-loops in $graph are ignored. Multi-edges are written just once, and if $graph is directed then an edge of either direction is written.

sparse6 represents an undirected graph possibly with multi-edges and self-loops. If $graph is directed then an edge in either direction is written. If there's edges both ways then a multi-edge is written.

digraph6 represents a directed graph, possibly with self-loops but no multi-edges. Any multi-edges in $graph are written just once. If $graph is undirected then an edge in written in both directions (though usually graph6 or sparse6 would be preferred in that case).

The formats have no vertex names and no attributes. In the current implementation $graph->vertices() is sorted alphabetically (sort) to give a consistent (though slightly arbitrary) vertex numbering.

See Graph::Graph6 for further notes on the formats. See examples/graph-random.pl for a complete sample program.

FUNCTIONS

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

Create and return a new writer object. The key/value options are

format   => "graph6", "sparse6" or "digraph6",
              string, default "graph6"
header   => boolean, default false

If header is true then write a header >>graph6<<, >>sparse6<< or >>digraph6<< as appropriate.

$writer->write_graph($graph, $filename_or_fh)

Write $graph to $filename_or_fh in the selected format. A final newline "\n" is written so this is suitable for writing multiple graphs one after the other.

$graph is either a Graph.pm object or something sufficiently compatible. There's no check on the actual class of $graph. (Don't mistakenly pass a Graph::Easy here. It's close enough that it runs, but doesn't give a consistent vertex order and might miss edges on undirected graphs.)

BUGS

For graph6 and digraph6, the current implementation uses Graph.pm method has_edge() and makes O(N^2) calls to it for a graph of N vertices. The overhead of this means writing a graph of many vertices is not particularly fast. For a graph of relatively few edges getting all edges() at once would be faster, but in that case writing sparse6 would be both smaller and faster, provided that format is suitable for a given application.

Graph.pm 0.96 had a bug on undirected multiedged graphs where its edges() method sometimes did not return all the edges of the graph, causing sparse6 output to miss some edges. This likely affects other things too so use version 0.97 for such a graph (or countedged undirected was ok).

SEE ALSO

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

Graph::Graph6, nauty-showg(1), nauty-copyg(1)

HOME PAGE

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

LICENSE

Copyright 2015, 2016, 2017 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/.