Esempio n. 1
0
        public static void GivenExampleGraphFindFlow()
        {
            var exampleGraph = ExampleGraph.Create();

            var res = Algorithm.EdmondsKarpAlgo(exampleGraph, source: 0, sink: 6);

            Assert.Equal(expected: 7, actual: res);
        }
Esempio n. 2
0
        public static void GivenGraphFindDijkstraSolution(string name, int target, int[] expectedPath, int expectedCost)
        {
            Debug.Write($"Test: {name}.");

            var graph = ExampleGraph.Create();

            var dijkstra = Algorithm.DijkStra(graph, source: 0);

            var path = dijkstra.Path(target);
            var cost = dijkstra.Distance(target);

            Assert.Equal(expected: expectedPath, actual: path);
            Assert.Equal(expected: expectedCost, actual: cost);
        }
Esempio n. 3
0
        public static void GivenGraphFindSpanningTreeUsingPrimAlg()
        {
            var g = ExampleGraph.Create();

            var spanningTreeEdges = Algorithm.SpanningTreePrim(g)
                                    .AsEnumerable()
                                    .ToList();

            var expectedTree = new Graph();

            expectedTree.AddVertexRange(g.NumberOfVertices);
            expectedTree.AddDoubleEdge(new Edge {
                Start = 0, Stop = 1, Weight = 5
            });
            expectedTree.AddDoubleEdge(new Edge {
                Start = 0, Stop = 3, Weight = 7
            });
            expectedTree.AddDoubleEdge(new Edge {
                Start = 3, Stop = 4, Weight = 4
            });
            expectedTree.AddDoubleEdge(new Edge {
                Start = 3, Stop = 5, Weight = 3
            });
            expectedTree.AddDoubleEdge(new Edge {
                Start = 5, Stop = 2, Weight = 2
            });
            expectedTree.AddDoubleEdge(new Edge {
                Start = 5, Stop = 6, Weight = 2
            });
            var expectedTreeEdges = expectedTree.AsEnumerable().ToList();

            Assert.Equal(
                expected: expectedTreeEdges.Count(),
                actual: spanningTreeEdges.Count());

            foreach (var exp in expectedTreeEdges)
            {
                spanningTreeEdges.Contains(exp);
            }
        }