當前位置: 首頁>>代碼示例>>Java>>正文


Java DirectedGraph.addEdge方法代碼示例

本文整理匯總了Java中org.jgrapht.DirectedGraph.addEdge方法的典型用法代碼示例。如果您正苦於以下問題:Java DirectedGraph.addEdge方法的具體用法?Java DirectedGraph.addEdge怎麽用?Java DirectedGraph.addEdge使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jgrapht.DirectedGraph的用法示例。


在下文中一共展示了DirectedGraph.addEdge方法的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: 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

示例3: 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

示例4: 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

示例5: replaceVertex

import org.jgrapht.DirectedGraph; //導入方法依賴的package包/類
private static void replaceVertex(DirectedGraph<IAtomicDerivedStateProcessor<? extends EObject>, DefaultEdge> graph,
        IAtomicDerivedStateProcessor<? extends EObject> original,
        IAtomicDerivedStateProcessor<? extends EObject> replacement) {

    Collection<DefaultEdge> edgeDump = new ArrayList<>();

    for (DefaultEdge incomingEdge : graph.incomingEdgesOf(original)) {
        IAtomicDerivedStateProcessor<? extends EObject> edgeSource = graph.getEdgeSource(incomingEdge);
        edgeDump.add(incomingEdge);
        graph.addEdge(edgeSource, replacement);
    }

    for (DefaultEdge outgoingEdge : graph.outgoingEdgesOf(original)) {
        // we do not insert the dependencies of the removed vertex because the new vertex has its own dependencies
        edgeDump.add(outgoingEdge);
    }

    edgeDump.forEach(graph::removeEdge);
    graph.removeVertex(original);
}
 
開發者ID:Cooperate-Project,項目名稱:CooperateModelingEnvironment,代碼行數:21,代碼來源:DerivedStateProcessor.java

示例6: 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

示例7: 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

示例8: 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

示例9: 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:j123b567,項目名稱:stack-usage,代碼行數:20,代碼來源:TarjanLowestCommonAncestorTest.java

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: testOrderingWithSubgraph

import org.jgrapht.DirectedGraph; //導入方法依賴的package包/類
@Test
public void testOrderingWithSubgraph() {
    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 : shuffledList(sp1, sp2, sp3, sp4, sp5)) {
        graph.addVertex(vertex);
    }

    graph.addEdge(sp2, sp1);
    graph.addEdge(sp5, sp4);
    graph.addEdge(sp1, sp5);
    graph.addEdge(sp3, sp5);

    ImmutableList<String> sorted = sorter.sortChanges(graph, Lists.mutable.with(sp1, sp2, sp3));

    // First, compare the root topological order (i.e. ensure that the dependencies are respected)
    assertEquals(3, sorted.size());
    assertThat(sorted.indexOf(sp1), greaterThan(sorted.indexOf(sp2)));

    // Now check that we can achieve a consistent order too (for easier debuggability for clients)
    assertEquals(Lists.immutable.with(sp2, sp1, sp3), sorted);
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:29,代碼來源:GraphSorterTest.java

示例15: testCycleDetection

import org.jgrapht.DirectedGraph; //導入方法依賴的package包/類
@Test
public void testCycleDetection() {
    SortableDependency sp1 = newVertex("sp1");
    SortableDependency sp2 = newVertex("sp2");
    SortableDependency sp3 = newVertex("sp3");
    SortableDependency sp4 = newVertex("sp4");
    SortableDependency sp5 = newVertex("sp5");
    SortableDependency sp6 = newVertex("sp6");
    SortableDependency sp7 = newVertex("sp7");
    SortableDependency sp8 = newVertex("sp8");

    DirectedGraph<SortableDependency, DefaultEdge> graph = new DefaultDirectedGraph<SortableDependency, DefaultEdge>(DefaultEdge.class);
    for (SortableDependency vertex : shuffledList(sp1, sp2, sp3, sp4, sp5, sp6, sp7, sp8)) {
        graph.addVertex(vertex);
    }

    graph.addEdge(sp2, sp1);
    graph.addEdge(sp5, sp4);
    graph.addEdge(sp1, sp5);
    graph.addEdge(sp3, sp5);
    graph.addEdge(sp4, sp5);
    graph.addEdge(sp7, sp6);
    graph.addEdge(sp8, sp7);
    graph.addEdge(sp6, sp8);

    try {
        sorter.sortChanges(graph);
        fail("Expecting exception here: " + GraphCycleException.class);
    } catch (GraphCycleException e) {
        verifyCycleExists(e, Sets.immutable.with("sp4", "sp5"));
        verifyCycleExists(e, Sets.immutable.with("sp6", "sp7", "sp8"));
        Verify.assertSize(2, e.getCycleComponents());
    }
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:35,代碼來源:GraphSorterTest.java


注:本文中的org.jgrapht.DirectedGraph.addEdge方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。