我想制作一个简单的图,这是一个没有节点自循环的图。在在线可用的教程中,据说我应该使用 SimpleGraph 接口(interface),但是它不起作用,因为在任何 jar 中都找不到它。我可以做些什么来禁用自循环,或者我应该只是为了前。在每次鼠标键释放时,检查是否添加了任何自循环并删除此类边缘,这将是非常低效的。
最佳答案
正如上面提到的那样。 3 你的代码应该如下所示:
public class UndirectedSimpleGraph<V,E> extends UndirectedSparseGraph<V,E> {
public UndirectedSimpleGraph(){
super();
}
public boolean addEdge(E edge, Pair<? extends V> endpoints, EdgeType edgeType){
Pair<V> new_endpoints = getValidatedEndpoints(edge, endpoints);
if (new_endpoints == null)
return false;
V v1 = new_endpoints.getFirst();
V v2 = new_endpoints.getSecond();
if(v1.equals(v2))
return false;
else
return super.addEdge(edge,endpoints,edgeType);
}
关于java - 荣格2 : how to disable node selfloop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15921658/