Am 20.08.21 um 20:51 schrieb oliver.baum...@uni-bayreuth.de:
Hi all,

I'm currently offloading construction of the uni-modal projection of a 
bipartite graph from Python to C++ (NB: I am not very familiar with C++ or BGL, 
_yet_).
Thanks to the docs on writing such extensions, I know roughly where I'm heading.

This is the signature of the projection-function:

     template <class Graph, class ProjectedGraph>
     void projection(const Graph &g, ProjectedGraph &pg)

Here, g is the bipartite graph, and pg is constructed in Python as:
     pg = Graph(GraphView(g, vfilt=lambda v: g.vp.type == 0))

This would remove every vertex from the graph, since g.vp.type == 0 will always return False.

I also do not understand why do you construct a new Graph object, instead of working with the GraphView directly.

I am thus passing in the graph containing only the vertices I wish to project 
onto, and add the edges between them in C++.

In Python, pg.num_edges() correctly returns zero.
In C++, it returns the same number of edges as the base-graph it was 
constructed from, g.

How can I obtain the filtered view of pg in C++, which I expect to have no 
edges?

Since you have not provided any code, I can only guess what is going on.

A typical pitfall is that the C++ function num_edges(g) will always return the number of edges in the _unfiltered_ graph, even if the graph is being filtered. This is due to the BGL semantics that requires the function to be computed in time O(1). But that does not mean that the graph is not being filtered... If you iterate over it, you will get what you expect.

Best,
Tiago

--
Tiago de Paula Peixoto <ti...@skewed.de>
_______________________________________________
graph-tool mailing list -- graph-tool@skewed.de
To unsubscribe send an email to graph-tool-le...@skewed.de

Reply via email to