Discussion:
[igraph] Adding tuples as vertex names
Arjun Krishnan
2017-10-20 14:54:31 UTC
Permalink
Hi

I'm trying to make a regular 2 dimensional lattice using igraph's python
module. But I want to be able to refer to a vertex by its coordinates. So I
do the following:

g = Graph()
g.add_vertex(name=(0,0))
g.add_vertex(name=(1,0))
g.add_edge((0,0),(1,0))

But this results in an error

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-52-b1b5147f3828> in <module>()
----> 1 g.add_edge((0,0),(1,0))

/usr/lib/python3.6/site-packages/igraph/__init__.py in add_edge(self,
source, target, **kwds)
235 """
236 if not kwds:
--> 237 return self.add_edges([(source, target)])
238
239 eid = self.ecount()

/usr/lib/python3.6/site-packages/igraph/__init__.py in add_edges(self, es)
253 endpoints. Vertices are enumerated from zero.
254 """
--> 255 return GraphBase.add_edges(self, es)
256
257 def add_vertex(self, name=None, **kwds):

TypeError: only numbers, vertex names or igraph.Vertex objects can be
converted to vertex IDs

Does this mean that vertex names can only be strings? Is there an easier
way to make a lattice using

g = Graph.Lattice([n,n])


And then refering to the vertices by their coordinates?

Arjun

Loading...