Class Graph6GraphWriter
- All Implemented Interfaces:
GraphWriter<Integer,
Integer>
'graph6' is a format for storing undirected graphs in a compact manner, using only printable ASCII characters. Files
in these format have text type and contain one line per graph. It is suitable for small graphs, or large dense
graphs. The format support graphs with vertices numbered 0..n-1 only, where n is the number of vertices, and edges
numbered 0..m-1 only, where m is the number of edges. A graph6 file contains a bit vector with n (n - 1) / 2
bits representing the edges of the graph. All bytes of a graph6 file are in the range 63..126, which are the
printable ASCII characters, therefore a bit vector is represented by a sequence of bytes in which each byte encode
only 6 bits.
The format does not support specifying the ids of the edges, therefore the writer will not write them. Nevertheless,
its possible to write and later read the graph using the Graph6GraphReader
class while keeping the edges ids:
if the edges in the written graph are numbered 0..m-1, and when they are iterated from 0
to m-1
they
are also ordered by the order of the bit vector, then the reader will assigned the same ids to the edges. The order
of the bit vector and the format details can be found
here. This way of keeping the edges ids is
enforced by the writer by default, but can be disabled by calling keepEdgesIds(boolean)
with false
.
The 'graph6' format is efficient for dense graph, for dense graphs the 'sparse6' format should be used.
Self edges and parallel edges are not supported by the format.
File with a graph in 'graph6' format usually have the extension .g6
.
- Author:
- Barak Ugav
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
keepEdgesIds
(boolean enable) Enable or disable keeping the edges ids.final void
writeGraph
(Graph<Integer, Integer> graph, Writer writer) Write a graph to an I/O writer.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.jgalgo.io.GraphWriter
writeGraph, writeGraph
-
Constructor Details
-
Graph6GraphWriter
public Graph6GraphWriter()Create a new writer.
-
-
Method Details
-
keepEdgesIds
public void keepEdgesIds(boolean enable) Enable or disable keeping the edges ids.The format does not support specifying the ids of the edges, therefore the writer will not write them. Nevertheless, its possible to write and later read the graph using the
Graph6GraphReader
class while keeping the edges ids: if the edges in the written graph are numbered 0..m-1, and when they are iterated from0
tom-1
they are also ordered by the order of the bit vector, then the reader will assigned the same ids to the edges. The order of the bit vector and the format details can be found here.If this option is enabled, which is also the default, if a graph is written by the writer and the edges iterated from
0
tom-1
are not ordered by the order of the bit vector, then an exception will be thrown. If this option is disabled, the ids of the edges will be ignored and there is not guarantee that the reader will assign the same ids to the edges.- Parameters:
enable
-true
to enable keeping the edges ids,false
to disable it
-
writeGraph
Description copied from interface:GraphWriter
Write a graph to an I/O writer.- Specified by:
writeGraph
in interfaceGraphWriter<V,
E> - Parameters:
graph
- a graphwriter
- an I/O writer to which the graph description will be written to
-