示例#1
0
  // Helper method for updateM( boolean, Node, Node )
  // Calculates M for Node n, given that M for the two children
  // of n has been calculated.
  // (Last modified: 10/02/01)
  private void calculateMforNode(Node n) {

    if (!n.isExternal()) {

      boolean was_duplication = n.isDuplication();
      Node a = n.getChild1().getLink(), b = n.getChild2().getLink();

      while (a != b) {
        if (a.getID() > b.getID()) {
          a = a.getParent();
        } else {
          b = b.getParent();
        }
      }

      n.setLink(a);

      if (a == n.getChild1().getLink() || a == n.getChild2().getLink()) {
        n.setDuplication(true);
        if (!was_duplication) {
          increaseDuplications();
        }
      } else {
        n.setDuplication(false);
        if (was_duplication) {
          decreaseDuplications();
        }
      }
    }
  } // calculateMforNode( Node )
  /**
   * Returns the node after the given one
   *
   * @param x node
   * @return next node
   * @throws HsqlException
   */
  Node next(Node x) throws HsqlException {

    if (x == null) {
      return null;
    }

    Node r = x.getRight();

    if (r != null) {
      x = r;

      Node l = x.getLeft();

      while (l != null) {
        x = l;
        l = x.getLeft();
      }

      return x;
    }

    Node ch = x;

    x = x.getParent();

    while (x != null && ch.equals(x.getRight())) {
      ch = x;
      x = x.getParent();
    }

    return x;
  }
示例#3
0
 @Override
 public Zeepbel<Key> geefLinkerBroerzeepbel() {
   if (getWortelNode().getParent() == null) {
     return null; // dan is dit de wortelzeepbel
   }
   Node<Key> zpblroot = getWortelNode();
   Zeepbel<Key> ouderzpbl = getOuderZeepbel();
   if (zpblroot.isLinkerkind()) {
     Node<Key> node = zpblroot.getParent();
     while (node.isLinkerkind()) {
       if (node.getParent() != null && node.getParent().getZeepbel() == ouderzpbl) {
         node = node.getParent();
       } else {
         return null; // geen linkerzeepbel, dit is de meest linkse
       }
     }
     Node<Key> nodeP = node.getParent();
     return node.isRoot() || nodeP.getZeepbel() != ouderzpbl
         ? null
         : nodeP.getLeft().inZelfdeZeepbelAls(nodeP)
             ? vindMaxInZeepbelVanuit(nodeP.getLeft()).getRight().getZeepbel()
             : nodeP.getLeft().getZeepbel();
   } else {
     // zpblroot is een rechterkind van zijn parent.
     assert (zpblroot.isRechterkind());
     Node<Key> sibling = zpblroot.getSibling();
     assert (sibling != null); // zeepbel structuur, deze zeepbel is geen root
     if (sibling.getZeepbel() != getOuderZeepbel()) {
       assert (sibling.getZeepbel().getWortelNode() == sibling);
       return sibling.getZeepbel();
     } else {
       return vindMaxInZeepbelVanuit(sibling).getRight().getZeepbel();
     }
   }
 }
示例#4
0
  @Override
  public boolean containsMoreThan1Key() {
    assert (root.getParent() == null || root.getParent().getZeepbel() != this);

    return (root.hasLeft() && root.getLeft().getZeepbel() == this)
        || (root.hasRight() && root.getRight().getZeepbel() == this);
  }
示例#5
0
  /**
   * Traverses the subtree of Node g in postorder, calculating the mapping function M, and
   * determines which nodes represent speciation events and which ones duplication events.
   *
   * <p>Preconditions: Mapping M for external nodes must have been calculated and the species tree
   * must be labelled in preorder.
   *
   * <p>(Last modified: 01/11/01)
   *
   * @param g starting node of a gene tree - normally the root
   */
  void geneTreePostOrderTraversal(Node g) {

    Node a, b;

    if (!g.isExternal()) {

      geneTreePostOrderTraversal(g.getChild1());
      geneTreePostOrderTraversal(g.getChild2());

      a = g.getChild1().getLink();
      b = g.getChild2().getLink();

      while (a != b) {
        if (a.getID() > b.getID()) {
          a = a.getParent();
        } else {
          b = b.getParent();
        }
      }
      g.setLink(a);

      // Determines whether dup. or spec.
      g.setDuplicationOrSpecAssigned(true);

      if (a == g.getChild1().getLink() || a == g.getChild2().getLink()) {
        g.setDuplication(true);
        increaseDuplications();
      } else {
        g.setDuplication(false);
      }
    }
  } // geneTreePostOrderTraversal( Node )
示例#6
0
  public void right_rotate(Node curr) {
    if (curr != null) {
      if (curr.getLeftChild() == null) {
        System.out.println("Cannot rotate right since left child is not present");
        return;
      }

      Node rotateWith = curr.getLeftChild();
      rotateWith.setParent(curr.getParent());

      if (curr.getParent() != null) {
        Node currParent = curr.getParent();
        if (curr == currParent.getLeftChild()) currParent.setLeftChild(rotateWith);
        else currParent.setRightChild(rotateWith);
      } else {
        root = rotateWith;
      }

      curr.setLeftChild(rotateWith.getRightChild());

      if (rotateWith.getRightChild() != null) rotateWith.getRightChild().setParent(curr);

      rotateWith.setRightChild(curr);
      curr.setParent(rotateWith);
    }
  }
示例#7
0
 /**
  * Generates the list of names of the operators in the path from the root node to the current
  * node.
  *
  * <p>This is a recursive method that builds the names list on to the list passed within the
  * parameter.
  *
  * @param node current node. Usually a node containing a final problem state.
  * @param operatorNames List<String> names of the operators making up the path from the root node
  *     to the current node.
  */
 public void solutionPath(Node node, List<String> operatorNames) {
   if (node == null || node.getParent() == null) {
     return;
   } else {
     operatorNames.add(0, node.getOperator());
     solutionPath(node.getParent(), operatorNames);
   }
 }
示例#8
0
 public Solution(Node solutionNode) {
   this.addSolutionNode(solutionNode);
   Node iterationNode = solutionNode;
   while (iterationNode.getParent() != Game.EMPTY_NODE) {
     iterationNode = iterationNode.getParent();
     this.addSolutionNode(iterationNode);
   }
 }
示例#9
0
 public void transplant(Node curr, Node replace) {
   if (curr.getParent() == null) root = replace;
   else if (curr == curr.getParent().getLeftChild()) {
     curr.getParent().setLeftChild(replace);
   } else {
     curr.getParent().setRightChild(replace);
   }
   if (replace != null) replace.setParent(curr.getParent());
 }
示例#10
0
 @Override
 public Zeepbel<Key> getOuderZeepbel() {
   Zeepbel<Key> zeepbel;
   if (root.getParent() == null) {
     zeepbel = null;
   } else {
     zeepbel = root.getParent().getZeepbel();
   }
   return zeepbel;
 }
示例#11
0
  public List<Node> getChildren(Node folder) {
    if (nodes == null || folder == null) return Collections.emptyList();

    LinkedList<Node> children = new LinkedList<Node>();
    for (Node n : nodes.values()) {
      if (n.getParent() != null && n.getParent().equals(folder.getHandle())) {
        children.add(n);
      }
    }
    return children;
  }
示例#12
0
 private void remove(Node n) {
   n.flag = true;
   if (n.getParent() != null) setChildCount(n.getParent(), getChildCount(n.getParent()) - 1);
   removeSink(n, null);
   removeSource(n, null);
   sL.add(n);
   if (n instanceof Subgraph) {
     Subgraph s = (Subgraph) n;
     isolateSubgraph(s, s);
     cycleRemove(s.members);
   }
 }
  /** Pull collapsed node bak onto the tree */
  public void undo() {
    if (nodeToCollapse != null) {
      NodeGraveyard.getGraveyard().getNode(nodeToCollapse.getId());
    }

    node.getParent().setChildrenChanged(oldParentHasChanged);
    if (node.getParent().getParent() != null) {
      node.getParent().getParent().setChildrenChanged(oldGrandParentHasChanged);
    }
    TreePanel.getTreePanel().getTree().updateTree(oldTreeString);

    updateTreePanel();
  }
示例#14
0
 /* Returns whether the node is visible by the TreeWalker. */
 private boolean isNodeVisible(final Node n) {
   if (acceptNode(n) == NodeFilter.FILTER_ACCEPT) {
     if (filter_ == null || filter_.acceptNode(n) == NodeFilter.FILTER_ACCEPT) {
       if (!expandEntityReferences_) {
         if (n.getParent() != null && n.getParent().getNodeType() == Node.ENTITY_REFERENCE_NODE) {
           return false;
         }
       }
       return true;
     }
   }
   return false;
 }
示例#15
0
 /* Returns whether the node is rejected by the TreeWalker. */
 private boolean isNodeRejected(final Node n) {
   if (acceptNode(n) == NodeFilter.FILTER_REJECT) {
     return true;
   }
   if (filter_ != null && filter_.acceptNode(n) == NodeFilter.FILTER_REJECT) {
     return true;
   }
   if (!expandEntityReferences_) {
     if (n.getParent() != null && n.getParent().getNodeType() == Node.ENTITY_REFERENCE_NODE) {
       return true;
     }
   }
   return false;
 }
示例#16
0
  /**
   * Helper method to get the previous node in document order (preorder traversal) from the given
   * node.
   */
  private Node getPreviousNode(final Node n) {
    if (n == root_) {
      return null;
    }
    final Node left = getEquivalentLogical(n.getPreviousSibling(), true);
    if (left == null) {
      final Node parent = n.getParent();
      if (parent == null) {
        return null;
      }
      if (isNodeVisible(parent)) {
        return parent;
      }
    }

    Node follow = left;
    while (follow.hasChildNodes()) {
      final Node toFollow = getEquivalentLogical(follow.getLastChild(), true);
      if (toFollow == null) {
        break;
      }
      follow = toFollow;
    }
    return follow;
  }
  public void testGetLoad() {
    clearCounts();

    Session s = openSession();
    Transaction tx = s.beginTransaction();
    Employer emp = new Employer();
    s.persist(emp);
    Node node = new Node("foo");
    Node parent = new Node("bar");
    parent.addChild(node);
    s.persist(parent);
    tx.commit();
    s.close();

    s = openSession();
    tx = s.beginTransaction();
    emp = (Employer) s.get(Employer.class, emp.getId());
    assertTrue(Hibernate.isInitialized(emp));
    assertFalse(Hibernate.isInitialized(emp.getEmployees()));
    node = (Node) s.get(Node.class, node.getName());
    assertTrue(Hibernate.isInitialized(node));
    assertFalse(Hibernate.isInitialized(node.getChildren()));
    assertFalse(Hibernate.isInitialized(node.getParent()));
    assertNull(s.get(Node.class, "xyz"));
    tx.commit();
    s.close();

    s = openSession();
    tx = s.beginTransaction();
    emp = (Employer) s.load(Employer.class, emp.getId());
    emp.getId();
    assertFalse(Hibernate.isInitialized(emp));
    node = (Node) s.load(Node.class, node.getName());
    assertEquals(node.getName(), "foo");
    assertFalse(Hibernate.isInitialized(node));
    tx.commit();
    s.close();

    s = openSession();
    tx = s.beginTransaction();
    emp = (Employer) s.get("org.hibernate.ejb.test.ops.Employer", emp.getId());
    assertTrue(Hibernate.isInitialized(emp));
    node = (Node) s.get("org.hibernate.ejb.test.ops.Node", node.getName());
    assertTrue(Hibernate.isInitialized(node));
    tx.commit();
    s.close();

    s = openSession();
    tx = s.beginTransaction();
    emp = (Employer) s.load("org.hibernate.ejb.test.ops.Employer", emp.getId());
    emp.getId();
    assertFalse(Hibernate.isInitialized(emp));
    node = (Node) s.load("org.hibernate.ejb.test.ops.Node", node.getName());
    assertEquals(node.getName(), "foo");
    assertFalse(Hibernate.isInitialized(node));
    tx.commit();
    s.close();

    assertFetchCount(0);
  }
  /** Track node to collapse, and previous status of "changed" variables */
  public AbstractCollapsableUndoableEdit(Node node, Node toCollapse) {
    this.node = node;

    nodeToCollapse = toCollapse;

    affectedNodes = new ArrayList();
    if (nodeToCollapse != null) {
      affectedNodes.add(toCollapse.getParent());
    }

    oldParentHasChanged = node.getParent().getChildrenChanged();
    oldGrandParent = node.getParent().getParent();
    if (oldGrandParent != null) {
      oldGrandParentHasChanged = node.getParent().getParent().getChildrenChanged();
    }
  }
示例#19
0
  // Helper method for getEquivalentLogical
  private Node getSibling(final Node n, final boolean lookLeft) {
    if (n == null) {
      return null;
    }

    if (isNodeVisible(n)) {
      return null;
    }

    final Node sibling;
    if (lookLeft) {
      sibling = n.getPreviousSibling();
    } else {
      sibling = n.getNextSibling();
    }

    if (sibling == null) {
      // If this node has no logical siblings at or below it's "level", it might have one above
      if (n == root_) {
        return null;
      }
      return getSibling(n.getParent(), lookLeft);
    }
    return getEquivalentLogical(sibling, lookLeft);
  }
示例#20
0
  public Node DFS() {
    boolean found;
    Math math;
    int tmp;
    math = new Math();
    found = false;
    currVal = 0;
    while (!found) {
      System.out.println(currNode.getId());
      if (math.equal(currNode.getVal(), value)) {
        found = true;
      } else {
      }

      if (!found && math.equal(currVal, currNode.getNumChilds())) {
        if (stack.isEmpty()) {
          found = true;
        } else {
          currNode = currNode.getParent();
          currVal = stack.pop();
        }
      } else if (!found) {
        tmp = currNode.getNode(currVal).setParent(currNode);
        currNode = currNode.getNode(currVal);

        currVal = currVal + 1;
        tmp = stack.push(currVal);
        currVal = 0;
      } else {
      }
    }

    return currNode;
  }
示例#21
0
  void left(Node node) {
    String str = node.getState();
    String parent = node.getParent();
    Node newState = new Node();
    int a = str.indexOf("0");
    char temp;
    char[] s = str.toCharArray();
    String newStr;

    if (a != 0) {
      temp = s[a - 1];
      s[a - 1] = '0';
      s[a] = temp;
      newStr = this.gString(s);
      newState.setState(newStr);
      newState.setParent(str);
      // newState.setLevel(node.getLevel()+1);
      // newState.setHeuristic(newState.calculateHeuristic(goal));
      // newState.setFvalue(newState.getHeuristic() + newState.getLevel());
      add(newState, map.get(str) + 1);
      // add(s,map.get(str)+1);
      if (newStr.equals("www0bbb")) {
        System.out.println(
            "Solution found after searching through " + map.get(newStr) + " states of the tree");
        printSolution();
        System.exit(0);
      }
    }
  }
  /**
   * This scales the x values to between 0 and 1 for each individual line rather than doing them all
   * at once.
   */
  private void scaleByInd() {
    // ammendment to what i may have commented before
    // this takes the lowest x and highest x  on each line and uses that for
    // the line in question
    double l_x, h_x;

    Edge e;
    Node r, s;
    r = m_groups[0].m_p;
    r.setCenter(.5);
    double m_scale;
    for (int noa = 0; noa < m_levelNum; noa++) {
      l_x = m_groups[m_levels[noa].m_start].m_left;
      h_x = m_groups[m_levels[noa].m_end].m_right;
      m_scale = h_x - l_x + 1;
      for (int nob = m_levels[noa].m_start; nob <= m_levels[noa].m_end; nob++) {
        r = m_groups[nob].m_p;
        for (int noc = 0; (e = r.getChild(noc)) != null; noc++) {
          s = e.getTarget();
          if (s.getParent(0) == e) {
            s.setCenter((s.getCenter() - l_x) / m_scale);
          }
        }
      }
    }
  }
  /** This scales all the x values to be between 0 and 1. */
  private void scaleByMax() {
    // ammendment to what i may have commented before
    // this takes the lowest x and highest x  and uses that as the scaling
    // factor
    double l_x = 5000, h_x = -5000;
    for (int noa = 0; noa < m_groupNum; noa++) {
      if (l_x > m_groups[noa].m_left) {
        l_x = m_groups[noa].m_left;
      }

      if (h_x < m_groups[noa].m_right) {
        h_x = m_groups[noa].m_right;
      }
    }

    Edge e;
    Node r, s;
    double m_scale = h_x - l_x + 1;
    if (m_groupNum > 0) {
      r = m_groups[0].m_p;
      r.setCenter((r.getCenter() - l_x) / m_scale);
      // System.out.println("from scaler " + l_x + " " + m_scale);
      for (int noa = 0; noa < m_groupNum; noa++) {
        r = m_groups[noa].m_p;
        for (int nob = 0; (e = r.getChild(nob)) != null; nob++) {
          s = e.getTarget();
          if (s.getParent(0) == e) {
            s.setCenter((s.getCenter() - l_x) / m_scale);
          }
        }
      }
    }
  }
  MultiTypeNode copyFromFlatNode(Node node) {

    MultiTypeNode mNode = new MultiTypeNode();

    mNode.height = node.height;
    mNode.parent = node.parent;

    mNode.nTypeChanges = 0;
    mNode.changeTimes.addAll(new ArrayList<Double>());
    mNode.changeTypes.addAll(new ArrayList<Integer>());
    mNode.nodeType = 0;

    mNode.labelNr = node.labelNr;

    if (node.isLeaf()) {

      int type = (int) node.getMetaData("location");

      if (type != 0) {

        mNode.setNodeType(type);
        mNode.addChange(
            0,
            (node.getHeight()
                + (node.getParent().getHeight() - node.getHeight()) * Randomizer.nextDouble()));
      }

    } else {

      mNode.addChild(copyFromFlatNode(node.getLeft()));
      mNode.addChild(copyFromFlatNode(node.getRight()));
    }

    return mNode;
  }
示例#25
0
 /**
  * Adds the node to this parent. Children must be stored in the order in which they were added.
  * Otherwise various operators will perform incorrectly (such as - % / and others).
  *
  * @param node child node.
  */
 public void addChild(Node node) {
   ParentNode parent = node.getParent();
   if (parent != null) {
     parent.children.remove(node);
   }
   children.add(node);
   node.setParent(this);
 } // addChild
示例#26
0
 /**
  * Gets the first ancestor instance of {@link Element}. It is mostly identical to {@link
  * #getParent()} except that it skips non {@link Element} nodes.
  *
  * @return the parent element
  * @see #getParent()
  */
 @Override
 public Element getParentElement() {
   Node parent = getParent();
   while (parent != null && !(parent instanceof Element)) {
     parent = parent.getParent();
   }
   return (Element) parent;
 }
示例#27
0
  public static void deleteSubTree2(Node[] tree, int index) {

    tree[index].setValid(false);
    tree[index].setVisited(true);

    for (int i = 0; i < tree.length; i++) {
      Node n = tree[i];
      if (n.getVisited() == false) {
        while (n.getParent() != -1 && n.getVisited() == false) {
          n = tree[n.getParent()];
        }
        if (n.getValid() == false) {
          deleteTree(tree, i);
        }
      }
    }
  }
示例#28
0
  public Node successor(int key) {
    Node curr = search(key);

    if (curr.getRightChild() != null) {
      return findMin(curr.getRightChild());
    } else if (curr == findMax(root)) {
      System.out.println(
          "this element is the maximum in the tree and hence does not have a successor");
      return null;
    } else {
      while (curr.getParent().getRightChild() == curr) {
        curr = curr.getParent();
      }

      return curr.getParent();
    }
  }
示例#29
0
  /**
   * Guts of the delete method
   *
   * @param token node to be deleted
   */
  public void delete(Node token) {
    // has two children
    if ((token.getLeft() != null)
        && (token.getRight() != null)) { // get left childs right most child
      Node rightMost = getRightMostChild(token.getLeft());
      rightMost.setRight(token.getRight());
      token.getRight().setParent(rightMost);

      if (root == token) // checks if root and 'token' point to the same place
      {
        root = token.getLeft();
      } else { // have to deal with parent nodes now
        // was token a right or left child?
        // if left then point parents left child to token.getLeft()
        if (token.getParent().getLeft() == token) {
          token.getParent().setLeft(token.getLeft());
        } else { // if right then point parents right child to token.Right()
          token.getParent().setRight(token.getLeft());
        }
        token.getLeft().setParent(token.getParent());
      }
    } else if ((token.getLeft() != null) && (token.getRight() == null)) { // has only left child
      if (root == token) // checks if root and 'token' point to the same place
      {
        root = token.getLeft();
      } else {
        token.getParent().setLeft(token.getLeft());
      }
    } else if ((token.getLeft() == null) && (token.getRight() != null)) { // has only right child
      if (root == token) // checks if root and 'token' point to the same place
      {
        root = token.getRight();
      } else {
        token.getParent().setRight(token.getRight());
      }
    } else { // has no children. replace with null
      if (root == token) {
        root = null;
      } else {
        // was token a right or left child?
        if (token.getParent().getLeft() == token) // left child
        {
          token.getParent().setLeft(null);
        } else { // if right then point parents right child to null
          token.getParent().setRight(null);
        }
      }
    }
    count--;
  }
示例#30
0
  /**
   * Adds the given node to this group.
   *
   * @param node Node to add
   * @throws IllegalArgumentException if the node cannot be added to this group
   */
  void add(Node node) {
    if (node.getParent() != null)
      throw new IllegalArgumentException("Node already has a parent: " + this);
    if (node == this) throw new IllegalArgumentException("Cannot add to self");
    checkNotCyclic(node);

    children.add(node);
    propagate(Flag.GRAPH);
  }