Esempio n. 1
0
        static void CalculaCaminhoMinimo()
        {
            Console.Clear();
            while (true)
            {
                GeraTitlo();
                grafo.ImprimeVertices();
                Console.Write("\nDigite o nó origem: ");
                string origem = Console.ReadLine();
                Console.Write("Digite o nó destino: ");
                string destino = Console.ReadLine();
                Console.Write("Digite a métrica utilizada(Digite a letra \"A\" para Hops/Digite a letra \"B\" para Distância Geográfica/Digite a letra \"C\" para Custo)");
                string metrica = Console.ReadLine();

                if (metrica == "A")
                {
                    grafo.AdicionaArestaPonderada(new Vertice("POA"), new Vertice("FLO"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("POA"), new Vertice("BLU"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("FLO"), new Vertice("FLO"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("FLO"), new Vertice("CUR"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("FLO"), new Vertice("RJO"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("BLU"), new Vertice("CUR"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("CUR"), new Vertice("LON"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("CUR"), new Vertice("SPO"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("LON"), new Vertice("SPO"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("LON"), new Vertice("BAU"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("SPO"), new Vertice("RJO"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("SPO"), new Vertice("CAM"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("SPO"), new Vertice("SJC"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("SJC"), new Vertice("CAM"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("RJO"), new Vertice("SJC"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("RJO"), new Vertice("BHO"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("RJO"), new Vertice("SLV"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("BHO"), new Vertice("SJC"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("BHO"), new Vertice("BSB"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("CAM"), new Vertice("BAU"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("CAM"), new Vertice("RBP"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("RBP"), new Vertice("BSB"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("BAU"), new Vertice("CPG"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("CPG"), new Vertice("CUI"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("CUI"), new Vertice("MAN"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("MAN"), new Vertice("BEL"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("BEL"), new Vertice("NTL"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("BSB"), new Vertice("MAN"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("BSB"), new Vertice("NTL"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("NTL"), new Vertice("REC"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("REC"), new Vertice("SLV"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("SLV"), new Vertice("NTL"), 1);
                }
                else if (metrica == "B")
                {
                    grafo.AdicionaArestaPonderada(new Vertice("POA"), new Vertice("FLO"), 6);
                    grafo.AdicionaArestaPonderada(new Vertice("POA"), new Vertice("BLU"), 7);
                    grafo.AdicionaArestaPonderada(new Vertice("FLO"), new Vertice("FLO"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("FLO"), new Vertice("CUR"), 2);
                    grafo.AdicionaArestaPonderada(new Vertice("FLO"), new Vertice("RJO"), 12);
                    grafo.AdicionaArestaPonderada(new Vertice("BLU"), new Vertice("CUR"), 2);
                    grafo.AdicionaArestaPonderada(new Vertice("CUR"), new Vertice("LON"), 6);
                    grafo.AdicionaArestaPonderada(new Vertice("CUR"), new Vertice("SPO"), 5);
                    grafo.AdicionaArestaPonderada(new Vertice("LON"), new Vertice("SPO"), 7);
                    grafo.AdicionaArestaPonderada(new Vertice("LON"), new Vertice("BAU"), 3);
                    grafo.AdicionaArestaPonderada(new Vertice("SPO"), new Vertice("RJO"), 5);
                    grafo.AdicionaArestaPonderada(new Vertice("SPO"), new Vertice("CAM"), 1);
                    grafo.AdicionaArestaPonderada(new Vertice("SPO"), new Vertice("SJC"), 2);
                    grafo.AdicionaArestaPonderada(new Vertice("SJC"), new Vertice("CAM"), 2);
                    grafo.AdicionaArestaPonderada(new Vertice("RJO"), new Vertice("SJC"), 3);
                    grafo.AdicionaArestaPonderada(new Vertice("RJO"), new Vertice("BHO"), 7);
                    grafo.AdicionaArestaPonderada(new Vertice("RJO"), new Vertice("SLV"), 20);
                    grafo.AdicionaArestaPonderada(new Vertice("BHO"), new Vertice("SJC"), 7);
                    grafo.AdicionaArestaPonderada(new Vertice("BHO"), new Vertice("BSB"), 9);
                    grafo.AdicionaArestaPonderada(new Vertice("CAM"), new Vertice("BAU"), 3);
                    grafo.AdicionaArestaPonderada(new Vertice("CAM"), new Vertice("RBP"), 2);
                    grafo.AdicionaArestaPonderada(new Vertice("RBP"), new Vertice("BSB"), 8);
                    grafo.AdicionaArestaPonderada(new Vertice("BAU"), new Vertice("CPG"), 10);
                    grafo.AdicionaArestaPonderada(new Vertice("CPG"), new Vertice("CUI"), 8);
                    grafo.AdicionaArestaPonderada(new Vertice("CUI"), new Vertice("MAN"), 20);
                    grafo.AdicionaArestaPonderada(new Vertice("MAN"), new Vertice("BEL"), 18);
                    grafo.AdicionaArestaPonderada(new Vertice("BEL"), new Vertice("NTL"), 21);
                    grafo.AdicionaArestaPonderada(new Vertice("BSB"), new Vertice("MAN"), 22);
                    grafo.AdicionaArestaPonderada(new Vertice("BSB"), new Vertice("NTL"), 22);
                    grafo.AdicionaArestaPonderada(new Vertice("NTL"), new Vertice("REC"), 4);
                    grafo.AdicionaArestaPonderada(new Vertice("REC"), new Vertice("SLV"), 8);
                    grafo.AdicionaArestaPonderada(new Vertice("SLV"), new Vertice("NTL"), 15);
                }
                else if (metrica == "C")
                {
                    grafo.AdicionaArestaPonderada(new Vertice("POA"), new Vertice("FLO"), 2);
                    grafo.AdicionaArestaPonderada(new Vertice("POA"), new Vertice("BLU"), 2);
                    grafo.AdicionaArestaPonderada(new Vertice("FLO"), new Vertice("FLO"), 3);
                    grafo.AdicionaArestaPonderada(new Vertice("FLO"), new Vertice("CUR"), 5);
                    grafo.AdicionaArestaPonderada(new Vertice("FLO"), new Vertice("RJO"), 10);
                    grafo.AdicionaArestaPonderada(new Vertice("BLU"), new Vertice("CUR"), 5);
                    grafo.AdicionaArestaPonderada(new Vertice("CUR"), new Vertice("LON"), 2);
                    grafo.AdicionaArestaPonderada(new Vertice("CUR"), new Vertice("SPO"), 10);
                    grafo.AdicionaArestaPonderada(new Vertice("LON"), new Vertice("SPO"), 2);
                    grafo.AdicionaArestaPonderada(new Vertice("LON"), new Vertice("BAU"), 2);
                    grafo.AdicionaArestaPonderada(new Vertice("SPO"), new Vertice("RJO"), 15);
                    grafo.AdicionaArestaPonderada(new Vertice("SPO"), new Vertice("CAM"), 7);
                    grafo.AdicionaArestaPonderada(new Vertice("SPO"), new Vertice("SJC"), 16);
                    grafo.AdicionaArestaPonderada(new Vertice("SJC"), new Vertice("CAM"), 10);
                    grafo.AdicionaArestaPonderada(new Vertice("RJO"), new Vertice("SJC"), 10);
                    grafo.AdicionaArestaPonderada(new Vertice("RJO"), new Vertice("BHO"), 6);
                    grafo.AdicionaArestaPonderada(new Vertice("RJO"), new Vertice("SLV"), 6);
                    grafo.AdicionaArestaPonderada(new Vertice("BHO"), new Vertice("SJC"), 8);
                    grafo.AdicionaArestaPonderada(new Vertice("BHO"), new Vertice("BSB"), 6);
                    grafo.AdicionaArestaPonderada(new Vertice("CAM"), new Vertice("BAU"), 6);
                    grafo.AdicionaArestaPonderada(new Vertice("CAM"), new Vertice("RBP"), 4);
                    grafo.AdicionaArestaPonderada(new Vertice("RBP"), new Vertice("BSB"), 4);
                    grafo.AdicionaArestaPonderada(new Vertice("BAU"), new Vertice("CPG"), 3);
                    grafo.AdicionaArestaPonderada(new Vertice("CPG"), new Vertice("CUI"), 2);
                    grafo.AdicionaArestaPonderada(new Vertice("CUI"), new Vertice("MAN"), 3);
                    grafo.AdicionaArestaPonderada(new Vertice("MAN"), new Vertice("BEL"), 2);
                    grafo.AdicionaArestaPonderada(new Vertice("BEL"), new Vertice("NTL"), 3);
                    grafo.AdicionaArestaPonderada(new Vertice("BSB"), new Vertice("MAN"), 6);
                    grafo.AdicionaArestaPonderada(new Vertice("BSB"), new Vertice("NTL"), 7);
                    grafo.AdicionaArestaPonderada(new Vertice("NTL"), new Vertice("REC"), 3);
                    grafo.AdicionaArestaPonderada(new Vertice("REC"), new Vertice("SLV"), 5);
                    grafo.AdicionaArestaPonderada(new Vertice("SLV"), new Vertice("NTL"), 4);
                }

                List <int> rotas_r = grafo.AlgoritmoDijkstra(new Vertice(origem), new Vertice(destino));
                foreach (int i in rotas_r)
                {
                    Console.Write(grafo.Vertices[i].Rotulo + "-->");
                }
                Console.WriteLine();
                Console.WriteLine("Pressione enter para retornar ao menu anterior");
                Console.ReadLine();
                Console.Clear();
                return;
            }
        }