From 47598e32a7de96264c1e1db9b6e062cf18df2132 Mon Sep 17 00:00:00 2001 From: Joey Date: Thu, 7 Nov 2024 16:08:38 -0500 Subject: [PATCH] Fix ambiguity on steiner_tree --- src/steiner_tree.jl | 14 +++++++++++++- test/test_namedgraph.jl | 10 ++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/steiner_tree.jl b/src/steiner_tree.jl index c01207f..1672955 100644 --- a/src/steiner_tree.jl +++ b/src/steiner_tree.jl @@ -1,7 +1,7 @@ using Graphs: Graphs, IsDirected, nv, steiner_tree using SimpleTraits: SimpleTraits, Not, @traitfn -@traitfn function Graphs.steiner_tree( +@traitfn function namedgraph_steiner_tree( g::AbstractNamedGraph::(!IsDirected), term_vert, distmx=weights(g) ) position_tree = steiner_tree( @@ -11,3 +11,15 @@ using SimpleTraits: SimpleTraits, Not, @traitfn ) return typeof(g)(position_tree, map(v -> ordered_vertices(g)[v], vertices(position_tree))) end + +@traitfn function Graphs.steiner_tree( + g::AbstractNamedGraph::(!IsDirected), term_vert, args... +) + return namedgraph_steiner_tree(g, term_vert, args...) +end + +@traitfn function Graphs.steiner_tree( + g::AbstractNamedGraph::(!IsDirected), term_vert::Vector{<:Integer}, args... +) + return namedgraph_steiner_tree(g, term_vert, args...) +end diff --git a/test/test_namedgraph.jl b/test/test_namedgraph.jl index 2d9e6c0..f28f96c 100644 --- a/test/test_namedgraph.jl +++ b/test/test_namedgraph.jl @@ -679,6 +679,16 @@ end for e in es @test has_edge(st, e) end + + g = named_path_graph(4) + terminal_vertices = [1, 3] + st = steiner_tree(g, terminal_vertices) + es = [1 => 2, 2 => 3] + @test ne(st) == 2 + @test nv(st) == 3 + for e in es + @test has_edge(st, e) + end end @testset "topological_sort_by_dfs" begin g = NamedDiGraph(["A", "B", "C", "D", "E", "F", "G"])