public void clear() { graph = new DelegateForest<V, Integer>(); edgeCount = 0; }
/** * Add vertex as a root of the tree * * @param vertex the tree root to add * @return true if this call mutates the underlying graph * @see edu.uci.ics.jung.graph.Graph#addVertex(java.lang.Object) */ @Override public boolean addVertex(V vertex) { setRoot(vertex); return true; }
/** * @param v the vertex to test * @return {@code true} if {@code v} has no child nodes. */ public boolean isLeaf(V v) { return getChildren(v).size() == 0; }
/** * computes and returns the height of the tree * * @return the height */ public int getHeight() { int height = 0; for (V v : getVertices()) { height = Math.max(height, getDepth(v)); } return height; }
public DerivationTreeTransformer(DerivationTree t, Dimension d, boolean isAnchored) { this.isAnchored = isAnchored; anchorPoint = new Point2D.Double(0, 0); graph = t; DelegateForest<Node, DerivationTreeEdge> del = new DelegateForest<>(t); del.setRoot(t.root); del.setRoot(t.sourceRoot); root = t.root; sourceRoot = t.sourceRoot; Y_DIST = d.getHeight() / (2 * (1 + distanceToLeaf(root))); int leafCount = 0; for (Node n : t.getVertices()) { if (t.outDegree(n) == 0) leafCount++; } X_DIST = d.getWidth() / leafCount; treeLayout = new TreeLayout<>(del, (int) Math.round(X_DIST)); }
/** * Removes <code>edge</code> from this tree. * If <code>remove_subtree</code> is <code>true</code>, removes * the subtree rooted at the child vertex incident to <code>edge</code>. * Otherwise, leaves the subtree intact as a new component tree of this * forest. * @param edge the edge to remove * @param remove_subtree if <code>true</code>, remove the subtree * @return <code>true</code> iff the tree was modified */ public boolean removeEdge(E edge, boolean remove_subtree) { if (!delegate.containsEdge(edge)) return false; V child = getDest(edge); if (remove_subtree) return removeVertex(child); else { delegate.removeEdge(edge); return false; } }
/** * Returns true if {@code v} has no parent node. */ public boolean isRoot(V v) { return getParent(v) == null; }
/** * computes and returns the depth of the tree from the * root to the passed vertex * * @param v the node who's depth is computed * @return the depth to the passed node. */ public int getDepth(V v) { return getPath(v).size(); }
@SuppressWarnings("unchecked") @Override public boolean addEdge(E edge, Collection<? extends V> vertices) { Pair<V> pair = null; if (vertices instanceof Pair) { pair = (Pair<V>) vertices; } else { pair = new Pair<V>(vertices); } return addEdge(edge, pair.getFirst(), pair.getSecond()); }
@Override public Collection<Tree<V, E>> getTrees() { Collection<Tree<V, E>> trees = new HashSet<Tree<V, E>>(); for (V v : getRoots()) { Tree<V, E> tree = new DelegateTree<V, E>(); tree.addVertex(v); TreeUtils.growSubTree(this, tree, v); trees.add(tree); } return trees; }
/** * computes and returns the height of the tree * * @return the height */ public int getHeight() { int height = 0; for(V v : getVertices()) { height = Math.max(height, getDepth(v)); } return height; }
/** * Removes <code>edge</code> from this tree. If <code>remove_subtree</code> * is <code>true</code>, removes the subtree rooted at the child vertex * incident to <code>edge</code>. Otherwise, leaves the subtree intact as a * new component tree of this forest. * * @param edge * the edge to remove * @param remove_subtree * if <code>true</code>, remove the subtree * @return <code>true</code> iff the tree was modified */ public boolean removeEdge(E edge, boolean remove_subtree) { if (!delegate.containsEdge(edge)) { return false; } V child = getDest(edge); if (remove_subtree) { return removeVertex(child); } delegate.removeEdge(edge); return false; }
/** * @param v the vertex to test * @return {@code true} if {@code v} has no parent node. */ public boolean isRoot(V v) { return getParent(v) == null; }
/** * computes and returns the depth of the tree from the root to the passed * vertex * * @param v * the node who's depth is computed * @return the depth to the passed node. */ public int getDepth(V v) { return getPath(v).size(); }
@SuppressWarnings("unchecked") @Override public boolean addEdge(E edge, Collection<? extends V> vertices) { Pair<V> pair = null; if(vertices instanceof Pair) { pair = (Pair<V>)vertices; } else { pair = new Pair<V>(vertices); } return addEdge(edge, pair.getFirst(), pair.getSecond()); }
public Collection<Tree<V, E>> getTrees() { Collection<Tree<V,E>> trees = new HashSet<Tree<V,E>>(); for(V v : getRoots()) { Tree<V,E> tree = new DelegateTree<V,E>(); tree.addVertex(v); TreeUtils.growSubTree(this, tree, v); trees.add(tree); } return trees; }
public void clear() { graph = new DelegateForest<V, Integer>(); edgeCount = 0; }
/** * Add vertex as a root of the tree * * @param vertex * the tree root to add * @return true if this call mutates the underlying graph * @see edu.uci.ics.jung.graph.Graph#addVertex(java.lang.Object) */ @Override public boolean addVertex(V vertex) { setRoot(vertex); return true; }
/** * returns an ordered list of the nodes beginning at the root * and ending at the passed child node, including all intermediate * nodes. * @param child the last node in the path from the root * @return an ordered list of the nodes from root to child */ public List<V> getPath(V child) { if (!delegate.containsVertex(child)) return null; List<V> list = new ArrayList<V>(); list.add(child); V parent = getParent(child); while(parent != null) { list.add(list.size(), parent); parent = getParent(parent); } return list; }
/** * Returns true if {@code v} has no child nodes. */ public boolean isLeaf(V v) { return getChildren(v).size() == 0; }