code: public double getSolutionDensity(int solutionNum) {
          if (solutionNum < 0 || solutionNum >= mergeOrder.size()) {
              throw new IllegalArgumentException(
                  "not a valid solution: " + solutionNum);
          }      
          if (mergeOrder == null || edgeList == null) {
              throw new IllegalStateException(
                  "initial clustering solution is not valid yet");
          }
          
          int numEdges = edgeList.size();
  
          // Get the merges for this particular partitioning of the links
          List<Merge> mergeSteps = 
              mergeOrder.subList(0, solutionNum);
          
          // Convert the merges to a specific cluster labeling
          MultiMap<Integer,Integer> clusterToElements = 
              convertMergesToAssignments(mergeSteps, numEdges);
          
          // Based on the link partitioning, calculate the node partition density
          double partitionDensitySum = 0d;
          for (Integer cluster : clusterToElements.keySet()) {
              Set<Integer> linkPartition = clusterToElements.get(cluster);
              int numLinks = linkPartition.size();
              BitSet nodesInPartition = new BitSet(numRows);
              for (Integer linkIndex : linkPartition) {
                  Edge link = edgeList.get(linkIndex);
                  nodesInPartition.set(link.from);
                  nodesInPartition.set(link.to);
              }
              int numNodes = nodesInPartition.cardinality();
              // This reflects the density of this particular cluster within the
              // total partitioning
              double partitionDensity = (numLinks - (numNodes - 1d))
                  / (((numNodes * (numNodes - 1d)) / 2d) - (numLinks - 1));                
              partitionDensitySum += partitionDensity;
          }
          // Compute the density for the total partitioning solution
          double partitionDensity =  (2d / numEdges) * partitionDensitySum;
          return partitionDensity;
      }
docs: Returns the partition density of the clustering solution.