Skip to content

Commit

Permalink
Merge pull request #40 from storopoli/move-Graphs
Browse files Browse the repository at this point in the history
Move From LightGraphs.jl to Graphs.jl
  • Loading branch information
matbesancon authored Oct 23, 2021
2 parents eb35fe3 + 1cc29c8 commit fbde6c3
Show file tree
Hide file tree
Showing 20 changed files with 184 additions and 114 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CompatHelper

on:
schedule:
- cron: 0 * * * *

jobs:
CompatHelper:
runs-on: ubuntu-latest
steps:
- name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: julia -e 'using CompatHelper; CompatHelper.main()'
12 changes: 12 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: TagBot
on:
schedule:
- cron: 30 * * * *
workflow_dispatch:
jobs:
TagBot:
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI
on:
pull_request:
branches:
- master
push:
branches:
- master
tags: '*'
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1'
os:
- ubuntu-latest
arch:
- x64
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
file: lcov.info
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.DS_Store
*.jl.cov
*.jl.*.cov
*.jl.mem
.vscode
docs/build/
docs/site/
benchmark/.results/*
benchmark/.tune.jld
*.cov
Manifest.toml
14 changes: 7 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
name = "GraphIO"
uuid = "aa1b3936-2fda-51b9-ab35-c553d3a640a2"
version = "0.5.0"
version = "0.6.0"

[deps]
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"

[compat]
EzXML = "1"
LightGraphs = "1"
ParserCombinator = "2"
julia = "1"
Graphs = "1.4"
ParserCombinator = "2.1"
Requires = "1"
SimpleTraits = "0.9"
julia = "1"

[extras]
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
ParserCombinator = "fae87a5f-d1ad-5cf0-8f61-c941e1580b46"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["CodecZlib", "LightGraphs", "EzXML", "ParserCombinator", "Test"]
test = ["CodecZlib", "Graphs", "EzXML", "ParserCombinator", "Test"]
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# GraphIO

[![Build Status](https://travis-ci.org/JuliaGraphs/GraphIO.jl.svg?branch=master)](https://travis-ci.org/JuliaGraphs/GraphIO.jl)
[![Build Status](https://github.com/JuliaGraphs/GraphIO.jl/workflows/CI/badge.svg)](https://github.com/JuliaGraphs/GraphIO.jl/actions?query=workflow%3ACI+branch%3Amaster)
[![codecov.io](http://codecov.io/github/JuliaGraphs/GraphIO.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaGraphs/GraphIO.jl?branch=master)

GraphIO provides support to [LightGraphs.jl](https://github.com/JuliaGraphs/LightGraphs.jl) for reading/writing graphs in various formats.

The current version of GraphIO works with Julia version >= 0.7.
GraphIO provides support to [Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl) for reading/writing graphs in various formats.

Currently, the following functionality is provided:

Expand All @@ -29,11 +27,11 @@ Format | Read | Write | Multiple Graphs| Format Name |
[DOT]: https://en.wikipedia.org/wiki/DOT_(graph_description_language)

Graphs are read using either the `loadgraph` function or, for formats that support multiple graphs in a single file,
the `loadgraphs` functions. `loadgraph` returns a LightGraph object, while `loadgraphs` returns a dictionary of LightGraph objects.
the `loadgraphs` functions. `loadgraph` returns a Graph object, while `loadgraphs` returns a dictionary of Graph objects.

For example, an edgelist file could be loaded as:

```
```julia
graph = loadgraph("path_to_graph/my_edgelist.txt", "graph_key", EdgeListFormat())
```

Expand Down
8 changes: 4 additions & 4 deletions src/CDF/Cdf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module CDF
# http://www2.ee.washington.edu/research/pstca/formats/cdf.txt
# http://www2.ee.washington.edu/research/pstca/pf30/ieee30cdf.txt

using LightGraphs
using LightGraphs: AbstractGraphFormat
using Graphs
using Graphs: AbstractGraphFormat

import LightGraphs: loadgraph, loadgraphs, savegraph
import Graphs: loadgraph, loadgraphs, savegraph

export CDFFormat

Expand Down Expand Up @@ -45,7 +45,7 @@ function _loadcdf(io::IO)
end
end
n_v = length(vertices)
g = LightGraphs.Graph(n_v)
g = Graphs.Graph(n_v)
for p in zip(srcs, dsts)
add_edge!(g, p)
end
Expand Down
41 changes: 19 additions & 22 deletions src/DOT/Dot.jl
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
module DOT

using GraphIO.ParserCombinator.Parsers
using LightGraphs
using LightGraphs: AbstractGraphFormat
using Graphs
using Graphs: AbstractGraphFormat

import LightGraphs: loadgraph, loadgraphs, savegraph
import Graphs: loadgraph, loadgraphs, savegraph

export DOTFormat

struct DOTFormat <: AbstractGraphFormat end

function savedot(io::IO, g::LightGraphs.AbstractGraph, gname::String = "")
isdir = LightGraphs.is_directed(g)
function savedot(io::IO, g::Graphs.AbstractGraph, gname::String = "")
isdir = Graphs.is_directed(g)
println(io,(isdir ? "digraph " : "graph ") * gname * " {")
for i in LightGraphs.vertices(g)
for i in Graphs.vertices(g)
println(io,"\t" * string(i))
end
if isdir
for u in LightGraphs.vertices(g)
out_nbrs = LightGraphs.outneighbors(g, u)
for u in Graphs.vertices(g)
out_nbrs = Graphs.outneighbors(g, u)
length(out_nbrs) == 0 && continue
println(io, "\t" * string(u) * " -> {" * join(out_nbrs,',') * "}")
end
else
for e in LightGraphs.edges(g)
source = string(LightGraphs.src(e))
dest = string(LightGraphs.dst(e))
for e in Graphs.edges(g)
source = string(Graphs.src(e))
dest = string(Graphs.dst(e))
println(io, "\t" * source * " -- " * dest)
end
end
Expand All @@ -46,9 +46,9 @@ function _dot_read_one_graph(pg::Parsers.DOT.Graph)
nvg = length(Parsers.DOT.nodes(pg))
nodedict = Dict(zip(collect(Parsers.DOT.nodes(pg)), 1:nvg))
if isdir
g = LightGraphs.DiGraph(nvg)
g = Graphs.DiGraph(nvg)
else
g = LightGraphs.Graph(nvg)
g = Graphs.Graph(nvg)
end
for es in Parsers.DOT.edges(pg)
s = nodedict[es[1]]
Expand All @@ -58,27 +58,24 @@ function _dot_read_one_graph(pg::Parsers.DOT.Graph)
return g
end

_name(pg::Parsers.DOT.Graph) =
pg.id !== nothing ? pg.id.id :
Parsers.DOT.StringID(pg.directed ? "digraph" : "graph")

function loaddot(io::IO, gname::String)
p = Parsers.DOT.parse_dot(read(io, String))
for pg in p
isdir = pg.directed
possname = isdir ? Parsers.DOT.StringID("digraph") : Parsers.DOT.StringID("graph")
name = get(pg.id, possname).id
name == gname && return _dot_read_one_graph(pg)
_name(pg) == gname && return _dot_read_one_graph(pg)
end
error("Graph $gname not found")
end

function loaddot_mult(io::IO)
p = Parsers.DOT.parse_dot(read(io, String))

graphs = Dict{String,AbstractGraph}()

for pg in p
isdir = pg.directed
possname = isdir ? Parsers.DOT.StringID("digraph") : Parsers.DOT.StringID("graph")
name = get(pg.id, possname).id
graphs[name] = _dot_read_one_graph(pg)
graphs[_name(pg)] = _dot_read_one_graph(pg)
end
return graphs
end
Expand Down
12 changes: 6 additions & 6 deletions src/Edgelist/Edgelist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ module EdgeList
# each line. Will return a directed graph.

using DelimitedFiles: writedlm
using LightGraphs
using LightGraphs: AbstractGraphFormat
using Graphs
using Graphs: AbstractGraphFormat

import LightGraphs: loadgraph, loadgraphs, savegraph
import Graphs: loadgraph, loadgraphs, savegraph

export EdgeListFormat

Expand Down Expand Up @@ -36,15 +36,15 @@ function loadedgelist(io::IO, gname::String)
end

n_v = length(vxset)
g = LightGraphs.DiGraph(n_v)
g = Graphs.DiGraph(n_v)
for (u, v) in zip(srcs, dsts)
add_edge!(g, vxdict[u], vxdict[v])
end
return g
end

function saveedgelist(io::IO, g::LightGraphs.AbstractGraph, gname::String)
writedlm(io, ([src(e), dst(e)] for e in LightGraphs.edges(g)), ',')
function saveedgelist(io::IO, g::Graphs.AbstractGraph, gname::String)
writedlm(io, ([src(e), dst(e)] for e in Graphs.edges(g)), ',')
return 1
end

Expand Down
2 changes: 1 addition & 1 deletion src/Edgelist/IntEdgeList.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function loadintedgelist(io::IO, gname::String, offset::Int64)
push!(badjlist[v], u)
end
end
return LightGraphs.DiGraph(neg, fadjlist, badjlist)
return Graphs.DiGraph(neg, fadjlist, badjlist)
end

loadgraph(io::IO, gname::String, fmt::IntEdgeListFormat) = loadintedgelist(io, gname, fmt.offset)
Expand Down
10 changes: 5 additions & 5 deletions src/GEXF/Gexf.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module GEXF

using GraphIO.EzXML
using LightGraphs
using LightGraphs: AbstractGraph, AbstractGraphFormat
using Graphs
using Graphs: AbstractGraph, AbstractGraphFormat

import LightGraphs: savegraph
import Graphs: savegraph

export GEXFFormat

Expand All @@ -16,7 +16,7 @@ struct GEXFFormat <: AbstractGraphFormat end
Write a graph `g` with name `gname` to an IO stream `io` in the
[Gexf](http://gexf.net/format/) format. Return 1 (number of graphs written).
"""
function savegexf(io::IO, g::LightGraphs.AbstractGraph, gname::String)
function savegexf(io::IO, g::Graphs.AbstractGraph, gname::String)
xdoc = XMLDocument()
xroot = setroot!(xdoc, ElementNode("gexf"))
xroot["xmlns"] = "http://www.gexf.net/1.2draft"
Expand All @@ -38,7 +38,7 @@ function savegexf(io::IO, g::LightGraphs.AbstractGraph, gname::String)

xedges = addelement!(xg, "edges")
m = 0
for e in LightGraphs.edges(g)
for e in Graphs.edges(g)
xe = addelement!(xedges, "edge")
xe["id"] = "$m"
xe["source"] = "$(src(e)-1)"
Expand Down
16 changes: 8 additions & 8 deletions src/GML/Gml.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module GML

using GraphIO.ParserCombinator.Parsers
using LightGraphs
using LightGraphs: AbstractGraphFormat
using Graphs
using Graphs: AbstractGraphFormat

import LightGraphs: loadgraph, loadgraphs, savegraph
import Graphs: loadgraph, loadgraphs, savegraph

export GMLFormat

Expand All @@ -14,9 +14,9 @@ struct GMLFormat <: AbstractGraphFormat end
function _gml_read_one_graph(gs, dir)
nodes = [x[:id] for x in gs[:node]]
if dir
g = LightGraphs.DiGraph(length(nodes))
g = Graphs.DiGraph(length(nodes))
else
g = LightGraphs.Graph(length(nodes))
g = Graphs.Graph(length(nodes))
end
mapping = Dict{Int,Int}()
for (i, n) in enumerate(nodes)
Expand All @@ -42,7 +42,7 @@ end

function loadgml_mult(io::IO)
p = Parsers.GML.parse_dict(read(io, String))
graphs = Dict{String,LightGraphs.AbstractGraph}()
graphs = Dict{String,Graphs.AbstractGraph}()
for gs in p[:graph]
dir = Bool(get(gs, :directed, 0))
graphname = get(gs, :label, dir ? "digraph" : "graph")
Expand All @@ -57,7 +57,7 @@ end
Write a graph `g` with name `gname` to an IO stream `io` in the
[GML](https://en.wikipedia.org/wiki/Graph_Modelling_Language) format. Return 1.
"""
function savegml(io::IO, g::LightGraphs.AbstractGraph, gname::String = "")
function savegml(io::IO, g::Graphs.AbstractGraph, gname::String = "")
println(io, "graph")
println(io, "[")
length(gname) > 0 && println(io, "label \"$gname\"")
Expand All @@ -68,7 +68,7 @@ function savegml(io::IO, g::LightGraphs.AbstractGraph, gname::String = "")
println(io, "\t\tid $i")
println(io, "\t]")
end
for e in LightGraphs.edges(g)
for e in Graphs.edges(g)
s, t = Tuple(e)
println(io, "\tedge")
println(io, "\t[")
Expand Down
Loading

0 comments on commit fbde6c3

Please sign in to comment.