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


Java Graph類代碼示例

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


Graph類屬於org.jgrapht包,在下文中一共展示了Graph類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: findFormulaWithAdornments

import org.jgrapht.Graph; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private FormulaWithAdornments findFormulaWithAdornments(UndirectedGraph<FormulaGraphVertex, DefaultEdge> formulaGraph,
        List<VariablePair> variablePairs, List<FormulaVariable> anonymousVariables, IFormula formula) {
    Set<FormulaGraphVertex> vertices = new HashSet<FormulaGraphVertex>(formulaGraph.vertexSet());
    for (VariablePair variablePair : variablePairs) {
        vertices.remove(variablePair.getVertex());
    }
    UndirectedSubgraph<FormulaGraphVertex, DefaultEdge> subgraph = new UndirectedSubgraph<FormulaGraphVertex, DefaultEdge>(formulaGraph, vertices, formulaGraph.edgeSet());
    ConnectivityInspector<FormulaGraphVertex, DefaultEdge> inspector = new ConnectivityInspector<FormulaGraphVertex, DefaultEdge>(subgraph);
    List<Set<FormulaGraphVertex>> connectedVertices = inspector.connectedSets();
    if (connectedVertices.size() != 2) {
        return null;
    }
    UndirectedSubgraph<FormulaGraphVertex, DefaultEdge> connectedSubgraphOne = new UndirectedSubgraph<FormulaGraphVertex, DefaultEdge>(formulaGraph, connectedVertices.get(0), formulaGraph.edgeSet());
    UndirectedSubgraph<FormulaGraphVertex, DefaultEdge> connectedSubgraphTwo = new UndirectedSubgraph<FormulaGraphVertex, DefaultEdge>(formulaGraph, connectedVertices.get(1), formulaGraph.edgeSet());
    VertexEquivalenceComparator vertexComparator = new VertexEquivalenceComparator(variablePairs, anonymousVariables);
    UniformEquivalenceComparator<DefaultEdge, Graph<FormulaGraphVertex, DefaultEdge>> edgeComparator = new UniformEquivalenceComparator<DefaultEdge, Graph<FormulaGraphVertex, DefaultEdge>>();
    GraphIsomorphismInspector<Graph<FormulaGraphVertex, DefaultEdge>> isomorphismInspector = AdaptiveIsomorphismInspectorFactory.createIsomorphismInspector(connectedSubgraphOne, connectedSubgraphTwo, vertexComparator, edgeComparator);
    boolean areIsomorphic = isomorphismInspector.isIsomorphic();
    if (logger.isDebugEnabled()) logger.debug("Graph One: \n" + connectedSubgraphOne + "\nGraph Two: \n" + connectedSubgraphTwo + "\nAre isomorphic: " + areIsomorphic);
    if (!areIsomorphic) {
        return null;
    }
    return formulaWithAdornmentsGenerator.generate(formula, connectedSubgraphOne, connectedSubgraphTwo, variablePairs);
}
 
開發者ID:dbunibas,項目名稱:BART,代碼行數:26,代碼來源:FindFormulaWithAdornments.java

示例2: generateCompleteGraph

import org.jgrapht.Graph; //導入依賴的package包/類
private Graph<AutomatVertex, DefaultEdge> generateCompleteGraph(int size) {
    LOG.info("--- generateCompleteGraph ---");

    //Create the CompleteGraphGenerator object
    final Graph<AutomatVertex, DefaultEdge> completeGraph = new SimpleGraph<>(DefaultEdge.class);
    final CompleteGraphGenerator<AutomatVertex, DefaultEdge> completeGenerator = new CompleteGraphGenerator<>(size);

    //Create the VertexFactory so the generator can create vertices
    final VertexFactory<AutomatVertex> vFactory = new ClassBasedVertexFactory<>(AutomatVertex.class);

    LOG.info("Generating complete graph");

    //Use the CompleteGraphGenerator object to make completeGraph a
    //complete graph with [size] number of vertices
    completeGenerator.generateGraph(completeGraph, vFactory, null);
    return completeGraph;
}
 
開發者ID:bedla,項目名稱:parkovani-v-praze,代碼行數:18,代碼來源:GraphDataLoaderController.java

示例3: exampleGraph

import org.jgrapht.Graph; //導入依賴的package包/類
/**
 * Shows how to create an FNSS Topology, convert it to a JGraphT Graph and
 * then compute shortest paths
 */
public static void exampleGraph() {
	// create a simple FNSS topology
	Topology topology = new Topology();
	topology.addEdge("1", "2", new Edge());
	topology.addEdge("2", "3", new Edge());
	
	// convert to JGraphT
	Graph<String, Edge> graph = JGraphTConverter.getGraph(topology);
	
	// Find shortest paths
	String source = "3";
	String destination = "1";
	List<Edge> sp = DijkstraShortestPath.findPathBetween(graph, source, destination);
	
	// Print results
	System.out.println("Shortest path from " + source + " to " + destination + ":");
	for (Edge e : sp) {
		System.out.println(graph.getEdgeSource(e) + " -> " + graph.getEdgeTarget(e));
	}
}
 
開發者ID:fnss,項目名稱:fnss-java,代碼行數:25,代碼來源:ExampleJGraphT.java

示例4: getGraph

import org.jgrapht.Graph; //導入依賴的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

示例5: difference

import org.jgrapht.Graph; //導入依賴的package包/類
public static <V, E, T extends Graph<V, E>> T difference(T result, Graph<V, E> baseSet, Graph<V, E> removalSet) {

        baseSet.edgeSet().forEach(e -> {
            boolean skip = removalSet.containsEdge(e);
            if(!skip) {
                V srcVertex = baseSet.getEdgeSource(e);
                V tgtVertex = baseSet.getEdgeTarget(e);
                result.addVertex(srcVertex);
                result.addVertex(tgtVertex);
                result.addEdge(srcVertex, tgtVertex, e);
            }
        });

//    	Graphs.addGraph(result, baseSet);
//
//        //Graphs.unio
//        result.removeAllEdges(removalSet.edgeSet());
//        baseSet.vertexSet().forEach(v -> {
//            if(baseSet.edgesOf(v).isEmpty()) {
//                result.removeVertex(v);
//            }
//        });
//
        return result;
    }
 
開發者ID:SmartDataAnalytics,項目名稱:SubgraphIsomorphismIndex,代碼行數:26,代碼來源:SetOpsJGraphTBase.java

示例6: transformItems

import org.jgrapht.Graph; //導入依賴的package包/類
public static <V, E, G extends Graph<V, E>> G transformItems(G result, G set, Function<V, V> nodeTransform, BiFunction<E, Function<V, V>, E> edgeTransform) {
    set.vertexSet().stream()
        .map(item -> MoreObjects.firstNonNull(nodeTransform.apply(item), item))
        .forEach(result::addVertex);

    set.edgeSet().stream().forEach(e -> {
        V src = set.getEdgeSource(e);
        V tgt = set.getEdgeTarget(e);

        V tmpSrc = nodeTransform.apply(src);
        V tmpTgt = nodeTransform.apply(tgt);

        V isoSrc = tmpSrc != null ? tmpSrc : src;
        V isoTgt = tmpTgt != null ? tmpTgt : tgt;

        E isoEdge = edgeTransform.apply(e, nodeTransform);

        result.addEdge(isoSrc, isoTgt, isoEdge);
    });

    return result;
}
 
開發者ID:SmartDataAnalytics,項目名稱:SubgraphIsomorphismIndex,代碼行數:23,代碼來源:SetOpsJGraphTBase.java

示例7: getAndUpdateSubGraphs

import org.jgrapht.Graph; //導入依賴的package包/類
/**
 * @param parentGraph
 * @return SubGraphs sets, with graph items indices
 */
public List<Collection<Integer>> getAndUpdateSubGraphs(Graph<GraphItem, JGraphEdge> parentGraph) {
  ConnectivityInspector<GraphItem, JGraphEdge> connectivityInspector = new ConnectivityInspector<>((UndirectedGraph)parentGraph);
  return getSubGraphsIndicesFrom(connectivityInspector.connectedSets());
}
 
開發者ID:Orange-OpenSource,項目名稱:documentare-simdoc,代碼行數:9,代碼來源:GraphBuilder.java

示例8: compareContent

import org.jgrapht.Graph; //導入依賴的package包/類
private void compareContent(final Graph<Node, Edge> givenGraph, final Graph<Node, Edge> expectedGraph,
        final AssertionErrorCollector errorCollector) {

    final Set<String> expectedNodeTypes = expectedGraph.vertexSet().stream().map(Node::getType).collect(toSet());

    final Set<String> currentNodeTypes = givenGraph.vertexSet().stream().map(Node::getType).collect(toSet());

    verifyNodeLabels(currentNodeTypes, expectedNodeTypes, errorCollector,
            "Nodes with %s labels were expected to be present, but not found");

    checkPresenceOfExpectedNodes(givenGraph, expectedGraph, errorCollector);
    checkPresenceOfExpectedReferences(givenGraph, expectedGraph, errorCollector);
    checkAbsenseOfNotExpectedNodes(givenGraph, expectedGraph, errorCollector);
    checkAbsenseOfNotExpectedReferences(givenGraph, expectedGraph, errorCollector);

    if (isStrict) {
        verifyNodeLabels(expectedNodeTypes, currentNodeTypes, errorCollector,
                "Nodes with %s labels were not expected, but are present");
    }
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:21,代碼來源:GraphComparator.java

示例9: checkPresenceOfExpectedNodes

import org.jgrapht.Graph; //導入依賴的package包/類
private void checkPresenceOfExpectedNodes(final Graph<Node, Edge> givenGraph, final Graph<Node, Edge> expectedGraph,
        final AssertionErrorCollector errorCollector) {
    for (final Node expectedNode : expectedGraph.vertexSet()) {

        final List<String> attributesToExclude = expectedNode.getLabels().stream().map(toExclude::getColumns).flatMap(List::stream)
                .distinct().collect(toList());

        final List<Node> availableNodesOfExpectedType = givenGraph.vertexSet().stream()
                .filter(n -> n.getType().equals(expectedNode.getType())).collect(toList());

        final List<Node> foundNodes = availableNodesOfExpectedType.stream().filter(n -> n.isSame(expectedNode, attributesToExclude))
                .collect(toList());

        if (foundNodes.isEmpty()) {
            errorCollector.collect(expectedNode.asString() + " was expected, but is not present");
        } else if (foundNodes.size() > 1) {
            errorCollector.collect("Ambiguouty detected for node " + expectedNode.asString() + " for given attribute filter");
        }
    }
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:21,代碼來源:GraphComparator.java

示例10: checkPresenceOfExpectedReferences

import org.jgrapht.Graph; //導入依賴的package包/類
private void checkPresenceOfExpectedReferences(final Graph<Node, Edge> givenGraph, final Graph<Node, Edge> expectedGraph,
        final AssertionErrorCollector errorCollector) {
    for (final Edge expectedEdge : expectedGraph.edgeSet()) {

        final List<String> attributesToExclude = expectedEdge.getLabels().stream().map(toExclude::getColumns).flatMap(List::stream)
                .distinct().collect(toList());

        final List<Edge> availableEdgesOfExpectedType = givenGraph.edgeSet().stream()
                .filter(e -> e.getType().equals(expectedEdge.getType())).collect(toList());

        final List<Edge> foundEdges = availableEdgesOfExpectedType.stream().filter(e -> e.isSame(expectedEdge, attributesToExclude))
                .collect(toList());

        if (foundEdges.isEmpty()) {
            errorCollector.collect(expectedEdge.asString() + " was expected, but is not present");
        } else if (foundEdges.size() > 1) {
            errorCollector.collect("Ambiguouty detected for edge " + expectedEdge.asString() + " for given attribute filter");
        }
    }
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:21,代碼來源:GraphComparator.java

示例11: usedTablesOnlyStrategy

import org.jgrapht.Graph; //導入依賴的package包/類
@Override
public CleanupStrategyExecutor<Connection, Graph<Node, Edge>> usedTablesOnlyStrategy() {
    return (final Connection connection, final List<Graph<Node, Edge>> initialGraphs, final String... nodeTypesToRetain) -> {
        if (initialGraphs.isEmpty()) {
            return;
        }

        try {
            for (final Graph<Node, Edge> graph : initialGraphs) {
                Neo4JOperations.DELETE_ALL.execute(connection, computeGraphToBeDeleted(graph, nodeTypesToRetain));
            }

            connection.commit();
        } catch (final SQLException e) {
            throw new DbFeatureException(UNABLE_TO_CLEAN_DATABASE, e);
        }
    };
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:19,代碼來源:CleanupStrategyProvider.java

示例12: usedRowsOnlyStrategy

import org.jgrapht.Graph; //導入依賴的package包/類
@Override
public CleanupStrategyExecutor<Connection, Graph<Node, Edge>> usedRowsOnlyStrategy() {
    return (final Connection connection, final List<Graph<Node, Edge>> initialGraphs, final String... nodeTypesToRetain) -> {
        if (initialGraphs.isEmpty()) {
            return;
        }

        try {
            for (final Graph<Node, Edge> graph : initialGraphs) {
                Neo4JOperations.DELETE.execute(connection, computeGraphToBeDeleted(graph, nodeTypesToRetain));
            }

            connection.commit();
        } catch (final SQLException e) {
            throw new DbFeatureException(UNABLE_TO_CLEAN_DATABASE, e);
        }
    };
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:19,代碼來源:CleanupStrategyProvider.java

示例13: testLoadDataSetsUsingAvailableFilePaths

import org.jgrapht.Graph; //導入依賴的package包/類
@Test
public void testLoadDataSetsUsingAvailableFilePaths() {
    // GIVEN

    // WHEN
    final List<Graph<Node, Edge>> dataSetList = featureExecutor.loadDataSets(Arrays.asList("test-data.xml", "test-data.xml"));

    // THEN
    assertNotNull(dataSetList);
    assertThat(dataSetList.size(), equalTo(2));

    final Graph<Node, Edge> graph1 = dataSetList.get(0);
    assertNotNull(graph1);
    assertThat(graph1.vertexSet().size(), equalTo(6));
    assertThat(graph1.edgeSet().size(), equalTo(4));

    final Graph<Node, Edge> graph2 = dataSetList.get(1);
    assertNotNull(graph2);
    assertThat(graph2.vertexSet().size(), equalTo(6));
    assertThat(graph2.edgeSet().size(), equalTo(4));

    assertThat(graph1, equalTo(graph1));
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:24,代碼來源:Neo4JDbFeatureExecutorTest.java

示例14: testXmlLoaderLoadUsingProperResource

import org.jgrapht.Graph; //導入依賴的package包/類
@Test
public void testXmlLoaderLoadUsingProperResource() throws Exception {
    // WHEN
    final DataSetLoader<Graph<Node, Edge>> loader = LOADER_PROVIDER.xmlLoader();

    // THEN
    assertThat(loader, notNullValue());

    // WHEN
    final Graph<Node, Edge> graph = loader.load(getFile("test-data.xml"));

    // THEN
    assertThat(graph, notNullValue());

    // TODO: finalize me
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:17,代碼來源:DataSetLoaderProviderTest.java

示例15: testExecute

import org.jgrapht.Graph; //導入依賴的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


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