Skip to content

Commit

Permalink
Change behavior of steiner_tree to remove degree-zero vertices.
Browse files Browse the repository at this point in the history
  • Loading branch information
emstoudenmire committed May 28, 2024
1 parent 0feb539 commit 6dce507
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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)(
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
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:
zv = filter(v -> degree(st, v) == 0, vertices(st))
@test isempty(zv)
for e in es
@test has_edge(st, e)
end
Expand Down

0 comments on commit 6dce507

Please sign in to comment.