diff --git a/Project.toml b/Project.toml index 48199812..cd2db021 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "NamedGraphs" uuid = "678767b0-92e7-4007-89e4-4527a8725b19" -version = "0.11.5" +version = "0.12.0" authors = ["Matthew Fishman , Joseph Tindall and contributors"] [workspace] diff --git a/docs/Project.toml b/docs/Project.toml index fc7076f7..37f6732b 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -11,4 +11,4 @@ path = ".." Documenter = "1.10" ITensorFormatter = "0.2.27" Literate = "2.20.1" -NamedGraphs = "0.11" +NamedGraphs = "0.12" diff --git a/examples/Project.toml b/examples/Project.toml index e0527b64..6ebaee8c 100644 --- a/examples/Project.toml +++ b/examples/Project.toml @@ -7,4 +7,4 @@ path = ".." [compat] Graphs = "1.12" -NamedGraphs = "0.11" +NamedGraphs = "0.12" diff --git a/src/lib/NamedGraphGenerators/src/graphgenerators.jl b/src/lib/NamedGraphGenerators/src/graphgenerators.jl index f9f1a641..a880583f 100644 --- a/src/lib/NamedGraphGenerators/src/graphgenerators.jl +++ b/src/lib/NamedGraphGenerators/src/graphgenerators.jl @@ -28,29 +28,29 @@ end simple_children = children(tree, simple_parent) for n in 1:length(simple_children) simple_child = simple_children[n] - named_child = (named_parent..., child_name(n)) + named_child = [named_parent; child_name(n)] named_vertices[simple_child] = named_child set_named_vertices!(named_vertices, tree, simple_child, named_child; child_name) end return named_vertices end -# TODO: Use vectors as vertex names? +# Each vertex is named by its path from the root, as a vector of child indices. # k = 3: -# 1 => (1,) -# 2 => (1, 1) -# 3 => (1, 2) -# 4 => (1, 1, 1) -# 5 => (1, 1, 2) -# 6 => (1, 2, 1) -# 7 => (1, 2, 2) +# 1 => [1] +# 2 => [1, 1] +# 3 => [1, 2] +# 4 => [1, 1, 1] +# 5 => [1, 1, 2] +# 6 => [1, 2, 1] +# 7 => [1, 2, 2] function named_bfs_tree_vertices( simple_graph::AbstractSimpleGraph, source::Integer = 1; source_name = 1, child_name = identity ) tree = bfs_tree(simple_graph, source) - named_vertices = Vector{Tuple}(undef, nv(simple_graph)) - named_source = (source_name,) + named_source = [source_name] + named_vertices = Vector{typeof(named_source)}(undef, nv(simple_graph)) named_vertices[source] = named_source set_named_vertices!(named_vertices, tree, source, named_source; child_name) return named_vertices diff --git a/test/Project.toml b/test/Project.toml index 9d7fb95b..dd4e2b5f 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -31,7 +31,7 @@ ITensorPkgSkeleton = "0.3.42" ITensorVisualizationBase = "0.1" KaHyPar = "0.3.1" Metis = "1.5" -NamedGraphs = "0.11" +NamedGraphs = "0.12" Pkg = "1.10" Random = "1.10" SafeTestsets = "0.1" diff --git a/test/test_abstractgraph.jl b/test/test_abstractgraph.jl index 60ce4ad0..16333afe 100644 --- a/test/test_abstractgraph.jl +++ b/test/test_abstractgraph.jl @@ -38,17 +38,17 @@ using Test: @test, @testset ng2 = named_binary_tree(3) net2 = edgetype(ng2) - @test vertex_path(ng2, (1, 1), (1, 2, 1)) == [(1, 1), (1,), (1, 2), (1, 2, 1)] - @test edge_path(ng2, (1, 1), (1, 2, 1)) == - [net2((1, 1), (1,)), net2((1,), (1, 2)), net2((1, 2), (1, 2, 1))] - @test vertex_path(ng2, (1, 1, 2), (1, 1, 1)) == [(1, 1, 2), (1, 1), (1, 1, 1)] - @test edge_path(ng2, (1, 1, 2), (1, 1, 1)) == - [net2((1, 1, 2), (1, 1)), net2((1, 1), (1, 1, 1))] + @test vertex_path(ng2, [1, 1], [1, 2, 1]) == [[1, 1], [1], [1, 2], [1, 2, 1]] + @test edge_path(ng2, [1, 1], [1, 2, 1]) == + [net2([1, 1], [1]), net2([1], [1, 2]), net2([1, 2], [1, 2, 1])] + @test vertex_path(ng2, [1, 1, 2], [1, 1, 1]) == [[1, 1, 2], [1, 1], [1, 1, 1]] + @test edge_path(ng2, [1, 1, 2], [1, 1, 1]) == + [net2([1, 1, 2], [1, 1]), net2([1, 1], [1, 1, 1])] # Test DFS traversals - @test post_order_dfs_vertices(ng2, (1,)) == - [(1, 1, 1), (1, 1, 2), (1, 1), (1, 2, 1), (1, 2, 2), (1, 2), (1,)] - @test pre_order_dfs_vertices(ng2, (1,)) == - [(1,), (1, 1), (1, 1, 1), (1, 1, 2), (1, 2), (1, 2, 1), (1, 2, 2)] + @test post_order_dfs_vertices(ng2, [1]) == + [[1, 1, 1], [1, 1, 2], [1, 1], [1, 2, 1], [1, 2, 2], [1, 2], [1]] + @test pre_order_dfs_vertices(ng2, [1]) == + [[1], [1, 1], [1, 1, 1], [1, 1, 2], [1, 2], [1, 2, 1], [1, 2, 2]] # directed trees dg1 = dfs_tree(g1, 5) diff --git a/test/test_namedgraphgenerators.jl b/test/test_namedgraphgenerators.jl index d93c2b9e..1c758b0a 100644 --- a/test/test_namedgraphgenerators.jl +++ b/test/test_namedgraphgenerators.jl @@ -4,7 +4,7 @@ using Graphs: a_star, add_edge!, add_vertex!, degree, edges, edgetype, has_edge, is_directed, ne, neighbors, nv, rem_edge!, rem_vertex!, vertices using NamedGraphs.GraphsExtensions: is_cycle_graph, vertextype using NamedGraphs.NamedGraphGenerators: NamedGridGraph, grid_ndims, grid_size, - is_directed_grid, ishypertorus, named_cycle_graph, named_grid, + is_directed_grid, ishypertorus, named_binary_tree, named_cycle_graph, named_grid, named_hexagonal_lattice_graph, named_triangular_lattice_graph using NamedGraphs: NamedEdge using Test: @test, @test_throws, @testset @@ -57,6 +57,19 @@ end @test is_cycle_graph(g) end +@testset "named_binary_tree" begin + g = named_binary_tree(3) + @test nv(g) == 7 + @test ne(g) == 6 + # The path-from-root labels share a concrete element type, so `vertextype` + # is concrete (the point of naming vertices this way). + @test vertextype(g) == Vector{Int} + @test issetequal( + vertices(g), + [[1], [1, 1], [1, 2], [1, 1, 1], [1, 1, 2], [1, 2, 1], [1, 2, 2]] + ) +end + @testset "NamedGridGraph" begin g = NamedGridGraph((4, 4))