public int getPartition(WritablePoint key, LongWritable value, int numReduceTasks) { int grid = (int) Math.sqrt(numReduceTasks); minlat = conf.getDouble(OSMMapper.MINLAT, 0); minlon = conf.getDouble(OSMMapper.MINLON, 0); maxlat = conf.getDouble(OSMMapper.MAXLAT, 0); maxlon = conf.getDouble(OSMMapper.MAXLON, 0); double w = (maxlon - minlon) / grid; double h = (maxlat - minlat) / grid; int ret = -1; for (int i = 0; i < grid; i++) { double comp = minlat + (double) (i + 1) * h; if (key.getY() < comp) { ret = i * grid; // determine highside value break; } } if (ret == -1) { // We had a slight double imprecision problem assume we didn't properly arrive at maxlat ret = grid * grid - grid; } for (int i = 0; i < grid; i++) { if (key.getX() < minlon + (double) (i + 1) * w) { ret = ret + i; return ret; // determine lowside value } } ret = ret + grid - 1; return ret; }
public void setup(Context context) { Configuration conf = context.getConfiguration(); minlat = conf.getDouble(MINLAT, 0); minlon = conf.getDouble(MINLON, 0); maxlat = conf.getDouble(MAXLAT, 0); maxlon = conf.getDouble(MAXLON, 0); }
public static void iterativePageRank(Configuration conf) throws IOException, InterruptedException, ClassNotFoundException { String initialVector = conf.get("initialRankVectorPath"); String currentVector = conf.get("currentRankVectorPath"); String finalVector = conf.get("finalRankVectorPath"); /*here the testing system will seach for the final rank vector*/ Double epsilon = conf.getDouble("epsilon", 0.1); Double beta = conf.getDouble("beta", 0.8); // Launch remove dead ends jobs RemoveDeadends.job(conf); // Create initial vector Long nNodes = conf.getLong("numNodes", 1); createInitialRankVector(initialVector, conf.getLong("numNodes", 1)); // Create stochastic matrix GraphToMatrix.job(conf); boolean converg = false; // multiplication M * r MatrixVectorMult.job(conf); avoidSpiderTraps(currentVector, nNodes, beta); while (!converg) { FileUtils.deleteQuietly(new File(initialVector)); FileUtils.moveFile( new File(currentVector + "/part-r-00000"), new File(initialVector + "/part-r-00000")); // multiplication M * r MatrixVectorMult.job(conf); avoidSpiderTraps(currentVector, nNodes, beta); converg = checkConvergence(initialVector, currentVector, epsilon); } FileUtils.copyDirectory(new File(currentVector), new File(finalVector)); }