Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia graphs, dijkstra_shortest_paths

Tags:

graph

julia

I would like to have expandable graph, being able to add vertices and edges, and run dijkstra_shortest_paths algo. I am not able to find right way to define graph so that dijkstra_shortest_paths would work. Below is my attempt.

using Graphs
g1= graph(ExVertex[], ExEdge{ExVertex}[], is_directed=false)
dist_key = "dist"
v1 = add_vertex!(g1, "a")
v2 = add_vertex!(g1, "b")
v3 = add_vertex!(g1, "c")
e12 = add_edge!(g1, v1, v2)
e12.attributes[dist_key]=1.0
e13 = add_edge!(g1, v1, v3)
e13.attributes[dist_key]=1.0
e23 = add_edge!(g1, v2, v3)
e23.attributes[dist_key]=1.0
epi = AttributeEdgePropertyInspector{Float64}(dist_key)
dijkstra_shortest_paths(g1, epi, ["a"])

Error message:

dijkstra_shortest_paths has no method matching   dijkstra_shortest_paths(::GenericGraph{ExVertex,ExEdge{ExVertex},Array{ExVertex,1},Array{ExEdge{ExVertex},1},Array{Array{ExEdge{ExVertex},1},1}}, ::AttributeEdgePropertyInspector{Float64}, ::Array{ASCIIString,1})
like image 906
dejan Avatar asked Feb 12 '23 09:02

dejan


1 Answers

I think the problem is the ["a"] - you have to refer to the actual vertex "manually", i.e.

julia> sp = dijkstra_shortest_paths(g1, epi, [v1])
julia> sp.parents
3-element Array{ExVertex,1}:
 vertex [1] "a"
 vertex [1] "a"
 vertex [1] "a"
julia> sp.dists
3-element Array{Float64,1}:
 0.0
 1.0
 1.0

Works for me.

like image 83
IainDunning Avatar answered Feb 19 '23 19:02

IainDunning