edge removal not removing value from property map

Hi Guys

I am trying to remove edges from my graph.

I first copy my graph:
gCopy = g.copy()
pCopy = gCopy.new_edge_property("double")

then I go through the edges in the original graph to check for a particular property:
for j, e in enumerate(g.edges():
    src = e.source()
    tgt = e.target()

When a certain value for the property map of the original graph is found I use:
if p[e] > value:
    print pCopy.a
    gCopy.remove_edge(e)
    print pCopy.a

When I look at pCopy.a I see that the array does not shorten and that 0 values remain.
These values do not show up when I use:
for e in gCopy.edges():
    print pCopy[e]

I can still find these values, however, when I use
for e in g.edges():
    print pCopy[e]

I want to use this array in the max flow algorithm and it complains:
res = gt.edmonds_karp_max_flow(gCopy, src, tgt, pCopy)
res.a = pCopy.a - res.a
ValueError: operands could not be broadcast together with shapes (17,) (32,)

Is there any way I can remove the zero values from pCopy.a?

Thanks!
Best,

Alex

attachment.html (1.6 KB)

Hi Guys

I am trying to remove edges from my graph.

I first copy my graph:
gCopy = g.copy()
pCopy = gCopy.new_edge_property("double")

then I go through the edges in the original graph to check for a particular
property:
for j, e in enumerate(g.edges():
    src = e.source()
    tgt = e.target()

When a certain value for the property map of the original graph is found I use:
if p[e] > value:
    print pCopy.a
    gCopy.remove_edge(e)
    print pCopy.a

(Side note: You should never remove vertices or edges during iteration,
since this can invalidate iterators. You should store them first, and delete
them after the loop.)

When I look at pCopy.a I see that the array does not shorten and that 0
values remain.
These values do not show up when I use:
for e in gCopy.edges():
    print pCopy[e]

I can still find these values, however, when I use
for e in g.edges():
    print pCopy[e]

This is totally normal. The property maps are simple C++ vectors which are
indexed by the edge index. As is explained in the documentation, when an
edge is removed, the indices of the remaining ones are not modified. This is
done for efficiency reasons.

I want to use this array in the max flow algorithm and it complains:
res = gt.edmonds_karp_max_flow(gCopy, src, tgt, pCopy)
res.a = pCopy.a - res.a
ValueError: operands could not be broadcast together with shapes (17,) (32,)

Is there any way I can remove the zero values from pCopy.a?

Just use res.fa instead of res.a.

The .fa attribute returns a filtered array to the actual edges, whereas .a
always returns the naked underlying array.

Best,
Tiago

Great.
Thank you for another swift reply.
Best,

Alex