private Dsm<Resource> getDsm(Collection<Resource> subProjects) { CycleDetector<Resource> cycleDetector = new CycleDetector<Resource>(index, subProjects); Set<Cycle> cycles = cycleDetector.getCycles(); MinimumFeedbackEdgeSetSolver solver = new MinimumFeedbackEdgeSetSolver(cycles); Set<Edge> feedbackEdges = solver.getEdges(); Dsm<Resource> dsm = new Dsm<Resource>(index, subProjects, feedbackEdges); DsmTopologicalSorter.sort(dsm); return dsm; }
@Test public void testFlagFeedbackEdgesOnSimpleLoop() { DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph(); dcg.addEdge("A", "B", 3).addEdge("B", "A", 1); CycleDetector<String> cycleDetector = new CycleDetector<String>(dcg); cycleDetector.detectCycles(); MinimumFeedbackEdgeSetSolver solver = new MinimumFeedbackEdgeSetSolver(cycleDetector.getCycles()); Set<Edge> feedbackEdges = solver.getEdges(); assertTrue(feedbackEdges.contains(dcg.getEdge("B", "A"))); }
@Test public void testGetFeedbackEdgesOnComplexGraph() { DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph(); dcg.addEdge("A", "B", 7).addEdge("B", "C", 3).addEdge("C", "D", 1).addEdge("D", "A", 3); dcg.addEdge("B", "A", 12); CycleDetector<String> cycleDetector = new CycleDetector<String>(dcg); cycleDetector.detectCycles(); MinimumFeedbackEdgeSetSolver solver = new MinimumFeedbackEdgeSetSolver(cycleDetector.getCycles()); Set<Edge> feedbackEdges = solver.getEdges(); assertThat(feedbackEdges.size(), is(1)); assertTrue(feedbackEdges.contains(dcg.getEdge("A", "B"))); }
@Test public void testApproximateMinimumFeedbackEdges() { DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph(); dcg.addEdge("A", "B", 5).addEdge("B", "C", 9).addEdge("C", "A", 1); dcg.addEdge("D", "B", 5).addEdge("C", "D", 7); dcg.addEdge("F", "B", 5).addEdge("C", "F", 4); CycleDetector<String> cycleDetector = new CycleDetector<String>(dcg); cycleDetector.detectCycles(); MinimumFeedbackEdgeSetSolver minimumSolver = new MinimumFeedbackEdgeSetSolver(cycleDetector.getCycles()); assertThat(minimumSolver.getEdges().size(), is(1)); assertTrue(minimumSolver.getEdges().contains(dcg.getEdge("B", "C"))); MinimumFeedbackEdgeSetSolver approximateSolver = new MinimumFeedbackEdgeSetSolver(cycleDetector.getCycles(), 2); assertThat(approximateSolver.getEdges().size(), is(2)); assertTrue(approximateSolver.getEdges().contains(dcg.getEdge("B", "C"))); assertTrue(approximateSolver.getEdges().contains(dcg.getEdge("C", "A"))); }
@Test public void testFlagFeedbackEdgesOnUnrelatedCycles() { DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph(); dcg.addEdge("A", "B", 7).addEdge("B", "C", 3).addEdge("C", "A", 2); dcg.addEdge("D", "E", 3).addEdge("E", "D", 5); dcg.addEdge("F", "G", 1).addEdge("G", "H", 4).addEdge("H", "F", 7); CycleDetector<String> cycleDetector = new CycleDetector<String>(dcg); cycleDetector.detectCycles(); MinimumFeedbackEdgeSetSolver solver = new MinimumFeedbackEdgeSetSolver(cycleDetector.getCycles()); Set<Edge> feedbackEdges = solver.getEdges(); assertThat(feedbackEdges.size(), is(3)); assertTrue(feedbackEdges.contains(dcg.getEdge("C", "A"))); assertTrue(feedbackEdges.contains(dcg.getEdge("D", "E"))); assertTrue(feedbackEdges.contains(dcg.getEdge("F", "G"))); }