Exemple #1
0
 protected void executeImpl() {
   initKeys();
   layerCount = 0;
   bfsTraverser = Traverser.newBfs().notRepeatingEdges().build();
   boolean exit = bfs(startNode);
   if (!exit) {
     for (Node n : graph.nodes()) {
       if (!isVisited(n)) {
         exit = bfs(n);
         if (exit) {
           break;
         }
       }
     }
   }
   bfsTraverser = null;
 }
Exemple #2
0
  // return true to break
  protected boolean bfs(Node start) {
    Object tree = new Object();
    incTreeNumber();
    markNodeTree(start, tree);
    markNode(start, 0, null);
    if (visitNewTree(start)) {
      return true;
    }
    final boolean[] exit = new boolean[1];
    PathIterator iterator = bfsTraverser.traverse(graph, start, direction).iterator();
    while (iterator.hasNext()) {
      Path path = iterator.next();
      if (path.size() == 0) {
        continue;
      }
      Edge e = path.tailEdge();
      Node node = path.tailNode();

      if (isVisited(node)) {
        markEdge(e, EdgeType.crossEdge);
        if (visitCrossEdge(path)) {
          return true;
        }
        iterator.skipExplorationOfLastPath();
        continue;
      } else {
        markEdge(e, EdgeType.treeEdge);
      }

      Node parent = e.opposite(node);
      int level = getLevel(parent) + 1;
      markNodeTree(node, getComponentIdentifier(parent));
      markNode(node, level, e);

      if (visitTreeEdge(path)) {
        return true;
      }
    }
    return false;
  }