在JUNG 2.0中它是
edu.uci.ics.jung.algorithms.filters.KNeighborhoodFilter:
A filter used to extract the k-neighborhood around one or more root
node(s). The k-neighborhood is defined as the subgraph induced by the
set of vertices that are k or fewer hops (unweighted shortest-path
distance) away from the root node.
这是你如何使用它(假设你已经有了图形和顶点/边缘类型):
Graph graph = // ...
int k = 3; // maximum hops
V startVertex = // ... (pick your starting node)
Filter filter = new KNeighborhoodFilter(
startVertex, k, EdgeType.IN_OUT);
Graph neighborhood = filter.transform(graph);
邻域图将与原始图形属于同一类.您必须为每个不同的起始节点创建一个新过滤器.