private void addEdges(Set<PlanFragmentId> sourceFragments, Set<PlanFragmentId> targetFragments) { for (PlanFragmentId targetFragment : targetFragments) { for (PlanFragmentId sourceFragment : sourceFragments) { graph.addEdge(sourceFragment, targetFragment); } } } }
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; }
/** * 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; }
DirectedGraph<PlanFragmentId, DefaultEdge> graph = new DefaultDirectedGraph<>(DefaultEdge.class); fragments.forEach(fragment -> graph.addVertex(fragment.getId())); List<Set<PlanFragmentId>> components = new StrongConnectivityInspector<>(graph).stronglyConnectedSets(); DirectedGraph<Set<PlanFragmentId>, DefaultEdge> componentGraph = new DefaultDirectedGraph<>(DefaultEdge.class); components.forEach(componentGraph::addVertex); for (DefaultEdge edge : graph.edgeSet()) { PlanFragmentId source = graph.getEdgeSource(edge); PlanFragmentId target = graph.getEdgeTarget(edge); componentGraph.addEdge(from, to); List<Set<PlanFragmentId>> schedulePhases = ImmutableList.copyOf(new TopologicalOrderIterator<>(componentGraph)); return schedulePhases;
DirectedGraph graph = new DefaultDirectedGraph<BaseFlowStep, FlowGraphEdge>( new EdgeFactory<BaseFlowStep, FlowGraphEdge>() { @Override graph.addVertex(v); graph.addEdge(e.getSourceProcessID(), e.getSinkProcessID());
/** * 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 fillDependencyGraph(DirectedGraph<String, DefaultEdge> g, String sourceVertex, Map<String, ExtensionModel> allExtensionsByNamespace) { final ExtensionModel extensionModel = allExtensionsByNamespace.get(sourceVertex); g.addVertex(sourceVertex); for (String dependencyNamespace : getDependenciesOrFail(extensionModel)) { if (allExtensionsByNamespace.containsKey(dependencyNamespace)) { g.addVertex(dependencyNamespace); g.addEdge(sourceVertex, dependencyNamespace); fillDependencyGraph(g, dependencyNamespace, allExtensionsByNamespace); } } }
private static Map<Group, Integer> getGroupParallelisms(DirectedGraph<Node, IndexedEdge> graph, GraphGrouper grouper, Collection<Group> groups) { UndirectedGraph<Group, Object> equivs = new Pseudograph<>(Object.class); for(Group g: groups) { equivs.addVertex(g); Group parentGroup = grouper.nodeGroup(parent); if(parentGroup!=null && !parentGroup.equals(g)) { equivs.addEdge(parentGroup, g); List<Set<Group>> equivGroups = new ConnectivityInspector<>(equivs).connectedSets(); for(Set<Group> equivGroup: equivGroups) { Integer fixedP = getFixedParallelism(equivGroup);
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); }
private void addType(ErrorTypeDefinition<?> errorType, Graph<ErrorTypeDefinition, Pair<ErrorTypeDefinition, ErrorTypeDefinition>> graph) { graph.addVertex(errorType); String type = errorType.getType(); if (!ANY.name().equals(type) && !CRITICAL.name().equals(type)) { ErrorTypeDefinition parentErrorType = errorType.getParent().orElse((ANY)); graph.addVertex(parentErrorType); graph.addEdge(errorType, parentErrorType); } }
public static Set outgoingEdgesOf(Graph g, Object node) { if (g instanceof DirectedGraph) { return ((DirectedGraph) g).outgoingEdgesOf(node); } else { return g.edgesOf(node); } }
/** * 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)); } }
/** * Return a Collection of successor nodes of a certain vertex. * * @param vertex the step or node its successors nodes will be returned. * @return collection of successor DAGNodes for each node. */ protected Collection<DAGNode<? extends Job>> getNodeSuccessors(Object vertex) { Collection<DAGNode<? extends Job>> nodeSuccessors = Sets.newHashSet(); List successorNodes = Graphs.successorListOf(jobsGraph, vertex); for (Object node : successorNodes) { BaseFlowStep step = (BaseFlowStep) node; String name = step.getName(); nodeSuccessors.add(dagNamesMap.get(name)); } return nodeSuccessors; } }
/** * Constructor for AsWeightedGraph where the weights are provided through a map. Invocations of * the @link{setEdgeWeight} method will update the map. Moreover, calls to @link{setEdgeWeight} * are propagated to the underlying graph. * * @param graph the backing graph over which a weighted view is to be created. * @param weights the map containing the edge weights. * @throws NullPointerException if the graph or the weights are null. */ public AsWeightedGraph(Graph<V, E> graph, Map<E, Double> weights) { this(graph, weights, graph.getType().isWeighted()); }
/** * Constructor * * @param graph the input graph */ public AbstractFundamentalCycleBasis(Graph<V, E> graph) { this.graph = GraphTests.requireDirectedOrUndirected(graph); }
/** * Create a simple cycle finder for the specified graph. * * @param graph - the DirectedGraph in which to find cycles. * * @throws IllegalArgumentException if the graph argument is <code> * null</code>. */ public SzwarcfiterLauerSimpleCycles(Graph<V, E> graph) { this.graph = GraphTests.requireDirected(graph, "Graph must be directed"); }
private static void addEdge(DirectedGraph g, Object source, Object target, int index) { g.addEdge(source, target, new IndexedEdge(source, target, index)); }
/** * Return a Collection of successor nodes of a certain vertex. * * @param vertex the step or node its successors nodes will be returned. * @return collection of successor DAGNodes for each node. */ protected Collection<DAGNode<? extends Job>> getNodeSuccessors(Object vertex) { Collection<DAGNode<? extends Job>> nodeSuccessors = Sets.newHashSet(); List successorNodes = Graphs.successorListOf(jobsGraph, vertex); for (Object node : successorNodes) { BaseFlowStep step = (BaseFlowStep) node; String name = step.getName(); nodeSuccessors.add(dagNamesMap.get(name)); } return nodeSuccessors; } }
private Set<PlanFragmentId> processJoin(PlanNode build, PlanNode probe, PlanFragmentId currentFragmentId) { Set<PlanFragmentId> buildSources = build.accept(this, currentFragmentId); Set<PlanFragmentId> probeSources = probe.accept(this, currentFragmentId); for (PlanFragmentId buildSource : buildSources) { for (PlanFragmentId probeSource : probeSources) { graph.addEdge(buildSource, probeSource); } } return ImmutableSet.<PlanFragmentId>builder() .addAll(buildSources) .addAll(probeSources) .build(); }
@Override public Set<PlanFragmentId> visitRemoteSource(RemoteSourceNode node, PlanFragmentId currentFragmentId) { ImmutableSet.Builder<PlanFragmentId> sources = ImmutableSet.builder(); Set<PlanFragmentId> previousFragmentSources = ImmutableSet.of(); for (PlanFragmentId remoteFragment : node.getSourceFragmentIds()) { // this current fragment depends on the remote fragment graph.addEdge(currentFragmentId, remoteFragment); // get all sources for the remote fragment Set<PlanFragmentId> remoteFragmentSources = processFragment(remoteFragment); sources.addAll(remoteFragmentSources); // For UNION there can be multiple sources. // Link the previous source to the current source, so we only // schedule one at a time. addEdges(previousFragmentSources, remoteFragmentSources); previousFragmentSources = remoteFragmentSources; } return sources.build(); }