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

Remove degree-zero vertices from steiner_tree output #82

Merged
merged 5 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/steiner_tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@ using SimpleTraits: SimpleTraits, Not, @traitfn
map(v -> vertex_positions(g)[v], term_vert),
dist_matrix_to_position_dist_matrix(g, distmx),
)
return typeof(g)(position_tree, map(v -> ordered_vertices(g)[v], vertices(position_tree)))
named_st = typeof(g)(
emstoudenmire marked this conversation as resolved.
Show resolved Hide resolved
position_tree, map(v -> ordered_vertices(g)[v], vertices(position_tree))
)
# Detect and remove vertices of degree zero
zero_verts = filter(v -> degree(named_st, v) == 0, vertices(named_st))
for v in zero_verts
rem_vertex!(named_st, v)
end
emstoudenmire marked this conversation as resolved.
Show resolved Hide resolved
return named_st
end
5 changes: 4 additions & 1 deletion test/test_namedgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,10 @@ end
st = steiner_tree(g, terminal_vertices)
es = [(1, 2) => (1, 3), (1, 3) => (1, 4), (1, 4) => (2, 4), (2, 4) => (3, 4)]
@test ne(st) == 4
@test nv(st) == 12
@test nv(st) == 5
# Test that there are no degree-zero vertices in output:
zero_deg_verts = filter(v -> degree(st, v) == 0, vertices(st))
@test isempty(zero_deg_verts)
for e in es
@test has_edge(st, e)
end
Expand Down
Loading