public static <T> List<T> getChildren(DirectedGraph g, T n) { List<IndexedEdge> outgoing = new ArrayList(g.outgoingEdgesOf(n)); List<T> ret = new ArrayList(); for(IndexedEdge e: outgoing) { ret.add((T)e.target); } return ret; }
/** * Converts the flowStep that generated from cascading to a Map of DAGNode and its name to be used * to build Ambrose Graph. */ public void convert() { // returns a set of the nodes contained in this graph Set vertices = jobsGraph.vertexSet(); // create ambrose nodes for (Object vertex : vertices) { BaseFlowStep step = (BaseFlowStep) vertex; CascadingJob job = new CascadingJob(); job.setFeatures(getNodeFeatures(step)); String name = step.getName(); DAGNode<CascadingJob> node = new DAGNode<CascadingJob>(name, job); dagNamesMap.put(name, node); } // loop again to set the successors for each node after nodes are created for (Object vertex : vertices) { BaseFlowStep step = (BaseFlowStep) vertex; String name = step.getName(); DAGNode<CascadingJob> node = dagNamesMap.get(name); node.setSuccessors(getNodeSuccessors(vertex)); } }
fragments.forEach(fragment -> graph.addVertex(fragment.getId())); for (DefaultEdge edge : graph.edgeSet()) { PlanFragmentId source = graph.getEdgeSource(edge); PlanFragmentId target = graph.getEdgeTarget(edge); componentGraph.addEdge(from, to);
/** * 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)); } }
Preconditions.checkArgument(graph.containsVertex(source), "Source not found in graph"); int vertCount = graph.vertexSet().size(); int edgeCount = graph.edgeSet().size(); Set<A> verticesToRemove = new HashSet<A>(graph.vertexSet()); verticesToRemove.removeAll(reachableFromSource(graph, source)); for (B edge : graph.incomingEdgesOf(b)) { if (verticesToRemove.contains(graph.getEdgeSource(edge))) { egdesToRemove.add(edge); for (B edge : graph.outgoingEdgesOf(b)) { if (verticesToRemove.contains(graph.getEdgeTarget(edge))) { egdesToRemove.add(edge); graph.removeAllVertices(verticesToRemove); graph.removeAllEdges(egdesToRemove); return !(vertCount == graph.vertexSet().size() && edgeCount == graph.edgeSet().size());
private void addEdges(Set<PlanFragmentId> sourceFragments, Set<PlanFragmentId> targetFragments) { for (PlanFragmentId targetFragment : targetFragments) { for (PlanFragmentId sourceFragment : sourceFragments) { graph.addEdge(sourceFragment, targetFragment); } } } }
/** * Goes over the {@code innerComponents} collection checking if any reference is a {@link MacroExpansionModuleModel#TNS_PREFIX}, * in which case it adds an edge to the current vertex {@code sourceOperationVertex} * * @param directedGraph graph to contain all the vertex operations and linkage with other operations * @param sourceOperationVertex current vertex we are working on * @param innerComponents collection of elements to introspect and assembly the graph with */ private void fillGraphWithTnsReferences(DirectedGraph<String, DefaultEdge> directedGraph, String sourceOperationVertex, final List<ComponentModel> innerComponents) { innerComponents.forEach(childMPComponentModel -> { if (TNS_PREFIX.equals(childMPComponentModel.getIdentifier().getNamespace())) { // we will take the current component model name, as any child of it are actually TNS child references (aka: parameters) final String targetOperationVertex = childMPComponentModel.getIdentifier().getName(); if (!directedGraph.containsVertex(targetOperationVertex)) { directedGraph.addVertex(targetOperationVertex); } directedGraph.addEdge(sourceOperationVertex, targetOperationVertex); } else { // scenario for nested scopes that might be having cyclic references to operations childMPComponentModel.getInnerComponents() .forEach(childChildMPComponentModel -> fillGraphWithTnsReferences(directedGraph, sourceOperationVertex, childMPComponentModel.getInnerComponents())); } }); }
private void extractOperationExtension(HasOperationDeclarer declarer, ComponentModel operationModel, DirectedGraph<String, DefaultEdge> directedGraph, XmlDslModel xmlDslModel) { String operationName = operationModel.getNameAttribute(); OperationDeclarer operationDeclarer = declarer.withOperation(operationName); ComponentModel bodyComponentModel = operationModel.getInnerComponents() .stream() .filter(child -> child.getIdentifier().equals(OPERATION_BODY_IDENTIFIER)).findFirst() .orElseThrow(() -> new IllegalArgumentException(format("The operation '%s' is missing the <body> statement", operationName))); directedGraph.addVertex(operationName); fillGraphWithTnsReferences(directedGraph, operationName, bodyComponentModel.getInnerComponents()); operationDeclarer.withModelProperty(new OperationComponentModelModelProperty(operationModel, bodyComponentModel)); operationDeclarer.describedAs(getDescription(operationModel)); operationDeclarer.getDeclaration().setDisplayModel(getDisplayModel(operationModel)); extractOperationParameters(operationDeclarer, operationModel); extractOutputType(operationDeclarer.withOutput(), OPERATION_OUTPUT_IDENTIFIER, operationModel, getDeclarationOutputFor(operationName)); extractOutputType(operationDeclarer.withOutputAttributes(), OPERATION_OUTPUT_ATTRIBUTES_IDENTIFIER, operationModel, getDeclarationOutputAttributesFor(operationName)); declareErrorModels(operationDeclarer, xmlDslModel, operationName, operationModel); }
@Override public void add(MethodGraph element, MethodGraph parent) { if (element.equals(parent)) { return; } directedGraph.addVertex(element); directedGraph.addVertex(parent); directedGraph.addEdge(parent, element); if (findCycles(element)) { directedGraph.removeEdge(parent, element); } }
private void replaceVertex(JavaClass newClass) { List<JavaClass> incomingEdges = getParents(newClass); graph.removeVertex(newClass); graph.addVertex(newClass); for (JavaClass each : incomingEdges) { graph.addEdge(each, newClass); } }
/** {@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(); }
protected List<String> getEndVertices() { final List<String> endVertices = new ArrayList<>(); Set<String> vertices = _directedGraph.vertexSet(); for (String vertex : vertices) { Set<UpgradeProcessEdge> upgradeProcessEdges = _directedGraph.outgoingEdgesOf(vertex); if (upgradeProcessEdges.isEmpty()) { endVertices.add(vertex); } } return endVertices; }
public static Set<LabeledLink> getDomainLinksInLabeledGraph(DirectedGraph<Node, LabeledLink> g, ColumnNode n) { Set<LabeledLink> domainLinks = new HashSet<>(); if (g == null || n == null || !g.vertexSet().contains(n)) return domainLinks; Set<LabeledLink> incomingLinks = g.incomingEdgesOf(n); if (incomingLinks != null) { for (DefaultLink l : incomingLinks) { domainLinks.add((LabeledLink)l); } } return domainLinks; }
private void updateParentReferences(JavaClass parentClass) { for (String child : parentClass.getImports()) { JavaClass childClass = findJavaClass(child); if ((childClass != null) && !childClass.equals(parentClass)) { if (graph.containsVertex(childClass)) { graph.addEdge(parentClass, childClass); } } } }
/** * Fetch all of the dependencies of the given source vertex * @return mutable snapshot of the target vertices of all outgoing edges */ public static <V> Set<V> getOutgoingVertices(DirectedGraph<V, DefaultEdge> graph, V source) { Set<DefaultEdge> edges = graph.outgoingEdgesOf(source); Set<V> targets = new LinkedHashSet<V>(); for (DefaultEdge edge : edges) { targets.add(graph.getEdgeTarget(edge)); } return targets; }
/** * 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; }
/** * @param clickable * the edge. * @return the target state of this edge. */ public StateVertex getTargetState(Eventable clickable) { return sfg.getEdgeTarget(clickable); }
/** * Assumes edge contains an index */ public static <T> List<T> getParents(DirectedGraph g, T n) { List<IndexedEdge> incoming = new ArrayList(g.incomingEdgesOf(n)); Collections.sort(incoming); List<T> ret = new ArrayList(); for(IndexedEdge e: incoming) { ret.add((T)e.source); } return ret; }
/** * 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); } }