本文整理匯總了Java中edu.uci.ics.jung.graph.DirectedSparseGraph.getEdges方法的典型用法代碼示例。如果您正苦於以下問題:Java DirectedSparseGraph.getEdges方法的具體用法?Java DirectedSparseGraph.getEdges怎麽用?Java DirectedSparseGraph.getEdges使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類edu.uci.ics.jung.graph.DirectedSparseGraph
的用法示例。
在下文中一共展示了DirectedSparseGraph.getEdges方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: deleteDoubleEdges
import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入方法依賴的package包/類
/**
* Erases the multiple edges of a graph
* @param graph
*/
public static void deleteDoubleEdges(DirectedSparseGraph<Vertex,Edge> graph){
HashSet<Edge> toDelete = new HashSet<Edge>();
for (Edge edge1 : graph.getEdges()) {
for (Edge edge2 : graph.getEdges()) {
if(graph.getSource(edge1) == graph.getDest(edge2)
&& graph.getSource(edge2) == graph.getDest(edge1)
&& !toDelete.contains(edge1)
&& graph.getSource(edge1).toString().compareTo(graph.getDest(edge1).toString()) > 0){
toDelete.add(edge1);
}
}
}
System.out.println(toDelete.size());
for (Edge edge : toDelete) {
System.out.println(graph.getEdges().contains(edge));
graph.removeEdge(edge);
}
}
示例2: writeEdgeList
import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入方法依賴的package包/類
/**
* Writes on the output a list of the edges of the network
* @param graph to print
* @param ps output stream
*/
public static void writeEdgeList(DirectedSparseGraph<Vertex,Edge> graph, PrintStream ps) {
Hashtable<Vertex, Integer> table = new Hashtable<Vertex, Integer>();
int count=0;
for(Vertex v: graph.getVertices()){
table.put(v, count);
count++;
}
for(Edge e: graph.getEdges()){
ps.println(table.get(graph.getSource(e)) + "\t"+table.get(graph.getDest(e)));
}
}