コード例 #1
0
        public void CheckPredecessorLineGraph()
        {
            AdjacencyGraph <int, Edge <int> > g = new AdjacencyGraph <int, Edge <int> >(true);

            g.AddVertex(1);
            g.AddVertex(2);
            g.AddVertex(3);

            Edge <int> e12 = new Edge <int>(1, 2); g.AddEdge(e12);
            Edge <int> e23 = new Edge <int>(2, 3); g.AddEdge(e23);

            Dictionary <Edge <int>, double> weights =
                DijkstraShortestPathAlgorithm <int, Edge <int> > .UnaryWeightsFromEdgeList(g);

            DijkstraShortestPathAlgorithm <int, Edge <int> >     dij = new DijkstraShortestPathAlgorithm <int, Edge <int> >(g, weights);
            VertexPredecessorRecorderObserver <int, Edge <int> > vis = new VertexPredecessorRecorderObserver <int, Edge <int> >();

            vis.Attach(dij);
            dij.Compute(1);

            IList <Edge <int> > col = vis.Path(2);

            Assert.AreEqual(1, col.Count);
            Assert.AreEqual(e12, col[0]);

            col = vis.Path(3);
            Assert.AreEqual(2, col.Count);
            Assert.AreEqual(e12, col[0]);
            Assert.AreEqual(e23, col[1]);
        }
コード例 #2
0
        public void RunOnLineGraph()
        {
            AdjacencyGraph <int, Edge <int> > g = new AdjacencyGraph <int, Edge <int> >(true);

            g.AddVertex(1);
            g.AddVertex(2);
            g.AddVertex(3);

            g.AddEdge(new Edge <int>(1, 2));
            g.AddEdge(new Edge <int>(2, 3));

            Dictionary <Edge <int>, double> weights =
                DijkstraShortestPathAlgorithm <int, Edge <int> > .UnaryWeightsFromEdgeList(g);

            DijkstraShortestPathAlgorithm <int, Edge <int> > dij = new DijkstraShortestPathAlgorithm <int, Edge <int> >(g, weights);

            dij.Compute(1);

            Assert.AreEqual <double>(0, dij.Distances[1]);
            Assert.AreEqual <double>(1, dij.Distances[2]);
            Assert.AreEqual <double>(2, dij.Distances[3]);
        }
コード例 #3
0
        private void Search(IVertexAndEdgeListGraph <string, Edge <string> > g, string root)
        {
            DijkstraShortestPathAlgorithm <string, Edge <string> > algo = new DijkstraShortestPathAlgorithm <string, Edge <string> >(g,
                                                                                                                                     DijkstraShortestPathAlgorithm <string, Edge <string> > .UnaryWeightsFromEdgeList(g)
                                                                                                                                     );
            VertexPredecessorRecorderObserver <string, Edge <string> > predecessors = new VertexPredecessorRecorderObserver <string, Edge <string> >();

            predecessors.Attach(algo);
            algo.Compute(root);

            Verify(algo, predecessors);
        }
コード例 #4
0
 public void UnaryWeights()
 {
     AdjacencyGraph <int, Edge <int> > g       = new AdjacencyGraph <int, Edge <int> >(true);
     Dictionary <Edge <int>, double>   weights =
         DijkstraShortestPathAlgorithm <int, Edge <int> > .UnaryWeightsFromEdgeList(g);
 }