Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand functionality and tests #69

Merged
merged 3 commits into from
Apr 24, 2024
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,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
Loading