File storage

using Graphs
using MetaGraphsNext

MGFormat

MetaGraphsNext.jl overloads Graphs.savegraph to write graphs in a custom format called MGFormat, which is based on JLD2. It is not very readable, but it does give the right result when we load it back.

example = MetaGraph(Graph(), Symbol);

example2 = mktemp() do file, io
    savegraph(file, example)
    loadgraph(file, "something", MGFormat())
end

example2 == example
true

DOTFormat

MetaGraphsNext.jl also support the more standard DOT encoding, which is used as follows.

simple = MetaGraph(Graph(), Symbol);

simple[:a] = nothing;
simple[:b] = nothing;
simple[:a, :b] = nothing;

simple_str = mktemp() do file, io
    savegraph(file, simple, DOTFormat())
    read(file, String)
end

print(simple_str)
graph T {
    a
    b
    a -- b
}
complicated = MetaGraph(
    DiGraph();
    label_type=Symbol,
    vertex_data_type=Dict{Symbol,Int},
    edge_data_type=Dict{Symbol,Int},
    graph_data=(tagged=true,),
);

complicated[:a] = Dict(:code_1 => 1, :code_2 => 2);

complicated[:b] = Dict(:code => 2);

complicated[:a, :b] = Dict(:code => 12);

complicated_str = mktemp() do file, io
    savegraph(file, complicated, DOTFormat())
    read(file, String)
end

print(complicated_str)
digraph G {
    tagged = true
    a [code_1 = 1, code_2 = 2]
    b [code = 2]
    a -> b [code = 12]
}

This page was generated using Literate.jl.