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! -- Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
Am 11.09.19 um 00:39 schrieb redBlackTree:
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?
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 -- Tiago de Paula Peixoto <tiago@skewed.de>
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! -- Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
Am 11.09.19 um 20:15 schrieb redBlackTree:
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 -- Tiago de Paula Peixoto <tiago@skewed.de>
Thank you a lot, Tiago. -- Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
participants (2)
-
redBlackTree -
Tiago de Paula Peixoto