public void CheckPredecessorLineGraph() { AdjacencyGraph g = new AdjacencyGraph(true); IVertex v1 = g.AddVertex(); IVertex v2 = g.AddVertex(); IVertex v3 = g.AddVertex(); IEdge e12 = g.AddEdge(v1,v2); IEdge e23 = g.AddEdge(v2,v3); EdgeDoubleDictionary weights = DijkstraShortestPathAlgorithm.UnaryWeightsFromEdgeList(g); DijkstraShortestPathAlgorithm dij = new DijkstraShortestPathAlgorithm(g,weights); PredecessorRecorderVisitor vis = new PredecessorRecorderVisitor(); dij.RegisterPredecessorRecorderHandlers(vis); dij.Compute(v1); EdgeCollection col = vis.Path(v2); Assert.AreEqual(1,col.Count); Assert.AreEqual(e12,col[0]); col = vis.Path(v3); Assert.AreEqual(2,col.Count); Assert.AreEqual(e12,col[0]); Assert.AreEqual(e23,col[1]); }
public void AttachPredecessorRecorderVisitor() { AdjacencyGraph g = new AdjacencyGraph(true); EdgeDoubleDictionary weights = DijkstraShortestPathAlgorithm.UnaryWeightsFromEdgeList(g); DijkstraShortestPathAlgorithm dij = new DijkstraShortestPathAlgorithm(g,weights); PredecessorRecorderVisitor vis = new PredecessorRecorderVisitor(); dij.RegisterPredecessorRecorderHandlers(vis); }