Domanda

I am trying to implement the simple random bipartite generator described in Guillam, Latapy, "Bipartite graphs as models of complex networks", Physica A 371 (2006) 795–813.

The rules are quite simple: - create top nodes and bottom nodes - assign to each node a degree (the distribution for top and bottom nodes must be consistent with each other - in my case, I have empirical data to feed top and bottom nodes) - randomly connect nodes from top and bottom sets

The code I have so far is:

UndirectedSparseGraph<Node, Edge> random = new UndirectedSparseGraph<Node, Edge>();
// totalLinks is the number of edges in the empirical network
while (totalLinks > 0) {
 Node u = topNodes.get(cntxt.getRNG().nextInt(topNodes.size()));
 Node t = bottomNodes.get(cntxt.getRNG().nextInt(bottomNodes.size()));
 // if both nodes can accept new links, i.e. the actual degree is lower than 
 // the assigned degree
 if(u.getFinalDegree()>random.degree(u) && t.getFinalDegree()>random.degree(t)){
   // create the new link
   random.addEdge(new Edge(0), u, t, EdgeType.UNDIRECTED);
   // decrement total links
   totalLinks--;
 }
}

This approach is simple but produces multiple edges. The result is that the final degree distribution is different from the empirical one.

Could someone suggest a way to overcome this issue? I am thinking about weighting the links, and then set the degree of a node as the sum of the weights of its links... Or maybe JUNG can handle multiple links?

Best regards, Simone

È stato utile?

Soluzione

JUNG can handle multiple edges with the right implementation; look for classes that have "Multi" in the name.

Or you can look to see if two nodes already are connected and pick another pair if they are.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top