Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "NamedGraphs"
uuid = "678767b0-92e7-4007-89e4-4527a8725b19"
version = "0.11.5"
version = "0.12.0"
authors = ["Matthew Fishman <mfishman@flatironinstitute.org>, Joseph Tindall <jtindall@flatironinstitute.org> and contributors"]

[workspace]
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ path = ".."
Documenter = "1.10"
ITensorFormatter = "0.2.27"
Literate = "2.20.1"
NamedGraphs = "0.11"
NamedGraphs = "0.12"
2 changes: 1 addition & 1 deletion examples/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ path = ".."

[compat]
Graphs = "1.12"
NamedGraphs = "0.11"
NamedGraphs = "0.12"
22 changes: 11 additions & 11 deletions src/lib/NamedGraphGenerators/src/graphgenerators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 10 additions & 10 deletions test/test_abstractgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion test/test_namedgraphgenerators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down
Loading