@Test public void testSolve() throws Exception { ConstraintSolver.ConstraintSolverBuilder<String> solverBuilder = new ConstraintSolver.ConstraintSolverBuilder<>(); solverBuilder.add("E1", "E2", "x -> y", "1", "A", "D", 1, 1, 1); solverBuilder.add("E1", "E2", "x -> y", "2", "A#", "D", 3, 1, 1); solverBuilder.add("E2", "E3", "x -> y", "3", "D", "B", 1, 1, 1); solverBuilder.add("E1", "E3", "x -> y", "4", "A", "B", 1, 1, 1); solverBuilder.add("E3", "E4", "x -> y", "5", "B", "C", 1, 1, 1); PrintCollector printCollector = new PrintCollector(true); final List<DetectedRelation<String>> solve = solverBuilder.build().solve(printCollector); assertNotNull(solve); assertThat(solve.size(), is(4)); assertThat(solve.get(0).getEdge(), is(new Edge(1, "1", "x -> y", "A", "D", 1, 1, 1, false))); assertThat(solve.get(1).getEdge(), is(new Edge(4, "4", "x -> y", "A", "B", 1, 1, 1, false))); assertThat(solve.get(2).getEdge(), is(new Edge(3, "3", "x -> y", "D", "B", 1, 1, 1, false))); assertThat(solve.get(3).getEdge(), is(new Edge(5, "5", "x -> y", "B", "C", 1, 1, 1, false))); printCollector.print(Joiner.on("\n").join(solve)); printCollector.print(Graph.transform(solve).toString()); }
public List<DetectedRelation<T>> solve(PrintCollector printCollector) { List<DetectedRelation<T>> detectedRelations = Lists.newArrayList(); pruneGraph(printCollector); ConnectivityInspector<T, Edge> connectivityInspector = new ConnectivityInspector<>(graph); List<Set<T>> connectedComponents = connectivityInspector.connectedSets(); final UndirectedGraph<T, Edge> restored = new Multigraph<>(Edge.class); Graphs.addGraph(restored, graph); printCollector.print(String.format("Graph has %2d components", connectedComponents.size())); for (Set<T> connectedComponent : connectedComponents) { printCollector.print(String.format("Solving connected component with %d vertices", connectedComponent.size())); HashSet<T> difference = Sets.newHashSet(Sets.difference(graph.vertexSet(), connectedComponent)); graph.removeAllVertices(difference); detectedRelations.addAll(solveConnectedComponent(printCollector, connectedComponent)); Graphs.addGraph(graph, restored); } return detectedRelations; }
ConstraintSolver { public List<DetectedRelation<T>> solve(PrintCollector printCollector) { List<DetectedRelation<T>> detectedRelations = Lists.newArrayList(); pruneGraph(printCollector); ConnectivityInspector<T, Edge> connectivityInspector = new ConnectivityInspector<>(graph); List<Set<T>> connectedComponents = connectivityInspector.connectedSets(); final UndirectedGraph<T, Edge> restored = new Multigraph<>(Edge.class); Graphs.addGraph(restored, graph); printCollector.print(String.format("Graph has %2d components", connectedComponents.size())); for (Set<T> connectedComponent : connectedComponents) { printCollector.print(String.format("Solving connected component with %d vertices", connectedComponent.size())); HashSet<T> difference = Sets.newHashSet(Sets.difference(graph.vertexSet(), connectedComponent)); graph.removeAllVertices(difference); detectedRelations.addAll(solveConnectedComponent(printCollector, connectedComponent)); Graphs.addGraph(graph, restored); } return detectedRelations; } }
ConstraintSolver { public List<DetectedRelation<T>> solve(PrintCollector printCollector) { List<DetectedRelation<T>> detectedRelations = Lists.newArrayList(); pruneGraph(printCollector); ConnectivityInspector<T, Edge> connectivityInspector = new ConnectivityInspector<>(graph); List<Set<T>> connectedComponents = connectivityInspector.connectedSets(); final UndirectedGraph<T, Edge> restored = new Multigraph<>(Edge.class); Graphs.addGraph(restored, graph); printCollector.print(String.format("Graph has %2d components", connectedComponents.size())); for (Set<T> connectedComponent : connectedComponents) { printCollector.print(String.format("Solving connected component with %d vertices", connectedComponent.size())); HashSet<T> difference = Sets.newHashSet(Sets.difference(graph.vertexSet(), connectedComponent)); graph.removeAllVertices(difference); detectedRelations.addAll(solveConnectedComponent(printCollector, connectedComponent)); Graphs.addGraph(graph, restored); } return detectedRelations; } private  ConstraintSolver(Set<String> types, Table<String, String, String> rel, Multigraph<T, Edge> graph); }
ConstraintSolver { public List<DetectedRelation<T>> solve(PrintCollector printCollector) { List<DetectedRelation<T>> detectedRelations = Lists.newArrayList(); pruneGraph(printCollector); ConnectivityInspector<T, Edge> connectivityInspector = new ConnectivityInspector<>(graph); List<Set<T>> connectedComponents = connectivityInspector.connectedSets(); final UndirectedGraph<T, Edge> restored = new Multigraph<>(Edge.class); Graphs.addGraph(restored, graph); printCollector.print(String.format("Graph has %2d components", connectedComponents.size())); for (Set<T> connectedComponent : connectedComponents) { printCollector.print(String.format("Solving connected component with %d vertices", connectedComponent.size())); HashSet<T> difference = Sets.newHashSet(Sets.difference(graph.vertexSet(), connectedComponent)); graph.removeAllVertices(difference); detectedRelations.addAll(solveConnectedComponent(printCollector, connectedComponent)); Graphs.addGraph(graph, restored); } return detectedRelations; } private  ConstraintSolver(Set<String> types, Table<String, String, String> rel, Multigraph<T, Edge> graph); List<DetectedRelation<T>> solve(PrintCollector printCollector); }
ConstraintSolver { public List<DetectedRelation<T>> solve(PrintCollector printCollector) { List<DetectedRelation<T>> detectedRelations = Lists.newArrayList(); pruneGraph(printCollector); ConnectivityInspector<T, Edge> connectivityInspector = new ConnectivityInspector<>(graph); List<Set<T>> connectedComponents = connectivityInspector.connectedSets(); final UndirectedGraph<T, Edge> restored = new Multigraph<>(Edge.class); Graphs.addGraph(restored, graph); printCollector.print(String.format("Graph has %2d components", connectedComponents.size())); for (Set<T> connectedComponent : connectedComponents) { printCollector.print(String.format("Solving connected component with %d vertices", connectedComponent.size())); HashSet<T> difference = Sets.newHashSet(Sets.difference(graph.vertexSet(), connectedComponent)); graph.removeAllVertices(difference); detectedRelations.addAll(solveConnectedComponent(printCollector, connectedComponent)); Graphs.addGraph(graph, restored); } return detectedRelations; } private  ConstraintSolver(Set<String> types, Table<String, String, String> rel, Multigraph<T, Edge> graph); List<DetectedRelation<T>> solve(PrintCollector printCollector);  }