Extracting a subgraph from a graph using JUNG?

I have a big chart that I process with JUNG. I was wondering if JUNG provides a way to extract, say, a 2-hop neighborhood of a vertex (complete with all edges between them) into a separate graph?

+3
source share
2 answers

In JUNG 2.0, this is edu.uci.ics.jung.algorithms.filters.KNeighborhoodFilter :

A filter used to extract a k-neighborhood around one or more roots of node (s). A K-neighborhood is defined as a subgraph, an induced set of vertices that are k or less hops (unweighted shortest distance path) from the root node.

(, /):

Graph<V, E> graph = // ...
int k = 3; // maximum hops
V startVertex = // ... (pick your starting node)
Filter<V, E> filter = new KNeighborhoodFilter<V, E>(
    startVertex, k, EdgeType.IN_OUT);
Graph<V, E> neighborhood = filter.transform(graph);

neighborhood , . node.

+7

edu.uci.ics.jung.algorithms.connectivity.KNeighborhoodExtractor

0

Source: https://habr.com/ru/post/1752729/


All Articles