示例#1
0
 public void imprimeArestas(Aresta item)
 {
     Console.WriteLine("Aresta origem: " + item.Origem.Id);
     Console.WriteLine("Aresta destino: " + item.Destino.Id);
     Console.WriteLine("Aresta peso: " + item.Peso);
     Console.WriteLine("\n");
 }
示例#2
0
        public static void readFileGrafo(string path)
        {
            StreamReader arq   = new StreamReader(path);
            int          count = 0;
            string       linha = "";

            string[] separador;
            linha = arq.ReadLine();
            bool read = false;

            while (linha != null)
            {
                separador = linha.Split(';');
                if (!read)
                {
                    arrayV = new Vertice[int.Parse(separador[0])];
                    read   = true;
                }
                else
                {
                    int pos = verifyArray(new Vertice(int.Parse(separador[0])));
                    if (pos == -1)
                    {
                        //se nao existir o vertice
                        arrayV[count] = new Vertice(int.Parse(separador[0]));
                        arrayV[count].Adjacente.Add(new Vertice(int.Parse(separador[1])));
                        Aresta a = new Aresta(new Vertice(int.Parse(separador[0])), new Vertice(int.Parse(separador[1])), int.Parse(separador[2]));
                        arrayA.Add(a);
                        count++;
                        pos = verifyArray(new Vertice(int.Parse(separador[1])));
                        if (pos == -1)
                        {
                            arrayV[count] = new Vertice(int.Parse(separador[1]));
                            arrayV[count].Adjacente.Add(new Vertice(int.Parse(separador[0])));
                            //a = new Aresta(new Vertice(int.Parse(separador[1])), new Vertice(int.Parse(separador[0])), int.Parse(separador[2]));
                            //arrayA.Add(a);
                            count++;
                        }
                        else
                        {
                            arrayV[pos].Adjacente.Add(new Vertice(int.Parse(separador[0])));
                            a = new Aresta(new Vertice(int.Parse(separador[0])), new Vertice(int.Parse(separador[1])), int.Parse(separador[2]));
                            arrayA.Add(a);
                        }
                    }
                    else
                    {
                        //se o vertice ja existir no array
                        arrayV[pos].Adjacente.Add(new Vertice(int.Parse(separador[1])));
                        Aresta a = new Aresta(new Vertice(int.Parse(separador[0])), new Vertice(int.Parse(separador[1])), int.Parse(separador[2]));
                        arrayA.Add(a);
                        pos = verifyArray(new Vertice(int.Parse(separador[1])));
                        if (pos == -1)
                        {
                            arrayV[count] = new Vertice(int.Parse(separador[1]));
                            arrayV[count].Adjacente.Add(new Vertice(int.Parse(separador[0])));
                            count++;
                        }
                        else
                        {
                            arrayV[pos].Adjacente.Add(new Vertice(int.Parse(separador[0])));
                        }
                    }
                }
                linha = arq.ReadLine();
            }
        }