Exemplo n.º 1
0
        private void Search(
            IVertexListGraph <string, Edge <string> > g,
            string root, IDistanceRelaxer relaxer)
        {
            DagShortestPathAlgorithm <string, Edge <string> > algo =
                new DagShortestPathAlgorithm <string, Edge <string> >(
                    g,
                    DagShortestPathAlgorithm <string, Edge <string> > .UnaryWeightsFromVertexList(g),
                    relaxer
                    );
            VertexPredecessorRecorderObserver <string, Edge <string> > predecessors = new VertexPredecessorRecorderObserver <string, Edge <string> >();

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

            Verify(algo, predecessors);
        }
Exemplo n.º 2
0
        private void Search <TVertex, TEdge>(
            IVertexListGraph <TVertex, TEdge> g,
            TVertex root, IDistanceRelaxer relaxer)
            where TEdge : IEdge <TVertex>
        {
            var algo =
                new DagShortestPathAlgorithm <TVertex, TEdge>(
                    g,
                    e => 1,
                    relaxer
                    );
            var predecessors = new VertexPredecessorRecorderObserver <TVertex, TEdge>();

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

            Verify(algo, predecessors);
        }
Exemplo n.º 3
0
 private static void Verify(DagShortestPathAlgorithm <string, Edge <string> > algo, VertexPredecessorRecorderObserver <string, Edge <string> > predecessors)
 {
     // let's verify the result
     foreach (string v in algo.VisitedGraph.Vertices)
     {
         Edge <string> predecessor;
         if (!predecessors.VertexPredecessors.TryGetValue(v, out predecessor))
         {
             continue;
         }
         if (predecessor.Source == v)
         {
             continue;
         }
         Assert.AreEqual(
             algo.Distances[v], algo.Distances[predecessor.Source] + 1
             );
     }
 }
Exemplo n.º 4
0
 private static void Verify <TVertex, TEdge>(
     DagShortestPathAlgorithm <TVertex, TEdge> algo,
     VertexPredecessorRecorderObserver <TVertex, TEdge> predecessors)
     where TEdge : IEdge <TVertex>
 {
     // let's verify the result
     foreach (var v in algo.VisitedGraph.Vertices)
     {
         TEdge predecessor;
         if (!predecessors.VertexPredecessors.TryGetValue(v, out predecessor))
         {
             continue;
         }
         if (predecessor.Source.Equals(v))
         {
             continue;
         }
         Assert.Equal(algo.Distances[v], algo.Distances[predecessor.Source] + 1);
     }
 }
 private static void Verify(DagShortestPathAlgorithm<string, Edge<string>> algo, VertexPredecessorRecorderObserver<string, Edge<string>> predecessors)
 {
     // let's verify the result
     foreach (string v in algo.VisitedGraph.Vertices)
     {
         Edge<string> predecessor;
         if (!predecessors.VertexPredecessors.TryGetValue(v, out predecessor))
             continue;
         if (predecessor.Source == v)
             continue;
         Assert.AreEqual(
             algo.Distances[v], algo.Distances[predecessor.Source] + 1
             );
     }
 }
        private void Search(
            IVertexListGraph<string, Edge<string>> g, 
            string root, IDistanceRelaxer relaxer)
        {
            DagShortestPathAlgorithm<string, Edge<string>> algo = 
                new DagShortestPathAlgorithm<string, Edge<string>>(
                    g,
                    DagShortestPathAlgorithm<string, Edge<string>>.UnaryWeightsFromVertexList(g),
                    relaxer
                    );
            VertexPredecessorRecorderObserver<string, Edge<string>> predecessors = new VertexPredecessorRecorderObserver<string, Edge<string>>();
            predecessors.Attach(algo);
            algo.Compute(root);

            Verify(algo, predecessors);
        }