/** * Method gets the of edge-crossings, if an edge is vertical * * @param edge the vertical edge * @param edges the rest of edges in the graph * @param op the graph * @return crossing-amount */ private static int infinitSlope(Edge edge, LinkedList<Edge> edges, OperatorGraph op) { int crossings = 0; HashMap<GraphWrapper, GraphBox> boxes = op.getBoxes(); GraphBox source1 = boxes.get(edge.getSource()); GraphBox target1 = boxes.get(edge.getTarget()); for (Edge edge2 : edges) { GraphBox source2 = boxes.get(edge2.getSource()); GraphBox target2 = boxes.get(edge2.getTarget()); if (target2.getX() == source2.getX()) { double m = ((double) target2.getY() - (double) source2.getY()) / ((double) target2.getX() - (double) source2.getX()); // slope of line 2 double b = target2.getY() - (m * target2.getX()); // crossing with y-axis off line 2 double y = m * source1.getX() + b; double minY = Math.min(source1.getY(), target1.getY()); double maxY = Math.max(source1.getY(), target1.getY()); if ((y > minY) && (y < maxY)) { crossings++; } } } return crossings; }
/** * This will set initial places for the x coord of the nodes. * * @param start The `number for the first group to start on (I think). */ private void xPlacer(int start) { // this can be one of a few x_placers (the first) // it will work by placing 1 space inbetween each node // ie the first at 0 the second at 1 and so on // then it will add to this value the place of the parent // node - half of the size // i will break this up into several functions // first the gap setter; // then the shifter // it will require a vector shift function added to the node class // i will write an additional shifter for the untangler // for its particular situation Node r; Edge e; if (m_groupNum > 0) { m_groups[0].m_p.setCenter(0); for (int noa = start; noa < m_groupNum; noa++) { int nob, alter = 0; double c = m_groups[noa].m_gap; r = m_groups[noa].m_p; for (nob = 0; (e = r.getChild(nob)) != null; nob++) { if (e.getTarget().getParent(0) == e) { e.getTarget().setCenter(nob * c); } else { alter++; } } m_groups[noa].m_size = (nob - 1 - alter) * c; xShift(noa); } } }
/** * <<<<<<< HEAD ���ߵ�valueֵ���й��� ======= 按边的value值进行过滤 >>>>>>> seuvislogwws/master * * @param filter * @return */ public SankeyGraph FilterByEdgeValue(double filter) { Set<Integer> nodeset = new HashSet<Integer>(); Iterator<? extends Edge> iterator_links = this.links.iterator(); while (iterator_links.hasNext()) { Edge edge = iterator_links.next(); double value = ((StreamEdge) edge).getValue(); if (value < filter) iterator_links.remove(); // �Ƴ�� else { nodeset.add(edge.getSource()); nodeset.add(edge.getTarget()); } } Iterator<? extends Node> iterator_nodes = this.nodes.iterator(); while (iterator_nodes.hasNext()) { Node node = iterator_nodes.next(); if (!nodeset.contains(node.getName())) { // ����nodes�� iterator_nodes.remove(); } } // System.out.println( "���˺�nodes�Ĵ�С�� "+this.nodes.size()); // �����˹���json����ٴΰ�node��name��0��ʼ�ź� int index = 0; for (Node n : this.nodes) { int old_name = n.getName(); int new_name = index++; n.setName(new_name); for (Edge e : this.links) { if (e.getSource() == old_name) e.setSource(new_name); if (e.getTarget() == old_name) e.setTarget(new_name); } } return this; }
private void preparePathSearch() throws SourceNodeException { NEWNUM = new HashMap<Node, Integer>(); HIGHPT = new HashMap<Node, List<Integer>>(); START = new HashMap<Edge, Boolean>(); m_numCount = this.graphCopy.getNodes().size(); m_newPath = true; for (Node n : this.graphCopy.nodes) { DEGREE.put(n, 0); HIGHPT.put(n, new LinkedList<Integer>()); } for (Edge e : this.graphCopy.edges) { START.put(e, Boolean.FALSE); DEGREE.put(e.getSource(), DEGREE.get(e.getSource()).intValue() + 1); DEGREE.put(e.getTarget(), DEGREE.get(e.getTarget()).intValue() + 1); } this.pathFinder(this.m_start); int[] old2new = new int[graphCopy.getNodes().size() + 1]; for (Node n : graphCopy.getNodes()) old2new[NUMBER.get(n)] = NEWNUM.get(n); for (Node n : graphCopy.getNodes()) { NODEAT[NEWNUM.get(n)] = n; LOWPT1.put(n, old2new[LOWPT1.get(n)]); LOWPT2.put(n, old2new[LOWPT2.get(n)]); } // System.err.println(this); // System.err.println("-------------"); }
private void delHigh(Edge e) { if (HIGHPT.get(e.getTarget()) != null) { Node v = e.getTarget(); HIGHPT.get(v).remove(NEWNUM.get(e.getSource())); } }
private int getEdgeNumber(Edge e) { if (TYPE.get(e).equals(ArcType.TREE)) { if (LOWPT2.get(e.getTarget()) < NUMBER.get(e.getSource())) return 3 * LOWPT1.get(e.getTarget()); else return 3 * LOWPT1.get(e.getTarget()) + 2; } else { // otherwise it's a frond return 3 * NUMBER.get(e.getTarget()) + 1; } }
/** * This will set all of the children node of a particular node to their height. * * @param r The parent node of the children to set their height. */ private void nodeY(Node r) { Edge e; double h = r.getTop() + m_yRatio; for (int noa = 0; (e = r.getChild(noa)) != null; noa++) { if (e.getTarget().getParent(0) == e) { e.getTarget().setTop(h); if (!e.getTarget().getVisible()) { // System.out.println("oh bugger"); } } } }
/** * This will shift a group of nodes to be aligned under their parent. * * @param n The group number to shift */ private void xShift(int n) { Edge e; Node r = m_groups[n].m_p; double h = m_groups[n].m_size / 2; double c = m_groups[n].m_p.getCenter(); double m = c - h; m_groups[n].m_left = m; m_groups[n].m_right = c + h; for (int noa = 0; (e = r.getChild(noa)) != null; noa++) { if (e.getTarget().getParent(0) == e) { e.getTarget().adjustCenter(m); } } }
/** 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); } } } } }
private void visit(Set<Edge> visited) { boolean fixpoint = false; while (!fixpoint) { fixpoint = true; Vector<Vector<Edge>> newPaths = new Vector<Vector<Edge>>(); Vector<Vector<Edge>> delPaths = new Vector<Vector<Edge>>(); for (Vector<Edge> path : paths) { Edge e = path.lastElement(); boolean pathExtended = false; for (Edge succ : e.getTarget().getSucc()) { if (!visited.contains(succ)) { Vector<Edge> newPath = new Vector<Edge>(); newPath.addAll(path); newPath.add(succ); newPaths.add(newPath); visited.add(succ); pathExtended = true; fixpoint = false; } } if (pathExtended) delPaths.add(path); } for (Vector<Edge> path : delPaths) paths.remove(path); paths.addAll(newPaths); } }
@Override public void addEdge(Edge edge) { checkInTransaction(); if (edge == null) { throw new IllegalArgumentException("edge must not be null"); } Vertex source = edge.getSource(); Vertex target = edge.getTarget(); // Validate to ensure the model does not become corrupted. int si = vertexList.indexOf(source); int ti = vertexList.indexOf(target); if (si == -1 || ti == -1 || si >= adjacencies.size() || ti >= adjacencies.size()) { throw new IllegalStateException("vertices not in model"); } if (source.equals(target)) { throw new IllegalStateException("edge endpoints are same"); } if (findEdge(source, target) != null || (!edge.isDirected() && findEdge(target, source) != null)) { throw new IllegalArgumentException("edge already exists"); } // Add the new edge to the list and make the source vertex // adjacent to the target vertex. If the edge is undirected, // then make target adjacent to source, as well. edgeList.add(edge); addAdjacency(source, target); if (!edge.isDirected()) { addAdjacency(target, source); } fireModelEvent(new ModelEvent(this, ModelEventType.EDGE_ADDED)); fireUndoableEdit(new EdgeAddUndoableEdit(this, edge)); }
/** * 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); } } } } }
public boolean addE(Edge myE) { if (!existingEdges.contains(myE.toString())) { existingEdges.add(myE.toString()); edgeRef.put(myE.toString(), myE); Vertex src = myE.getSource(); Vertex trg = myE.getTarget(); if (src == null) { if (__DEBUG) { a.e.println("src node not found "); } return false; } if (trg == null) { if (__DEBUG) { a.e.println("trg node not found "); } return false; } if (__DEBUG && a.e.__HIGHDETAILS) { a.e.println(src.name + " " + inDegreeOf(src)); } if (__DEBUG && a.e.__HIGHDETAILS) { a.e.println(trg.toString() + " "); } return this.addEdge(src, trg, myE); } return false; }
/** * This will recursively shift a sub there to be centered about a particular value. * * @param n The first group in the sub tree. * @param o The point to start shifting the subtree. */ private void moveSubtree(int n, double o) { Edge e; Node r = m_groups[n].m_p; for (int noa = 0; (e = r.getChild(noa)) != null; noa++) { if (e.getTarget().getParent(0) == e) { e.getTarget().adjustCenter(o); } } m_groups[n].m_left += o; m_groups[n].m_right += o; if (m_groups[n].m_start != -1) { for (int noa = m_groups[n].m_start; noa <= m_groups[n].m_end; noa++) { moveSubtree(noa, o); } } }
@Override public Edge findEdge(Vertex source, Vertex target) { if (source == null || target == null || source == target) { return null; } int si = vertexList.indexOf(source); int ti = vertexList.indexOf(target); if (si == -1 || ti == -1) { return null; } // Perform a quick search of the adjlist, to see if the edge exists. int[] list = adjacencies.get(si); if (list == null) { list = adjacencies.get(ti); if (list == null) { return null; } ti = si; } int ii; for (ii = 0; ii < list.length; ii++) { if (list[ii] == ti) { break; } } if (ii == list.length) { return null; } // Look through all of the edges, looking for one whose "source" // and "target" match the parameters. for (Edge edge : edgeList) { if (edge.getSource().equals(source) && edge.getTarget().equals(target)) { return edge; } // If the edge is undirected, then we can match // the source and target in the reverse order. if (!edge.isDirected() && edge.getSource().equals(target) && edge.getTarget().equals(source)) { return edge; } } return null; }
/** * This is called to build the rest of the grouping information. * * @param r The parent of the group. * @param pg The number for the parents group. */ private void groupFind(Node r, int pg) { Edge e; boolean first = true; for (int noa = 0; (e = r.getChild(noa)) != null; noa++) { if (e.getTarget().getParent(0) == e) { if (e.getTarget().getChild(0) != null && e.getTarget().getCVisible()) { if (first) { m_groups[pg].m_start = m_groupNum; first = false; } m_groups[pg].m_end = m_groupNum; m_groups[m_groupNum].m_p = e.getTarget(); m_groups[m_groupNum].m_pg = pg; m_groups[m_groupNum].m_id = m_groupNum; // just in case I ever need // this info m_groupNum++; } } } }
/** * Remove critical edges. A critical edge is an edge from a block with more than one successor to * a block with more than one predecessor. Critical edges can hinder code motion and should be * removed. */ private void removeCriticalEdges() { LinkedList list = new LinkedList(); for (BasicBlock bb = firstBB; bb != null; bb = bb.getNext()) { if (bb.getOutEdgesNumber() > 1) { Iterator outEdges = bb.getOutEdges(); while (outEdges.hasNext()) { Edge outEdge = (Edge) outEdges.next(); BasicBlock succ = (BasicBlock) outEdge.getTarget(); if (succ.getInEdgesNumber() > 1 && !succ.isFirstBlockSubroutine() && !succ.isCatchBlock()) { list.addLast(outEdge); } } } } while (!list.isEmpty()) { Edge edge = (Edge) list.removeFirst(); BasicBlock source = (BasicBlock) edge.getSource(); BasicBlock target = (BasicBlock) edge.getTarget(); if (source.getOutEdgesNumber() > 1 && target.getInEdgesNumber() > 1) { // insert a new block in the CFG between source and target BasicBlock insert = new BasicBlock(graph); edge.getSource().changeEdgeTarget(edge, insert); insert.addDefaultNextBlock(target); // insert the new block before target in the trace target.insertBefore(insert); for (int i = 0; i < exceptionHandlers.length; ++i) { if (exceptionHandlers[i].contains(target)) { exceptionHandlers[i].addProtectedBlock(insert); insert.addExceptionNextBlock(target); } } } } }
@Override public void removeEdge(Edge edge) { checkInTransaction(); if (edge == null) { throw new IllegalArgumentException("edge must not be null"); } if (!edgeList.remove(edge)) { throw new IllegalArgumentException("edge not in model"); } // Remove the connections from the adjancency list. Vertex source = edge.getSource(); Vertex target = edge.getTarget(); removeAdjacency(source, target); if (!edge.isDirected()) { removeAdjacency(target, source); } fireModelEvent(new ModelEvent(this, ModelEventType.EDGE_REMOVED)); fireUndoableEdit(new EdgeRemoveUndoableEdit(this, edge)); }
/** * Get the Location where exception(s) thrown on given exception edge are thrown. * * @param exceptionEdge the exception Edge * @return Location where exception(s) are thrown from */ public Location getExceptionThrowerLocation(Edge exceptionEdge) { if (!exceptionEdge.isExceptionEdge()) { throw new IllegalArgumentException(); } InstructionHandle handle = exceptionEdge.getSource().getExceptionThrower(); if (handle == null) { throw new IllegalStateException(); } BasicBlock basicBlock = (handle.getInstruction() instanceof ATHROW) ? exceptionEdge.getSource() : getSuccessorWithEdgeType(exceptionEdge.getSource(), EdgeTypes.FALL_THROUGH_EDGE); if (basicBlock == null) { if (removedEdgeList != null) { // The fall-through edge might have been removed during // CFG pruning. Look for it in the removed edge list. for (Edge removedEdge : removedEdgeList) { if (removedEdge.getType() == EdgeTypes.FALL_THROUGH_EDGE && removedEdge.getSource() == exceptionEdge.getSource()) { basicBlock = removedEdge.getTarget(); break; } } } } if (basicBlock == null) { throw new IllegalStateException( "No basic block for thrower " + handle + " in " + this.methodGen.getClassName() + "." + this.methodName + " : " + this.methodGen.getSignature()); } return new Location(handle, basicBlock); }
@Override public String toString() { StringBuilder b = new StringBuilder(100); b.append("Nodes: "); b.append(this.NEWNUM); b.append("\nEDGES:\n"); for (Edge e : this.graphCopy.edges) { b.append(e.getSource()); if (TYPE.get(e).equals(ArcType.TREE) || TYPE.get(e).equals(ArcType.FROND)) { if (TYPE.get(e).equals(ArcType.FROND)) b.append("^"); b.append("-->" + e.getTarget() + "\n"); } } b.append("START: " + START); return b.toString(); }
@Override public List<Edge> findAdjacentEdges(Vertex vertex, boolean directedOnly) { List<Edge> result = new LinkedList<Edge>(); if (directedOnly) { // Look for edges that contain a matching source vertex. for (Edge edge : edgeList) { if (edge.getSource().equals(vertex)) { result.add(edge); } } } else { // Look for edges that contain any matching vertex. for (Edge edge : edgeList) { if (edge.getSource().equals(vertex)) { result.add(edge); } else if (edge.getTarget().equals(vertex)) { result.add(edge); } } } return result; }
private void pathFinder(Node v) { NEWNUM.put(v, m_numCount - ND.get(v) + 1); IterableAdjacencyList adj = ADJ.get(v); while (adj.hasNext()) { Edge e = adj.next(); Node w = e.getTarget(); if (m_newPath) { m_newPath = false; START.put(e, true); } if (TYPE.get(e).equals(ArcType.TREE)) { this.pathFinder(w); m_numCount--; } else { HIGHPT.get(w).add(NEWNUM.get(v)); int sIndex = HIGHPT.get(w).size(); m_newPath = true; } } }
/** * Construct a new palm tree from the given graph. For the sake of simplicity we only consider * graphs with one source. If the given graph has multiple sources an exception is thrown. * * @param graph the graph * @throws SourceNodeException This exception is thrown if the graph has multiple source nodes. */ public PalmTree(NormalizedGraph graph) throws SourceNodeException { super(); Node source = this.getSingleSource(graph); this.graph = graph; this.graphCopy = new GraphCopy(graph); this.initializeDFSStructures(); this.depthFirstSearch(source, null); for (Edge e : graphCopy.edges) { boolean up = (NUMBER.get(e.getTarget()) - NUMBER.get(e.getSource()) > 0); if ((up && TYPE.get(e).equals(ArcType.FROND)) || (!up && TYPE.get(e).equals(ArcType.TREE))) { graphCopy.reverseEdge(e); } } this.ADJ = new HashMap<Node, IterableAdjacencyList>(); this.buildAcceptableAdjStructure(); }
@Override public void save() { List<WrappedVertex> vertices = new ArrayList<WrappedVertex>(); for (Vertex vertex : getVertices()) { if (vertex.isGroup()) { vertices.add(new WrappedGroup(vertex)); } else { vertices.add(new WrappedLeafVertex(vertex)); } } List<WrappedEdge> edges = new ArrayList<WrappedEdge>(); for (Edge edge : getEdges()) { WrappedEdge newEdge = new WrappedEdge( edge, new WrappedLeafVertex(m_vertexProvider.getVertex(edge.getSource().getVertex())), new WrappedLeafVertex(m_vertexProvider.getVertex(edge.getTarget().getVertex()))); edges.add(newEdge); } WrappedGraph graph = new WrappedGraph(getEdgeNamespace(), vertices, edges); JAXB.marshal(graph, new File(getConfigurationFile())); }
/** * Method computes the amount of edge-crossing in a graph and displays the result on command-line */ public static String minEdgeCrossing_Test(OperatorGraph graph) { HashMap<GraphWrapper, GraphBox> boxes = graph.getBoxes(); LinkedList<Edge> edges = new LinkedList<Edge>(); int crossCounter = 0; // get all edges of the graph for (GraphWrapper gw : boxes.keySet()) { LinkedList<GraphWrapperIDTuple> children = gw.getSucceedingElements(); for (GraphWrapperIDTuple child : children) { Edge edge = new Edge(gw, child.getOperator(), 0); edges.add(edge); } } int edgecount = 0; LinkedList<Edge> visited = new LinkedList<Edge>(); for (int i = 0; i < edges.size(); i++ /** Edge edge1 : edges* */ ) { Edge edge1 = edges.get(i); edgecount++; GraphBox sourceE1 = boxes.get(edge1.getSource()); GraphBox targetE1 = boxes.get(edge1.getTarget()); // edge 1 is vertical if ((targetE1.getX() == sourceE1.getX())) { crossCounter = infinitSlope(edge1, edges, graph); } else { double m1 = ((double) targetE1.getY() - (double) sourceE1.getY()) / ((double) targetE1.getX() - (double) sourceE1.getX()); // slope of line 1 double b1 = (targetE1.getY()) - (m1 * targetE1.getX()); // slope of line 1 for (int j = 0; j < edges.size(); j++ /** Edge edge2 : edges* */ ) { Edge edge2 = edges.get(j); if ((!edge2.equals(edge1)) && (!visited.contains(edge2)) && (m1 != 0.0)) { GraphBox sourceE2 = boxes.get(edge2.getSource()); GraphBox targetE2 = boxes.get(edge2.getTarget()); // edge 2 is vertical if (targetE2.getX() == sourceE2.getX()) { crossCounter += infinitSlope(edge2, edge1, graph); } else { double m2 = ((double) targetE2.getY() - (double) sourceE2.getY()) / ((double) targetE2.getX() - (double) sourceE2.getX()); // slope of line 2 double b2 = (targetE2.getY()) - (m2 * targetE2.getX()); // crossing with y-axis of line 2 double x = ((b2 - b1) / (m1 - m2)); double y = ((m1 * x) + b1); // cross-point-coordinates of the 2 lines double maxXe1 = Math.max(sourceE1.getX(), targetE1.getX()); double maxXe2 = Math.max(sourceE2.getX(), targetE2.getX()); double minXe1 = Math.min(sourceE1.getX(), targetE1.getX()); double minXe2 = Math.min(sourceE2.getX(), targetE2.getX()); double maxYe1 = Math.max(sourceE1.getY(), targetE1.getY()); double maxYe2 = Math.max(sourceE2.getY(), targetE2.getY()); double minYe1 = Math.min(sourceE1.getY(), targetE1.getY()); double minYe2 = Math.min(sourceE2.getY(), targetE2.getY()); // test if cross-point is part of edge 1 if ((x < maxXe1) && (x > minXe1) && (y < maxYe1) && (y > minYe1)) { if ((x < maxXe2) && (x > minXe2) && (y < maxYe2) && (y > minYe2)) { crossCounter++; } } } // visited.add(edge2); } } } visited.add(edge1); } return "Test: Crossing Edges:\nThe number of edges crossing is " + crossCounter + " of total " + edgecount + " edges.\n"; }
/** * Removes the given subtree, replacing it with one of its children. Returns the new root of the * subtree * * @param subTree * @return the index of the new root * @since 3.1 */ private final int removeNode(int subTree) { int left = leftSubTree[subTree]; int right = rightSubTree[subTree]; if (left == -1 || right == -1) { int result = -1; if (left == -1 && right == -1) { // If this is a leaf node, replace it with its first unsorted child result = nextUnsorted[subTree]; } else { // Either the left or right child is missing -- replace with the remaining child if (left == -1) { result = right; } else { result = left; } try { result = partition(result, new FastProgressReporter()); } catch (InterruptedException e) { } if (result == -1) { result = nextUnsorted[subTree]; } else { int unsorted = nextUnsorted[subTree]; nextUnsorted[result] = unsorted; int additionalNodes = 0; if (unsorted != -1) { parentTree[unsorted] = result; additionalNodes = treeSize[unsorted]; } treeSize[result] += additionalNodes; } } replaceNode(subTree, result); destroyNode(subTree); return result; } // Find the edges that lead to the next-smallest and // next-largest nodes Edge nextSmallest = new Edge(subTree, DIR_LEFT); while (!nextSmallest.isNull()) { nextSmallest.advance(DIR_RIGHT); } Edge nextLargest = new Edge(subTree, DIR_RIGHT); while (!nextLargest.isNull()) { nextLargest.advance(DIR_LEFT); } // Index of the replacement node int replacementNode = -1; // Count of number of nodes moved to the right int leftSize = getSubtreeSize(left); int rightSize = getSubtreeSize(right); // Swap with a child from the larger subtree if (leftSize > rightSize) { replacementNode = nextSmallest.getStart(); // Move any unsorted nodes that are larger than the replacement node into // the left subtree of the next-largest node Edge unsorted = new Edge(replacementNode, DIR_UNSORTED); while (!unsorted.isNull()) { int target = unsorted.getTarget(); if (!isLess(target, replacementNode)) { unsorted.setTarget(nextUnsorted[target]); nextLargest.setTarget(addUnsorted(nextLargest.getTarget(), target)); } else { unsorted.advance(DIR_UNSORTED); } } forceRecomputeTreeSize(unsorted.getStart(), replacementNode); forceRecomputeTreeSize(nextLargest.getStart(), subTree); } else { replacementNode = nextLargest.getStart(); // Move any unsorted nodes that are smaller than the replacement node into // the right subtree of the next-smallest node Edge unsorted = new Edge(replacementNode, DIR_UNSORTED); while (!unsorted.isNull()) { int target = unsorted.getTarget(); if (isLess(target, replacementNode)) { unsorted.setTarget(nextUnsorted[target]); nextSmallest.setTarget(addUnsorted(nextSmallest.getTarget(), target)); } else { unsorted.advance(DIR_UNSORTED); } } forceRecomputeTreeSize(unsorted.getStart(), replacementNode); forceRecomputeTreeSize(nextSmallest.getStart(), subTree); } // Now all the affected treeSize[...] elements should be updated to reflect the // unsorted nodes that moved. Swap nodes. Object replacementContent = contents[replacementNode]; contents[replacementNode] = contents[subTree]; contents[subTree] = replacementContent; if (objectIndices != null) { objectIndices.put(replacementContent, subTree); // Note: currently we don't bother updating the index of the replacement // node since we're going to remove it immediately afterwards and there's // no good reason to search for the index in a method that was given the // index as a parameter... // objectIndices.put(contents[replacementNode], replacementNode) } int replacementParent = parentTree[replacementNode]; replaceNode(replacementNode, removeNode(replacementNode)); // Edge parentEdge = getEdgeTo(replacementNode); // parentEdge.setTarget(removeNode(replacementNode)); forceRecomputeTreeSize(replacementParent, subTree); recomputeTreeSize(subTree); // testInvariants(); return subTree; }
/** * Get the first successor reachable from given edge type. * * @param source the source block * @param edgeType the edge type leading to the successor * @return the successor, or null if there is no outgoing edge with the specified edge type */ public BasicBlock getSuccessorWithEdgeType(BasicBlock source, @Type int edgeType) { Edge edge = getOutgoingEdgeWithType(source, edgeType); return edge != null ? edge.getTarget() : null; }
/** * Derive the split components of this palm tree. This method is taken from the paper of Gutwenger * and Mutzel "A linear time implementation of SPQR trees". UPDATE: This is more taken from the * OGDF C++ implementation since the paper hides a lot of necessary information. * * @param v the start node */ private void pathSearch(Node v) { // System.err.println("BEGIN pS(" + v + ");" ); int vnum = NEWNUM.get(v); int wnum; int y = 0; int a, b; IterableAdjacencyList adj = ADJ.get(v); adj.reset(); Node w; int outv = adj.size(); while (adj.hasNext()) { Edge e = adj.next(); // System.err.println("CURRENT EDGE: " + e); w = e.getTarget(); wnum = NEWNUM.get(w); if (TYPE.get(e).equals(ArcType.TREE)) { if (START.get(e)) { y = 0; if (tStackGetTopA() > LOWPT1.get(w)) { do { y = Math.max(y, tStackGetTopH()); b = tStackGetTopB(); TSTACK.pop(); } while (tStackGetTopA() > LOWPT1.get(w)); Triple t = new Triple(Math.max(y, wnum + ND.get(w) - 1), LOWPT1.get(w), b); TSTACK.push(t); // System.err.println("TSTACK push 1: " + t); } else { Triple t = new Triple(wnum + ND.get(w) - 1, LOWPT1.get(w), vnum); TSTACK.push(t); // System.err.println("TSTACK push 2: " + t); } tStackPushEos(); } pathSearch(w); ESTACK.push(TREE_ARC.get(w)); // System.err.println("TSTACK: " + TSTACK); // System.err.println("CURRENT VNUM: " + vnum); // System.err.println("DEG(w): " + DEGREE.get(w)); // check for type 2 pairs while (vnum != 1 && ((tStackGetTopA() == vnum) || (DEGREE.get(w) == 2 && NEWNUM.get(firstChild(w)) > wnum))) { a = tStackGetTopA(); b = tStackGetTopB(); Edge eVirt = null; if (a == vnum && FATHER.get(NODEAT[b]) == NODEAT[a]) { TSTACK.pop(); } else { Edge e_ab = null; Node x = null; // System.err.println("W: " + w); // System.err.println("DEG(W): " + DEGREE.get(w) ); if (DEGREE.get(w) == 2 && NEWNUM.get(firstChild(w)) > wnum) { // System.err.println("FOUND type-2 pair " + v + " , " + // firstChild(w)); // System.err.println("ESTACK: " + ESTACK); Edge e1 = ESTACK.pop(); Edge e2 = ESTACK.pop(); ADJ.get(e2.getSource()).remove(e2); ADJ.get(e1.getSource()).remove(e1); x = e2.getTarget(); // System.err.println("X:" + x); decrementDegree(x); decrementDegree(v); eVirt = new Edge(0, v, x); eVirt.setVirtual(true); SplitComponent sc = new SplitComponent(); sc.add(e1); sc.add(e2); sc.add(eVirt); sc.setType(ComponentType.POLYGON); splitComponents.add(sc); // System.err.println("COMP1: " + sc); // System.err.println("ESTACK: " + ESTACK); if (!ESTACK.empty() && ESTACK.peek().getSource() == x && ESTACK.peek().getTarget() == v) { e_ab = ESTACK.pop(); ADJ.get(x).remove(e_ab); delHigh(e_ab); } } else { // System.err.println("ESTACK: " + ESTACK); // System.err.println("FOUND type-2 pair " + NODEAT[a] + " // , " + NODEAT[b]); int h = TSTACK.peek().h; TSTACK.pop(); SplitComponent sc = new SplitComponent(); while (true) { Edge xy = ESTACK.peek(); x = xy.getSource(); if (!(a <= NEWNUM.get(x) && NEWNUM.get(x) <= h && a <= NEWNUM.get(xy.getTarget()) && NEWNUM.get(xy.getTarget()) <= h)) { break; } if ((NEWNUM.get(x) == a && NEWNUM.get(xy.getTarget()) == b) || (NEWNUM.get(xy.getTarget()) == a && NEWNUM.get(x) == b)) { e_ab = ESTACK.pop(); ADJ.get(e_ab.getSource()).remove(e_ab); delHigh(e_ab); } else { Edge eh = ESTACK.pop(); if (e != eh) { ADJ.get(eh.getSource()).remove(eh); delHigh(eh); } sc.add(eh); decrementDegree(x); decrementDegree(xy.getTarget()); } } eVirt = new Edge(0, NODEAT[a], NODEAT[b]); eVirt.setVirtual(true); sc.add(eVirt); sc.finishTriconnectedOrPolygon(); splitComponents.add(sc); // System.err.println("COMP2: " + sc); x = NODEAT[b]; } if (e_ab != null) { SplitComponent sc = new SplitComponent(); sc.setType(ComponentType.BOND); sc.add(e_ab); sc.add(eVirt); eVirt = new Edge(0, v, x); eVirt.setVirtual(true); sc.add(eVirt); splitComponents.add(sc); // System.err.println("COMP: " + sc); decrementDegree(x); decrementDegree(v); } ESTACK.push(eVirt); adj.insert(eVirt); START.put(eVirt, START.get(e)); incrementDegree(x); incrementDegree(v); FATHER.put(x, v); TREE_ARC.put(x, eVirt); TYPE.put(eVirt, ArcType.TREE); w = x; wnum = NEWNUM.get(w); } } // check for type 1 pair if (LOWPT2.get(w) >= vnum && LOWPT1.get(w) < vnum && (FATHER.get(v) != m_start || outv >= 2)) { // System.err.println( "Found type-1 pair( " + v + "," + NODEAT[ // LOWPT1.get(w) ] + ")"); SplitComponent c = new SplitComponent(); Edge xy = null; int xnum, ynum; // System.err.println("ESTACK: " + ESTACK); while (!ESTACK.isEmpty()) { xy = ESTACK.peek(); xnum = NEWNUM.get(xy.getSource()); ynum = NEWNUM.get(xy.getTarget()); if (!((wnum <= xnum && xnum < wnum + ND.get(w)) || (wnum <= ynum && ynum < wnum + ND.get(w)))) { break; } ESTACK.pop(); c.add(xy); delHigh(xy); decrementDegree(xy.getSource()); ADJ.get(xy.getSource()).remove(xy); this.graphCopy.edges.remove(xy); decrementDegree(xy.getTarget()); } Edge eVirt = new Edge(0, v, NODEAT[LOWPT1.get(w)]); eVirt.setVirtual(true); this.graphCopy.addEdge(eVirt); c.add(eVirt); c.finishTriconnectedOrPolygon(); splitComponents.add(c); // System.err.println("COMP: " + c); // System.out.println("STACK HERE: " + ESTACK); if ( /*!ESTACK.isEmpty() && */ (xy.getSource() == v && xy.getTarget() == NODEAT[LOWPT1.get(w)]) || (xy.getTarget() == v && xy.getSource() == NODEAT[LOWPT1.get(w)])) { SplitComponent sc = new SplitComponent(); sc.setType(ComponentType.BOND); Edge eh = ESTACK.pop(); if (eh != e) { ADJ.get(eh.getSource()).remove(eh); } sc.add(eh); ADJ.get(eh.getSource()).remove(eh); this.graphCopy.edges.remove(eh); decrementDegree(eh.getSource()); decrementDegree(eh.getTarget()); sc.add(eVirt); eVirt = new Edge(0, v, NODEAT[LOWPT1.get(w)]); eVirt.setVirtual(true); // BLOCK IN OGDF left out --> m_IN_HIGH sc.add(eVirt); splitComponents.add(sc); // System.err.println("COMP: " + sc ); } if ((NODEAT[LOWPT1.get(w)] != FATHER.get(v))) { ESTACK.push(eVirt); adj.insert(eVirt); START.put(eVirt, false); TYPE.put(eVirt, ArcType.FROND); if (high(NODEAT[LOWPT1.get(w)]) < vnum) HIGHPT.get(NODEAT[LOWPT1.get(w)]).add(0, vnum); incrementDegree(v); incrementDegree(NODEAT[LOWPT1.get(w)]); } else { adj.remove(e); // BLOCK from OGDF --> Adj.del(it); SplitComponent sc = new SplitComponent(); sc.setType(ComponentType.BOND); sc.add(eVirt); Edge eh = TREE_ARC.get(v); sc.add(eh); splitComponents.add(sc); ADJ.get(eh.getSource()).remove(eh); eVirt = new Edge(0, NODEAT[LOWPT1.get(w)], v); eVirt.setVirtual(true); sc.add(eVirt); // System.err.println("COMP: " + sc); TYPE.put(eVirt, ArcType.TREE); // System.out.println("INSERT HERE into " + eh.getSource() + // "TARGET: " + eh.getTarget()); ADJ.get(eh.getSource()).insert(eVirt); TREE_ARC.put(v, eVirt); START.put(eVirt, START.get(eh)); } } if (START.get(e)) { while (tStackNotEos()) { TSTACK.pop(); } TSTACK.pop(); } while (tStackNotEos() && tStackGetTopA() != vnum && tStackGetTopB() != vnum && high(v) > tStackGetTopH()) { TSTACK.pop(); } outv--; } else { // frond arc // System.err.println("TSTACK 2: " + TSTACK); if (START.get(e)) { y = 0; if (tStackGetTopA() > LOWPT1.get(w)) { do { y = Math.max(y, tStackGetTopH()); b = tStackGetTopB(); TSTACK.pop(); } while (tStackGetTopA() > LOWPT1.get(w)); Triple t = new Triple(y, wnum, b); TSTACK.push(t); // System.err.println("TSTACK push3: " + t); } else { Triple t = new Triple(vnum, wnum, vnum); TSTACK.push(new Triple(vnum, wnum, vnum)); // System.err.println("TSTACK push4: " + t); } // tStackPushEos(); } // BLOCK FROM PAPER left out --> if ( w = parent(v) ) ESTACK.push(e); } } // System.err.println("END pS(" + v + ");" ); }
/** * This untangles the nodes so that they will will fall on the correct side of the other nodes * along their row. */ private void untangle2() { Ease a; Edge e; Node r, nf = null, ns = null, mark; int l = 0, times = 0; int f, s, tf = 0, ts = 0, pf, ps; while ((a = overlap(l)) != null) { times++; // System.out.println("from untang 2 " + group_num); f = a.m_place; s = a.m_place + 1; while (f != s) { a.m_lev--; tf = f; ts = s; f = m_groups[f].m_pg; s = m_groups[s].m_pg; } l = a.m_lev; pf = 0; ps = 0; r = m_groups[f].m_p; mark = m_groups[tf].m_p; nf = null; ns = null; for (int noa = 0; nf != mark; noa++) { pf++; nf = r.getChild(noa).getTarget(); } mark = m_groups[ts].m_p; for (int noa = pf; ns != mark; noa++) { ps++; // the number of gaps between the two nodes ns = r.getChild(noa).getTarget(); } // m_groups[f].gap = // Math.ceil((a.amount / (double)ps) + m_groups[f].gap); // note for this method i do not need the group gap ,but i will leave // it for the other methods; Vector o_pos = new Vector(20, 10); for (int noa = 0; (e = r.getChild(noa)) != null; noa++) { if (e.getTarget().getParent(0) == e) { Double tem = new Double(e.getTarget().getCenter()); o_pos.addElement(tem); } } pf--; double inc = a.m_amount / (double) ps; for (int noa = 0; (e = r.getChild(noa)) != null; noa++) { ns = e.getTarget(); if (ns.getParent(0) == e) { if (noa > pf + ps) { ns.adjustCenter(a.m_amount); } else if (noa > pf) { ns.adjustCenter(inc * (double) (noa - pf)); } } } nf = r.getChild(0).getTarget(); inc = ns.getCenter() - nf.getCenter(); m_groups[f].m_size = inc; m_groups[f].m_left = r.getCenter() - inc / 2; m_groups[f].m_right = m_groups[f].m_left + inc; inc = m_groups[f].m_left - nf.getCenter(); double shift; int g_num = 0; for (int noa = 0; (e = r.getChild(noa)) != null; noa++) { ns = e.getTarget(); if (ns.getParent(0) == e) { ns.adjustCenter(inc); shift = ns.getCenter() - ((Double) o_pos.elementAt(noa)).doubleValue(); if (ns.getChild(0) != null) { moveSubtree(m_groups[f].m_start + g_num, shift); g_num++; } } // ns.adjustCenter(-shift); } // zero_offset(r); // x_placer(f); } }
/** * If this is a resource that is available, and this user has access to it, this method sets the * URI. */ private void setURI(String userID) { if ((userID == null) || (!(node instanceof SGNode))) return; // only do this for SGNodes SGNode n = (SGNode) node; List<Edge> list = n.getOutgoingEdges("HasURI"); if (list.size() > 0) { SGStringNode target = (SGStringNode) list.get(0).getTarget(); uri = (String) target.getValue(); } if (uri == null) return; // if there is no URI, we are done list = n.getOutgoingEdges("AccessConditions"); if (list.size() == 0) { System.out.println("Could not find access rights to node " + n.getNLLabel(reader)); uri = null; return; // assume that access must be public, if unspecified } String access = (String) ((SGStringNode) list.get(0).getTarget()).getValue(); if (access.equals("public")) return; // everyone has access to a public resource SGNode depositor = n.getPropertyTarget("DepositedBy", reader); if ((depositor != null) && userID.equals(depositor.getUniqueID())) return; // depositor has access to all his resources if (access.equals("restricted to project members")) // access restricted to project members { // find out which project the resource is associated with SGNode project = n.getPropertyTarget("ProducedInProject", reader); if (project != null) { // find out if this user is a member List<String> subprops = reader.getSubProperties("HasMember"); for (Iterator it = project.getOutgoingEdges(); it.hasNext(); ) { SGEdge edge = (SGEdge) it.next(); if (subprops.contains(edge.getLabel()) && userID.equals(edge.getTarget().getUniqueID())) { System.out.println( "FOUND MEMBER OF PROJECT " + project.getNLLabel(reader) + ": " + edge.getTarget().getNLLabel(reader)); return; } } subprops = reader.getSubProperties("MemberOf"); for (Iterator it = project.getIncomingEdges(); it.hasNext(); ) { SGEdge edge = (SGEdge) it.next(); if (subprops.contains(edge.getLabel()) && userID.equals(edge.getSource().getUniqueID())) { System.out.println( "FOUND MEMBER OF PROJECT " + project.getNLLabel(reader) + ": " + edge.getSource().getNLLabel(reader)); return; } } } } else if (access.equals("restricted to authors")) { for (Edge edge : n.getOutgoingEdges("HasAuthor")) { if (userID.equals(((SGNode) edge.getTarget()).getUniqueID())) return; } for (Edge edge : n.getIncomingEdges("AuthorOf")) { if (userID.equals(((SGNode) edge.getSource()).getUniqueID())) return; } } uri = null; // in all other cases, the user should not have access to the resource }