Beispiel #1
0
            public ImmutableList <ImmutableHashSet <T> > Solve <T>(IDirectedAcyclicGraph <T> graph)
                where T : IEquatable <T>
            {
                var reducedGraph = DirectedAcyclicGraphTransitiveReducer <T> .ReduceGraph(graph);

                return(internalSolver.Solve(reducedGraph));
            }
Beispiel #2
0
        public void GetTransitiveReduction_HandlesCasesWithMultiplePaths()
        {
            /*
             * ----------|
             * |         V
             * 1 -> 2 -> 3 -> 4
             *      |         ^
             *      ----------|
             */
            var graph = DirectedGraphBuilder <string> .NewBuilder()
                        .AddElement("one")
                        .AddElement("two")
                        .AddElement("three")
                        .AddElement("four")
                        .AddArrow("one", "two")
                        .AddArrow("two", "three")
                        .AddArrow("three", "four")
                        .AddArrow("one", "three")
                        .AddArrow("two", "four")
                        .CreateAcyclicGraphUnsafe();

            /*
             * 1 -> 2 -> 3 -> 4
             */
            var reducedGraph = DirectedAcyclicGraphTransitiveReducer.ReduceGraph(graph);

            reducedGraph.GetDirectSuccessorsOf("one").Should().Contain("two");
            reducedGraph.GetDirectPredecessorsOf("two").Should().Contain("one");
            reducedGraph.GetDirectSuccessorsOf("two").Should().Contain("three");
            reducedGraph.GetDirectPredecessorsOf("three").Should().Contain("two");
            reducedGraph.GetDirectSuccessorsOf("three").Should().Contain("four");
            reducedGraph.GetDirectPredecessorsOf("four").Should().Contain("three");
        }
Beispiel #3
0
        public void GetTransitiveReduction_DoesNotRemoveElements()
        {
            /*
             * ----------|
             * |         V
             * 1 -> 2 -> 3
             */
            var graph = DirectedGraphBuilder <string> .NewBuilder()
                        .AddElement("one")
                        .AddElement("two")
                        .AddElement("three")
                        .AddArrow("one", "two")
                        .AddArrow("two", "three")
                        .AddArrow("one", "three")
                        .CreateAcyclicGraphUnsafe();

            /*
             * 1 -> 2 -> 3
             */
            var reducedGraph = DirectedAcyclicGraphTransitiveReducer.ReduceGraph(graph);

            reducedGraph.Elements.Should().Contain(graph.Elements);
        }
Beispiel #4
0
        public void GetTransitiveReduction_KeepsRequiredEdges()
        {
            /*
             * 1 -> 2 -> 3
             */
            var graph = DirectedGraphBuilder <string> .NewBuilder()
                        .AddElement("one")
                        .AddElement("two")
                        .AddElement("three")
                        .AddArrow("one", "two")
                        .AddArrow("two", "three")
                        .AddArrow("one", "three")
                        .CreateAcyclicGraphUnsafe();

            /*
             * 1 -> 2 -> 3
             */
            var reducedGraph = DirectedAcyclicGraphTransitiveReducer.ReduceGraph(graph);

            reducedGraph.GetDirectSuccessorsOf("one").Should().Contain("two");
            reducedGraph.GetDirectPredecessorsOf("two").Should().Contain("one");
            reducedGraph.GetDirectSuccessorsOf("two").Should().Contain("three");
            reducedGraph.GetDirectPredecessorsOf("three").Should().Contain("two");
        }