GraphViz2::Parse::Graph6 - read graph6 or sparse6 file into a GraphViz2 graph
use GraphViz2::Parse::Graph6; my $parse = GraphViz2::Parse::Graph6->new; $parse->create(file_name => 'foo.g6'); my $graphviz2 = $parse->graph; # GraphViz2 object # or in one chain ... my $graphviz2 = GraphViz2::Parse::Graph6->new ->create(str => ":Bf\n") ->graph; # GraphViz2 object
GraphViz2::Parse::Graph6 reads a graph6 or sparse6 format file into a GraphViz2 graph object. These file formats are per
GraphViz2::Parse::Graph6
GraphViz2
http://cs.anu.edu.au/~bdm/data/formats.txt
The formats represent a graph with vertices numbered 0 to n-1. These are made into GraphViz2 vertex names as numbers like "0" to "99".
graph6 and sparse6 are undirected. sparse6 can have multi-edges and self loops. They are added to the graph with multiple add_edge() in the usual way.
add_edge()
See Graph::Graph6 for further notes on the formats.
$parse = GraphViz2::Parse::Graph6->new (key=>value, ...)
Create and return a new parse object. The only key/value parameter is a graph to read into
graph => GraphViz2 object
The default is to create a suitable undirected graph. Currently no options or attributes are set on this default.
graph
graph6 and sparse6 have no attributes (only vertex numbers and edges) so it's up to an application to set any desired drawing styles. That can be done by giving a graph with options, or by retrieving the $parse->graph created and adding to it. Note that node or edge defaults should be set before reading with create() since those settings apply only to subsequently added nodes and edges. A graph given should be undirected (which is the GraphViz2 default).
$parse->graph
node
edge
create()
$graphviz2 = $parse->graph ()
$parse->graph ($graphviz2)
Get or set the graph object which create() will write into.
$parse->create (key=>value, ...)
Read a graph from a file or string of graph6 or sparse6 data. The key/value parameters are
file_name => filename (string) fh => file handle (globref) str => string of graph6 or sparse6
One of these must be given as the input source. The return value is the $parse object itself if successful, or undef at end of file.
$parse
undef
Invalid file contents or read error call the graph object log() method $graphviz2->log(error=>"..."), which by default is a die.
log()
$graphviz2->log(error=>"...")
die
It's common to have several graphs in a graph6 or sparse6 file, one after the other. They can be read successively by giving fh as an open handle to such a file. After a successful read the handle is left positioned at the next graph.
fh
The end-of-file undef return is given for fh reaching EOF, or immediate EOF on an empty file or empty str. This is designed to make the three inputs the same (file_name equivalent to open and fh, or both equivalent to slurp and contents as str). An application can consider whether an empty file should mean no graphs or some error.
str
file_name
A $parse object can be re-used to read further graphs. Set a new empty graph to write to each time. See examples/graphviz2-geng.pl for a complete sample program doing this.
digraph6 format is accepted by the code here, but the handling of directedness of the resulting GraphViz2 object is not quite right. The intention is for create() to set directedness of the target graph, reckoning directedness as being part of the input read, ie. the format graph6, sparse6 or digraph6. But GraphViz2 circa 2.46 takes directedness only when creating the graph, not a later change. For now reading digraph6 works if the application passes in a directed graph.
GraphViz2, GraphViz2::Parse::Yacc
Graph::Graph6, nauty-showg(1)
http://user42.tuxfamily.org/graph-graph6/index.html
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/.
To install Graph::Graph6, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Graph::Graph6
CPAN shell
perl -MCPAN -e shell install Graph::Graph6
For more information on module installation, please visit the detailed CPAN module installation guide.