Skip to content

Commit

Permalink
Remove degree-zero vertices from steiner_tree output (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
emstoudenmire authored May 28, 2024
1 parent 949d0a2 commit a8535ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/steiner_tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ 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)))
tree = typeof(g)(position_tree, map(v -> ordered_vertices(g)[v], vertices(position_tree)))
for v in copy(vertices(tree))
iszero(degree(tree, v)) && rem_vertex!(tree, v)
end
return tree
end
3 changes: 2 additions & 1 deletion test/test_namedgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,8 @@ 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 !any(v -> iszero(degree(st, v)), vertices(st))
for e in es
@test has_edge(st, e)
end
Expand Down

0 comments on commit a8535ec

Please sign in to comment.