當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultDirectedGraph.containsEdge方法代碼示例

本文整理匯總了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());
	}
}
 
開發者ID:yubinbai,項目名稱:javatemplates,代碼行數:41,代碼來源:DFSTest.java

示例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());
	}

}
 
開發者ID:yubinbai,項目名稱:javatemplates,代碼行數:44,代碼來源:BFSTest.java


注:本文中的org.jgrapht.graph.DefaultDirectedGraph.containsEdge方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。