@Override
  protected double cost() {
    double cost = 0;
    final double targetUsage = ((double) this.cluster.numRegions / (double) this.totalCapacity);

    for (int i = 0; i < this.cluster.numServers; i++) {
      // retrieve capacity for each RS
      final ServerName sn = this.cluster.servers[i];
      final double limit = this.limitPerRS.getOrDefault(sn, defaultNumberOfRegions);
      final double nbrRegions = this.cluster.regionsPerServer[i].length;
      final double usage = nbrRegions / limit;
      if (usage > targetUsage) {
        // cost is the number of regions above the local limit
        final double localCost = (nbrRegions - Math.round(limit * targetUsage)) / limit;
        cost += localCost;
      }
    }

    return cost / (double) this.cluster.numServers;
  }
Called once per LB invocation to give the cost function to initialize it's state, and perform
any costly calculation.
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/HeterogeneousRegionCountCostFunction.java