Converting a directed graph to undirected

I am reading a graph from an edge list and then trying to convert the directed graph into undirected as follows.

using GraphIO
using SimpleGraphs

data = "network.txt" #edge list of the network
g = loadgraph(data,GraphIO.EdgeList.EdgeListFormat())

print(typeof(g)) #prints SimpleDiGraph{Int64}

print(simplify(g)) #should convert SimpleDiGraph to SimpleGraph according to [this documentation](https://github.com/EliasBcd/SimpleGraphs.jl)

But I get the following error

ERROR: LoadError: MethodError: no method matching simplify(::SimpleDiGraph{Int64})
Closest candidates are:
  simplify(!Matched::SimpleGraphs.SimpleGraph) at /u/racball/.julia/packages/SimpleGraphs/xiUMi/src/simple_core.jl:388
  simplify(!Matched::SimpleDigraph{T}) where T at /u/racball/.julia/packages/SimpleGraphs/xiUMi/src/d_simple_core.jl:284
  simplify(!Matched::SimpleHypergraph{T}) where T at /u/racball/.julia/packages/SimpleGraphs/xiUMi/src/hyper/SimpleHypergraphs.jl:50
Stacktrace:
 [1] top-level scope at /nfs/nfs9/home/nobackup/racball/github/graphzip/exps/20210824_julia/main.jl:12
 [2] include(::Module, ::String) at ./Base.jl:377
 [3] exec_options(::Base.JLOptions) at ./client.jl:288
 [4] _start() at ./client.jl:484
in expression starting at /nfs/nfs9/home/nobackup/racball/github/graphzip/exps/20210824_julia/main.jl:12

Any suggestions?

I think GraphIO is loading the graph as a LightGraphs.SimpleDiGraph rather than a SimpleGraphs.SimpleDigraph. In other words, LightGraphs is a completely separate graph library that is not compatible with the SimpleGraphs library.

Also, the github link in your comment points to a very old fork of SimpleGraphs.jl. The correct, up-to-date repository with newer documentation is here:

1 Like

Thank you! I did put a feature request in GraphIO to read it as undirected.

You can use SimpleGraph(g) to cast to an undirected graph.

1 Like

Thank you. This works

Just a note for future visitors to this thread -
G = LightGraphs.SimpleGraph(g) makes a directed graph g into undirected G