Skip to content

Commit

Permalink
Expand functionality and tests (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman authored Apr 24, 2024
1 parent 10b9ce6 commit e064b67
Show file tree
Hide file tree
Showing 19 changed files with 898 additions and 170 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NamedGraphs"
uuid = "678767b0-92e7-4007-89e4-4527a8725b19"
authors = ["Matthew Fishman <[email protected]> and contributors"]
version = "0.4.2"
version = "0.5.0"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ julia> using NamedGraphs: NamedGraph
julia> using NamedGraphs.GraphsExtensions: , disjoint_union, subgraph, rename_vertices

julia> g = NamedGraph(grid((4,)), ["A", "B", "C", "D"])
NamedGraph{String} with 4 vertices:
NamedGraphs.NamedGraph{String} with 4 vertices:
4-element Dictionaries.Indices{String}
"A"
"B"
Expand Down Expand Up @@ -81,7 +81,7 @@ julia> neighbors(g, "B")
"C"

julia> subgraph(g, ["A", "B"])
NamedGraph{String} with 2 vertices:
NamedGraphs.NamedGraph{String} with 2 vertices:
2-element Dictionaries.Indices{String}
"A"
"B"
Expand All @@ -108,7 +108,7 @@ julia> dims = (2, 2)
(2, 2)

julia> g = NamedGraph(grid(dims), Tuple.(CartesianIndices(dims)))
NamedGraph{Tuple{Int64, Int64}} with 4 vertices:
NamedGraphs.NamedGraph{Tuple{Int64, Int64}} with 4 vertices:
4-element Dictionaries.Indices{Tuple{Int64, Int64}}
(1, 1)
(2, 1)
Expand Down Expand Up @@ -152,7 +152,7 @@ You can use vertex names to get [induced subgraphs](https://juliagraphs.org/Grap

```julia
julia> subgraph(v -> v[1] == 1, g)
NamedGraph{Tuple{Int64, Int64}} with 2 vertices:
NamedGraphs.NamedGraph{Tuple{Int64, Int64}} with 2 vertices:
2-element Dictionaries.Indices{Tuple{Int64, Int64}}
(1, 1)
(1, 2)
Expand All @@ -162,7 +162,7 @@ and 1 edge(s):


julia> subgraph(v -> v[2] == 2, g)
NamedGraph{Tuple{Int64, Int64}} with 2 vertices:
NamedGraphs.NamedGraph{Tuple{Int64, Int64}} with 2 vertices:
2-element Dictionaries.Indices{Tuple{Int64, Int64}}
(1, 2)
(2, 2)
Expand All @@ -172,7 +172,7 @@ and 1 edge(s):


julia> subgraph(g, [(1, 1), (2, 2)])
NamedGraph{Tuple{Int64, Int64}} with 2 vertices:
NamedGraphs.NamedGraph{Tuple{Int64, Int64}} with 2 vertices:
2-element Dictionaries.Indices{Tuple{Int64, Int64}}
(1, 1)
(2, 2)
Expand All @@ -186,7 +186,7 @@ You can also take [disjoint unions](https://en.wikipedia.org/wiki/Disjoint_union

```julia
julia> g₁ = g
NamedGraph{Tuple{Int64, Int64}} with 4 vertices:
NamedGraphs.NamedGraph{Tuple{Int64, Int64}} with 4 vertices:
4-element Dictionaries.Indices{Tuple{Int64, Int64}}
(1, 1)
(2, 1)
Expand All @@ -201,7 +201,7 @@ and 4 edge(s):


julia> g₂ = g
NamedGraph{Tuple{Int64, Int64}} with 4 vertices:
NamedGraphs.NamedGraph{Tuple{Int64, Int64}} with 4 vertices:
4-element Dictionaries.Indices{Tuple{Int64, Int64}}
(1, 1)
(2, 1)
Expand All @@ -216,7 +216,7 @@ and 4 edge(s):


julia> disjoint_union(g₁, g₂)
NamedGraph{Tuple{Tuple{Int64, Int64}, Int64}} with 8 vertices:
NamedGraphs.NamedGraph{Tuple{Tuple{Int64, Int64}, Int64}} with 8 vertices:
8-element Dictionaries.Indices{Tuple{Tuple{Int64, Int64}, Int64}}
((1, 1), 1)
((2, 1), 1)
Expand All @@ -239,7 +239,7 @@ and 8 edge(s):


julia> g₁ g₂ # Same as above
NamedGraph{Tuple{Tuple{Int64, Int64}, Int64}} with 8 vertices:
NamedGraphs.NamedGraph{Tuple{Tuple{Int64, Int64}, Int64}} with 8 vertices:
8-element Dictionaries.Indices{Tuple{Tuple{Int64, Int64}, Int64}}
((1, 1), 1)
((2, 1), 1)
Expand Down Expand Up @@ -279,7 +279,7 @@ The original graphs can be obtained from subgraphs:

```julia
julia> rename_vertices(first, subgraph(v -> v[2] == 1, g₁ g₂))
NamedGraph{Tuple{Int64, Int64}} with 4 vertices:
NamedGraphs.NamedGraph{Tuple{Int64, Int64}} with 4 vertices:
4-element Dictionaries.Indices{Tuple{Int64, Int64}}
(1, 1)
(2, 1)
Expand All @@ -294,7 +294,7 @@ and 4 edge(s):


julia> rename_vertices(first, subgraph(v -> v[2] == 2, g₁ g₂))
NamedGraph{Tuple{Int64, Int64}} with 4 vertices:
NamedGraphs.NamedGraph{Tuple{Int64, Int64}} with 4 vertices:
4-element Dictionaries.Indices{Tuple{Int64, Int64}}
(1, 1)
(2, 1)
Expand Down
3 changes: 2 additions & 1 deletion src/NamedGraphs.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module NamedGraphs
include("lib/SimilarType/src/SimilarType.jl")
include("lib/Keys/src/Keys.jl")
include("lib/GraphGenerators/src/GraphGenerators.jl")
include("lib/GraphsExtensions/src/GraphsExtensions.jl")
Expand All @@ -16,7 +17,7 @@ include("namedgraph.jl")
include("lib/NamedGraphGenerators/src/NamedGraphGenerators.jl")
include("lib/PartitionedGraphs/src/PartitionedGraphs.jl")

export NamedGraph, NamedDiGraph, NamedEdge
export AbstractNamedGraphs, NamedDiGraph, NamedEdge, NamedGraph

using PackageExtensionCompat: @require_extensions
function __init__()
Expand Down
4 changes: 2 additions & 2 deletions src/decorate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using Graphs.SimpleGraphs: SimpleGraph
using .GraphsExtensions: GraphsExtensions, add_edges!

function GraphsExtensions.decorate_graph_edges(
g::AbstractNamedGraph; edge_map::Function=Returns(SimpleGraph(1))
g::AbstractNamedGraph; edge_map::Function=Returns(NamedGraph(1))
)
g_dec = copy(g)
es = edges(g_dec)
Expand All @@ -19,7 +19,7 @@ function GraphsExtensions.decorate_graph_edges(
end

function GraphsExtensions.decorate_graph_vertices(
g::AbstractNamedGraph; vertex_map::Function=Returns(SimpleGraph(1))
g::AbstractNamedGraph; vertex_map::Function=Returns(NamedGraph(1))
)
g_dec = copy(g)
vs = vertices(g_dec)
Expand Down
15 changes: 14 additions & 1 deletion src/lib/GraphGenerators/src/GraphGenerators.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module GraphGenerators
using Dictionaries: Dictionary
using Graphs: SimpleGraph, add_edge!
using Graphs: add_edge!, dst, edges, nv, src
using Graphs.SimpleGraphs: SimpleDiGraph, SimpleGraph, binary_tree

function comb_tree(dims::Tuple)
@assert length(dims) == 2
Expand Down Expand Up @@ -28,4 +29,16 @@ function comb_tree(tooth_lengths::Vector{<:Integer})
end
return graph
end

# TODO: More efficient implementation based
# on the implementation of `binary_tree`.
function binary_arborescence(k::Integer)
graph = binary_tree(k)
digraph = SimpleDiGraph(nv(graph))
for e in edges(graph)
@assert dst(e) > src(e)
add_edge!(digraph, e)
end
return digraph
end
end
2 changes: 2 additions & 0 deletions src/lib/GraphsExtensions/.JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
style = "blue"
indent = 2
6 changes: 6 additions & 0 deletions src/lib/GraphsExtensions/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
NamedGraphs = "678767b0-92e7-4007-89e4-4527a8725b19"
SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
SplitApplyCombine = "03a91e81-4c3e-53e1-a0a4-9c0c8f19dd66"
1 change: 1 addition & 0 deletions src/lib/GraphsExtensions/src/GraphsExtensions.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module GraphsExtensions
include("abstractgraph.jl")
include("abstracttrees.jl")
include("boundary.jl")
include("shortestpaths.jl")
include("symrcm.jl")
Expand Down
Loading

2 comments on commit e064b67

@mtfishman
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/105506

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.0 -m "<description of version>" e064b675351deff691997688ee2e66ed3e11c5b7
git push origin v0.5.0

Please sign in to comment.