【发布时间】:2023-03-19 09:17:01
【问题描述】:
我正在尝试使用 jung 库创建 kNN 图。我已经到了需要检查图表中是否已经存在 2 个Nodes 之间的链接的时刻。
到目前为止我的代码:
for (int i = 0; i < k; i++) {
for (Iterator<Node> it1 = mGraph.getVertices().iterator(); it1.hasNext();) {
Node n1 = (Node) it1.next();
double minDistance = 9999999;
Node toConnect = null;
for (Iterator<Node> it2 = mGraph.getVertices().iterator(); it2.hasNext();) {
Node n2 = (Node) it2.next();
double currDistance = this.getDistance(n1, n2);
if( currDistance < minDistance &&
mGraph.containsEdge( /* WHAT HERE */ ) ){
minDistance = currDistance;
toConnect = n2;
}
}
mGraph.addEdge(new Link(), n1, toConnect, EdgeType.DIRECTED);
}
}
我不知道该怎么做,因为Link 只有一个没有任何参数的构造函数。
【问题讨论】:
标签: java graph distance jung knn