Ray_M
(Ray M)
September 10, 2019, 10:39pm
1
Hi all,

I was trying to build a weighted graph. The input is a list of connections
with their weights, something like

*connections = [[edge1, edge2, weight1], [edge1, edge3, weight2], ...]*

where all edges are string and all weights are float64. I called
add-edge_list:

*graph.add_edge_list(connections, eprops =
graph.new_edge_property("float"))*

but got this error:

File
".conda/envs/graph-tool/lib/python3.7/site-packages/graph_tool/__init__.py",
line 2460, in add_edge_list
libcore.add_edge_list_iter(self.__graph, edge_list, eprops)
TypeError: No registered converter was able to produce a C++ rvalue of type
unsigned long from this Python object of type str

What is the most efficient way to build a weighted graph in my case?

Thanks!

tiago
(Tiago Peixoto)
September 11, 2019, 9:13am
2
Please read the documentation more carefully: help(Graph.add_edge_list)

If your edges do not point to vertex indexes (i.e. integers), you need
the option hashed=True. Furthermore the value passed to 'eprops' needs
to be a list of property maps.

Best,
Tiago

Ray_M
(Ray M)
September 11, 2019, 6:15pm
3
Hello Tiago,

Thank you for your advice. I built the graph as follow:

*weight = graph.new_edge_property("double")
eprops = [weight]
graph.add_edge_list(connections, hashed = True, string_vals = True, eprops =
eprops)*

After building the graph, I would like to execute shortest_distance() from a
source node to a target node:

*dist = shortest_distance(graph, source = 'start', target = 'end', weights =
weight)*

Seems like I need to use vertex indices of the 'start' and 'end' nodes for
input source and target, respectively.

How can I find vertex indices using vertex values (strings)? Is this finding
in O(1) time complexity?

Thanks!

tiago
(Tiago Peixoto)
September 12, 2019, 9:15am
4
After building the graph, I would like to execute shortest_distance() from a
source node to a target node:

*dist = shortest_distance(graph, source = 'start', target = 'end', weights =
weight)*

Seems like I need to use vertex indices of the 'start' and 'end' nodes for
input source and target, respectively.

Yes. This is covered extensively in the documentation, in particular in
the quickstart guide:

https://graph-tool.skewed.de/static/doc/quickstart.html

Please read the documentation. It will save both our times.

How can I find vertex indices using vertex values (strings)? Is this finding
in O(1) time complexity?

You can use the find_vertex() function. Its complexity is O(N). For O(1)
lookup you need to build your own dictionary mapping.

Best,
Tiago