Help getting started with Julia's Graphs package

1,167 views
Skip to first unread message

Ed Scheinerman

unread,
Feb 22, 2014, 5:24:24 PM2/22/14
to julia...@googlegroups.com
I have looked through the documentation for the Graphs package here: http://julialang.org/Graphs.jl/index.html 
But I'm finding it difficult to get started, even creating simple graphs (undirected, no loops, no multiple edges). Adding vertices doesn't seem to work. 
Is there a tutorial somewhere to help me get started? Thanks. 

Uwe Korn

unread,
Feb 23, 2014, 12:50:01 PM2/23/14
to julia...@googlegroups.com

On Saturday, 22 February 2014 22:24:24 UTC, Ed Scheinerman wrote:
I have looked through the documentation for the Graphs package here: http://julialang.org/Graphs.jl/index.html 
But I'm finding it difficult to get started, even creating simple graphs (undirected, no loops, no multiple edges). Adding vertices doesn't seem to work. 

For an adjacency list representation, this short snippet may be helpful:

using Graphs

# Create new graph
g = adjlist(KeyVertex{ASCIIString}, is_directed=false)

# Add 2 vertices
v = add_vertex!(g, "v")
u = add_vertex!(g, "u")

# Add an edge between them
add_edge!(g, v, u)

# This will print:
#   KeyVertex{ASCIIString}(1,"v")
# which is the neighbour of u
println(out_neighbors(u, g))
 
Is there a tutorial somewhere to help me get started? Thanks. 

I'm not aware of a tutorial (which would be indeed very helpful) but I learnt how to use the Graphs package by looking at its tests like https://github.com/JuliaLang/Graphs.jl/blob/master/test/adjlist.jl which outline quite short how that package works.

svaksha

unread,
Feb 23, 2014, 11:27:42 PM2/23/14
to julia...@googlegroups.com
I found a paper written by an MIT student who used the Graphs.jl
package : http://beowulf.lcs.mit.edu/18.337/projects/18.337project_huberman_report.pdf
Hope That Helps !
॥ svaksha ॥ http://svaksha.com

RecentConvert

unread,
Feb 24, 2014, 3:15:50 AM2/24/14
to julia...@googlegroups.com, sva...@gmail.com
From what I've seen on the Google group it seems like most people use an external package like Winston, PyPlot, or Gadfly. Searching for those might be a better place to start.

Eric Davies

unread,
Feb 24, 2014, 3:56:48 AM2/24/14
to julia...@googlegroups.com, sva...@gmail.com
Those are for plotting (graphing as in data visualization). The OP is asking about graphs, the data structures.

Ed Scheinerman

unread,
Feb 26, 2014, 8:06:29 AM2/26/14
to julia...@googlegroups.com
Thanks. This helps some. Let me illustrate. I just want simple graphs with integer-named vertices. This starts off well:

julia> using Graphs

julia> g = simple_graph(4)
Directed Graph (4 vertices, 0 edges)

julia> using Graphs

julia> g = simple_graph(4,is_directed=false)
Undirected Graph (4 vertices, 0 edges)

julia> add_edge!(g,1,2)
edge [1]: 1 -- 2

But if I want to add an additional vertex, I get trouble:

julia> add_vertex!(g,5)
ERROR: no method push!(Range1{Int64},Int64)
 in add_vertex! at /home/ers/.julia/Graphs/src/graph.jl:50

And I can't figure out how to delete vertices!

Uwe Korn

unread,
Feb 26, 2014, 4:07:40 PM2/26/14
to julia...@googlegroups.com


On Wednesday, 26 February 2014 13:06:29 UTC, Ed Scheinerman wrote:
But if I want to add an additional vertex, I get trouble:

julia> add_vertex!(g,5)
ERROR: no method push!(Range1{Int64},Int64)
 in add_vertex! at /home/ers/.julia/Graphs/src/graph.jl:50

This is because SimpleGraph is using a Range1{Int64} as the container of its vertices which cannot be modified using push!.

I opened a pull request that should make SimpleGraph editable: https://github.com/JuliaLang/Graphs.jl/pull/59

Jihui Han

unread,
Nov 3, 2015, 9:41:06 AM11/3/15
to julia-users
using  Graphs
g  
=  graph(collect(1:4),Edge{Int}[])
add_edge
!(g,1,2)
add_vertex
!(g,5)
delete vertex or edge is very expensive, so there are no those interfaces in Graphs.jl currently


在 2014年2月26日星期三 UTC+8下午9:06:29,Ed Scheinerman写道:
Reply all
Reply to author
Forward
0 new messages