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