Skip to content

Commit

Permalink
LightGraphs -> Graphs and associated other compats
Browse files Browse the repository at this point in the history
Signed-off-by: Rachel Kurchin <[email protected]>
  • Loading branch information
rkurchin committed Feb 15, 2024
1 parent b07d104 commit 8ec2ab3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 32 deletions.
11 changes: 5 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Nodariety"
uuid = "ffab58b1-199d-4bd9-83d9-8aaad2b4ff2e"
authors = ["Rachel Kurchin <[email protected]>"]
version = "0.1.0"
version = "0.1.1"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand All @@ -13,7 +13,7 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Fontconfig = "186bb1d3-e1f7-5a2c-a377-96d770f13627"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
LongestPaths = "3a25c17e-307c-411a-a047-890a9a5fbb4d"
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
NetworkLayout = "46757867-2c16-5918-afeb-47bfcb05e46a"
Expand All @@ -30,9 +30,8 @@ DataFrames = "1"
Fontconfig = "0.4"
GLMakie = "0.4"
GraphMakie = "0.2"
LightGraphs = "1.3"
LongestPaths = "0.1"
MetaGraphs = "0.6"
NetworkLayout = "0.4"
LongestPaths = "0.2.4"
MetaGraphs = "0.7"
NetworkLayout = "0.4.6"
StatsBase = "0.33"
julia = "1.6"
2 changes: 1 addition & 1 deletion src/Nodariety.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Nodariety

using CSV, DataFrames
using LightGraphs
using Graphs

include("hyphengraph.jl")
hg = HyphenGraph()
Expand Down
8 changes: 4 additions & 4 deletions src/graph_analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function longest_path(graph::HyphenGraph = hg)
local longest_length = 0
local longest_start_inds = [1]
for i = 1:nv(graph)
p = find_longest_path(graph, i, log_level = 0)
p = find_longest_path(graph.graph, i, log_level = 0)
len = length(p.longest_path) - 1
if len > longest_length
longest_length = len
Expand All @@ -33,15 +33,15 @@ function longest_path(graph::HyphenGraph = hg)
end
end
paths = [
find_longest_path(graph, i, log_level = 0).longest_path for i in longest_start_inds
find_longest_path(graph.graph, i, log_level = 0).longest_path for i in longest_start_inds
]
return paths
end

"""
most_central(centrality_fcn, g=hg)
Return the most central node in `g` according to the provided centrality measure. `centrality_fcn` can be any of the LightGraphs centrality measures: https://juliagraphs.org/LightGraphs.jl/stable/centrality/ e.g. betweenness_centrality, closeness_centrality, degree_centrality, and many others...
Return the most central node in `g` according to the provided centrality measure. `centrality_fcn` can be any of the Graphs centrality measures: https://juliagraphs.org/Graphs.jl/stable/algorithms/centrality/ e.g. betweenness_centrality, closeness_centrality, degree_centrality, and many others...
See also: [`all_centrals`](@ref)
"""
Expand All @@ -64,7 +64,7 @@ const centrality_fcns = [
"""
all_centrals(fcns=centrality_fcns, graph=hg)
Iterate through every centrality measure provided (defaults to the LightGraphs list) and find the most central node of it in `graph`. Print results.
Iterate through every centrality measure provided (defaults to the Graphs.jl list) and find the most central node of it in `graph`. Print results.
See also: [`most_central`](@ref)
Expand Down
2 changes: 1 addition & 1 deletion src/graph_vis.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Colors
using LightGraphs
using Graphs
using DataFrames
using Serialization
using GLMakie
Expand Down
37 changes: 17 additions & 20 deletions src/hyphengraph.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using LightGraphs, MetaGraphs
using Graphs, MetaGraphs
using DataFrames
using Serialization

Expand Down Expand Up @@ -82,26 +82,20 @@ function Base.show(io::IO, g::HyphenGraph)
print(io, st)
end

# implement LightGraphs API...
const lg = LightGraphs
# Base.reverse
# implement Graphs API...
Base.zero(HyphenGraph) =
HyphenGraph(MetaDiGraph(zero(SimpleDiGraph)), DataFrame(), DataFrame())
lg.edges(g::HyphenGraph) = lg.edges(g.graph)
lg.edgetype(g::HyphenGraph) = lg.edgetype(g.graph)
lg.has_edge(g::HyphenGraph, i, j) = lg.has_edge(g.graph, i, j)
lg.has_vertex(g::HyphenGraph, v::Integer) = lg.has_vertex(g.graph, v)
lg.inneighbors(g::HyphenGraph, node) = lg.inneighbors(g.graph, node)
lg.ne(g::HyphenGraph) = lg.ne(g.graph)
lg.nv(g::HyphenGraph) = lg.nv(g.graph)
lg.outneighbors(g::HyphenGraph, node) = lg.outneighbors(g.graph, node)
lg.vertices(g::HyphenGraph) = lg.vertices(g.graph)
lg.eltype(g::HyphenGraph) = lg.eltype(g.graph)
lg.weights(g::HyphenGraph) = lg.weights(g.graph)
# I'm not sure which one of these I need, but even with all of them calling some of the centrality stuff directly on the HyphenGraph doesn't seem to work :/
lg.is_directed(g::HyphenGraph) = true
lg.is_directed(::Type{HyphenGraph}) = true
#lg.is_directed(HyphenGraph) = true
Graphs.edges(g::HyphenGraph) = Graphs.edges(g.graph)
Graphs.edgetype(g::HyphenGraph) = Graphs.edgetype(g.graph)
Graphs.has_edge(g::HyphenGraph, i, j) = Graphs.has_edge(g.graph, i, j)
Graphs.has_vertex(g::HyphenGraph, v::Integer) = Graphs.has_vertex(g.graph, v)
Graphs.inneighbors(g::HyphenGraph, node) = Graphs.inneighbors(g.graph, node)
Graphs.ne(g::HyphenGraph) = Graphs.ne(g.graph)
Graphs.nv(g::HyphenGraph) = Graphs.nv(g.graph)
Graphs.outneighbors(g::HyphenGraph, node) = Graphs.outneighbors(g.graph, node)
Graphs.vertices(g::HyphenGraph) = Graphs.vertices(g.graph)
Graphs.is_directed(g::HyphenGraph) = true
Graphs.is_directed(::Type{HyphenGraph}) = true

# helper fcn
function edge_has_nodes(edge, new_edges, index_map)
Expand All @@ -116,7 +110,10 @@ function edge_has_nodes(edge, new_edges, index_map)
end
end

function lg.induced_subgraph(
# NB that this implementation messes up the indices currently
# which is why in graph_analysis.jl, I have to call induced_subraph on graph.graph
# instead of just graph
function Graphs.induced_subgraph(
g::HyphenGraph{T},
vlist::AbstractVector{U},
) where {U<:Integer,T<:Integer}
Expand Down

0 comments on commit 8ec2ab3

Please sign in to comment.