public TridentTopology() { this(new DefaultDirectedGraph<Node, IndexedEdge>(new ErrorEdgeFactory()), new LinkedHashMap<String, List<Node>>(), new UniqueIdGen()); }
DefaultDirectedGraph<Node, IndexedEdge> graph = (DefaultDirectedGraph) _graph.clone(); for(Node n: graph.vertexSet()) { if(n instanceof SpoutNode) { spoutNodes.add((SpoutNode) n); for(IndexedEdge<Node> e: new HashSet<>(graph.edgeSet())) { if(!(e.source instanceof PartitionNode) && !(e.target instanceof PartitionNode)) { Group g1 = grouper.nodeGroup(e.source); throw new RuntimeException("Planner exception: Null source group must indicate a spout node at this phase of planning"); if(g1==null || !g1.equals(g2)) { graph.removeEdge(e); PartitionNode pNode = makeIdentityPartition(e.source); graph.addVertex(pNode); graph.addEdge(e.source, pNode, new IndexedEdge(e.source, pNode, 0)); graph.addEdge(pNode, e.target, new IndexedEdge(pNode, e.target, e.index)); Node newPartitionNode = new PartitionNode(idNode.streamId, n.name, idNode.allOutputFields, n.thriftGrouping); Node parentNode = TridentUtils.getParent(graph, n); Set<IndexedEdge> outgoing = graph.outgoingEdgesOf(n); graph.removeVertex(n); graph.addVertex(idNode); graph.addVertex(newPartitionNode); addEdge(graph, parentNode, idNode, 0); addEdge(graph, idNode, newPartitionNode, 0);
private List<Annotation> getOrderedAnnotations(Method method) { DefaultDirectedGraph<Annotation, DefaultEdge> graph = new DefaultDirectedGraph<Annotation, DefaultEdge>(DefaultEdge.class); for (Annotation annotation : method.getAnnotations()) { graph.addVertex(annotation); } for (Annotation annotation : method.getAnnotations()) { Class<? extends Annotation> thisClass = annotation.annotationType(); RunAfter runAfterAnnotation = thisClass.getAnnotation(RunAfter.class); if (runAfterAnnotation != null) { for (Class<? extends Annotation> otherClass : runAfterAnnotation.value()) { graph.addEdge(method.getAnnotation(otherClass), annotation); } } RunBefore runBeforeAnnotation = thisClass.getAnnotation(RunBefore.class); if (runBeforeAnnotation != null) { for (Class<? extends Annotation> otherClass : runBeforeAnnotation.value()) { graph.addEdge(annotation, method.getAnnotation(otherClass)); } } } return getOrderedReferences(graph); }
private static DefaultDirectedGraph<DataRangeExpression,DefaultEdge> getDataRangeGraph (OntologyImpl.UnclassifiedOntologyTBox ontology, DefaultDirectedGraph<DataPropertyExpression,DefaultEdge> dataPropertyGraph) { DefaultDirectedGraph<DataRangeExpression,DefaultEdge> dataRangeGraph = new DefaultDirectedGraph<>(DefaultEdge.class); // ranges of roles for (DataPropertyExpression role : dataPropertyGraph.vertexSet()) dataRangeGraph.addVertex(role.getRange()); // edges between the ranges for sub-properties for (DefaultEdge edge : dataPropertyGraph.edgeSet()) { DataPropertyExpression child = dataPropertyGraph.getEdgeSource(edge); DataPropertyExpression parent = dataPropertyGraph.getEdgeTarget(edge); dataRangeGraph.addEdge(child.getRange(), parent.getRange()); } // data range inclusions from the ontology for (BinaryAxiom<DataRangeExpression> clsIncl : ontology.getSubDataRangeAxioms()) { dataRangeGraph.addVertex(clsIncl.getSuper()); // Datatype is not among the vertices from the start dataRangeGraph.addEdge(clsIncl.getSub(), clsIncl.getSuper()); } return dataRangeGraph; }
DefaultDirectedGraph<ObjectPropertyExpression,DefaultEdge> graph = new DefaultDirectedGraph<>(DefaultEdge.class); graph.addVertex(role); graph.addVertex(role.getInverse()); graph.addVertex(role); graph.addVertex(role.getInverse()); graph.addVertex(top); graph.addEdge(roleIncl.getSub(), roleIncl.getSuper()); graph.addEdge(roleIncl.getSub().getInverse(), roleIncl.getSuper().getInverse()); for (ObjectPropertyExpression ope : graph.vertexSet()) graph.addEdge(ope, top);
@NotNull @Override public <T> DirectedGraph<T, DefaultEdge> createSimpleDependencyGraph(@NotNull Iterable<? extends T> inputs, @NotNull Function1<? super T, ? extends Iterable<? extends T>> edgesFunction) { final DefaultDirectedGraph<T, DefaultEdge> graph = new DefaultDirectedGraph<T, DefaultEdge>(DefaultEdge.class); for (T input : inputs) { graph.addVertex(input); } for (T input : inputs) { Iterable<? extends T> targetVertices = edgesFunction.invoke(input); for (T targetVertex : targetVertices) { if (graph.containsVertex(targetVertex)) { graph.addEdge(targetVertex, input); } else { LOG.info("Problem?"); } } } return graph; }
static public <V> DefaultDirectedGraph<V, Edge<V>> getDiGraph(IMatrixBinary<V, V> source) { final SimpleEdgeFactory<V> factory = new SimpleEdgeFactory<V>(); final DefaultDirectedGraph<V, Edge<V>> g = new DefaultDirectedGraph<V, Edge<V>>(factory); for (V v1 : source.getRows()) { for (V v2 : source.getColumns()) { if (source.getBooleanValue(v1, v2)) { g.addEdge(v1, v2); } } } return g; }
private void build(Task task, ImmutableList.Builder<RunnableTaskDag> entriesBuilder, ImmutableMap.Builder<TaskId, Task> tasksBuilder) { DefaultDirectedGraph<TaskId, DefaultEdge> graph = new DefaultDirectedGraph<>(DefaultEdge.class); worker(graph, task, null, tasksBuilder, Sets.newHashSet()); CycleDetector<TaskId, DefaultEdge> cycleDetector = new CycleDetector<>(graph); if ( cycleDetector.detectCycles() ) { throw new RuntimeException("The Task DAG contains cycles: " + task); } TopologicalOrderIterator<TaskId, DefaultEdge> orderIterator = new TopologicalOrderIterator<>(graph); while ( orderIterator.hasNext() ) { TaskId taskId = orderIterator.next(); Set<DefaultEdge> taskIdEdges = graph.edgesOf(taskId); Set<TaskId> processed = taskIdEdges .stream() .map(graph::getEdgeSource) .filter(edge -> !edge.equals(taskId) && !edge.getId().equals("")) .collect(Collectors.toSet()); entriesBuilder.add(new RunnableTaskDag(taskId, processed)); } }
private void addStateNode(AGENT agent, STATE state, ITimePeriod timePeriod, ITemporalSeries<STATE> temporalSeries, STATE parentState) { // add the state node to the agent's time series. will inherently check for illegal overlaps. temporalSeries.put(timePeriod, state); // register the state in the reverse index stateAgentReverseIndex.put(state, agent); stateTimePeriodIndex.put(state, timePeriod); // add the state node to the graph graph.addVertex(state); if (parentState != null) { // the parent has a CAUSAL relationship with the child graph.addEdge(parentState, state, new CausalRelationship()); } }
protected void registerSourcedNode(List<Stream> sources, Node newNode) { registerNode(newNode); int streamIndex = 0; for(Stream s: sources) { _graph.addEdge(s._node, newNode, new IndexedEdge(s._node, newNode, streamIndex)); streamIndex++; } }
public void addEdge(V parent, V child) { tree.addVertex(parent); tree.addVertex(child); Verify.verify(tree.inDegreeOf(child)==0, "Node already has a parent: "+child); tree.addEdge(parent, child); isDirty = true; }
protected void registerNode(Node n) { _graph.addVertex(n); if(n.stateInfo!=null) { String id = n.stateInfo.id; if(!_colocate.containsKey(id)) { _colocate.put(id, new ArrayList()); } _colocate.get(id).add(n); } }
private void recomputeRootAndLeavesIfDirty() { if (isDirty) { root = null; leaves = new HashSet<V>(); isDirty = false; for (V vertex : tree.vertexSet()) { if (tree.inDegreeOf(vertex)==0) { Verify.verify(root==null, "More than one root in tree."); root = vertex; } if (tree.outDegreeOf(vertex)==0) { leaves.add(vertex); } } } }
@Override public Set<V> vertexSet() { return m_graph.vertexSet(); }
static public <V> DefaultDirectedGraph<V, Edge<V>> getDefaultDiGraph(BinaryRelation<V, V> source) { final SimpleEdgeFactory<V> factory = new SimpleEdgeFactory<V>(); final DefaultDirectedGraph<V, Edge<V>> g = new DefaultDirectedGraph<V, Edge<V>>(factory); final Set<Pair<V, V>> pairs = source.asPairs(); for (Pair<V, V> pair : pairs) { g.addVertex(pair.getElt1()); g.addVertex(pair.getElt2()); g.addEdge(pair.getElt1(), pair.getElt2()); } return g; }
private static DefaultDirectedGraph<DataRangeExpression,DefaultEdge> getDataRangeGraph (OntologyImpl.UnclassifiedOntologyTBox ontology, DefaultDirectedGraph<DataPropertyExpression,DefaultEdge> dataPropertyGraph) { DefaultDirectedGraph<DataRangeExpression,DefaultEdge> dataRangeGraph = new DefaultDirectedGraph<>(DefaultEdge.class); // ranges of roles for (DataPropertyExpression role : dataPropertyGraph.vertexSet()) dataRangeGraph.addVertex(role.getRange()); // edges between the ranges for sub-properties for (DefaultEdge edge : dataPropertyGraph.edgeSet()) { DataPropertyExpression child = dataPropertyGraph.getEdgeSource(edge); DataPropertyExpression parent = dataPropertyGraph.getEdgeTarget(edge); dataRangeGraph.addEdge(child.getRange(), parent.getRange()); } // data range inclusions from the ontology for (BinaryAxiom<DataRangeExpression> clsIncl : ontology.getSubDataRangeAxioms()) { dataRangeGraph.addVertex(clsIncl.getSuper()); // Datatype is not among the vertices from the start dataRangeGraph.addEdge(clsIncl.getSub(), clsIncl.getSuper()); } return dataRangeGraph; }
DefaultDirectedGraph<ObjectPropertyExpression,DefaultEdge> graph = new DefaultDirectedGraph<>(DefaultEdge.class); graph.addVertex(role); graph.addVertex(role.getInverse()); graph.addVertex(role); graph.addVertex(role.getInverse()); graph.addVertex(top); graph.addEdge(roleIncl.getSub(), roleIncl.getSuper()); graph.addEdge(roleIncl.getSub().getInverse(), roleIncl.getSuper().getInverse()); for (ObjectPropertyExpression ope : graph.vertexSet()) graph.addEdge(ope, top);
@NotNull @Override public <T> DirectedGraph<T, DefaultEdge> createSimpleDependencyGraph(@NotNull Iterable<? extends T> inputs, @NotNull Function1<? super T, ? extends Iterable<? extends T>> edgesFunction) { final DefaultDirectedGraph<T, DefaultEdge> graph = new DefaultDirectedGraph<T, DefaultEdge>(DefaultEdge.class); for (T input : inputs) { graph.addVertex(input); } for (T input : inputs) { Iterable<? extends T> targetVertices = edgesFunction.invoke(input); for (T targetVertex : targetVertices) { if (graph.containsVertex(targetVertex)) { graph.addEdge(targetVertex, input); } else { LOG.info("Problem?"); } } } return graph; }
public void applyEnter(EventBean[] eventsPerStream, ExprEvaluatorContext exprEvaluatorContext) { Object from = factory.getFrom().evaluate(eventsPerStream, true, exprEvaluatorContext); Object to = factory.getTo().evaluate(eventsPerStream, true, exprEvaluatorContext); if (vertexReferenceCount.add(from)) { graph.addVertex(from); } if (vertexReferenceCount.add(to)) { graph.addVertex(to); } EventBean event = eventsPerStream[0]; graph.addEdge(from, to, event); }