/** * Remove an edge from the graph. * @param e the Edge to remove from the graph * @return true if the edge was successfully removed, false if the * edge was not found in this graph */ public boolean removeEdge(Edge e) { edgeCheck(e, true); return removeEdge(e.getRow()); }
/** * Remove a child edge from the Tree. The child node and its subtree * will also be removed from the Tree. * @param e the edge to remove * @return true if the edge and attached subtree is successfully removed, * false otherwise */ public boolean removeChildEdge(Edge e) { edgeCheck(e, true); return removeChild(getTargetNode(e.getRow())); }
/** * Get the target Node for the given Edge instance. * @param e an Edge instance * @return the target Node of the edge */ public Node getTargetNode(Edge e) { edgeCheck(e, true); return getNode(getTargetNode(e.getRow())); }
/** * Get the source Node for the given Edge instance. * @param e an Edge instance * @return the source Node of the edge */ public Node getSourceNode(Edge e) { edgeCheck(e, true); return getNode(getSourceNode(e.getRow())); }
/** * Build the spanning tree, starting at the given root. Uses an * unweighted breadth first traversal to build the spanning tree. * @param root the root node of the spanning tree */ public void buildSpanningTree(Node root) { // re-use a previously allocated tree if possible super.clearEdges(); super.setRoot(root); // build unweighted spanning tree by BFS LinkedList q = new LinkedList(); BitSet visit = new BitSet(); q.add(root); visit.set(root.getRow()); Table edges = getEdgeTable(); while ( !q.isEmpty() ) { Node p = (Node)q.removeFirst(); for ( Iterator iter = p.edges(); iter.hasNext(); ) { Edge e = (Edge)iter.next(); Node n = e.getAdjacentNode(p); if ( !visit.get(n.getRow()) ) { q.add(n); visit.set(n.getRow()); int er = super.addChildEdge(p.getRow(), n.getRow()); edges.setInt(er, SOURCE_EDGE, e.getRow()); } } } }
/** * Given an Edge and an incident Node, return the other Node * connected to the edge. * @param e an Edge instance * @param n a Node instance. This node must * be connected to the edge * @return the adjacent Node */ public Node getAdjacentNode(Edge e, Node n) { edgeCheck(e, true); nodeCheck(n, true); return getNode(getAdjacentNode(e.getRow(), n.getRow())); }
while ( edges.hasNext() ) { Edge e = (Edge)edges.next(); vals[0] = String.valueOf(e.getRow()); vals[1] = String.valueOf(e.getSourceNode().getRow()); vals[2] = String.valueOf(e.getTargetNode().getRow());