@@ -8,15 +8,15 @@ export 𝑠vertices, 𝑑vertices, has_𝑠vertex, has_𝑑vertex, 𝑠neighbors
8
8
using DocStringExtensions
9
9
using UnPack
10
10
using SparseArrays
11
- using LightGraphs
11
+ using Graphs
12
12
using Setfield
13
13
14
14
# ##
15
15
# ## Edges & Vertex
16
16
# ##
17
17
@enum VertType SRC DST ALL
18
18
19
- struct BipartiteEdge{I<: Integer } <: LightGraphs .AbstractEdge{I}
19
+ struct BipartiteEdge{I<: Integer } <: Graphs .AbstractEdge{I}
20
20
src:: I
21
21
dst:: I
22
22
function BipartiteEdge (src:: I , dst:: V ) where {I,V}
@@ -25,8 +25,8 @@ struct BipartiteEdge{I<:Integer} <: LightGraphs.AbstractEdge{I}
25
25
end
26
26
end
27
27
28
- LightGraphs . src (edge:: BipartiteEdge ) = edge. src
29
- LightGraphs . dst (edge:: BipartiteEdge ) = edge. dst
28
+ Graphs . src (edge:: BipartiteEdge ) = edge. src
29
+ Graphs . dst (edge:: BipartiteEdge ) = edge. dst
30
30
31
31
function Base. show (io:: IO , edge:: BipartiteEdge )
32
32
@unpack src, dst = edge
@@ -65,7 +65,7 @@ badjlist = [[1,2,5,6],[3,4,6]]
65
65
bg = BipartiteGraph(7, fadjlist, badjlist)
66
66
```
67
67
"""
68
- mutable struct BipartiteGraph{I<: Integer ,F<: Vector{Vector{I}} ,B<: Union{Vector{Vector{I}},I} ,M} <: LightGraphs .AbstractGraph{I}
68
+ mutable struct BipartiteGraph{I<: Integer ,F<: Vector{Vector{I}} ,B<: Union{Vector{Vector{I}},I} ,M} <: Graphs .AbstractGraph{I}
69
69
ne:: Int
70
70
fadjlist:: F # `fadjlist[src] => dsts`
71
71
badjlist:: B # `badjlist[dst] => srcs` or `ndsts`
@@ -112,11 +112,11 @@ Base.length(::BipartiteGraph) = error("length is not well defined! Use `ne` or `
112
112
113
113
@noinline throw_no_back_edges () = throw (ArgumentError (" The graph has no back edges." ))
114
114
115
- if isdefined (LightGraphs , :has_contiguous_vertices )
116
- LightGraphs . has_contiguous_vertices (:: Type{<:BipartiteGraph} ) = false
115
+ if isdefined (Graphs , :has_contiguous_vertices )
116
+ Graphs . has_contiguous_vertices (:: Type{<:BipartiteGraph} ) = false
117
117
end
118
- LightGraphs . is_directed (:: Type{<:BipartiteGraph} ) = false
119
- LightGraphs . vertices (g:: BipartiteGraph ) = (𝑠vertices (g), 𝑑vertices (g))
118
+ Graphs . is_directed (:: Type{<:BipartiteGraph} ) = false
119
+ Graphs . vertices (g:: BipartiteGraph ) = (𝑠vertices (g), 𝑑vertices (g))
120
120
𝑠vertices (g:: BipartiteGraph ) = axes (g. fadjlist, 1 )
121
121
𝑑vertices (g:: BipartiteGraph ) = g. badjlist isa AbstractVector ? axes (g. badjlist, 1 ) : Base. OneTo (g. badjlist)
122
122
has_𝑠vertex (g:: BipartiteGraph , v:: Integer ) = v in 𝑠vertices (g)
@@ -126,14 +126,14 @@ function 𝑑neighbors(g::BipartiteGraph, j::Integer, with_metadata::Val{M}=Val(
126
126
g. badjlist isa AbstractVector || throw_no_back_edges ()
127
127
M ? zip (g. badjlist[j], (g. metadata[i][j] for i in g. badjlist[j])) : g. badjlist[j]
128
128
end
129
- LightGraphs . ne (g:: BipartiteGraph ) = g. ne
130
- LightGraphs . nv (g:: BipartiteGraph ) = sum (length, vertices (g))
131
- LightGraphs . edgetype (g:: BipartiteGraph{I} ) where I = BipartiteEdge{I}
129
+ Graphs . ne (g:: BipartiteGraph ) = g. ne
130
+ Graphs . nv (g:: BipartiteGraph ) = sum (length, vertices (g))
131
+ Graphs . edgetype (g:: BipartiteGraph{I} ) where I = BipartiteEdge{I}
132
132
133
133
nsrcs (g:: BipartiteGraph ) = length (𝑠vertices (g))
134
134
ndsts (g:: BipartiteGraph ) = length (𝑑vertices (g))
135
135
136
- function LightGraphs . has_edge (g:: BipartiteGraph , edge:: BipartiteEdge )
136
+ function Graphs . has_edge (g:: BipartiteGraph , edge:: BipartiteEdge )
137
137
@unpack src, dst = edge
138
138
(src in 𝑠vertices (g) && dst in 𝑑vertices (g)) || return false # edge out of bounds
139
139
insorted (𝑠neighbors (src), dst)
@@ -146,8 +146,8 @@ struct NoMetadata
146
146
end
147
147
const NO_METADATA = NoMetadata ()
148
148
149
- LightGraphs . add_edge! (g:: BipartiteGraph , i:: Integer , j:: Integer , md= NO_METADATA) = add_edge! (g, BipartiteEdge (i, j), md)
150
- function LightGraphs . add_edge! (g:: BipartiteGraph , edge:: BipartiteEdge , md= NO_METADATA)
149
+ Graphs . add_edge! (g:: BipartiteGraph , i:: Integer , j:: Integer , md= NO_METADATA) = add_edge! (g, BipartiteEdge (i, j), md)
150
+ function Graphs . add_edge! (g:: BipartiteGraph , edge:: BipartiteEdge , md= NO_METADATA)
151
151
@unpack fadjlist, badjlist = g
152
152
s, d = src (edge), dst (edge)
153
153
(has_𝑠vertex (g, s) && has_𝑑vertex (g, d)) || error (" edge ($edge ) out of range." )
@@ -168,7 +168,7 @@ function LightGraphs.add_edge!(g::BipartiteGraph, edge::BipartiteEdge, md=NO_MET
168
168
return true # edge successfully added
169
169
end
170
170
171
- function LightGraphs . add_vertex! (g:: BipartiteGraph{T} , type:: VertType ) where T
171
+ function Graphs . add_vertex! (g:: BipartiteGraph{T} , type:: VertType ) where T
172
172
if type === DST
173
173
if g. badjlist isa AbstractVector
174
174
push! (g. badjlist, T[])
@@ -186,11 +186,11 @@ end
186
186
# ##
187
187
# ## Edges iteration
188
188
# ##
189
- LightGraphs . edges (g:: BipartiteGraph ) = BipartiteEdgeIter (g, Val (ALL))
189
+ Graphs . edges (g:: BipartiteGraph ) = BipartiteEdgeIter (g, Val (ALL))
190
190
𝑠edges (g:: BipartiteGraph ) = BipartiteEdgeIter (g, Val (SRC))
191
191
𝑑edges (g:: BipartiteGraph ) = BipartiteEdgeIter (g, Val (DST))
192
192
193
- struct BipartiteEdgeIter{T,G} <: LightGraphs .AbstractEdgeIter
193
+ struct BipartiteEdgeIter{T,G} <: Graphs .AbstractEdgeIter
194
194
g:: G
195
195
type:: Val{T}
196
196
end
259
259
# ##
260
260
# ## Utils
261
261
# ##
262
- function LightGraphs . incidence_matrix (g:: BipartiteGraph , val= true )
262
+ function Graphs . incidence_matrix (g:: BipartiteGraph , val= true )
263
263
I = Int[]
264
264
J = Int[]
265
265
for i in 𝑠vertices (g), n in 𝑠neighbors (g, i)
0 commit comments