From df88100187462bef49f19151fde9178cdb04e15e Mon Sep 17 00:00:00 2001 From: etienneINSA Date: Tue, 7 May 2024 09:11:26 +0200 Subject: [PATCH 01/12] first shot --- src/{Test => WrappedGraph}/Test.jl | 0 src/WrappedGraph/WrappedGraph.jl | 69 ++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) rename src/{Test => WrappedGraph}/Test.jl (100%) create mode 100644 src/WrappedGraph/WrappedGraph.jl diff --git a/src/Test/Test.jl b/src/WrappedGraph/Test.jl similarity index 100% rename from src/Test/Test.jl rename to src/WrappedGraph/Test.jl diff --git a/src/WrappedGraph/WrappedGraph.jl b/src/WrappedGraph/WrappedGraph.jl new file mode 100644 index 000000000..81a60acb4 --- /dev/null +++ b/src/WrappedGraph/WrappedGraph.jl @@ -0,0 +1,69 @@ + +""" + Graphs.Test + +A module that provides utilities for testing functions that should work with any `Graphs.AbstractGraph`. +""" +module Test + +using Graphs + +""" + AbstractWrappedGraph{G <: AbstractGraph{T}} <: Graphs.AbstractGraph{T} + +An undirected graph type that wraps an `AbstractGraph{T}`. + +""" +@traitfn abstract type AbstractWrappedGraph{G::(!IsDirected)} <: Graphs.AbstractGraph{T} where {T, G<:AbstractGraph{T}} +# @traitfn abstract type AbstractWrappedGraph{G<:AbstractGraph{T}} <: Graphs.AbstractGraph{T} + +""" + AbstractWrappedGraph{G <: AbstractGraph{T}} <: Graphs.AbstractGraph{T} + +An undirected graph type that wraps an `AbstractGraph{T}`. + +""" +@traitfn abstract type AbstractWrappedDiGraph{G::IsDirected} <: Graphs.AbstractGraph{T} where {T, G<:AbstractGraph{T}} + +""" + wrapped_graph(g::AbstractWrappedGraph) + +Return the wrapped graph + +""" +function wrapped_graph(g::AbstractWrappedGraph) = _NI("wrapped_graph") + +# """ +# AbstractWrappedDiGraph{T} <: Graphs.AbstractGraph{T} + +Graphs.is_directed(::Type{<:AbstractWrappedGraph}) = false +Graphs.is_directed(::Type{<:AbstractWrappedDiGraph}) = true + +Graphs.edges(g::AbstractWrappedGraph) = (e for e in Graphs.edges(g.g)) +Graphs.edges(g::AbstractWrappedDiGraph) = (e for e in Graphs.edges(g.g)) + +Graphs.edgetype(g::AbstractWrappedGraph) = eltype(g) +Graphs.edgetype(g::AbstractWrappedDiGraph) = eltype(g) + +Graphs.has_edge(g::AbstractWrappedGraph, s, d) = Graphs.has_edge(g.g, s, d) +Graphs.has_edge(g::AbstractWrappedDiGraph, s, d) = Graphs.has_edge(g.g, s, d) + +Graphs.has_vertex(g::AbstractWrappedGraph, v) = Graphs.has_vertex(g.g, v) +Graphs.has_vertex(g::AbstractWrappedDiGraph, v) = Graphs.has_vertex(g.g, v) + +Graphs.inneighbors(g::AbstractWrappedGraph, v) = (u for u in Graphs.inneighbors(g.g, v)) +Graphs.inneighbors(g::AbstractWrappedDiGraph, v) = (u for u in Graphs.inneighbors(g.g, v)) + +Graphs.outneighbors(g::AbstractWrappedGraph, v) = (u for u in Graphs.outneighbors(g.g, v)) +Graphs.outneighbors(g::AbstractWrappedDiGraph, v) = (u for u in Graphs.outneighbors(g.g, v)) + +Graphs.ne(g::AbstractWrappedGraph) = Graphs.ne(g.g) +Graphs.ne(g::AbstractWrappedDiGraph) = Graphs.ne(g.g) + +Graphs.nv(g::AbstractWrappedGraph) = Graphs.nv(g.g) +Graphs.nv(g::AbstractWrappedDiGraph) = Graphs.nv(g.g) + +Graphs.vertices(g::AbstractWrappedGraph) = (v for v in Graphs.vertices(g.g)) +Graphs.vertices(g::AbstractWrappedDiGraph) = (v for v in Graphs.vertices(g.g)) + +end # module From 143c83c041476207a2613d1d96de640287147bb2 Mon Sep 17 00:00:00 2001 From: etienneINSA Date: Tue, 7 May 2024 18:30:38 +0200 Subject: [PATCH 02/12] wrapped graph and subtypes --- src/Graphs.jl | 7 +++ src/{WrappedGraph => Test}/Test.jl | 25 +++------ src/WrappedGraph/WrappedGraph.jl | 69 ------------------------- src/wrappedGraphs/graphviews.jl | 63 +++++++++++++++++++++++ src/wrappedGraphs/wrappedGraph.jl | 40 ++++++++++++++ test/runtests.jl | 1 + test/wrappedGraphs/graphviews.jl | 83 ++++++++++++++++++++++++++++++ 7 files changed, 200 insertions(+), 88 deletions(-) rename src/{WrappedGraph => Test}/Test.jl (73%) delete mode 100644 src/WrappedGraph/WrappedGraph.jl create mode 100644 src/wrappedGraphs/graphviews.jl create mode 100644 src/wrappedGraphs/wrappedGraph.jl create mode 100644 test/wrappedGraphs/graphviews.jl diff --git a/src/Graphs.jl b/src/Graphs.jl index f5c548b31..bf367c430 100644 --- a/src/Graphs.jl +++ b/src/Graphs.jl @@ -121,6 +121,11 @@ export squash, weights, + # wrapped graphs + AbstractWrappedGraph, + ReverseView, + UndirectedView, + # simplegraphs add_edge!, add_vertex!, @@ -462,6 +467,8 @@ include("utils.jl") include("deprecations.jl") include("core.jl") +include("wrappedGraphs/wrappedGraph.jl") +include("wrappedGraphs/graphviews.jl") include("SimpleGraphs/SimpleGraphs.jl") using .SimpleGraphs """ diff --git a/src/WrappedGraph/Test.jl b/src/Test/Test.jl similarity index 73% rename from src/WrappedGraph/Test.jl rename to src/Test/Test.jl index 5998a20b5..55647a49c 100644 --- a/src/WrappedGraph/Test.jl +++ b/src/Test/Test.jl @@ -27,22 +27,22 @@ Graphs.dst(e::GenericEdge) = Graphs.dst(e.e) Base.reverse(e::GenericEdge) = GenericEdge(reverse(e.e)) """ - GenericGraph{T} <: Graphs.AbstractGraph{T} + GenericGraph{T} <: Graphs.AbstractWrappedGraph{T, SimpleGraph{T}} An undirected graph type that can be used to tests functions that relay on the Graphs.jl interface. """ -struct GenericGraph{T} <: Graphs.AbstractGraph{T} +struct GenericGraph{T} <: Graphs.AbstractWrappedGraph{T, SimpleGraph{T}} g::SimpleGraph{T} end """ - GenericDiGraph{T} <: Graphs.AbstractGraph{T} + GenericDiGraph{T} <: Graphs.AbstractWrappedGraph{T, SimpleDiGraph{T}} A directed graph type that can be used to tests functions that relay on the Graphs.jl interface. """ -struct GenericDiGraph{T} <: Graphs.AbstractGraph{T} +struct GenericDiGraph{T} <: Graphs.AbstractWrappedGraph{T, SimpleDiGraph{T}} g::SimpleDiGraph{T} end @@ -60,8 +60,8 @@ function GenericDiGraph(elist::Vector{Graphs.SimpleDiGraphEdge{T}}) where {T<:In return GenericDiGraph{T}(SimpleDiGraph(elist)) end -Graphs.is_directed(::Type{<:GenericGraph}) = false -Graphs.is_directed(::Type{<:GenericDiGraph}) = true +Graphs.wrapped_graph(g::GenericGraph) = g.g +Graphs.wrapped_graph(g::GenericDiGraph) = g.g Graphs.edges(g::GenericGraph) = (GenericEdge(e) for e in Graphs.edges(g.g)) Graphs.edges(g::GenericDiGraph) = (GenericEdge(e) for e in Graphs.edges(g.g)) @@ -69,25 +69,12 @@ Graphs.edges(g::GenericDiGraph) = (GenericEdge(e) for e in Graphs.edges(g.g)) Graphs.edgetype(g::GenericGraph) = GenericEdge{eltype(g)} Graphs.edgetype(g::GenericDiGraph) = GenericEdge{eltype(g)} -Graphs.has_edge(g::GenericGraph, s, d) = Graphs.has_edge(g.g, s, d) -Graphs.has_edge(g::GenericDiGraph, s, d) = Graphs.has_edge(g.g, s, d) - -Graphs.has_vertex(g::GenericGraph, v) = Graphs.has_vertex(g.g, v) -Graphs.has_vertex(g::GenericDiGraph, v) = Graphs.has_vertex(g.g, v) - Graphs.inneighbors(g::GenericGraph, v) = (u for u in Graphs.inneighbors(g.g, v)) Graphs.inneighbors(g::GenericDiGraph, v) = (u for u in Graphs.inneighbors(g.g, v)) Graphs.outneighbors(g::GenericGraph, v) = (u for u in Graphs.outneighbors(g.g, v)) Graphs.outneighbors(g::GenericDiGraph, v) = (u for u in Graphs.outneighbors(g.g, v)) -Graphs.ne(g::GenericGraph) = Graphs.ne(g.g) -Graphs.ne(g::GenericDiGraph) = Graphs.ne(g.g) - -Graphs.nv(g::GenericGraph) = Graphs.nv(g.g) -Graphs.nv(g::GenericDiGraph) = Graphs.nv(g.g) - Graphs.vertices(g::GenericGraph) = (v for v in Graphs.vertices(g.g)) Graphs.vertices(g::GenericDiGraph) = (v for v in Graphs.vertices(g.g)) - end # module diff --git a/src/WrappedGraph/WrappedGraph.jl b/src/WrappedGraph/WrappedGraph.jl deleted file mode 100644 index 81a60acb4..000000000 --- a/src/WrappedGraph/WrappedGraph.jl +++ /dev/null @@ -1,69 +0,0 @@ - -""" - Graphs.Test - -A module that provides utilities for testing functions that should work with any `Graphs.AbstractGraph`. -""" -module Test - -using Graphs - -""" - AbstractWrappedGraph{G <: AbstractGraph{T}} <: Graphs.AbstractGraph{T} - -An undirected graph type that wraps an `AbstractGraph{T}`. - -""" -@traitfn abstract type AbstractWrappedGraph{G::(!IsDirected)} <: Graphs.AbstractGraph{T} where {T, G<:AbstractGraph{T}} -# @traitfn abstract type AbstractWrappedGraph{G<:AbstractGraph{T}} <: Graphs.AbstractGraph{T} - -""" - AbstractWrappedGraph{G <: AbstractGraph{T}} <: Graphs.AbstractGraph{T} - -An undirected graph type that wraps an `AbstractGraph{T}`. - -""" -@traitfn abstract type AbstractWrappedDiGraph{G::IsDirected} <: Graphs.AbstractGraph{T} where {T, G<:AbstractGraph{T}} - -""" - wrapped_graph(g::AbstractWrappedGraph) - -Return the wrapped graph - -""" -function wrapped_graph(g::AbstractWrappedGraph) = _NI("wrapped_graph") - -# """ -# AbstractWrappedDiGraph{T} <: Graphs.AbstractGraph{T} - -Graphs.is_directed(::Type{<:AbstractWrappedGraph}) = false -Graphs.is_directed(::Type{<:AbstractWrappedDiGraph}) = true - -Graphs.edges(g::AbstractWrappedGraph) = (e for e in Graphs.edges(g.g)) -Graphs.edges(g::AbstractWrappedDiGraph) = (e for e in Graphs.edges(g.g)) - -Graphs.edgetype(g::AbstractWrappedGraph) = eltype(g) -Graphs.edgetype(g::AbstractWrappedDiGraph) = eltype(g) - -Graphs.has_edge(g::AbstractWrappedGraph, s, d) = Graphs.has_edge(g.g, s, d) -Graphs.has_edge(g::AbstractWrappedDiGraph, s, d) = Graphs.has_edge(g.g, s, d) - -Graphs.has_vertex(g::AbstractWrappedGraph, v) = Graphs.has_vertex(g.g, v) -Graphs.has_vertex(g::AbstractWrappedDiGraph, v) = Graphs.has_vertex(g.g, v) - -Graphs.inneighbors(g::AbstractWrappedGraph, v) = (u for u in Graphs.inneighbors(g.g, v)) -Graphs.inneighbors(g::AbstractWrappedDiGraph, v) = (u for u in Graphs.inneighbors(g.g, v)) - -Graphs.outneighbors(g::AbstractWrappedGraph, v) = (u for u in Graphs.outneighbors(g.g, v)) -Graphs.outneighbors(g::AbstractWrappedDiGraph, v) = (u for u in Graphs.outneighbors(g.g, v)) - -Graphs.ne(g::AbstractWrappedGraph) = Graphs.ne(g.g) -Graphs.ne(g::AbstractWrappedDiGraph) = Graphs.ne(g.g) - -Graphs.nv(g::AbstractWrappedGraph) = Graphs.nv(g.g) -Graphs.nv(g::AbstractWrappedDiGraph) = Graphs.nv(g.g) - -Graphs.vertices(g::AbstractWrappedGraph) = (v for v in Graphs.vertices(g.g)) -Graphs.vertices(g::AbstractWrappedDiGraph) = (v for v in Graphs.vertices(g.g)) - -end # module diff --git a/src/wrappedGraphs/graphviews.jl b/src/wrappedGraphs/graphviews.jl new file mode 100644 index 000000000..dcbb615bd --- /dev/null +++ b/src/wrappedGraphs/graphviews.jl @@ -0,0 +1,63 @@ +""" + ReverseView{G} <: AbstractWrappedGraph{G} where {G <: AbstractGraph} + +A wrapper on a graph that reverse the direction of every edge. +""" +# @traitfn struct ReverseView{G<:AbstractGraph{T}::IsDirected} <: AbstractWrappedGraph{T, G} +struct ReverseView{T<:Integer, G<:AbstractGraph} <: AbstractWrappedGraph{T, G} + g::G +end + +ReverseView(g::G) where {T<:Integer, G<:AbstractGraph{T}} = ReverseView{T, G}(g) + +Graphs.wrapped_graph(g::ReverseView) = g.g + +Graphs.edges(g::ReverseView) = (reverse(e) for e in Graphs.edges(wrapped_graph(g))) + +Graphs.has_edge(g::ReverseView, s, d) = Graphs.has_edge(wrapped_graph(g), d, s) + +Graphs.inneighbors(g::ReverseView, v) = Graphs.outneighbors(wrapped_graph(g), v) + +Graphs.outneighbors(g::ReverseView, v) = Graphs.inneighbors(wrapped_graph(g), v) + +""" + UndirectedView{G} <: AbstractWrappedGraph{G} where {G <: AbstractGraph} + +A wrapper on a graph that consider every edges as undirected. +""" +struct UndirectedView{T<:Integer, G<:AbstractGraph} <: AbstractWrappedGraph{T, G} + g::G +end + +UndirectedView(g::G) where {T<:Integer, G<:AbstractGraph{T}} = UndirectedView{T, G}(g) + +Graphs.wrapped_graph(g::UndirectedView) = g.g + +Graphs.edges(g::UndirectedView) = ( + begin + (u, v) = src(e), dst(e); + if (v < u) + (u, v) = (v, u) + end; + Edge(u, v) + end + for e in Graphs.edges(wrapped_graph(g)) + if (src(e) <= dst(e) || !has_edge(g, dst(e), src(e))) +) + +Graphs.is_directed(::UndirectedView) = false +Graphs.is_directed(::Type{<:UndirectedView}) = false + +Graphs.has_edge(g::UndirectedView, s, d) = Graphs.has_edge(wrapped_graph(g), s, d) || Graphs.has_edge(wrapped_graph(g), d, s) + +Graphs.inneighbors(g::UndirectedView, v) = Graphs.all_neighbors(wrapped_graph(g), v) + +Graphs.outneighbors(g::UndirectedView, v) = Graphs.all_neighbors(wrapped_graph(g), v) + + + + + + + + diff --git a/src/wrappedGraphs/wrappedGraph.jl b/src/wrappedGraphs/wrappedGraph.jl new file mode 100644 index 000000000..0c80f0b2d --- /dev/null +++ b/src/wrappedGraphs/wrappedGraph.jl @@ -0,0 +1,40 @@ +""" + AbstractWrappedGraph{T<:Integer, G <: AbstractGraph{T}} <: Graphs.AbstractGraph{T} + +A graph type that wraps an `AbstractGraph{T}`. + +""" +abstract type AbstractWrappedGraph{T<:Integer, G<:AbstractGraph{T}} <: Graphs.AbstractGraph{T} end + +""" + wrapped_graph(g::AbstractWrappedGraph) + +Return the wrapped graph + +""" +wrapped_graph(g::AbstractWrappedGraph) =_NI("wrapped_graph") + + +Graphs.is_directed(::AbstractWrappedGraph{T, G}) where {T, G} = Graphs.is_directed(G) +Graphs.is_directed(::Type{<:AbstractWrappedGraph{T, G}}) where {T, G} = Graphs.is_directed(G) +# Graphs.is_directed(::AbstractWrappedGraph) = Graphs.is_directed(wrapped_graph(g)) +# Graphs.is_directed(::Type{<:AbstractWrappedGraph{T}}) where {G} = Graphs.is_directed(G) + + +Graphs.edges(g::AbstractWrappedGraph) = Graphs.edges(wrapped_graph(g)) + +Graphs.edgetype(g::AbstractWrappedGraph) = Graphs.edgetype(wrapped_graph(g)) + +Graphs.has_edge(g::AbstractWrappedGraph, s, d) = Graphs.has_edge(wrapped_graph(g), s, d) + +Graphs.has_vertex(g::AbstractWrappedGraph, v) = Graphs.has_vertex(wrapped_graph(g), v) + +Graphs.inneighbors(g::AbstractWrappedGraph, v) = Graphs.inneighbors(wrapped_graph(g), v) + +Graphs.outneighbors(g::AbstractWrappedGraph, v) = Graphs.outneighbors(wrapped_graph(g), v) + +Graphs.ne(g::AbstractWrappedGraph) = Graphs.ne(wrapped_graph(g)) + +Graphs.nv(g::AbstractWrappedGraph) = Graphs.nv(wrapped_graph(g)) + +Graphs.vertices(g::AbstractWrappedGraph) = Graphs.vertices(wrapped_graph(g)) diff --git a/test/runtests.jl b/test/runtests.jl index 1764fe537..ccd97cb96 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -79,6 +79,7 @@ tests = [ "interface", "core", "operators", + "wrappedGraphs/graphviews", "degeneracy", "distance", "digraph/transitivity", diff --git a/test/wrappedGraphs/graphviews.jl b/test/wrappedGraphs/graphviews.jl new file mode 100644 index 000000000..d10ffacd9 --- /dev/null +++ b/test/wrappedGraphs/graphviews.jl @@ -0,0 +1,83 @@ +@testset "Graph Views" begin + @testset "ReverseView" begin + gx = DiGraph([ + Edge(1, 1), + Edge(1, 2), + Edge(1, 4), + Edge(2, 1), + Edge(2, 2), + Edge(2, 4), + Edge(3, 1), + Edge(4, 3) + ]) + + gr = erdos_renyi(20, 0.5; is_directed = true) + + for g in hcat(test_generic_graphs(gx), test_generic_graphs(gr)) + rg = ReverseView(g) + + @test nv(rg) == nv(g) + @test ne(rg) == ne(g) + @test all((u, v) -> (u == v), zip(inneighbors(rg, 2), outneighbors(g, 2))) + @test all((u, v) -> (u == v), zip(outneighbors(rg, 2), inneighbors(g, 2))) + @test indegree(rg, 3) == outdegree(g, 3) + @test degree(rg, 1) == degree(g, 1) + @test has_edge(rg, 1, 3) == has_edge(g, 3, 1) + @test has_edge(rg, 1, 4) == has_edge(g, 4, 1) + + allocated_rg = reverse(g) + + rg_res = dijkstra_shortest_paths(rg, 3, 2) + allocated_rg_res = @inferred(dijkstra_shortest_paths(allocated_rg, 3, 2)) + @test rg_res.parents == allocated_rg_res.parents + @test rg_res.dists == allocated_rg_res.dists + + rg_res = biconnected_components(rg) + allocated_rg_res = @inferred(biconnected_components(allocated_rg)) + @test rg_res == allocated_rg_res + end + end + + @testset "UndirectedView" begin + gx = DiGraph([ + Edge(1, 1), + Edge(1, 2), + Edge(1, 4), + Edge(2, 1), + Edge(2, 2), + Edge(2, 4), + Edge(3, 1), + Edge(4, 3) + ]) + + gr = erdos_renyi(20, 0.5; is_directed = true) + + for g in test_generic_graphs(gx) + ug = UndirectedView(g) + @test ne(ug) == 7 # one less edge since there was two edges in reverse directions + end + + for g in hcat(test_generic_graphs(gx), test_generic_graphs(gr)) + ug = UndirectedView(g) + + @test nv(ug) == nv(g) + @test all((u, v) -> (u == v), zip(inneighbors(ug, 2), all_neighbors(g, 2))) + @test all((u, v) -> (u == v), zip(outneighbors(ug, 2), all_neighbors(g, 2))) + @test indegree(ug, 3) == length(all_neighbors(g, 3)) + @test degree(ug, 1) == degree(g, 1) + @test has_edge(ug, 1, 3) == has_edge(g, 1, 3) || has_edge(g, 3, 1) + @test has_edge(ug, 1, 4) == has_edge(g, 1, 4) || has_edge(g, 4, 1) + + allocated_ug = Graph(g) + + ug_res = dijkstra_shortest_paths(ug, 3, 2) + allocated_ug_res = @inferred(dijkstra_shortest_paths(allocated_ug, 3, 2)) + @test ug_res.parents == allocated_ug_res.parents + @test ug_res.dists == allocated_ug_res.dists + + ug_res = biconnected_components(ug) + allocated_ug_res = @inferred(biconnected_components(allocated_ug)) + @test ug_res == allocated_ug_res + end + end +end \ No newline at end of file From 45d08e12f3c8dfd15048b1816d76d417fc101606 Mon Sep 17 00:00:00 2001 From: etienneINSA Date: Wed, 8 May 2024 15:52:46 +0200 Subject: [PATCH 03/12] Yanking WrappedGraph --- src/Graphs.jl | 1 - src/Test/Test.jl | 27 ++++++++--- src/wrappedGraphs/graphviews.jl | 66 +++++++++++++++++---------- src/wrappedGraphs/wrappedGraph.jl | 40 ---------------- test/wrappedGraphs/graphviews.jl | 76 +++++++++++++++++-------------- 5 files changed, 103 insertions(+), 107 deletions(-) delete mode 100644 src/wrappedGraphs/wrappedGraph.jl diff --git a/src/Graphs.jl b/src/Graphs.jl index bf367c430..44c5bec94 100644 --- a/src/Graphs.jl +++ b/src/Graphs.jl @@ -467,7 +467,6 @@ include("utils.jl") include("deprecations.jl") include("core.jl") -include("wrappedGraphs/wrappedGraph.jl") include("wrappedGraphs/graphviews.jl") include("SimpleGraphs/SimpleGraphs.jl") using .SimpleGraphs diff --git a/src/Test/Test.jl b/src/Test/Test.jl index 55647a49c..b3bd0204b 100644 --- a/src/Test/Test.jl +++ b/src/Test/Test.jl @@ -27,22 +27,22 @@ Graphs.dst(e::GenericEdge) = Graphs.dst(e.e) Base.reverse(e::GenericEdge) = GenericEdge(reverse(e.e)) """ - GenericGraph{T} <: Graphs.AbstractWrappedGraph{T, SimpleGraph{T}} + GenericGraph{T} <: Graphs.AbstractGraph{T} An undirected graph type that can be used to tests functions that relay on the Graphs.jl interface. """ -struct GenericGraph{T} <: Graphs.AbstractWrappedGraph{T, SimpleGraph{T}} +struct GenericGraph{T} <: Graphs.AbstractGraph{T} g::SimpleGraph{T} end """ - GenericDiGraph{T} <: Graphs.AbstractWrappedGraph{T, SimpleDiGraph{T}} + GenericDiGraph{T} <: Graphs.AbstractGraph{T} A directed graph type that can be used to tests functions that relay on the Graphs.jl interface. """ -struct GenericDiGraph{T} <: Graphs.AbstractWrappedGraph{T, SimpleDiGraph{T}} +struct GenericDiGraph{T} <: Graphs.AbstractGraph{T} g::SimpleDiGraph{T} end @@ -60,8 +60,8 @@ function GenericDiGraph(elist::Vector{Graphs.SimpleDiGraphEdge{T}}) where {T<:In return GenericDiGraph{T}(SimpleDiGraph(elist)) end -Graphs.wrapped_graph(g::GenericGraph) = g.g -Graphs.wrapped_graph(g::GenericDiGraph) = g.g +Graphs.is_directed(::Type{<:GenericGraph}) = false +Graphs.is_directed(::Type{<:GenericDiGraph}) = true Graphs.edges(g::GenericGraph) = (GenericEdge(e) for e in Graphs.edges(g.g)) Graphs.edges(g::GenericDiGraph) = (GenericEdge(e) for e in Graphs.edges(g.g)) @@ -69,12 +69,25 @@ Graphs.edges(g::GenericDiGraph) = (GenericEdge(e) for e in Graphs.edges(g.g)) Graphs.edgetype(g::GenericGraph) = GenericEdge{eltype(g)} Graphs.edgetype(g::GenericDiGraph) = GenericEdge{eltype(g)} +Graphs.has_edge(g::GenericGraph, s, d) = Graphs.has_edge(g.g, s, d) +Graphs.has_edge(g::GenericDiGraph, s, d) = Graphs.has_edge(g.g, s, d) + +Graphs.has_vertex(g::GenericGraph, v) = Graphs.has_vertex(g.g, v) +Graphs.has_vertex(g::GenericDiGraph, v) = Graphs.has_vertex(g.g, v) + Graphs.inneighbors(g::GenericGraph, v) = (u for u in Graphs.inneighbors(g.g, v)) Graphs.inneighbors(g::GenericDiGraph, v) = (u for u in Graphs.inneighbors(g.g, v)) Graphs.outneighbors(g::GenericGraph, v) = (u for u in Graphs.outneighbors(g.g, v)) Graphs.outneighbors(g::GenericDiGraph, v) = (u for u in Graphs.outneighbors(g.g, v)) +Graphs.ne(g::GenericGraph) = Graphs.ne(g.g) +Graphs.ne(g::GenericDiGraph) = Graphs.ne(g.g) + +Graphs.nv(g::GenericGraph) = Graphs.nv(g.g) +Graphs.nv(g::GenericDiGraph) = Graphs.nv(g.g) + Graphs.vertices(g::GenericGraph) = (v for v in Graphs.vertices(g.g)) Graphs.vertices(g::GenericDiGraph) = (v for v in Graphs.vertices(g.g)) -end # module + +end # module \ No newline at end of file diff --git a/src/wrappedGraphs/graphviews.jl b/src/wrappedGraphs/graphviews.jl index dcbb615bd..f87fc4e63 100644 --- a/src/wrappedGraphs/graphviews.jl +++ b/src/wrappedGraphs/graphviews.jl @@ -1,38 +1,66 @@ """ - ReverseView{G} <: AbstractWrappedGraph{G} where {G <: AbstractGraph} + ReverseView{G} <: ReverseView{G} where {G <: AbstractGraph} A wrapper on a graph that reverse the direction of every edge. """ -# @traitfn struct ReverseView{G<:AbstractGraph{T}::IsDirected} <: AbstractWrappedGraph{T, G} -struct ReverseView{T<:Integer, G<:AbstractGraph} <: AbstractWrappedGraph{T, G} +# @traitfn struct ReverseView{G<:AbstractGraph{T}::IsDirected} <: ReverseView{T, G} +struct ReverseView{T<:Integer, G<:AbstractGraph} <: AbstractGraph{T} g::G + + @traitfn ReverseView{T, G}(g::::(IsDirected)) where {T<:Integer, G<:AbstractGraph{T}} = new(g) + @traitfn ReverseView{T, G}(g::::(!IsDirected)) where {T<:Integer, G<:AbstractGraph{T}} = "Your graph needs to be directed" end ReverseView(g::G) where {T<:Integer, G<:AbstractGraph{T}} = ReverseView{T, G}(g) -Graphs.wrapped_graph(g::ReverseView) = g.g +wrapped_graph(g::ReverseView) = g.g -Graphs.edges(g::ReverseView) = (reverse(e) for e in Graphs.edges(wrapped_graph(g))) -Graphs.has_edge(g::ReverseView, s, d) = Graphs.has_edge(wrapped_graph(g), d, s) +Graphs.is_directed(::ReverseView{T, G}) where {T, G} = true +Graphs.is_directed(::Type{<:ReverseView{T, G}}) where {T, G} = true -Graphs.inneighbors(g::ReverseView, v) = Graphs.outneighbors(wrapped_graph(g), v) - -Graphs.outneighbors(g::ReverseView, v) = Graphs.inneighbors(wrapped_graph(g), v) +Graphs.edgetype(g::ReverseView) = Graphs.edgetype(g.g) +Graphs.has_vertex(g::ReverseView, v) = Graphs.has_vertex(g.g, v) +Graphs.ne(g::ReverseView) = Graphs.ne(g.g) +Graphs.nv(g::ReverseView) = Graphs.nv(g.g) +Graphs.vertices(g::ReverseView) = Graphs.vertices(g.g) +Graphs.edges(g::ReverseView) = (reverse(e) for e in Graphs.edges(g.g)) +Graphs.has_edge(g::ReverseView, s, d) = Graphs.has_edge(g.g, d, s) +Graphs.inneighbors(g::ReverseView, v) = Graphs.outneighbors(g.g, v) +Graphs.outneighbors(g::ReverseView, v) = Graphs.inneighbors(g.g, v) """ - UndirectedView{G} <: AbstractWrappedGraph{G} where {G <: AbstractGraph} + UndirectedView{G} <: ReverseView{G} where {G <: AbstractGraph} A wrapper on a graph that consider every edges as undirected. """ -struct UndirectedView{T<:Integer, G<:AbstractGraph} <: AbstractWrappedGraph{T, G} +struct UndirectedView{T<:Integer, G<:AbstractGraph} <: AbstractGraph{T} g::G + ne::Int + @traitfn function UndirectedView{T, G}(g::::(IsDirected)) where {T<:Integer, G<:AbstractGraph{T}} + ne = count(e -> src(e) <= dst(e) || !has_edge(g, dst(e), src(e)), Graphs.edges(g)) + new(g, ne) + end + + @traitfn UndirectedView{T, G}(g::::(!IsDirected)) where {T<:Integer, G<:AbstractGraph{T}} = error("Your graph need to be directed") end UndirectedView(g::G) where {T<:Integer, G<:AbstractGraph{T}} = UndirectedView{T, G}(g) -Graphs.wrapped_graph(g::UndirectedView) = g.g +wrapped_graph(g::UndirectedView) = g.g + +Graphs.is_directed(::UndirectedView) = false +Graphs.is_directed(::Type{<:UndirectedView}) = false + +Graphs.edgetype(g::UndirectedView) = Graphs.edgetype(g.g) +Graphs.has_vertex(g::UndirectedView, v) = Graphs.has_vertex(g.g, v) +Graphs.ne(g::UndirectedView) = g.ne +Graphs.nv(g::UndirectedView) = Graphs.nv(g.g) +Graphs.vertices(g::UndirectedView) = Graphs.vertices(g.g) +Graphs.has_edge(g::UndirectedView, s, d) = Graphs.has_edge(g.g, s, d) || Graphs.has_edge(g.g, d, s) +Graphs.inneighbors(g::UndirectedView, v) = Graphs.all_neighbors(g.g, v) +Graphs.outneighbors(g::UndirectedView, v) = Graphs.all_neighbors(g.g, v) Graphs.edges(g::UndirectedView) = ( begin (u, v) = src(e), dst(e); @@ -41,20 +69,10 @@ Graphs.edges(g::UndirectedView) = ( end; Edge(u, v) end - for e in Graphs.edges(wrapped_graph(g)) - if (src(e) <= dst(e) || !has_edge(g, dst(e), src(e))) + for e in Graphs.edges(g.g) + if (src(e) <= dst(e) || !has_edge(g.g, dst(e), src(e))) ) -Graphs.is_directed(::UndirectedView) = false -Graphs.is_directed(::Type{<:UndirectedView}) = false - -Graphs.has_edge(g::UndirectedView, s, d) = Graphs.has_edge(wrapped_graph(g), s, d) || Graphs.has_edge(wrapped_graph(g), d, s) - -Graphs.inneighbors(g::UndirectedView, v) = Graphs.all_neighbors(wrapped_graph(g), v) - -Graphs.outneighbors(g::UndirectedView, v) = Graphs.all_neighbors(wrapped_graph(g), v) - - diff --git a/src/wrappedGraphs/wrappedGraph.jl b/src/wrappedGraphs/wrappedGraph.jl deleted file mode 100644 index 0c80f0b2d..000000000 --- a/src/wrappedGraphs/wrappedGraph.jl +++ /dev/null @@ -1,40 +0,0 @@ -""" - AbstractWrappedGraph{T<:Integer, G <: AbstractGraph{T}} <: Graphs.AbstractGraph{T} - -A graph type that wraps an `AbstractGraph{T}`. - -""" -abstract type AbstractWrappedGraph{T<:Integer, G<:AbstractGraph{T}} <: Graphs.AbstractGraph{T} end - -""" - wrapped_graph(g::AbstractWrappedGraph) - -Return the wrapped graph - -""" -wrapped_graph(g::AbstractWrappedGraph) =_NI("wrapped_graph") - - -Graphs.is_directed(::AbstractWrappedGraph{T, G}) where {T, G} = Graphs.is_directed(G) -Graphs.is_directed(::Type{<:AbstractWrappedGraph{T, G}}) where {T, G} = Graphs.is_directed(G) -# Graphs.is_directed(::AbstractWrappedGraph) = Graphs.is_directed(wrapped_graph(g)) -# Graphs.is_directed(::Type{<:AbstractWrappedGraph{T}}) where {G} = Graphs.is_directed(G) - - -Graphs.edges(g::AbstractWrappedGraph) = Graphs.edges(wrapped_graph(g)) - -Graphs.edgetype(g::AbstractWrappedGraph) = Graphs.edgetype(wrapped_graph(g)) - -Graphs.has_edge(g::AbstractWrappedGraph, s, d) = Graphs.has_edge(wrapped_graph(g), s, d) - -Graphs.has_vertex(g::AbstractWrappedGraph, v) = Graphs.has_vertex(wrapped_graph(g), v) - -Graphs.inneighbors(g::AbstractWrappedGraph, v) = Graphs.inneighbors(wrapped_graph(g), v) - -Graphs.outneighbors(g::AbstractWrappedGraph, v) = Graphs.outneighbors(wrapped_graph(g), v) - -Graphs.ne(g::AbstractWrappedGraph) = Graphs.ne(wrapped_graph(g)) - -Graphs.nv(g::AbstractWrappedGraph) = Graphs.nv(wrapped_graph(g)) - -Graphs.vertices(g::AbstractWrappedGraph) = Graphs.vertices(wrapped_graph(g)) diff --git a/test/wrappedGraphs/graphviews.jl b/test/wrappedGraphs/graphviews.jl index d10ffacd9..a2fd9b4f6 100644 --- a/test/wrappedGraphs/graphviews.jl +++ b/test/wrappedGraphs/graphviews.jl @@ -11,30 +11,34 @@ Edge(4, 3) ]) - gr = erdos_renyi(20, 0.5; is_directed = true) + gr = erdos_renyi(20, 0.1; is_directed = true) for g in hcat(test_generic_graphs(gx), test_generic_graphs(gr)) rg = ReverseView(g) - - @test nv(rg) == nv(g) - @test ne(rg) == ne(g) - @test all((u, v) -> (u == v), zip(inneighbors(rg, 2), outneighbors(g, 2))) - @test all((u, v) -> (u == v), zip(outneighbors(rg, 2), inneighbors(g, 2))) - @test indegree(rg, 3) == outdegree(g, 3) - @test degree(rg, 1) == degree(g, 1) - @test has_edge(rg, 1, 3) == has_edge(g, 3, 1) - @test has_edge(rg, 1, 4) == has_edge(g, 4, 1) + allocated_rg = DiGraph(nv(g)) + for e in edges(g) + add_edge!(allocated_rg, Edge(dst(e), src(e))) + end - allocated_rg = reverse(g) + @test eltype(rg) == eltype(g) + @test is_directed(rg) == true + @test nv(rg) == nv(g) == nv(allocated_rg) + @test ne(rg) == ne(g) == ne(allocated_rg) + @test sort(collect(inneighbors(rg, 2))) == sort(collect(inneighbors(allocated_rg, 2))) + @test sort(collect(outneighbors(rg, 2))) == sort(collect(outneighbors(allocated_rg, 2))) + @test indegree(rg, 3) == indegree(allocated_rg, 3) + @test degree(rg, 1) == degree(allocated_rg, 1) + @test has_edge(rg, 1, 3) == has_edge(allocated_rg, 1, 3) + @test has_edge(rg, 1, 4) == has_edge(allocated_rg, 1, 4) - rg_res = dijkstra_shortest_paths(rg, 3, 2) - allocated_rg_res = @inferred(dijkstra_shortest_paths(allocated_rg, 3, 2)) - @test rg_res.parents == allocated_rg_res.parents - @test rg_res.dists == allocated_rg_res.dists + rg_res = @inferred(dijkstra_shortest_paths(rg, 3)) + allocated_rg_res = dijkstra_shortest_paths(allocated_rg, 3) + @test rg_res.dists == allocated_rg_res.dists # parents may not be the same - rg_res = biconnected_components(rg) - allocated_rg_res = @inferred(biconnected_components(allocated_rg)) - @test rg_res == allocated_rg_res + rg_res = @inferred(strongly_connected_components(rg)) + allocated_rg_res = strongly_connected_components(allocated_rg) + @test length(rg_res) == length(allocated_rg_res) + @test sort(length.(rg_res)) == sort(length.(allocated_rg_res)) end end @@ -50,7 +54,7 @@ Edge(4, 3) ]) - gr = erdos_renyi(20, 0.5; is_directed = true) + gr = erdos_renyi(20, 0.05; is_directed = true) for g in test_generic_graphs(gx) ug = UndirectedView(g) @@ -59,25 +63,27 @@ for g in hcat(test_generic_graphs(gx), test_generic_graphs(gr)) ug = UndirectedView(g) - - @test nv(ug) == nv(g) - @test all((u, v) -> (u == v), zip(inneighbors(ug, 2), all_neighbors(g, 2))) - @test all((u, v) -> (u == v), zip(outneighbors(ug, 2), all_neighbors(g, 2))) - @test indegree(ug, 3) == length(all_neighbors(g, 3)) - @test degree(ug, 1) == degree(g, 1) - @test has_edge(ug, 1, 3) == has_edge(g, 1, 3) || has_edge(g, 3, 1) - @test has_edge(ug, 1, 4) == has_edge(g, 1, 4) || has_edge(g, 4, 1) - allocated_ug = Graph(g) + + @test eltype(ug) == eltype(g) + @test is_directed(ug) == false + @test nv(ug) == nv(g) == nv(allocated_ug) + @test ne(ug) == ne(allocated_ug) + @test sort(collect(inneighbors(ug, 2))) == sort(collect(inneighbors(allocated_ug, 2))) + @test sort(collect(outneighbors(ug, 2))) == sort(collect(outneighbors(allocated_ug, 2))) + @test indegree(ug, 3) == indegree(allocated_ug, 3) + @test degree(ug, 1) == degree(allocated_ug, 1) + @test has_edge(ug, 1, 3) == has_edge(allocated_ug, 1, 3) + @test has_edge(ug, 1, 4) == has_edge(allocated_ug, 1, 4) - ug_res = dijkstra_shortest_paths(ug, 3, 2) - allocated_ug_res = @inferred(dijkstra_shortest_paths(allocated_ug, 3, 2)) - @test ug_res.parents == allocated_ug_res.parents - @test ug_res.dists == allocated_ug_res.dists + ug_res = @inferred(dijkstra_shortest_paths(ug, 3)) + allocated_ug_res = dijkstra_shortest_paths(allocated_ug, 3) + @test ug_res.dists == allocated_ug_res.dists # parents may not be the same - ug_res = biconnected_components(ug) - allocated_ug_res = @inferred(biconnected_components(allocated_ug)) - @test ug_res == allocated_ug_res + ug_res = @inferred(biconnected_components(ug)) + allocated_ug_res = biconnected_components(allocated_ug) + @test length(ug_res) == length(allocated_ug_res) + @test sort(length.(ug_res)) == sort(length.(allocated_ug_res)) end end end \ No newline at end of file From 64f05f19a0a5fc85d05ec659bc20430de48fc8e2 Mon Sep 17 00:00:00 2001 From: etienneINSA Date: Wed, 8 May 2024 15:59:43 +0200 Subject: [PATCH 04/12] oups --- src/Graphs.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Graphs.jl b/src/Graphs.jl index 44c5bec94..861be96a7 100644 --- a/src/Graphs.jl +++ b/src/Graphs.jl @@ -122,7 +122,6 @@ export weights, # wrapped graphs - AbstractWrappedGraph, ReverseView, UndirectedView, From a88a2277a7ae656e2d32d5093b367b2f6685529c Mon Sep 17 00:00:00 2001 From: etienneINSA Date: Wed, 8 May 2024 16:20:52 +0200 Subject: [PATCH 05/12] format --- src/Test/Test.jl | 2 +- src/wrappedGraphs/graphviews.jl | 68 ++++++++++++++++---------------- test/wrappedGraphs/graphviews.jl | 28 +++++++------ 3 files changed, 51 insertions(+), 47 deletions(-) diff --git a/src/Test/Test.jl b/src/Test/Test.jl index b3bd0204b..5998a20b5 100644 --- a/src/Test/Test.jl +++ b/src/Test/Test.jl @@ -90,4 +90,4 @@ Graphs.nv(g::GenericDiGraph) = Graphs.nv(g.g) Graphs.vertices(g::GenericGraph) = (v for v in Graphs.vertices(g.g)) Graphs.vertices(g::GenericDiGraph) = (v for v in Graphs.vertices(g.g)) -end # module \ No newline at end of file +end # module diff --git a/src/wrappedGraphs/graphviews.jl b/src/wrappedGraphs/graphviews.jl index f87fc4e63..bd385eec6 100644 --- a/src/wrappedGraphs/graphviews.jl +++ b/src/wrappedGraphs/graphviews.jl @@ -4,20 +4,21 @@ A wrapper on a graph that reverse the direction of every edge. """ # @traitfn struct ReverseView{G<:AbstractGraph{T}::IsDirected} <: ReverseView{T, G} -struct ReverseView{T<:Integer, G<:AbstractGraph} <: AbstractGraph{T} +struct ReverseView{T<:Integer,G<:AbstractGraph} <: AbstractGraph{T} g::G - - @traitfn ReverseView{T, G}(g::::(IsDirected)) where {T<:Integer, G<:AbstractGraph{T}} = new(g) - @traitfn ReverseView{T, G}(g::::(!IsDirected)) where {T<:Integer, G<:AbstractGraph{T}} = "Your graph needs to be directed" + + @traitfn ReverseView{T,G}(g::::(IsDirected)) where {T<:Integer,G<:AbstractGraph{T}} = + new(g) + @traitfn ReverseView{T,G}(g::::(!IsDirected)) where {T<:Integer,G<:AbstractGraph{T}} = + "Your graph needs to be directed" end -ReverseView(g::G) where {T<:Integer, G<:AbstractGraph{T}} = ReverseView{T, G}(g) +ReverseView(g::G) where {T<:Integer,G<:AbstractGraph{T}} = ReverseView{T,G}(g) wrapped_graph(g::ReverseView) = g.g - -Graphs.is_directed(::ReverseView{T, G}) where {T, G} = true -Graphs.is_directed(::Type{<:ReverseView{T, G}}) where {T, G} = true +Graphs.is_directed(::ReverseView{T,G}) where {T,G} = true +Graphs.is_directed(::Type{<:ReverseView{T,G}}) where {T,G} = true Graphs.edgetype(g::ReverseView) = Graphs.edgetype(g.g) Graphs.has_vertex(g::ReverseView, v) = Graphs.has_vertex(g.g, v) @@ -34,19 +35,22 @@ Graphs.outneighbors(g::ReverseView, v) = Graphs.inneighbors(g.g, v) A wrapper on a graph that consider every edges as undirected. """ -struct UndirectedView{T<:Integer, G<:AbstractGraph} <: AbstractGraph{T} +struct UndirectedView{T<:Integer,G<:AbstractGraph} <: AbstractGraph{T} g::G ne::Int - @traitfn function UndirectedView{T, G}(g::::(IsDirected)) where {T<:Integer, G<:AbstractGraph{T}} + @traitfn function UndirectedView{T,G}( + g::::(IsDirected) + ) where {T<:Integer,G<:AbstractGraph{T}} ne = count(e -> src(e) <= dst(e) || !has_edge(g, dst(e), src(e)), Graphs.edges(g)) - new(g, ne) + return new(g, ne) end - - @traitfn UndirectedView{T, G}(g::::(!IsDirected)) where {T<:Integer, G<:AbstractGraph{T}} = error("Your graph need to be directed") -end -UndirectedView(g::G) where {T<:Integer, G<:AbstractGraph{T}} = UndirectedView{T, G}(g) + @traitfn UndirectedView{T,G}( + g::::(!IsDirected) + ) where {T<:Integer,G<:AbstractGraph{T}} = error("Your graph need to be directed") +end +UndirectedView(g::G) where {T<:Integer,G<:AbstractGraph{T}} = UndirectedView{T,G}(g) wrapped_graph(g::UndirectedView) = g.g @@ -58,24 +62,20 @@ Graphs.has_vertex(g::UndirectedView, v) = Graphs.has_vertex(g.g, v) Graphs.ne(g::UndirectedView) = g.ne Graphs.nv(g::UndirectedView) = Graphs.nv(g.g) Graphs.vertices(g::UndirectedView) = Graphs.vertices(g.g) -Graphs.has_edge(g::UndirectedView, s, d) = Graphs.has_edge(g.g, s, d) || Graphs.has_edge(g.g, d, s) +function Graphs.has_edge(g::UndirectedView, s, d) + return Graphs.has_edge(g.g, s, d) || Graphs.has_edge(g.g, d, s) +end Graphs.inneighbors(g::UndirectedView, v) = Graphs.all_neighbors(g.g, v) Graphs.outneighbors(g::UndirectedView, v) = Graphs.all_neighbors(g.g, v) -Graphs.edges(g::UndirectedView) = ( - begin - (u, v) = src(e), dst(e); - if (v < u) - (u, v) = (v, u) - end; - Edge(u, v) - end - for e in Graphs.edges(g.g) - if (src(e) <= dst(e) || !has_edge(g.g, dst(e), src(e))) -) - - - - - - - +function Graphs.edges(g::UndirectedView) + return ( + begin + (u, v) = src(e), dst(e) + if (v < u) + (u, v) = (v, u) + end + Edge(u, v) + end for + e in Graphs.edges(g.g) if (src(e) <= dst(e) || !has_edge(g.g, dst(e), src(e))) + ) +end diff --git a/test/wrappedGraphs/graphviews.jl b/test/wrappedGraphs/graphviews.jl index a2fd9b4f6..977fd502a 100644 --- a/test/wrappedGraphs/graphviews.jl +++ b/test/wrappedGraphs/graphviews.jl @@ -8,10 +8,10 @@ Edge(2, 2), Edge(2, 4), Edge(3, 1), - Edge(4, 3) + Edge(4, 3), ]) - gr = erdos_renyi(20, 0.1; is_directed = true) + gr = erdos_renyi(20, 0.1; is_directed=true) for g in hcat(test_generic_graphs(gx), test_generic_graphs(gr)) rg = ReverseView(g) @@ -24,11 +24,13 @@ @test is_directed(rg) == true @test nv(rg) == nv(g) == nv(allocated_rg) @test ne(rg) == ne(g) == ne(allocated_rg) - @test sort(collect(inneighbors(rg, 2))) == sort(collect(inneighbors(allocated_rg, 2))) - @test sort(collect(outneighbors(rg, 2))) == sort(collect(outneighbors(allocated_rg, 2))) + @test sort(collect(inneighbors(rg, 2))) == + sort(collect(inneighbors(allocated_rg, 2))) + @test sort(collect(outneighbors(rg, 2))) == + sort(collect(outneighbors(allocated_rg, 2))) @test indegree(rg, 3) == indegree(allocated_rg, 3) @test degree(rg, 1) == degree(allocated_rg, 1) - @test has_edge(rg, 1, 3) == has_edge(allocated_rg, 1, 3) + @test has_edge(rg, 1, 3) == has_edge(allocated_rg, 1, 3) @test has_edge(rg, 1, 4) == has_edge(allocated_rg, 1, 4) rg_res = @inferred(dijkstra_shortest_paths(rg, 3)) @@ -51,10 +53,10 @@ Edge(2, 2), Edge(2, 4), Edge(3, 1), - Edge(4, 3) + Edge(4, 3), ]) - gr = erdos_renyi(20, 0.05; is_directed = true) + gr = erdos_renyi(20, 0.05; is_directed=true) for g in test_generic_graphs(gx) ug = UndirectedView(g) @@ -64,16 +66,18 @@ for g in hcat(test_generic_graphs(gx), test_generic_graphs(gr)) ug = UndirectedView(g) allocated_ug = Graph(g) - + @test eltype(ug) == eltype(g) @test is_directed(ug) == false @test nv(ug) == nv(g) == nv(allocated_ug) @test ne(ug) == ne(allocated_ug) - @test sort(collect(inneighbors(ug, 2))) == sort(collect(inneighbors(allocated_ug, 2))) - @test sort(collect(outneighbors(ug, 2))) == sort(collect(outneighbors(allocated_ug, 2))) + @test sort(collect(inneighbors(ug, 2))) == + sort(collect(inneighbors(allocated_ug, 2))) + @test sort(collect(outneighbors(ug, 2))) == + sort(collect(outneighbors(allocated_ug, 2))) @test indegree(ug, 3) == indegree(allocated_ug, 3) @test degree(ug, 1) == degree(allocated_ug, 1) - @test has_edge(ug, 1, 3) == has_edge(allocated_ug, 1, 3) + @test has_edge(ug, 1, 3) == has_edge(allocated_ug, 1, 3) @test has_edge(ug, 1, 4) == has_edge(allocated_ug, 1, 4) ug_res = @inferred(dijkstra_shortest_paths(ug, 3)) @@ -86,4 +90,4 @@ @test sort(length.(ug_res)) == sort(length.(allocated_ug_res)) end end -end \ No newline at end of file +end From 714c1f8740f82299f23beccfbcea4c2a07ba6de8 Mon Sep 17 00:00:00 2001 From: etienneINSA Date: Wed, 8 May 2024 18:23:52 +0200 Subject: [PATCH 06/12] docstrings --- src/wrappedGraphs/graphviews.jl | 44 ++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/src/wrappedGraphs/graphviews.jl b/src/wrappedGraphs/graphviews.jl index bd385eec6..98c23abbf 100644 --- a/src/wrappedGraphs/graphviews.jl +++ b/src/wrappedGraphs/graphviews.jl @@ -1,9 +1,26 @@ """ - ReverseView{G} <: ReverseView{G} where {G <: AbstractGraph} + ReverseView{T<:Integer,G<:AbstractGraph} <: AbstractGraph{T} A wrapper on a graph that reverse the direction of every edge. + +# Examples +```jldoctest +julia> using Graphs + +julia> g = SimpleDiGraph(2) + +julia> add_edge!(g, 1, 2) + +julia> rg = ReverseView(g) + +julia> neighbors(rg, 1) +Int64[] + +julia> neighbors(rg, 2) +1-element Vector{Int64}: + 1 +``` """ -# @traitfn struct ReverseView{G<:AbstractGraph{T}::IsDirected} <: ReverseView{T, G} struct ReverseView{T<:Integer,G<:AbstractGraph} <: AbstractGraph{T} g::G @@ -31,9 +48,28 @@ Graphs.inneighbors(g::ReverseView, v) = Graphs.outneighbors(g.g, v) Graphs.outneighbors(g::ReverseView, v) = Graphs.inneighbors(g.g, v) """ - UndirectedView{G} <: ReverseView{G} where {G <: AbstractGraph} + UndirectedView{T<:Integer,G<:AbstractGraph} <: AbstractGraph{T} + +A wrapper on a graph that consider every edge as undirected. + +# Examples +```jldoctest +julia> using Graphs + +julia> g = SimpleDiGraph(2) + +julia> add_edge!(g, 1, 2) + +julia> ug = UndirectedView(g) + +julia> neighbors(ug, 1) +1-element Vector{Int64}: + 2 -A wrapper on a graph that consider every edges as undirected. +julia> neighbors(ug, 2) +1-element Vector{Int64}: + 1 +``` """ struct UndirectedView{T<:Integer,G<:AbstractGraph} <: AbstractGraph{T} g::G From 78ee8cdc067a51437a9b6982275cef09ba38e256 Mon Sep 17 00:00:00 2001 From: etienneINSA Date: Wed, 8 May 2024 18:35:10 +0200 Subject: [PATCH 07/12] documentation --- docs/make.jl | 1 + docs/src/core_functions/wrappedgraphs.md | 20 ++++++++++++++++++++ src/wrappedGraphs/graphviews.jl | 4 ++-- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 docs/src/core_functions/wrappedgraphs.md diff --git a/docs/make.jl b/docs/make.jl index 4a407f687..cf6e739ac 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -44,6 +44,7 @@ pages_files = [ "core_functions/persistence.md", "core_functions/simplegraphs_generators.md", "core_functions/simplegraphs.md", + "core_functions/wrappedgraphs.md", ], "Algorithms API" => [ "algorithms/biconnectivity.md", diff --git a/docs/src/core_functions/wrappedgraphs.md b/docs/src/core_functions/wrappedgraphs.md new file mode 100644 index 000000000..a1290dc2c --- /dev/null +++ b/docs/src/core_functions/wrappedgraphs.md @@ -0,0 +1,20 @@ +# Graph views formats + +*Graphs.jl* provides views around directed graphs. +`ReverseGraph` is a graph view that wraps a directed graph and reverse the direction of every edge. +`UndirectedGraph` is a graph view that wraps a directed graph and consider every edge as undirected. + +## Index + +```@index +Pages = ["wrappedgraphs.md"] +``` + +## Full docs + +```@autodocs +Pages = [ + "wrappedgraphs/graphviews.jl", +] + +``` \ No newline at end of file diff --git a/src/wrappedGraphs/graphviews.jl b/src/wrappedGraphs/graphviews.jl index 98c23abbf..b0605bef0 100644 --- a/src/wrappedGraphs/graphviews.jl +++ b/src/wrappedGraphs/graphviews.jl @@ -1,7 +1,7 @@ """ ReverseView{T<:Integer,G<:AbstractGraph} <: AbstractGraph{T} -A wrapper on a graph that reverse the direction of every edge. +A graph view that wraps a directed graph and reverse the direction of every edge. # Examples ```jldoctest @@ -50,7 +50,7 @@ Graphs.outneighbors(g::ReverseView, v) = Graphs.inneighbors(g.g, v) """ UndirectedView{T<:Integer,G<:AbstractGraph} <: AbstractGraph{T} -A wrapper on a graph that consider every edge as undirected. +A graph view that wraps a directed graph and consider every edge as undirected. # Examples ```jldoctest From c5627ad50c4a2456eaf203521a2ea22bb8aea134 Mon Sep 17 00:00:00 2001 From: etienneINSA Date: Wed, 8 May 2024 19:01:31 +0200 Subject: [PATCH 08/12] fix doctests --- src/wrappedGraphs/graphviews.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wrappedGraphs/graphviews.jl b/src/wrappedGraphs/graphviews.jl index b0605bef0..d8f64ce01 100644 --- a/src/wrappedGraphs/graphviews.jl +++ b/src/wrappedGraphs/graphviews.jl @@ -7,11 +7,11 @@ A graph view that wraps a directed graph and reverse the direction of every edge ```jldoctest julia> using Graphs -julia> g = SimpleDiGraph(2) +julia> g = SimpleDiGraph(2); -julia> add_edge!(g, 1, 2) +julia> add_edge!(g, 1, 2); -julia> rg = ReverseView(g) +julia> rg = ReverseView(g); julia> neighbors(rg, 1) Int64[] @@ -56,11 +56,11 @@ A graph view that wraps a directed graph and consider every edge as undirected. ```jldoctest julia> using Graphs -julia> g = SimpleDiGraph(2) +julia> g = SimpleDiGraph(2); -julia> add_edge!(g, 1, 2) +julia> add_edge!(g, 1, 2); -julia> ug = UndirectedView(g) +julia> ug = UndirectedView(g); julia> neighbors(ug, 1) 1-element Vector{Int64}: From 06b04cc57afb3ac6ae54be2b10876c717c143bdb Mon Sep 17 00:00:00 2001 From: etienneINSA Date: Wed, 8 May 2024 19:05:52 +0200 Subject: [PATCH 09/12] fix --- docs/src/core_functions/wrappedgraphs.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/src/core_functions/wrappedgraphs.md b/docs/src/core_functions/wrappedgraphs.md index a1290dc2c..e2c6a31fe 100644 --- a/docs/src/core_functions/wrappedgraphs.md +++ b/docs/src/core_functions/wrappedgraphs.md @@ -13,6 +13,7 @@ Pages = ["wrappedgraphs.md"] ## Full docs ```@autodocs +Modules = [Graphs] Pages = [ "wrappedgraphs/graphviews.jl", ] From fbad556f6fa26952975f4ff34eb3ab51cb6f49d6 Mon Sep 17 00:00:00 2001 From: etienneINSA Date: Thu, 9 May 2024 11:42:28 +0200 Subject: [PATCH 10/12] pleasing codecov --- src/Graphs.jl | 1 + src/wrappedGraphs/graphviews.jl | 12 ++- test/runtests.jl | 174 +++++++++++++++---------------- test/wrappedGraphs/graphviews.jl | 14 ++- 4 files changed, 110 insertions(+), 91 deletions(-) diff --git a/src/Graphs.jl b/src/Graphs.jl index 861be96a7..066aec806 100644 --- a/src/Graphs.jl +++ b/src/Graphs.jl @@ -124,6 +124,7 @@ export # wrapped graphs ReverseView, UndirectedView, + wrapped_graph, # simplegraphs add_edge!, diff --git a/src/wrappedGraphs/graphviews.jl b/src/wrappedGraphs/graphviews.jl index d8f64ce01..ea679814d 100644 --- a/src/wrappedGraphs/graphviews.jl +++ b/src/wrappedGraphs/graphviews.jl @@ -27,7 +27,7 @@ struct ReverseView{T<:Integer,G<:AbstractGraph} <: AbstractGraph{T} @traitfn ReverseView{T,G}(g::::(IsDirected)) where {T<:Integer,G<:AbstractGraph{T}} = new(g) @traitfn ReverseView{T,G}(g::::(!IsDirected)) where {T<:Integer,G<:AbstractGraph{T}} = - "Your graph needs to be directed" + throw(ArgumentError("Your graph needs to be directed")) end ReverseView(g::G) where {T<:Integer,G<:AbstractGraph{T}} = ReverseView{T,G}(g) @@ -83,11 +83,19 @@ struct UndirectedView{T<:Integer,G<:AbstractGraph} <: AbstractGraph{T} @traitfn UndirectedView{T,G}( g::::(!IsDirected) - ) where {T<:Integer,G<:AbstractGraph{T}} = error("Your graph need to be directed") + ) where {T<:Integer,G<:AbstractGraph{T}} = + throw(ArgumentError("Your graph needs to be directed")) end UndirectedView(g::G) where {T<:Integer,G<:AbstractGraph{T}} = UndirectedView{T,G}(g) +""" + wrapped_graph(g) + +Return the graph wrapped by `g` +""" +function wrapped_graph end + wrapped_graph(g::UndirectedView) = g.g Graphs.is_directed(::UndirectedView) = false diff --git a/test/runtests.jl b/test/runtests.jl index ccd97cb96..4694feb33 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -73,100 +73,100 @@ function test_large_generic_graphs(g; skip_if_too_large::Bool=false) end tests = [ - "simplegraphs/runtests", - "linalg/runtests", - "parallel/runtests", - "interface", - "core", - "operators", + # "simplegraphs/runtests", + # "linalg/runtests", + # "parallel/runtests", + # "interface", + # "core", + # "operators", "wrappedGraphs/graphviews", - "degeneracy", - "distance", - "digraph/transitivity", - "cycles/hawick-james", - "cycles/johnson", - "cycles/karp", - "cycles/basis", - "cycles/limited_length", - "cycles/incremental", - "edit_distance", - "connectivity", - "persistence/persistence", - "shortestpaths/utils", - "shortestpaths/astar", - "shortestpaths/bellman-ford", - "shortestpaths/desopo-pape", - "shortestpaths/dijkstra", - "shortestpaths/johnson", - "shortestpaths/floyd-warshall", - "shortestpaths/yen", - "shortestpaths/spfa", - "shortestpaths/longest_path", - "traversals/bfs", - "traversals/bipartition", - "traversals/greedy_color", - "traversals/dfs", - "traversals/maxadjvisit", - "traversals/randomwalks", - "traversals/diffusion", - "traversals/eulerian", - "traversals/all_simple_paths", - "community/cliques", - "community/core-periphery", - "community/label_propagation", - "community/modularity", - "community/clustering", - "community/clique_percolation", - "community/assortativity", - "community/rich_club", - "centrality/betweenness", - "centrality/closeness", - "centrality/degree", - "centrality/katz", - "centrality/pagerank", - "centrality/eigenvector", - "centrality/stress", - "centrality/radiality", - "utils", - "deprecations", - "spanningtrees/boruvka", - "spanningtrees/kruskal", - "spanningtrees/prim", - "steinertree/steiner_tree", - "biconnectivity/articulation", - "biconnectivity/biconnect", - "biconnectivity/bridge", - "graphcut/normalized_cut", - "graphcut/karger_min_cut", - "dominatingset/degree_dom_set", - "dominatingset/minimal_dom_set", - "independentset/degree_ind_set", - "independentset/maximal_ind_set", - "vertexcover/degree_vertex_cover", - "vertexcover/random_vertex_cover", - "trees/prufer", - "experimental/experimental", + # "degeneracy", + # "distance", + # "digraph/transitivity", + # "cycles/hawick-james", + # "cycles/johnson", + # "cycles/karp", + # "cycles/basis", + # "cycles/limited_length", + # "cycles/incremental", + # "edit_distance", + # "connectivity", + # "persistence/persistence", + # "shortestpaths/utils", + # "shortestpaths/astar", + # "shortestpaths/bellman-ford", + # "shortestpaths/desopo-pape", + # "shortestpaths/dijkstra", + # "shortestpaths/johnson", + # "shortestpaths/floyd-warshall", + # "shortestpaths/yen", + # "shortestpaths/spfa", + # "shortestpaths/longest_path", + # "traversals/bfs", + # "traversals/bipartition", + # "traversals/greedy_color", + # "traversals/dfs", + # "traversals/maxadjvisit", + # "traversals/randomwalks", + # "traversals/diffusion", + # "traversals/eulerian", + # "traversals/all_simple_paths", + # "community/cliques", + # "community/core-periphery", + # "community/label_propagation", + # "community/modularity", + # "community/clustering", + # "community/clique_percolation", + # "community/assortativity", + # "community/rich_club", + # "centrality/betweenness", + # "centrality/closeness", + # "centrality/degree", + # "centrality/katz", + # "centrality/pagerank", + # "centrality/eigenvector", + # "centrality/stress", + # "centrality/radiality", + # "utils", + # "deprecations", + # "spanningtrees/boruvka", + # "spanningtrees/kruskal", + # "spanningtrees/prim", + # "steinertree/steiner_tree", + # "biconnectivity/articulation", + # "biconnectivity/biconnect", + # "biconnectivity/bridge", + # "graphcut/normalized_cut", + # "graphcut/karger_min_cut", + # "dominatingset/degree_dom_set", + # "dominatingset/minimal_dom_set", + # "independentset/degree_ind_set", + # "independentset/maximal_ind_set", + # "vertexcover/degree_vertex_cover", + # "vertexcover/random_vertex_cover", + # "trees/prufer", + # "experimental/experimental", ] @testset verbose = true "Graphs" begin - @testset "Code quality (JET.jl)" begin - if VERSION >= v"1.9" - @assert get_pkg_version("JET") >= v"0.8.4" - JET.test_package( - Graphs; target_defined_modules=true, ignore_missing_comparison=true - ) - end - end + # @testset "Code quality (JET.jl)" begin + # if VERSION >= v"1.9" + # @assert get_pkg_version("JET") >= v"0.8.4" + # JET.test_package( + # Graphs; target_defined_modules=true, ignore_missing_comparison=true + # ) + # end + # end - @testset "Code quality (Aqua.jl)" begin - Aqua.test_all(Graphs; ambiguities=false) - end + # @testset "Code quality (Aqua.jl)" begin + # Aqua.test_all(Graphs; ambiguities=false) + # end - @testset "Code formatting (JuliaFormatter.jl)" begin - @test format(Graphs; verbose=false, overwrite=false) - end + # @testset "Code formatting (JuliaFormatter.jl)" begin + # @test format(Graphs; verbose=false, overwrite=false) + # end - doctest(Graphs) + # doctest(Graphs) @testset verbose = true "Actual tests" begin for t in tests diff --git a/test/wrappedGraphs/graphviews.jl b/test/wrappedGraphs/graphviews.jl index 977fd502a..9c562f22f 100644 --- a/test/wrappedGraphs/graphviews.jl +++ b/test/wrappedGraphs/graphviews.jl @@ -20,10 +20,13 @@ add_edge!(allocated_rg, Edge(dst(e), src(e))) end - @test eltype(rg) == eltype(g) + @test wrapped_graph(rg) == g @test is_directed(rg) == true + @test eltype(rg) == eltype(g) + @test has_vertex(rg, 4) == has_vertex(g, 4) @test nv(rg) == nv(g) == nv(allocated_rg) @test ne(rg) == ne(g) == ne(allocated_rg) + @test all(adjacency_matrix(rg) .== adjacency_matrix(allocated_rg)) @test sort(collect(inneighbors(rg, 2))) == sort(collect(inneighbors(allocated_rg, 2))) @test sort(collect(outneighbors(rg, 2))) == @@ -42,6 +45,8 @@ @test length(rg_res) == length(allocated_rg_res) @test sort(length.(rg_res)) == sort(length.(allocated_rg_res)) end + + @test_throws ArgumentError ReverseView(path_graph(5)) end @testset "UndirectedView" begin @@ -67,10 +72,13 @@ ug = UndirectedView(g) allocated_ug = Graph(g) - @test eltype(ug) == eltype(g) + @test wrapped_graph(ug) == g @test is_directed(ug) == false + @test eltype(ug) == eltype(g) + @test has_vertex(ug, 4) == has_vertex(g, 4) @test nv(ug) == nv(g) == nv(allocated_ug) @test ne(ug) == ne(allocated_ug) + @test all(adjacency_matrix(ug) .== adjacency_matrix(allocated_ug)) @test sort(collect(inneighbors(ug, 2))) == sort(collect(inneighbors(allocated_ug, 2))) @test sort(collect(outneighbors(ug, 2))) == @@ -89,5 +97,7 @@ @test length(ug_res) == length(allocated_ug_res) @test sort(length.(ug_res)) == sort(length.(allocated_ug_res)) end + + @test_throws ArgumentError UndirectedView(path_graph(5)) end end From 995e07522c07fbd818ba10b5863e693a442df1ac Mon Sep 17 00:00:00 2001 From: etienneINSA Date: Thu, 9 May 2024 11:47:54 +0200 Subject: [PATCH 11/12] oups --- test/runtests.jl | 174 +++++++++++++++++++++++------------------------ 1 file changed, 87 insertions(+), 87 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 4694feb33..ccd97cb96 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -73,100 +73,100 @@ function test_large_generic_graphs(g; skip_if_too_large::Bool=false) end tests = [ - # "simplegraphs/runtests", - # "linalg/runtests", - # "parallel/runtests", - # "interface", - # "core", - # "operators", + "simplegraphs/runtests", + "linalg/runtests", + "parallel/runtests", + "interface", + "core", + "operators", "wrappedGraphs/graphviews", - # "degeneracy", - # "distance", - # "digraph/transitivity", - # "cycles/hawick-james", - # "cycles/johnson", - # "cycles/karp", - # "cycles/basis", - # "cycles/limited_length", - # "cycles/incremental", - # "edit_distance", - # "connectivity", - # "persistence/persistence", - # "shortestpaths/utils", - # "shortestpaths/astar", - # "shortestpaths/bellman-ford", - # "shortestpaths/desopo-pape", - # "shortestpaths/dijkstra", - # "shortestpaths/johnson", - # "shortestpaths/floyd-warshall", - # "shortestpaths/yen", - # "shortestpaths/spfa", - # "shortestpaths/longest_path", - # "traversals/bfs", - # "traversals/bipartition", - # "traversals/greedy_color", - # "traversals/dfs", - # "traversals/maxadjvisit", - # "traversals/randomwalks", - # "traversals/diffusion", - # "traversals/eulerian", - # "traversals/all_simple_paths", - # "community/cliques", - # "community/core-periphery", - # "community/label_propagation", - # "community/modularity", - # "community/clustering", - # "community/clique_percolation", - # "community/assortativity", - # "community/rich_club", - # "centrality/betweenness", - # "centrality/closeness", - # "centrality/degree", - # "centrality/katz", - # "centrality/pagerank", - # "centrality/eigenvector", - # "centrality/stress", - # "centrality/radiality", - # "utils", - # "deprecations", - # "spanningtrees/boruvka", - # "spanningtrees/kruskal", - # "spanningtrees/prim", - # "steinertree/steiner_tree", - # "biconnectivity/articulation", - # "biconnectivity/biconnect", - # "biconnectivity/bridge", - # "graphcut/normalized_cut", - # "graphcut/karger_min_cut", - # "dominatingset/degree_dom_set", - # "dominatingset/minimal_dom_set", - # "independentset/degree_ind_set", - # "independentset/maximal_ind_set", - # "vertexcover/degree_vertex_cover", - # "vertexcover/random_vertex_cover", - # "trees/prufer", - # "experimental/experimental", + "degeneracy", + "distance", + "digraph/transitivity", + "cycles/hawick-james", + "cycles/johnson", + "cycles/karp", + "cycles/basis", + "cycles/limited_length", + "cycles/incremental", + "edit_distance", + "connectivity", + "persistence/persistence", + "shortestpaths/utils", + "shortestpaths/astar", + "shortestpaths/bellman-ford", + "shortestpaths/desopo-pape", + "shortestpaths/dijkstra", + "shortestpaths/johnson", + "shortestpaths/floyd-warshall", + "shortestpaths/yen", + "shortestpaths/spfa", + "shortestpaths/longest_path", + "traversals/bfs", + "traversals/bipartition", + "traversals/greedy_color", + "traversals/dfs", + "traversals/maxadjvisit", + "traversals/randomwalks", + "traversals/diffusion", + "traversals/eulerian", + "traversals/all_simple_paths", + "community/cliques", + "community/core-periphery", + "community/label_propagation", + "community/modularity", + "community/clustering", + "community/clique_percolation", + "community/assortativity", + "community/rich_club", + "centrality/betweenness", + "centrality/closeness", + "centrality/degree", + "centrality/katz", + "centrality/pagerank", + "centrality/eigenvector", + "centrality/stress", + "centrality/radiality", + "utils", + "deprecations", + "spanningtrees/boruvka", + "spanningtrees/kruskal", + "spanningtrees/prim", + "steinertree/steiner_tree", + "biconnectivity/articulation", + "biconnectivity/biconnect", + "biconnectivity/bridge", + "graphcut/normalized_cut", + "graphcut/karger_min_cut", + "dominatingset/degree_dom_set", + "dominatingset/minimal_dom_set", + "independentset/degree_ind_set", + "independentset/maximal_ind_set", + "vertexcover/degree_vertex_cover", + "vertexcover/random_vertex_cover", + "trees/prufer", + "experimental/experimental", ] @testset verbose = true "Graphs" begin - # @testset "Code quality (JET.jl)" begin - # if VERSION >= v"1.9" - # @assert get_pkg_version("JET") >= v"0.8.4" - # JET.test_package( - # Graphs; target_defined_modules=true, ignore_missing_comparison=true - # ) - # end - # end + @testset "Code quality (JET.jl)" begin + if VERSION >= v"1.9" + @assert get_pkg_version("JET") >= v"0.8.4" + JET.test_package( + Graphs; target_defined_modules=true, ignore_missing_comparison=true + ) + end + end - # @testset "Code quality (Aqua.jl)" begin - # Aqua.test_all(Graphs; ambiguities=false) - # end + @testset "Code quality (Aqua.jl)" begin + Aqua.test_all(Graphs; ambiguities=false) + end - # @testset "Code formatting (JuliaFormatter.jl)" begin - # @test format(Graphs; verbose=false, overwrite=false) - # end + @testset "Code formatting (JuliaFormatter.jl)" begin + @test format(Graphs; verbose=false, overwrite=false) + end - # doctest(Graphs) + doctest(Graphs) @testset verbose = true "Actual tests" begin for t in tests From 24f255bc7f6689c4aae3ac8cc1d9d28732a606ba Mon Sep 17 00:00:00 2001 From: etienneINSA Date: Thu, 9 May 2024 12:11:12 +0200 Subject: [PATCH 12/12] switch to floyd warshall to reach edges --- test/wrappedGraphs/graphviews.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/wrappedGraphs/graphviews.jl b/test/wrappedGraphs/graphviews.jl index 9c562f22f..d03b2ec8a 100644 --- a/test/wrappedGraphs/graphviews.jl +++ b/test/wrappedGraphs/graphviews.jl @@ -23,6 +23,7 @@ @test wrapped_graph(rg) == g @test is_directed(rg) == true @test eltype(rg) == eltype(g) + @test edgetype(rg) == edgetype(g) @test has_vertex(rg, 4) == has_vertex(g, 4) @test nv(rg) == nv(g) == nv(allocated_rg) @test ne(rg) == ne(g) == ne(allocated_rg) @@ -36,8 +37,8 @@ @test has_edge(rg, 1, 3) == has_edge(allocated_rg, 1, 3) @test has_edge(rg, 1, 4) == has_edge(allocated_rg, 1, 4) - rg_res = @inferred(dijkstra_shortest_paths(rg, 3)) - allocated_rg_res = dijkstra_shortest_paths(allocated_rg, 3) + rg_res = @inferred(floyd_warshall_shortest_paths(rg)) + allocated_rg_res = floyd_warshall_shortest_paths(allocated_rg) @test rg_res.dists == allocated_rg_res.dists # parents may not be the same rg_res = @inferred(strongly_connected_components(rg)) @@ -75,6 +76,7 @@ @test wrapped_graph(ug) == g @test is_directed(ug) == false @test eltype(ug) == eltype(g) + @test edgetype(ug) == edgetype(g) @test has_vertex(ug, 4) == has_vertex(g, 4) @test nv(ug) == nv(g) == nv(allocated_ug) @test ne(ug) == ne(allocated_ug) @@ -88,8 +90,8 @@ @test has_edge(ug, 1, 3) == has_edge(allocated_ug, 1, 3) @test has_edge(ug, 1, 4) == has_edge(allocated_ug, 1, 4) - ug_res = @inferred(dijkstra_shortest_paths(ug, 3)) - allocated_ug_res = dijkstra_shortest_paths(allocated_ug, 3) + ug_res = @inferred(floyd_warshall_shortest_paths(ug)) + allocated_ug_res = floyd_warshall_shortest_paths(allocated_ug) @test ug_res.dists == allocated_ug_res.dists # parents may not be the same ug_res = @inferred(biconnected_components(ug))