本文整理匯總了Java中org.jgrapht.graph.DefaultDirectedGraph.containsEdge方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultDirectedGraph.containsEdge方法的具體用法?Java DefaultDirectedGraph.containsEdge怎麽用?Java DefaultDirectedGraph.containsEdge使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jgrapht.graph.DefaultDirectedGraph
的用法示例。
在下文中一共展示了DefaultDirectedGraph.containsEdge方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testDFS
import org.jgrapht.graph.DefaultDirectedGraph; //導入方法依賴的package包/類
/**
* Rigourous Test :-)
*/
public void testDFS() {
DefaultDirectedGraph<Vertex, Double> graph = new DefaultDirectedGraph<Vertex, Double>(
Double.class);
Vertex v = null;
for (int i = 0; i < this.numOfVertices; i++) {
v = new Vertex("v" + i);
graph.addVertex(v);
}
Vertex lastVertex = v;
Set<Vertex> vertices = graph.vertexSet();
Random rand = new Random();
Double nextEdge = 0.0;
for (Vertex start : vertices)
for (Vertex end : vertices)
if (!start.equals(end) && !graph.containsEdge(start, end)) {
nextEdge = rand.nextDouble();
if (nextEdge > 0.9)
graph.addEdge(start, end, nextEdge);
}
System.out.println("Vertices: " + vertices.size());
System.out.println("Edges: " + graph.edgeSet().size());
DepthFirstIterator<Vertex, Double> dfsIter = new DepthFirstIterator<Vertex, Double>(
graph, lastVertex);
DFS<Double> dfs = new DFS<Double>(graph);
Vertex[] dfsResult = dfs.depthFirstTree(lastVertex);
for (int i = 0; i < this.numOfVertices && dfsIter.hasNext(); i++) {
System.out.println(dfsResult[i] + " " + dfsIter.next());
}
}
示例2: testBFS
import org.jgrapht.graph.DefaultDirectedGraph; //導入方法依賴的package包/類
/**
* Rigourous Test :-)
*/
public void testBFS() {
DefaultDirectedGraph<Vertex, Double> graph = new DefaultDirectedGraph<Vertex, Double>(
Double.class);
Vertex v = null;
for (int i = 0; i < this.numOfVertices; i++) {
v = new Vertex("v" + i);
graph.addVertex(v);
}
// use last vertex as start point of search
Vertex lastVertex = v;
Set<Vertex> vertices = graph.vertexSet();
// add edges to graph
Random rand = new Random();
Double nextEdge = 0.0;
for (Vertex start : vertices)
for (Vertex end : vertices)
if (!start.equals(end) && !graph.containsEdge(start, end)) {
nextEdge = rand.nextDouble();
if (nextEdge > 0.9)
graph.addEdge(start, end, nextEdge);
}
System.out.println("Vertices: " + vertices.size());
System.out.println("Edges: " + graph.edgeSet().size());
BreadthFirstIterator<Vertex, Double> bfsIter = new BreadthFirstIterator<Vertex, Double>(
graph, lastVertex);
BFS<Double> bfs = new BFS<Double>(graph);
Vertex[] bfsResult = bfs.breadthFirstTree(lastVertex);
for (int i = 0; i < this.numOfVertices && bfsIter.hasNext(); i++) {
System.out.println(bfsResult[i] + " " + bfsIter.next());
}
}