java - how to make a projection of a bipartite graph with JUNG -


I have created a bilateral graph in the battle, and I want to launch one-mode for a set of sets of nodes . In the launch, two nodes of the same set will be linked if they have a node related to another set. Is there a festival in Zhang that already does? The code I have so far (very slow for a bilateral network of 1600 nodes where only 400 sets I want to project):

  public static void display (UndirectedSparseGraph & LT; Node, edge & gt; g, list & lt; node & gt; companies) throws exceptions {// Unsecured sparsaft & lt; Node, edge & gt; Acne = new indirect SparseGraph & lt; & Gt; (); // for (node ​​n: companies) {// store my concepts & lt; Node & gt; MyConcepts = g.getNeighbors (n); // For each of my ideas (node ​​m: myConcepts) {// Collect your companies & lt; Node & gt; Its companies = G. Janet Nibers (M); // For every company that uses this concept (node ​​NN: its companies) {// If Company does not own (if !! Nn.equals (n)) {// If at least one of these graphs Go directly to add a link (! OneMode.containsVertex (nn) ||! A Mode.containsVertex (n)) {// Add a new link edge = new edges (1); // Set edge edge edge. Setnam (search aggregate (n, nn)); Edge.setFrom (nn); Edge.setTo (n); // Add a link between your company and this one. Mode.addEgege (Edges, N, NN, EdgeType.Unended); } Else {if (oneMode.isNeighbor (n, nn)) {// Retrieve edge based on Boolean incrementWeight = incrementWeight (oneMode.getEdges (), findEdgeLabel (n, nn)); If (! Increase increase) {new exception throw ("does not work"); }} And {// add a new link edge edge = new edges (1); // Set edge edge edge. Setnam (search aggregate (n, nn)); Edge.setFrom (nn); Edge.setTo (n); // Add a link between your company and this one. Mode.addEgege (Edges, N, NN, EdgeType.Unended); }}}}}} Now try to write the result to write (PrintWriter author = new PrintWriter ("icleantech-a mode.csv", "UTF-8")) {// (For Edge E iterative: oneMode .getEdges ()) {author.printline (E.Getfrom (). GetName () + ";" + e.getTo (). GetName () + ";" + string.whouf (e.getweight ()); }} Hold (FileNotFoundException | unsupported encoding exceptions) {Logger.getLogger (BipartiteProjection.class.getName ()). Logs (level SESEE, blank, east); }} Private static string findEdgeLabel (node ​​n, node nn) {if (n.getId () & lt; nn.getId ()) {return String.valueOf (n.getId) + "-" + nn.getId ()); } And {return String.valueOf (nn.getId () + "-" + n.getId ()); }} Private Stable Boolean incrementWeight (collection of the & lt; edge & gt; edges, string findEdgeLabel) {for (edge ​​e: edges) {if (e.getName () is equal to (findEdgeLabel).) {// e.setWeight Weight gain (e.getWeight (+ 1); Back true; }     }     return false; }  

The code is interrupted when I want to update link weight ... Without it, the code is really fast ... I do not know where I am wrong. Any help over welcome.

The most effective way to do this, so far, instead of one bilateral graph, hypergraph (a split hypergraph The corner gets, the other gets hyperedges, each hyperedge corner that connects the corresponding peak in the original graph.) Then you can just ask a top for your neighbors in the hypergraph, and you're done.


Comments