Well, it looks like we have two questions. There is one question in the title of the question: "How to find the identifier of the vertices if we have the Vertex object"? Siddhart answered correctly: you can simply use the index property for the top. Another question is in the question: "I want to add a line between a and b, how should I go?" The answer is simply to use the add_edge method, which accepts Vertex objects as well as vertex identifiers:
g.add_edge(a, b)
Here I suggested that a and b are objects of type Vertex . However, judging by your code snippet, you essentially want to do is add a border between the two vertices for which you know the names. You can also do this using the find method of VertexSeq objects, which works the way you do, but returns only the first vertex that VertexSeq . So you can simply:
g.add_edge(g.vs.find(Name="A"), g.vs.find(Name="B"))
Even better, if you use the name vertex attribute to store vertex names (rather than name - pay attention to the capital letter), you can even use the name itself without calling g.vs.find , since igraph considers the name vertex attribute:
g.add_edge("A", "B")
source share