Question

I am using graph-tool for python, a library which implements boost. I need to do a depth-first search using only edges which have the edge_property:

rel_need = True

So, i'm using

gt.dfs_search(g, g.vertex(0), NeedFinder(rel_need, pred, time))

with this DFSVisitor:

class NeedFinder(gt.DFSVisitor):

    def __init__(self, rel_need, pred, time):
        self.rel_need = rel_need
        self.pred = pred
        self.time = time
        self.last_time = 0

    def discover_vertex(self, u):
        self.time[u] = self.last_time
        self.last_time += 1

    def examine_edge(self, e):
        pass

    def tree_edge(self, e):
        if self.rel_need[e]:
            self.pred[e.target()] = int(e.source())

It seems like I should be doing some sort of check in the examine_edge def, but I haven't been able to find docs explaining it. I have the check in the tree_edge def, which successfully filters all of the rel_need=true edges, but it doesn't change the traversal. How do I make a DFSVisitor that only traverses certain edges, and not all edges?

Was it helpful?

Solution

You should create a filtered graph first. You can do:

u = GraphView(g, efilt=rel_need)

where rel_need is a Boolean property map, where rel_need[e] == True means that the edge is not filtered out.

You can then proceed to do the DFS search with the graph u, and the edges for which rel_need[e] == False will be ignored.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top