Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MetaGraphs load and save

How can I save and load a MetaGraph object from LightGraphs, and MetaGraphs, so that if I load the metagraph I still have the metadata? Right now I have a metagraph mg that I save using:

LightGraphs.savegraph("net.lg", mg)

But trying to reload it :

reloaded = LightGraphs.loadgraph("net.lg")

gives me the following:

BoundsError: attempt to access 2-element Array{SubString{String},1} at index [3]

Is there anyway to read in the metagraphs in the MetaGaphs package?

like image 628
A.Yazdiha Avatar asked May 07 '18 11:05

A.Yazdiha


1 Answers

We support MetaGraphs persistence using a JLD format provided by JLD2.jl:

using LightGraphs, MetaGraphs
julia> g = Graph(10,20)
{10, 20} undirected simple Int64 graph

julia> mg = MetaGraph(g)
{10, 20} undirected Int64 metagraph with Float64 weights defined by :weight (default weight 1.0)

julia> savegraph("foo.mg", mg)
1

julia> mg2 = loadgraph("foo.mg", MGFormat())
{10, 20} undirected Int64 metagraph with Float64 weights defined by :weight (default weight 1.0)

julia> mg2 == mg
true

Note that you need to specify MGFormat() in the loadgraph, otherwise LightGraphs won't know what type of graph you're trying to load.

like image 103
sbromberger Avatar answered Oct 10 '22 02:10

sbromberger