2
2
# as they require cloning and modifying graphs.
3
3
4
4
"""
5
- complement(g)
5
+ complement(g)
6
6
7
7
Return the [graph complement](https://en.wikipedia.org/wiki/Complement_graph)
8
8
of a graph
@@ -58,7 +58,7 @@ function complement(g::DiGraph)
58
58
end
59
59
60
60
"""
61
- reverse(g)
61
+ reverse(g)
62
62
63
63
Return a directed graph where all edges are reversed from the
64
64
original directed graph.
@@ -93,7 +93,7 @@ function reverse end
93
93
end
94
94
95
95
"""
96
- reverse!(g)
96
+ reverse!(g)
97
97
98
98
In-place reverse of a directed graph (modifies the original graph).
99
99
See [`reverse`](@ref) for a non-modifying version.
@@ -105,7 +105,7 @@ function reverse! end
105
105
end
106
106
107
107
"""
108
- blockdiag(g, h)
108
+ blockdiag(g, h)
109
109
110
110
Return a graph with ``|V(g)| + |V(h)|`` vertices and ``|E(g)| + |E(h)|``
111
111
edges where the vertices and edges from graph `h` are appended to graph `g`.
@@ -150,7 +150,7 @@ function blockdiag(g::T, h::T) where {T<:AbstractGraph}
150
150
end
151
151
152
152
"""
153
- intersect(g, h)
153
+ intersect(g, h)
154
154
155
155
Return a graph with edges that are only in both graph `g` and graph `h`.
156
156
@@ -184,7 +184,7 @@ function intersect(g::T, h::T) where {T<:AbstractGraph}
184
184
end
185
185
186
186
"""
187
- difference(g, h)
187
+ difference(g, h)
188
188
189
189
Return a graph with edges in graph `g` that are not in graph `h`.
190
190
@@ -218,7 +218,7 @@ function difference(g::T, h::T) where {T<:AbstractGraph}
218
218
end
219
219
220
220
"""
221
- symmetric_difference(g, h)
221
+ symmetric_difference(g, h)
222
222
223
223
Return a graph with edges from graph `g` that do not exist in graph `h`,
224
224
and vice versa.
@@ -264,7 +264,7 @@ function symmetric_difference(g::T, h::T) where {T<:AbstractGraph}
264
264
end
265
265
266
266
"""
267
- union(g, h)
267
+ union(g, h)
268
268
269
269
Return a graph that combines graphs `g` and `h` by taking the set union
270
270
of all vertices and edges.
@@ -319,7 +319,7 @@ function union(g::T, h::T) where {T<:AbstractSimpleGraph}
319
319
end
320
320
321
321
"""
322
- join(g, h)
322
+ join(g, h)
323
323
324
324
Return a graph that combines graphs `g` and `h` using `blockdiag` and then
325
325
adds all the edges between the vertices in `g` and those in `h`.
@@ -359,7 +359,7 @@ function join(g::T, h::T) where {T<:AbstractGraph}
359
359
end
360
360
361
361
"""
362
- crosspath(len::Integer, g::Graph)
362
+ crosspath(len::Integer, g::Graph)
363
363
364
364
Return a graph that duplicates `g` `len` times and connects each vertex
365
365
with its copies in a path.
@@ -420,7 +420,7 @@ function *(g::AbstractGraph, v::Vector{T}) where {T<:Real}
420
420
end
421
421
422
422
"""
423
- sum(g, i)
423
+ sum(g, i)
424
424
425
425
Return a vector of indegree (`i`=1) or outdegree (`i`=2) values for graph `g`.
426
426
455
455
456
456
size (g:: AbstractGraph ) = (nv (g), nv (g))
457
457
"""
458
- size(g, i)
458
+ size(g, i)
459
459
460
460
Return the number of vertices in `g` if `i`=1 or `i`=2, or `1` otherwise.
461
461
@@ -478,7 +478,7 @@ julia> size(g, 3)
478
478
size (g:: AbstractGraph , dim:: Int ) = (dim == 1 || dim == 2 ) ? nv (g) : 1
479
479
480
480
"""
481
- sum(g)
481
+ sum(g)
482
482
483
483
Return the number of edges in `g`.
484
484
@@ -495,7 +495,7 @@ julia> sum(g)
495
495
sum (g:: AbstractGraph ) = ne (g)
496
496
497
497
"""
498
- sparse(g)
498
+ sparse(g)
499
499
500
500
Return the default adjacency matrix of `g`.
501
501
"""
518
518
end
519
519
520
520
"""
521
- cartesian_product(g, h)
521
+ cartesian_product(g, h)
522
522
523
523
Return the [cartesian product](https://en.wikipedia.org/wiki/Cartesian_product_of_graphs)
524
524
of `g` and `h`.
@@ -570,7 +570,7 @@ function cartesian_product(g::G, h::G) where {G<:AbstractGraph}
570
570
end
571
571
572
572
"""
573
- tensor_product(g, h)
573
+ tensor_product(g, h)
574
574
575
575
Return the [tensor product](https://en.wikipedia.org/wiki/Tensor_product_of_graphs)
576
576
of `g` and `h`.
618
618
# # subgraphs ###
619
619
620
620
"""
621
- induced_subgraph(g, vlist)
622
- induced_subgraph(g, elist)
621
+ induced_subgraph(g, vlist)
622
+ induced_subgraph(g, elist)
623
623
624
624
Return the subgraph of `g` induced by the vertices in `vlist` or edges in `elist`
625
625
along with a vector mapping the new vertices to the old ones
@@ -706,15 +706,15 @@ function induced_subgraph(
706
706
end
707
707
708
708
"""
709
- g[iter]
709
+ g[iter]
710
710
711
711
Return the subgraph induced by `iter`.
712
712
Equivalent to [`induced_subgraph`](@ref)`(g, iter)[1]`.
713
713
"""
714
714
getindex (g:: AbstractGraph , iter) = induced_subgraph (g, iter)[1 ]
715
715
716
716
"""
717
- egonet(g, v, d, distmx=weights(g))
717
+ egonet(g, v, d, distmx=weights(g))
718
718
719
719
Return the subgraph of `g` induced by the neighbors of `v` up to distance
720
720
`d`, using weights (optionally) provided by `distmx`.
@@ -735,7 +735,7 @@ function egonet(
735
735
end
736
736
737
737
"""
738
- compute_shifts(n::Int, x::AbstractArray)
738
+ compute_shifts(n::Int, x::AbstractArray)
739
739
740
740
Determine how many elements of `x` are less than `i` for all `i` in `1:n`.
741
741
"""
@@ -746,7 +746,7 @@ function compute_shifts(n::Integer, x::AbstractArray)
746
746
end
747
747
748
748
"""
749
- merge_vertices(g::AbstractGraph, vs)
749
+ merge_vertices(g::AbstractGraph, vs)
750
750
751
751
Create a new graph where all vertices in `vs` have been aliased to the same vertex `minimum(vs)`.
752
752
@@ -772,7 +772,7 @@ julia> collect(edges(h))
772
772
Edge 3 => 4
773
773
```
774
774
"""
775
- function merge_vertices (g:: AbstractSimpleGraph , vs)
775
+ function merge_vertices (g:: G , vs) where {G <: AbstractSimpleGraph }
776
776
# Use lowest value as new vertex id.
777
777
vs = unique! (sort (vs))
778
778
merged_vertex = popfirst! (vs)
@@ -788,7 +788,7 @@ function merge_vertices(g::AbstractSimpleGraph, vs)
788
788
new_vertex_ids[vs] .= merged_vertex
789
789
790
790
# if v in vs then labels[v] == v0 else labels[v] == v
791
- newg = SimpleGraph (nvnew)
791
+ newg = G (nvnew)
792
792
for e in edges (g)
793
793
u, w = src (e), dst (e)
794
794
if new_vertex_ids[u] != new_vertex_ids[w] # not a new self loop
@@ -799,7 +799,7 @@ function merge_vertices(g::AbstractSimpleGraph, vs)
799
799
end
800
800
801
801
"""
802
- merge_vertices!(g, vs)
802
+ merge_vertices!(g, vs)
803
803
804
804
Combine vertices specified in `vs` into single vertex whose
805
805
index will be the lowest value in `vs`. All edges connected to vertices in `vs`
0 commit comments