当前位置: 首页>>代码示例>>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;未经允许,请勿转载。