// Path: src/main/java/org/trend/hgraph/mapreduce/pagerank/CalculatePageRankReducer.java
// static boolean pageRankEquals(double src, double dest, int scale) {
//   BigDecimal a = new BigDecimal(src);
//   BigDecimal b = new BigDecimal(dest);
//   a = a.setScale(scale, RoundingMode.DOWN);
//   b = b.setScale(scale, RoundingMode.DOWN);
//   return a.compareTo(b) == 0 ? true : false;
// }
// 
// Path: src/main/java/org/trend/hgraph/HBaseGraphConstants.java
// public class HBaseGraphConstants {
//   
//   public static final String HBASE_GRAPH_TABLE_VERTEX_NAME_KEY = "hbase.graph.table.vertex.name";
//   
//   public static final String HBASE_GRAPH_TABLE_EDGE_NAME_KEY = "hbase.graph.table.edge.name";
//   
//   public static final String HBASE_GRAPH_TABLE_COLFAM_PROPERTY_NAME = "property";
//   
//   public static final String HBASE_GRAPH_TABLE_COLFAM_PROPERTY_NAME_DELIMITER = "@";
// 
//   public static final String HBASE_GRAPH_TABLE_EDGE_DELIMITER_1 = "-->";
// 
//   public static final String HBASE_GRAPH_TABLE_EDGE_DELIMITER_2 = "-->";
// }


import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.trend.hgraph.HBaseGraphConstants;
import static org.trend.hgraph.mapreduce.pagerank.CalculatePageRankReducer.pageRankEquals;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.LineIterator;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.junit.After;
import org.junit.AfterClass;
    int prChanged = 0;
    int round = 0;
    do {
      round++;
      prChanged = 0;
      // housekeeping
      for (V v : vs)
        v.tprs.clear();

      // as mapper
      double cpr = 0.0D;
      double tpr = 0.0D;
      for (V v : vs) {
        cpr = v.pr;
        tpr = cpr / (double) v.al.size();
        for (V alv : v.al)
          alv.tprs.add(tpr);
      }

      // as reducer
      double opr = 0.0D;
      double pr = 0.0D;
      double npr = 0.0D;
      for (V v : vs) {
        opr = v.pr;
        pr = 0.0D;
        for (double tpr1 : v.tprs) {
          pr = pr + tpr1;
        }
        npr = (0.85D * pr) + ((1.0D - 0.85D) / (double) vs.size());
// Path: src/main/java/org/trend/hgraph/mapreduce/pagerank/CalculatePageRankReducer.java
// static boolean pageRankEquals(double src, double dest, int scale) {
//   BigDecimal a = new BigDecimal(src);
//   BigDecimal b = new BigDecimal(dest);
//   a = a.setScale(scale, RoundingMode.DOWN);
//   b = b.setScale(scale, RoundingMode.DOWN);
//   return a.compareTo(b) == 0 ? true : false;
// }
// 
// Path: src/main/java/org/trend/hgraph/HBaseGraphConstants.java
// public class HBaseGraphConstants {
//   
//   public static final String HBASE_GRAPH_TABLE_VERTEX_NAME_KEY = "hbase.graph.table.vertex.name";
//   
//   public static final String HBASE_GRAPH_TABLE_EDGE_NAME_KEY = "hbase.graph.table.edge.name";
//   
//   public static final String HBASE_GRAPH_TABLE_COLFAM_PROPERTY_NAME = "property";
//   
//   public static final String HBASE_GRAPH_TABLE_COLFAM_PROPERTY_NAME_DELIMITER = "@";
// 
//   public static final String HBASE_GRAPH_TABLE_EDGE_DELIMITER_1 = "-->";
// 
//   public static final String HBASE_GRAPH_TABLE_EDGE_DELIMITER_2 = "-->";
// }


// Path: src/test/java/org/trend/hgraph/mapreduce/pagerank/LocalPrTest.java
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.trend.hgraph.HBaseGraphConstants;
import static org.trend.hgraph.mapreduce.pagerank.CalculatePageRankReducer.pageRankEquals;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.LineIterator;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.junit.After;
import org.junit.AfterClass;

    int prChanged = 0;
    int round = 0;
    do {
      round++;
      prChanged = 0;
      // housekeeping
      for (V v : vs)
        v.tprs.clear();

      // as mapper
      double cpr = 0.0D;
      double tpr = 0.0D;
      for (V v : vs) {
        cpr = v.pr;
        tpr = cpr / (double) v.al.size();
        for (V alv : v.al)
          alv.tprs.add(tpr);
      }

      // as reducer
      double opr = 0.0D;
      double pr = 0.0D;
      double npr = 0.0D;
      for (V v : vs) {
        opr = v.pr;
        pr = 0.0D;
        for (double tpr1 : v.tprs) {
          pr = pr + tpr1;
        }
        npr = (0.85D * pr) + ((1.0D - 0.85D) / (double) vs.size());
        if (!pageRankEquals(opr, npr, 3)) prChanged++;