Am 20.08.21 um 22:09 schrieb Oliver Baumann:
Tiago de Paula Peixoto wrote:
Am 20.08.21 um 20:51 schrieb oliver.baumann(a)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.
This was a typo whilst drafting my message, it is of course `lambda v:
g.vp.type[v] == 0`.
I also do not understand why do you construct a new Graph object,
instead of working with the GraphView directly.
To my understanding, modifying the GraphView by adding edges to it would also reflect in
the original, bipartite graph, which I don't want. Would an EdgePropertyMap only on the
view with a binary "exists/missing" be the cleaner approach, you reckon?
If you don't want to modify in place, then you should remove the
filtering altogether by passing "prune=True" to the Graph() constructor.
This will make the code faster.
Slightly hijacking the topic, is there any room for improvement on the
projection code:
#include <graph_tool.hh>
namespace gt = graph_tool;
template <class Graph, class ProjectedGraph>
void projection(const Graph &g, ProjectedGraph &pg) {
// iterate the filtered nodes, type==0
for (const auto v : gt::vertices_range(pg)) {
// iterate the neighbourhood of type == 1
for (const auto direct_neigh : gt::all_neighbors_range(v, g)) {
// iterate this neighbourhood, again of type == 0 to determine edges
between type-0-nodes
for (const auto next_neigh : gt::all_neighbors_range(direct_neigh, g)) {
if (v != nn) {
boost::add_edge(v, next_neigh, pg);
}
}
}
}
}
This looks like it adds every edge twice...
--
Tiago de Paula Peixoto <[email protected]>
_______________________________________________
graph-tool mailing list -- [email protected]
To unsubscribe send an email to [email protected]