components.forEach(componentGraph::addVertex); for (DefaultEdge edge : graph.edgeSet()) { PlanFragmentId source = graph.getEdgeSource(edge); PlanFragmentId target = graph.getEdgeTarget(edge);
@Override public T valueOf(DefaultEdge e) { return graph.getEdgeSource(e); } });
@Override public T valueOf(DefaultEdge e) { return graph.getEdgeSource(e); } });
public ExecutableMethod getEdgeSource(DirectedEdge<ExecutableMethod> e) { return graph.getEdgeSource(e); }
public ExecutableMethod getEdgeSource(DirectedEdge<ExecutableMethod> e) { return graph.getEdgeSource(e); }
/** * Fetch all of the dependents of the given target vertex * @return mutable snapshot of the source vertices of all incoming edges */ public static <V> Set<V> getIncomingVertices(DirectedGraph<V, DefaultEdge> graph, V target) { Set<DefaultEdge> edges = graph.incomingEdgesOf(target); Set<V> sources = new LinkedHashSet<V>(); for (DefaultEdge edge : edges) { sources.add(graph.getEdgeSource(edge)); } return sources; }
/** * <p>getEdgeSource</p> * * @param e a E object. * @return a V object. */ public V getEdgeSource(E e) { if (!containsEdge(e)) throw new IllegalArgumentException("edge not in graph"); return graph.getEdgeSource(e); }
@Override public Pair<T, E> valueOf(E edge) { return Tuples.pair(graph.getEdgeSource(edge), edge); } });
/** * @param pageID The pageID of the category. * @return A set of parent nodes of the given category. */ protected Set<Integer> __getParents(int pageID) { Set<DefaultEdge> incomingEdges = graph.incomingEdgesOf(pageID); Set<Integer> inLinks = new HashSet<Integer>(); for (DefaultEdge edge : incomingEdges) { inLinks.add(graph.getEdgeSource(edge)); } return inLinks; }
@Override public Pair<T, E> valueOf(E edge) { return Tuples.pair(graph.getEdgeSource(edge), edge); } });
/** * Gives all the rules that depends on the input <code>rule</code> * @param rule * @return */ public List<CQIE> getFatherRules(CQIE rule){ Set<DefaultEdge> fatherEdges = ruleDependencyGraph.incomingEdgesOf(rule); List<CQIE> fatherRules = Lists.newArrayListWithCapacity(fatherEdges.size()); for(DefaultEdge edge : fatherEdges){ fatherRules.add(ruleDependencyGraph.getEdgeSource(edge)); } return fatherRules; }
/** {@inheritDoc} */ @Override public String toString() { StringBuffer sb = new StringBuffer(); for (ControlFlowEdge e : graph.edgeSet()) { sb.append(graph.getEdgeSource(e) + " -> " + graph.getEdgeTarget(e)); sb.append("\n"); } return sb.toString(); }
/** * Gives you the predicate that is defined using <code>pred</code> * @param pred * @return */ public List<Predicate> getFatherPredicates(Predicate pred){ Set<DefaultEdge> fatherEdges = predicateDependencyGraph.incomingEdgesOf(pred); List<Predicate> fathers = new LinkedList<Predicate>(); for (DefaultEdge fatherEdge: fatherEdges){ Predicate father = predicateDependencyGraph.getEdgeSource(fatherEdge); fathers.add(father); } //= fatherEdges.iterator().next(); return fathers; }
public static void renderDirected(DirectedGraph graph, String fileName) throws IOException { try (PrintStream out = new PrintStream(new FileOutputStream(fileName))) { out.println("digraph G {"); for (Object e : graph.edgeSet()) { out.println("\t" + graph.getEdgeSource(e) + " -> " + graph.getEdgeTarget(e)); } out.println("}"); } } }
private void collapseCycle(Set<ATermAppl> scc) { Iterator<ATermAppl> i = scc.iterator(); ATermAppl rep = i.next(); while( i.hasNext() ) { ATermAppl node = i.next(); addEquivalent( rep, node ); for( DefaultEdge edge : graph.incomingEdgesOf( node ) ) { ATermAppl incoming = graph.getEdgeSource( edge ); if( !incoming.equals( rep ) ) graph.addEdge( incoming, rep ); } for( DefaultEdge edge : graph.outgoingEdgesOf( node ) ) { ATermAppl outgoing = graph.getEdgeTarget( edge ); if( !outgoing.equals( rep ) ) graph.addEdge( rep, outgoing ); } graph.removeVertex( node ); } }
@Override public void edgeTraversed(final EdgeTraversalEvent<DefaultEdge> e) { final IServiceDAGVertex<?> dagSource = traversedGraph.getEdgeSource(e.getEdge()); final IServiceDAGVertex<?> dagTarget = traversedGraph.getEdgeTarget(e.getEdge()); final Collection<IServiceTreeVertex<?>> treeParents = findVisitedDAGVertices(dagSource); treeParents.forEach(treeParent -> addTreeVertex(treeParent, dagTarget)); }
public void destructiveTopologocialSort(List<ATermAppl> nodesSorted) { Queue<ATermAppl> nodesPending = createQueue(); for( ATermAppl node : graph.vertexSet() ) { if( graph.outDegreeOf( node ) == 0 ) nodesPending.add( node ); } while( !nodesPending.isEmpty() ) { ATermAppl node = nodesPending.remove(); assert graph.outDegreeOf( node ) == 0; nodesSorted.addAll( getAllEquivalents( node ) ); for( DefaultEdge edge : graph.incomingEdgesOf( node ) ) { ATermAppl source = graph.getEdgeSource( edge ); if( graph.outDegreeOf( source ) == 1 ) nodesPending.add( source ); } graph.removeVertex( node ); } assert graph.vertexSet().isEmpty() : "Failed to sort elements: " + graph.vertexSet(); } }
/** * Copy the source graph into the target graph */ public static <V> void copyGraph(DirectedGraph<V, DefaultEdge> sourceGraph, DirectedGraph<V, DefaultEdge> targetGraph) { addAllVertices(targetGraph, sourceGraph.vertexSet()); for (DefaultEdge edge : sourceGraph.edgeSet()) { targetGraph.addEdge(sourceGraph.getEdgeSource(edge), sourceGraph.getEdgeTarget(edge)); } }
public Method createMethodFromSubgraph(DirectedGraph<CfgBlock, CfgEdge> subgraph, String newMethodName) { Preconditions.checkArgument(vertexSet().containsAll(subgraph.vertexSet()), "Method does not contain all nodes from subgraph."); Method subgraphMethod = new Method(location, newMethodName, this.parameterList, this.returnTypes); for (CfgBlock v : subgraph.vertexSet()) { subgraphMethod.addVertex(v); } for (CfgEdge e : subgraph.edgeSet()) { subgraphMethod.addEdge(subgraph.getEdgeSource(e), subgraph.getEdgeTarget(e)); } subgraphMethod.initialize(thisVariable, returnVariables, locals, source, isProgramEntry); return subgraphMethod; }
/** * Removes cycles from the graph that was used to construct the cycle handler. * @throws WikiApiException Thrown if errors occurred. */ public void removeCycles() throws WikiApiException { DefaultEdge edge = null; while ((edge = findCycle()) != null) { Category sourceCat = wiki.getCategory(categoryGraph.getGraph().getEdgeSource(edge)); Category targetCat = wiki.getCategory(categoryGraph.getGraph().getEdgeTarget(edge)); logger.info("Removing cycle: " + sourceCat.getTitle() + " - " + targetCat.getTitle()); categoryGraph.getGraph().removeEdge(edge); } }