Skip to content

Commit a8535ec

Browse files
Remove degree-zero vertices from steiner_tree output (#82)
1 parent 949d0a2 commit a8535ec

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/steiner_tree.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ using SimpleTraits: SimpleTraits, Not, @traitfn
99
map(v -> vertex_positions(g)[v], term_vert),
1010
dist_matrix_to_position_dist_matrix(g, distmx),
1111
)
12-
return typeof(g)(position_tree, map(v -> ordered_vertices(g)[v], vertices(position_tree)))
12+
tree = typeof(g)(position_tree, map(v -> ordered_vertices(g)[v], vertices(position_tree)))
13+
for v in copy(vertices(tree))
14+
iszero(degree(tree, v)) && rem_vertex!(tree, v)
15+
end
16+
return tree
1317
end

test/test_namedgraph.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,8 @@ end
675675
st = steiner_tree(g, terminal_vertices)
676676
es = [(1, 2) => (1, 3), (1, 3) => (1, 4), (1, 4) => (2, 4), (2, 4) => (3, 4)]
677677
@test ne(st) == 4
678-
@test nv(st) == 12
678+
@test nv(st) == 5
679+
@test !any(v -> iszero(degree(st, v)), vertices(st))
679680
for e in es
680681
@test has_edge(st, e)
681682
end

0 commit comments

Comments
 (0)