gpt4 book ai didi

graph - Julia 图,dijkstra_shortest_paths

转载 作者:行者123 更新时间:2023-12-04 23:20:52 29 4
gpt4 key购买 nike

我想要可扩展的图,能够添加顶点和边,并运行 dijkstra_shortest_paths算法。
我无法找到定义图形的正确方法,以便 dijkstra_shortest_paths会工作。
下面是我的尝试。

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"])

错误信息:
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})

最佳答案

我认为问题是["a"] - 您必须“手动”引用实际顶点,即

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

为我工作。

关于graph - Julia 图,dijkstra_shortest_paths,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27327295/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com