Skip to content

Commit e064b67

Browse files
authored
Expand functionality and tests (#69)
1 parent 10b9ce6 commit e064b67

19 files changed

+898
-170
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "NamedGraphs"
22
uuid = "678767b0-92e7-4007-89e4-4527a8725b19"
33
authors = ["Matthew Fishman <[email protected]> and contributors"]
4-
version = "0.4.2"
4+
version = "0.5.0"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ julia> using NamedGraphs: NamedGraph
4848
julia> using NamedGraphs.GraphsExtensions: , disjoint_union, subgraph, rename_vertices
4949

5050
julia> g = NamedGraph(grid((4,)), ["A", "B", "C", "D"])
51-
NamedGraph{String} with 4 vertices:
51+
NamedGraphs.NamedGraph{String} with 4 vertices:
5252
4-element Dictionaries.Indices{String}
5353
"A"
5454
"B"
@@ -81,7 +81,7 @@ julia> neighbors(g, "B")
8181
"C"
8282

8383
julia> subgraph(g, ["A", "B"])
84-
NamedGraph{String} with 2 vertices:
84+
NamedGraphs.NamedGraph{String} with 2 vertices:
8585
2-element Dictionaries.Indices{String}
8686
"A"
8787
"B"
@@ -108,7 +108,7 @@ julia> dims = (2, 2)
108108
(2, 2)
109109

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

153153
```julia
154154
julia> subgraph(v -> v[1] == 1, g)
155-
NamedGraph{Tuple{Int64, Int64}} with 2 vertices:
155+
NamedGraphs.NamedGraph{Tuple{Int64, Int64}} with 2 vertices:
156156
2-element Dictionaries.Indices{Tuple{Int64, Int64}}
157157
(1, 1)
158158
(1, 2)
@@ -162,7 +162,7 @@ and 1 edge(s):
162162

163163

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

173173

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

187187
```julia
188188
julia> g₁ = g
189-
NamedGraph{Tuple{Int64, Int64}} with 4 vertices:
189+
NamedGraphs.NamedGraph{Tuple{Int64, Int64}} with 4 vertices:
190190
4-element Dictionaries.Indices{Tuple{Int64, Int64}}
191191
(1, 1)
192192
(2, 1)
@@ -201,7 +201,7 @@ and 4 edge(s):
201201

202202

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

217217

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

240240

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

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

295295

296296
julia> rename_vertices(first, subgraph(v -> v[2] == 2, g₁ g₂))
297-
NamedGraph{Tuple{Int64, Int64}} with 4 vertices:
297+
NamedGraphs.NamedGraph{Tuple{Int64, Int64}} with 4 vertices:
298298
4-element Dictionaries.Indices{Tuple{Int64, Int64}}
299299
(1, 1)
300300
(2, 1)

src/NamedGraphs.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module NamedGraphs
2+
include("lib/SimilarType/src/SimilarType.jl")
23
include("lib/Keys/src/Keys.jl")
34
include("lib/GraphGenerators/src/GraphGenerators.jl")
45
include("lib/GraphsExtensions/src/GraphsExtensions.jl")
@@ -16,7 +17,7 @@ include("namedgraph.jl")
1617
include("lib/NamedGraphGenerators/src/NamedGraphGenerators.jl")
1718
include("lib/PartitionedGraphs/src/PartitionedGraphs.jl")
1819

19-
export NamedGraph, NamedDiGraph, NamedEdge
20+
export AbstractNamedGraphs, NamedDiGraph, NamedEdge, NamedGraph
2021

2122
using PackageExtensionCompat: @require_extensions
2223
function __init__()

src/decorate.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using Graphs.SimpleGraphs: SimpleGraph
33
using .GraphsExtensions: GraphsExtensions, add_edges!
44

55
function GraphsExtensions.decorate_graph_edges(
6-
g::AbstractNamedGraph; edge_map::Function=Returns(SimpleGraph(1))
6+
g::AbstractNamedGraph; edge_map::Function=Returns(NamedGraph(1))
77
)
88
g_dec = copy(g)
99
es = edges(g_dec)
@@ -19,7 +19,7 @@ function GraphsExtensions.decorate_graph_edges(
1919
end
2020

2121
function GraphsExtensions.decorate_graph_vertices(
22-
g::AbstractNamedGraph; vertex_map::Function=Returns(SimpleGraph(1))
22+
g::AbstractNamedGraph; vertex_map::Function=Returns(NamedGraph(1))
2323
)
2424
g_dec = copy(g)
2525
vs = vertices(g_dec)

src/lib/GraphGenerators/src/GraphGenerators.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module GraphGenerators
22
using Dictionaries: Dictionary
3-
using Graphs: SimpleGraph, add_edge!
3+
using Graphs: add_edge!, dst, edges, nv, src
4+
using Graphs.SimpleGraphs: SimpleDiGraph, SimpleGraph, binary_tree
45

56
function comb_tree(dims::Tuple)
67
@assert length(dims) == 2
@@ -28,4 +29,16 @@ function comb_tree(tooth_lengths::Vector{<:Integer})
2829
end
2930
return graph
3031
end
32+
33+
# TODO: More efficient implementation based
34+
# on the implementation of `binary_tree`.
35+
function binary_arborescence(k::Integer)
36+
graph = binary_tree(k)
37+
digraph = SimpleDiGraph(nv(graph))
38+
for e in edges(graph)
39+
@assert dst(e) > src(e)
40+
add_edge!(digraph, e)
41+
end
42+
return digraph
43+
end
3144
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
style = "blue"
2+
indent = 2
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[deps]
2+
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
3+
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
4+
NamedGraphs = "678767b0-92e7-4007-89e4-4527a8725b19"
5+
SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
6+
SplitApplyCombine = "03a91e81-4c3e-53e1-a0a4-9c0c8f19dd66"

src/lib/GraphsExtensions/src/GraphsExtensions.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module GraphsExtensions
22
include("abstractgraph.jl")
3+
include("abstracttrees.jl")
34
include("boundary.jl")
45
include("shortestpaths.jl")
56
include("symrcm.jl")

0 commit comments

Comments
 (0)