[英]Jung2: how to disable node selfloop
我想制作一個簡單的圖,它是沒有節點自環的圖。 在在線提供的教程中,有人說我應該使用SimpleGraph接口,但是由於在任何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);
}
我不知道這是什么教程,但是JUNG沒有“ SimpleGraph”界面。
但是,您可以通過以下機制之一來輕松實現此目的:
我不明白您為什么認為這效率低下; 這些檢查中的任何一個都是O(1)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.