Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kruskal_mst and prim_mst return different types from SimpleWeightedGraph input #17

Closed
wjholden opened this issue Apr 1, 2022 · 2 comments
Labels
breaking Fixing this would require a breaking change

Comments

@wjholden
Copy link

wjholden commented Apr 1, 2022

The kruskal_mst function may contain some logic that the prim_mst function lacks. When I supply a SimpleWeightedGraph as input, the kruskal_mst function returns a vector of SimpleWeightedEdge. By contrast, the prim_mst function returns a vector of SimpleEdge instead. The behavior of kruskal_mst seems more beneficial, to me. Here is a small example:

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.7.1 (2021-12-22)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using Graphs, SimpleWeightedGraphs

julia> A=[0 7 0 5 0 0 0;0 0 8 0 7 0 0;0 0 0 0 5 0 0;0 0 0 0 18 6 0;0 0 0 0 0 8 9; 0 0 0 0 0 0 11;0 0 0 0 0 0 0]
7×7 Matrix{Int64}:
 0  7  0  5   0  0   0
 0  0  8  0   7  0   0
 0  0  0  0   5  0   0
 0  0  0  0  18  6   0
 0  0  0  0   0  8   9
 0  0  0  0   0  0  11
 0  0  0  0   0  0   0

julia> kruskal_mst(SimpleWeightedGraph(A + A'))
6-element Vector{SimpleWeightedEdge{Int64, Int64}}:
 Edge 1 => 4 with weight 5
 Edge 3 => 5 with weight 5
 Edge 4 => 6 with weight 6
 Edge 1 => 2 with weight 7
 Edge 2 => 5 with weight 7
 Edge 5 => 7 with weight 9

julia> prim_mst(SimpleWeightedGraph(A + A'))
6-element Vector{Graphs.SimpleGraphs.SimpleEdge{Int64}}:
 Edge 1 => 2
 Edge 5 => 3
 Edge 1 => 4
 Edge 2 => 5
 Edge 4 => 6
 Edge 5 => 7
@gdalle
Copy link
Member

gdalle commented May 21, 2022

See JuliaGraphs/Graphs.jl#130 and JuliaGraphs/Graphs.jl#172

This would require a breaking change in Graphs.jl, so we're saving it for v2.0

@gdalle gdalle added the enhancement New feature or request label May 21, 2022
@gdalle gdalle added wontfix This will not be worked on breaking Fixing this would require a breaking change and removed enhancement New feature or request wontfix This will not be worked on labels Apr 6, 2023
@gdalle
Copy link
Member

gdalle commented Apr 6, 2023

Since this is a Graphs.jl issue, I'm closing here

@gdalle gdalle closed this as completed Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Fixing this would require a breaking change
Projects
None yet
Development

No branches or pull requests

2 participants