rustworkx.PyDAG.filter_edges#

PyDAG.filter_edges(filter_function)#

Filters a graph’s edges by some criteria conditioned on a edge’s data payload and returns those edges’ indices.

This function takes in a function as an argument. This filter function will be passed in an edge’s data payload and is required to return a boolean value stating whether the edge’s data payload fits some criteria.

For example:

from rustworkx import PyGraph
from rustworkx.generators import complete_graph

graph = PyGraph()
graph.add_nodes_from(range(3))
graph.add_edges_from([(0, 1, 'A'), (0, 1, 'B'), (1, 2, 'C')])

def my_filter_function(edge):
    if edge:
        return edge == 'B'
    return False  

indices = graph.filter_edges(my_filter_function)
assert indices == [1]
Parameters:

filter_function – Function with which to filter edges

Returns:

The edge indices that match the filter

Return type:

EdgeIndices