Exemple #1
0
        static void Main(string[] args)
        {
            Graph g = new Graph();

            g.add_vertex('A', new Dictionary <char, int>()
            {
                { 'B', 1 }, { 'C', 2 }
            });
            g.add_vertex('B', new Dictionary <char, int>()
            {
                { 'C', 1 }, { 'D', 5 }, { 'E', 2 }
            });
            g.add_vertex('C', new Dictionary <char, int>()
            {
                { 'D', 2 }, { 'E', 1 }, { 'F', 4 }
            });
            g.add_vertex('D', new Dictionary <char, int>()
            {
                { 'E', 3 }, { 'F', 6 }, { 'G', 8 }
            });
            g.add_vertex('E', new Dictionary <char, int>()
            {
                { 'F', 3 }, { 'G', 7 }
            });
            g.add_vertex('F', new Dictionary <char, int>()
            {
                { 'G', 5 }, { 'H', 2 }
            });
            g.add_vertex('G', new Dictionary <char, int>()
            {
                { 'H', 6 }
            });
            g.add_vertex('H', new Dictionary <char, int>()
            {
            });


            //  g.shortest_path('A', 'F').ForEach(x => Console.WriteLine(x));
            Console.WriteLine("Dijskra ALgorithm");
            foreach (var vertex in g.shortest_path('A', 'F'))
            {
                Console.WriteLine(vertex.Key + "," + vertex.Value);
            }

            Console.WriteLine("..................................................");
            Console.WriteLine("FLoyd's Part");
            foreach (var startVertex in g.vertices)
            {
                foreach (var endVertex in g.vertices)
                {
                    Console.WriteLine($"From {startVertex.Key} to {endVertex.Key}");
                    foreach (var vertex in g.shortest_path(startVertex.Key, endVertex.Key))
                    {
                        Console.WriteLine(vertex.Key + "," + vertex.Value);
                    }
                }
                Console.WriteLine("--------------------");
            }
            Console.ReadLine();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Graph g = new Graph();

            g.add_vertex('A', new Dictionary <char, int>()
            {
                { 'B', 7 }, { 'C', 8 }
            });
            g.add_vertex('B', new Dictionary <char, int>()
            {
                { 'A', 7 }, { 'F', 2 }
            });
            g.add_vertex('C', new Dictionary <char, int>()
            {
                { 'A', 8 }, { 'F', 6 }, { 'G', 4 }
            });
            g.add_vertex('D', new Dictionary <char, int>()
            {
                { 'F', 8 }
            });
            g.add_vertex('E', new Dictionary <char, int>()
            {
                { 'H', 1 }
            });
            g.add_vertex('F', new Dictionary <char, int>()
            {
                { 'B', 2 }, { 'C', 6 }, { 'D', 8 }, { 'G', 9 }, { 'H', 3 }
            });
            g.add_vertex('G', new Dictionary <char, int>()
            {
                { 'C', 4 }, { 'F', 9 }
            });
            g.add_vertex('H', new Dictionary <char, int>()
            {
                { 'E', 1 }, { 'F', 3 }
            });

            g.shortest_path('E', 'G').ForEach(x => Console.WriteLine(x));
            Console.ReadKey();
        }
Exemple #3
0
 public List <Node> shortest_path(Node start, Node finish)
 {
     return(graph.shortest_path(start, finish));
 }
Exemple #4
0
 public static List <UnityEngine.Vector3> GetPath(UnityEngine.Vector3 start, UnityEngine.Vector3 finish)
 {
     return(g.shortest_path(start, finish));
 }