Reading and writing Graphs
Graphs may be written to I/O streams and files using the writegraph
function and read with the readgraph
function. Currently supported common graph formats are GraphML, GML, Gexf, DOT, Pajek .net, graph-tool gt. If fast I/O and small memory footprint is a priority, use the .gt
binary format.
Examples
writegraph("mygraph.gml", g) #format is inferred by the name
writegraph("mygraph.graphml", g)
g = readgraph("mygraph.dot")
g = readgraph("mygraph.net")
#
Erdos.readgraph
— Method.
readgraph(filename, G=Graph)
readgraph(filename, t, G=Graph; compressed=false)
Reads a graph from filename
in the format t
. Returns a graph of type G
or the corresponding digraph/graph type. Compressed files can eventually be read.
Supported formats are :gml, :dot, :graphml, :gexf, :net, :gt
.
If no format is provided, it will be inferred from filename
.
readgraph(s::Symbol, G=Graph)
Read a graph identified by s
from Erdos datasets collection (e.g. s=:karate
). They are stored in the gt
binary format in the datasets
directory of the package. For a list of available graph refer to the documentation.
#
Erdos.readnetwork
— Method.
readnetwork(filename, G=Graph)
readnetwork(filename, t, G=Graph; compressed=false)
Reads a graph from filename
in the format t
. Returns a graph of type G
or the corresponding digraph/graph type. Compressed files can eventually be read.
Supported formats are :gml, :dot, :graphml, :gexf, :net, :gt
.
If no format is provided, it will be inferred from filename
.
readnetwork(s::Symbol, G=Graph)
Read a graph identified by s
from Erdos datasets collection (e.g. s=:karate
). They are stored in the gt
binary format in the datasets
directory of the package. For a list of available graph refer to the documentation.
#
Erdos.writegraph
— Method.
writegraph(file, g)
writegraph(file, g, t; compress=false)
Save a graph g
to file
in the format t
.
Eventually the resulting file can be compressed in the gzip format.
Currently supported formats are :gml, :graphml, :gexf, :dot, :net, :gt
.
If no format is provided, it will be inferred from file
along with compression.
#
Erdos.writenetwork
— Method.
writenetwork(file, g)
writenetwork(file, g, t; compress=false)
Save a graph g
to file
in the format t
.
Eventually the resulting file can be compressed in the gzip format.
Currently supported formats are :gml, :graphml, :gexf, :dot, :net, :gt
.
If no format is provided, it will be inferred from file
along with compression.