Skip to content

LightGraphs to Graphs #163

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

Merged
merged 1 commit into from
Nov 10, 2021
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
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Expand All @@ -24,10 +24,10 @@ Compat = "2.2, 3"
DataStructures = "0.17, 0.18"
FiniteDiff = "2.8.1"
ForwardDiff = "0.10"
LightGraphs = "1.3"
Graphs = "1.4"
Requires = "0.5, 1.0"
StaticArrays = "1"
VertexSafeGraphs = "0.1"
VertexSafeGraphs = "0.2"
julia = "1.6"

[extras]
Expand Down
4 changes: 2 additions & 2 deletions src/SparseDiffTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module SparseDiffTools
using Compat
using FiniteDiff
using ForwardDiff
using LightGraphs
using LightGraphs: SimpleGraph
using Graphs
using Graphs: SimpleGraph
using Requires
using VertexSafeGraphs
using Adapt
Expand Down
28 changes: 14 additions & 14 deletions src/coloring/acyclic_coloring.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
color_graph(g::LightGraphs.AbstractGraphs, ::AcyclicColoring)
color_graph(g::Graphs.AbstractGraphs, ::AcyclicColoring)

Returns a coloring vector following the acyclic coloring rules (1) the coloring
corresponds to a distance-1 coloring, and (2) vertices in every cycle of the
Expand All @@ -9,7 +9,7 @@ is a collection of trees—and hence is acyclic.

Reference: Gebremedhin AH, Manne F, Pothen A. **New Acyclic and Star Coloring Algorithms with Application to Computing Hessians**
"""
function color_graph(g::LightGraphs.AbstractGraph, ::AcyclicColoring)
function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
color = zeros(Int, nv(g))
two_colored_forest = DisjointSets{Int}(())

Expand Down Expand Up @@ -67,7 +67,7 @@ end
v::Integer,
w::Integer,
x::Integer,
g::LightGraphs.AbstractGraph,
g::Graphs.AbstractGraph,
two_colored_forest::DisjointSets{<:Integer},
color::AbstractVector{<:Integer})

Expand All @@ -81,7 +81,7 @@ function prevent_cycle!(first_visit_to_tree::AbstractVector{<:Tuple{Integer,Inte
v::Integer,
w::Integer,
x::Integer,
g::LightGraphs.AbstractGraph,
g::Graphs.AbstractGraph,
two_colored_forest::DisjointSets{<:Integer},
color::AbstractVector{<:Integer})
e = find(w, x, g, two_colored_forest)
Expand All @@ -100,7 +100,7 @@ end
first_neighbor::AbstractVector{<: Tuple{Integer,Integer}},
v::Integer,
w::Integer,
g::LightGraphs.AbstractGraph,
g::Graphs.AbstractGraph,
color::AbstractVector{<:Integer})

Grow a 2-colored star after assigning a new color to the
Expand All @@ -112,7 +112,7 @@ function grow_star!(two_colored_forest::DisjointSets{<:Integer},
first_neighbor::AbstractVector{<: Tuple{Integer,Integer}},
v::Integer,
w::Integer,
g::LightGraphs.AbstractGraph,
g::Graphs.AbstractGraph,
color::AbstractVector{<:Integer})
insert_new_tree!(two_colored_forest,v,w,g)
p, q = first_neighbor[color[w]]
Expand All @@ -132,7 +132,7 @@ end
v::Integer,
w::Integer,
x::Integer,
g::LightGraphs.AbstractGraph)
g::Graphs.AbstractGraph)

Subroutine to merge trees present in the disjoint set which have a
common edge.
Expand All @@ -141,7 +141,7 @@ function merge_trees!(two_colored_forest::DisjointSets{<:Integer},
v::Integer,
w::Integer,
x::Integer,
g::LightGraphs.AbstractGraph)
g::Graphs.AbstractGraph)
e1 = find(v,w,g,two_colored_forest)
e2 = find(w,x,g,two_colored_forest)
if e1 != e2
Expand All @@ -154,15 +154,15 @@ end
insert_new_tree!(two_colored_forest::DisjointSets{<:Integer},
v::Integer,
w::Integer,
g::LightGraphs.AbstractGraph)
g::Graphs.AbstractGraph)

creates a new singleton set in the disjoint set 'two_colored_forest' consisting
of the edge connecting v and w in the graph g
"""
function insert_new_tree!(two_colored_forest::DisjointSets{<:Integer},
v::Integer,
w::Integer,
g::LightGraphs.AbstractGraph)
g::Graphs.AbstractGraph)
edge_index = find_edge_index(v,w,g)
push!(two_colored_forest,edge_index)
end
Expand All @@ -181,28 +181,28 @@ end
"""
find(w::Integer,
x::Integer,
g::LightGraphs.AbstractGraph,
g::Graphs.AbstractGraph,
two_colored_forest::DisjointSets{<:Integer})

Returns the root of the disjoint set to which the edge connecting vertices w and x
in the graph g belongs to
"""
function find(w::Integer,
x::Integer,
g::LightGraphs.AbstractGraph,
g::Graphs.AbstractGraph,
two_colored_forest::DisjointSets{<:Integer})
edge_index = find_edge_index(w, x, g)
return find_root!(two_colored_forest, edge_index)
end


"""
find_edge(g::LightGraphs.AbstractGraph, v::Integer, w::Integer)
find_edge(g::Graphs.AbstractGraph, v::Integer, w::Integer)

Returns an integer equivalent to the index of the edge connecting the vertices
v and w in the graph g
"""
function find_edge_index(v::Integer, w::Integer, g::LightGraphs.AbstractGraph)
function find_edge_index(v::Integer, w::Integer, g::Graphs.AbstractGraph)
pos = 1
for i in edges(g)

Expand Down
14 changes: 7 additions & 7 deletions src/coloring/backtracking_coloring.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
color_graph(g::LightGraphs.AbstractGraph, ::BacktrackingColor)
color_graph(g::Graphs.AbstractGraph, ::BacktrackingColor)

Return a tight, distance-1 coloring of graph g
using the minimum number of colors possible (i.e.
the chromatic number of graph, `χ(g)`)
"""
function color_graph(g::LightGraphs.AbstractGraph, ::BacktrackingColor)
function color_graph(g::Graphs.AbstractGraph, ::BacktrackingColor)
v = nv(g)

#A is list of vertices in non-increasing order of degree
Expand Down Expand Up @@ -96,14 +96,14 @@ function color_graph(g::LightGraphs.AbstractGraph, ::BacktrackingColor)
end

"""
sort_by_degree(g::LightGraphs.AbstractGraph)
sort_by_degree(g::Graphs.AbstractGraph)

Returns a list of the vertices of graph g sorted
in non-increasing order of their degrees
"""
function sort_by_degree(g::LightGraphs.AbstractGraph)
function sort_by_degree(g::Graphs.AbstractGraph)
vs = vertices(g)
degrees = (LightGraphs.degree(g, v) for v in vs)
degrees = (Graphs.degree(g, v) for v in vs)
vertex_pairs = collect(zip(vs, degrees))
sort!(vertex_pairs, by = p -> p[2], rev = true)
return [v[1] for v in vertex_pairs]
Expand All @@ -129,7 +129,7 @@ end
A::AbstractVector{<:Integer},
colors::AbstractVector{<:Integer},
F::Array{Integer,1},
g::LightGraphs.AbstractGraph,
g::Graphs.AbstractGraph,
opt::Integer)

Returns set of free colors of x which are less
Expand All @@ -149,7 +149,7 @@ function free_colors(x::Integer,
A::AbstractVector{<:Integer},
colors::AbstractVector{<:Integer},
F::Array{Integer,1},
g::LightGraphs.AbstractGraph,
g::Graphs.AbstractGraph,
opt::Integer)
index = -1

Expand Down
2 changes: 1 addition & 1 deletion src/coloring/greedy_star1_coloring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ colors.

Reference: Gebremedhin AH, Manne F, Pothen A. **What color is your Jacobian? Graph coloring for computing derivatives.** SIAM review. 2005;47(4):629-705.
"""
function color_graph(g::LightGraphs.AbstractGraph, ::GreedyStar1Color)
function color_graph(g::Graphs.AbstractGraph, ::GreedyStar1Color)
v = nv(g)
colorvec = zeros(Int, v)

Expand Down
2 changes: 1 addition & 1 deletion src/coloring/greedy_star2_coloring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Reference: Gebremedhin AH, Manne F, Pothen A. **What color is your Jacobian? Gra

TODO: add text explaining the difference between star1 and star2
"""
function color_graph(g::LightGraphs.AbstractGraph, ::GreedyStar2Color)
function color_graph(g::Graphs.AbstractGraph, ::GreedyStar2Color)
v = nv(g)
colorvec = zeros(Int, v)

Expand Down
4 changes: 2 additions & 2 deletions test/test_acyclic.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using SparseDiffTools
using LightGraphs
using LightGraphs: SimpleGraph
using Graphs
using Graphs: SimpleGraph
using Test

using Random
Expand Down
4 changes: 2 additions & 2 deletions test/test_bsc.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using SparseDiffTools
using LightGraphs
using LightGraphs: SimpleGraph
using Graphs
using Graphs: SimpleGraph
using Random
#=
Graph g0
Expand Down
4 changes: 2 additions & 2 deletions test/test_contraction.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using SparseDiffTools
using VertexSafeGraphs
using LightGraphs
using LightGraphs: SimpleGraph
using Graphs
using Graphs: SimpleGraph

using Random
Random.seed!(123)
Expand Down
4 changes: 2 additions & 2 deletions test/test_greedy_d1.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using SparseDiffTools
using VertexSafeGraphs
using LightGraphs
using LightGraphs: SimpleGraph
using Graphs
using Graphs: SimpleGraph
using Test

using Random
Expand Down
8 changes: 4 additions & 4 deletions test/test_greedy_star.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using SparseDiffTools
using LightGraphs
using LightGraphs: SimpleGraph
using Graphs
using Graphs: SimpleGraph
using Test

using Random
Expand Down Expand Up @@ -73,7 +73,7 @@ for i in 1:6

#test condition 2
for j = vertices(g)
walk = LightGraphs.self_avoiding_walk(g, j, 4)
walk = Graphs.self_avoiding_walk(g, j, 4)
walk_colors = zeros(Int64, 0)
if length(walk) >= 4
for t in walk
Expand All @@ -93,7 +93,7 @@ for i in 1:6

#test condition 2
for j = vertices(g)
walk = LightGraphs.self_avoiding_walk(g, j, 4)
walk = Graphs.self_avoiding_walk(g, j, 4)
walk_colors = zeros(Int64, 0)
if length(walk) >= 4
for t in walk
Expand Down
12 changes: 5 additions & 7 deletions test/test_matrix2graph.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using SparseDiffTools
using SparseArrays
using VertexSafeGraphs
using LightGraphs
using Graphs
using Random

const LG = LightGraphs

n = rand(10:100)
matrices = Array{SparseMatrixCSC, 1}(undef, 0)

Expand All @@ -19,8 +17,8 @@ for i in 1:20
matrix = matrices[i]
g = matrix2graph(matrix, false)
for e in edges(g)
src = LG.src(e)
dst = LG.dst(e)
src = Graphs.src(e)
dst = Graphs.dst(e)
col1 = abs.(matrix[:, src])
col2 = abs.(matrix[:, dst])
pr = col1' * col2
Expand All @@ -32,8 +30,8 @@ for i in 1:20
matrix = matrices[i]
g = matrix2graph(matrix, true)
for e in edges(g)
src = LG.src(e)
dst = LG.dst(e)
src = Graphs.src(e)
dst = Graphs.dst(e)
row1 = abs.(matrix[src, :])
row2 = abs.(matrix[dst, :])
pr = row1' * row2
Expand Down