Java Code Examples for org.jgrapht.UndirectedGraph#edgeSet()
The following examples show how to use
org.jgrapht.UndirectedGraph#edgeSet() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FindFormulaWithAdornments.java From BART with MIT License | 6 votes |
@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); }
Example 2
Source File: FindSymmetricAtoms.java From Llunatic with GNU General Public License v3.0 | 6 votes |
private SymmetricAtoms analyzeAtoms(SelfJoin selfJoin, UndirectedGraph<TableAlias, LabeledEdge> joinGraph) { Set<TableAlias> symmetricAtoms = new HashSet<TableAlias>(); if (logger.isDebugEnabled()) logger.debug("Analyzing self join " + selfJoin); for (int i = 0; i < selfJoin.getAtoms().size() - 1; i++) { TableAlias aliasi = selfJoin.getAtoms().get(i); for (int j = i + 1; j < selfJoin.getAtoms().size(); j++) { TableAlias aliasj = selfJoin.getAtoms().get(j); UndirectedGraph<TableAlias, LabeledEdge> joinGraphForTableAliasi = buildSubGraph(aliasi, aliasj, joinGraph); UndirectedGraph<TableAlias, LabeledEdge> joinGraphForTableAliasj = buildSubGraph(aliasj, aliasi, joinGraph); Set<LabeledEdge> edgesi = joinGraphForTableAliasi.edgeSet(); Set<LabeledEdge> edgesj = joinGraphForTableAliasj.edgeSet(); if (containsAll(edgesi, edgesj) && containsAll(edgesj, edgesi)) { symmetricAtoms.addAll(joinGraphForTableAliasi.vertexSet()); } } } return new SymmetricAtoms(symmetricAtoms, selfJoin); }
Example 3
Source File: FindSymmetricAtoms.java From Llunatic with GNU General Public License v3.0 | 5 votes |
private UndirectedGraph<TableAlias, LabeledEdge> buildSubGraph(TableAlias alias, TableAlias otherAlias, UndirectedGraph<TableAlias, LabeledEdge> graph) { Set<TableAlias> vertices = new HashSet<TableAlias>(graph.vertexSet()); vertices.remove(otherAlias); UndirectedSubgraph<TableAlias, LabeledEdge> subgraph = new UndirectedSubgraph<TableAlias, LabeledEdge>(graph, vertices, graph.edgeSet()); ConnectivityInspector<TableAlias, LabeledEdge> inspector = new ConnectivityInspector<TableAlias, LabeledEdge>(subgraph); Set<TableAlias> connectedVertices = inspector.connectedSetOf(alias); UndirectedSubgraph<TableAlias, LabeledEdge> connectedSubgraph = new UndirectedSubgraph<TableAlias, LabeledEdge>(graph, connectedVertices, graph.edgeSet()); return connectedSubgraph; }
Example 4
Source File: TGraphs.java From Llunatic with GNU General Public License v3.0 | 4 votes |
public void testGraph() { UndirectedGraph<String, LabeledEdge> graph = new SimpleGraph<String, LabeledEdge>(LabeledEdge.class); Set<String> vertices = new HashSet<String>(); vertices.add("R1"); vertices.add("R2"); vertices.add("T1"); vertices.add("T2"); vertices.add("S"); vertices.add("V"); graph.addVertex("R1"); graph.addVertex("R2"); graph.addVertex("T1"); graph.addVertex("T2"); graph.addVertex("S"); graph.addVertex("V"); graph.addEdge("R1", "S", new LabeledEdge("R1", "S", "R.A,S.A")); graph.addEdge("R2", "S", new LabeledEdge("R2", "S", "R.A,S.A")); graph.addEdge("R1", "T1", new LabeledEdge("R1", "T1", "R.B,T.B")); graph.addEdge("R2", "T2", new LabeledEdge("R2", "T2", "R.B,T.B")); graph.addEdge("R1", "R2", new LabeledEdge("R1", "R2", "R.A,R.A")); // graph.addEdge("T1", "V", new LabeledEdge("T1", "V", "T.C,V.C")); Set<String> vertices1 = new HashSet<String>(vertices); vertices1.remove("R2"); UndirectedSubgraph<String, LabeledEdge> subgraph1 = new UndirectedSubgraph<String, LabeledEdge>(graph, vertices1, graph.edgeSet()); ConnectivityInspector<String, LabeledEdge> inspector1 = new ConnectivityInspector<String, LabeledEdge>(subgraph1); Set<String> connectedVertices1 = inspector1.connectedSetOf("R1"); UndirectedSubgraph<String, LabeledEdge> connectedSubgraph1 = new UndirectedSubgraph<String, LabeledEdge>(graph, connectedVertices1, graph.edgeSet()); Set<String> vertices2 = new HashSet<String>(vertices); vertices2.remove("R1"); UndirectedSubgraph<String, LabeledEdge> subgraph2 = new UndirectedSubgraph<String, LabeledEdge>(graph, vertices2, graph.edgeSet()); ConnectivityInspector<String, LabeledEdge> inspector2 = new ConnectivityInspector<String, LabeledEdge>(subgraph2); Set<String> connectedVertices2 = inspector2.connectedSetOf("R2"); UndirectedSubgraph<String, LabeledEdge> connectedSubgraph2 = new UndirectedSubgraph<String, LabeledEdge>(graph, connectedVertices2, graph.edgeSet()); Set<LabeledEdge> edges1 = connectedSubgraph1.edgeSet(); Set<LabeledEdge> edges2 = connectedSubgraph2.edgeSet(); if (containsAll(edges1, edges2)) { logger.debug("R1 is contained in R2"); } if (containsAll(edges2, edges1)) { logger.debug("R2 is contained in R1"); } }