Hi,

I am wondering: is it possible to generate a vertex variable name from a
string. 

Let me explain: I need to read a set of vertices from a csv file, and a set
of arcs from another file. My vertices have names of the form XYZ, and my
arcs then indicate whether there is a connection between XYZ and, say, ABC.

Of course, I could define a property "name", assign it to the vertex, then
find the indices of the origin and end vertices when I browsing my
connection file.

But I am wondering.. From the examples, I would like to do something like

v1 = g.add_vertex()
v2 = g.add_vertex()
e = g.add_edge(v1, v2)

but where v1, v2, etc., would be replaced by vertexName[i] (in a loop).
Probably it is my incompetence with python, but I don't seem to be able to
do that. A call to 

for i in range(1, len(vertexName)):
    vertexName[i] = g.add_vertex()

does not give an error. But when I try to assign an edge using the "same"
method,

for i in range(1, len(listVertices)):
    e = g.add_edge(origVertex[i], destVertex[i])

I get

Traceback (innermost last):
  File "<stdin>", line 1, in <module>
  File "import_graph.py", line 59, in <module>
    e = g.add_edge(origVertex[i], destVertex[i])
  File "/usr/local/lib/python2.7/dist-packages/graph_tool/__init__.py", line
1109, in add_edge
    e = libcore.add_edge(weakref.ref(self), source, target)
TypeError: No registered converter was able to extract a C++ reference to
type graph_tool::PythonVertex from this Python object of type str

I am guessing that, if at all possible, then some typecasting is needed..
So, is it possible and if so, how?

Thanks!

--
View this message in context: 
http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/Vertex-variable-name-from-a-string-tp4024715.html
Sent from the Main discussion list for the graph-tool project mailing list 
archive at Nabble.com.
_______________________________________________
graph-tool mailing list
[email protected]
http://lists.skewed.de/mailman/listinfo/graph-tool

Reply via email to