コード例 #1
0
  /** . */
  public void testDirectedGraph() {
    ListenableDirectedGraph<String, DefaultEdge> g =
        new ListenableDirectedGraph<String, DefaultEdge>(DefaultEdge.class);
    g.addVertex(V1);
    g.addVertex(V2);
    g.addVertex(V3);

    g.addEdge(V1, V2);

    ConnectivityInspector<String, DefaultEdge> inspector =
        new ConnectivityInspector<String, DefaultEdge>(g);
    g.addGraphListener(inspector);

    assertEquals(false, inspector.isGraphConnected());

    g.addEdge(V1, V3);

    assertEquals(true, inspector.isGraphConnected());
  }
コード例 #2
0
  public void parseInput(String file, int threads, int limit)
      throws FileNotFoundException, InterruptedException {
    // long startParseTime = System.currentTimeMillis();
    m_jgAdapter = new JGraphModelAdapter<Position, DefaultEdge>(graph);
    jgraph = new JGraph(m_jgAdapter);
    this.threads = threads;

    Scanner input = new Scanner(new File(file));
    try {
      for (int r = 0; input.hasNextLine() && r < limit; r++) {
        Scanner line = new Scanner(input.nextLine());
        try {

          ArrayList<Position> row = new ArrayList<Position>();
          grid.add(row);

          System.out.println("Row " + r);

          for (int c = 0; line.hasNextInt() && c < limit; c++) {
            Position position = new Position(r, c, line.nextInt());
            row.add(position);
            graph.addVertex(position);
            positionVertexAt(position, position.column * 5, position.row * 5);
          }
        } finally {
          line.close();
        }
      }
    } finally {
      input.close();
    }

    graphGrid(grid);

    // ArrayList<ArrayList<Position>> grid2 = transpose(grid);
    // outputGrid(grid2);

  }