private void removeNodeFrom(int node, Community from) { Community community = nodeCommunities[node]; for (Edge e : topology[node]) { int neighbor = e.getTarget(); //////// // Remove Node Connection to this community Double edgesTo = nodeConnectionsWeight[neighbor].get(community); int countEdgesTo = nodeConnectionsCount[neighbor].get(community); if (countEdgesTo - 1 == 0) { nodeConnectionsWeight[neighbor].remove(community); nodeConnectionsCount[neighbor].remove(community); } else { nodeConnectionsWeight[neighbor].put( community, edgesTo - Double.parseDouble(e.getProperty("weight").toString())); nodeConnectionsCount[neighbor].put(community, countEdgesTo - 1); } /////////////////// // Remove Adjacency Community's connection to this community Community adjCom = nodeCommunities[neighbor]; Double oEdgesto = adjCom.connectionsWeight.get(community); int oCountEdgesto = adjCom.connectionsCount.get(community); if (oCountEdgesto - 1 == 0) { adjCom.connectionsWeight.remove(community); adjCom.connectionsCount.remove(community); } else { adjCom.connectionsWeight.put( community, oEdgesto - Double.parseDouble(e.getProperty("weight").toString())); adjCom.connectionsCount.put(community, oCountEdgesto - 1); } if (node == neighbor) { continue; } if (adjCom != community) { Double comEdgesto = community.connectionsWeight.get(adjCom); Integer comCountEdgesto = community.connectionsCount.get(adjCom); if (comCountEdgesto - 1 == 0) { community.connectionsWeight.remove(adjCom); community.connectionsCount.remove(adjCom); } else { community.connectionsWeight.put( adjCom, comEdgesto - Double.parseDouble(e.getProperty("weight").toString())); community.connectionsCount.put(adjCom, comCountEdgesto - 1); } } Double nodeEgesTo = nodeConnectionsWeight[node].get(adjCom); Integer nodeCountEgesTo = nodeConnectionsCount[node].get(adjCom); if (nodeCountEgesTo - 1 == 0) { nodeConnectionsWeight[node].remove(adjCom); nodeConnectionsCount[node].remove(adjCom); } else { nodeConnectionsWeight[node].put( adjCom, nodeEgesTo - Double.parseDouble(e.getProperty("weight").toString())); nodeConnectionsCount[node].put(adjCom, nodeCountEgesTo - 1); } } from.remove(node); }