本文整理汇总了Java中org.jgrapht.graph.DirectedPseudograph.addVertex方法的典型用法代码示例。如果您正苦于以下问题:Java DirectedPseudograph.addVertex方法的具体用法?Java DirectedPseudograph.addVertex怎么用?Java DirectedPseudograph.addVertex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgrapht.graph.DirectedPseudograph
的用法示例。
在下文中一共展示了DirectedPseudograph.addVertex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkIsDAG
import org.jgrapht.graph.DirectedPseudograph; //导入方法依赖的package包/类
private static void checkIsDAG(List<QueryQueueRule> rules)
{
DirectedPseudograph<String, DefaultEdge> graph = new DirectedPseudograph<>(DefaultEdge.class);
for (QueryQueueRule rule : rules) {
String lastQueueName = null;
for (QueryQueueDefinition queue : rule.getQueues()) {
String currentQueueName = queue.getTemplate();
graph.addVertex(currentQueueName);
if (lastQueueName != null) {
graph.addEdge(lastQueueName, currentQueueName);
}
lastQueueName = currentQueueName;
}
}
List<String> shortestCycle = shortestCycle(graph);
if (shortestCycle != null) {
String s = Joiner.on(", ").join(shortestCycle);
throw new IllegalArgumentException(format("Queues must not contain a cycle. The shortest cycle found is [%s]", s));
}
}
示例2: findGraph
import org.jgrapht.graph.DirectedPseudograph; //导入方法依赖的package包/类
private Pair<DirectedPseudograph<Resource, Edge>, Double>
findGraph(URI referent,
DirectedPseudograph<Resource, Edge> fullGraph, DirectedPseudograph<Resource, Edge> bestGraph,
double bestGraphCost, DirectedPseudograph<Resource, Edge> candidate, long startTime,
final Map<String, Integer>mappedOrder)
throws ReferringExpressionException {
double candidateCost = cost(candidate);
if (bestGraph != null && bestGraphCost <= candidateCost)
return Pair.of(bestGraph, bestGraphCost);
List<Resource> distractors = new ArrayList<Resource>(fullGraph.vertexSet().size());
for (Resource v : fullGraph.vertexSet()) {
if (System.currentTimeMillis() - startTime > maxTime)
throw new ReferringExpressionException("Time-out");
if (v != referent && matchGraphs(referent, candidate, v, fullGraph, startTime))
distractors.add(v);
}
if (distractors.isEmpty())
return Pair.of(candidate, candidateCost);
Collection<Edge>neighbors = neighbors(candidate, fullGraph);
if(mappedOrder != null){
List<Edge>toSort = new ArrayList<Edge>(neighbors);
Collections.sort(toSort, new Comparator<Edge>() {
public int compare(Edge e1, Edge e2) {
Integer m1 = mappedOrder.get(e1.getURI().getLocalName());
Integer m2 = mappedOrder.get(e2.getURI().getLocalName());
if (m1 != null && m2 != null)
return m1.compareTo(m2);
if (m1 != null)
return -1;
if (m2 != null)
return 1;
return e1.getURI().toString().compareTo(e2.getURI().toString());
}
});
neighbors = toSort;
}
for (Edge e : neighbors) {
if (System.currentTimeMillis() - startTime > maxTime)
throw new ReferringExpressionException("Time-out");
@SuppressWarnings("unchecked")
DirectedPseudograph<Resource, Edge> newCandidate = (DirectedPseudograph<Resource, Edge>) candidate.clone();
Resource source = fullGraph.getEdgeSource(e);
Resource target = fullGraph.getEdgeTarget(e);
if (!newCandidate.vertexSet().contains(source))
// odd, this shouldn't always be the case?
newCandidate.addVertex(source);
if (!newCandidate.vertexSet().contains(target))
newCandidate.addVertex(target);
newCandidate.addEdge(fullGraph.getEdgeSource(e), fullGraph.getEdgeTarget(e), e);
Pair<DirectedPseudograph<Resource, Edge>, Double> p =
findGraph(referent, fullGraph, bestGraph,
bestGraphCost, newCandidate, startTime, mappedOrder);
if (bestGraph == null || p.getRight() <= bestGraphCost) {
bestGraph = p.getLeft();
bestGraphCost = p.getRight();
}
}
return Pair.of(bestGraph, bestGraphCost);
}
示例3: buildFromFile
import org.jgrapht.graph.DirectedPseudograph; //导入方法依赖的package包/类
public static DirectedPseudograph<String, Edge> buildFromFile(String file)
throws FileNotFoundException, IOException {
DirectedPseudograph<String, Edge> g = new DirectedPseudograph<String, Edge>(
Edge.class);
Map<String, String> vertices = new HashMap<String, String>();
BufferedReader E = null;
E = new BufferedReader(new FileReader(file));
String line, edge[];
try {
while ((line = E.readLine()) != null) {
edge = line.split(";");
if (edge.length > 1) {
String fromStr = edge[0];
String toStr = edge[1];
String from, to = null;
from = vertices.get(fromStr);
if (from == null) {
from = new String(fromStr);
vertices.put(fromStr, from);
g.addVertex(from);
}
to = vertices.get(toStr);
if (to == null) {
to = new String(toStr);
vertices.put(toStr, to);
g.addVertex(to);
}
g.addEdge(from, to, new Edge());
}
}
} catch (IOException e) {
e.printStackTrace();
}
E.close();
return g;
}
示例4: testRuleApplication
import org.jgrapht.graph.DirectedPseudograph; //导入方法依赖的package包/类
@Test
public void testRuleApplication() {
EdgeFactory<GVertex,GEdge> gEF = new ClassBasedEdgeFactory<GVertex,GEdge>(GEdge.class);
DirectedPseudograph<GVertex,GEdge> g = new DirectedPseudograph<GVertex,GEdge>(gEF);
GammaGraphBuilder gammaBuilder = new GammaGraphBuilder();
GVertex gv1 = new GVertex("0");
GVertex gv2 = new GVertex("1");
g.addVertex(gv1);
g.addVertex(gv2);
GEdge ge1 = new GEdge("0","0","a");
GEdge ge2 = new GEdge("0","0","b");
GEdge ge3 = new GEdge("0","1","c");
GEdge ge4 = new GEdge("1","0","d");
GEdge ge5 = new GEdge("1","1","e");
g.addEdge(gv1, gv1, ge1);
g.addEdge(gv1, gv1, ge2);
g.addEdge(gv1, gv2, ge3);
g.addEdge(gv2, gv1, ge4);
g.addEdge(gv2, gv2, ge5);
GammaVertex gammav1 = new GammaVertex(gv1,gv1,"u");
GammaVertex gammav2 = new GammaVertex(gv1,gv2,"v");
GammaVertex gammav3 = new GammaVertex(gv2,gv1,"w");
gammaBuilder.addVertex(gammav1);
gammaBuilder.addVertex(gammav2);
gammaBuilder.addVertex(gammav3);
GammaEdge gammae1 = new GammaEdge("u","u","a","a","A");
GammaEdge gammae2 = new GammaEdge("u","v","a","c","B");
GammaEdge gammae3 = new GammaEdge("u","w","c","b","C");
GammaEdge gammae4 = new GammaEdge("v","u","b","d","D");
GammaEdge gammae5 = new GammaEdge("v","v","b","e","E");
GammaEdge gammae6 = new GammaEdge("w","u","d","a","F");
GammaEdge gammae7 = new GammaEdge("w","v","d","c","G");
GammaEdge gammae8 = new GammaEdge("w","w","e","b","H");
gammaBuilder.addEdge(gammav1, gammav1, gammae1);
gammaBuilder.addEdge(gammav1, gammav2, gammae2);
gammaBuilder.addEdge(gammav1, gammav3, gammae3);
gammaBuilder.addEdge(gammav2, gammav1, gammae4);
gammaBuilder.addEdge(gammav2, gammav2, gammae5);
gammaBuilder.addEdge(gammav3, gammav1, gammae6);
gammaBuilder.addEdge(gammav3, gammav2, gammae7);
gammaBuilder.addEdge(gammav3, gammav3, gammae8);
// GammaGraph gamma = gammaBuilder.build();
ProductionRule oneToTwoRule = new ProductionRule(gammav1,gammav2);
ProductionRule oneToThreeRule = new ProductionRule(gammav1,gammav3);
Set<ProductionRule> prodRuleSet = new HashSet<ProductionRule>();
prodRuleSet.add(oneToTwoRule);
prodRuleSet.add(oneToThreeRule);
ProductionRuleMachine prm = new ProductionRuleMachine(prodRuleSet);
TypeSet typeSetOfOne = new TypeSet();
TypeSet typeSetOfTwo = new TypeSet();
typeSetOfOne.addVertex(gammav1);
typeSetOfTwo.addVertex(gammav2);
TypeSet resultFromOne = prm.applyRules(typeSetOfOne);
TypeSet resultFromTwo = prm.applyRules(typeSetOfTwo);
Assert.assertEquals("failure - rule machine does not apply properly", 2, resultFromOne.getSize());
Assert.assertEquals("failure - rule machine does not apply if no applicable rules", 0, resultFromTwo.getSize());
}
示例5: testAddToSpecHelper
import org.jgrapht.graph.DirectedPseudograph; //导入方法依赖的package包/类
@Test
public void testAddToSpecHelper() {
EdgeFactory<GVertex,GEdge> gEF = new ClassBasedEdgeFactory<GVertex,GEdge>(GEdge.class);
DirectedPseudograph<GVertex,GEdge> g = new DirectedPseudograph<GVertex,GEdge>(gEF);
GVertex gv1 = new GVertex("0");
GVertex gv2 = new GVertex("1");
g.addVertex(gv1);
g.addVertex(gv2);
GEdge ge1 = new GEdge("0","0","a");
GEdge ge2 = new GEdge("0","1","b");
GEdge ge3 = new GEdge("1","0","c");
GEdge ge4 = new GEdge("1","0","d");
g.addEdge(gv1, gv1, ge1);
g.addEdge(gv1, gv2, ge2);
g.addEdge(gv2, gv1, ge3);
g.addEdge(gv2, gv2, ge4);
SpecHelper sh = new SpecHelper();
EquivEntry ee = new EquivEntry(ge1,ge2,ge3,ge4);
EdgePair ep1 = new EdgePair(ge1,ge4);
EdgePair ep2 = new EdgePair(ge2,ge3);
ep1.printEdgePair();
sh.addEquivEntry(ee);
EdgePair ep3 = new EdgePair(ee.getA(),ee.getBPrime());
Set<EdgePair> sabp = sh.getSeenABPrimePairs();
Set<EdgePair> sbap = sh.getSeenBAPrimePairs();
Set<EdgePair> testSet = new HashSet<EdgePair>();
testSet.add(ep1);
for(EdgePair e : sabp) {
e.printEdgePair();
org.junit.Assert.assertTrue("Not in iterator", e.equals(ep1));
}
org.junit.Assert.assertTrue("Ep1 != Ep3", ep1.equals(ep3));
org.junit.Assert.assertTrue("Ep3 != Ep1", ep3.equals(ep1));
org.junit.Assert.assertTrue("testSet does not contain ep3", sabp.contains(ep3));
org.junit.Assert.assertTrue("specHelper seenABPrime does not contain ep3", sabp.contains(ep3));
org.junit.Assert.assertTrue("specHelper seenABPrime does not contain ep1", sabp.contains(ep1));
org.junit.Assert.assertTrue(sbap.contains(ep2));
}