public static void Main(string[] args) { Console.Title = "Dijkstra-Algorithmus"; 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 } }); Console.WriteLine("Ausgangspunkt: "); var start = Console.ReadLine().ToUpper(); Console.WriteLine("Zielpunkt: "); var ziel = Console.ReadLine().ToUpper(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Der kürzeste Weg zu Punkt '" + ziel + "' ist:"); g.shortest_path(Convert.ToChar(start), Convert.ToChar(ziel)).ForEach(x => Console.WriteLine(x)); Console.ReadLine(); }
float go(int init, int end) { List <int> list = graph.shortest_path(init, end); if (list != null) { return(showLines(list)); } else { Debug.Log("No hay ruta " + init + " " + end); noRoutes.GetComponentInChildren <Text> ().text = "No existe una ruta \n" + init + " - " + end; noRoutes.SetActive(true); return(0); } }
public 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 } }); var paths = g.shortest_path('A', 'H'); //use our iteration for out put IterationSample itSample = new IterationSample(paths); foreach (var value in itSample) { Console.WriteLine(value); } // out put is A B F H Console.ReadLine(); }
public static void Main1(string[] args) { Graph g = new Graph(); g.add_vertex('1', new Dictionary <char, int>() { { '2', 1 }, { '6', 6 } }); g.add_vertex('2', new Dictionary <char, int>() { { '1', 1 }, { '2', 3 }, { '4', 1 }, { '6', 2 } }); g.add_vertex('3', new Dictionary <char, int>() { { '2', 3 /* 0 */ }, { '4', 4 }, { '5', 5 }, { '6', 5 } }); g.add_vertex('4', new Dictionary <char, int>() { { '3', 3 } /* 0 */, { '5', 5 }, { '2', 1 } /* 0 */ }); g.add_vertex('5', new Dictionary <char, int>() { { '4', 4 }, { '6', 6 }, { '3', 5 } }); g.add_vertex('6', new Dictionary <char, int>() { { '5', 5 }, { '7', 7 }, { '3', 5 }, { '1', 6 }, { '2', 2 } }); g.add_vertex('7', new Dictionary <char, int>() { { '6', 6 }, { '8', 7 /*shtct*/ }, { 'A', 10 /*shtct*/ }, { '4', 4 } }); g.add_vertex('8', new Dictionary <char, int>() { { '7', 3 }, { '9', 9 } }); g.add_vertex('9', new Dictionary <char, int>() { { '8', 8 }, { 'A', 10 } }); g.add_vertex('A', new Dictionary <char, int>() { { '9', 9 }, { '7', 10 } }); g.shortest_path('1', 'A').ForEach(x => Console.WriteLine(x)); }
public 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('A', 'H').ForEach(x => Console.WriteLine(x)); Console.ReadKey(); }
public static void Main(string[] args) { Graph g = new Graph(); g.add_vertex('A', new Dictionary <char, int>() { { 'B', 20 } }); g.add_vertex('B', new Dictionary <char, int>() { { 'A', 20 }, { 'C', 10 }, { 'E', 30 }, { 'J', 90 }, { 'H', 50 } }); g.add_vertex('C', new Dictionary <char, int>() { { 'B', 10 }, { 'D', 30 } }); g.add_vertex('D', new Dictionary <char, int>() { { 'C', 30 }, { 'F', 60 }, { 'E', 50 } }); g.add_vertex('E', new Dictionary <char, int>() { { 'D', 50 }, { 'F', 20 }, { 'G', 30 } }); g.add_vertex('F', new Dictionary <char, int>() { { 'E', 20 }, { 'G', 40 }, { 'L', 100 } }); g.add_vertex('G', new Dictionary <char, int>() { { 'B', 50 }, { 'J', 30 }, { 'L', 40 } }); g.add_vertex('H', new Dictionary <char, int>() { { 'I', 90 } }); g.add_vertex('I', new Dictionary <char, int>() { { 'H', 90 }, { 'J', 40 }, { 'K', 90 } }); g.add_vertex('J', new Dictionary <char, int>() { { 'I', 40 }, { 'K', 40 }, { 'G', 30 } }); g.add_vertex('K', new Dictionary <char, int>() { { 'M', 20 }, { 'L', 30 } }); g.add_vertex('L', new Dictionary <char, int>() { { 'F', 100 }, { 'K', 30 } }); g.add_vertex('M', new Dictionary <char, int>() { { 'K', 20 } }); BB: Console.Write("Baslangıç: "); char baslangıc = Convert.ToChar(Console.ReadLine().ToUpper()); Console.Write("Bitiş: "); char bitis = Convert.ToChar(Console.ReadLine().ToUpper()); ArrayList dizi = new ArrayList(); foreach (var item in g.shortest_path(baslangıc, bitis)) { dizi.Add(item); } dizi.Add(baslangıc); Console.WriteLine("----BAŞLANGIÇ---"); dizi.Reverse(); foreach (var item in dizi) { Console.WriteLine(item + " "); } Console.WriteLine("----BİTİŞ-------"); g.yolhesapla(dizi); g.lambahesapla(dizi); goto BB; }
public 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('A', 'H').ForEach( x => Console.WriteLine(x) ); }