Beispiel #1
0
        /// <summary>
        /// Carrega os dados do grafo para a instâncias small
        /// </summary>
        protected void CarregarInformacoesInstancia()
        {
            string nomeArquivo = this.CaminhoBaseInstancias + Instancia;

            using (var leitorArquivo = new StreamReader(nomeArquivo))
            {
                string   linha = leitorArquivo.ReadLine();
                string[] parametrosInstancia = leitorArquivo.ReadLine().Split(' ');
                int      qtdVertices         = int.Parse(parametrosInstancia[0]);

                for (int i = 1; i <= qtdVertices; i++)
                {
                    Grafo.Add(i, new List <int>());
                }

                linha = leitorArquivo.ReadLine();
                while (!string.IsNullOrEmpty(linha))
                {
                    int[] aresta = linha.Split(' ').Select(x => int.Parse(x)).ToArray();

                    Grafo[aresta[0]].Add(aresta[1]);
                    Grafo[aresta[1]].Add(aresta[0]);

                    linha = leitorArquivo.ReadLine();
                }
            }
        }
Beispiel #2
0
        public void ReadFile(String path)
        {
            string[] lines = System.IO.File.ReadAllLines(path);
            foreach (string line in lines)
            {
                string[] linea = line.Split(new Char[] { ',', ':', ' ' });
                switch (linea.Length)
                {
                case 1:
                    Grafo.Add(new Nodo(linea[0]));
                    break;

                case 2:
                    Heuristica.Add(linea[0], Convert.ToInt32(linea[1]));
                    break;

                case 3:
                    AristasGlobales.Add(new Arista(Convert.ToInt32(linea[0]), BuscaNodo(linea[1]), BuscaNodo(linea[2])));
                    break;
                }
            }
            foreach (Arista arista in AristasGlobales)
            {
                foreach (Nodo nodo in Grafo)
                {
                    if (arista.partida.Equals(nodo))
                    {
                        nodo.AgregaArista(arista);
                    }
                }
            }
        }
Beispiel #3
0
        private void NewNodo(IDTokens valor, int cantidad)
        {
            List <int> listaNodos;
            bool       newKey;

            listaNodos = (newKey = !_NodosLex.TryGetValue(valor, out listaNodos)) ?
                         new List <int>()
            {
                0
            } : listaNodos;
            for (int i = 0; i < cantidad; i++)
            {
                listaNodos.Add(_GrafoTokens.Add(valor));
            }

            if (newKey)
            {
                _NodosLex.Add(valor, listaNodos);
            }
        }