Exemple #1
0
        public static void readFileDigrafo(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 = 0;
                    if (int.Parse(separador[3]) > 0)
                    {
                        pos = verifyArray(new Vertice(int.Parse(separador[0])));
                        if (pos == -1)
                        {
                            arrayV[count] = new Vertice(int.Parse(separador[0]));
                            arrayV[count].Adjacente.Add(new Vertice(int.Parse(separador[1])));
                            count++;
                        }
                        else
                        {
                            arrayV[pos].Adjacente.Add(new Vertice(int.Parse(separador[1])));
                        }
                    }
                    else
                    {
                        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();
            }

            /*for (int i = 0; i < arrayV.Length; i++)
             * {
             *  Console.WriteLine(arrayV[i].Id + " vertice array \n");
             *  foreach (var item in arrayV[i].Adjacente)
             *  {
             *      Console.WriteLine(item.Id + " adjacente");
             *  }
             * }
             * Console.ReadKey();*/
        }
Exemple #2
0
 public Aresta(Vertice o, Vertice d, int p)
 {
     this.origem  = o;
     this.destino = d;
     this.peso    = p;
 }
Exemple #3
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();
            }
        }