Пример #1
0
  public void testRemoveDeadendsJob() {
    try {
      FileUtils.deleteQuietly(new File(conf.get("intermediaryResultPath")));
      FileUtils.deleteQuietly(new File(conf.get("finalVectorPath")));
      FileUtils.deleteQuietly(new File(conf.get("processedGraphPath")));

      FileUtils.copyDirectory(
          new File(conf.get("graphPath")), new File(conf.get("processedGraphPath")));

      conf.setLong("numNodes", 9);
      RemoveDeadends.job(conf);

      File directory = new File(conf.get("processedGraphPath"));
      if (!directory.exists()) fail("Output directory processedGraphPath doesn't exist");

      File[] contents = directory.listFiles();
      File outputFile = null;

      for (int i = 0; i < contents.length; ++i)
        if (!contents[i].getName().equals("_SUCCESS") && !contents[i].getName().startsWith("."))
          outputFile = contents[i].getAbsoluteFile();

      if (outputFile == null) fail("Output file doesn't exist");

      BufferedReader r = new BufferedReader(new FileReader(outputFile));
      int noLines = 0;
      String line;
      while ((line = r.readLine()) != null) {
        String[] parts = line.split("\\s+");
        noLines++;
        if (Integer.valueOf(parts[0]) == 7 && Integer.valueOf(parts[1]) == 8)
          fail("Deadend was not removed.");
      }

      r.close();
      assertEquals("The number of edges outputed is not correct.", 9, noLines);
      assertEquals(
          "The value of numNodes in conf was not updated.", 7, conf.getLong("numNodes", 0));

    } catch (IOException | ClassNotFoundException | InterruptedException e) {
      System.out.println(e.toString());
      fail(e.toString());
    }
  }
Пример #2
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));
  }