本文整理汇总了Java中org.jgrapht.DirectedGraph.addVertex方法的典型用法代码示例。如果您正苦于以下问题:Java DirectedGraph.addVertex方法的具体用法?Java DirectedGraph.addVertex怎么用?Java DirectedGraph.addVertex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgrapht.DirectedGraph
的用法示例。
在下文中一共展示了DirectedGraph.addVertex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testComplexDag
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
@Test
public void testComplexDag() {
DirectedGraph<String, DefaultEdge> g = new DefaultDirectedGraph<String, DefaultEdge>(DefaultEdge.class);
g.addVertex("a");
g.addVertex("b");
g.addVertex("c");
g.addVertex("d");
g.addVertex("e");
g.addVertex("f");
g.addVertex("g");
g.addEdge("a", "b");
g.addEdge("b", "c");
g.addEdge("c", "d");
g.addEdge("d", "f");
g.addEdge("b", "e");
g.addEdge("e", "f");
g.addEdge("f", "g");
g.addEdge("a", "f");
Assert.assertEquals("b", new TarjanLowestCommonAncestor<String, DefaultEdge>(g).calculate("a", "e", "c"));
}
示例2: determineAndSolveConflicts
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
protected static void determineAndSolveConflicts(final PathBlockSet resultBlocks) {
// determine conflicts
final PathBlockSet deletedBlocks = new PathBlockSet();
final DirectedGraph<Block, BlockConflict> blockConflictGraph = new SimpleDirectedGraph<>(BlockConflict::of);
for (final Block block : resultBlocks.getBlocks()) {
blockConflictGraph.addVertex(block);
}
for (final Block x : blockConflictGraph.vertexSet()) {
createArcs(blockConflictGraph, resultBlocks, x);
}
// solve conflicts
while (true) {
final Optional<BlockConflict> mostUsefulConflictsFirst =
blockConflictGraph.edgeSet().stream().max(Comparator.comparingInt(BlockConflict::getQuality));
if (!mostUsefulConflictsFirst.isPresent()) {
break;
}
final BlockConflict blockConflict = mostUsefulConflictsFirst.get();
solveConflict(blockConflict, blockConflictGraph, resultBlocks, deletedBlocks);
}
}
示例3: solveConflict
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
protected static void solveConflict(final BlockConflict blockConflict,
final DirectedGraph<Block, BlockConflict> blockConflictGraph, final PathBlockSet resultBlocks,
final PathBlockSet deletedBlocks) {
final Block replaceBlock = blockConflict.getReplaceBlock();
final Set<FilterInstance> xWOcfi =
replaceBlock.getFlatFilterInstances().stream().filter(negate(blockConflict.getCfi()::contains))
.collect(toSet());
resultBlocks.remove(replaceBlock);
// remove replaceBlock and update qualities
removeArc(blockConflictGraph, blockConflict);
// find the horizontally maximal blocks within xWOcfi
final PathBlockSet newBlocks = findAllMaximalBlocksInReducedScope(xWOcfi, new PathBlockSet());
// for every such block,
for (final Block block : newBlocks.getBlocks()) {
if (!deletedBlocks.isContained(block)) {
if (resultBlocks.addDuringConflictResolution(block)) {
blockConflictGraph.addVertex(block);
createArcs(blockConflictGraph, resultBlocks, block);
}
}
}
deletedBlocks.addDuringConflictResolution(replaceBlock);
}
示例4: extractMentionNetwork
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
protected DirectedGraph<Figure, DefaultEdge> extractMentionNetwork(JCas jcas) {
DirectedGraph<Figure, DefaultEdge> graph = new DirectedPseudograph<Figure, DefaultEdge>(DefaultEdge.class);
for (Utterance utterance : JCasUtil.select(jcas, Utterance.class)) {
Speaker speaker = DramaUtil.getFirstSpeaker(utterance);
if (speaker != null)
for (FigureMention mention : JCasUtil.selectCovered(jcas, FigureMention.class, utterance)) {
if (speaker.getFigure() != null && mention.getFigure() != null) {
if (!graph.containsVertex(speaker.getFigure()))
graph.addVertex(speaker.getFigure());
if (!graph.containsVertex(mention.getFigure()))
graph.addVertex(mention.getFigure());
graph.addEdge(speaker.getFigure(), mention.getFigure());
}
}
}
return graph;
}
示例5: initDependencyGraph
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
private DirectedGraph<Dependency, DefaultEdge> initDependencyGraph(List<Dependency> dependencies, Map<Dependency, Set<AttributeRef>> affectedAttributes, Map<Dependency, Set<AttributeRef>> queriedAttributes) {
DirectedGraph<Dependency, DefaultEdge> dependencyGraph = new DefaultDirectedGraph<Dependency, DefaultEdge>(DefaultEdge.class);
for (Dependency dependency : dependencies) {
dependencyGraph.addVertex(dependency);
}
for (int i = 0; i < dependencies.size(); i++) {
Dependency d1 = dependencies.get(i);
for (int j = 0; j < dependencies.size(); j++) {
if (i == j) {
continue;
}
Dependency d2 = dependencies.get(j);
if (haveOverlap(d1, d2, affectedAttributes, queriedAttributes)) {
if (logger.isDebugEnabled()) logger.debug("Edge btw " + d1.getId() + " and " + d2.getId());
dependencyGraph.addEdge(d1, d2);
}
}
}
return dependencyGraph;
}
示例6: getSpeciesInHierarchicalOrder
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
private Iterable<SpeciesDescription> getSpeciesInHierarchicalOrder(final ModelDescription model) {
final DirectedGraph<SpeciesDescription, Object> hierarchy = new SimpleDirectedGraph<>(Object.class);
final DescriptionVisitor visitor = new DescriptionVisitor<SpeciesDescription>() {
@Override
public boolean visit(final SpeciesDescription desc) {
if (desc instanceof ModelDescription)
return true;
final SpeciesDescription sd = desc.getParent();
if (sd == null || sd == desc)
return false;
hierarchy.addVertex(desc);
if (!sd.isBuiltIn()) {
hierarchy.addVertex(sd);
hierarchy.addEdge(sd, desc);
}
return true;
}
};
model.visitAllSpecies(visitor);
return () -> new TopologicalOrderIterator<>(hierarchy);
}
示例7: asDirectedGraph
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
public static DirectedGraph<Node, DefaultLink> asDirectedGraph(UndirectedGraph<Node, DefaultLink> undirectedGraph) {
if (undirectedGraph == null) {
logger.debug("graph is null.");
return null;
}
DirectedGraph<Node, DefaultLink> g = new DirectedWeightedMultigraph<Node, DefaultLink>(DefaultLink.class);
for (Node v : undirectedGraph.vertexSet())
g.addVertex(v);
for (DefaultLink e: undirectedGraph.edgeSet())
g.addEdge(e.getSource(), e.getTarget(), e);
return g;
}
示例8: addNodes
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
private void addNodes(DirectedGraph<AttributeRef, ExtendedEdge> dependencyGraph, IFormula formula, Set<AttributeRef> positionsAdded) {
for (IFormulaAtom atom : formula.getAtoms()) {
if (!(atom instanceof RelationalAtom)) {
continue;
}
RelationalAtom relationalAtom = (RelationalAtom) atom;
if (relationalAtom.isSource()) {
continue;
}
String tableName = relationalAtom.getTableAlias().getTableName();
for (FormulaAttribute attribute : relationalAtom.getAttributes()) {
String attributeName = attribute.getAttributeName();
AttributeRef position = buildPosition(tableName, attributeName);
if (positionsAdded.contains(position)) {
continue;
}
dependencyGraph.addVertex(position);
positionsAdded.add(position);
}
}
}
示例9: buildEGDStrataGraph
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
private DirectedGraph<EGDStratum, DefaultEdge> buildEGDStrataGraph(DirectedGraph<ExtendedEGD, DefaultEdge> dependencyGraph, List<EGDStratum> egdStrata) {
DirectedGraph<EGDStratum, DefaultEdge> strataGraph = new DefaultDirectedGraph<EGDStratum, DefaultEdge>(DefaultEdge.class);
for (EGDStratum stratum : egdStrata) {
strataGraph.addVertex(stratum);
}
for (EGDStratum stratumA : egdStrata) {
for (EGDStratum stratumB : egdStrata) {
if(stratumA.equals(stratumB)){
continue;
}
if (existsPath(dependencyGraph, stratumA, stratumB)) {
strataGraph.addEdge(stratumA, stratumB);
}
}
}
return strataGraph;
}
示例10: buildStrataGraph
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
private DirectedGraph<TGDStratum, DefaultEdge> buildStrataGraph(DirectedGraph<Dependency, DefaultEdge> dependencyGraph, List<TGDStratum> tgdStrata) {
DirectedGraph<TGDStratum, DefaultEdge> strataGraph = new DefaultDirectedGraph<TGDStratum, DefaultEdge>(DefaultEdge.class);
for (TGDStratum stratum : tgdStrata) {
strataGraph.addVertex(stratum);
}
for (TGDStratum stratumA : tgdStrata) {
for (TGDStratum stratumB : tgdStrata) {
if(stratumA.equals(stratumB)){
continue;
}
if (existsPath(dependencyGraph, stratumA, stratumB)) {
strataGraph.addEdge(stratumA, stratumB);
}
}
}
return strataGraph;
}
示例11: testBinaryTree
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
@Test
public void testBinaryTree() {
DirectedGraph<String, DefaultEdge> g = new DefaultDirectedGraph<String, DefaultEdge>(DefaultEdge.class);
g.addVertex("a");
g.addVertex("b");
g.addVertex("c");
g.addVertex("d");
g.addVertex("e");
g.addEdge("a", "b");
g.addEdge("b", "c");
g.addEdge("b", "d");
g.addEdge("d", "e");
Assert.assertEquals("b", new TarjanLowestCommonAncestor<String, DefaultEdge>(g).calculate("a", "c", "e"));
Assert.assertEquals("b", new TarjanLowestCommonAncestor<String, DefaultEdge>(g).calculate("a", "b", "d"));
Assert.assertEquals("d", new TarjanLowestCommonAncestor<String, DefaultEdge>(g).calculate("a", "d", "e"));
}
示例12: buildDefinitionGraph
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
private void buildDefinitionGraph(Collection<DefinitionModel> definitions,
DirectedGraph<DefinitionModel, DefaultEdge> definitionGraph) {
for (DefinitionModel definition : definitions) {
if (!definitionGraph.containsVertex(definition)) {
definitionGraph.addVertex(definition);
buildDefinitionGraph(definition.getDependencies(), definitionGraph);
for (DefinitionModel dependency : definition.getDependencies()) {
definitionGraph.addEdge(definition, dependency);
}
}
}
}
示例13: detectCyclesInEntityGraph
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
/**
* Inspects the instance graph for cycles, any cycle is printed as an error. The nameToEntity parameter doesn't list expected
* instances, any instances that are not found in the nameToInstances map (they are looked for because they are referenced as a
* dependency by an instance in the map) and are not found by name in the definition's expectedInstances are treated as errors
* as well.
*
* @param definition definition being processed. Will uses it's expected list, any instances references as dependencies but
* not found, not listed as expected in this DefinitionModel, will be treated as errors.
* @param nameToEntity name to unique instanceModels, verified before call.
* @param errorListner accepts and displays all errors produced by analyzing the models
* @return true if an error occurred, false otherwise
*/
private boolean detectCyclesInEntityGraph(final DefinitionModel definition, final Map<String, InstanceModel> nameToEntity,
final Consumer<ErrorModel> errorListener) {
final Map<String, ExpectedModel> missing = new HashMap<>();
final DirectedGraph<BaseInstanceModel, DefaultEdge> entityGraph = new DefaultDirectedGraph<>(DefaultEdge.class);
for (BaseInstanceModel entity : nameToEntity.values()) {
if (!entityGraph.containsVertex(entity)) {
entityGraph.addVertex(entity);
}
if (InstanceModel.class.isAssignableFrom(entity.getClass())) {
InstanceModel instanceModel = (InstanceModel) entity;
for (InstanceDependencyModel instanceDependency : instanceModel.getDependencies()) {
BaseInstanceModel dependency = nameToEntity.get(instanceDependency.getIdentity());
if (dependency == null) {
dependency = missing.computeIfAbsent(instanceDependency.getIdentity(), s -> new ExpectedModel(s));
missing.get(instanceDependency.getIdentity())
.addDefinitionReferenceToType(instanceModel.getIdentity(), instanceDependency.getType());
}
if (!entityGraph.containsVertex(dependency)) {
entityGraph.addVertex(dependency);
}
entityGraph.addEdge(entity, dependency);
}
}
}
boolean errored = errorsForCycles(errorListener, entityGraph);
errored = testAllMissingEntitiesAreExpected(definition, errorListener, missing, entityGraph) || errored;
errored = errorUnusedExpectedsOnDefinition(definition, errorListener, missing) || errored;
return errored;
}
示例14: testBasicOrdering
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
@Test
public void testBasicOrdering() {
String sp1 = "sp1";
String sp2 = "sp2";
String sp3 = "sp3";
String sp4 = "sp4";
String sp5 = "sp5";
DirectedGraph<String, DefaultEdge> graph = new DefaultDirectedGraph<String, DefaultEdge>(DefaultEdge.class);
for (String vertex : Lists.mutable.with(sp1, sp2, sp3, sp4, sp5).toReversed()) {
graph.addVertex(vertex);
}
graph.addEdge(sp1, sp5);
graph.addEdge(sp3, sp5);
graph.addEdge(sp2, sp1);
graph.addEdge(sp5, sp4);
ListIterable<String> sorted = sorter.sortChanges(graph);
// First, compare the root topological order (i.e. ensure that the dependencies are respected)
assertEquals(5, sorted.size());
assertThat(sorted.indexOf(sp1), greaterThan(sorted.indexOf(sp2)));
assertThat(sorted.indexOf(sp5), greaterThan(sorted.indexOf(sp1)));
assertThat(sorted.indexOf(sp5), greaterThan(sorted.indexOf(sp3)));
assertThat(sorted.indexOf(sp4), greaterThan(sorted.indexOf(sp5)));
// Now check that we can achieve a consistent order too (for easier debuggability for clients)
assertEquals(Lists.immutable.with(sp2, sp1, sp3, sp5, sp4), sorted);
}
示例15: testBasicOrderingWithComparator
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
@Test
public void testBasicOrderingWithComparator() {
SortableDependency sp1 = newVertex("sp1");
SortableDependency sp2 = newVertex("sp2");
SortableDependency sp3 = newVertex("sp3");
SortableDependency sp4 = newVertex("sp4");
SortableDependency sp5 = newVertex("sp5");
DirectedGraph<SortableDependency, DefaultEdge> graph = new DefaultDirectedGraph<SortableDependency, DefaultEdge>(DefaultEdge.class);
for (SortableDependency vertex : shuffledList(sp1, sp2, sp3, sp4, sp5)) {
graph.addVertex(vertex);
}
graph.addEdge(sp1, sp5);
graph.addEdge(sp3, sp5);
graph.addEdge(sp2, sp1);
graph.addEdge(sp5, sp4);
ListIterable<SortableDependency> sorted = sorter.sortChanges(graph, Comparators.fromFunctions(SortableDependency.TO_CHANGE_NAME));
// First, compare the root topological order (i.e. ensure that the dependencies are respected)
assertEquals(5, sorted.size());
assertThat(sorted.indexOf(sp1), greaterThan(sorted.indexOf(sp2)));
assertThat(sorted.indexOf(sp5), greaterThan(sorted.indexOf(sp1)));
assertThat(sorted.indexOf(sp5), greaterThan(sorted.indexOf(sp3)));
assertThat(sorted.indexOf(sp4), greaterThan(sorted.indexOf(sp5)));
// Now check that we can achieve a consistent order too (for easier debuggability for clients)
assertEquals(Lists.immutable.with(sp2, sp1, sp3, sp5, sp4), sorted);
}