Exemple #1
0
  public static void find_all_paths(
      AbstractVariable x, AbstractVariable end, Vector path_set, Stack path_stack)
      throws RemoteException {
    int i;

    path_stack.push(x);

    if (x == end) {
      // Construct a path from the beginning to the end, using what's on the stack.

      AbstractVariable[] path = new AbstractVariable[path_stack.size()];

      // System.err.println( "\tFound path: " );
      Enumeration e;
      for (i = 0, e = path_stack.elements(); e.hasMoreElements(); i++) {
        path[i] = (AbstractVariable) e.nextElement();
        // System.err.print( path[i].get_name()+" " );
      }
      // System.err.println("");

      path_set.addElement(path);
      path_stack.pop();
      return;
    }

    AbstractVariable[] parents = x.get_parents();
    for (i = 0; i < parents.length; i++) {
      Enumeration e = path_stack.elements();
      boolean is_on_stack = false;
      while (e.hasMoreElements())
        if (e.nextElement() == parents[i]) {
          is_on_stack = true;
          break;
        }

      if (!is_on_stack) find_all_paths(parents[i], end, path_set, path_stack);
    }

    AbstractVariable[] children = x.get_children();
    for (i = 0; i < children.length; i++) {
      Enumeration e = path_stack.elements();
      boolean is_on_stack = false;
      while (e.hasMoreElements())
        if (e.nextElement() == children[i]) {
          is_on_stack = true;
          break;
        }

      if (!is_on_stack) find_all_paths(children[i], end, path_set, path_stack);
    }

    path_stack.pop();
  }
Exemple #2
0
  public static boolean is_converging(AbstractVariable a, AbstractVariable b, AbstractVariable c)
      throws RemoteException {
    AbstractVariable[] bparents = b.get_parents();
    boolean found_a = false, found_c = false;

    for (int i = 0; i < bparents.length; i++) {
      if (found_a) {
        if (bparents[i] == c) return true;
      } else if (found_c) {
        if (bparents[i] == a) return true;
      } else {
        if (bparents[i] == a) found_a = true;
        else if (bparents[i] == c) found_c = true;
      }
    }

    return false;
  }
Exemple #3
0
  public static boolean is_ancestor(
      AbstractVariable possible_ancestor, AbstractVariable x, Stack path_stack)
      throws RemoteException {
    AbstractVariable[] parents = x.get_parents();
    for (int i = 0; i < parents.length; i++) {
      if (parents[i] == possible_ancestor) {
        path_stack.push(parents[i]);
        return true;
      } else if (is_ancestor(possible_ancestor, parents[i], path_stack)) {
        path_stack.push(parents[i]);
        return true;
      }
    }

    // If we didn't find the ancestor, don't add anything to the path_stack.
    // This saves a lot of useless pushing and popping, since ordinarily few paths
    // will be directed cycles.
    return false;
  }