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


Java DirectedGraph.addVertex方法代码示例

本文整理汇总了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"));

   }
 
开发者ID:JanaWengenroth,项目名称:GKA1,代码行数:25,代码来源:TarjanLowestCommonAncestorTest.java

示例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);
    }
}
 
开发者ID:RWTH-i5-IDSG,项目名称:jamocha,代码行数:22,代码来源:PathBlocks.java

示例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);
}
 
开发者ID:RWTH-i5-IDSG,项目名称:jamocha,代码行数:24,代码来源:PathBlocks.java

示例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;
}
 
开发者ID:quadrama,项目名称:DramaNLP,代码行数:19,代码来源:NetworkExtractor.java

示例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;
}
 
开发者ID:dbunibas,项目名称:BART,代码行数:21,代码来源:GenerateStratification.java

示例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);
}
 
开发者ID:gama-platform,项目名称:gama,代码行数:23,代码来源:ModelAssembler.java

示例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;
}
 
开发者ID:therelaxist,项目名称:spring-usc,代码行数:18,代码来源:GraphUtil.java

示例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);
        }
    }
}
 
开发者ID:donatellosantoro,项目名称:Llunatic,代码行数:22,代码来源:BuildFaginDependencyGraph.java

示例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;
}
 
开发者ID:donatellosantoro,项目名称:Llunatic,代码行数:18,代码来源:BuildEGDStratification.java

示例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;
}
 
开发者ID:donatellosantoro,项目名称:Llunatic,代码行数:18,代码来源:BuildTGDStratification.java

示例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"));
   }
 
开发者ID:JanaWengenroth,项目名称:GKA1,代码行数:20,代码来源:TarjanLowestCommonAncestorTest.java

示例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);
      }
    }
  }
}
 
开发者ID:salesforce,项目名称:AptSpring,代码行数:13,代码来源:DefinitionGraphInpector.java

示例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;
}
 
开发者ID:salesforce,项目名称:AptSpring,代码行数:43,代码来源:DefinitionContentInspector.java

示例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);
}
 
开发者ID:goldmansachs,项目名称:obevo,代码行数:32,代码来源:GraphSorterTest.java

示例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);
}
 
开发者ID:goldmansachs,项目名称:obevo,代码行数:32,代码来源:GraphSorterTest.java


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