Exemplo n.º 1
0
  private void graphGrid(ArrayList<ArrayList<Position>> grid) throws InterruptedException {
    System.out.println(
        "Size of file by rows = " + grid.size() + ", columns = " + grid.get(0).size());
    final long current = System.currentTimeMillis();
    // System.out.println("Time for parsing file: " + ((current - startParseTime) / 1000) + " sec");
    // long afterEdge = 0;
    // long timeFindEdge = 0;

    ArrayList<Integer> ranges = findRanges();
    final Cell<Integer> threadsActive = new Cell<Integer>(threads);
    class EdgeThread extends Thread {

      int startRow = 0;
      int endRow = 0;

      public EdgeThread(int startRow, int endRow) {
        this.startRow = startRow;
        this.endRow = endRow;
      }

      public void run() {
        System.out.println("Thread: " + this.getId());
        findEdges(startRow, endRow);
        boolean lastThread;
        synchronized (threadsActive) {
          lastThread = --threadsActive.object == 0;
        }
        if (lastThread) {
          System.out.println("Last Thread: " + this.getId());
          long afterEdge = System.currentTimeMillis();
          long timeFindEdge = (afterEdge - current) / 1000;
          System.out.println("Time for findEdges: " + timeFindEdge + " sec");

          colorSCC();
          long afterColor = System.currentTimeMillis();
          long timeForColor = (afterColor - afterEdge) / 1000;
          System.out.println("Time for coloring and find CC: " + timeForColor + " sec");
          // findConnectedComponents();
          create();
          long timeForCreate = (System.currentTimeMillis() - afterColor) / 1000;
          System.out.println("Time for creating map: " + timeForCreate + " sec");
        }
      }
    }
    for (int i = 0; i < threads; i++) {
      EdgeThread thread = new EdgeThread(ranges.get(2 * i), ranges.get(2 * i + 1));
      thread.start();
    }

    Thread.currentThread().join();
  }
Exemplo n.º 2
0
      public void run() {
        System.out.println("Thread: " + this.getId());
        findEdges(startRow, endRow);
        boolean lastThread;
        synchronized (threadsActive) {
          lastThread = --threadsActive.object == 0;
        }
        if (lastThread) {
          System.out.println("Last Thread: " + this.getId());
          long afterEdge = System.currentTimeMillis();
          long timeFindEdge = (afterEdge - current) / 1000;
          System.out.println("Time for findEdges: " + timeFindEdge + " sec");

          colorSCC();
          long afterColor = System.currentTimeMillis();
          long timeForColor = (afterColor - afterEdge) / 1000;
          System.out.println("Time for coloring and find CC: " + timeForColor + " sec");
          // findConnectedComponents();
          create();
          long timeForCreate = (System.currentTimeMillis() - afterColor) / 1000;
          System.out.println("Time for creating map: " + timeForCreate + " sec");
        }
      }