Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

rem_vertex! key not found when adding edges #87

Open
Jademaster opened this issue Aug 27, 2019 · 0 comments
Open

rem_vertex! key not found when adding edges #87

Jademaster opened this issue Aug 27, 2019 · 0 comments

Comments

@Jademaster
Copy link

I am implementing a function merges two vertices of a MetaDiGraph and retains the current edges

using LightGraphs, MetaGraphs

function joinedge!(graph, v1, v2)
    add_vertex!(graph)
    v = nv(graph)
    for i in vcat(outneighbors(graph,v1),outneighbors(graph,v2))
        add_edge!(graph,v,i)
    end
    for i in vcat(inneighbors(graph,v1),inneighbors(graph,v2))
        add_edge!(graph,i,v)
    end
    rem_vertex!(graph, max(v1,v2))
    rem_vertex!(graph, min(v1,v2))
    graph
end

When I run this on for example a wheelgraph

g=wheel_digraph(10)
mg=MetaDiGraph(g)
joinedge(mg,2,3)

I get the following error

ERROR: LoadError: KeyError: key 3 not found

I am guessing that this is related to #21 because when I change my code to

function joinedge!(graph, v1, v2)
    add_vertex!(graph)
    v = nv(graph)
    for i in vcat(outneighbors(graph,v1),outneighbors(graph,v2))
        if !(i in (v1,v2))
            add_edge!(graph,v,i)
        end
    end
    for i in vcat(inneighbors(graph,v1),inneighbors(graph,v2))
        if !(i in (v1,v2))
            add_edge!(graph,i,v)
        end
    end
    rem_vertex!(graph, max(v1,v2))
    rem_vertex!(graph, min(v1,v2))
    graph
end

it works. The difference here is that I am no longer adding edges to the joined vertex which produce self-loops.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant