Betweenness Centrality calculated for entire graph, not calling collection
See original GitHub issueIssue type
Bug report
Environment info
- Cytoscape.js version : 3.14.0
- Browser/Node.js & version : 13.10.1
Current (buggy) behaviour
I have a completely connected graph. I select a subgraph of this that contains all nodes but different edges (e.g. cy.elements('nodes, edges[weight < 50]')
. When I run the betweennessCentrality
function (alias bc
) on this subgraph collection, it calculates betweenness centrality for the whole graph, not respecting the collection.
Desired behaviour
I was expecting a similar outcome to if I were to run it on a clone of the graph without the elements outside the subgraph. I.e.
cy = cytoscape({ elements: cy.elements('node, edge[weight > 50]').jsons() });
let bc = cy.elements().bc();
cy.nodes().map(bc.betweenness);
Minimum steps to reproduce
Go to whatever example on the main page (I use grid layout) and find the betweenness centralities of a collection without any edges whatsoever (theoretically it should give you all zeros).
let bc = cy.nodes().bc();
cy.nodes().map(bc.betweenness);
It doesn’t give you all zeros and acts as if we are considering the whole graph, unlike what the documentation suggests (“Considering only the elements in the calling collection, calculate the betweenness centrality of the nodes.”).
Thanks.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
I would expect the source of the problem is how the algorithm makes use of calls to outgoers() openNeighborhood() and edgesTo() multiple times. None of these is bounded by the source collection, so they all will reach out to the entire graph.
I can add @somedmguy’s suggested change, but I need someone to provide sample data for at least one subgraph test case.