/** * {@inheritDoc} */ @Override public Set<E> outgoingEdgesOf(V vertex) { return delegate.outgoingEdgesOf(vertex); }
public Set<Scope> outgoingEdgesOf( FlowElement vertex ) { return graph.outgoingEdgesOf( vertex ); }
/** * Check if a vertex has any direct successors. * * @param graph the graph to look for successors * @param vertex the vertex to look for successors * @param <V> the graph vertex type * @param <E> the graph edge type * * @return true if the vertex has any successors, false otherwise */ public static <V, E> boolean vertexHasSuccessors(Graph<V, E> graph, V vertex) { return !graph.outgoingEdgesOf(vertex).isEmpty(); }
/** * {@inheritDoc} */ @Override public Set<E> outgoingEdgesOf(V vertex) { assertVertexExist(vertex); return base.outgoingEdgesOf(vertex).stream().filter(edgeSet::contains).collect( Collectors.toCollection(LinkedHashSet::new)); }
/** * {@inheritDoc} */ @Override public Set<E> outgoingEdgesOf(V vertex) { boolean inG1 = g1.containsVertex(vertex); boolean inG2 = g2.containsVertex(vertex); if (inG1 && inG2) { return new UnmodifiableUnionSet<>( g1.outgoingEdgesOf(vertex), g2.outgoingEdgesOf(vertex)); } else if (inG1) { return Collections.unmodifiableSet(g1.outgoingEdgesOf(vertex)); } else if (inG2) { return Collections.unmodifiableSet(g2.outgoingEdgesOf(vertex)); } else { throw new IllegalArgumentException("no such vertex in graph: " + vertex.toString()); } }
/** * Returns a list of vertices that are the direct successors of a specified vertex. If the graph * is a multigraph vertices may appear more than once in the returned list. * * <p> * The method uses {@link Graph#outgoingEdgesOf(Object)} to traverse the graph. * * @param g the graph to look for successors in * @param vertex the vertex to get the successors of * @param <V> the graph vertex type * @param <E> the graph edge type * * @return a list of the vertices that are the direct successors of the specified vertex. */ public static <V, E> List<V> successorListOf(Graph<V, E> g, V vertex) { List<V> successors = new ArrayList<>(); Set<? extends E> edges = g.outgoingEdgesOf(vertex); for (E e : edges) { successors.add(getOppositeVertex(g, e, vertex)); } return successors; }
private V advance() { V result = queue.poll(); if (result != null) { for (E e : graph.outgoingEdgesOf(result)) { V other = Graphs.getOppositeVertex(graph, e, result); ModifiableInteger inDegree = inDegreeMap.get(other); if (inDegree.value > 0) { inDegree.value--; if (inDegree.value == 0) { queue.offer(other); } } } --remainingVertices; } else { /* * Still expecting some vertices, but no vertex has zero degree. */ if (remainingVertices > 0) { throw new IllegalArgumentException(GRAPH_IS_NOT_A_DAG); } } return result; }
private void dfs(int u, int parent) { component[u] = numberComponent; timeIn[u] = ++clock; ancestors[0][u] = parent; for (int l = 1; l < maxLevel; l++) { if (ancestors[l - 1][u] != -1) ancestors[l][u] = ancestors[l - 1][ancestors[l - 1][u]]; } V vertexU = indexList.get(u); for (E edge : graph.outgoingEdgesOf(vertexU)) { int v = vertexMap.get(Graphs.getOppositeVertex(graph, edge, vertexU)); if (v != parent) { dfs(v, u); } } timeOut[u] = ++clock; }
/** * {@inheritDoc} */ @Override public Set<E> outgoingEdgesOf(V vertex) { assertVertexExist(vertex); return new MaskEdgeSet<>(base, base.outgoingEdgesOf(vertex), vertexMask, edgeMask); }
@Override public Set<E> getCutEdges() { if (cutEdges != null) return cutEdges; cutEdges = new LinkedHashSet<>(); Set<V> p1 = getSourcePartition(); if (directedGraph) { for (V vertex : p1) { cutEdges.addAll( network .outgoingEdgesOf(vertex).stream() .filter(edge -> !p1.contains(network.getEdgeTarget(edge))) .collect(Collectors.toList())); } } else { cutEdges.addAll( network .edgeSet().stream() .filter( e -> p1.contains(network.getEdgeSource(e)) ^ p1.contains(network.getEdgeTarget(e))) .collect(Collectors.toList())); } return cutEdges; }
public Set<Integer> getSuccessors( int vertex ) { Set<Integer> results = successors.get( vertex ); if( results != null ) return results; results = new HashSet<>(); Set<Edge> edges = getDelegate().outgoingEdgesOf( getVertex( vertex ) ); for( Edge edge : edges ) { Object result = getEdgeTarget( edge ); Integer value = getIndex( result ); if( value != null ) results.add( value ); } successors.put( vertex, results ); return results; }
/** * @param vertexNumber the number which identifies the vertex $v$ in this order. * * @return the identifying numbers of all vertices which are connected to $v$ by an edge * outgoing from $v$. */ public int[] getOutEdges(int vertexNumber) { if (cacheEdges && (outgoingEdges[vertexNumber] != null)) { return outgoingEdges[vertexNumber]; } V v = getVertex(vertexNumber); Set<E> edgeSet = graph.outgoingEdgesOf(v); int[] vertexArray = new int[edgeSet.size()]; int i = 0; for (E edge : edgeSet) { V source = graph.getEdgeSource(edge), target = graph.getEdgeTarget(edge); vertexArray[i++] = mapVertexToOrder.get(source.equals(v) ? target : source); } if (cacheEdges) { outgoingEdges[vertexNumber] = vertexArray; } return vertexArray; }
private void computeTarjanOLCA(V u, V p, Set<V> visited) { visited.add(u); unionFind.addElement(u); ancestors.put(u, u); for (E edge : graph.outgoingEdgesOf(u)) { V v = Graphs.getOppositeVertex(graph, edge, u); if (!v.equals(p)) { computeTarjanOLCA(v, u, visited); unionFind.union(u, v); ancestors.put(unionFind.find(u), u); } } blackNodes.add(u); for (int index : queryOccurs.computeIfAbsent(u, x -> new HashSet<>())) { Pair<V, V> query = queries.get(index); V v; if (query.getFirst().equals(u)) v = query.getSecond(); else v = query.getFirst(); if (blackNodes.contains(v)) { lowestCommonAncestors.set(index, ancestors.get(unionFind.find(v))); } } }
private void collapseCycle(final Set<ATermAppl> scc) { final Iterator<ATermAppl> i = scc.iterator(); final ATermAppl rep = i.next(); while (i.hasNext()) { final ATermAppl node = i.next(); addEquivalent(rep, node); for (final DefaultEdge edge : _graph.incomingEdgesOf(node)) { final ATermAppl incoming = _graph.getEdgeSource(edge); if (!incoming.equals(rep)) _graph.addEdge(incoming, rep); } for (final DefaultEdge edge : _graph.outgoingEdgesOf(node)) { final ATermAppl outgoing = _graph.getEdgeTarget(edge); if (!outgoing.equals(rep)) _graph.addEdge(rep, outgoing); } _graph.removeVertex(node); } }
private void exportAsAdjacencyList(Graph<V, E> g, PrintWriter out) { boolean exportEdgeWeights = parameters.contains(CSVFormat.Parameter.EDGE_WEIGHTS); for (V v : g.vertexSet()) { exportEscapedField(out, vertexIDProvider.getName(v)); for (E e : g.outgoingEdgesOf(v)) { V w = Graphs.getOppositeVertex(g, e, v); out.print(delimiter); exportEscapedField(out, vertexIDProvider.getName(w)); if (exportEdgeWeights) { out.print(delimiter); exportEscapedField(out, String.valueOf(g.getEdgeWeight(e))); } } out.println(); } }
private void collapseCycle(final Set<ATermAppl> scc) { final Iterator<ATermAppl> i = scc.iterator(); final ATermAppl rep = i.next(); while (i.hasNext()) { final ATermAppl node = i.next(); addEquivalent(rep, node); for (final DefaultEdge edge : _graph.incomingEdgesOf(node)) { final ATermAppl incoming = _graph.getEdgeSource(edge); if (!incoming.equals(rep)) _graph.addEdge(incoming, rep); } for (final DefaultEdge edge : _graph.outgoingEdgesOf(node)) { final ATermAppl outgoing = _graph.getEdgeTarget(edge); if (!outgoing.equals(rep)) _graph.addEdge(rep, outgoing); } _graph.removeVertex(node); } }
/** * {@inheritDoc} */ @Override public V next() { if (!hasNext()) { throw new NoSuchElementException(); } // settle next node FibonacciHeapNode<QueueEntry> vNode = heap.removeMin(); V v = vNode.getData().v; double vDistance = vNode.getKey(); // relax edges for (E e : graph.outgoingEdgesOf(v)) { V u = Graphs.getOppositeVertex(graph, e, v); double eWeight = graph.getEdgeWeight(e); if (eWeight < 0.0) { throw new IllegalArgumentException("Negative edge weight not allowed"); } updateDistance(u, e, vDistance + eWeight); } return v; }
public static <V, E> List<NestedPath<V, E>> advanceFrontier(Graph<V, E> graph, Collection<NestedPath<V, E>> paths) { List<NestedPath<V, E>> result = new ArrayList<>(); for(NestedPath<V, E> path : paths) { V current = path.getCurrent(); Set<E> edges = graph.outgoingEdgesOf(current); for(E edge : edges) { boolean isCycle = path.containsEdge(edge, false); V v = graph.getEdgeTarget(edge); if(!isCycle) { NestedPath<V, E> nextPath = new NestedPath<>(new ParentLink<>(path, new Directed<>(edge, false)), v); result.add(nextPath); } } } return result; }
private void addUnseenChildrenOf(V vertex) { for (E edge : graph.outgoingEdgesOf(vertex)) { if (nListeners != 0) { fireEdgeTraversed(createEdgeTraversalEvent(edge)); } V oppositeV = Graphs.getOppositeVertex(graph, edge, vertex); if (isSeenVertex(oppositeV)) { encounterVertexAgain(oppositeV, edge); } else { encounterVertex(oppositeV, edge); } } }
@Override public V next() { if (!hasNext()) { throw new NoSuchElementException(); } Set<? extends E> potentialEdges = graph.outgoingEdgesOf(currentVertex); // randomly select an edge from the set of potential edges. E nextEdge = drawEdge(potentialEdges); if (nextEdge != null) { V nextVertex; nextVertex = Graphs.getOppositeVertex(graph, nextEdge, currentVertex); encounterVertex(nextVertex, nextEdge); fireEdgeTraversed(createEdgeTraversalEvent(nextEdge)); fireVertexTraversed(createVertexTraversalEvent(nextVertex)); currentVertex = nextVertex; return nextVertex; } else { sinkReached = true; return currentVertex; } }