[graph-tool] How can I know a specific edge from a Graph?

spolo96 samuelpp1996 at hotmail.com
Wed Jul 22 00:12:48 CEST 2020

Hello everyone, I'm having a hard time dealing with multiple edges in a graph
with the use of gt.shortest_path with negative weights. This is a simple
code that creates a simple graph in order to show my problem:

g70 = gt.Graph()

edge_weight = g70.new_edge_property("double")
g70.edge_properties["weight"] = edge_weight

edges = [[0,1],[1,2],[0,2],[0,2]]
weights = [-1,0,-2, 0]

for i in range(len(edges)):
    e = g70.add_edge(edges[i][0], edges[i][1])
    g70.ep.weight[e] = weights[i]

for path in gt.shortest_path(g70, 0, 2, weights=g70.ep.weight,
gt.graph_draw(g70, vertex_text=g70.vertex_index, edge_text=g70.ep.weight)

As you can see in the image, there are 2 edges from node 0 to node 2, the
solution that appears before the image specifies: <Edge object with source
'0' and target '2' at 0x7f2b70d49930> meaning that the shortest path from
node 0 to node 2 is an edge from node 0 to node 2. However it doesn't
specify which one of the two edges: (0,2) ->0, (0,2)->-2 is the solution

Since this is a small part of an another algorithm I'm writing, I also need
to know the final sum of the path (-2 in this case), because I'm using
Bellman-Ford as a solution to linear inequalities, so I tried accessing the
edge with the nodes like g70.weight[g70.edge(path[node],path[node+1])] and
because the path doesn't specify which of the two edges is the solution, I
can't seem to find the SPECIFIC edge that appears in the path. (In this case
it was simple: (0->2), however in my program for example a path is:
(0->4->5->6) and I have two edges (5->6) )

TL;DR: I have a directed graph with multiple edges and negative weights. I
plan to use Bellman Ford to solve a small system of linear inequalities.
After using gt.shortest_path, how can I access each EDGE of the path in
order to sum each weight of the specific edge that appears in the path? 


Sent from: https://nabble.skewed.de/

More information about the graph-tool mailing list