How to remove the vertex in Graphs or LightGraphs?

julia> myedges = [ 1 => 2,
         1 => 3,
        2 => 1,
        2 => 3,
        3 => 1,
        3 => 2,
        3 => 4,
        4 => 3,
        4 => 8,
        4 => 13,
       5 => 6,
        6 => 5,
         7 => 8,
        8 => 4,
         8 => 7,
         9 => 10,
        10 => 9,
        11 => 12,
        12 => 11,
        13 => 4,
        13 => 14,
        14 => 13]
julia> ed =Edge.(myedges)
22-element Vector{Graphs.SimpleGraphs.SimpleEdge{Int64}}:
 Edge 1 => 2
 Edge 1 => 3
 Edge 2 => 1
 Edge 2 => 3
 Edge 3 => 1
 Edge 3 => 2
 Edge 3 => 4
 Edge 4 => 3
 Edge 4 => 8
 Edge 4 => 13
 Edge 5 => 6
 Edge 6 => 5
 Edge 7 => 8
 Edge 8 => 4
 Edge 8 => 7
 Edge 9 => 10
 Edge 10 => 9
 Edge 11 => 12
 Edge 12 => 11
 Edge 13 => 4
 Edge 13 => 14
 Edge 14 => 13

julia> g = SimpleDiGraph(ed)
{14, 22} directed simple Int64 graph

lets remove vertex 2

julia> rem_vertex!(g, 2)
true

but i still see the vertex 2 in following edges


julia> collect(edges(g))
18-element Vector{Graphs.SimpleGraphs.SimpleEdge{Int64}}:
 Edge 1 => 3
 Edge 2 => 13
 Edge 3 => 1
 Edge 3 => 4
 Edge 4 => 3
 Edge 4 => 8
 Edge 4 => 13
 Edge 5 => 6
 Edge 6 => 5
 Edge 7 => 8
 Edge 8 => 4
 Edge 8 => 7
 Edge 9 => 10
 Edge 10 => 9
 Edge 11 => 12
 Edge 12 => 11
 Edge 13 => 2
 Edge 13 => 4

Why do i still see vertex 2 in the edges ? Shouldn’t all the edges involving vertex 2 be removed ?

Unfortunately, the LightGraphs documentation seems to be currently offline. I cannot remember how it was written there (but it was stated to be careful with this operation). I think the vertex to be removed is moved to the last index and then deleted (thus, vertex 14 is missing after deletion in your example). However, I cannot remember if simply vertex 2 and 14 are swapped, or if all vertices > 2 get a new index, i.e., i-1.

Getting Started · LightGraphs here is the documentation

Ok, then see the “Implementation Notes” here.