Ejemplo n.º 1
0
        /// <inheritdoc/>
        protected override IResult <V, E> InternalSearch(IGraph <V, E> graph, V src, V dst, IEdgeWeigher <V, E> weigher, int maxPaths = -1)
        {
            // Prepare the search result.
            var result = new SpanningTreeResult(src, dst, maxPaths);

            // The source vertex has cost 0, of course.
            result.UpdateVertex(src, default, weigher.InitialWeight, true);
Ejemplo n.º 2
0
        public void ExecuteBroadSearch()
        {
            Graph = new TestAdjacencyListsGraph(Vertices, Edges);
            TestAbstractGraphPathSearch search = GraphSearch;
            SpanningTreeResult          result = (SpanningTreeResult)search.Search(Graph, A, null, Weigher, TestAbstractGraphPathSearch.AllPaths);

            Assert.Equal(7, result.Paths.Count);

            int[] types = new int[] { 0, 0, 0, 0 };
            foreach (EdgeType type in result.Edges.Values)
            {
                types[(int)type] += 1;
            }
            Assert.Equal(7, types[(int)EdgeType.TreeEdge]);
            Assert.Equal(1, types[(int)EdgeType.BackEdge]);
            Assert.Equal(4, types[(int)EdgeType.ForwardEdge] + types[(int)EdgeType.CrossEdge]);
        }
Ejemplo n.º 3
0
        protected void ExecuteDefaultTest(int minLength, int maxLength, IWeight minCost, IWeight maxCost)
        {
            Graph = new TestAdjacencyListsGraph(Vertices, Edges);
            TestAbstractGraphPathSearch          search = GraphSearch;
            SpanningTreeResult                   result = (SpanningTreeResult)search.Search(Graph, A, H, Weigher, 1);
            ISet <IPath <TestVertex, TestEdge> > paths  = result.Paths;

            Assert.Equal(1, paths.Count);

            IPath <TestVertex, TestEdge> path = paths.First();

            Console.WriteLine(path);
            Assert.Equal(A, path.Src);
            Assert.Equal(H, path.Dst);

            int l = path.Edges.Count;

            Assert.True(minLength <= l && l <= maxLength);
            Assert.True(path.Cost.CompareTo(minCost) >= 0 && path.Cost.CompareTo(maxCost) <= 0);

            Console.WriteLine(result.Edges);
            PrintPaths(paths);
        }