コード例 #1
0
  /**
   * Verify that some non-looping paths from {@code a} to {@code b} pass through at least one node
   * where {@code nodePredicate} is true.
   */
  private boolean checkSomePathsWithoutBackEdges(DiGraphNode<N, E> a, DiGraphNode<N, E> b) {
    if (nodePredicate.apply(a.getValue()) && (inclusive || (a != start && a != end))) {
      return true;
    }
    if (a == b) {
      return false;
    }
    for (DiGraphEdge<N, E> e : a.getOutEdges()) {
      // Once we visited that edge once, we no longer need to
      // re-visit it again.
      if (e.getAnnotation() == VISITED_EDGE) {
        continue;
      }
      e.setAnnotation(VISITED_EDGE);

      if (ignoreEdge(e)) {
        continue;
      }
      if (e.getAnnotation() == BACK_EDGE) {
        continue;
      }

      DiGraphNode<N, E> next = e.getDestination();
      if (checkSomePathsWithoutBackEdges(next, b)) {
        return true;
      }
    }
    return false;
  }
コード例 #2
0
 private void discoverBackEdges(DiGraphNode<N, E> u) {
   u.setAnnotation(GRAY);
   for (DiGraphEdge<N, E> e : u.getOutEdges()) {
     if (ignoreEdge(e)) {
       continue;
     }
     DiGraphNode<N, E> v = e.getDestination();
     if (v.getAnnotation() == WHITE) {
       discoverBackEdges(v);
     } else if (v.getAnnotation() == GRAY) {
       e.setAnnotation(BACK_EDGE);
     }
   }
   u.setAnnotation(BLACK);
 }