public static void printGraph(Graph hgraph) {
   for (Node n : hgraph.getNodes()) {
     for (Node m : hgraph.getNeighbors(n)) {
       System.out.println(n.getID() + " --> " + m.getID());
     }
     System.out.println();
   }
 }
    CommunityStructure(Graph hgraph) {
      this.graph = hgraph;
      N = hgraph.getNodeCount();
      invMap = new HashMap<>();
      nodeConnectionsWeight = new HashMap[N];
      nodeConnectionsCount = new HashMap[N];
      nodeCommunities = new Community[N];
      map = new HashMap<>();
      topology = new LinkedList[N];
      communities = new LinkedList<>();
      int index = 0;
      weights = new double[N];
      for (Node node : hgraph.getNodes()) {
        map.put(node, index);
        nodeCommunities[index] = new Community(this);
        nodeConnectionsWeight[index] = new HashMap<>();
        nodeConnectionsCount[index] = new HashMap<>();
        weights[index] = 0;
        nodeCommunities[index].seed(index);
        Community hidden = new Community(structure);
        hidden.nodes.add(index);
        invMap.put(index, hidden);
        communities.add(nodeCommunities[index]);
        index++;
      }

      for (Node node : hgraph.getNodes()) {
        int node_index = map.get(node);
        topology[node_index] = new LinkedList<>();

        for (Node neighbor : hgraph.getNeighbors(node)) {
          if (node == neighbor) {
            continue;
          }
          int neighbor_index = map.get(neighbor);
          double weight = 1; // TODO : change to actual weight

          weights[node_index] += weight;
          Edge me = new Edge(node_index, neighbor_index, weight);
          topology[node_index].add(me);
          Community adjCom = nodeCommunities[neighbor_index];
          nodeConnectionsWeight[node_index].put(adjCom, weight);
          nodeConnectionsCount[node_index].put(adjCom, 1);
          nodeCommunities[node_index].connectionsWeight.put(adjCom, weight);
          nodeCommunities[node_index].connectionsCount.put(adjCom, 1);
          nodeConnectionsWeight[neighbor_index].put(nodeCommunities[node_index], weight);
          nodeConnectionsCount[neighbor_index].put(nodeCommunities[node_index], 1);
          nodeCommunities[neighbor_index].connectionsWeight.put(
              nodeCommunities[node_index], weight);
          nodeCommunities[neighbor_index].connectionsCount.put(nodeCommunities[node_index], 1);
          graphWeightSum += weight;
        }
      }
      graphWeightSum /= 2.0;
    }
 public int buildCommunities(Graph hgraph) {
   int[] comStructure = new int[hgraph.getNodeCount()];
   computeModularity(hgraph, structure, comStructure, resolution);
   Set<Integer> communityCount = new HashSet<>();
   int idx = 0;
   for (Node n : hgraph.getNodes()) {
     communityCount.add(comStructure[idx]);
     n.setProperty("communityID", comStructure[idx++]);
   }
   return communityCount.size();
 }