当前位置: 首页>>代码示例>>Java>>正文


Java GraphGenerator类代码示例

本文整理汇总了Java中org.jgrapht.generate.GraphGenerator的典型用法代码示例。如果您正苦于以下问题:Java GraphGenerator类的具体用法?Java GraphGenerator怎么用?Java GraphGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GraphGenerator类属于org.jgrapht.generate包,在下文中一共展示了GraphGenerator类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testOnlyCyclesComplete

import org.jgrapht.generate.GraphGenerator; //导入依赖的package包/类
@Test
public void testOnlyCyclesComplete() {

	Pool pool = new Pool(Edge.class);
	int numPairs = 10;
	assertTrue(numPairs >= 4);
	
	GraphGenerator<Vertex,Edge,Vertex> cgg = new CompleteGraphGenerator<Vertex,Edge>(numPairs);
	cgg.generateGraph(pool, new AllMatchVertexPairFactory(), null);
	
	// Number of edges in complete directed graph: n(n-1)
	assertEquals(numPairs*(numPairs-1), pool.edgeSet().size());
	
	CycleGenerator cg = new CycleGenerator(pool);
	
	// Number of 2-cycles = n(n-1)/2  (#edges in undirected complete graph)
	assertEquals(numPairs*(numPairs-1)/2, cg.generateCyclesAndChains(2, Integer.MAX_VALUE).size());
	
	// Number of at-most-3-cyles = number of 2-cycles + number of 3-cycles, so
	// n(n-1)/2   +  n(n-1)(n-2)/3
	assertEquals(numPairs*(numPairs-1)/2 + numPairs*(numPairs-1)*(numPairs-2)/3, cg.generateCyclesAndChains(3, Integer.MAX_VALUE).size());
	
	// ... + n(n-1)(n-2)(n-3)/4
	assertEquals(numPairs*(numPairs-1)/2 + numPairs*(numPairs-1)*(numPairs-2)/3 + numPairs*(numPairs-1)*(numPairs-2)*(numPairs-3)/4, cg.generateCyclesAndChains(4, Integer.MAX_VALUE).size());
}
 
开发者ID:JohnDickerson,项目名称:KidneyExchange,代码行数:26,代码来源:CycleGeneratorTest.java

示例2: testConstantFailureProbs

import org.jgrapht.generate.GraphGenerator; //导入依赖的package包/类
@Test
public void testConstantFailureProbs() {

	Pool pool = new Pool(Edge.class);
	int numPairs = 3;
	assertTrue(numPairs >= 0);

	GraphGenerator<Vertex,Edge,Vertex> cgg = new CompleteGraphGenerator<Vertex,Edge>(numPairs);
	cgg.generateGraph(pool, new AllMatchVertexPairFactory(), null);

	// Add some constant edge failure probabilities
	FailureProbabilityUtil.setFailureProbability(pool, FailureProbabilityUtil.ProbabilityDistribution.CONSTANT, new Random());

	for(Edge e : pool.edgeSet()) {
		assertTrue(0.7 == e.getFailureProbability());
	}
}
 
开发者ID:JohnDickerson,项目名称:KidneyExchange,代码行数:18,代码来源:FailureProbabilityUtilTest.java

示例3: testCompareSolvers

import org.jgrapht.generate.GraphGenerator; //导入依赖的package包/类
@Test
public void testCompareSolvers() {
	Pool pool = new Pool(Edge.class);
	int numPairs = 10;
	assertTrue(numPairs >= 4);

	// Test 10 random graphs, make sure the fairness solver (with no fairness constraint) and the base solver return the same value of answer
	for(int repeatIdx=0; repeatIdx<10; repeatIdx++) {
		GraphGenerator<Vertex,Edge,Vertex> rgg = new RandomGraphGenerator<Vertex,Edge>(numPairs, (int)(numPairs*numPairs*0.10));
		rgg.generateGraph(pool, new AllMatchVertexPairFactory(), null);

		CycleGenerator cg = new CycleGenerator(pool);
		List<Cycle> cycles = cg.generateCyclesAndChains(3, 0);

		CycleMembership membership = new CycleMembership(pool, cycles);

		try {
			Solution fSol = new FairnessCPLEXSolver(pool, cycles, membership, new HashSet<Vertex>()).solve(0.0);
			Solution cSol = new CycleFormulationCPLEXSolver(pool, cycles, membership).solve();

			assertTrue(fSol.getObjectiveValue() == cSol.getObjectiveValue());

		} catch(SolverException e) {
			fail(e.getMessage());
		}
	}
}
 
开发者ID:JohnDickerson,项目名称:KidneyExchange,代码行数:28,代码来源:CycleFormulationCPLEXSolverTest.java


注:本文中的org.jgrapht.generate.GraphGenerator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。