diff --git a/Project.toml b/Project.toml index 32c9c56..fbd005e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "NestedGraphs" uuid = "03c36417-ddab-428a-818d-5359aee292ef" authors = ["fchrstou and contributors"] -version = "0.2" +version = "0.2.1" [deps] AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" @@ -22,7 +22,7 @@ AbstractTrees = "0.4" DocStringExtensions = "0.9" Graphs = "1" MetaGraphs = "0.7" -AttributeGraphs = "0.2" +AttributeGraphs = "0.3" SimpleTraits = "0.9" julia = "1.9" diff --git a/ext/NestedGraphsAttributeGraphsExt.jl b/ext/NestedGraphsAttributeGraphsExt.jl index 8e7754a..39a112e 100644 --- a/ext/NestedGraphsAttributeGraphsExt.jl +++ b/ext/NestedGraphsAttributeGraphsExt.jl @@ -3,18 +3,18 @@ module NestedGraphsAttributeGraphsExt using NestedGraphs, Graphs, DocStringExtensions using AttributeGraphs -import AttributeGraphs: AbstractAttibuteGraph, addgraphattr!, remgraphattr!, addvertexattr!, remvertexattr!, addedgeattr!, remedgeattr!, graph_attr, vertex_attr, edge_attr, addvertex!, remvertex!, addedge!, remedge!, hasedgeattr, hasgraphattr, hasvertexattr, getgraphattr, getvertexattr, getedgeattr +import AttributeGraphs: AbstractAttributeGraph, addgraphattr!, remgraphattr!, addvertexattr!, remvertexattr!, addedgeattr!, remedgeattr!, graph_attr, vertex_attr, edge_attr, addvertex!, remvertex!, addedge!, remedge!, hasedgeattr, hasgraphattr, hasvertexattr, getgraphattr, getvertexattr, getedgeattr -getgraphattr(ag::NestedGraph{T,G}, k) where {T<:Integer,G<:AbstractAttibuteGraph} = getgraphattr(NestedGraphs.getgraph(ag), k) -getvertexattr(ag::NestedGraph{T,G}, k) where {T<:Integer,G<:AbstractAttibuteGraph} = getvertexattr(NestedGraphs.getgraph(ag), k) -getedgeattr(ag::NestedGraph{T,G}, args...) where {T<:Integer,G<:AbstractAttibuteGraph} = getedgeattr(NestedGraphs.getgraph(ag), args...) +getgraphattr(ag::NestedGraph{T,G}, k) where {T<:Integer,G<:AbstractAttributeGraph} = getgraphattr(NestedGraphs.getgraph(ag), k) +getvertexattr(ag::NestedGraph{T,G}, k) where {T<:Integer,G<:AbstractAttributeGraph} = getvertexattr(NestedGraphs.getgraph(ag), k) +getedgeattr(ag::NestedGraph{T,G}, args...) where {T<:Integer,G<:AbstractAttributeGraph} = getedgeattr(NestedGraphs.getgraph(ag), args...) -hasgraphattr(ag::NestedGraph{T,G}, k) where {T<:Integer,G<:AbstractAttibuteGraph} = hasgraphattr(NestedGraphs.getgraph(ag), k) -hasvertexattr(ag::NestedGraph{T,G}, k) where {T<:Integer,G<:AbstractAttibuteGraph} = hasvertexattr(NestedGraphs.getgraph(ag), k) -hasedgeattr(ag::NestedGraph{T,G}, args...) where {T<:Integer,G<:AbstractAttibuteGraph} = hasedgeattr(NestedGraphs.getgraph(ag), args...) +hasgraphattr(ag::NestedGraph{T,G}, k) where {T<:Integer,G<:AbstractAttributeGraph} = hasgraphattr(NestedGraphs.getgraph(ag), k) +hasvertexattr(ag::NestedGraph{T,G}, k) where {T<:Integer,G<:AbstractAttributeGraph} = hasvertexattr(NestedGraphs.getgraph(ag), k) +hasedgeattr(ag::NestedGraph{T,G}, args...) where {T<:Integer,G<:AbstractAttributeGraph} = hasedgeattr(NestedGraphs.getgraph(ag), args...) -function addvertex!(ng::NestedGraph{T,G}; subgraphs=1) where {T<:Integer, G<:AbstractAttibuteGraph} +function addvertex!(ng::NestedGraph{T,G}; subgraphs=1) where {T<:Integer, G<:AbstractAttributeGraph} subgraph = first(subgraphs) length(ng.grv) == 0 && (add_vertex!(ng, G())) targetnode = nv(ng.grv[subgraph])+1 @@ -24,7 +24,7 @@ function addvertex!(ng::NestedGraph{T,G}; subgraphs=1) where {T<:Integer, G<:Abs NestedGraphs._propagate_to_nested(ng, addvertex!, subgraphs) end -function remvertex!(ng::NestedGraph{T,G}, v::T) where {T<:Integer, G<:AbstractAttibuteGraph} +function remvertex!(ng::NestedGraph{T,G}, v::T) where {T<:Integer, G<:AbstractAttributeGraph} Graphs.has_vertex(ng, v) || return false remvertex!(ng.flatgr, v) nver = ng.vmap[v] @@ -33,9 +33,9 @@ function remvertex!(ng::NestedGraph{T,G}, v::T) where {T<:Integer, G<:AbstractAt NestedGraphs.update_vmapneds_after_delete!(ng, nver) end -addedge!(mg::NestedGraph{T,G}, args...) where {T<:Integer, G<:AbstractAttibuteGraph} = add_edge!(mg, args...) +addedge!(mg::NestedGraph{T,G}, args...) where {T<:Integer, G<:AbstractAttributeGraph} = add_edge!(mg, args...) -function remedge!(ng::NestedGraph{T,G}, src::T, dst::T) where {T<:Integer, G<:AbstractAttibuteGraph} +function remedge!(ng::NestedGraph{T,G}, src::T, dst::T) where {T<:Integer, G<:AbstractAttributeGraph} Graphs.has_edge(ng, src, dst) || return false remedge!(ng.flatgr, src, dst) srctup = ng.vmap[src] @@ -47,37 +47,37 @@ function remedge!(ng::NestedGraph{T,G}, src::T, dst::T) where {T<:Integer, G<:Ab end end -addgraphattr!(ng::NestedGraph{T,G}, k, v) where {T<:Integer, G<:AbstractAttibuteGraph} = addgraphattr!(NestedGraphs.getgraph(ng), k, v) -remgraphattr!(ng::NestedGraph{T,G}, k) where {T<:Integer, G<:AbstractAttibuteGraph} = remgraphattr!(NestedGraphs.getgraph(ng), k) +addgraphattr!(ng::NestedGraph{T,G}, k, v) where {T<:Integer, G<:AbstractAttributeGraph} = addgraphattr!(NestedGraphs.getgraph(ng), k, v) +remgraphattr!(ng::NestedGraph{T,G}, k) where {T<:Integer, G<:AbstractAttributeGraph} = remgraphattr!(NestedGraphs.getgraph(ng), k) -function addvertexattr!(ng::NestedGraph{T,G}, k, v) where {T<:Integer, G<:AbstractAttibuteGraph} +function addvertexattr!(ng::NestedGraph{T,G}, k, v) where {T<:Integer, G<:AbstractAttributeGraph} addvertexattr!(NestedGraphs.getgraph(ng), k, v) addvertexattr!(ng.grv[ng.vmap[k][1]], ng.vmap[k][2], v) end -function remvertexattr!(ng::NestedGraph{T,G}, k) where {T<:Integer, G<:AbstractAttibuteGraph} +function remvertexattr!(ng::NestedGraph{T,G}, k) where {T<:Integer, G<:AbstractAttributeGraph} remvertexattr!(NestedGraphs.getgraph(ng), k) remvertexattr!(ng.grv[ng.vmap[k][1]], ng.vmap[k][2]) end -remedgeattr!(ng::NestedGraph{T,G}, e::AbstractEdge, args...) where {T<:Integer, G<:AbstractAttibuteGraph} = remedgeattr!(ng, src(e), dst(e), args...) -function remedgeattr!(ng::NestedGraph{T,G}, s::T, d::T, args...) where {T<:Integer, G<:AbstractAttibuteGraph} +remedgeattr!(ng::NestedGraph{T,G}, e::AbstractEdge, args...) where {T<:Integer, G<:AbstractAttributeGraph} = remedgeattr!(ng, src(e), dst(e), args...) +function remedgeattr!(ng::NestedGraph{T,G}, s::T, d::T, args...) where {T<:Integer, G<:AbstractAttributeGraph} remedgeattr!(NestedGraphs.getgraph(ng), s, d, args...) if NestedGraphs.issamesubgraph(ng, s, d) remedgeattr!(ng.grv[ng.vmap[s][1]], ng.vmap[s][2], ng.vmap[d][2], args...) end end -addedgeattr!(ng::NestedGraph{T,G}, e::AbstractEdge, args...) where {T<:Integer, G<:AbstractAttibuteGraph} = addedgeattr!(ng, src(e), dst(e), args...) -function addedgeattr!(ng::NestedGraph{T,G}, s::T, d::T, args...) where {T<:Integer, G<:AbstractAttibuteGraph} +addedgeattr!(ng::NestedGraph{T,G}, e::AbstractEdge, args...) where {T<:Integer, G<:AbstractAttributeGraph} = addedgeattr!(ng, src(e), dst(e), args...) +function addedgeattr!(ng::NestedGraph{T,G}, s::T, d::T, args...) where {T<:Integer, G<:AbstractAttributeGraph} addedgeattr!(NestedGraphs.getgraph(ng), s, d, args...) if NestedGraphs.issamesubgraph(ng, s, d) addedgeattr!(ng.grv[ng.vmap[s][1]], ng.vmap[s][2], ng.vmap[d][2], args...) end end -vertex_attr(mg::NestedGraph{T,G}) where {T<:Integer, G<:AbstractAttibuteGraph} = vertex_attr(NestedGraphs.getgraph(mg)) -edge_attr(mg::NestedGraph{T,G}) where {T<:Integer, G<:AbstractAttibuteGraph} = edge_attr(NestedGraphs.getgraph(mg)) -graph_attr(mg::NestedGraph{T,G}) where {T<:Integer, G<:AbstractAttibuteGraph} = graph_attr(NestedGraphs.getgraph(mg)) +vertex_attr(mg::NestedGraph{T,G}) where {T<:Integer, G<:AbstractAttributeGraph} = vertex_attr(NestedGraphs.getgraph(mg)) +edge_attr(mg::NestedGraph{T,G}) where {T<:Integer, G<:AbstractAttributeGraph} = edge_attr(NestedGraphs.getgraph(mg)) +graph_attr(mg::NestedGraph{T,G}) where {T<:Integer, G<:AbstractAttributeGraph} = graph_attr(NestedGraphs.getgraph(mg)) # I need to implement shallow copy function NestedGraphs.shallowcopy_vertices!(g1::AttributeGraph{T,G,V}, g2::AttributeGraph{T,G,V}) where {T<:Integer,G<:AbstractGraph{T},V<:AbstractVector} @@ -102,7 +102,7 @@ end # multilayer.jl -function getsquashedgraph(ng::NestedGraph{T,R,N}, sqvertices::Vector{Vector{Q}}) where {T,R<:AbstractAttibuteGraph,N,Q<:Integer} +function getsquashedgraph(ng::NestedGraph{T,R,N}, sqvertices::Vector{Vector{Q}}) where {T,R<:AbstractAttributeGraph,N,Q<:Integer} # squashedgraph = ng.flatgr |> deepcopy |> adjacency_matrix |> SimpleGraph squashedgraph = getsimplegraphcopy(ng) _rec_merge_vertices!(SimpleGraph(squashedgraph), sqvertices) diff --git a/src/attributegraphs.jl b/src/attributegraphs.jl deleted file mode 100644 index 5a45278..0000000 --- a/src/attributegraphs.jl +++ /dev/null @@ -1,94 +0,0 @@ -getgraphattr(ag::NestedGraph{T,G}, k) where {T<:Integer,G<:AbstractAttibuteGraph} = getgraphattr(graph(ag), k) -getvertexattr(ag::NestedGraph{T,G}, k) where {T<:Integer,G<:AbstractAttibuteGraph} = getvertexattr(graph(ag), k) -getedgeattr(ag::NestedGraph{T,G}, args...) where {T<:Integer,G<:AbstractAttibuteGraph} = getedgeattr(graph(ag), args...) - -hasgraphattr(ag::NestedGraph{T,G}, k) where {T<:Integer,G<:AbstractAttibuteGraph} = hasgraphattr(graph(ag), k) -hasvertexattr(ag::NestedGraph{T,G}, k) where {T<:Integer,G<:AbstractAttibuteGraph} = hasvertexattr(graph(ag), k) -hasedgeattr(ag::NestedGraph{T,G}, args...) where {T<:Integer,G<:AbstractAttibuteGraph} = hasedgeattr(graph(ag), args...) - - -function addvertex!(ng::NestedGraph{T,G}; subgraphs=1) where {T<:Integer, G<:AbstractAttibuteGraph} - subgraph = first(subgraphs) - length(ng.grv) == 0 && (add_vertex!(ng, G())) - targetnode = nv(ng.grv[subgraph])+1 - Graphs.has_vertex(ng, subgraph, targetnode) && return false - addvertex!(ng.flatgr) - push!(ng.vmap, (subgraph, targetnode) ) - _propagate_to_nested(ng, addvertex!, subgraphs) -end - -function remvertex!(ng::NestedGraph{T,G}, v::T) where {T<:Integer, G<:AbstractAttibuteGraph} - Graphs.has_vertex(ng, v) || return false - remvertex!(ng.flatgr, v) - nver = ng.vmap[v] - remvertex!(ng.grv[nver[1]], nver[2]) - deleteat!(ng.vmap, v) - update_vmapneds_after_delete!(ng, nver) -end - -addedge!(mg::NestedGraph{T,G}, args...) where {T<:Integer, G<:AbstractAttibuteGraph} = add_edge!(mg, args...) - -function remedge!(ng::NestedGraph{T,G}, src::T, dst::T) where {T<:Integer, G<:AbstractAttibuteGraph} - Graphs.has_edge(ng, src, dst) || return false - remedge!(ng.flatgr, src, dst) - srctup = ng.vmap[src] - dsttup = ng.vmap[dst] - if srctup[1] != dsttup[1] - deleteat!(ng.neds, findfirst(==(NestedEdge(srctup, dsttup)), ng.neds)) - else - remedge!(ng.grv[srctup[1]], srctup[2], dsttup[2]) - end -end - -addgraphattr!(ng::NestedGraph{T,G}, k, v) where {T<:Integer, G<:AbstractAttibuteGraph} = addgraphattr!(graph(ng), k, v) -remgraphattr!(ng::NestedGraph{T,G}, k) where {T<:Integer, G<:AbstractAttibuteGraph} = remgraphattr!(graph(ng), k) - -function addvertexattr!(ng::NestedGraph{T,G}, k, v) where {T<:Integer, G<:AbstractAttibuteGraph} - addvertexattr!(graph(ng), k, v) - addvertexattr!(ng.grv[ng.vmap[k][1]], ng.vmap[k][2], v) -end -function remvertexattr!(ng::NestedGraph{T,G}, k) where {T<:Integer, G<:AbstractAttibuteGraph} - remvertexattr!(graph(ng), k) - remvertexattr!(ng.grv[ng.vmap[k][1]], ng.vmap[k][2]) -end - -remedgeattr!(ng::NestedGraph{T,G}, e::AbstractEdge, args...) where {T<:Integer, G<:AbstractAttibuteGraph} = remedgeattr!(ng, src(e), dst(e), args...) -function remedgeattr!(ng::NestedGraph{T,G}, s::T, d::T, args...) where {T<:Integer, G<:AbstractAttibuteGraph} - remedgeattr!(graph(ng), s, d, args...) - if issamesubgraph(ng, s, d) - remedgeattr!(ng.grv[ng.vmap[s][1]], ng.vmap[s][2], ng.vmap[d][2], args...) - end -end - -addedgeattr!(ng::NestedGraph{T,G}, e::AbstractEdge, args...) where {T<:Integer, G<:AbstractAttibuteGraph} = addedgeattr!(ng, src(e), dst(e), args...) -function addedgeattr!(ng::NestedGraph{T,G}, s::T, d::T, args...) where {T<:Integer, G<:AbstractAttibuteGraph} - addedgeattr!(graph(ng), s, d, args...) - if issamesubgraph(ng, s, d) - addedgeattr!(ng.grv[ng.vmap[s][1]], ng.vmap[s][2], ng.vmap[d][2], args...) - end -end - -vertex_attr(mg::NestedGraph{T,G}) where {T<:Integer, G<:AbstractAttibuteGraph} = vertex_attr(graph(mg)) -edge_attr(mg::NestedGraph{T,G}) where {T<:Integer, G<:AbstractAttibuteGraph} = edge_attr(graph(mg)) -graph_attr(mg::NestedGraph{T,G}) where {T<:Integer, G<:AbstractAttibuteGraph} = graph_attr(graph(mg)) - -# I need to implement shallow copy -function shallowcopy_vertices!(g1::AttributeGraph{T,G,V}, g2::AttributeGraph{T,G,V}) where {T<:Integer,G<:AbstractGraph{T},V<:AbstractVector} - for _ in vertices(g2) - add_vertex!(g1) - end - # todo shallow reference ? - for vatr in vertex_attr(g2) - push!(vertex_attr(g1), vatr) - end -end - -function shallowcopy_edges!(g1::AttributeGraph{T,G,V,E}, g2::AttributeGraph{T,G,V,E}, offset::Int) where {T<:Integer,G<:AbstractGraph{T},V,E<:AbstractDict} - for e in edges(g2) - add_edge!(g1, offset+src(e), offset+dst(e)) - end - # todo shallow reference ? - for (eatrkey,eatrval) in edge_attr(g2) - edge_attr(g1)[eatrkey] = eatrval - end -end diff --git a/test/Manifest.toml b/test/Manifest.toml index fa39098..12ac15a 100644 --- a/test/Manifest.toml +++ b/test/Manifest.toml @@ -1,6 +1,6 @@ # This file is machine-generated - editing it directly is not advised -julia_version = "1.9.0" +julia_version = "1.9.1" manifest_format = "2.0" project_hash = "4c10ced6dbf6a1004a10f82866da531e325c4d73" @@ -24,18 +24,18 @@ uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" [[deps.AttributeGraphs]] deps = ["DocStringExtensions", "Graphs"] -git-tree-sha1 = "35f8c0b552ad5ec872078db8c5cf61119b01671a" +git-tree-sha1 = "a92f0a56ce4faebcc8668d764a346be90bc5161f" uuid = "d091dd56-f8c5-469d-b7f7-ff847498145f" -version = "0.2.0" +version = "0.3.0" [[deps.Base64]] uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" [[deps.Compat]] deps = ["UUIDs"] -git-tree-sha1 = "7a60c856b9fa189eb34f5f8a6f6b5529b7942957" +git-tree-sha1 = "4e88377ae7ebeaf29a047aa1ee40826e0b708a5d" uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "4.6.1" +version = "4.7.0" weakdeps = ["Dates", "LinearAlgebra"] [deps.Compat.extensions] @@ -48,9 +48,9 @@ version = "1.0.2+0" [[deps.DataStructures]] deps = ["Compat", "InteractiveUtils", "OrderedCollections"] -git-tree-sha1 = "d1fff3a548102f48987a52a2e0d114fa97d730f0" +git-tree-sha1 = "cf25ccb972fec4e4817764d01c82386ae94f77b4" uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" -version = "0.18.13" +version = "0.18.14" [[deps.Dates]] deps = ["Printf"] @@ -302,7 +302,7 @@ version = "1.2.13+0" [[deps.libblastrampoline_jll]] deps = ["Artifacts", "Libdl"] uuid = "8e850b90-86db-534c-a0d3-1478176c7d93" -version = "5.7.0+0" +version = "5.8.0+0" [[deps.nghttp2_jll]] deps = ["Artifacts", "Libdl"]