本文整理汇总了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());
}
}