Returns a subgraph of <code>this</code> directed graph
containing only the vertices from <code>verts</code>.
194183
public DiGraph<Vertex> subDiGraph(final Collection<Vertex> verts) {
	final BiDiNavigator<Vertex> origNav = this.getBiDiNavigator();
	return DiGraph.diGraph
	    (verts,
	     new BiDiNavigator<Vertex>() {
		public List<Vertex> next(Vertex v) {
		    return
			(List<Vertex>)
			diff(origNav.next(v), verts, new LinkedList<Vertex>());
		}
		public List<Vertex> prev(Vertex v) {
		    return
			(List<Vertex>)
			diff(origNav.prev(v), verts, new LinkedList<Vertex>());
		}
		
		private <T> Collection<T> diff(Iterable<T> a,
					       Collection<T> b,
					       Collection<T> res) {
		    for(T t : a) {
			if(b.contains(t)) {
			    res.add(t);
			}
		    }
		    return res;
		}
	    });
    }
658879
public Graph<K, VV, EV> reverse() throws UnsupportedOperationException {
		DataSet<Edge<K, EV>> reversedEdges = edges.map(new ReverseEdgesMap<>()).name("Reverse edges");
		return new Graph<>(vertices, reversedEdges, this.context);
	}
25356
def edges
      vertices.map { |vert| vert.successors.map { |succ| [vert, succ] }}.flatten 1
    end
206266
public static <TT> EquivalencesDAGImpl<TT> getEquivalencesDAG(DefaultDirectedGraph<TT,DefaultEdge> graph) {
		
		// each set contains vertices which together form a strongly connected
		// component within the given graph		
		GabowSCC<TT, DefaultEdge> inspector = new GabowSCC<>(graph);
		List<Equivalences<TT>> equivalenceSets = inspector.stronglyConnectedSets();

		// create the vertex index
		
		ImmutableMap.Builder<TT, Equivalences<TT>> vertexIndexBuilder = new ImmutableMap.Builder<>();
		for (Equivalences<TT> equivalenceSet : equivalenceSets) {
			for (TT node : equivalenceSet) 
				vertexIndexBuilder.put(node, equivalenceSet);
		}
		ImmutableMap<TT, Equivalences<TT>> vertexIndex = vertexIndexBuilder.build();
		
		// compute the edges between the SCCs
		
		Map<Equivalences<TT>, Set<Equivalences<TT>>> outgoingEdges = new HashMap<>();
		
		for (DefaultEdge edge : graph.edgeSet()) {
			Equivalences<TT> v1 = vertexIndex.get(graph.getEdgeSource(edge));
			Equivalences<TT> v2 = vertexIndex.get(graph.getEdgeTarget(edge));
			if (v1 == v2)
				continue; // do not add loops
			
			Set<Equivalences<TT>> out = outgoingEdges.get(v1);
			if (out == null) {
				out = new HashSet<>();
				outgoingEdges.put(v1, out);
			}
			out.add(v2);
		}

		// compute the transitively reduced DAG
		
		SimpleDirectedGraph<Equivalences<TT>,DefaultEdge> dag = new SimpleDirectedGraph<>(DefaultEdge.class);
		for (Equivalences<TT> equivalenceSet : equivalenceSets)  
			dag.addVertex(equivalenceSet);
		
		for (Map.Entry<Equivalences<TT>, Set<Equivalences<TT>>> edges : outgoingEdges.entrySet()) {
			Equivalences<TT> v1 = edges.getKey();
			for (Equivalences<TT> v2 : edges.getValue()) {
				// an edge from v1 to v2 is redundant if 
				//  v1 has an edge going to a vertex v2p 
				//         from which v2 is reachable (in one step) 
				boolean redundant = false;
				if (edges.getValue().size() > 1) {
	 				for (Equivalences<TT> v2p : edges.getValue()) {
						Set<Equivalences<TT>> t2p = outgoingEdges.get(v2p);
						if (t2p!= null && t2p.contains(v2)) {
							redundant = true;
							break;
						}	
					}
				}
				if (!redundant)
					dag.addEdge(v1, v2);
			}
		}
		
		return new EquivalencesDAGImpl<>(graph, dag, vertexIndex, vertexIndex);
	}
459417
public static <V> Set<V> getLeafVertices(DirectedGraph<V, DefaultEdge> graph) {
        Set<V> vertexSet = graph.vertexSet();
        Set<V> leaves = new HashSet<V>(vertexSet.size()*2);
        for (V vertex : vertexSet) {
            if (graph.outgoingEdgesOf(vertex).isEmpty()) {
                leaves.add(vertex);
            }
        }
        return leaves;
    }
1216494
GraphvizGraph getPassGraph() {
    LinkedDirectedGraph<String, String> graph =
        LinkedDirectedGraph.createWithoutAnnotations();
    Iterable<PassFactory> allPasses =
        Iterables.concat(getChecks(), getOptimizations());
    String lastPass = null;
    String loopStart = null;
    for (PassFactory pass : allPasses) {
      String passName = pass.getName();
      int i = 1;
      while (graph.hasNode(passName)) {
        passName = pass.getName() + (i++);
      }
      graph.createNode(passName);

      if (loopStart == null && !pass.isOneTimePass()) {
        loopStart = passName;
      } else if (loopStart != null && pass.isOneTimePass()) {
        graph.connect(lastPass, "loop", loopStart);
        loopStart = null;
      }

      if (lastPass != null) {
        graph.connect(lastPass, "", passName);
      }
      lastPass = passName;
    }
    return graph;
  }
567350
def full_subgraph(self, objects):
        
        vertices = ElementTransformSet(transform=id)
        out_edges = KeyTransformDict(transform=id)
        in_edges = KeyTransformDict(transform=id)
        for obj in objects:
            vertices.add(obj)
            out_edges[obj] = []
            in_edges[obj] = []

        edges = set()
        head = {}
        tail = {}

        for referrer in vertices:
            for edge in self._out_edges[referrer]:
                referent = self._head[edge]
                if referent not in vertices:
                    continue
                edges.add(edge)
                tail[edge] = referrer
                head[edge] = referent
                out_edges[referrer].append(edge)
                in_edges[referent].append(edge)

        return ObjectGraph._raw(
            vertices=vertices,
            edges=edges,
            out_edges=out_edges,
            in_edges=in_edges,
            head=head,
            tail=tail,
        )
1090402
public DataSet<Triplet<K, VV, EV>> getTriplets() {
		return this.getVertices()
			.join(this.getEdges()).where(0).equalTo(0)
			.with(new ProjectEdgeWithSrcValue<>())
				.name("Project edge with source value")
			.join(this.getVertices()).where(1).equalTo(0)
			.with(new ProjectEdgeWithVertexValues<>())
				.name("Project edge with vertex values");
	}
28938
@SuppressWarnings("unchecked")
	public Set<OGraphVertex> browseOutEdgesVertexes() {
		final Set<OGraphVertex> resultset = new HashSet<OGraphVertex>();

		Set<OGraphEdge> temp = out != null ? out.get() : null;

		if (temp == null) {
			final Set<OIdentifiable> docEdges = (Set<OIdentifiable>) document.field(OGraphDatabase.VERTEX_FIELD_OUT);

			// TRANSFORM ALL THE EDGES
			if (docEdges != null)
				for (OIdentifiable d : docEdges) {
					resultset.add((OGraphVertex) database.getUserObjectByRecord(
							(ODocument) ((ODocument) d.getRecord()).field(OGraphDatabase.EDGE_FIELD_IN), null));
				}
		} else {
			for (OGraphEdge edge : temp) {
				resultset.add(edge.getIn());
			}
		}

		return resultset;
	}
579381
private Graph<K, VV, EV> removeVertices(DataSet<Vertex<K, VV>> verticesToBeRemoved) {

		DataSet<Vertex<K, VV>> newVertices = getVertices().coGroup(verticesToBeRemoved).where(0).equalTo(0)
				.with(new VerticesRemovalCoGroup<>()).name("Remove vertices");

		DataSet <Edge< K, EV>> newEdges = newVertices.join(getEdges()).where(0).equalTo(0)
				// if the edge source was removed, the edge will also be removed
				.with(new ProjectEdgeToBeRemoved<>()).name("Edges to be removed")
				// if the edge target was removed, the edge will also be removed
				.join(newVertices).where(1).equalTo(0)
				.with(new ProjectEdge<>()).name("Remove edges");

		return new Graph<>(newVertices, newEdges, context);
	}
184026
@Pure
	protected final Graph<ST, PT> getParentGraph() {
		return this.parentGraph == null ? null : this.parentGraph.get();
	}
56294
public static List<SubGraph> getSubgraphsMatching(SameDiff sd, SubGraphPredicate p) {
        List<SubGraph> out = new ArrayList<>();
        for (DifferentialFunction df : sd.functions()) {
            if (p.matches(sd, df)) {
                SubGraph sg = p.getSubGraph(sd, df);
                out.add(sg);
            }
        }

        return out;
    }
229407
def connected_subgraphs(self, directed=True, ordered=False):
    '''
    '''
    num_ccs, labels = self.connected_components(directed=directed)
    # check the trivial case first
    if num_ccs == 1:
      yield self
      raise StopIteration
    if ordered:
      # sort by descending size (num vertices)
      order = np.argsort(np.bincount(labels))[::-1]
    else:
      order = range(num_ccs)

    # don't use self.subgraph() here, because we can reuse adj
    adj = self.matrix('dense', 'csr', 'csc')
    for c in order:
      mask = labels == c
      sub_adj = adj[mask][:,mask]
      yield self.__class__.from_adj_matrix(sub_adj)
704057
def reverse
      return self unless directed?
      result = DirectedAdjacencyGraph.new
      each_vertex { |v| result.add_vertex v }
      each_edge { |u,v| result.add_edge(v, u) }
      result
    end
384686
public Graph<K, VV, EV> union(Graph<K, VV, EV> graph) {
		DataSet<Vertex<K, VV>> unionedVertices = graph
			.getVertices()
			.union(this.getVertices())
				.name("Vertices")
			.distinct()
				.name("Vertices");

		DataSet<Edge<K, EV>> unionedEdges = graph
			.getEdges()
			.union(this.getEdges())
				.name("Edges");

		return new Graph<>(unionedVertices, unionedEdges, this.context);
	}
527638
@Override
  public Set<EndpointPair<N>> edges() {
    return new AbstractSet<EndpointPair<N>>() {
      @Override
      public UnmodifiableIterator<EndpointPair<N>> iterator() {
        return EndpointPairIterator.of(AbstractGraph.this);
      }

      @Override
      public int size() {
        return Ints.saturatedCast(edgeCount());
      }

      @Override
      public boolean contains(@Nullable Object obj) {
        if (!(obj instanceof EndpointPair)) {
          return false;
        }
        EndpointPair<?> endpointPair = (EndpointPair<?>) obj;
        return isDirected() == endpointPair.isOrdered()
            && nodes().contains(endpointPair.nodeU())
            && successors(endpointPair.nodeU()).contains(endpointPair.nodeV());
      }
    };
  }
1051505
public static DataSet<Vertex<Long, String>> getVertices(ExecutionEnvironment env) {
		List<Vertex<Long, String>> vertices = new ArrayList<>(INPUT_VERTICES.length);
		for (String vertex : INPUT_VERTICES) {
			String[] tokens = vertex.split(";");
			vertices.add(new Vertex<>(Long.parseLong(tokens[0]), tokens[1]));
		}

		return env.fromCollection(vertices);
	}