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


Java DefaultDirectedGraph类代码示例

本文整理汇总了Java中org.jgrapht.graph.DefaultDirectedGraph的典型用法代码示例。如果您正苦于以下问题:Java DefaultDirectedGraph类的具体用法?Java DefaultDirectedGraph怎么用?Java DefaultDirectedGraph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DefaultDirectedGraph类属于org.jgrapht.graph包,在下文中一共展示了DefaultDirectedGraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testComplexDag

import org.jgrapht.graph.DefaultDirectedGraph; //导入依赖的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: getGraph

import org.jgrapht.graph.DefaultDirectedGraph; //导入依赖的package包/类
/**
 * Convert an FNSS Topology to a JGraphT graph.
 * 
 * @param topology FNSS Topology object
 * @return A JGraphT graph
 */
public static Graph<String, Edge> getGraph(Topology topology) {
	Graph<String, Edge> graph = null;
	if (topology.isDirected()) {
		graph = new DefaultDirectedGraph<String, Edge>(Edge.class);
	} else {
		graph = new SimpleGraph<String, Edge>(Edge.class);
	}
	for(String node : topology.getAllNodes()) {
		graph.addVertex(node);
	}
	for(Pair<String, String> endpoints : topology.getAllEdges()) {
		Edge edge = topology.getEdge(endpoints);
		graph.addEdge(endpoints.getU(), endpoints.getV(), edge);
	}
	return graph;
}
 
开发者ID:fnss,项目名称:fnss-java,代码行数:23,代码来源:JGraphTConverter.java

示例3: testExecute

import org.jgrapht.graph.DefaultDirectedGraph; //导入依赖的package包/类
@Test
public void testExecute() throws Exception {
    // GIVEN
    final Node n1 = graphElementFactory.createNode("n1", Arrays.asList("A"),
            ImmutableMap.<String, Object>builder().put("id", 1l).build());
    final Node n2 = graphElementFactory.createNode("n2", Arrays.asList("A"),
            ImmutableMap.<String, Object>builder().put("id", 2l).build());
    final Edge e1 = graphElementFactory.createEdge(n1, n2, "e1", Arrays.asList("E"),
            ImmutableMap.<String, Object>builder().put("id", 3l).build());

    final Graph<Node, Edge> graph = new DefaultDirectedGraph<>(new ClassBasedEdgeFactory<>(Edge.class));
    graph.addVertex(n1);
    graph.addVertex(n2);
    graph.addEdge(e1.getSourceNode(), e1.getTargetNode(), e1);

    // WHEN
    operation.execute(connection, graph);

    // THEN
    final ArgumentCaptor<String> queryCaptor = ArgumentCaptor.forClass(String.class);
    verify(operation).executeQuery(eq(connection), queryCaptor.capture());
    final String query = queryCaptor.getValue();
    assertThat(query, containsString("CREATE (n1:A {id:1}),(n2:A {id:2}),(n1)-[e1:E {id:3}]->(n2)"));
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:25,代码来源:InsertOperationTest.java

示例4: testExecute

import org.jgrapht.graph.DefaultDirectedGraph; //导入依赖的package包/类
@Test
public void testExecute() throws Exception {
    // GIVEN
    final Node n1 = graphElementFactory.createNode("n1", Arrays.asList("A"),
            ImmutableMap.<String, Object>builder().put("id", 1l).build());
    final Node n2 = graphElementFactory.createNode("n2", Arrays.asList("A"),
            ImmutableMap.<String, Object>builder().put("id", 2l).build());
    final Edge e1 = graphElementFactory.createEdge(n1, n2, "e1", Arrays.asList("E"), Collections.emptyMap());

    final Graph<Node, Edge> graph = new DefaultDirectedGraph<>(new ClassBasedEdgeFactory<>(Edge.class));
    graph.addVertex(n1);
    graph.addVertex(n2);
    graph.addEdge(e1.getSourceNode(), e1.getTargetNode(), e1);

    // WHEN
    operation.execute(connection, graph);

    // THEN
    final ArgumentCaptor<String> queryCaptor = ArgumentCaptor.forClass(String.class);
    verify(operation, times(2)).executeQuery(eq(connection), queryCaptor.capture());
    final String query = queryCaptor.getValue();
    assertThat(query, containsString("MATCH (n:A) DETACH DELETE n"));
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:24,代码来源:DeleteAllOperationTest.java

示例5: testExecute

import org.jgrapht.graph.DefaultDirectedGraph; //导入依赖的package包/类
@Test
public void testExecute() throws Exception {
    // GIVEN
    final Node n1 = graphElementFactory.createNode("n1", Arrays.asList("A"),
            ImmutableMap.<String, Object>builder().put("id", 1l).put("value", "A").build());
    final Node n2 = graphElementFactory.createNode("n2", Arrays.asList("A"),
            ImmutableMap.<String, Object>builder().put("id", 2l).build());
    final Edge e1 = graphElementFactory.createEdge(n1, n2, "e1", Arrays.asList("E"),
            ImmutableMap.<String, Object>builder().put("id", 3l).put("value", "C").build());

    final Graph<Node, Edge> graph = new DefaultDirectedGraph<>(new ClassBasedEdgeFactory<>(Edge.class));
    graph.addVertex(n1);
    graph.addVertex(n2);
    graph.addEdge(e1.getSourceNode(), e1.getTargetNode(), e1);

    // WHEN
    operation.execute(connection, graph);

    // THEN
    final ArgumentCaptor<String> queryCaptor = ArgumentCaptor.forClass(String.class);
    verify(operation, times(2)).executeQuery(eq(connection), queryCaptor.capture());
    final List<String> queries = queryCaptor.getAllValues();
    assertThat(queries.get(0), containsString("MATCH (n1:A {id:1}) SET n1.value=\"A\""));
    assertThat(queries.get(1), containsString("MATCH (n1:A {id:1}),(n2:A {id:2}) MERGE (n1)-[e1:E]->(n2) SET e1.id=3,e1.value=\"C\""));
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:26,代码来源:UpdateOperationTest.java

示例6: testExecute

import org.jgrapht.graph.DefaultDirectedGraph; //导入依赖的package包/类
@Test
public void testExecute() throws Exception {
    // GIVEN
    final Node n1 = graphElementFactory.createNode("n1", Arrays.asList("A"),
            ImmutableMap.<String, Object>builder().put("id", 1l).put("value", "A").build());
    final Node n2 = graphElementFactory.createNode("n2", Arrays.asList("A"),
            ImmutableMap.<String, Object>builder().put("id", 2l).build());
    final Edge e1 = graphElementFactory.createEdge(n1, n2, "e1", Arrays.asList("E"),
            ImmutableMap.<String, Object>builder().put("id", 3l).put("value", "C").build());

    final Graph<Node, Edge> graph = new DefaultDirectedGraph<>(new ClassBasedEdgeFactory<>(Edge.class));
    graph.addVertex(n1);
    graph.addVertex(n2);
    graph.addEdge(e1.getSourceNode(), e1.getTargetNode(), e1);

    // WHEN
    operation.execute(connection, graph);

    // THEN
    final ArgumentCaptor<String> queryCaptor = ArgumentCaptor.forClass(String.class);
    verify(operation, times(3)).executeQuery(eq(connection), queryCaptor.capture());
    final List<String> queries = queryCaptor.getAllValues();
    assertThat(queries.get(0), containsString("MERGE (n1:A {id:1}) SET n1.value=\"A\""));
    assertThat(queries.get(1), containsString("MERGE (n2:A {id:2})"));
    assertThat(queries.get(2), containsString("MATCH (n1:A {id:1}),(n2:A {id:2}) MERGE (n1)-[e1:E]->(n2) SET e1.id=3,e1.value=\"C\""));
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:27,代码来源:RefreshOperationTest.java

示例7: initDependencyGraph

import org.jgrapht.graph.DefaultDirectedGraph; //导入依赖的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

示例8: computeReverseJGraph

import org.jgrapht.graph.DefaultDirectedGraph; //导入依赖的package包/类
/**
 * Returns a reverted version of this graph in a jGraph
 *
 * That is a graph containing exactly the same nodes as this one but for
 * each edge from v1 to v2 in this graph the resulting graph will contain an
 * edge from v2 to v1 - or in other words the reverted edge
 *
 * This is used to revert CFGs in order to determine control dependencies
 * for example
 *
 * @return a {@link org.jgrapht.graph.DefaultDirectedGraph} object.
 */
protected DefaultDirectedGraph<V, E> computeReverseJGraph() {

	DefaultDirectedGraph<V, E> r = new DefaultDirectedGraph<V, E>(edgeClass);

	for (V v : vertexSet())
		if (!r.addVertex(v))
			throw new IllegalStateException(
					"internal error while adding vertices");

	for (E e : edgeSet()) {
		V src = getEdgeSource(e);
		V target = getEdgeTarget(e);
		if (r.addEdge(target, src) == null)
			throw new IllegalStateException(
					"internal error while adding reverse edges");
	}

	return r;
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:32,代码来源:EvoSuiteGraph.java

示例9: createGraphFrom

import org.jgrapht.graph.DefaultDirectedGraph; //导入依赖的package包/类
@Override public @NonNull DirectedGraph<String, DefaultEdge> createGraphFrom(
		final @NonNull Set<? extends NodeDescriptor> identities) {
	requireNonNull(identities);

	final DefaultDirectedGraph<String, DefaultEdge> graph = new DefaultDirectedGraph<>(DefaultEdge.class);
	identities.forEach(identity -> graph.addVertex(identity.id()));

	final List<String> sortedIds = identities.stream()
	                                         .map(NodeDescriptor::id)
	                                         .sorted()
	                                         .collect(Collectors.toList());
	sortedIds.stream().reduce(getLast(sortedIds), (nodeIdentity1, nodeIdentity2) -> {
		graph.addEdge(nodeIdentity1, nodeIdentity2);
		return nodeIdentity2;
	});
	return new UnmodifiableDirectedGraph<>(graph);
}
 
开发者ID:Kelleth,项目名称:age3-nanorobots,代码行数:18,代码来源:RingTopologyProcessor.java

示例10: getTopology

import org.jgrapht.graph.DefaultDirectedGraph; //导入依赖的package包/类
protected StormTopology getTopology() {
	// Crawl the graph and create execution pipelines to be run in the bolts.
	ft.logicalToBoltGraph();

	// Now, convert the bolt graph to a topology.		
	TopologyBuilder builder = new TopologyBuilder();

	// Create the coordinator spout.
	builder.setSpout("FlexyMaster", new FlexyMasterSpout());

	// Start from the leaves and walk to the spouts using DFS.
	Set<FlexyBolt> built_memo = new HashSet<FlexyBolt>();
	DefaultDirectedGraph<FlexyBolt, IndexedEdge<FStream>> boltG = ft.getBoltG();
	for (FlexyBolt b : boltG.vertexSet()) {
		if (boltG.outDegreeOf(b) == 0) {
			_visitAndBuild(b, built_memo, builder);
		}
	}

	return builder.createTopology();
}
 
开发者ID:JamesLampton,项目名称:piggybank-squeal,代码行数:22,代码来源:Main.java

示例11: buildEGDStrataGraph

import org.jgrapht.graph.DefaultDirectedGraph; //导入依赖的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

示例12: buildStrataGraph

import org.jgrapht.graph.DefaultDirectedGraph; //导入依赖的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

示例13: testBinaryTree

import org.jgrapht.graph.DefaultDirectedGraph; //导入依赖的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

示例14: build

import org.jgrapht.graph.DefaultDirectedGraph; //导入依赖的package包/类
private void build(Task task, ImmutableList.Builder<RunnableTaskDag> entriesBuilder, ImmutableMap.Builder<TaskId, Task> tasksBuilder)
{
    DefaultDirectedGraph<TaskId, DefaultEdge> graph = new DefaultDirectedGraph<>(DefaultEdge.class);
    worker(graph, task, null, tasksBuilder, Sets.newHashSet());

    CycleDetector<TaskId, DefaultEdge> cycleDetector = new CycleDetector<>(graph);
    if ( cycleDetector.detectCycles() )
    {
        throw new RuntimeException("The Task DAG contains cycles: " + task);
    }

    TopologicalOrderIterator<TaskId, DefaultEdge> orderIterator = new TopologicalOrderIterator<>(graph);
    while ( orderIterator.hasNext() )
    {
        TaskId taskId = orderIterator.next();
        Set<DefaultEdge> taskIdEdges = graph.edgesOf(taskId);
        Set<TaskId> processed = taskIdEdges
            .stream()
            .map(graph::getEdgeSource)
            .filter(edge -> !edge.equals(taskId) && !edge.getId().equals(""))
            .collect(Collectors.toSet());
        entriesBuilder.add(new RunnableTaskDag(taskId, processed));
    }
}
 
开发者ID:NirmataOSS,项目名称:workflow,代码行数:25,代码来源:RunnableTaskDagBuilder.java

示例15: testAddEdgeWithMissingVertices

import org.jgrapht.graph.DefaultDirectedGraph; //导入依赖的package包/类
@Test
public void testAddEdgeWithMissingVertices() {
	Graph<String, String> graph = new DefaultDirectedGraph<>(new EdgeFactory<String, String>() {
		public String createEdge(String sourceVertex, String targetVertex) {
			return sourceVertex + targetVertex;
		};
	});
	graph = new AddVerticesAutomatically<>(graph);
	graph.addEdge("A", "B");
	graph.addEdge("A", "C", "DEF");
	assertTrue(graph.containsVertex("A"));
	assertTrue(graph.containsVertex("B"));
	assertTrue(graph.containsVertex("C"));
	assertTrue(graph.containsEdge("AB"));
	assertTrue(graph.containsEdge("DEF"));
}
 
开发者ID:andreasbehnke,项目名称:javaan,代码行数:17,代码来源:TestAddVerticesAutomatically.java


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