Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

distance calculation with a_star fails with SimpleWeightedGraph and SimpleWeightedDiGraph #69

Open
henrik-wolf opened this issue Apr 24, 2021 · 1 comment · May be fixed by #70
Open

Comments

@henrik-wolf
Copy link

I was trying to calculate the distance between two nodes using the A* algorithm implemented in LightGraphs. For example

using LightGraphs, SimpleWeightedGraphs
t = SimpleWeightedGraph(3)
add_edge!(t, 1, 2, 0.5)
add_edge!(t, 2, 3, 0.8)
add_edge!(t, 1, 3, 2.0)
a_star(t, 1,  3)

throws an error:

MethodError: no method matching SimpleWeightedGraphs.SimpleWeightedEdge{Int64,Float64}(::Int64, ::Int64)

So far I have worked out, that the problem arises, when the a_star algorithm tries to call the constructor of the SimpleWeightedEdge type in the a_start.jl file.
I would have believed that the definition of

SimpleWeightedEdge(x, y) = SimpleWeightedEdge(x, y, one(Float64))

in line 18 of simpleweightededge.jl would exactly match this case. Am I missing something, or is this a bug?

@mforets
Copy link

mforets commented May 10, 2021

The problem is that with E = edgetype(g) in reconstruct_path!, the full type parameters are used, but that's more specific than SimpleWeightedEdge(x, y).

A fix would be to define SimpleWeightedGraphs.SimpleWeightedEdge{T, U}(x::T, y::T) where T<:Integer where U<:Real = SimpleWeightedEdge(x, y, one(U)).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants