From c2331124a1950a20e6ba13e221a466202236065e Mon Sep 17 00:00:00 2001 From: Matthew Fishman Date: Mon, 15 Jun 2026 17:38:08 -0400 Subject: [PATCH] Add named_cycle_graph Adds `named_cycle_graph(n)`, returning the cycle graph on `n` vertices as a `NamedGraph`, mirroring the existing `named_path_graph`. --- Project.toml | 2 +- .../NamedGraphGenerators/src/NamedGraphGenerators.jl | 4 ++-- src/lib/NamedGraphGenerators/src/graphgenerators.jl | 8 ++++++-- test/test_exports.jl | 1 + test/test_namedgraphgenerators.jl | 12 ++++++++++-- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Project.toml b/Project.toml index d5dab0f3..48199812 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "NamedGraphs" uuid = "678767b0-92e7-4007-89e4-4527a8725b19" -version = "0.11.4" +version = "0.11.5" authors = ["Matthew Fishman , Joseph Tindall and contributors"] [workspace] diff --git a/src/lib/NamedGraphGenerators/src/NamedGraphGenerators.jl b/src/lib/NamedGraphGenerators/src/NamedGraphGenerators.jl index 763234e8..78c8af5d 100644 --- a/src/lib/NamedGraphGenerators/src/NamedGraphGenerators.jl +++ b/src/lib/NamedGraphGenerators/src/NamedGraphGenerators.jl @@ -1,7 +1,7 @@ module NamedGraphGenerators -export NamedGridGraph, named_binary_tree, named_comb_tree, named_grid, - named_hexagonal_lattice_graph, named_path_digraph, named_path_graph, +export NamedGridGraph, named_binary_tree, named_comb_tree, named_cycle_graph, + named_grid, named_hexagonal_lattice_graph, named_path_digraph, named_path_graph, named_triangular_lattice_graph include("graphgenerators.jl") diff --git a/src/lib/NamedGraphGenerators/src/graphgenerators.jl b/src/lib/NamedGraphGenerators/src/graphgenerators.jl index 16d296fe..f9f1a641 100644 --- a/src/lib/NamedGraphGenerators/src/graphgenerators.jl +++ b/src/lib/NamedGraphGenerators/src/graphgenerators.jl @@ -2,8 +2,8 @@ using ..GraphGenerators: comb_tree using ..GraphsExtensions: add_edges!, rem_vertices! using ..NamedGraphs: NamedGraph using Graphs.SimpleGraphs: AbstractSimpleGraph -using Graphs: IsDirected, bfs_tree, binary_tree, grid, inneighbors, merge_vertices, nv, - outneighbors, path_graph, rem_vertex! +using Graphs: IsDirected, bfs_tree, binary_tree, cycle_graph, grid, inneighbors, + merge_vertices, nv, outneighbors, path_graph, rem_vertex! using SimpleTraits: SimpleTraits, @traitfn, Not ## TODO: Bring this back in some form? @@ -75,6 +75,10 @@ function named_path_graph(dim::Integer) return NamedGraph(path_graph(dim)) end +function named_cycle_graph(dim::Integer) + return NamedGraph(cycle_graph(dim)) +end + function named_path_digraph(dim::Integer) return NamedDiGraph(path_digraph(dim)) end diff --git a/test/test_exports.jl b/test/test_exports.jl index 78dbaef3..8441495c 100644 --- a/test/test_exports.jl +++ b/test/test_exports.jl @@ -19,6 +19,7 @@ using Test: @test, @testset :NamedGridGraph, :named_binary_tree, :named_comb_tree, + :named_cycle_graph, :named_grid, :named_hexagonal_lattice_graph, :named_path_digraph, diff --git a/test/test_namedgraphgenerators.jl b/test/test_namedgraphgenerators.jl index 4a56d512..d93c2b9e 100644 --- a/test/test_namedgraphgenerators.jl +++ b/test/test_namedgraphgenerators.jl @@ -4,8 +4,8 @@ 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_grid, named_hexagonal_lattice_graph, - named_triangular_lattice_graph + is_directed_grid, ishypertorus, named_cycle_graph, named_grid, + named_hexagonal_lattice_graph, named_triangular_lattice_graph using NamedGraphs: NamedEdge using Test: @test, @test_throws, @testset @@ -49,6 +49,14 @@ using Test: @test, @test_throws, @testset @test all(d -> d == 6, degree_dist) end +@testset "named_cycle_graph" begin + g = named_cycle_graph(4) + @test nv(g) == 4 + @test ne(g) == 4 + @test issetequal(vertices(g), 1:4) + @test is_cycle_graph(g) +end + @testset "NamedGridGraph" begin g = NamedGridGraph((4, 4))