Skip to content

Commit 8961bb3

Browse files
Merge pull request #1 from JuliaGraphs/transition-to-graphs.jl
Migrate from LightGraphs to Graphs.jl
2 parents 8624502 + d6f4a97 commit 8961bb3

File tree

8 files changed

+26
-26
lines changed

8 files changed

+26
-26
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
name = "SimpleWeightedGraphs"
22
uuid = "47aef6b3-ad0c-573a-a1e2-d07658019622"
3-
version = "1.1.1"
3+
version = "1.2.0"
44

55
[deps]
6-
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
6+
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
88
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
99
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1010
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1111

1212
[compat]
13-
LightGraphs = "1.3"
13+
Graphs = "1.4"
1414
julia = "1"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
**Project Status:** As of 8 October 2021 SimpleWeightedGraphs is no longer under active development. It will remain available on Github at [sbromberger/SimpleWeightedGraphs.jl](https://github.com/sbromberger/SimpleWeightedGraphs.jl). The JuliaGraphs organization will continue to maintain packages that use SimpleWeightedGraphs and transition development over the long term.
77

8-
Edge-Weighted Graphs for [LightGraphs.jl](https://github.com/JuliaGraphs/LightGraphs.jl).
8+
Edge-Weighted Graphs for [Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl).
99

1010
Usage:
1111
```julia
12-
using LightGraphs, SimpleWeightedGraphs
12+
using Graphs, SimpleWeightedGraphs
1313

1414
g = SimpleWeightedGraph(3) # or use `SimpleWeightedDiGraph` for directed graphs
1515
add_edge!(g, 1, 2, 0.5)

src/SimpleWeightedGraphs.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module SimpleWeightedGraphs
22

3-
using LightGraphs
3+
using Graphs
44
using LinearAlgebra
55
using Markdown
66
using SparseArrays
77

88
import Base:
99
convert, eltype, show, ==, Pair, Tuple, copy, length, issubset, zero
1010

11-
import LightGraphs:
11+
import Graphs:
1212
_NI, AbstractGraph, AbstractEdge, AbstractEdgeIter,
1313
src, dst, edgetype, nv, ne, vertices, edges, is_directed,
1414
add_vertex!, add_edge!, rem_vertex!, rem_edge!,

src/overrides.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ savegraph(fn::AbstractString, g::AbstractSimpleWeightedGraph, gname::AbstractStr
8080
savegraph(fn::AbstractString, d::Dict{T, U}; compress=true) where T <: AbstractString where U <: AbstractSimpleWeightedGraph =
8181
savegraph(fn, d, SWGFormat(), compress=compress)
8282

83-
# It is possible that this is suboptimal, but it is the most trivial extension of the implementation used in LightGraphs
83+
# It is possible that this is suboptimal, but it is the most trivial extension of the implementation used in Graphs.jl
8484
function cartesian_product(g::G, h::G) where G <: AbstractSimpleWeightedGraph
8585
z = G(nv(g) * nv(h))
8686
id(i, j) = (i - 1) * nv(h) + j

src/simpleweighteddigraph.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ SimpleWeightedDiGraph(::Type{T}) where T<:Integer = SimpleWeightedDiGraph{T, Flo
5858
SimpleWeightedDiGraph(::Type{T}, ::Type{U}) where {T <: Integer, U <: Real} = SimpleWeightedDiGraph{T, U}(zero(T))
5959

6060
# DiGraph(AbstractGraph, ::Type{U})
61-
function SimpleWeightedDiGraph(g::LightGraphs.AbstractGraph{T}, ::Type{U}=Float64) where {U <: Real, T}
61+
function SimpleWeightedDiGraph(g::Graphs.AbstractGraph{T}, ::Type{U}=Float64) where {U <: Real, T}
6262
return SimpleWeightedDiGraph{T}(adjacency_matrix(g, U))
6363
end
6464

@@ -67,7 +67,7 @@ end
6767
6868
Construct a weighted digraph from other graph `g` with initial weight `x`.
6969
"""
70-
function SimpleWeightedDiGraph(g::LightGraphs.AbstractGraph{T}, x::U) where {U <: Real, T}
70+
function SimpleWeightedDiGraph(g::Graphs.AbstractGraph{T}, x::U) where {U <: Real, T}
7171
m = adjacency_matrix(g, U)'
7272
return SimpleWeightedDiGraph{T, U}(x .* m, permute=false)
7373
end
@@ -78,7 +78,7 @@ function SimpleWeightedDiGraph(i::AbstractVector{T}, j::AbstractVector{T}, v::Ab
7878
SimpleWeightedDiGraph{T, U}(sparse(j, i, v, m, m, combine), permute=false)
7979
end
8080

81-
LightGraphs.SimpleDiGraph(g::SimpleWeightedDiGraph) = SimpleDiGraph(g.weights')
81+
Graphs.SimpleDiGraph(g::SimpleWeightedDiGraph) = SimpleDiGraph(g.weights')
8282

8383
edgetype(::SimpleWeightedDiGraph{T, U}) where T<:Integer where U<:Real = SimpleWeightedGraphEdge{T,U}
8484

src/simpleweightededge.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Base: Pair, Tuple, show, ==
2-
import LightGraphs: AbstractEdge, src, dst, reverse
2+
import Graphs: AbstractEdge, src, dst, reverse
33

44
abstract type AbstractSimpleWeightedEdge{T} <: AbstractEdge{T} end
55

@@ -35,4 +35,4 @@ Tuple(e::AbstractSimpleWeightedEdge) = (src(e), dst(e), weight(e))
3535
reverse(e::T) where T<:AbstractSimpleWeightedEdge = T(dst(e), src(e), weight(e))
3636
==(e1::AbstractSimpleWeightedEdge, e2::AbstractSimpleWeightedEdge) = (src(e1) == src(e2) && dst(e1) == dst(e2))
3737
==(e1::AbstractSimpleWeightedEdge, e2::AbstractEdge) = (src(e1) == src(e2) && dst(e1) == dst(e2))
38-
==(e1::AbstractEdge, e2::AbstractSimpleWeightedEdge) = (src(e1) == src(e2) && dst(e1) == dst(e2))
38+
==(e1::AbstractEdge, e2::AbstractSimpleWeightedEdge) = (src(e1) == src(e2) && dst(e1) == dst(e2))

src/simpleweightedgraph.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,31 +59,31 @@ SimpleWeightedGraph(::Type{T}, ::Type{U}) where {T<:Integer, U<:Real} = SimpleWe
5959

6060
# Graph(SimpleGraph)
6161

62-
function SimpleWeightedGraph(g::LightGraphs.AbstractGraph{T}, ::Type{U}=Float64) where {T <: Integer, U <: Real}
63-
adj_matrix = if LightGraphs.is_directed(g)
62+
function SimpleWeightedGraph(g::Graphs.AbstractGraph{T}, ::Type{U}=Float64) where {T <: Integer, U <: Real}
63+
adj_matrix = if Graphs.is_directed(g)
6464
# TODO abstract function instead of SimpleGraph constructor
65-
adjacency_matrix(LightGraphs.SimpleGraphs.SimpleGraph(g), U)
65+
adjacency_matrix(Graphs.SimpleGraphs.SimpleGraph(g), U)
6666
else
6767
adjacency_matrix(g, U)
6868
end
6969
return SimpleWeightedGraph{T, U}(adj_matrix)
7070
end
7171

72-
function SimpleWeightedGraph(g::LightGraphs.AbstractGraph{T}, x::U) where {T <: Integer, U <: Real}
73-
adj_matrix = if LightGraphs.is_directed(g)
72+
function SimpleWeightedGraph(g::Graphs.AbstractGraph{T}, x::U) where {T <: Integer, U <: Real}
73+
adj_matrix = if Graphs.is_directed(g)
7474
# TODO abstract function instead of SimpleGraph constructor
75-
adjacency_matrix(LightGraphs.SimpleGraphs.SimpleGraph(g), U)
75+
adjacency_matrix(Graphs.SimpleGraphs.SimpleGraph(g), U)
7676
else
7777
adjacency_matrix(g, U)
7878
end
7979
return SimpleWeightedGraph{T, U}(x .* adj_matrix)
8080
end
8181

8282
# SimpleWeightedGraph{T, U}(SimpleGraph)
83-
function (::Type{SimpleWeightedGraph{T, U}})(g::LightGraphs.AbstractGraph) where {T<:Integer, U <: Real}
84-
adj_matrix = if LightGraphs.is_directed(g)
83+
function (::Type{SimpleWeightedGraph{T, U}})(g::Graphs.AbstractGraph) where {T<:Integer, U <: Real}
84+
adj_matrix = if Graphs.is_directed(g)
8585
# TODO abstract function instead of SimpleGraph constructor
86-
adjacency_matrix(LightGraphs.SimpleGraphs.SimpleGraph{T}(g), U)
86+
adjacency_matrix(Graphs.SimpleGraphs.SimpleGraph{T}(g), U)
8787
else
8888
adjacency_matrix(g, U)
8989
end
@@ -97,7 +97,7 @@ function SimpleWeightedGraph(i::AbstractVector{T}, j::AbstractVector{T}, v::Abst
9797
SimpleWeightedGraph{T, U}(s)
9898
end
9999

100-
LightGraphs.SimpleGraph(g::SimpleWeightedGraph) = SimpleGraph(g.weights)
100+
Graphs.SimpleGraph(g::SimpleWeightedGraph) = SimpleGraph(g.weights)
101101

102102
edgetype(::SimpleWeightedGraph{T, U}) where {T<:Integer, U<:Real} = SimpleWeightedGraphEdge{T,U}
103103

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using LightGraphs
1+
using Graphs
22
using SimpleWeightedGraphs
33
using LinearAlgebra
44
using Test
@@ -8,8 +8,8 @@ testdir = dirname(@__FILE__)
88
testgraphs(g) = [g, SimpleWeightedGraph{UInt8,Float64}(g), SimpleWeightedGraph{Int16,Float32}(g)]
99
testdigraphs(g) = [g, SimpleWeightedDiGraph{UInt8,Float64}(g), SimpleWeightedDiGraph{Int16,Float32}(g)]
1010

11-
testsimplegraphs(g) = [g, LightGraphs.SimpleGraph{UInt8}(g), LightGraphs.SimpleGraph{Int16}(g)]
12-
testsimpledigraphs(g) = [g, LightGraphs.SimpleDiGraph{UInt8}(g), LightGraphs.SimpleDiGraph{Int16}(g)]
11+
testsimplegraphs(g) = [g, Graphs.SimpleGraph{UInt8}(g), Graphs.SimpleGraph{Int16}(g)]
12+
testsimpledigraphs(g) = [g, Graphs.SimpleDiGraph{UInt8}(g), Graphs.SimpleDiGraph{Int16}(g)]
1313

1414
tests = [
1515
"simpleweightededge",

0 commit comments

Comments
 (0)