rustworkx icon indicating copy to clipboard operation
rustworkx copied to clipboard

Specify the edge when applying remove_edge

Open yulunwang opened this issue 1 year ago • 2 comments

What is the expected enhancement?

Currently the method rustworkx.PyGraph.remove_edge is only taking parent and child as input: def remove_edge(self, parent: int, child: int, /) -> None: ... In the function description, it says:

Note if there are multiple edges between the specified nodes only one will be removed.

But this is ambiguous. Which one of these edge will be exactly removed? It seems random and it caused some trouble. Can you please modify the function input so we can specify edge to be removed? Just like add_edge(self, parent: int, child: int, edge: _T, /) function

yulunwang avatar Aug 01 '24 22:08 yulunwang

As you can see PyGraph.remove_edge was not designed with multigraphs in mind. The functionality you want though, already exists with PyGraph.remove_edge_from_index. If you want to delete a specific edge between the many edges between nodes A and B, you will need to disambiguate with the edge index.

Maybe a follow up question is on how to find the edge index. The most straightforward way is to keep the index from PyGraph.add_edge or related methods, that for sure works. But let's say that is not possible, you can still query all edge indices with PyGraph.edge_indices_from_endpoints and then narrow down the edge you want to delete.

I think there might be a value adding a function such as PyGraph.remove_matching_edges(parent, child, value). But we will need to narrow down if we want to remove one occurrence, all occurrences or let the user specify how many values they want removed.

IvanIsCoding avatar Aug 02 '24 03:08 IvanIsCoding

@yulunwang if you specify exactly except what is provided by PyGraph.remove_edge_from_index, what you want to achieve , I can work on that one.

ranjana-mishra avatar Oct 07 '24 16:10 ranjana-mishra