diff --git a/docs/src/reference.md b/docs/src/reference.md index d7f915a..329bf75 100644 --- a/docs/src/reference.md +++ b/docs/src/reference.md @@ -75,6 +75,8 @@ nhe(::Hypergraph) getvertices(::Hypergraph, ::Int) gethyperedges(::Hypergraph, ::Int) get_connected_components(::Hypergraph) +getneighbours(::Hypergraph, ::Int) +hellyprop(::Hypergraph) modularity(::Hypergraph, ::Vector{Set{Int}}, ::SimpleHypergraphs.HypergraphAggs) random_walk(::Hypergraph, ::Int; heselect::Function, vselect::Function) diff --git a/src/hypergraph.jl b/src/hypergraph.jl index 2eb7dc5..c2549e9 100644 --- a/src/hypergraph.jl +++ b/src/hypergraph.jl @@ -421,5 +421,38 @@ function get_connected_components(h::Hypergraph) cc end +""" + getneighbours(h::Hypergraph, v::Int) +Return a set of vertices which are neighbours to vertex `v` in hypergraph `h` +(i.e. are located on the same edge). +""" +function getneighbours(h::Hypergraph,v::Int) + cc = Set{Int}() + for he in keys(gethyperedges(h,v)) + union!(cc,Set(keys(getvertices(h,he)))) + end + delete!(cc,v) +end + +""" + hellyprop(h::Hypergraph) +Return logical value depending on whether the hypergraph `h` has the Helly property. +""" +function hellyprop(h::Hypergraph) + helly = [] + for x in 1:nhv(h) + for y in 1:nhv(h) + x == y && continue + for v in intersect(getneighbours(h,x), getneighbours(h,y)) + isempty(v) && continue + xyv = [keys(intersect(gethyperedges(h,i[1]), gethyperedges(h,i[2]))) for i = [[x,y],[y,v],[x,v]]] + X = intersect(xyv[1],xyv[2],xyv[3]) + append!(helly, !isempty(X)) + end + end + end + all(helly) +end + # TODO find connected components without recurrence # TODO needs validate_hypergraph!(h::Hypergraph{T}) diff --git a/test/runtests.jl b/test/runtests.jl index 5ace696..40b2ae7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -349,6 +349,11 @@ end @test typeof(cc2) == Vector{Vector{Int}} end +@testset "SimpleHypergraphs helly property" begin + getneighbours(h1,1) == Set([2,3]) + hellyprop(h1) == false +end + @testset "SimpleHypergraphs hypernetx bridge" begin if (!SimpleHypergraphs.support_hypernetx)