Esempio n. 1
0
 private int calculaDiferenca(List<VerticeTsp> caminho, GrafoTsp grafo, VerticeTsp a, VerticeTsp b, VerticeTsp c, VerticeTsp d)
 {
     int diferenca = (
         grafo.MatrizDistancias[a.Id, b.Id] + grafo.MatrizDistancias[c.Id, d.Id]
       - grafo.MatrizDistancias[a.Id, c.Id] - grafo.MatrizDistancias[b.Id, d.Id]);
     return diferenca;
 }
Esempio n. 2
0
 private int CalcularDistancia(VerticeTsp origem, VerticeTsp destino)
 {
     if (origem.Id != destino.Id)
     {
         double dx = origem.Ponto.x - destino.Ponto.x;
         double dy = origem.Ponto.y - destino.Ponto.y;
         double distanciaReal = Math.Sqrt((dx * dx) + (dy * dy));
         return (int)(distanciaReal + 0.5);
     }
     else
     {
         return Int32.MaxValue;
     }
 }
Esempio n. 3
0
        public static GrafoTsp LerTsp(string caminhoArquivo)
        {
            var arquivo = File.ReadAllLines(caminhoArquivo);
            var retorno = new GrafoTsp(arquivo.Length);

            foreach (var linha in arquivo)
            {
                try
                {
                    var split = linha.Trim().Split(' ');
                    var ponto = new Ponto(Convert.ToDouble(split[1]), Convert.ToDouble(split[2]));
                    var vertice = new VerticeTsp(Convert.ToInt32(split[0]), ponto);
                    retorno.Vertices.Add(Convert.ToInt32(split[0]), vertice);
                }
                catch (Exception e)
                {
                    throw new Exception(String.Format("Erro ao tratar linha: '{0}' . Mensagem de erro: {1}", linha, e.Message));
                }
            }

            return retorno;
        }