【问题标题】:How to filter the result of KNeighborhoodFilter?如何过滤 KNeighborhoodFilter 的结果?
【发布时间】:2013-10-23 09:15:07
【问题描述】:

我有一个 UndirectedSparseGraph g,其中存储了两种节点,即都扩展节点的用户和线程。对于用户 u,我想检索其 2-dist 邻域,即与 u 链接的其他用户,因为他们对属于 u 的 1-dist 邻域的线程具有优势。我知道 KNeighborhoodFilter 是从调用者节点“以半径”k 检索节点的方式...这意味着,在我的情况下,将返回 1 跳的线程和 2 跳的用户,因此我必须过滤结果集合。这是我到目前为止所拥有的:

// filter users in 2-dist nei
Predicate<Node> onlyUsers = new Predicate<Node>() {
    @Override
    public boolean apply(Node node) {
        return node.getName().startsWith("u");
    }
};
// find neighbors of nodes with degree i
Filter<Node, Edge> filter = new KNeighborhoodFilter<Node, Edge>(u, 2, KNeighborhoodFilter.EdgeType.IN_OUT);
// retrieve the nodes - but here we have both types of nodes
Collection<Node> twoDistNei = filter.transform(g).getVertices();
// filter the collection to retain only threads
Collection<Node> twoDistUsers = Collections2.filter(twoDistNei, onlyUsers);

我是否在正确的轨道上使用这种方法?还是我应该遵循不同的模式来完成我的任务,即在距离选定用户 2 处检索用户?

最好的问候, 西蒙娜

【问题讨论】:

    标签: java filter jung


    【解决方案1】:

    您正在做的事情将起作用,除了您还需要删除原始的“根”节点。

    基本上,您有三个选择: 1. 做你现在正在做的事。 2. 编写你自己的代码来收集一组你的邻居的邻居。如果这是一个二分图,那么您只需删除根即可。 这可能更节省空间,因为您正在构建的集合永远不会比它必须的大。 3. 如果这是一个二分图,请改用超图,其中节点是用户,超边是线程。然后你只需向超图询问节点的邻居。

    【讨论】:

      猜你喜欢
      • 2013-10-06
      • 1970-01-01
      • 2020-01-31
      • 2019-05-15
      • 2017-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-07
      相关资源
      最近更新 更多