Ejemplo n.º 1
0
        static void Main()
        {
            IGraph      g;
            IPathFinder pathFinder = new DijkstraPathFinder();

            Console.WriteLine("=== Graph initialized with Adj. Matrix ===");
            g = TestAM();
            //ShowConns(g);
            ShowPath(pathFinder.FindPath(g, 0, 7));

            Console.WriteLine("=== Graph initialized with Adj. List ===");
            g = TestAL();
            //ShowConns(g);
            ShowPath(pathFinder.FindPath(g, 0, 6));
        }
Ejemplo n.º 2
0
        public void SinglePath()
        {
            var reader = new StringReader(
                @"graph {
A -- B -- C
}");
            var dotReader = new DotReader(reader);
            var g         = dotReader.Read();

            g.Edges["A", "B"].UserData[DistanceProperty] = 1;
            g.Edges["B", "C"].UserData[DistanceProperty] = 2;

            var finder = new DijkstraPathFinder(DistanceProperty);
            var path   = finder.FindPath(g.Nodes["A"], g.Nodes["C"]).ToArray();

            Assert.Equal(new[] { g.Nodes["A"], g.Nodes["B"], g.Nodes["C"] }, path);
        }
Ejemplo n.º 3
0
        public void UnreachableNode()
        {
            var reader = new StringReader(
                @"graph {
A -- B -- C -- D
E
}");
            var dotReader = new DotReader(reader);
            var g         = dotReader.Read();

            g.Edges["A", "B"].UserData[DistanceProperty] = 1;
            g.Edges["B", "C"].UserData[DistanceProperty] = 2;
            g.Edges["C", "D"].UserData[DistanceProperty] = 3;

            var finder = new DijkstraPathFinder(DistanceProperty);

            Assert.Null(finder.FindPath(g.Nodes["A"], g.Nodes["E"]));
        }