forked from JuliaAttic/OldGraphs.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a16c09c
commit 66f4597
Showing
14 changed files
with
314 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,41 @@ | ||
<!-- AUTOGENERATED. See 'doc/build.jl' for source. --> | ||
## Writing a Graph | ||
Graphs may be written to I/O streams and files using the `write` function: | ||
### write | ||
Graphs may be written to I/O streams and files using the `save` function: | ||
### save | ||
``` | ||
write(io::IO, graphname::AbstractString, g::Union{LightGraphs.DiGraph,LightGraphs.Graph}) | ||
write(io::IO, g::LightGraphs.Graph) | ||
write(io::IO, g::LightGraphs.DiGraph) | ||
write(g::LightGraphs.Graph) | ||
write(g::LightGraphs.DiGraph) | ||
write{S<:AbstractString,G<:Union{LightGraphs.DiGraph,LightGraphs.Graph}}(graphs::Dict{S<:AbstractString,G<:Union{LightGraphs.DiGraph,LightGraphs.Graph}}, fn::AbstractString) | ||
write(g::LightGraphs.Graph, fn::AbstractString) | ||
write(g::LightGraphs.DiGraph, fn::AbstractString) | ||
write(g::Union{LightGraphs.DiGraph,LightGraphs.Graph}, gname::AbstractString, fn::AbstractString) | ||
save(io::IO, g::LightGraphs.Graph) | ||
save(io::IO, g::LightGraphs.DiGraph) | ||
save(io::IO, g::Union{LightGraphs.DiGraph,LightGraphs.Graph}, gname::AbstractString) | ||
save(io::IO, g::Union{LightGraphs.DiGraph,LightGraphs.Graph}, gname::AbstractString, t::Symbol) | ||
save(io::IO, g::LightGraphs.Graph, t::Symbol) | ||
save(io::IO, g::LightGraphs.DiGraph, t::Symbol) | ||
save(io::IO, d::Dict{AbstractString,Union{LightGraphs.DiGraph,LightGraphs.Graph}}) | ||
save(io::IO, d::Dict{AbstractString,Union{LightGraphs.DiGraph,LightGraphs.Graph}}, t::Symbol) | ||
save(fn::AbstractString, x...) | ||
``` | ||
``` | ||
write(stream, x) | ||
``` | ||
|
||
Write the canonical binary representation of a value to the given stream. Returns the number of bytes written into the stream. | ||
|
||
You can write multiple values with the same :func:`write` call. i.e. the following are equivalent: | ||
|
||
``` | ||
write(stream, x, y...) | ||
write(stream, x) + write(stream, y...) | ||
``` | ||
|
||
Writes a dictionary of (name=>graph) to a file `fn`, with default `GZip` compression. | ||
Saves multiple graphs in a dictionary mapping graph name to graph to stream `io` using graph type `t`. | ||
|
||
Returns number of graphs written. | ||
|
||
Writes a graph `g` with name `graphname` in a proprietary format to the IO stream designated by `io`. | ||
|
||
Returns 1 (number of graphs written). | ||
Saves a single graph `g` with name `gname` to stream `io` using graph type `t`. Returns the number of graphs written (1). | ||
|
||
## Reading a Graph From a File | ||
Graphs stored using the `write` functions above may be loaded using `readgraph`: | ||
### readgraph | ||
Graphs stored using the `save` functions above may be loaded using `load`: | ||
### load | ||
``` | ||
readgraph(fn::AbstractString) | ||
readgraph(fn::AbstractString, gname::AbstractString) | ||
load(io::IO) | ||
load(io::IO, gname::AbstractString) | ||
load(io::IO, gname::AbstractString, t::Symbol) | ||
load(io::IO, t::Symbol) | ||
load(fn::AbstractString, x...) | ||
``` | ||
Returns a dictionary of (name=>graph) loaded from file `fn`. | ||
Loads a single graph from stream `io` with name `gname` and graph type `t`. | ||
|
||
### readgraphml | ||
``` | ||
readgraphml(filename::AbstractString) | ||
readgraphml(filename::AbstractString, gname::AbstractString) | ||
``` | ||
Returns a dictionary (name=>graph) from file `fn` stored in [GraphML](http://en.wikipedia.org/wiki/GraphML) format. Can optionally restrict to a single graph by specifying a name in gname. | ||
|
||
### readgml | ||
``` | ||
readgml(filename::AbstractString) | ||
readgml(filename::AbstractString, gname::AbstractString) | ||
``` | ||
Returns a dictionary (name=>graph) from file `fn` stored in [GML](https://en.wikipedia.org/wiki/Graph_Modelling_Language) format. Can optionally restrict to a single graph by specifying a name in gname. | ||
Loads multiple graphs of type `t` from stream `io`. Returns a dictionary mapping graph name to graph. | ||
|
||
## Examples | ||
```julia | ||
julia> write(STDOUT, g) | ||
julia> write(g, "mygraph.jgz") | ||
julia> g = readgraph("mygraph.jgz") | ||
julia> g = readgraphml("mygraph.xml") | ||
julia> g = readgml("mygraph.gml") | ||
julia> save(STDOUT, g) | ||
julia> save("mygraph.jgz", g, "mygraph"; compress=true) | ||
julia> g = load("multiplegraphs.jgz") | ||
julia> g = load("multiplegraphs.xml", :graphml) | ||
julia> g = load("mygraph.gml", "mygraph", :gml) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
NI(x...) = error("This function is not implemented.") | ||
|
||
@deprecate readgraph load | ||
|
||
const filemap = Dict{Symbol, Tuple{Function, Function, Function, Function}}() | ||
# :gml => (loadgml, loadgml_mult, savegml, savegml_mult) | ||
# :graphml => (loadgraphml, loadgraphml_mult, savegraphml, savegraphml_mult) | ||
# :md => (loadmatrixdepot, NOTIMPLEMENTED, NOTIMPLEMENTED, NOTIMPLEMENTED) | ||
|
||
# load a single graph by name | ||
"""Loads a single graph from stream `io` with name `gname` and graph type `t`. | ||
""" | ||
function load(io::IO, gname::AbstractString, t::Symbol=:lg) | ||
t in keys(filemap) || error("Please select a supported graph format: one of $(keys(filemap))") | ||
return filemap[t][1](io, gname) | ||
end | ||
|
||
"""Loads multiple graphs of type `t` from stream `io`. Returns a dictionary | ||
mapping graph name to graph.""" | ||
function load(io::IO, t::Symbol=:lg) | ||
t in keys(filemap) || error("Please select a supported graph format: one of $(keys(filemap))") | ||
return filemap[t][2](io) | ||
end | ||
|
||
"""Saves a single graph `g` with name `gname` to stream `io` using graph type `t`. | ||
Returns the number of graphs written (1).""" | ||
function save(io::IO, g::SimpleGraph, gname::AbstractString, t::Symbol=:lg) | ||
t in keys(filemap) || error("Please select a supported graph format: one of $(keys(filemap))") | ||
return filemap[t][3](io, g, gname) | ||
end | ||
|
||
# save a single graph without name | ||
save(io::IO, g::Graph, t::Symbol=:lg) = save(io, g, "Unnamed Graph", t) | ||
save(io::IO, g::DiGraph, t::Symbol=:lg) = save(io, g, "Unnamed DiGraph", t) | ||
|
||
# save a dictionary of graphs {"name" => graph} | ||
"""Saves multiple graphs in a dictionary mapping graph name to graph to stream | ||
`io` using graph type `t`.""" | ||
function save(io::IO, d::Dict{AbstractString, SimpleGraph}, t::Symbol=:lg) | ||
t in keys(filemap) || error("Please select a supported graph format: one of $(keys(filemap))") | ||
return filemap[t][4](io, d) | ||
end | ||
|
||
# load from a file | ||
function load(fn::AbstractString, x...) | ||
GZip.open(fn,"r") do io | ||
load(io, x...) | ||
end | ||
end | ||
|
||
# save to a file | ||
function save(fn::AbstractString, x...; compress::Bool=false) | ||
if compress | ||
io = GZip.open(fn,"w") | ||
else | ||
io = open(fn,"w") | ||
end | ||
retval = save(io, x...) | ||
close(io) | ||
return retval | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.