# problem building weighted graph

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

graph.new_edge_property("float"))*

but got this error:

File
".conda/envs/graph-tool/lib/python3.7/site-packages/graph_tool/__init__.py",
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!

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

Hello Tiago,

*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!

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: