public void Exceptions() { ImmutableHashSet <TestVertex> set1 = new HashSet <TestVertex>() { A, B, C, D }.ToImmutableHashSet(); ImmutableHashSet <TestEdge> set2 = new HashSet <TestEdge>() { new TestEdge(A, B, W2), new TestEdge(B, A, W1), new TestEdge(A, A, W3), new TestEdge(A, C, NW1), new TestEdge(C, D, W3), }.ToImmutableHashSet(); Graph = new TestAdjacencyListsGraph(set1, set2); TestAbstractGraphPathSearch gs = GraphSearch; ISet <IPath <TestVertex, TestEdge> > paths = gs.Search(Graph, A, D, Weigher, TestAbstractGraphPathSearch.AllPaths).Paths; PrintPaths(paths); Assert.Equal(0, paths.Count); paths = gs.Search(Graph, A, A, Weigher, 5).Paths; // Should find no paths between the same vertices. Assert.Equal(0, paths.Count); // Invalid operation since there should be no paths. Assert.Throws <InvalidOperationException>(() => paths.First().Cost); }
public void NoPath() { ImmutableHashSet <TestVertex> set1 = new HashSet <TestVertex>() { A, B, C, D }.ToImmutableHashSet(); ImmutableHashSet <TestEdge> set2 = new HashSet <TestEdge>() { new TestEdge(A, B, W1), new TestEdge(B, A, W1), new TestEdge(C, D, W1), new TestEdge(D, C, W1), }.ToImmutableHashSet(); Graph = new TestAdjacencyListsGraph(set1, set2); TestAbstractGraphPathSearch gs = GraphSearch; ISet <IPath <TestVertex, TestEdge> > paths = gs.Search(Graph, A, B, Weigher, 1).Paths; PrintPaths(paths); Assert.Equal(1, paths.Count); Assert.Equal(new TestDoubleWeight(1.0), paths.First().Cost); paths = gs.Search(Graph, A, D, Weigher, 1).Paths; PrintPaths(paths); Assert.Equal(0, paths.Count); paths = gs.Search(Graph, A, null, Weigher, 1).Paths; PrintPaths(paths); Assert.Equal(1, paths.Count); Assert.Equal(new TestDoubleWeight(1.0), paths.First().Cost); }
public void DualEdgeMultiplePath() { ImmutableHashSet <TestVertex> set1 = new HashSet <TestVertex>() { A, B, C, D, E, F, G, H }.ToImmutableHashSet(); ImmutableHashSet <TestEdge> set2 = new HashSet <TestEdge>() { new TestEdge(A, B, W1), new TestEdge(A, C, W3), new TestEdge(B, D, W2), new TestEdge(B, C, W1), new TestEdge(B, E, W4), new TestEdge(C, E, W1), new TestEdge(D, H, W5), new TestEdge(D, E, W1), new TestEdge(E, F, W1), new TestEdge(F, D, W1), new TestEdge(F, G, W1), new TestEdge(F, H, W1), new TestEdge(A, E, W3), new TestEdge(B, D, W1), }.ToImmutableHashSet(); Graph = new TestAdjacencyListsGraph(set1, set2); ExecuteSearch(GraphSearch, Graph, A, E, Weigher, 3, W3); ExecuteSinglePathSearch(GraphSearch, Graph, A, E, Weigher, 1, W3); TestAbstractGraphPathSearch gs = GraphSearch; ISet <IPath <TestVertex, TestEdge> > pathF = gs.Search(Graph, A, F, Weigher, TestAbstractGraphPathSearch.AllPaths).Paths; ISet <IPath <TestVertex, TestEdge> > pathE = gs.Search(Graph, A, E, Weigher, TestAbstractGraphPathSearch.AllPaths).Paths; Assert.Equal(0, pathF.Count - pathE.Count); Assert.Equal(new TestDoubleWeight(1.0), pathF.First().Cost.Subtract(pathE.First().Cost)); }
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]); }
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); }