Example #1
0
  /**
   * Recursively assigns g_value for all nodes that could be reached from this node.
   *
   * @param val the value to assign to this node
   * @param max the maximum value (= # of keywords)
   */
  public void assignGValue(long val, int max) {
    // check for valid input
    if ((val < 0) || (val >= max)) {
      System.err.println("Invalid g-value.");
    }

    // only change if not already assigned
    if (this.gValue == -1) {
      this.gValue = val;

      Enumeration<Node> e = adjacency.keys();
      while (e.hasMoreElements()) {
        Node adj = e.nextElement();

        val = (adjacency.get(adj).longValue() - this.gValue + max) % max;
        adj.assignGValue(val, max);
      }
    }
  }
Example #2
0
  /**
   * Checks wheter there is a path from this node to the target node. Uses Depth First Search and
   * marks visited nodes on the path
   *
   * @param target the target node
   * @return true iff the target node is reachable
   */
  public boolean reaches(Node target) {
    if (target == this) {
      return true;
    } else {
      // depth first search the adjacency list
      setVisited(true);

      Enumeration<Node> e = adjacency.keys();
      while (e.hasMoreElements()) {
        Node adj = e.nextElement();

        if (!adj.getVisited()) {
          if (adj.reaches(target)) {
            return true;
          }
        }
      }
      return false;
    }
  }